Complete the semantic analysis phase (RFC-0023–0028) #20
Loading…
Reference in a new issue
No description provided.
Delete branch "sema/even-more"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Finishes the
semaphase:check()now runs the full front end, and all 31tests/fixtures/semantics/fixtures pass (22 accepted, 9 refused on their markedline). The
.known-redexemption is deleted —cargo test --allis green(332 passed, 0 failed), clippy is warning-free, and fmt is clean.
Six RFCs, each test-driven, adversarially reviewed, and committed on its own:
coerce/cast, overload ranking,is+ narrowingSpanand union-typed parametersfor..inownedflow tracking,release/delete, destruction order, cycle detection${…}string interpolation (parser + ast + sema)check(), diagnostic rendering, phase completionSpec corrections folded in (docs updated with citations)
T == U(the spec'ssum1requires it).is-on-a-union-parameter behavior requires it).owned-rebinding.catrebuilt around?*T— field access through a pointer doesn't lower (§ Pointer auto-derefs only method calls).Deferred (recorded in the manifest)
Interface conformance checking and vtable layout (RFC-0016 q6) — the next phase, which consumes the
hir.is, and overload ranking 32b681d061Record what code generation would monomorphize, and settle the two forms of implicit generic the language has. New `sema/src/generics.rs` holds `InstKey`/`Instantiations` (a deduplicating set threaded into `hir::Program`), positional `substitute`, and `infer_type_args` for call-site recovery. `lower_type` gains a `TypePosition` so a bare `Span` is an implicit generic in annotation/parameter position but collapses to `Span<size_t>` in a recorded field — including when reached through an alias (`type W = Span; struct S { w: W; }`), which otherwise left a dangling inference variable in a non-generic field. A call binds an implicit `Span` parameter from its argument and records the key; explicit and impl interface references record theirs. Follows the codebase's `Var(TypeVar(i))` representation of a type parameter rather than the RFC draft's `Named`/`ParamId`, documented in the module header as RFC-0023 documented its `&DefTable` deviation. A union-typed parameter is checked "valid for every member" at each operator, with the result the union of per-member results and an invalid member named — `input * 2` over `number` types as `u32 | s32 | u64 | s64 | f32 | f64`. This corrects the RFC's drafted reading 2 (monomorphize the body per member), which cannot coexist with RFC-0023's committed union semantics: `is` narrows a union-typed parameter in both branches, and monomorphizing it away would leave no tag to test. The RFC now records reading 1. Interface conformance stays deferred (RFC-0016 question 6). `check()` stays the stub; the fixture driver goes green at RFC-0028.The `${...}` holes inside a string literal become real expressions for the first time. The parser expands an interpolated literal into its parts and re-enters `expression` for each hole; semantics types the parts and the whole as `string`. `ast::Expr::StrLit` now carries `Vec<StrPart>` (a `Text` run or a `Hole` expression) instead of a raw `String`; a hole-free literal is one `Text` part and dumps as its raw body unchanged, so existing goldens don't churn. The parser's `expand_string` finds a hole's matching `}` by balancing braces while skipping the spans of char literals and comments (nesting block comments as the scanner does), so a `}` inside `'}'` or `// }` no longer closes a hole early; a string literal still cannot appear in a hole, the one limitation the scanner's raw-body rule leaves, now recorded as the only one. Hole spans are lifted into file coordinates so a diagnostic inside a hole points at the source, and a hole must be exactly one expression. `sema::lower_str_lit` produces `hir::ExprKind::Str` typed `string`, and RFC-0020's prelude gains the `string` type it never seeded — an opaque def, enough for `Type::Named(string, [])` to exist and for a double-quoted literal to have a type. `check()` stays the stub; RFC-0028 wires the phase.