Skip to content

openspec: add codegen-ir-correctness-and-gate change proposal#14

Merged
Hyper66666 merged 1 commit into
mainfrom
devin/1781100048-codegen-ir-correctness-and-gate
Jun 10, 2026
Merged

openspec: add codegen-ir-correctness-and-gate change proposal#14
Hyper66666 merged 1 commit into
mainfrom
devin/1781100048-codegen-ir-correctness-and-gate

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 10, 2026

Copy link
Copy Markdown

Summary

Planning-only OpenSpec proposal (no code changes). It re-plans the next step toward a mainstream-usable Sengoo after core-language-correctness (PR #13) was merged and CI went green.

Why: building the toolchain and exercising the real sgc CLI on the toolchain this repo pins for developers (clang-14) shows the "done" core forms still fail to compile. The previous gate is green only because it compiles through the in-crate #[cfg(test)] compile_source() helper and runs under CI's clang-19.

Reproduced on clang 14.0.0 / rustc 1.94.0 (the pinned rust-toolchain.toml):

Form Command Observed
Array index sgc run examples/04_array.sg '%u_4' defined with type '[3 x i64]*' but expected 'i64*'
Array write/for sgc run examples/05_loop.sg, conformance/03_array_write.sg same element-pointer mismatch
Closure capture sgc run examples/06_lambda.sg, conformance/04_closure_multi_capture.sg '%u_5' defined with type '[1 x i64]*' but expected 'i64*'
Enum-returning fn function with -> EnumType @get typed { i64, [8 x i8] }(i64)* but call site expects i64(i64)*
Multi-payload match arm Variant(b) => ... followed by any arm parse error: invalid pattern: expected identifier
Local gate cargo test -p sgc core_conformance_examples_compile_link_and_run FAILED (the array case, inside the test)

Root cause: codegen states pointer operand types that disagree with the value's defined type, e.g.

%u_4 = alloca [3 x i64]                          ; %u_4 : [3 x i64]*
%u_4.elem.0 = getelementptr i64, i64* %u_4, i64 0  ; operand stated i64* — mismatch

Typed-pointer LLVM (clang <= 14) rejects this; opaque-pointer LLVM (clang >= 15, every pointer is ptr) drops the pointee type so the mismatch disappears and the address still computes correctly. CI uses clang-19, so it never sees the error. Separately, the match-arm parser only terminates a Variant(bindings) pattern correctly when it is the last arm; every committed conformance example places its single payload arm last, hiding the defect.

What the proposal owns

  • Emit type-consistent IR for array places, closure-captured slots, and aggregate (enum/struct) function results — the type a value is defined with and the type it is used with must agree and pass the pinned toolchain's verifier.
  • Fix the multi-payload match parse so a payload-binding arm parses in first/middle/last position.
  • Make the conformance gate drive the real sgc CLI (sgc build/sgc run), not the in-crate helper, and add the two forms the old gate could not catch (multi-payload match, enum-returning fn).
  • Pin the LLVM/clang contract: CI and the developer blueprint share one major version; sgc reports a clear error below contract instead of a raw IR verifier error.

This is a correctness/gate-integrity change; it explicitly does not add traits/Option-Result/as-casts/generic collections (those are separate proposed directions). For fairness, let mut, immutable-assignment rejection, and match exhaustiveness from core-language-correctness were independently verified as genuinely working.

Contents (openspec/changes/codegen-ir-correctness-and-gate/): proposal.md, design.md (reproductions + root cause + two acceptable pointer-model fixes), tasks.md (7 phases + archive gate), specs/.../spec.md (4 ADDED requirements, WHEN/THEN scenarios). openspec validate codegen-ir-correctness-and-gate --strict passes (CLI @fission-ai/openspec 1.4.1).

Link to Devin session: https://app.devin.ai/sessions/01c0d55188c64bef8f68fbe3c905738f
Requested by: @Hyper66666


Open in Devin Review

@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@Hyper66666 Hyper66666 merged commit c66a899 into main Jun 10, 2026
5 of 7 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 1 additional finding.

Open in Devin Review

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