@shd101wyy/yo 0.1.33 → 0.1.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/.github/skills/yo-core-patterns/SKILL.md +1 -1
  2. package/.github/skills/yo-core-patterns/core-patterns-cheatsheet.md +51 -21
  3. package/.github/skills/yo-syntax/SKILL.md +1 -1
  4. package/.github/skills/yo-syntax/syntax-cheatsheet.md +56 -67
  5. package/out/cjs/index.cjs +670 -655
  6. package/out/cjs/yo-cli.cjs +744 -729
  7. package/out/cjs/yo-lsp.cjs +687 -672
  8. package/out/esm/index.mjs +492 -477
  9. package/out/types/src/codegen/exprs/comptime-value.d.ts +2 -1
  10. package/out/types/src/codegen/types/generation.d.ts +1 -1
  11. package/out/types/src/codegen/utils/index.d.ts +2 -4
  12. package/out/types/src/evaluator/exprs/_expr.d.ts +1 -0
  13. package/out/types/src/evaluator/types/flowability.d.ts +21 -0
  14. package/out/types/src/expr.d.ts +5 -13
  15. package/out/types/src/types/creators.d.ts +2 -3
  16. package/out/types/src/types/definitions.d.ts +2 -3
  17. package/out/types/src/types/guards.d.ts +2 -2
  18. package/out/types/src/types/tags.d.ts +2 -2
  19. package/out/types/src/value-tag.d.ts +0 -1
  20. package/out/types/src/value.d.ts +2 -11
  21. package/out/types/tsconfig.tsbuildinfo +1 -1
  22. package/package.json +1 -1
  23. package/std/alg/hash.yo +5 -3
  24. package/std/build.yo +46 -46
  25. package/std/collections/array_list.yo +73 -66
  26. package/std/collections/hash_map.yo +2 -81
  27. package/std/collections/list_view.yo +77 -0
  28. package/std/crypto/random.yo +5 -5
  29. package/std/encoding/base64.yo +12 -13
  30. package/std/encoding/hex.yo +6 -6
  31. package/std/encoding/json.yo +6 -5
  32. package/std/encoding/utf16.yo +9 -9
  33. package/std/env.yo +8 -8
  34. package/std/fmt/to_string.yo +12 -12
  35. package/std/http/client.yo +1 -1
  36. package/std/imm/list.yo +4 -3
  37. package/std/imm/map.yo +3 -2
  38. package/std/imm/set.yo +4 -3
  39. package/std/imm/sorted_map.yo +3 -2
  40. package/std/imm/sorted_set.yo +4 -3
  41. package/std/imm/string.yo +12 -5
  42. package/std/imm/vec.yo +8 -3
  43. package/std/prelude.yo +175 -401
  44. package/std/string/string.yo +198 -71
  45. package/std/url/index.yo +26 -26
  46. package/out/types/src/evaluator/types/slice.d.ts +0 -8
package/std/prelude.yo CHANGED
@@ -12,7 +12,7 @@
12
12
  // `Comptime` and `Runtime` are defined first because every other
13
13
  // type (including `Pragma` below) is type-checked against them.
14
14
  /// Comptime trait — indicates a type that can be used at compile-time.
15
- /// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `comptime_string`.
15
+ /// Examples: `i32`, `bool`, `Type`, `comptime_int`, `comptime_float`, `comptime_str`.
16
16
  /// Non-examples: `int`, `ushort` (runtime-only types).
17
17
  Comptime :: trait(
18
18
  id := "Comptime"
@@ -20,7 +20,7 @@ Comptime :: trait(
20
20
  export(Comptime);
21
21
  /// Runtime trait — indicates a type that can be used at runtime.
22
22
  /// Examples: `i32`, `bool`, `*(i32)`, `void`.
23
- /// Non-examples: `comptime_int`, `comptime_float`, `comptime_string`, `Type` (compile-time-only types).
23
+ /// Non-examples: `comptime_int`, `comptime_float`, `comptime_str`, `Type` (compile-time-only types).
24
24
  Runtime :: trait(
25
25
  id := "Runtime"
26
26
  );
@@ -83,6 +83,7 @@ extern(
83
83
  "Yo",
84
84
  __yo_return_self : (fn(forall(T : Type), self : T) -> T),
85
85
  __yo_noop : (fn(forall(T : Type)) -> T),
86
+ __yo_borrow_assert_unborrowed : (fn(forall(T : Type), obj : T) -> unit),
86
87
  __yo_as : (fn(forall(_Self : Type), self : _Self, comptime(Target) : Type) -> Target),
87
88
  // Arithmetic Operators
88
89
  /// +
@@ -145,27 +146,27 @@ extern(
145
146
  fn(forall(T : Type), ptr1 : T, ptr2 : T) -> bool,
146
147
  __yo_ptr_gte :
147
148
  fn(forall(T : Type), ptr1 : T, ptr2 : T) -> bool,
148
- // slice related
149
- __yo_slice_len :
150
- fn(forall(T : Type), slice : Slice(T)) -> usize,
151
- __yo_slice_new :
152
- fn(forall(T : Type), ptr : *(T), length : usize) -> Slice(T),
153
- __yo_slice_ptr :
154
- fn(forall(T : Type), slice : Slice(T)) -> *(T),
155
- // array/slice indexing builtins (used by Index trait impls)
149
+ // str (builtin static string view) intrinsics
150
+ __yo_str_from_raw_parts :
151
+ fn(ptr : *(u8), length : usize) -> str,
152
+ __yo_str_len :
153
+ fn(s : str) -> usize,
154
+ __yo_str_ptr :
155
+ fn(s : str) -> *(u8),
156
+ __yo_str_byte :
157
+ fn(s : str, idx : usize) -> u8,
158
+ // array indexing builtin (used by Index trait impls)
156
159
  __yo_array_index :
157
160
  fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : usize) -> *(T),
158
- __yo_slice_index :
159
- fn(forall(T : Type), self : *(Slice(T)), idx : usize) -> *(T),
160
161
  // C macro related
161
- __yo_c_macro_defined : (fn(comptime(name) : comptime_string) -> comptime(bool)),
162
- __yo_c_macro_value : (fn(comptime(name) : comptime_string) -> comptime(comptime_string)),
162
+ __yo_c_macro_defined : (fn(comptime(name) : comptime_str) -> comptime(bool)),
163
+ __yo_c_macro_value : (fn(comptime(name) : comptime_str) -> comptime(comptime_str)),
163
164
  // Process related functions
164
- __yo_process_platform : (fn() -> comptime(comptime_string)),
165
- __yo_process_arch : (fn() -> comptime(comptime_string)),
166
- __yo_process_cwd : (fn() -> comptime(comptime_string)),
167
- __yo_process_env_get : (fn(comptime(key) : comptime_string) -> comptime(comptime_string)),
168
- __yo_process_node_version : (fn() -> comptime(comptime_string))
165
+ __yo_process_platform : (fn() -> comptime(comptime_str)),
166
+ __yo_process_arch : (fn() -> comptime(comptime_str)),
167
+ __yo_process_cwd : (fn() -> comptime(comptime_str)),
168
+ __yo_process_env_get : (fn(comptime(key) : comptime_str) -> comptime(comptime_str)),
169
+ __yo_process_node_version : (fn() -> comptime(comptime_str))
169
170
  );
170
171
  export(__yo_as);
171
172
  /// The `unsafe` module — provides low-level unwind hatches.
@@ -181,7 +182,7 @@ export(unsafe);
181
182
  // c_macro :: impl {
182
183
  // /// Check if a C macro is defined
183
184
  // /// Returns true if the macro exists, false otherwise
184
- // defined :: (fn(comptime(name) : comptime_string) -> comptime(bool))(
185
+ // defined :: (fn(comptime(name) : comptime_str) -> comptime(bool))(
185
186
  // __yo_c_macro_defined(name)
186
187
  // );
187
188
  // export defined;
@@ -189,13 +190,13 @@ export(unsafe);
189
190
  // /// Get the value of a C macro as a compile-time string
190
191
  // /// Returns the macro's value as a string, or empty string "" if not defined
191
192
  // /// Note: For function-like macros, returns the definition without expansion
192
- // value :: (fn(comptime(name) : comptime_string) -> comptime(comptime_string))(
193
+ // value :: (fn(comptime(name) : comptime_str) -> comptime(comptime_str))(
193
194
  // __yo_c_macro_value(name)
194
195
  // );
195
196
  // export value;
196
197
  //
197
198
  // /// Get a macro value with a default fallback
198
- // value_or :: (fn(comptime(name) : comptime_string, comptime(default_val) : comptime_string) -> comptime(comptime_string))(
199
+ // value_or :: (fn(comptime(name) : comptime_str, comptime(default_val) : comptime_str) -> comptime(comptime_str))(
199
200
  // cond(
200
201
  // defined(name) => value(name),
201
202
  // true => default_val
@@ -239,21 +240,6 @@ Index :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
239
240
  )
240
241
  );
