fix: native compiler segfault on unknown new expression at module scope#516
Merged
fix: native compiler segfault on unknown new expression at module scope#516
Conversation
…ia variabledeclaration struct alignment
Contributor
Benchmark Results (Linux x86-64)
CLI Tool Benchmarks
|
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.
User impact
Before this PR,
const x = new UnknownClass()at module scope caused the native self-hosted compiler (.build/chad) to segfault silently. After this PR, it emits a compile error and exits cleanly.Root cause
VariableDeclarationcreation sites had inconsistent field counts across parsers:{ type, kind, name, value }{ type, kind, name, value, declaredType }{ type, kind, name, value, declaredType, loc }Per CLAUDE.md rule #3, the native compiler infers struct layouts from creation sites. Inconsistent field sets caused GEP misalignment — reading
stmt.valuereturned a wrong pointer, and subsequent field accesses on the misaligned expression struct crashed.Fix
VariableDeclarationcreation sites to include all 6 fields (addingdeclaredType: undefined, loc: undefinedwhere missing)generateGlobalVariableDeclarationsto use the realVariableDeclarationtype (per rule Add cross compilation support #5: never invent subset types for assertions)What this does NOT fix
new Date()at module scope still segfaults — requires aligningNewNodecreation sites, but doing so shifts the overall union struct layout and undoes theVariableDeclarationfix (cascading struct-layout interference)instanceofwith class hierarchies still segfaults — same systemic issueTest plan
tests/fixtures/edge-cases/new-unknown-class-module-scope.ts— new fixturenpm run verify:quick— all tests + stage 1 self-hosting pass