The prelude's generics name their element types with the sigil, so a program global named t, k or v no longer breaks them

This commit is contained in:
Joseph Ferano 2026-09-25 15:26:29 +07:00
parent 580d377847
commit 0f0fbc68ef
2 changed files with 11 additions and 4 deletions

View File

@ -554,11 +554,11 @@ let source = {flan|
;; in. Owned by the caller: (free v), or let a (free-all a) take the region. ;; in. Owned by the caller: (free v), or let a (free-all a) take the region.
;; ;;
;; This is the one that proves the containers and the generics compose. It ;; This is the one that proves the containers and the generics compose. It
;; allocates — (vec-new t), push, returns (Vec t) — and the type-erased Vec ;; allocates — (vec-new $t), push, returns (Vec $t) — and the type-erased Vec
;; runtime needed no change at all, because SizeOf and AlignOf are computed at ;; runtime needed no change at all, because SizeOf and AlignOf are computed at
;; the instantiation site, where the element type is concrete. ;; the instantiation site, where the element type is concrete.
(defn filter [s [const $t] keep? (Fn [$t] bool)] (Vec $t) (defn filter [s [const $t] keep? (Fn [$t] bool)] (Vec $t)
(let [v (vec-new t)] (let [v (vec-new $t)]
(dotimes [i (length s)] (dotimes [i (length s)]
(when (keep? (at s i)) (when (keep? (at s i))
(push v (at s i)))) (push v (at s i))))
@ -570,7 +570,7 @@ let source = {flan|
;; the map's own key bytes and is good for as long as they are. ;; the map's own key bytes and is good for as long as they are.
(defn map-keys [m (Map $k $v)] (Vec $k) (defn map-keys [m (Map $k $v)] (Vec $k)
{:where (hashable? $k)} {:where (hashable? $k)}
(let [out (vec-new k) (let [out (vec-new $k)
cur (i64 0) cur (i64 0)
key (the $k (zeroed)) key (the $k (zeroed))
val (the $v (zeroed))] val (the $v (zeroed))]
@ -580,7 +580,7 @@ let source = {flan|
(defn map-values [m (Map $k $v)] (Vec $v) (defn map-values [m (Map $k $v)] (Vec $v)
{:where (hashable? $k)} {:where (hashable? $k)}
(let [out (vec-new v) (let [out (vec-new $v)
cur (i64 0) cur (i64 0)
key (the $k (zeroed)) key (the $k (zeroed))
val (the $v (zeroed))] val (the $v (zeroed))]

View File

@ -1,5 +1,12 @@
;; map-keys and map-values: the prelude's two generic walks over a map. Block ;; map-keys and map-values: the prelude's two generic walks over a map. Block
;; order is the hash's, so what comes back is sorted before it is printed. ;; order is the hash's, so what comes back is sorted before it is printed.
;;
;; The three globals are named after the prelude's type variables. A generic's
;; body names its element type as $t, $k or $v, never bare, because a bare
;; name there is an expression and would find these.
(defonce t i32 0)
(defonce k i32 0)
(defonce v i32 0)
(defn main [] i32 (defn main [] i32
(let [m (map-new i32 i64)] (let [m (map-new i32 i64)]