@@ -8458,6 +8458,7 @@
84588458 ?: ?=(%| -.result) result
84598459 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
84608460 %branch
8461+ ?^ defer.state (dg-boolean-branch e env state)
84618462 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
84628463 ?~ t.arms.e
84638464 =/ empty-list=(unit iresult) (empty-list-null-branch e env state ~)
@@ -9239,6 +9240,7 @@
92399240++ infer-call-context-arg
92409241 |= [e=expr expected=itype env=ienv state=istate context=span]
92419242 ^- iresult
9243+ ?: &(?=(^ defer.state) ?=(%branch -.e)) (infer-fragment e env state)
92429244 ?: ?=(%pair -.e) $(e (pair-as-cell e))
92439245 ?: ?=(%group -.e) $(e inner.e)
92449246 ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
@@ -10694,6 +10696,92 @@
1069410696 ?~ active |
1069510697 ?=(^ (union-state-tags-budget tags.state u.active))
1069610698::
10699+:: Positive overlap witnesses from parsed, one-hop local source only.
10700+:: Unknown or exhausted work returns no witness, never disjointness.
10701++$ uow-case [at=span head=@ payload=upat]
10702+++ union-overlap-primitive
10703+ |= s=shape
10704+ ^- (unit upat)
10705+ ?- -.s
10706+ %aura `[%atom ~]
10707+ %noun `[%all ~]
10708+ %void `[%empty ~]
10709+ %flag `[%flag ~]
10710+ %const
10711+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10712+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10713+ `[%atom `val.lit.s]
10714+ * ~
10715+ ==
10716+++ union-overlap-case
10717+ |= [s=shape molds=imolds fuel=@ud]
10718+ ^- (unit [item=uow-case left=@ud])
10719+ ?: =(0 fuel) ~
10720+ =. fuel (dec fuel)
10721+ :: Each body has exactly two fields; an application has exactly one
10722+ :: parameter and one concrete primitive argument. The full mold table
10723+ :: is scanned to establish unique ownership.
10724+ =/ expanded=(unit [body=shape param=(unit [name=@t pat=upat]) left=@ud])
10725+ ?: ?=(%cell -.s) `[s ~ fuel]
10726+ ?. ?=(%apply -.s) ~
10727+ ?. ?=([@ ~] ref.s) ~
10728+ ?. ?=([* ~] args.s) ~
10729+ ?: =(0 fuel) ~
10730+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10731+ ?~ found ~
10732+ ?. ?=(%generic -.body.u.found) ~
10733+ ?. ?=([@ ~] vars.body.u.found) ~
10734+ ?: =(0 left.u.found) ~
10735+ =/ argument=(unit upat) (union-overlap-primitive i.args.s)
10736+ ?~ argument ~
10737+ `[body.body.u.found `[i.vars.body.u.found u.argument] (dec left.u.found)]
10738+ ?~ expanded ~
10739+ =/ body=shape body.u.expanded
10740+ ?. ?=(%cell -.body) ~
10741+ ?. ?=([* * ~] fields.body) ~
10742+ :: Charge the cell, two fields, and the head and payload nodes.
10743+ ?: (lth left.u.expanded 5) ~
10744+ =/ head=(unit @) (union-source-cell-tag body)
10745+ ?~ head ~
10746+ =/ field=field i.t.fields.body
10747+ =/ payload=shape
10748+ ?- -.field
10749+ %bare shape.field
10750+ %face shape.field
10751+ %pun [%ref at.field ~[name.field]]
10752+ ==
10753+ =/ pattern=(unit upat)
10754+ ?: ?=(%tvar -.payload)
10755+ ?~ param.u.expanded ~
10756+ ?. =(name.payload name.u.param.u.expanded) ~
10757+ `pat.u.param.u.expanded
10758+ (union-overlap-primitive payload)
10759+ ?~ pattern ~
10760+ `[[at.s u.head u.pattern] (sub left.u.expanded 5)]
10761+++ union-overlap-against
10762+ |= [first=uow-case rest=(list shape) molds=imolds fuel=@ud]
10763+ ^- (unit [witness=(unit upair) left=@ud])
10764+ ?~ rest `[~ fuel]
10765+ ?: =(0 fuel) ~
10766+ =/ other=(unit [item=uow-case left=@ud]) (union-overlap-case i.rest molds (dec fuel))
10767+ ?~ other ~
10768+ ?: &(=(head.first head.item.u.other) =(%overlap (union-relate payload.first payload.item.u.other)))
10769+ `[`[at.first at.item.u.other %overlap] left.u.other]
10770+ $(rest t.rest, fuel left.u.other)
10771+++ union-source-overlap
10772+ |= [cases=(list shape) molds=imolds fuel=@ud]
10773+ ^- (unit upair)
10774+ ?~ cases ~
10775+ ?~ t.cases ~
10776+ ?: =(0 fuel) ~
10777+ =/ first=(unit [item=uow-case left=@ud]) (union-overlap-case i.cases molds (dec fuel))
10778+ ?~ first ~
10779+ =/ found=(unit [witness=(unit upair) left=@ud])
10780+ (union-overlap-against item.u.first t.cases molds left.u.first)
10781+ ?~ found ~
10782+ ?^ witness.u.found witness.u.found
10783+ $(cases t.cases, fuel left.u.found)
10784+::
1069710785++ union-pairs
1069810786 |= [cases=(list shape) molds=imolds]
1069910787 ^- (list upair)
@@ -10847,6 +10935,11 @@
1084710935 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
1084810936 =/ pairs=(list upair) (union-pairs cases.sh molds)
1084910937 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
10938+ =. overlapping
10939+ ?^ overlapping overlapping
10940+ ?. (lien pairs |=(p=upair =(%unknown relation.p))) ~
10941+ =/ witness=(unit upair) (union-source-overlap cases.sh molds 256)
10942+ ?~(witness ~ ~[u.witness])
1085010943 ?^ overlapping
1085110944 =/ p=upair i.overlapping
1085210945 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
@@ -12736,6 +12829,14 @@
1273612829 `[[normalized quantified]]
1273712830::
1273812831+$ dgcommit [env=ienv state=istate]
12832+:: A branch literal must not acquire a value face through replay.
12833+++ dg-literal-target-safe
12834+ |= target=itype
12835+ ^- ?
12836+ ?: ?=(%union -.target)
12837+ (levy cases.target |=(c=itype ?=(?(%const %cell) -.c)))
12838+ ?=(?(%const %atom %any-atom %flag %noun) -.target)
12839+::
1273912840++ dg-replay-edges
1274012841 |= [edges=(list dgo) state=istate fuel=@ud]
1274112842 ^- (unit istate)
@@ -12743,7 +12844,16 @@
1274312844 ?: =(0 fuel) ~
1274412845 =/ trial=ifit (itype-fit left.i.edges right.i.edges sub.state next.state)
1274512846 ?. ?=(%ok -.trial) ~
12746− ?. =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial)) ~
12847+ =/ valid=?
12848+ ?: ?=(%tag -.left.i.edges)
12849+ ?. constructor.left.i.edges
12850+ =/ closed=(unit dgscan) (dg-scan ~[right.i.edges] sub.trial 512 ~)
12851+ ?~ closed |
12852+ ?^ ids.u.closed |
12853+ (dg-literal-target-safe (itype-normalize right.i.edges sub.trial))
12854+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12855+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12856+ ?. valid ~
1274712857 $(edges t.edges, state state(sub sub.trial, next next.trial), fuel (dec fuel))
1274812858::
1274912859++ dg-close-env
@@ -12764,6 +12874,68 @@
1276412874 ?~ rest ~
1276512875 `[[name.i.env [normalized vars.s]] u.rest]
1276612876::
12877+:: A deferred boolean branch has exactly the two literal flag patterns.
12878+:: Arms are inferred in order. Equal types are retained; two direct pending
12879+:: literals may instead retain source-owned obligations for later context.
12880+++ dg-boolean-patterns
12881+ |= e=expr
12882+ ^- ?
12883+ ?. ?=(%branch -.e) |
12884+ ?~ arms.e |
12885+ ?~ t.arms.e |
12886+ ?^ t.t.arms.e |
12887+ =/ x=arm i.arms.e
12888+ =/ y=arm i.t.arms.e
12889+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
12890+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
12891+ !=(val.lit.pat.x val.lit.pat.y)
12892+:: Only a direct source literal which created its own unbound pending tag
12893+:: may create a branch edge. The caller must retain the exact source and state.
12894+++ dg-owned-arm-literal
12895+ |= [e=expr t=itype tags=(list ipending) sub=isub initial=@ud]
12896+ ^- ?
12897+ ?. ?=(%lit -.e) |
12898+ ?. ?=(%tag -.t) |
12899+ ?: constructor.t |
12900+ ?. =(lit.e literal.t) |
12901+ ?: (lth id.t initial) |
12902+ ?^ (itype-lookup id.t sub) |
12903+ (lien tags |=(x=ipending &(=(id.x id.t) =(literal.x literal.t))))
12904+++ dg-boolean-branch
12905+ |= [e=expr env=ienv state=istate]
12906+ ^- iresult
12907+ ?. (dg-boolean-patterns e) [%| ["deferred branch patterns need unsupported inference" ~]]
12908+ ?> ?=(%branch -.e)
12909+ ?> ?=(^ arms.e)
12910+ ?> ?=(^ t.arms.e)
12911+ =/ x=arm i.arms.e
12912+ =/ y=arm i.t.arms.e
12913+ =/ subject=iresult (infer-fragment subject.e env state)
12914+ ?: ?=(%| -.subject) subject
12915+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
12916+ ?~ su [%| ["deferred branch subject does not unify with ?" ~]]
12917+ =/ left=iresult (infer-fragment val.x env state.p.subject(sub u.su))
12918+ ?: ?=(%| -.left) left
12919+ =/ right=iresult (infer-fragment val.y env state.p.left)
12920+ ?: ?=(%| -.right) right
12921+ ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
12922+ =/ st=istate state.p.right
12923+ ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
12924+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12925+ ?. (dg-owned-arm-literal val.y typ.p.right tags.st sub.st next.state)
12926+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12927+ ?> ?=(%tag -.typ.p.left)
12928+ ?> ?=(%tag -.typ.p.right)
12929+ ?: =(id.typ.p.left id.typ.p.right)
12930+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12931+ ?: (gth (lent obligations.st) 62)
12932+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12933+ =/ result=itype [%var next.st]
12934+ =/ ex=dgo [typ.p.left result (span-of val.x) (span-of e)]
12935+ =/ ey=dgo [typ.p.right result (span-of val.y) (span-of e)]
12936+ [%& result st(next +(next.st), obligations [ex ey obligations.st])]
12937+ [%& typ.p.left state.p.right]
12938+::
1276712939:: Deferred inference uses only source forms whose successful fit sites are
1276812940:: guarded below; a shared source-node budget bounds this screen.
1276912941++ dg-safe-expressions
@@ -12790,6 +12962,13 @@
1279012962 $(e final.e, fuel fuel)
1279112963 %gate $(e body.e, fuel fuel)
1279212964 %gate-wide $(e body.e, fuel fuel)
12965+ %branch
12966+ ?. (dg-boolean-patterns e) ~
12967+ ?> ?=(^ arms.e)
12968+ ?> ?=(^ t.arms.e)
12969+ =/ subject=(unit @ud) $(e subject.e, fuel fuel)
12970+ ?~ subject ~
12971+ (dg-safe-expressions ~[val.i.arms.e val.i.t.arms.e] u.subject)
1279312972 %cast $(e val.e, fuel fuel)
1279412973 %call
1279512974 =/ head=(unit @ud) $(e head.e, fuel fuel)
@@ -12814,28 +12993,12 @@
1281412993 ?: &(positional ?=(^ ids.u.checked)) |
1281512994 =((itype-normalize actual sub) (itype-normalize expected sub))
1281612995::
12817−++ dg-stage
12818− |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
12819− ^- (unit dgcommit)
12820− ?~ ds
12821− =/ replayed=(unit istate) (dg-replay-edges pending state 64)
12822− ?~ replayed ~
12823− ?: (pending-tags tags.u.replayed sub.u.replayed) ~
12824− =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
12825− ?~ closed-edges ~
12826− ?^ ids.u.closed-edges ~
12827− =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
12828− ?~ rechecked ~
12829− ?. =(sub.u.rechecked sub.u.replayed) ~
12830− ?. =(next.u.rechecked next.u.replayed) ~
12831− =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
12832− ?~ closed ~
12833− `[[u.closed u.replayed(defer ~, obligations ~)]]
12834− ?: =(0 fuel) ~
12835− =/ d=def i.ds
12836− ?: ?=(%mold -.d) $(ds t.ds, fuel (dec fuel))
12837− ?^ (ienv-lookup name.d base) $(ds t.ds, fuel (dec fuel))
12838− ?^ (ienv-lookup name.d env) ~
12996+:: One definition attempt retains state only when inference succeeds.
12997++$ dg-step [env=ienv state=istate pending=(list dgo)]
12998+++ dg-stage-one
12999+ |= [d=def env=ienv state=istate]
13000+ ^- (unit dg-step)
13001+ ?> ?=(%value -.d)
1283913002 ?~ (dg-safe-expression val.d 512) ~
1284013003 =/ local=istate (reserve-def-caps val.d state)
1284113004 :: This first slice declines all written capitals and holes/projections.
@@ -12871,7 +13034,45 @@
1287113034 ?: (itype-has-nvar (itype-normalize typ sub.after)) ~
1287213035 =/ scheme=(unit ischeme) (dg-generalize typ env edges tags.after ~ after 32.768)
1287313036 ?~ scheme ~
12874− $(ds t.ds, env [[name.d u.scheme] env], state after, pending edges, fuel (dec fuel))
13037+ `[[[name.d u.scheme] env] after edges]
13038+:: Retry only definitions that did not infer. Successful definitions are
13039+:: committed into the local transaction, never published until all close.
13040+++ dg-stage
13041+ |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
13042+ ^- (unit dgcommit)
13043+ ?: (gth fuel 64) ~
13044+ ?: (gth (lent ds) fuel) ~
13045+ =/ remaining=(list def) ds
13046+ =/ waiting=(list def) ~
13047+ =/ progress=? |
13048+ =/ attempts=@ud (mul fuel fuel)
13049+ |-
13050+ ?~ remaining
13051+ ?^ waiting
13052+ ?. progress ~
13053+ $(remaining (flop waiting), waiting ~, progress |)
13054+ =/ replayed=(unit istate) (dg-replay-edges pending state 64)
13055+ ?~ replayed ~
13056+ ?: (pending-tags tags.u.replayed sub.u.replayed) ~
13057+ =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
13058+ ?~ closed-edges ~
13059+ ?^ ids.u.closed-edges ~
13060+ =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
13061+ ?~ rechecked ~
13062+ ?. =(sub.u.rechecked sub.u.replayed) ~
13063+ ?. =(next.u.rechecked next.u.replayed) ~
13064+ =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
13065+ ?~ closed ~
13066+ `[[u.closed u.replayed(defer ~, obligations ~)]]
13067+ ?: =(0 attempts) ~
13068+ =. attempts (dec attempts)
13069+ =/ d=def i.remaining
13070+ ?: ?=(%mold -.d) $(remaining t.remaining)
13071+ ?^ (ienv-lookup name.d base) $(remaining t.remaining)
13072+ ?^ (ienv-lookup name.d env) ~
13073+ =/ done=(unit dg-step) (dg-stage-one d env state)
13074+ ?~ done $(remaining t.remaining, waiting [d waiting])
13075+ $(remaining t.remaining, env env.u.done, state state.u.done, pending pending.u.done, progress &)
1287513076::
1287613077:: Cheap bounded eligibility check on the already parsed source. This
1287713078:: deliberately covers only direct constructor calls beneath transparent