Skip to content

D111 remainder (#2271): collecting view elements copies them; callable returned views keep their origin - #2384

Merged
ehartford merged 1 commit into
mainfrom
d111-view-collect
Oct 13, 2026
Merged

ehartford merged 1 commit into
mainfrom
d111-view-collect

Conversation

@ehartford

@ehartford ehartford commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2271's last shape: m.keys() |> map(it) |> collect[List]() and the annotated let ks: List[str] = ....

Origin erasure at callable values (the soundness half). check_callable_value_call recorded result origins only for a literal-closure callee. A call through a callable value (a field like Mapped.f, a parameter) recorded none — so Mapped.next's element originated nowhere, and a view of a dying local returned through f(k) compiled on main. The fn type's declared origin now decides (D39, the D122 principle): a result that is or holds a view originates from the callable value (its captures, through-viewed) and from every view-bearing argument — a &T argument through its pointee, an ephemeral value through its storage. Pinned by err_d111_callable_view_origin. The same elision seeds a builtin intrinsic's view-carrying result from its receiver when the resolving path recorded none (the D22 TODO at that site).

Collecting views built List[&T]. collect over an Iter[&T] implementor instantiated iter_collect at T = &T, a type no spelling can own: annotated demands mismatched and Mapped chains died in Rule 6 inside std. std gains iter_collect_views[T, I: Iter[&T]] -> List[T]; Sema dispatches a collect whose iterator element is a Copy view there (element resolved from the receiver's Iter impl exactly as bound inference does), on the user path and, undemanded too, in builtin collect target typing. A non-Copy view gets one diagnostic naming the explicit copy.

The map(it.clone()) stages in issue58/452, behav_d44_map_traversal_views, map_snapshot_cases and da_2165 are gone; behav_d111_collect_view_elements covers annotated, unannotated, return-demand and builtin-iterator shapes. Note the parser half of the issue comment did not reproduce (it was the reserved parameter name it; filed as #2382). A method-form collect ICE found alongside is #2383, pre-existing on main.

Iterate evidence: stage1 runs the new + touched fixtures (9 files) green, check src/main.w ok under the new origin rules, census --diff clean, audit:resolution clean. Gate/battery evidence follows.

…ble's returned view keeps its origin

Two defects closed the last D111 shape ( and the annotated ):

1. Origin erasure at callable values. check_callable_value_call
   recorded result origins only for a literal-closure callee (from its
   captures); a call through a callable VALUE (a field, a parameter)
   recorded none, so Mapped.next's summary said its element originated
   nowhere — and, worse, a view of a dying local returned through
    compiled. The fn type's declared origin now decides (D39):
   a result that is or holds a view originates from the callable
   value (its captures, through-viewed) and from every view-bearing
   argument (a &T argument through its pointee, an ephemeral value
   through its storage) — the D122 principle. The same elision seeds a
   builtin intrinsic's view-carrying result from its receiver when
   the resolving path recorded none (the D22 TODO at that site).

2. Collecting views built List[&T]. collect over an Iter[&T] user
   implementor instantiated iter_collect at T = &T — a type no
   spelling can own — so annotated demands mismatched and Mapped
   chains died in Rule 6 inside std. std gains iter_collect_views
   ([T, I: Iter[&T]] -> List[T]); Sema dispatches a collect whose
   iterator element is a Copy view there (element resolved from the
   receiver's Iter impl as bound inference does), on both the user
   path and, undemanded too, the builtin collect target typing.
   A non-Copy view gets one diagnostic naming the explicit copy.

The map(it.clone()) stages in issue58/452, behav_d44, map_snapshot
and da_2165 are gone. New: behav_d111_collect_view_elements (all four
shapes), err_d111_callable_view_origin (the dangling return main
accepted).
@ehartford

Copy link
Copy Markdown
Contributor Author

Gate GREEN on 6f9f74a (seed-driven src/main build :gate, 2026-10-12): d111-gate1.log: rc=0 green. Battery over this top next.

@ehartford

Copy link
Copy Markdown
Contributor Author

Battery GREEN on 6f9f74a (seed-driven, with run tools/battery.w, 2026-10-12):

6f9f74a14 /Users/eric/.local/with-staging/d111
gate rc=0 wall=150s
uat rc=0 wall=29s
battery-checks rc=0 wall=1381s
GREEN
battery: GREEN (6f9f74a14); logs in out/battery/

@ehartford
ehartford marked this pull request as ready for review October 13, 2026 07:16
@ehartford
ehartford merged commit 92abde0 into main Oct 13, 2026
@ehartford
ehartford deleted the d111-view-collect branch October 13, 2026 07:17
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.

D111 non-compliance: an owned str demand does not materialize a &str through Ok-wrap, collect, or a &&str join

1 participant