Repository navigation
Description
Summary
Premise appears stale. The current compiler already records @[iter_of_self] on user functions and impl methods, and method-call borrowing consults that marker. The remaining useful work is to add focused regression coverage proving a non-stdlib iterator constructor retains access to self.
Spec
docs/with-specification.md:5189-5199 says @[iter_of_self] is an explicit function attribute for iterator constructors that return a view over their receiver, and that any library can use it. docs/with-specification.md:5202-5207 requires two live next() results from the same iterator to be accepted while mutable access to the source collection remains forbidden. docs/with-specification.md:5209-5213 says unannotated custom constructors may use the conservative fallback.
Current state
src/Parser.w:518-520 recognizes the iter_of_self attribute. Ordinary function declarations apply the pending marker at src/Parser.w:1133-1135, and impl methods apply it at src/Parser.w:2857-2859. src/Ast.w:1229-1235 stores and queries the marked function node.
The borrow checker path is also not stdlib-only: src/SemaCheck.w:13192-13206 first checks the builtin iterator allowlist, then resolves the method function and asks ast.is_iter_of_self_fn_node(fn_node). Method calls register the retained receiver borrow at src/SemaCheck.w:10413-10419, and normal calls do the same for marked callees at src/SemaCheck.w:8071-8078.
Existing tests cover stdlib iterators: test/compile_errors/err_iter_of_self_vec_iter.w:1 and test/compile_errors/err_iter_of_self_hashmap_keys.w:1 reject mutable access while iterator views are live, and test/behavior/behav_iter_of_self_independent.w verifies independent values are not over-restricted. test/spec/spec_ss13_2_iterator_borrowing.w does not include a user-defined @[iter_of_self] constructor, so the stale premise is not guarded by a direct test.
Implementation plan
- Do not rewrite the compiler unless a new repro contradicts the current source.
- Add a non-stdlib type with an impl method annotated
@[iter_of_self]that returns a custom iterator overself. - Add one compile-error test that keeps a yielded view live and then mutates the receiver, expecting the same retained-access diagnostic as the stdlib tests.
- Add one positive test showing an unannotated owned iterator constructor remains usable without retained receiver borrowing.
Test plan
Run the new compile-error test through with build :test and confirm the failure text includes the retained-access diagnostic. Run the positive behavior/spec test to confirm user-defined iterators still iterate normally. Then run the normal full checklist required by the repository before closing.
Acceptance criteria
- A user-defined
@[iter_of_self]impl method is covered by tests. - The test fails on a build where
method_is_iter_of_self_fnignores user markers. - No stdlib-only special case is introduced.
- The issue can be closed as premise-stale if the tests pass without compiler changes.
Dependencies
None. This is a verification/regression-coverage cleanup for existing behavior.
Activity
ehartford commentedon Jun 13, 2026
Implemented in 9d4d829. User @[iter_of_self] constructors now survive impl-method parsing and AST comptime cloning, and semantic checks consult the resolved function symbol as well as builtin method names. Added a positive unannotated user iterator test and a negative user @[iter_of_self] retained-receiver conflict test. Verification passed: build, fixpoint, full test suite, and test-green.