241
242
  export(Index);
242
- /// Indexable trait — projection-style indexing yielding a borrow.
243
- /// Companion to `Index`, but instead of returning a raw `*(T)` the
244
- /// `project` method returns a `ref(Element)` — a second-class
245
- /// reference that flows through Yo's flowability rule (R1–R4) and
246
- /// can be received by a `ref(name) := coll.project(pos);` local
247
- /// binding. The for-loop macro lowers iteration through this trait
248
- /// so user code never sees a raw pointer. See
249
- /// plans/ITERATOR_REDESIGN.md.
250
- Indexable :: (fn(comptime(Idx) : Type) -> comptime(Trait))(
251
- trait(
252
- Element : Type,
253
- project : (fn(ref(self) : Self, pos : Idx) -> ref(Self.Element))
254
- )
255
- );
256
- export(Indexable);
257
243
  /// ComptimeIndex — compile-time indexing trait for constant expressions.
258
244
  ComptimeIndex :: (fn(comptime(Idx) : Type, where(Idx <: Comptime)) -> comptime(Trait))(
259
245
  trait(
@@ -283,39 +269,17 @@ RangeInclusiveOp :: trait(
283
269
  (..=) : (fn(start : Self, end : Self) -> RangeInclusive(Self))
284
270
  );
285
271
  export(RangeInclusiveOp);
286
- // array/slice range indexing builtins (declared after Range/RangeInclusive types)
287
- extern(
288
- "Yo",
289
- __yo_array_index_range :
290
- fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : Range(usize)) -> *(Slice(T)),
291
- __yo_array_index_range_inclusive :
292
- fn(forall(T : Type, N : usize), self : *(Array(T, N)), idx : RangeInclusive(usize)) -> *(Slice(T)),
293
- __yo_slice_index_range :
294
- fn(forall(T : Type), self : *(Slice(T)), idx : Range(usize)) -> *(Slice(T)),
295
- __yo_slice_index_range_inclusive :
296
- fn(forall(T : Type), self : *(Slice(T)), idx : RangeInclusive(usize)) -> *(Slice(T))
297
- );
298
272
  // comptime array/slice/string indexing builtins (used by ComptimeIndex trait impls)
299
273
  extern(
300
274
  "Yo",
301
275
  __yo_comptime_array_index :
302
276
  (fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
303
- __yo_comptime_slice_index :
304
- (fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
305
- __yo_comptime_array_index_range :
306
- (fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : Range(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
307
- __yo_comptime_array_index_range_inclusive :
308
- (fn(forall(T : Type, N : usize), comptime(self) : *(Array(T, N)), comptime(idx) : RangeInclusive(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
309
- __yo_comptime_slice_index_range :
310
- (fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : Range(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
311
- __yo_comptime_slice_index_range_inclusive :
312
- (fn(forall(T : Type), comptime(self) : *(Slice(T)), comptime(idx) : RangeInclusive(usize), where(T <: Comptime)) -> comptime(*(Slice(T)))),
313
277
  __yo_comptime_string_index :
314
- (fn(comptime(self) : comptime_string, comptime(idx) : comptime_int) -> comptime(comptime_string)),
278
+ (fn(comptime(self) : comptime_str, comptime(idx) : comptime_int) -> comptime(comptime_str)),
315
279
  __yo_comptime_string_index_range :
316
- (fn(comptime(self) : comptime_string, comptime(idx) : Range(comptime_int)) -> comptime(comptime_string)),
280
+ (fn(comptime(self) : comptime_str, comptime(idx) : Range(comptime_int)) -> comptime(comptime_str)),
317
281
  __yo_comptime_string_index_range_inclusive :
318
- (fn(comptime(self) : comptime_string, comptime(idx) : RangeInclusive(comptime_int)) -> comptime(comptime_string)),
282
+ (fn(comptime(self) : comptime_str, comptime(idx) : RangeInclusive(comptime_int)) -> comptime(comptime_str)),
319
283
  __yo_comptime_list_index :
320
284
  (fn(forall(T : Type), comptime(self) : *(ComptimeList(T)), comptime(idx) : usize, where(T <: Comptime)) -> comptime(*(T))),
321
285
  __yo_comptime_list_index_range :
@@ -739,11 +703,11 @@ Isolation :: trait(
739
703
  export(Isolation);
740
704
  /// ComptimeToString trait — compile-time string conversion.
741
705
  ComptimeToString :: trait(
742
- to_comptime_string : (fn(comptime(self) : Self) -> comptime(comptime_string)),
706
+ to_comptime_string : (fn(comptime(self) : Self) -> comptime(comptime_str)),
743
707
  where(Self <: Comptime)
744
708
  );
745
709
  // SAFETY: All builtin primitive types (unit, void, comptime_int,
746
- // comptime_float, comptime_string, bool, i8/i16/i32/i64, u8/u16/u32/u64,
710
+ // comptime_float, comptime_str, bool, i8/i16/i32/i64, u8/u16/u32/u64,
747
711
  // f32/f64, isize/usize, char/int/uint/short/ushort/long/ulong/longlong/
748
712
  // ulonglong/longdouble) are plain value types with no heap allocations
749
713
  // or thread-local state. They are trivially safe to send across threads
@@ -974,13 +938,13 @@ impl(
974
938
  );
975
939
  _comptime_float :: comptime_float;
976
940
  export(comptime_float : _comptime_float);
977
- /// comptime_string
978
- impl(comptime_string, Acyclic());
979
- impl(comptime_string, Comptime());
941
+ /// comptime_str
942
+ impl(comptime_str, Acyclic());
943
+ impl(comptime_str, Comptime());
980
944
  impl(
981
- comptime_string,
982
- ComptimeAdd(comptime_string)(
983
- Output : comptime_string,
945
+ comptime_str,
946
+ ComptimeAdd(comptime_str)(
947
+ Output : comptime_str,
984
948
  (+) : (
985
949
  (lhs, rhs) ->
986
950
  __yo_comptime_string_concat(lhs, rhs)
@@ -988,8 +952,8 @@ impl(
988
952
  )
989
953
  );
990
954
  impl(
991
- comptime_string,
992
- ComptimeEq(comptime_string)(
955
+ comptime_str,
956
+ ComptimeEq(comptime_str)(
993
957
  (==) : (
994
958
  (lhs, rhs) ->
995
959
  __yo_comptime_string_eq(lhs, rhs)
@@ -1001,8 +965,8 @@ impl(
1001
965
  )
1002
966
  );
1003
967
  impl(
1004
- comptime_string,
1005
- ComptimeOrd(comptime_string)(
968
+ comptime_str,
969
+ ComptimeOrd(comptime_str)(
1006
970
  (<) : (
1007
971
  (lhs, rhs) ->
1008
972
  __yo_comptime_string_lt(lhs, rhs)
@@ -1022,25 +986,25 @@ impl(
1022
986
  )
1023
987
  );
1024
988
  impl(
1025
- comptime_string,
1026
- len : (fn(comptime(self) : comptime_string) -> comptime(comptime_int))(
989
+ comptime_str,
990
+ len : (fn(comptime(self) : comptime_str) -> comptime(comptime_int))(
1027
991
  __yo_comptime_string_length(self)
1028
992
  ),
1029
- (to_upper) : (fn(comptime(self) : comptime_string) -> comptime(comptime_string))(
993
+ (to_upper) : (fn(comptime(self) : comptime_str) -> comptime(comptime_str))(
1030
994
  __yo_comptime_string_to_upper(self)
1031
995
  ),
1032
- (to_lower) : (fn(comptime(self) : comptime_string) -> comptime(comptime_string))(
996
+ (to_lower) : (fn(comptime(self) : comptime_str) -> comptime(comptime_str))(
1033
997
  __yo_comptime_string_to_lower(self)
1034
998
  ),
1035
- slice : (fn(comptime(self) : comptime_string, comptime(start) : comptime_int, comptime(end) : comptime_int) -> comptime(comptime_string))(
999
+ slice : (fn(comptime(self) : comptime_str, comptime(start) : comptime_int, comptime(end) : comptime_int) -> comptime(comptime_str))(
1036
1000
  __yo_comptime_string_slice(self, start, end)
1037
1001
  ),
1038
- to_expr : (fn(comptime(self) : comptime_string) -> comptime(Expr))(
1002
+ to_expr : (fn(comptime(self) : comptime_str) -> comptime(Expr))(
1039
1003
  __yo_comptime_string_to_expr(self)
1040
1004
  )
1041
1005
  );
1042
- _comptime_string :: comptime_string;
1043
- export(comptime_string : _comptime_string);
1006
+ _comptime_string :: comptime_str;
1007
+ export(comptime_str : _comptime_string);
1044
1008
  /// bool
1045
1009
  impl(bool, Send());
1046
1010
  impl(bool, Acyclic());
@@ -5605,119 +5569,19 @@ impl(
5605
5569
  )
5606
5570
  )
5607
5571
  );
5608
- impl(
5609
- forall(T : Type, N : usize),
5610
- Array(T, N),
5611
- Index(Range(usize))(
5612
- Output : Slice(T),
5613
- index : (fn(ref(self) : Self, idx : Range(usize)) -> *(Self.Output))(
5614
- __yo_array_index_range(&(self), idx)
5615
- )
5616
- )
5617
- );
5618
- impl(
5619
- forall(T : Type, N : usize),
5620
- Array(T, N),
5621
- Index(RangeInclusive(usize))(
5622
- Output : Slice(T),
5623
- index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
5624
- __yo_array_index_range_inclusive(&(self), idx)
5625
- )
5626
- )
5572
+ /// RawSlice — a plain ptr+len pair for PRIVILEGED (pragma'd) code: C
5573
+ /// interop and std internals. Carries a raw pointer, so the existing
5574
+ /// raw-pointer gates apply: safe code cannot name or construct it.
5575
+ /// Replaces the builtin Slice(T) for internal plumbing
5576
+ /// (plans/SLICE_REWORK.md step 4).
5577
+ RawSlice :: (fn(comptime(T) : Type) -> comptime(Type))(
5578
+ struct(ptr : *(T), len : usize)
5627
5579
  );
5628
- /// Array Indexable impl — projection-style indexing yielding `ref(T)`.
5629
- /// Body takes `&(self)` so `__yo_array_index`'s `self : *(Array(T, N))`
5630
- /// parameter is satisfied — the `ref(self) : Self` binding gives the
5631
- /// body a value-typed view of `self` even though the C ABI passes a
5632
- /// pointer. The `unsafe` wrap is the trusted escape from the
5633
- /// flowability rule (privileged code only). See plans/ITERATOR_REDESIGN.md.
5634
- impl(
5635
- forall(T : Type, N : usize),
5636
- Array(T, N),
5637
- Indexable(usize)(
5638
- Element : T,
5639
- project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
5640
- cond(
5641
- (pos >= N) => panic("Array: project out of bounds"),
5642
- true => unsafe(__yo_array_index(&(self), pos))
5643
- )
5644
- )
5645
- )
5646
- );
5647
- /// Slice
5648
- // SAFETY: Slice(T) is a value-typed view (pointer + length) over a backing
5580
+ export(RawSlice);
5649
5581
  // array. Sending a slice across threads copies the header; both threads
5650
5582
  // can independently read the backing array. The backing array's lifetime
5651
5583
  // is managed by its owning collection (which must itself be Send to cross
5652
5584
  // threads). Slice is always Acyclic — it is a value type with no ARC.
5653
- impl(forall(T : Type), where(T <: Send), Slice(T), Send());
5654
- impl(forall(T : Type), Slice(T), Acyclic());
5655
- impl(forall(T : Type), where(T <: Comptime), Slice(T), Comptime());
5656
- impl(forall(T : Type), where(T <: Runtime), Slice(T), Runtime());
5657
- impl(forall(T : Type), Range(T), Acyclic());
5658
- impl(forall(T : Type), where(T <: Comptime), Range(T), Comptime());
5659
- impl(forall(T : Type), where(T <: Runtime), Range(T), Runtime());
5660
- impl(forall(T : Type), RangeInclusive(T), Acyclic());
5661
- impl(forall(T : Type), where(T <: Comptime), RangeInclusive(T), Comptime());
5662
- impl(forall(T : Type), where(T <: Runtime), RangeInclusive(T), Runtime());
5663
- impl(
5664
- forall(T : Type),
5665
- Slice(T),
5666
- from_raw_parts : (fn(ptr : *(T), length : usize) -> Self)(
5667
- __yo_slice_new(ptr, length)
5668
- ),
5669
- len : (fn(self : Self) -> usize)(
5670
- __yo_slice_len(self)
5671
- ),
5672
- ptr : (fn(self : Self) -> *(T))(
5673
- __yo_slice_ptr(self)
5674
- )
5675
- );
5676
- /// Slice Index impls (same `&(self)` rationale as Array above).
5677
- impl(
5678
- forall(T : Type),
5679
- Slice(T),
5680
- Index(usize)(
5681
- Output : T,
5682
- index : (fn(ref(self) : Self, idx : usize) -> *(Self.Output))(
5683
- __yo_slice_index(&(self), idx)
5684
- )
5685
- )
5686
- );
5687
- impl(
5688
- forall(T : Type),
5689
- Slice(T),
5690
- Index(Range(usize))(
5691
- Output : Slice(T),
5692
- index : (fn(ref(self) : Self, idx : Range(usize)) -> *(Self.Output))(
5693
- __yo_slice_index_range(&(self), idx)
5694
- )
5695
- )
5696
- );
5697
- impl(
5698
- forall(T : Type),
5699
- Slice(T),
5700
- Index(RangeInclusive(usize))(
5701
- Output : Slice(T),
5702
- index : (fn(ref(self) : Self, idx : RangeInclusive(usize)) -> *(Self.Output))(
5703
- __yo_slice_index_range_inclusive(&(self), idx)
5704
- )
5705
- )
5706
- );
5707
- /// Slice Indexable impl — see Array Indexable above.
5708
- impl(
5709
- forall(T : Type),
5710
- Slice(T),
5711
- Indexable(usize)(
5712
- Element : T,
5713
- project : (fn(ref(self) : Self, pos : usize) -> ref(T))(
5714
- cond(
5715
- (pos >= self.len()) => panic("Slice: project out of bounds"),
5716
- true => unsafe(__yo_slice_index(&(self), pos))
5717
- )
5718
- )
5719
- )
5720
- );
5721
5585
  /// Array ComptimeIndex impls
5722
5586
  impl(
5723
5587
  forall(T : Type, N : usize),
@@ -5730,67 +5594,11 @@ impl(
5730
5594
  )
5731
5595
  )
5732
5596
  );
5597
+ /// comptime_str ComptimeIndex impls
5733
5598
  impl(
5734
- forall(T : Type, N : usize),
5735
- where(T <: Comptime),
5736
- Array(T, N),
5737
- ComptimeIndex(Range(usize))(
5738
- Output : Slice(T),
5739
- index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
5740
- __yo_comptime_array_index_range(self, idx)
5741
- )
5742
- )
5743
- );
5744
- impl(
5745
- forall(T : Type, N : usize),
5746
- where(T <: Comptime),
5747
- Array(T, N),
5748
- ComptimeIndex(RangeInclusive(usize))(
5749
- Output : Slice(T),
5750
- index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
5751
- __yo_comptime_array_index_range_inclusive(self, idx)
5752
- )
5753
- )
5754
- );
5755
- /// Slice ComptimeIndex impls
5756
- impl(
5757
- forall(T : Type),
5758
- where(T <: Comptime),
5759
- Slice(T),
5760
- ComptimeIndex(usize)(
5761
- Output : T,
5762
- index : (fn(comptime(ref(self)) : Self, comptime(idx) : usize) -> comptime(*(Self.Output)))(
5763
- __yo_comptime_slice_index(self, idx)
5764
- )
5765
- )
5766
- );
5767
- impl(
5768
- forall(T : Type),
5769
- where(T <: Comptime),
5770
- Slice(T),
5771
- ComptimeIndex(Range(usize))(
5772
- Output : Slice(T),
5773
- index : (fn(comptime(ref(self)) : Self, comptime(idx) : Range(usize)) -> comptime(*(Self.Output)))(
5774
- __yo_comptime_slice_index_range(self, idx)
5775
- )
5776
- )
5777
- );
5778
- impl(
5779
- forall(T : Type),
5780
- where(T <: Comptime),
5781
- Slice(T),
5782
- ComptimeIndex(RangeInclusive(usize))(
5783
- Output : Slice(T),
5784
- index : (fn(comptime(ref(self)) : Self, comptime(idx) : RangeInclusive(usize)) -> comptime(*(Self.Output)))(
5785
- __yo_comptime_slice_index_range_inclusive(self, idx)
5786
- )
5787
- )
5788
- );
5789
- /// comptime_string ComptimeIndex impls
5790
- impl(
5791
- comptime_string,
5599
+ comptime_str,
5792
5600
  ComptimeIndex(comptime_int)(
5793
- Output : comptime_string,
5601
+ Output : comptime_str,
5794
5602
  index : (
5795
5603
  (self, idx) ->
5796
5604
  __yo_comptime_string_index(self, idx)
@@ -5798,9 +5606,9 @@ impl(
5798
5606
  )
5799
5607
  );
5800
5608
  impl(
5801
- comptime_string,
5609
+ comptime_str,
5802
5610
  ComptimeIndex(Range(comptime_int))(
5803
- Output : comptime_string,
5611
+ Output : comptime_str,
5804
5612
  index : (
5805
5613
  (self, idx) ->
5806
5614
  __yo_comptime_string_index_range(self, idx)
@@ -5808,37 +5616,58 @@ impl(
5808
5616
  )
5809
5617
  );
5810
5618
  impl(
5811
- comptime_string,
5619
+ comptime_str,
5812
5620
  ComptimeIndex(RangeInclusive(comptime_int))(
5813
- Output : comptime_string,
5621
+ Output : comptime_str,
5814
5622
  index : (
5815
5623
  (self, idx) ->
5816
5624
  __yo_comptime_string_index_range_inclusive(self, idx)
5817
5625
  )
5818
5626
  )
5819
5627
  );
5820
- /// `str` — an immutable UTF-8 byte string view (newtype over `Slice(u8)`).
5628
+ /// `str` — the BUILTIN immutable view of STATIC string bytes (TypeTag.Str,
5629
+ /// a fat pointer `{ const uint8_t* ptr; size_t len; }` in C).
5821
5630
  ///
5822
- /// String literals `"hello"` produce `str` at runtime.
5631
+ /// String literals `"hello"` and template-literal segments produce `str`
5632
+ /// at runtime; the backing bytes live in static storage (immortal), so a
5633
+ /// `str` is freely copyable and storable with no lifetime constraints.
5823
5634
  /// For heap-allocated growable strings, see `String`.
5824
- str :: newtype(
5825
- /// The underlying byte slice.
5826
- bytes : Slice(u8)
5827
- );
5828
5635
  impl(
5829
5636
  str,
5830
5637
  /// Construct a `str` from a raw pointer and length.
5638
+ /// SAFETY: callers must guarantee the bytes outlive every use of the
5639
+ /// view — the safe surface only ever does this with static storage.
5831
5640
  from_raw_parts : (fn(ptr : *(u8), length : usize) -> Self)(
5832
- Self(bytes : __yo_slice_new(ptr, length))
5641
+ __yo_str_from_raw_parts(ptr, length)
5833
5642
  ),
5834
5643
  /// Return the length in bytes.
5835
5644
  len : (fn(self : Self) -> usize)(
5836
- __yo_slice_len(self.bytes)
5645
+ __yo_str_len(self)
5837
5646
  ),
5838
5647
  ptr : (fn(self : Self) -> *(u8))(
5839
- __yo_slice_ptr(self.bytes)
5648
+ __yo_str_ptr(self)
5649
+ ),
5650
+ /// Return the byte at `idx` (bounds are the caller's responsibility,
5651
+ /// mirroring slice indexing).
5652
+ bytes : (fn(self : Self, idx : usize) -> u8)(
5653
+ __yo_str_byte(self, idx)
5840
5654
  )
5841
5655
  );
5656
+ /// Range slicing on `str` stays a ZERO-COPY `str` — a window of static
5657
+ /// bytes is still static (byte indices). `s(a..b)` lowers to this.
5658
+ impl(
5659
+ str,
5660
+ slice_copy : (fn(self : Self, r : Range(usize)) -> Self)({
5661
+ e := cond((r.end > __yo_str_len(self)) => __yo_str_len(self), true => r.end);
5662
+ st := cond((r.start > e) => e, true => r.start);
5663
+ __yo_str_from_raw_parts(__yo_str_ptr(self) &+ st, e - st)
5664
+ }),
5665
+ slice_copy_inclusive : (fn(self : Self, r : RangeInclusive(usize)) -> Self)({
5666
+ e := cond(((r.end + usize(1)) > __yo_str_len(self)) => __yo_str_len(self), true => (r.end + usize(1)));
5667
+ st := cond((r.start > e) => e, true => r.start);
5668
+ __yo_str_from_raw_parts(__yo_str_ptr(self) &+ st, e - st)
5669
+ })
5670
+ );
5842
5671
  impl(
5843
5672
  str,
5844
5673
  Eq(str)(
@@ -5898,7 +5727,8 @@ impl(
5898
5727
  })
5899
5728
  )
5900
5729
  );
5901
- export(str);
5730
+ // (str is a builtin type — no export needed; the identifier resolves
5731
+ // everywhere like bool/i32.)
5902
5732
  assert :: (fn(flag : bool, (msg : str) ?= "Assertion failed.") -> unit)(
5903
5733
  cond(
5904
5734
  flag => (),
@@ -6026,7 +5856,7 @@ impl(
6026
5856
  neq : (fn(comptime(a) : Type, comptime(b) : Type) -> comptime(bool))({
6027
5857
  return(!(__yo_are_types_equal(a, b)));
6028
5858
  }),
6029
- to_comptime_string : (fn(comptime(self) : Type) -> comptime(comptime_string))({
5859
+ to_comptime_string : (fn(comptime(self) : Type) -> comptime(comptime_str))({
6030
5860
  return(__yo_type_to_comptime_string(self));
6031
5861
  })
6032
5862
  );
@@ -6055,7 +5885,7 @@ export(StructKind);
6055
5885
  /// TypeFieldInfo — metadata for a single struct/object field.
6056
5886
  TypeFieldInfo :: struct(
6057
5887
  /// Field name.
6058
- name : comptime_string,
5888
+ name : comptime_str,
6059
5889
  /// Field type.
6060
5890
  field_type : Type
6061
5891
  );
@@ -6078,7 +5908,7 @@ export(TraitInfo);
6078
5908
  /// TraitFieldInfo — metadata for a single trait field.
6079
5909
  TraitFieldInfo :: struct(
6080
5910
  /// Field name.
6081
- name : comptime_string,
5911
+ name : comptime_str,
6082
5912
  /// Field type.
6083
5913
  field_type : Type,
6084
5914
  /// `true` if this field is an associated type (not a method).
@@ -6089,7 +5919,7 @@ export(TraitFieldInfo);
6089
5919
  /// ParamInfo — metadata for a function parameter.
6090
5920
  ParamInfo :: struct(
6091
5921
  /// Parameter name.
6092
- name : comptime_string,
5922
+ name : comptime_str,
6093
5923
  /// Parameter type.
6094
5924
  param_type : Type,
6095
5925
  /// `true` if the parameter is compile-time (`comptime`).
@@ -6103,14 +5933,14 @@ impl(ParamInfo, Comptime());
6103
5933
  export(ParamInfo);
6104
5934
  /// ForallParamInfo — metadata for a forall type parameter.
6105
5935
  ForallParamInfo :: struct(
6106
- name : comptime_string,
5936
+ name : comptime_str,
6107
5937
  param_type : Type
6108
5938
  );
6109
5939
  impl(ForallParamInfo, Comptime());
6110
5940
  export(ForallParamInfo);
6111
5941
  /// ImplicitParamInfo — metadata for a `using`/effect parameter.
6112
5942
  ImplicitParamInfo :: struct(
6113
- name : comptime_string,
5943
+ name : comptime_str,
6114
5944
  param_type : Type
6115
5945
  );
6116
5946
  impl(ImplicitParamInfo, Comptime());
@@ -6144,7 +5974,7 @@ export(TraitKind);
6144
5974
  /// VariantInfo — metadata for an enum variant.
6145
5975
  VariantInfo :: struct(
6146
5976
  /// Variant name.
6147
- name : comptime_string,
5977
+ name : comptime_str,
6148
5978
  /// Variant fields (may be empty for unit variants).
6149
5979
  fields : ComptimeList(TypeFieldInfo),
6150
5980
  _enum_type : Type,
@@ -6182,9 +6012,10 @@ TypeInfo :: enum(
6182
6012
  ULongLong,
6183
6013
  LongDouble,
6184
6014
  Void,
6015
+ /// `str` — static string view (fieldless)
6016
+ Str,
6185
6017
  // Compound types (with metadata)
6186
6018
  Array(element : Type, length : comptime_int),
6187
- Slice(element : Type),
6188
6019
  Tuple(fields : ComptimeList(TypeFieldInfo)),
6189
6020
  Struct(
6190
6021
  fields : ComptimeList(TypeFieldInfo),
@@ -6210,7 +6041,7 @@ TypeInfo :: enum(
6210
6041
  ),
6211
6042
  Type(level : comptime_int),
6212
6043
  Some(
6213
- name : comptime_string,
6044
+ name : comptime_str,
6214
6045
  required_traits : ComptimeList(TraitInfo),
6215
6046
  negative_traits : ComptimeList(TraitInfo),
6216
6047
  resolved_type : Type
@@ -6218,7 +6049,7 @@ TypeInfo :: enum(
6218
6049
  // Comptime only
6219
6050
  ComptimeInt,
6220
6051
  ComptimeFloat,
6221
- ComptimeString,
6052
+ ComptimeStr,
6222
6053
  ComptimeList(element : Type),
6223
6054
  // Metaprogramming (fieldless)
6224
6055
  Expr,
@@ -6243,8 +6074,8 @@ impl(
6243
6074
  is_array : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
6244
6075
  match(self,.Array(_, _) => true, _ => false)
6245
6076
  ),
6246
- is_slice : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
6247
- match(self,.Slice(_) => true, _ => false)
6077
+ is_str : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
6078
+ match(self,.Str => true, _ => false)
6248
6079
  ),
6249
6080
  is_function : (fn(comptime(self) : TypeInfo) -> comptime(bool))(
6250
6081
  match(self,.Function(_) => true, _ => false)
@@ -6284,6 +6115,7 @@ impl(
6284
6115
  .LongLong => true,
6285
6116
  .ULongLong => true,
6286
6117
  .LongDouble => true,
6118
+ .Str => true,
6287
6119
  _ => false
6288
6120
  )
6289
6121
  ),
@@ -6326,7 +6158,7 @@ impl(
6326
6158
  self,
6327
6159
  .ComptimeInt => true,
6328
6160
  .ComptimeFloat => true,
6329
- .ComptimeString => true,
6161
+ .ComptimeStr => true,
6330
6162
  .ComptimeList(_) => true,
6331
6163
  .Expr => true,
6332
6164
  _ => false
@@ -6388,7 +6220,7 @@ impl(
6388
6220
  })
6389
6221
  );
6390
6222
  /// `FieldInfo` — compile-time struct field metadata for derive rules (legacy alias).
6391
- FieldInfo :: struct(name : comptime_string, field_type : Type);
6223
+ FieldInfo :: struct(name : comptime_str, field_type : Type);
6392
6224
  impl(FieldInfo, Comptime());
6393
6225
  impl(
6394
6226
  FieldInfo,
@@ -6685,9 +6517,9 @@ export(DeriveContext);
6685
6517
  __yo_comptime_fold_range :: (
6686
6518
  fn(
6687
6519
  comptime(n) : usize,
6688
- comptime(init) : comptime_string,
6689
- comptime(f) : (fn(comptime(acc) : comptime_string, comptime(i) : usize) -> comptime(comptime_string))
6690
- ) -> comptime(comptime_string)
6520
+ comptime(init) : comptime_str,
6521
+ comptime(f) : (fn(comptime(acc) : comptime_str, comptime(i) : usize) -> comptime(comptime_str))
6522
+ ) -> comptime(comptime_str)
6691
6523
  )(
6692
6524
  cond(
6693
6525
  (n == usize(0)) => init,
@@ -6696,17 +6528,17 @@ __yo_comptime_fold_range :: (
6696
6528
  )
6697
6529
  );
6698
6530
  // Helper: concat 2 strings
6699
- __s2 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string) -> comptime(comptime_string))(a + b);
6531
+ __s2 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str) -> comptime(comptime_str))(a + b);
6700
6532
  // Helper: concat 3 strings
6701
- __s3 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string) -> comptime(comptime_string))(
6533
+ __s3 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str) -> comptime(comptime_str))(
6702
6534
  (a + b) + c
6703
6535
  );
6704
6536
  // Helper: concat 4 strings
6705
- __s4 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string, comptime(d) : comptime_string) -> comptime(comptime_string))(
6537
+ __s4 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str, comptime(d) : comptime_str) -> comptime(comptime_str))(
6706
6538
  ((a + b) + c) + d
6707
6539
  );
6708
6540
  // Helper: concat 5 strings
6709
- __s5 :: (fn(comptime(a) : comptime_string, comptime(b) : comptime_string, comptime(c) : comptime_string, comptime(d) : comptime_string, comptime(e) : comptime_string) -> comptime(comptime_string))(
6541
+ __s5 :: (fn(comptime(a) : comptime_str, comptime(b) : comptime_str, comptime(c) : comptime_str, comptime(d) : comptime_str, comptime(e) : comptime_str) -> comptime(comptime_str))(
6710
6542
  (((a + b) + c) + d) + e
6711
6543
  );
6712
6544
  // --- derive_rule for Eq ---
@@ -6738,7 +6570,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
6738
6570
  eq_branches :: __yo_comptime_fold_range(
6739
6571
  vc,
6740
6572
  "",
6741
- (fn(comptime(acc) : comptime_string, comptime(vi) : usize) -> comptime(comptime_string))({
6573
+ (fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
6742
6574
  v :: variants.get(vi);
6743
6575
  branch :: cond(
6744
6576
  (v.fields.len() == 0) =>
@@ -6747,7 +6579,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
6747
6579
  lhs_bindings :: __yo_comptime_fold_range(
6748
6580
  v.fields.len(),
6749
6581
  "",
6750
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6582
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6751
6583
  fname :: v.fields.get(fi).name;
6752
6584
  cond(
6753
6585
  (a == "") => __s2("__lhs_", fname),
@@ -6758,7 +6590,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
6758
6590
  rhs_bindings :: __yo_comptime_fold_range(
6759
6591
  v.fields.len(),
6760
6592
  "",
6761
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6593
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6762
6594
  fname :: v.fields.get(fi).name;
6763
6595
  cond(
6764
6596
  (a == "") => __s2("__rhs_", fname),
@@ -6769,7 +6601,7 @@ __derive_eq :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(t
6769
6601
  eq_cmp :: __yo_comptime_fold_range(
6770
6602
  v.fields.len(),
6771
6603
  "",
6772
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6604
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6773
6605
  fname :: v.fields.get(fi).name;
6774
6606
  part :: __s4("(__lhs_", fname, " == __rhs_", fname);
6775
6607
  cond(
@@ -6828,7 +6660,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
6828
6660
  cloned_fields :: __yo_comptime_fold_range(
6829
6661
  fc,
6830
6662
  "",
6831
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6663
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6832
6664
  fname :: fields.get(fi).name;
6833
6665
  part :: __s3("self.", fname, ".clone()");
6834
6666
  cond(
@@ -6852,7 +6684,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
6852
6684
  clone_branches :: __yo_comptime_fold_range(
6853
6685
  vc,
6854
6686
  "",
6855
- (fn(comptime(acc) : comptime_string, comptime(vi) : usize) -> comptime(comptime_string))({
6687
+ (fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
6856
6688
  v :: variants.get(vi);
6857
6689
  branch :: cond(
6858
6690
  (v.fields.len() == 0) => __s4(".", v.name, " => .", v.name),
@@ -6860,7 +6692,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
6860
6692
  bindings :: __yo_comptime_fold_range(
6861
6693
  v.fields.len(),
6862
6694
  "",
6863
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6695
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6864
6696
  fname :: v.fields.get(fi).name;
6865
6697
  cond(
6866
6698
  (a == "") => __s2("__v_", fname),
@@ -6871,7 +6703,7 @@ __derive_clone :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptim
6871
6703
  cloned :: __yo_comptime_fold_range(
6872
6704
  v.fields.len(),
6873
6705
  "",
6874
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6706
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6875
6707
  fname :: v.fields.get(fi).name;
6876
6708
  cond(
6877
6709
  (a == "") => __s3("__v_", fname, ".clone()"),
@@ -6934,7 +6766,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
6934
6766
  hash_stmts :: __yo_comptime_fold_range(
6935
6767
  fc,
6936
6768
  "",
6937
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6769
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6938
6770
  fname :: fields.get(fi).name;
6939
6771
  cond(
6940
6772
  (fi == 0) => __s3("(h : u64) = self.", fname, ".hash()"),
@@ -6959,7 +6791,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
6959
6791
  hash_branches :: __yo_comptime_fold_range(
6960
6792
  vc,
6961
6793
  "",
6962
- (fn(comptime(acc) : comptime_string, comptime(vi) : usize) -> comptime(comptime_string))({
6794
+ (fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
6963
6795
  v :: variants.get(vi);
6964
6796
  vi_str :: __yo_comptime_usize_to_comptime_string(vi);
6965
6797
  branch :: cond(
@@ -6968,7 +6800,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
6968
6800
  bindings :: __yo_comptime_fold_range(
6969
6801
  v.fields.len(),
6970
6802
  "",
6971
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6803
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6972
6804
  fname :: v.fields.get(fi).name;
6973
6805
  cond(
6974
6806
  (a == "") => __s2("__v_", fname),
@@ -6979,7 +6811,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
6979
6811
  hash_stmts :: __yo_comptime_fold_range(
6980
6812
  v.fields.len(),
6981
6813
  __s3("(h : u64) = u64(", vi_str, ")"),
6982
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6814
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
6983
6815
  fname :: v.fields.get(fi).name;
6984
6816
  __s4(a, "; h = ((h * u64(31)) + __v_", fname, ".hash())")
6985
6817
  })
@@ -7021,7 +6853,7 @@ __derive_hash :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime
7021
6853
  derive_rule(Hash, __derive_hash);
7022
6854
  // --- derive_rule for Ord ---
7023
6855
  // Helper: generate lexicographic comparison for struct fields
7024
- __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_string) -> comptime(comptime_string))({
6856
+ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_str) -> comptime(comptime_str))({
7025
6857
  fields :: Type.get_struct_fields(T);
7026
6858
  fc :: fields.len();
7027
6859
  cond(
@@ -7033,7 +6865,7 @@ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_stri
7033
6865
  branches :: __yo_comptime_fold_range(
7034
6866
  fc,
7035
6867
  "",
7036
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6868
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
7037
6869
  fname :: fields.get(fi).name;
7038
6870
  branch :: cond(
7039
6871
  (fi == (fc - 1)) =>
@@ -7052,7 +6884,7 @@ __derive_ord_struct_body :: (fn(comptime(T) : Type, comptime(op) : comptime_stri
7052
6884
  )
7053
6885
  });
7054
6886
  // Helper: generate lexicographic comparison for enum variant bindings
7055
- __derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : comptime_string) -> comptime(comptime_string))(
6887
+ __derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : comptime_str) -> comptime(comptime_str))(
7056
6888
  cond(
7057
6889
  (v.fields.len() == 1) => {
7058
6890
  fname :: v.fields.get(0).name;
@@ -7062,7 +6894,7 @@ __derive_ord_variant_body :: (fn(comptime(v) : VariantInfo, comptime(op) : compt
7062
6894
  branches :: __yo_comptime_fold_range(
7063
6895
  v.fields.len(),
7064
6896
  "",
7065
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6897
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
7066
6898
  fname :: v.fields.get(fi).name;
7067
6899
  branch :: cond(
7068
6900
  (fi == (v.fields.len() - 1)) =>
@@ -7120,11 +6952,11 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
7120
6952
  variants :: Type.get_enum_variants(T);
7121
6953
  vc :: variants.len();
7122
6954
  // Generate one operator's match branches
7123
- __gen_op_branches :: (fn(comptime(op) : comptime_string, comptime(eq_val) : comptime_string) -> comptime(comptime_string))({
6955
+ __gen_op_branches :: (fn(comptime(op) : comptime_str, comptime(eq_val) : comptime_str) -> comptime(comptime_str))({
7124
6956
  branches :: __yo_comptime_fold_range(
7125
6957
  vc,
7126
6958
  "",
7127
- (fn(comptime(acc) : comptime_string, comptime(vi) : usize) -> comptime(comptime_string))({
6959
+ (fn(comptime(acc) : comptime_str, comptime(vi) : usize) -> comptime(comptime_str))({
7128
6960
  v :: variants.get(vi);
7129
6961
  branch :: cond(
7130
6962
  (v.fields.len() == 0) =>
@@ -7133,7 +6965,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
7133
6965
  lhs_bindings :: __yo_comptime_fold_range(
7134
6966
  v.fields.len(),
7135
6967
  "",
7136
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6968
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
7137
6969
  fname :: v.fields.get(fi).name;
7138
6970
  cond(
7139
6971
  (a == "") => __s2("__lhs_", fname),
@@ -7144,7 +6976,7 @@ __derive_ord :: (fn(comptime(T) : Type, comptime(ctx) : DeriveContext, comptime(
7144
6976
  rhs_bindings :: __yo_comptime_fold_range(
7145
6977
  v.fields.len(),
7146
6978
  "",
7147
- (fn(comptime(a) : comptime_string, comptime(fi) : usize) -> comptime(comptime_string))({
6979
+ (fn(comptime(a) : comptime_str, comptime(fi) : usize) -> comptime(comptime_str))({
7148
6980
  fname :: v.fields.get(fi).name;
7149
6981
  cond(
7150
6982
  (a == "") => __s2("__rhs_", fname),
@@ -7696,55 +7528,24 @@ IntoIterator :: trait(
7696
7528
  );
7697
7529
  export(IntoIterator);
7698
7530
  /// === Array Iterator ===
7699
- /// Position iterator for Array(T, N) — yields `usize` indices.
7700
- /// Used by `Array.iter()`; the for-macro pairs each yielded position
7701
- /// with `Array.project(pos)` (Indexable trait) to hand the body a
7702
- /// `ref(T)`-binding into the element. See plans/ITERATOR_REDESIGN.md.
7703
- _ArrayPosIter :: struct(
7704
- _index : usize,
7705
- _len : usize
7706
- );
7707
- impl(
7708
- _ArrayPosIter,
7709
- Iterator(
7710
- Item : usize,
7711
- next : (fn(ref(self) : Self) -> Option(usize))(
7712
- cond(
7713
- (self._index >= self._len) =>.None,
7714
- true => {
7715
- out := self._index;
7716
- self._index = (self._index + usize(1));
7717
- .Some(out)
7718
- }
7719
- )
7720
- )
7531
+ /// Value iterator for Array(T, N) — yields elements by value. Backs
7532
+ /// the for-macro value form `for(arr, (x) => body)` via `into_iter`.
7533
+ _ArrayIter :: (fn(comptime(T) : Type, comptime(N) : usize) -> comptime(Type))(
7534
+ struct(
7535
+ _arr : Array(T, N),
7536
+ _index : usize
7721
7537
  )
7722
7538
  );
7723
7539
  impl(
7724
7540
  forall(T : Type, N : usize),
7725
- Array(T, N),
7726
- iter : (fn(ref(self) : Self) -> _ArrayPosIter)(
7727
- _ArrayPosIter(_index : usize(0), _len : N)
7728
- )
7729
- );
7730
- /// === Slice Iterator ===
7731
- /// Position iterator for Slice(T) — yields `usize` indices into the
7732
- /// slice. Used by `Slice.iter()`; the for-macro pairs each yielded
7733
- /// position with `Slice.project(pos)` (Indexable) to bind the body's
7734
- /// `ref`-name. See plans/ITERATOR_REDESIGN.md.
7735
- _SlicePosIter :: struct(
7736
- _index : usize,
7737
- _len : usize
7738
- );
7739
- impl(
7740
- _SlicePosIter,
7541
+ _ArrayIter(T, N),
7741
7542
  Iterator(
7742
- Item : usize,
7743
- next : (fn(ref(self) : Self) -> Option(usize))(
7543
+ Item : T,
7544
+ next : (fn(ref(self) : Self) -> Option(T))(
7744
7545
  cond(
7745
- (self._index >= self._len) =>.None,
7546
+ (self._index >= N) =>.None,
7746
7547
  true => {
7747
- out := self._index;
7548
+ out := self._arr(self._index);
7748
7549
  self._index = (self._index + usize(1));
7749
7550
  .Some(out)
7750
7551
  }
@@ -7753,10 +7554,10 @@ impl(
7753
7554
  )
7754
7555
  );
7755
7556
  impl(
7756
- forall(T : Type),
7757
- Slice(T),
7758
- iter : (fn(ref(self) : Self) -> _SlicePosIter)(
7759
- _SlicePosIter(_index : usize(0), _len : self.len())
7557
+ forall(T : Type, N : usize),
7558
+ Array(T, N),
7559
+ into_iter : (fn(self : Self) -> _ArrayIter(T, N))(
7560
+ _ArrayIter(T, N)(_arr : self, _index : usize(0))
7760
7561
  )
7761
7562
  );
7762
7563
  /// TryFrom trait — fallible conversion from one type to another.
@@ -7822,33 +7623,30 @@ try :: (fn(quote(expr_to_try) : Expr) -> unquote(Expr))({
7822
7623
  })
7823
7624
  });
7824
7625
  export(try);
7825
- /// `for` macro — iterate over a collection. The lambda's binding shape
7826
- /// dictates whether the iteration borrows or consumes:
7827
- ///
7828
- /// `for(coll, ref(x) => body)` — borrow form. Calls `coll.iter()`
7829
- /// (must yield positions) + `coll.project(pos)` for each. `x` is
7830
- /// `ref`-bound to the element; reads auto-deref, writes propagate
7831
- /// back to the collection; `coll` survives the loop.
7626
+ /// `for` macro — iterate over a collection.
7832
7627
  ///
7833
- /// `for(coll, (x) => body)` — value form. Calls `coll.into_iter()`
7834
- /// and binds `x` to each yielded value. The collection is moved
7835
- /// into the iterator and consumed.
7628
+ /// `for(coll, (x) => body)` — calls `coll.into_iter()` and binds `x`
7629
+ /// to each yielded value. The collection is moved into the
7630
+ /// iterator; object elements are handles, so mutating `x` in the
7631
+ /// body mutates the element in place.
7836
7632
  ///
7837
- /// Combinator chains (`coll.iter().map(f)`, etc.) only support the
7838
- /// value form they yield computed values, not borrows. A blanket
7839
- /// `into_iter` impl on `Iterator` (below) makes the value form work
7840
- /// transparently on iterator chains.
7633
+ /// The old borrow form `for(coll, ref(x) => body)` was REMOVED: it
7634
+ /// required `ref`s into reallocatable storage, which is no longer
7635
+ /// expressible. Object elements mutate in place through the value
7636
+ /// handle; struct elements use an index loop with `get`/`set`.
7841
7637
  ///
7842
- /// See plans/ITERATOR_REDESIGN.md.
7638
+ /// Combinator chains (`coll.into_iter().map(f)`, etc.) work
7639
+ /// transparently: a blanket `into_iter` impl on `Iterator` (below)
7640
+ /// makes every iterator its own `IntoIterator`.
7843
7641
  ///
7844
7642
  /// # Examples
7845
7643
  /// ```rust
7846
- /// // Borrow form — mutate elements in place.
7847
- /// for(arr, ref(x) => {
7848
- /// x = (x + i32(1));
7644
+ /// // Object elements — mutate in place through the handle.
7645
+ /// for(names, (s) => {
7646
+ /// s.push_str("!");
7849
7647
  /// });
7850
7648
  ///
7851
- /// // Value form consume the collection.
7649
+ /// // Consume an iterator chain.
7852
7650
  /// for(list.into_iter(), (x) => print(x));
7853
7651
  /// ```
7854
7652
  for :: (
@@ -7879,38 +7677,14 @@ for :: (
7879
7677
  );
7880
7678
  cond(
7881
7679
  is_ref_form => {
7882
- v_args :: variable.get_args();
7883
- comptime_assert(v_args.len() == 1, "'for' macro: ref(name) requires exactly one name");
7884
- name :: v_args.car();
7885
- iter_var :: gensym("for_iter_var");
7886
- pos_var :: gensym("for_pos_var");
7887
- // Note: the borrow form does NOT materialize a local
7888
- // copy of `coll`. Writes through `ref(x) := …
7889
- // coll.project(pos)` need to propagate to the caller's
7890
- // storage; a value-typed local copy would receive the
7891
- // writes silently. The for-macro consumes `coll` as an
7892
- // expression directly so the `&coll` pointer it
7893
- // implicitly forms reaches the caller's collection.
7894
- // (This is correct for `coll : Array(T, N)` /
7895
- // `Slice(T)` / `String` value-typed collections and
7896
- // for `ref(coll)`-bound parameter inputs; for owning
7897
- // collections like `ArrayList` whose internal storage
7898
- // is heap, the receiver-by-ref semantics already work.)
7899
- quote({
7900
- unquote(iter_var) := unquote(coll).iter();
7901
- while(runtime(true), {
7902
- match(
7903
- unquote(iter_var).next(),
7904
- .Some(unquote(pos_var)) => {
7905
- ref(unquote(name)) := unquote(coll).project(unquote(pos_var));
7906
- unquote(body);
7907
- },
7908
- .None => {
7909
- break;
7910
- }
7911
- );
7912
- });
7913
- })
7680
+ // The borrow form is gone: it handed out refs into
7681
+ // reallocatable storage. Teach the migration instead
7682
+ // of failing with a resolution error.
7683
+ comptime_assert(
7684
+ false,
7685
+ "'for(coll, ref(x) => ...)' was removed - use the value form 'for(coll, (x) => ...)'. Object elements are handles and mutate in place; for struct elements use an index loop with get/set."
7686
+ );
7687
+ quote(())
7914
7688
  },
7915
7689
  true => {
7916
7690
  iter_var :: gensym("for_iter_var");