fix set heap allocation and require explicit type args#69
Merged
Conversation
set/stringset structs were stack-allocated (alloca) and stored in class fields, causing dangling pointers and segfaults when accessed after the constructor returned. switched to gc_malloc for heap allocation. also propagate declared set type through class field assignment so new Set<string>() always creates %StringSet* instead of %Set*. added error in codegen for new Set() without explicit type args (sema already catches this but codegen path is now explicit too). fixes native compiler segfault on resp.json<T>() and results[0].json<T>(). adds parallel.ts as example test [9/9] in run-examples.sh.
88acf35 to
1630356
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.
Summary
resp.json<T>()/results[0].json<T>():%Setand%StringSetstructs were stack-allocated (alloca) inside their generator functions, then stored in class fields. After the constructor returned, the pointer was dangling — dereferencing it ingenerateTypedJsoncaused SIGSEGV.generateSetLiteralandgenerateEmptyStringSetfromallocatoGC_malloc(16), matching JavaScript's heap semantics fornew Set().Set<string>type mismatch:new Set()without explicit type args was creating%Set*(double-backed) even when the field was declaredSet<string>(%StringSet*).handleClassFieldAssignmentnow propagatescurrentDeclaredSetTypebefore evaluating the RHS so the right generator is selected.new Set()without a type argument now throws in codegen (semantic analysis already catches this, but the codegen path is now explicit too).parallel.tsto example runner:scripts/run-examples.shnow includes parallel HTTP fetch as test [9/9] with a 30s watchdog timeout.Test plan
node ./dist/chad-node.js run examples/parallel.ts— still works (JS path)./.build/src/chad-native run examples/parallel.ts— no longer segfaults, prints Vue/React star counts./.build/src/chad-native run /tmp/test_json2.ts— simpleresp.json<Repo>()worksnew Set()without type arg produces error (sema + codegen)new Set<string>()andnew Set<number>()still workbash scripts/run-examples.sh— all 9 tests pass