Skip to content

Consolidate example suite + fix four cross-construct codegen bugs#130

Merged
MelbourneDeveloper merged 9 commits into
mainfrom
cleanup
May 30, 2026
Merged

Consolidate example suite + fix four cross-construct codegen bugs#130
MelbourneDeveloper merged 9 commits into
mainfrom
cleanup

Conversation

@MelbourneDeveloper
Copy link
Copy Markdown
Owner

TLDR

Consolidates the over-isolated examples/tested suite into fewer cross-cutting examples, relocates the language spec under docs/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 .osp examples 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.go moved its giant inline expected-output map onto sibling .expectedoutput files; 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.osp now 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:

  • spawn of a non-constant captured arg (record / runtime value) emitted use 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).
  • Discriminated-union construction used a stack alloca and 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 via malloc with an exact struct size (expression_generation.go).
  • m[key] on a runtime-built map (Map()/mapSet) read the opaque OspreyMap* 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 the mapGet builtin (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 standard TestBasicsExamples runner:

  • TestBasicsExamples/knownbugs/bug1_spawn_record27\n27
  • TestBasicsExamples/knownbugs/bug2_string_union_payloaddone 27\nfailed empty
  • TestBasicsExamples/knownbugs/bug3_map_built_indexa=9\nlen 2
  • TestBasicsExamples/knownbugs/bug4_union_return_argdone 27\ndone 27\nfailed 99

The mixup is verified by TestEffectsExamples/fiber_effects (exact stdout match). The full go test ./... for the compiler passes (integration + unit/codegen), and make lint/make build are clean, confirming no regression across the existing union/record/fiber/collection examples.

- 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.
@MelbourneDeveloper MelbourneDeveloper merged commit 304631f into main May 30, 2026
0 of 2 checks passed
@MelbourneDeveloper MelbourneDeveloper deleted the cleanup branch May 30, 2026 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant