@@ -4606,6 +4606,9 @@
46064606 [%atom aura=@ta]
46074607 [%any-atom ~]
46084608 [%flag ~]
4609+ [%tag id=@ud literal=lit constructor=?]
4610+ [%const literal=lit]
4611+ [%union cases=(list itype)]
46094612 [%face name=term body=itype]
46104613 [%fn sample=itype product=itype]
46114614 [%cell hed=itype tal=itype]
@@ -4636,6 +4639,10 @@
46364639 =/ found=(unit itype) (itype-lookup id.t sub)
46374640 ?~ found t
46384641 $(t u.found)
4642+ %tag
4643+ =/ found=(unit itype) (itype-lookup id.t sub)
4644+ ?~ found t
4645+ $(t u.found)
46394646 ==
46404647::
46414648++ itype-occurs
@@ -4649,6 +4656,9 @@
46494656 %atom |
46504657 %any-atom |
46514658 %flag |
4659+ %tag =(n id.t)
4660+ %const |
4661+ %union (lien cases.t |=(c=itype (itype-occurs n c sub)))
46524662 %face $(t body.t)
46534663 %fn |($(t sample.t) $(t product.t))
46544664 %cell |($(t hed.t) $(t tal.t))
@@ -4688,6 +4698,8 @@
46884698 ?: ?=(%avar -.b)
46894699 ?. |(?=(%atom -.a) ?=(%any-atom -.a) ?=(%flag -.a)) ~
46904700 `[[id.b a] sub]
4701+ ?: &(?=(%const -.a) ?=(%const -.b))
4702+ ?:(=(val.literal.a val.literal.b) `sub ~)
46914703 ?: &(?=(%atom -.a) ?=(%atom -.b)) ~
46924704 ?: &(?=(%face -.a) ?=(%face -.b))
46934705 ?. =(name.a name.b) ~
@@ -4719,6 +4731,9 @@
47194731 %atom |
47204732 %any-atom &
47214733 %flag |
4734+ %tag |
4735+ %const |
4736+ %union (lien cases.t |=(c=itype (itype-has-any-atom c sub)))
47224737 %face $(t body.t)
47234738 %fn |($(t sample.t) $(t product.t))
47244739 %cell |($(t hed.t) $(t tal.t))
@@ -4773,6 +4788,9 @@
47734788 %atom &
47744789 %any-atom &
47754790 %flag &
4791+ %tag &
4792+ %const &
4793+ %union (lien cases.typ |=(c=itype (itype-has-fixed-atom c)))
47764794 %face $(typ body.typ)
47774795 %fn |($(typ sample.typ) $(typ product.typ))
47784796 %cell |($(typ hed.typ) $(typ tal.typ))
@@ -4843,11 +4861,83 @@
48434861 ?- -.t
48444862 %var &
48454863 %cell &
4864+ %union &
48464865 %face $(t body.t)
48474866 %fn |($(t sample.t) $(t product.t))
48484867 * |
48494868 ==
48504869::
4870+++ pending-tags
4871+ |= [tags=(list @ud) sub=isub]
4872+ ^- ?
4873+ ?~ tags |
4874+ ?~ (itype-lookup i.tags sub) &
4875+ $(tags t.tags)
4876+::
4877+:: Tags remain constrained until a mold selects a case or permitted atom
4878+:: type. Never generalize an unresolved tag through aliases or cells.
4879+::
4880+++ itype-has-tag
4881+ |= t=itype
4882+ ^- ?
4883+ ?- -.t
4884+ %tag &
4885+ %face $(t body.t)
4886+ %fn |($(t sample.t) $(t product.t))
4887+ %cell |($(t hed.t) $(t tal.t))
4888+ %union (lien cases.t |=(c=itype (itype-has-tag c)))
4889+ * |
4890+ ==
4891+::
4892+++ itype-has-union
4893+ |= t=itype
4894+ ^- ?
4895+ ?- -.t
4896+ %union &
4897+ %face $(t body.t)
4898+ %fn |($(t sample.t) $(t product.t))
4899+ %cell |($(t hed.t) $(t tal.t))
4900+ * |
4901+ ==
4902+::
4903+++ itype-fit-cases
4904+ |= [actual=itype cases=(list itype) sub=isub next=@ud]
4905+ ^- ifit
4906+ =/ good=(unit ifit) ~
4907+ =/ pending=? |
4908+ |-
4909+ ?~ cases
4910+ ?: pending [%unknown ~]
4911+ ?~ good [%bad ~]
4912+ u.good
4913+ =/ trial=ifit (itype-fit actual i.cases sub next)
4914+ ?- -.trial
4915+ %unknown $(cases t.cases, pending &)
4916+ %bad $(cases t.cases)
4917+ %ok
4918+ ?^ good [%unknown ~]
4919+ $(cases t.cases, good `trial)
4920+ ==
4921+::
4922+:: A constructor needs a case with its tag at the head and a payload
4923+:: compatible with the expected gate sample. Other case forms do not
4924+:: identify a constructor.
4925+::
4926+++ itype-fit-ctor-cases
4927+ |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
4928+ ^- ifit
4929+ =/ found=(unit ifit) ~
4930+ |-
4931+ ?~ cases ?~(found [%bad ~] u.found)
4932+ =/ c=itype (itype-walk i.cases sub)
4933+ ?. ?=(%cell -.c) $(cases t.cases)
4934+ =/ head=itype (itype-walk hed.c sub)
4935+ ?. ?=(%const -.head) $(cases t.cases)
4936+ ?. =(val.literal.head val.tag) $(cases t.cases)
4937+ ?^ found [%unknown ~]
4938+ =/ trial=ifit (itype-fit sample tal.c sub next)
4939+ $(cases t.cases, found `trial)
4940+::
48514941++ itype-fit
48524942 |= [actual=itype expected=itype sub=isub next=@ud]
48534943 ^- ifit
@@ -4856,6 +4946,51 @@
48564946 =. actual (itype-walk actual sub)
48574947 =. expected (itype-walk expected sub)
48584948 ?: =(actual expected) [%ok sub next]
4949+ ?: &(?=(%union -.actual) ?=(%union -.expected)) [%unknown ~]
4950+ ?: ?=(%union -.actual) [%unknown ~]
4951+ ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
4952+ ?: &(?=(%union -.expected) !?=(%var -.actual))
4953+ (itype-fit-cases actual cases.expected sub next)
4954+ ?: ?=(%tag -.actual)
4955+ ?: ?=(%var -.expected)
4956+ =/ u=(unit isub) (itype-unify actual expected sub)
4957+ ?~ u [%bad ~]
4958+ [%ok u.u next]
4959+ ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
4960+ ?: ?=(%face -.expected) $(expected body.expected)
4961+ ?: constructor.actual
4962+ ?. ?=(%fn -.expected) [%bad ~]
4963+ =/ product=itype (itype-walk product.expected sub)
4964+ =/ cases=(list itype) ?:(?=(%union -.product) cases.product ~[product])
4965+ =/ trial=ifit (itype-fit-ctor-cases literal.actual sample.expected cases sub next)
4966+ ?. ?=(%ok -.trial) trial
4967+ [%ok [[id.actual expected] sub.trial] next.trial]
4968+ ?: ?=(%const -.expected)
4969+ ?:(=(val.literal.actual val.literal.expected) [%ok [[id.actual expected] sub] next] [%bad ~])
4970+ ?: ?=(%atom -.expected)
4971+ ?: |(=(%tas aura.expected) =(%ta aura.expected))
4972+ [%ok [[id.actual expected] sub] next]
4973+ [%bad ~]
4974+ ?: ?=(%flag -.expected)
4975+ ?:(|(=(0 val.literal.actual) =(1 val.literal.actual)) [%ok [[id.actual expected] sub] next] [%bad ~])
4976+ ?: ?=(%any-atom -.expected) [%ok [[id.actual expected] sub] next]
4977+ [%bad ~]
4978+ ?: ?=(%const -.actual)
4979+ ?: ?=(%var -.expected)
4980+ =/ u=(unit isub) (itype-unify actual expected sub)
4981+ ?~ u [%bad ~]
4982+ [%ok u.u next]
4983+ ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
4984+ ?: ?=(%face -.expected) $(expected body.expected)
4985+ ?: ?=(%const -.expected)
4986+ ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
4987+ ?: ?=(%atom -.expected)
4988+ ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
4989+ [%bad ~]
4990+ ?: ?=(%flag -.expected)
4991+ ?:(|(=(0 val.literal.actual) =(1 val.literal.actual)) [%ok sub next] [%bad ~])
4992+ ?: ?=(%any-atom -.expected) [%ok sub next]
4993+ [%bad ~]
48594994 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
48604995 ?: ?=(%any-atom -.expected)
48614996 ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
@@ -4943,7 +5078,7 @@
49435078:: This core has no Ford dependencies; unrecognized payloads fail closed.
49445079+$ iexternals (list [module=term name=term result=*])
49455080+$ imark-externals (list [mark=term result=*])
4946−+$ istate [next=@ud sub=isub caps=icaps binders=(list @ud) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) params=iparams active=(list term) in-mold=?]
5081++$ istate [next=@ud sub=isub caps=icaps binders=(list @ud) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) params=iparams active=(list term) tags=(list @ud) in-mold=?]
49475082+$ idiag [msg=tape sites=(list [at=span note=tape])]
49485083+$ iresult (each [typ=itype state=istate] idiag)
49495084+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -4963,6 +5098,8 @@
49635098 |= [t=itype sub=isub]
49645099 ^- itype
49655100 =. t (itype-walk t sub)
5101+ ?: ?=(%union -.t)
5102+ [%union (turn cases.t |=(c=itype (itype-normalize c sub)))]
49665103 ?: ?=(%face -.t)
49675104 [%face name.t $(t body.t)]
49685105 ?: ?=(%fn -.t)
@@ -4983,6 +5120,9 @@
49835120 %fn &
49845121 %cell |($(t hed.t) $(t tal.t))
49855122 %face $(t body.t)
5123+ %union (lien cases.t |=(c=itype (itype-has-gate c)))
5124+ %tag |
5125+ %const |
49865126 %var |
49875127 %avar |
49885128 %nvar |
@@ -5012,6 +5152,9 @@
50125152 %atom ~
50135153 %any-atom ~
50145154 %flag ~
5155+ %tag ~
5156+ %const ~
5157+ %union (zing (turn cases.t |=(c=itype (itype-vars c))))
50155158 %face $(t body.t)
50165159 %fn (weld $(t sample.t) $(t product.t))
50175160 %cell (weld $(t hed.t) $(t tal.t))
@@ -5045,6 +5188,9 @@
50455188 %atom t
50465189 %any-atom t
50475190 %flag t
5191+ %tag t
5192+ %const t
5193+ %union [%union (turn cases.t |=(c=itype (itype-rename c ren)))]
50485194 %face [%face name.t $(t body.t)]
50495195 %fn [%fn $(t sample.t) $(t product.t)]
50505196 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5063,6 +5209,9 @@
50635209 %atom |
50645210 %any-atom |
50655211 %flag |
5212+ %tag |
5213+ %const |
5214+ %union (lien cases.t |=(c=itype (itype-var-is-atom n c)))
50665215 %face $(t body.t)
50675216 %fn |($(t sample.t) $(t product.t))
50685217 %cell |($(t hed.t) $(t tal.t))
@@ -5301,6 +5450,16 @@
53015450 ?: =(0 aura.sh) `[[%any-atom ~] state]
53025451 `[[%atom aura.sh] state]
53035452 %flag `[[%flag ~] state]
5453+ %const
5454+ ?. =(%term form.lit.sh) ~
5455+ `[[%const lit.sh] state]
5456+ %union
5457+ =/ pairs=(list upair) (union-pairs cases.sh molds.state)
5458+ ?. (levy pairs |=(p=upair =(%disjoint relation.p))) ~
5459+ =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
5460+ ?~ cs ~
5461+ ?: (lien types.u.cs |=(t=itype ?=(^ (itype-vars t)))) ~
5462+ `[[%union types.u.cs] state.u.cs]
53045463 %cell (infer-simple-fields fields.sh state)
53055464 %fn
53065465 =/ arg=(unit [typ=itype state=istate]) $(sh sample.sh)
@@ -5528,6 +5687,8 @@
55285687 =/ inferred=iresult (infer-fragment val.d env state)
55295688 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
55305689 =/ typ=itype (itype-normalize typ.p.inferred sub.state.p.inferred)
5690+ ?: |((pending-tags tags.state.p.inferred sub.state.p.inferred) (itype-has-tag typ))
5691+ $(ds t.ds, remaining [d remaining])
55315692 ?: (unsupported-atom-vars typ caps.state.p.inferred binders.state.p.inferred sub.state.p.inferred)
55325693 $(ds t.ds, remaining [d remaining])
55335694 =/ free=(list @ud)
@@ -5583,6 +5744,7 @@
55835744 %duration [%& [%atom %dr] state]
55845745 %knot [%& [%atom %ta] state]
55855746 %loobean [%& [%flag ~] state]
5747+ %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [next.state tags.state])]
55865748 * [%| ["literal needs contextual inference" ~]]
55875749 ==
55885750 %str
@@ -5604,6 +5766,7 @@
56045766 =/ instance=[typ=itype state=istate] (instantiate-scheme u.scheme state)
56055767 [%& typ.instance state.instance]
56065768 %group $(e inner.e)
5769+ %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [next.state tags.state])]
56075770 %trace
56085771 =/ traced=iresult $(e val.e)
56095772 ?: ?=(%| -.traced) traced
@@ -5653,6 +5816,8 @@
56535816 [%| ["branch widening is not supported by partial inference" ~]]
56545817 =/ joined=(unit isub) (itype-unify typ.p.left typ.p.right sub.state.p.right)
56555818 ?~ joined
5819+ ?: |((itype-has-tag ltype) (itype-has-tag rtype) (itype-has-union ltype) (itype-has-union rtype))
5820+ [%| ["branch tag or union context is not supported by partial inference" ~]]
56565821 =/ common=(unit itype) (itype-concrete-join typ.p.left typ.p.right sub.state.p.right)
56575822 ?^ common [%& u.common state.p.right]
56585823 ?: |((itype-has-face typ.p.left sub.state.p.right) (itype-has-face typ.p.right sub.state.p.right))
@@ -5710,8 +5875,7 @@
57105875 * [%| ["expression is not supported by partial inference" ~]]
57115876 ==
57125877::
5713−:: Unfaced tuple expressions are the one supported cell construction.
5714−:: Faced cells wait for the representation to preserve record faces.
5878+:: Tuple and record expressions preserve their explicitly written faces.
57155879::
57165880++ infer-simple-items
57175881 |= [items=(list item) env=ienv state=istate]
@@ -5774,6 +5938,9 @@
57745938 %atom "@{(trip aura.t)}"
57755939 %any-atom "@"
57765940 %flag "?"
5941+ %tag (trip txt.literal.t)
5942+ %const (trip txt.literal.t)
5943+ %union "<union>"
57775944 %face "[{(trip name.t)}={$(t body.t)}]"
57785945 %fn "$-({$(t sample.t)} {$(t product.t)})"
57795946 %cell "[{(show-itype-item hed.t sub)} {(show-itype-item tal.t sub)}]"
@@ -5799,6 +5966,9 @@
57995966 %atom |
58005967 %any-atom |
58015968 %flag |
5969+ %tag |
5970+ %const |
5971+ %union (lien cases.typ |=(c=itype (itype-has-nvar c)))
58025972 %face $(typ body.typ)
58035973 %fn |($(typ sample.typ) $(typ product.typ))
58045974 %cell |($(typ hed.typ) $(typ tal.typ))
@@ -5808,7 +5978,7 @@
58085978 |= [label=tape typ=itype sub=isub]
58095979 ^- tape
58105980 =/ normalized=itype (itype-normalize typ sub)
5811− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized)) label
5981+ ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
58125982 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
58135983 ?: (gth (lent vars) 26) label
58145984 =/ printable=itype (canonical-itype normalized vars)
@@ -5850,6 +6020,9 @@
58506020 %atom |
58516021 %any-atom |
58526022 %flag |
6023+ %tag |
6024+ %const |
6025+ %union (lien cases.t |=(c=itype (has-atom-var n c)))
58536026 %face $(t body.t)
58546027 %fn |($(t sample.t) $(t product.t))
58556028 %cell |($(t hed.t) $(t tal.t))
@@ -5924,10 +6097,11 @@
59246097 ?: ?=(%mold -.d) $(ds t.ds)
59256098 ?. (unique-value-name name.d globals) $(ds t.ds)
59266099 ?^ (ienv-lookup name.d env) $(ds t.ds)
5927− =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ |])
6100+ =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ |])
59286101 ?: ?=(%| -.result) $(ds t.ds)
59296102 ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
59306103 =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
6104+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
59316105 ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
59326106 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
59336107 ?: (gth (lent vars) 26) $(ds t.ds)
@@ -6233,7 +6407,7 @@
62336407 =/ surs=(list term) (collect-sur-imports imports.mod)
62346408 =/ marks=(list term) (collect-mark-imports imports.mod)
62356409 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
6236− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ |]
6410+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ |]
62376411 =/ mts=(each imold-types @t) (module-mold-types molds state)
62386412 ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
62396413 =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved)
@@ -6306,12 +6480,16 @@
63066480 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
63076481 ?. (unique-value-name name.d globals)
63086482 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
6309− =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ |])
6483+ =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ |])
63106484 ?: ?=(%| -.result)
63116485 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
63126486 ?: (constrained-capitals caps.state.p.result sub.state.p.result)
63136487 $(ds t.ds, lines [(crip "++ {(trip name.d)}: explicit capital constraints are not supported by partial inference") lines])
63146488 =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
6489+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ))
6490+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: tag needs context in partial inference") lines])
6491+ ?: (itype-has-union typ)
6492+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: union type printing is not supported by partial inference") lines])
63156493 ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result)
63166494 $(ds t.ds, lines [(crip "++ {(trip name.d)}: unresolved aura-variable inference") lines])
63176495 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))