Consolidate example suite + fix four cross-construct codegen bugs#130
Merged
Conversation
- spawn with a non-constant captured arg (record/runtime value): spill captures through per-spawn globals so the fiber closure reloads them instead of referencing out-of-scope parent SSA values. - discriminated union construction: heap-allocate (malloc) instead of stack alloca so a union returned from a function no longer dangles (garbage int payload / string-payload segfault). - m[key] on a runtime-built map (Map()/mapSet): route through the C runtime get (osprey_map_contains/get) instead of the flat-literal array reader, which segfaulted on the opaque OspreyMap* handle. Covered by examples/tested/basics/knownbugs/bug1..bug4.
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.
TLDR
Consolidates the over-isolated
examples/testedsuite into fewer cross-cutting examples, relocates the language spec underdocs/specs, and fixes four LLVM-codegen bugs that the new construct-mixing examples exposed — each pinned by a regression test.Details
Test consolidation (net −2079 lines across examples). 69 single-purpose
.ospexamples were folded into omnibus files (feature_omnibus,list_basics,map_basics,comprehensive_math,boolean_consolidated,pattern_matching_complete,string_pipeline, …) plus a handful of new mixed examples.examples_test.gomoved its giant inline expected-output map onto sibling.expectedoutputfiles; the runner still fails loudly when an example has neither a file nor a map entry (no silent coverage loss).Spec relocation. 17 spec docs moved
compiler/spec/→docs/specs/(100% renames) with the website spec-copy script and pages updated to match.New cross-cutting mixup example.
examples/tested/effects/fiber_effects.ospnow threads fibers + algebraic effects + records + a union + pattern matching + persistent List/Map through one program instead of siloing each construct.Four codegen bug fixes (
compiler/internal/codegen/), each surfaced only when constructs are combined:spawnof a non-constant captured arg (record / runtime value) emitteduse of undefined value— the fiber closure referenced parent-function SSA values. Fixed by spilling non-constant captures to per-spawn module globals and reloading them inside the closure (fiber_generation.go).allocaand returned the pointer, so a union returned from a function dangled — garbage int payloads, or a segfault when a string payload was dereferenced. Now heap-allocated viamallocwith an exact struct size (expression_generation.go).m[key]on a runtime-built map (Map()/mapSet) read the opaqueOspreyMap*handle as the flat-literal{i64,i8*}array and segfaulted. Now routed through the C runtime get (osprey_map_contains/osprey_map_get), shared with themapGetbuiltin (collection_codegen.go,expression_generation.go).How Do The Automated Tests Prove It Works?
Four regression examples under
examples/tested/basics/knownbugs/pin each bug with its correct expected output; before the fixes they failed with the exact symptoms above (IR error / segfault / wrong output), and now pass through the standardTestBasicsExamplesrunner:TestBasicsExamples/knownbugs/bug1_spawn_record→27\n27TestBasicsExamples/knownbugs/bug2_string_union_payload→done 27\nfailed emptyTestBasicsExamples/knownbugs/bug3_map_built_index→a=9\nlen 2TestBasicsExamples/knownbugs/bug4_union_return_arg→done 27\ndone 27\nfailed 99The mixup is verified by
TestEffectsExamples/fiber_effects(exact stdout match). The fullgo test ./...for the compiler passes (integration + unit/codegen), andmake lint/make buildare clean, confirming no regression across the existing union/record/fiber/collection examples.