[codegen/closures] preserve concrete class info on captured class instances#655
Closed
[codegen/closures] preserve concrete class info on captured class instances#655
Conversation
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
4364b28 to
425d51e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before
A closure that captured a class instance by value lost the concrete class name. Inside the lambda body,
capturedVar.fieldcouldn't find the class struct for GEP, so the load used the field's nominal type against whatever alloca held the capture. Pointer/string fields segfaulted; number fields returned garbage.After
Captured class instances retain their concrete class in the inner scope, so
capturedVar.fieldgenerates the correct GEP + load. The repro above printshello.Description
Closes #646. Step 3b of #640.
Threads the
concreteClassof outer-scope vars from the symbol table throughClosureAnalyzerand intoCapturedVariablerecords, then — inside the lambda body — callssymbolTable.setConcreteClass(name, className)on the re-bound capture after the normaldefineVariablecall.Why this isn't PR #644 (closed)
PR #644 took the same plumbing path but re-bound captures via
defineVariableWithMetadata(..., createClassMetadata(...))instead ofdefineVariable. That completely swapped the symbol's metadata object — losing fields likeisPointerAllocathat other codegen paths depended on — and stage 1 self-hosting silently stopped rejecting"hello" - 5in thebinary-type-in-functionfixture.This PR keeps the existing
defineVariablecall untouched and only adds theconcreteClassfield to the already-defined symbol via the existingsetConcreteClasssetter. No metadata is replaced. Thebinary-type-in-functionfixture still fails to compile as expected on stages 0/1/2.~82 LOC across 10 files.
Verification
npm run verify(stages 0/1/2) green.tests/fixtures/semantic/binary-type-in-function.tsstill emits thecannot use '-' between 'string' and 'number'compile error.tests/fixtures/closures-cabi/closure-captures-class-field-string.tsprintsTEST_PASSEDon stages 0/1/2.