Semantic Diff

#9411 Instantiate non-generic types without a copy session

1 commit

5e5a3a74ec514944e3e4a08f75e090e1b35e2307..pr-9411

2e243f529 · cknitt + Claude · Nov 25, 2026, 20:23 UTC

Instantiate non-generic types without a copy session

Ctype.instance and instance_def opened a copy session even for a type that is neither generic nor marked by an enclosing session, which copy returns as it is. Typecore instantiates the expected type of every expression this way, so each of these empty sessions allocated for nothing. They now return the representative directly; marked types and partial instances still take the session. warning_scope skips empty attribute lists, which also saves the closure of its partial application.

Allocation matters because every minor collection stops all compiler workers. On 77 Belt and tests/tests files, compiling allocates 3.7% fewer words, with byte-identical JS and diagnostics; a clean build of tests/tests (690 modules) writes the same 3484 files, .cmi, .cmj, .cmt and .ast included. Build time is within noise.

Unit tests in tests/ounit_tests/ounit_instance_tests.ml check that a non-generic type and its structure come back as they are, that links are followed, that generic variables and links to generic or marked nodes are still copied, that a node marked by an enclosing session gives that session's copy, and that partial instances still replace a non-generic variable by a fresh one.