Skip to content

Seq iteration#15

Merged
Turupawn merged 43 commits intoTurupawn:seq-array-loopsfrom
micahscopes:seq-iteration
Jan 20, 2026
Merged

Seq iteration#15
Turupawn merged 43 commits intoTurupawn:seq-array-loopsfrom
micahscopes:seq-iteration

Conversation

@Turupawn
Copy link
Owner

No description provided.

sbillig and others added 30 commits January 2, 2026 21:25
  Fix name collisions in symbol generation
move contract desugaring into mir, effect type cleanup
Update check_for to resolve element types via Seq<T> trait lookup
rather than the placeholder Iterator reference. Arrays remain special
cased since const generics in array type positions aren't fully
supported yet.
Range expressions (a..b) now type check to DynRange. Both
operands are verified to be usize, and the result is resolved
from core::range::DynRange.
Desugar range expressions `start..end` in MIR lowering to allocate
and initialize a DynRange struct with start and end fields, rather
than leaving them as Range binops that panic at codegen.
Desugar for-loops into while loops:

- For ranges (DynRange): initialize loop var to start, loop while < end
- For arrays: create hidden index, bind element each iteration

Both cases increment by 1 and use standard loop control flow with
proper continue/break targets registered.
Remove the bifurcated Const<N>/Dyn type system in favor of a simple
approach that matches issue argotorg#1207:

- Remove Const<N> and Dyn marker types from seq.fe
- Remove Range<N> (const-length), keep only Range with start/end
- Simplify Seq trait to return usize directly (no Len associated type)
- Update type checker and MIR comments from DynRange to Range

This defers const-vs-dynamic optimization to the backend rather than
encoding it in the type system, reducing complexity significantly.
Previously, `impl<const N: usize> Trait for [T; N]` failed because the
target type was lowered before entering the impl scope, so const generic
params weren't available for array length expressions.

Fix by entering the impl scope with a preliminary ID first, lowering
generic params, then lowering the target type. The final ID is swapped
in before lowering nested items like methods.

This enables the array Seq implementation in core library.
Resolve Seq::len and Seq::get at type-check time and store in
ForLoopSeq for MIR lowering. Desugars `for x in seq` to an
index-based while loop calling the resolved trait methods.

- snapshot/rollback when probing Seq impls to prevent inference pollution
- route `continue` to increment block to avoid infinite loops
- preserve effect args on synthesized Seq method calls
- Prevent unification-table panics when resolving associated types via impls

- Constrain record init generics from expected type without inference pollution

- Add uitests for assoc-type struct fields and for-loop over array literal
Replace the simple Range struct with a generic Range<S: Bound, E: Bound>
that encodes bound constness in the type system:

- Range<Known<0>, Known<10>> for fully const ranges (0 words)
- Range<Known<0>, Unknown> for const start, runtime end (1 word)
- Range<Unknown, Unknown> for fully dynamic ranges (2 words)

The type checker now detects integer literals in range expressions
and constructs the appropriate Range type, enabling zero-cost
abstractions when bounds are compile-time known.
@Turupawn Turupawn merged commit 1919236 into Turupawn:seq-array-loops Jan 20, 2026
4 checks passed
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.

4 participants