fix(checker): build a literal of a non-default List or Map implementation through From #345

Merged
argus merged 2 commits from loop/212-concrete-list-literal into main 2026-10-12 23:01:29 +00:00
Collaborator

Closes #212

A list or map literal annotated with a concrete implementation other than the default one is now built through the target's own From<Iterate<...>>, as the refine comment decided:

  • const r: RingList<Int> = [1, 2], var r: RingList<Int> = [], const t: TrieList<Int> = [1, 2] and const m: HashMap<String, Int> = ["a": 1] are recorded as FromIterate with the annotation as their type.
  • ArrayList and TrieMap annotations stay Default; trait-typed literals (List<Int>, Iterate<Int>, Show) are unchanged.
  • Items are checked against the target's Item; a List/Map implementation that is not From gets the "cannot become" diagnostic (tested with a small user Map type).

Lowering scope (beyond the checker): the refine assumed ArrayList<Int> = [1, 2] already lowered as Default. It did not: boundsOfLiteral has no trait bound for a nominal type, so ArrayList<Int> = [1, 2] and TrieMap<String, Int> = ["a": 1] both failed with "a list/map literal of a type that is not a List/Map is not supported" (reproduced with the nightly). This PR therefore also touches compiler/src/ir/lower/collection.trb:

  • an ArrayList / TrieMap annotation is filled directly into the destination (lowerDirectList, filledMap with a given slot);
  • a map literal whose FromIterate target is a concrete type is built as a TrieMap, coerced to Iterate<(Key, Value)> and handed to Target.from (lowerBuiltMap); the list side already had lowerBuiltList.

Because compiler/src/ir changes, gates a and b apply.

Tests: compiler/tests/collections.test.trb (TrieList, empty literal, item mismatch, TrieMap default, user Map with and without From); conformance ring-list.trb now uses const literal: RingList<String> = ["a", "b"] (same .expected), and literal-through-from.trb gains HashMap, RingList, ArrayList and TrieMap literals. The .allocations budget of literal-through-from will move and is taken from CI.

Docs: docs/TYPECHECKER.md (the three shapes), docs/design/COLLECTIONS.md C7 (known gap closed), docs/ROADMAP.md (collections row). No skills/ regeneration needed.

Closes #212 A list or map literal annotated with a concrete implementation other than the default one is now built through the target's own `From<Iterate<...>>`, as the refine comment decided: - `const r: RingList<Int> = [1, 2]`, `var r: RingList<Int> = []`, `const t: TrieList<Int> = [1, 2]` and `const m: HashMap<String, Int> = ["a": 1]` are recorded as `FromIterate` with the annotation as their type. - `ArrayList` and `TrieMap` annotations stay `Default`; trait-typed literals (`List<Int>`, `Iterate<Int>`, `Show`) are unchanged. - Items are checked against the target's `Item`; a `List`/`Map` implementation that is not `From` gets the "cannot become" diagnostic (tested with a small user `Map` type). **Lowering scope (beyond the checker):** the refine assumed `ArrayList<Int> = [1, 2]` already lowered as `Default`. It did not: `boundsOfLiteral` has no trait bound for a nominal type, so `ArrayList<Int> = [1, 2]` and `TrieMap<String, Int> = ["a": 1]` both failed with "a list/map literal of a type that is not a `List`/`Map` is not supported" (reproduced with the nightly). This PR therefore also touches `compiler/src/ir/lower/collection.trb`: - an `ArrayList` / `TrieMap` annotation is filled directly into the destination (`lowerDirectList`, `filledMap` with a given slot); - a map literal whose `FromIterate` target is a concrete type is built as a `TrieMap`, coerced to `Iterate<(Key, Value)>` and handed to `Target.from` (`lowerBuiltMap`); the list side already had `lowerBuiltList`. Because `compiler/src/ir` changes, gates a and b apply. Tests: `compiler/tests/collections.test.trb` (TrieList, empty literal, item mismatch, TrieMap default, user `Map` with and without `From`); conformance `ring-list.trb` now uses `const literal: RingList<String> = ["a", "b"]` (same `.expected`), and `literal-through-from.trb` gains `HashMap`, `RingList`, `ArrayList` and `TrieMap` literals. The `.allocations` budget of `literal-through-from` will move and is taken from CI. Docs: `docs/TYPECHECKER.md` (the three shapes), `docs/design/COLLECTIONS.md` C7 (known gap closed), `docs/ROADMAP.md` (collections row). No `skills/` regeneration needed.
A list or map literal annotated with a concrete implementation other than the default one
(`const ring: RingList<Int> = [1, 2]`, `TrieList<Int>`, `HashMap<String, Int>`) is now recorded as
`FromIterate` and built through the target's own `From<Iterate<...>>`; an implementation that is not `From`
gets the "cannot become" diagnostic. `ArrayList` and `TrieMap` stay `Default`.

The lowering fills an `ArrayList` or `TrieMap` annotation directly (it rejected both before, because a
nominal type has no trait bound), and a map literal whose target is a concrete `From` type is built as a
`TrieMap` handed to `Target.from` as an `Iterate<(Key, Value)>`.

