Skip to content

#3047 Gap 2 (§11.7): IndexSpec is the spec's enum; MIR builds the specs, codegen stops laying the record out by hand - #3058

Merged
ehartford merged 1 commit into
mainfrom
indexspec-enum
Nov 7, 2026
Merged

ehartford merged 1 commit into
mainfrom
indexspec-enum

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

#3047 Gap 2: IndexSpec becomes the enum §11.7 writes, in place of the seven-field struct.

pub enum IndexSpec:
    Scalar(i64)
    Slice(Option[i64], Option[i64], Option[i64])
    Ellipsis
    NewAxis

One owner per fact (D65). Codegen used to lay the record out by hand (mir_build_multi_index_specs_ref: {i32, i64, i64, i64, i1, i1, i1} mirroring the std struct, a second declaration of one layout). Now:

  • Sema reads the &[IndexSpec] off the validated multi_index / multi_index_set signature and records, per multi-index node, the [IndexSpec; n] the specs are built into and the slice the method takes (record_multi_index_spec_types); is_index_spec_slice_ref_type accepts the enum.
  • MirLower builds each component as an IndexSpec value (lower_multi_index_specs_slice: Scalar with its bound widened to i64, Slice with Some(bound) or None per written bound, Ellipsis, NewAxis), the values into an array temp, and passes a view of it plus the count (plus the value for a set) to the MULTI_INDEX intrinsics.
  • Codegen forwards the view through the canonical reference marshalling (is_ref_param / marshal_ref_addr, as the receiver) and the hand layout is deleted (71 lines).

Fixtures. spec_ss11_7_multi_index_and_dispatch.w, behav_3047_multi_index_d140_no_import.w and behav_3047_multi_index_prelude_core.w read the specs by matching them. The D140 fixture keeps IndexSpec unnamed in the impl (that is what it tests), so its matches are inline. The spec fixture reads slice bounds through unwrap() / is_none() because start == Some(2) on a view-bound Option is miscompiled today (#3057, reproduced on main's installed compiler, filed with the repro and the icmp line).

Iterate tier: the three fixtures, behav_multi_index.w, the five err_multi_index_* fixtures and test/hello.w pass under stage1; check src/main.w clean; ceremony census diff ok.

…cs, codegen stops laying the record out by hand

`IndexSpec` is `Scalar(i64) | Slice(Option[i64], Option[i64], Option[i64]) |
Ellipsis | NewAxis` (lib/std/traits.w), as §11.7 writes it, in place of the
seven-field struct `{kind, start, stop, step, has_start, has_stop, has_step}`.

One owner per fact (D65): Sema reads the `&[IndexSpec]` off the validated
`multi_index` / `multi_index_set` signature and records, per multi-index node,
the `[IndexSpec; n]` the specs are built into and the slice the method takes
(record_multi_index_spec_types). MirLower builds each component as an
`IndexSpec` value (lower_multi_index_specs_slice: Scalar with its bound widened
to i64, Slice with `Some(bound)` / `None` per written bound, Ellipsis, NewAxis),
the values into an array temp, and passes a view of it with the count (and the
value, for a set) to the MULTI_INDEX intrinsics. Codegen forwards the view
through the canonical reference marshalling; mir_build_multi_index_specs_ref,
which laid `{i32, i64, i64, i64, i1, i1, i1}` out by hand to mirror the std
struct, is gone.

Fixtures read the specs by matching them (spec_ss11_7, behav_3047_*). The
spec fixture reads slice bounds through unwrap()/is_none(): `start == Some(2)`
on a view-bound Option is miscompiled today (#3057, reproduced on main).
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on 7c334a764 (seed-driven with run tools/battery.w): gate, with uat 13 scenarios (12 pass, 1 skip: the Windows raylib leg), battery-checks all green; :deep-debug-tool-tests and :drop-audit green.

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