Repository navigation
D113: brackets make a Vec; a fixed array or set is built where demanded - #2286
Merged
Merged
Conversation
A bracket literal is a Vec[T] unless the demanded type is another collection built from a list (a fixed array, HashSet, BTreeSet). A use of a let-bound literal that demands a fixed array, including through `&xs`, is a demand like a Vec or set one (D93). A duplicate string or integer constant in a literal built as a set warns. Spec change (D113, §4.3c): tests that relied on the fixed-array default now demand the array they test; the dynamic rest binding they would otherwise need is #2283.
added 2 commits
October 8, 2026 22:06
#2281 edited docs/spec/guide/with_for_ai.md and merged as docs-only, so nothing regenerated src/InitTemplates.w and cli-selfhost-project-tests (`with init` writes the guide as AGENTS.md) went red on main. Generated by tools/gen_init_templates.w.
…a temporary; every demand counts The battery on D113 found three defects that the fixed-array default had hidden: - A whole Drop local placed in a Vec or set literal was moved by MIR, but Sema never marked it moved: `let a: Vec[W] = [tmp]` then `tmp.id` read the vacated local (printed 0). Since #605 only array targets were marked, on the claim that other collections manage element ownership separately. They don't. Every target now marks the element consumed. - A VecRange (`split_at`, `split_at_mut`, `range`) views its Vec but was not ephemeral, so `mk().split_at(1)` bound two views into a Vec freed at the end of the statement. VecRange is ephemeral now, like CStr, and the existing temporary-borrow check refuses it. New test: err_vecrange_of_temporary. - D93 recorded a demand only where a use mismatched the binding's type. Under D113 a `&Vec` use already matches the default, so it went unrecorded, and two disagreeing demands became a plain mismatch at the first use. Every expected type checked against a literal's binding is now a demand, and the error names both at the second use again. Tests that relied on the fixed-array default now demand their arrays (spec change, D113): err_1367 (two files), behav_for_full_patterns, d_acceptance slice_pat_* and dump_typed_d22_contextual_joins (a sequence is a Vec now). err_split_at_index_type names `Vec.split_at`. err_split_at_mut_readonly_receiver tests a read-only `&Vec` receiver. That is the read-only case for a Vec: a `let` owner may call a `mut fn` (storage-types note: mutation through a marked operation is not rebinding).
This was referenced Oct 9, 2026
Contributor
Author
|
Battery GREEN on f329092 (stack top: #2280, #2284, #2285, #2286), The first battery, on 859e562, was red. It found three defects the fixed-array default had hidden, plus a red main, all fixed in f329092 and f57ba3c:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements D113 (§4.3c rule 1).
Vec[T]; this includes[v; N]and a literal passed straight to a&Vecparameter. A slice demand views the Vec.&xsat a&[T; N]parameter.Spec change, so tests follow it: behav_1367, behav_1389, behav_slice_pattern_rest_binding, slice_pat_both, slice_pat_head_rest and slice_pat_exhaustive tested fixed-array patterns on undemanded literals. They now demand the array (
[i32; N]). Without that they would need a rest binding on a Vec, which was never implemented; that is filed as #2283, with the spec's count-versus-view contradiction. behav_d93's comments are updated, and its set literal no longer carries a duplicate.New tests: behav_d113_brackets_make_a_vec and behav_d113_set_duplicate_warns both fail on the base compiler. behav_d113_collection_by_demand guards demand.
Scan: every test, lib, tools and examples file that has a bracket literal (599 files) was checked with this compiler and with the base stage1. No file regresses. No example needed a change.
Not done here: the optional storage optimization (stack or static data for a literal that is never grown or retained). The spec allows it but does not require it.
Battery fixes in this PR (f329092): a Vec or set literal consumes a Drop local placed in it (the use-after-move went undiagnosed before); VecRange is ephemeral, so a VecRange from a temporary Vec is refused (err_vecrange_of_temporary); every demand on a literal's binding is recorded, so two that disagree are again an error at the second use. f57ba3c regenerates src/InitTemplates.w, which #2281 left stale.