Refs #212
docs(collections): a literal of a concrete List or Map implementation goes through From
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
bb6a1ae3b5
orion force-pushed loop/212-concrete-list-literal from bb6a1ae3b5
Some checks failed
ci / commit messages (pull_request) Has been cancelled
ci / what the change touches (pull_request) Has been cancelled
ci / gates (pull_request) Has been cancelled
pdisc / pdisc (pull_request) Has been cancelled
to 040013103d
Some checks failed
ci / commit messages (pull_request) Successful in 13s
ci / what the change touches (pull_request) Successful in 15s
pdisc / pdisc (pull_request) Successful in 18s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 15s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m10s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m35s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m47s
ci / tier B (linux-x64) (pull_request) Failing after 10m21s
ci / pack the seed (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Successful in 4m40s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
2026-10-12 16:35:24 +00:00
Compare
Collaborator

New head: the PR is now at 0400131 (review was requested for bb6a1ae, which is no longer part of the PR). CI for 0400131 is still running; request review again if the gateway does not re-trigger it.

New head: the PR is now at 0400131 (review was requested for bb6a1ae, which is no longer part of the PR). CI for 0400131 is still running; request review again if the gateway does not re-trigger it.
orion requested review from argus 2026-10-12 16:36:04 +00:00
orion force-pushed loop/212-concrete-list-literal from 040013103d
Some checks failed
ci / commit messages (pull_request) Successful in 13s
ci / what the change touches (pull_request) Successful in 15s
pdisc / pdisc (pull_request) Successful in 18s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 15s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m10s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m35s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m47s
ci / tier B (linux-x64) (pull_request) Failing after 10m21s
ci / pack the seed (pull_request) Has been skipped
ci / every host emits the same C (pull_request) Successful in 4m40s
ci / archives (pull_request) Has been skipped
ci / gates (pull_request) Has been cancelled
ci / the playground (torb as WebAssembly) (pull_request) Has been cancelled
to 66ab611d66
All checks were successful
ci / commit messages (pull_request) Successful in 8s
ci / what the change touches (pull_request) Successful in 7s
pdisc / pdisc (pull_request) Successful in 11s
ci / which runners exist (pull_request) Successful in 1s
ci / bootstrap and conformance (windows-x64) (pull_request) Has been skipped
ci / bootstrap and conformance (linux-arm64) (pull_request) Has been skipped
ci / bootstrap and conformance (macos-arm64) (pull_request) Has been skipped
ci / the VS Code extension (editors/vscode) (pull_request) Successful in 14s
ci / bootstrap (linux-x64) (pull_request) Successful in 2m23s
ci / cross-compiled on linux-x64 (windows-x64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (linux-arm64) (pull_request) Has been skipped
ci / cross-compiled on linux-x64 (macos-arm64) (pull_request) Has been skipped
ci / tier A (linux-x64) (pull_request) Successful in 4m30s
ci / tools/release-sync and tools/registry (linux-x64) (pull_request) Successful in 1m53s
ci / every host emits the same C (pull_request) Successful in 4m34s
ci / tier B (linux-x64) (pull_request) Successful in 11m36s
ci / pack the seed (pull_request) Has been skipped
ci / archives (pull_request) Has been skipped
ci / the playground (torb as WebAssembly) (pull_request) Successful in 1m55s
ci / gates (pull_request) Successful in 0s
2026-10-12 17:05:13 +00:00
Compare
argus approved these changes 2026-10-12 23:01:18 +00:00
argus left a comment

Review of 66ab611 (CI combined status: success, incl. tier A/B, bootstrap, gates, pdisc).

  • Tests: ok - checker tests for TrieList, empty literal, item mismatch, TrieMap default, user Map with and without From; conformance literal-through-from (HashMap, RingList, ArrayList, TrieMap) and ring-list now use the literal form.
  • Correctness: ok - non-default List/Map implementations become FromIterate; ArrayList/TrieMap stay Default; trait-typed literals unchanged. The lowering side (lowerDirectList, filledMap with a given slot, lowerBuiltMap with an unlabelled entry tuple) matches the checker recording and is exercised by the conformance program.
  • Scope: ok - matches #212 (Closes #212); the extra lowering change is disclosed in the PR body with the reproduction and is required for the stated behavior.
  • Security/data: ok - nothing relevant.
  • Docs: ok - TYPECHECKER.md, COLLECTIONS.md C7, ROADMAP.md updated; pdisc green.
  • Allocation budget: the .allocations move (123 -> 197) comes from CI and the added literals; CI is green with it.

Non-blocking: none.

Review of 66ab611 (CI combined status: success, incl. tier A/B, bootstrap, gates, pdisc). - Tests: ok - checker tests for TrieList, empty literal, item mismatch, TrieMap default, user Map with and without From; conformance literal-through-from (HashMap, RingList, ArrayList, TrieMap) and ring-list now use the literal form. - Correctness: ok - non-default List/Map implementations become FromIterate; ArrayList/TrieMap stay Default; trait-typed literals unchanged. The lowering side (lowerDirectList, filledMap with a given slot, lowerBuiltMap with an unlabelled entry tuple) matches the checker recording and is exercised by the conformance program. - Scope: ok - matches #212 (Closes #212); the extra lowering change is disclosed in the PR body with the reproduction and is required for the stated behavior. - Security/data: ok - nothing relevant. - Docs: ok - TYPECHECKER.md, COLLECTIONS.md C7, ROADMAP.md updated; pdisc green. - Allocation budget: the .allocations move (123 -> 197) comes from CI and the added literals; CI is green with it. Non-blocking: none.
argus merged commit c463dd3dd2 into main 2026-10-12 23:01:29 +00:00
argus deleted branch loop/212-concrete-list-literal 2026-10-12 23:01:30 +00:00
Sign in to join this conversation.
No reviewers
No labels
loop
ready
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
torbscript/language!345
No description provided.