@@ -13371,10 +13371,10 @@
13371 (~(put by (direct-checked-gates ds env)) update.parts update-def)
13371 (~(put by (direct-checked-gates ds env)) update.parts update-def)
13372 =/ templates=ienv
13372 =/ templates=ienv
13373 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13373 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13374− =/ scanned=(unit dgscan)
13374+ =/ fresh=(unit @ud)
13375− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13375+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
13376− ?~ scanned ~
13376+ ?~ fresh ~
13377− =. next.initial (dg-next-id ids.u.scanned 0)
13377+ =. next.initial u.fresh
13378 =/ update-state=istate (reserve-def-caps val.update-def initial)
13378 =/ update-state=istate (reserve-def-caps val.update-def initial)
13379 =/ sam=isample-result (infer-sample u.written-update env update-state)
13379 =/ sam=isample-result (infer-sample u.written-update env update-state)
13380 ?: ?=(%| -.sam) ~
13380 ?: ?=(%| -.sam) ~
@@ -13533,10 +13533,10 @@
13533 =/ checked=(map term def) (direct-checked-gates ds env)
13533 =/ checked=(map term def) (direct-checked-gates ds env)
13534 =/ templates=ienv
13534 =/ templates=ienv
13535 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13535 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13536− =/ scanned=(unit dgscan)
13536+ =/ fresh=(unit @ud)
13537− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13537+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
13538− ?~ scanned ~
13538+ ?~ fresh ~
13539− =. next.initial (dg-next-id ids.u.scanned 0)
13539+ =. next.initial u.fresh
13540 =/ subs-state=istate (reserve-def-caps val.subs-def initial)
13540 =/ subs-state=istate (reserve-def-caps val.subs-def initial)
13541 =/ sam=isample-result (infer-sample u.written-subs env subs-state)
13541 =/ sam=isample-result (infer-sample u.written-subs env subs-state)
13542 ?: ?=(%| -.sam) ~
13542 ?: ?=(%| -.sam) ~
@@ -13884,10 +13884,10 @@
13884 =/ checked=(map term def) (direct-checked-gates ds env)
13884 =/ checked=(map term def) (direct-checked-gates ds env)
13885 =/ templates=ienv
13885 =/ templates=ienv
13886 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13886 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13887− =/ scanned=(unit dgscan)
13887+ =/ fresh=(unit @ud)
13888− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13888+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
13889− ?~ scanned ~
13889+ ?~ fresh ~
13890− =. next.initial (dg-next-id ids.u.scanned 0)
13890+ =. next.initial u.fresh
13891 =/ view-state=istate (reserve-def-caps val.view-def initial)
13891 =/ view-state=istate (reserve-def-caps val.view-def initial)
13892 =/ sam=isample-result (infer-sample u.written-view env view-state)
13892 =/ sam=isample-result (infer-sample u.written-view env view-state)
13893 ?: ?=(%| -.sam) ~
13893 ?: ?=(%| -.sam) ~
@@ -13998,10 +13998,10 @@
13998 =/ checked=(map term def) (direct-checked-gates ds env)
13998 =/ checked=(map term def) (direct-checked-gates ds env)
13999 =/ templates=ienv
13999 =/ templates=ienv
14000 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14000 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14001− =/ scanned=(unit dgscan)
14001+ =/ fresh=(unit @ud)
14002− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
14002+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14003− ?~ scanned ~
14003+ ?~ fresh ~
14004− =. next.initial (dg-next-id ids.u.scanned 0)
14004+ =. next.initial u.fresh
14005 =/ view-state=istate (reserve-def-caps val.view-def initial)
14005 =/ view-state=istate (reserve-def-caps val.view-def initial)
14006 =/ sam=isample-result (infer-sample u.written-view env view-state)
14006 =/ sam=isample-result (infer-sample u.written-view env view-state)
14007 ?: ?=(%| -.sam) ~
14007 ?: ?=(%| -.sam) ~
@@ -14195,10 +14195,10 @@
14195 =/ checked=(map term def) (direct-checked-gates ds env)
14195 =/ checked=(map term def) (direct-checked-gates ds env)
14196 =/ templates=ienv
14196 =/ templates=ienv
14197 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14197 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14198− =/ scanned=(unit dgscan)
14198+ =/ fresh=(unit @ud)
14199− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
14199+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14200− ?~ scanned ~
14200+ ?~ fresh ~
14201− =. next.initial (dg-next-id ids.u.scanned 0)
14201+ =. next.initial u.fresh
14202 =/ init-state=istate (reserve-def-caps val.init-def initial)
14202 =/ init-state=istate (reserve-def-caps val.init-def initial)
14203 =/ sam=isample-result (infer-sample u.written env init-state)
14203 =/ sam=isample-result (infer-sample u.written env init-state)
14204 ?: ?=(%| -.sam) ~
14204 ?: ?=(%| -.sam) ~
@@ -14267,10 +14267,10 @@
14267 =/ checked=(map term def) (direct-checked-gates ds env)
14267 =/ checked=(map term def) (direct-checked-gates ds env)
14268 =/ templates=ienv
14268 =/ templates=ienv
14269 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14269 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14270− =/ scanned=(unit dgscan)
14270+ =/ fresh=(unit @ud)
14271− (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
14271+ (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14272− ?~ scanned ~
14272+ ?~ fresh ~
14273− =. next.initial (dg-next-id ids.u.scanned 0)
14273+ =. next.initial u.fresh
14274 =/ instance=[typ=itype state=istate] (instantiate-scheme u.program initial)
14274 =/ instance=[typ=itype state=istate] (instantiate-scheme u.program initial)
14275 ?. ?=(%fn -.typ.instance) ~
14275 ?. ?=(%fn -.typ.instance) ~
14276 ?. ?=(%cell -.sample.typ.instance) ~
14276 ?. ?=(%cell -.sample.typ.instance) ~
@@ -15637,9 +15637,9 @@
15637 =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
15637 =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
15638 ?~ free ~
15638 ?~ free ~
15639 ?^ ids.u.free ~
15639 ?^ ids.u.free ~
15640− =/ all=(unit dgscan) (dg-all-env-ids base 32.768 ~)
15640+ =/ all=(unit @ud) (ienv-fresh-id base)
15641 ?~ all ~
15641 ?~ all ~
15642− =/ fresh=@ud (dg-next-id ids.u.all 0)
15642+ =/ fresh=@ud u.all
15643 =/ st=istate *istate
15643 =/ st=istate *istate
15644 =. st st(next fresh, defer `~, molds molds, globals globals, at at, top-molds (turn molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
15644 =. st st(next fresh, defer `~, molds molds, globals globals, at at, top-molds (turn molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
15645 =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
15645 =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
@@ -15679,33 +15679,60 @@
15679 =/ free=(unit dgscan) (dg-env all-env ~ 32.768 ~)
15679 =/ free=(unit dgscan) (dg-env all-env ~ 32.768 ~)
15680 ?~ free ~
15680 ?~ free ~
15681 ?^ ids.u.free ~
15681 ?^ ids.u.free ~
15682− =/ all=(unit dgscan) (dg-all-env-ids all-env 32.768 ~)
15682+ =/ all=(unit @ud) (ienv-fresh-id all-env)
15683 ?~ all ~
15683 ?~ all ~
15684− =/ fresh=@ud (dg-next-id ids.u.all 0)
15684+ =/ fresh=@ud u.all
15685 =/ st=istate *istate
15685 =/ st=istate *istate
15686 =. st st(next fresh, defer `~, molds local-molds, globals globals, at at, reserved-molds molds.prepared, prelude prelude, top-molds (turn local-molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
15686 =. st st(next fresh, defer `~, molds local-molds, globals globals, at at, reserved-molds molds.prepared, prelude prelude, top-molds (turn local-molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
15687 =/ checked-molds=(each imold-types @t) (module-mold-types local-molds st)
15687 =/ checked-molds=(each imold-types @t) (module-mold-types local-molds st)
15688 ?: ?=(%| -.checked-molds) ~
15688 ?: ?=(%| -.checked-molds) ~
15689 (dg-stage defs base base st ~ 64)
15689 (dg-stage defs base base st ~ 64)
15691−++ dg-all-env-ids
15691+:: +ienv-fresh-id: one above the largest type variable or tag ID in env
15693+:: One pass over every ID in env's schemes, quantified or free, so a
15694+:: variable numbered from it captures none of them. A %recursive or
15695+:: %jrec type names its mold and holds no variable, so it is a leaf,
15696+:: and the pass is linear in the size of the types, with no budget.
15697+:: A scheme that still holds an unresolved tag declines.
15692− |= [env=ienv fuel=@ud ids=(list @ud)]
15700+ |= env=ienv
15693− ^- (unit dgscan)
15701+ ^- (unit @ud)
15694− ?~ env `[ids fuel]
15702+ =/ top=@ud 0
15695− ?: =(0 fuel) ~
15703+ |-
15696 =/ sc=ischeme scheme.i.env
15705 =/ sc=ischeme scheme.i.env
15697 ?: (itype-has-tag typ.sc) ~
15706 ?: (itype-has-tag typ.sc) ~
15698− =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ (dec fuel) ids)
15707+ $(env t.env, top (itype-max-id typ.sc (max top (roll vars.sc max))))
15700− =/ quant=(unit dgscan) (dg-scan-ids vars.sc ~ fuel.u.raw ids.u.raw)
15709+:: +itype-max-id: the largest variable or tag ID in t, or top
15702− $(env t.env, fuel fuel.u.quant, ids ids.u.quant)
15704−++ dg-next-id
15711+++ itype-max-id
15705− |= [ids=(list @ud) largest=@ud]
15712+ |= [t=itype top=@ud]
15715+ %var (max top id.t)
15716+ %fvar (max top id.t)
15717+ %avar (max top id.t)
15718+ %rvar (max top id.t)
15719+ %nvar (max top id.t)
15720+ %rnvar (max top id.t)
15721+ %tag (max top id.t)
15722+ ?(%atom %any-atom %flag %noun %empty %const %recursive %jrec) top
15723+ %collection (itype-max-ids args.t top)
15724+ %grec (itype-max-ids args.t top)
15725+ %union (itype-max-ids args.t (itype-max-ids cases.t top))
15727+ %fn $(t sample.t, top $(t product.t))
15728+ %cell $(t hed.t, top $(t tal.t))
15732+ |= [ts=(list itype) top=@ud]
15707− ?~ ids +(largest)
15734+ ?~ ts top
15708− $(ids t.ids, largest (max largest i.ids))
15735+ $(ts t.ts, top (itype-max-id i.ts top))
15710++ dg-eligible-ctor
15737++ dg-eligible-ctor
15711 |= [e=expr head=itype actual=itype expected=itype state=istate]
15738 |= [e=expr head=itype actual=itype expected=itype state=istate]