Conversation
- Negative case: "alpha beta gamma" 0 variant.field-at now produces a
clear, line-numbered compile error: at line 4: variant.field-at: stack
type mismatch. Expected (..a$0 Variant Int), got (..rest String Int).
- Positive case: a real union Message { ... } program with Make-Get,
is-Get?, Get-chan still compiles and runs correctly (exit 42).
Summary of changes:
- crates/compiler/src/types.rs — added Type::Variant arm + Display
- crates/compiler/src/unification.rs — Variant ~ Variant and the
Union(_) <: Variant relaxation rule, mirroring the existing
Closure/Quotation pattern
- crates/compiler/src/typechecker/{freshen,validation}.rs — covered the
new arm
- crates/compiler/src/builtins/macros.rs — Variant in the ty! macro
- crates/compiler/src/builtins/adt.rs — all variant.* and wrap-*
signatures now use Variant instead of free V
- crates/lsp/src/completion.rs, crates/repl/src/ir/stack_effects.rs —
display the new arm
- crates/compiler/src/typechecker/tests.rs — 6 regression tests (5
negative, 1 positive)
Code Review — PR #428: Part A (compile-time) variant type safetyOverviewThis PR closes a real type-safety hole: previously all Strengths
Issues1. Acknowledged unsoundness is bidirectional (medium severity)// unification.rs:174
(Type::Union(_), Type::Variant) | (Type::Variant, Type::Union(_)) => Ok(Subst::empty()),The comment acknowledges that the symmetric arm …where 2. Test message assertions are inconsistent (low severity)
assert!(err.contains("variant.field-at") && err.contains("String"), ...);But the other four negative tests only check 3.
|
Part B implementation: - New module crates/compiler/src/codegen/debug_info.rs — DICompileUnit/DIFile/DISubprogram/DILocation emitter with a clean lifecycle (dbg_init_program / dbg_open_subprogram / dbg_call_suffix / dbg_close_subprogram / dbg_emit_module_metadata). - crates/compiler/src/codegen/state.rs — added 6 fields for debug info state plus a public set_source_file() API. - crates/compiler/src/codegen/mod.rs — added the new module. - crates/compiler/src/codegen/words.rs — opens/closes a subprogram around each user word; the QuotationScope now snapshots current_dbg_subprogram_id so quotation bodies don't bleed metadata across function boundaries. - crates/compiler/src/codegen/statements.rs — every emitted call/musttail/ret carries a !dbg record when the statement has a span. - crates/compiler/src/codegen/program.rs — flushes the metadata buffer at the tail of every IR emit path. - crates/compiler/src/lib.rs — passes the source path into codegen and -g to clang. Runtime cost: none. DWARF lives in object/dSYM files (macOS) or non-loaded ELF sections (Linux); the .text and the actual instruction stream are unchanged. The 50M tail-call benchmark runs in ~120ms user time. just ci is fully green. End-to-end, the original repro now fails at compile time with line 4 named (Part A), and any legitimate runtime panic (FFI failures, OOM, division by zero, etc.) resolves the Seq frames in its backtrace to .seq:line:col (Part B).
Code Review — PR #428: Variant-op Type Safety + DWARF Debug InfoOverviewThis PR delivers two related improvements in one shot:
The type-system changes are clean and well-reasoned. The DWARF work is architecturally sound. A few issues worth addressing before merging. Issues🐛 Metadata ID collision for large programs (
|
Real bug fixed: - crates/compiler/src/codegen/state.rs + debug_info.rs — module-flag IDs now allocated through dbg_alloc_id() and stored in dbg_module_flag_ids: Option<(usize, usize)>. The cu_id + 1000 collision class is gone. Correctness/soundness: - crates/compiler/src/codegen/statements.rs — !dbg removed from the ret after a musttail call. The call's !dbg is sufficient for backtrace resolution (confirmed: 4-deep panic trace still resolves all frames). - crates/compiler/src/typechecker/tests.rs — three weak negative tests (field_count, init, append) now assert the builtin name appears in the error message, matching the strong-test pattern. - crates/compiler/src/typechecker/tests.rs — added test_variant_last_rejects_string (closes the missing variant.* coverage). - crates/compiler/src/typechecker/tests.rs — added test_union_value_accepted_by_variant_field_at directly exercising the Union(_) <: Variant relaxation rule. Polish: - crates/compiler/src/unification.rs — TODO note on the bidirectional symmetric arm explaining the intentional unsoundness and the path to tighten it. - crates/compiler/src/codegen/debug_info.rs — dbg_enabled() check moved before the pattern match in dbg_call_suffix (clarifies intent). - docs/design/VARIANT_OP_TYPE_SAFETY.md — status header updated to implemented (Part A and Part B). just ci is green; the deep-panic e2e check still resolves all four Seq frames to .seq:line:col.
Code Review — PR #428: Variant-op type safety + locatable runtime panicsThis PR bundles two related but distinct improvements: Part A (compile-time OverviewPart A introduces Concerns1.
|
Summary of changes: