@@ -4595,8 +4595,9 @@
45954595:: their defaulting and inferred generalization are implemented.
45964596:: Bare @ is a separate unrestricted atom type. A directional fit check
45974597:: permits concrete atoms to widen to it, never the reverse. A fit that
4598−:: needs a not-yet-implemented constraint remains unsupported. Only
4599−:: unfaced cells are represented here.
4598+:: needs a not-yet-implemented constraint remains unsupported. Named closed
4599+:: unions retain their module of origin separately from their
4600+:: displayed name. Union printing is informational; it is not Jibb syntax.
46004601::
46014602+$ itype
46024603 $~ [%var 0]
@@ -4608,7 +4609,7 @@
46084609 [%flag ~]
46094610 [%tag id=@ud literal=lit constructor=?]
46104611 [%const literal=lit]
4611− [%union cases=(list itype)]
4612+ [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t)]
46124613 [%face name=term body=itype]
46134614 [%fn sample=itype product=itype]
46144615 [%cell hed=itype tal=itype]
@@ -4676,6 +4677,9 @@
46764677 =. a (itype-walk a sub)
46774678 =. b (itype-walk b sub)
46784679 ?: =(a b) `sub
4680+ ?: &(?=(%union -.a) ?=(%union -.b))
4681+ ?: &(=(origin.a origin.b) =(cases.a cases.b)) `sub
4682+ ~
46794683 ?: ?=(%var -.a)
46804684 ?: (itype-occurs id.a b sub) ~
46814685 `[[id.a b] sub]
@@ -4946,7 +4950,9 @@
49464950 =. actual (itype-walk actual sub)
49474951 =. expected (itype-walk expected sub)
49484952 ?: =(actual expected) [%ok sub next]
4949− ?: &(?=(%union -.actual) ?=(%union -.expected)) [%unknown ~]
4953+ ?: &(?=(%union -.actual) ?=(%union -.expected))
4954+ ?: &(=(origin.actual origin.expected) =(cases.actual cases.expected)) [%ok sub next]
4955+ [%unknown ~]
49504956 ?: ?=(%union -.actual) [%unknown ~]
49514957 ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
49524958 ?: &(?=(%union -.expected) !?=(%var -.actual))
@@ -5032,6 +5038,7 @@
50325038 [%unknown ~]
50335039 =/ unified=(unit isub) (itype-unify actual expected sub)
50345040 ?~ unified
5041+ ?: |((itype-has-union (itype-normalize actual sub)) (itype-has-union (itype-normalize expected sub))) [%unknown ~]
50355042 ?: (itype-family-related actual expected sub) [%unknown ~]
50365043 [%bad ~]
50375044 [%ok u.unified next]
@@ -5069,7 +5076,7 @@
50695076+$ ischeme [typ=itype vars=(list @ud)]
50705077+$ ienv (list [name=term scheme=ischeme])
50715078+$ imold-types (list [name=term template=ischeme])
5072−+$ ifile [values=ienv molds=imold-types]
5079++$ ifile [values=ienv molds=imold-types at=path]
50735080+$ ijimports (list [face=term interface=ifile])
50745081+$ icaps (list [name=@t id=@ud])
50755082+$ iparams (list [name=@t typ=itype])
@@ -5078,7 +5085,7 @@
50785085:: This core has no Ford dependencies; unrecognized payloads fail closed.
50795086+$ iexternals (list [module=term name=term result=*])
50805087+$ imark-externals (list [mark=term result=*])
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=?]
5088++$ 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=? at=path top-molds=(list term)]
50825089+$ idiag [msg=tape sites=(list [at=span note=tape])]
50835090+$ iresult (each [typ=itype state=istate] idiag)
50845091+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5099,7 +5106,7 @@
50995106 ^- itype
51005107 =. t (itype-walk t sub)
51015108 ?: ?=(%union -.t)
5102− [%union (turn cases.t |=(c=itype (itype-normalize c sub)))]
5109+ [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t]
51035110 ?: ?=(%face -.t)
51045111 [%face name.t $(t body.t)]
51055112 ?: ?=(%fn -.t)
@@ -5190,7 +5197,7 @@
51905197 %flag t
51915198 %tag t
51925199 %const t
5193− %union [%union (turn cases.t |=(c=itype (itype-rename c ren)))]
5200+ %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t]
51945201 %face [%face name.t $(t body.t)]
51955202 %fn [%fn $(t sample.t) $(t product.t)]
51965203 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5369,6 +5376,47 @@
53695376 ?: =(name name.i.ms) `template.i.ms
53705377 $(ms t.ms)
53715378::
5379+:: An exported alias may name a union from another module. Only a
5380+:: nongeneric alias of the same origin is usable through this import face.
5381+::
5382+++ imported-union-alias
5383+ |= [origin=[at=path name=term] molds=imold-types]
5384+ ^- (unit term)
5385+ ?~ molds ~
5386+ =/ template=ischeme template.i.molds
5387+ ?: &(?=(~ vars.template) ?=(%union -.typ.template))
5388+ ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
5389+ $(molds t.molds)
5390+::
5391+:: Only names exported by this directly imported module are visible through
5392+:: its face. Other origins retain identity but print as unnamed unions.
5393+::
5394+++ itype-in-import
5395+ |= [t=itype iface=ifile face=term]
5396+ ^- itype
5397+ ?- -.t
5398+ %union
5399+ =/ label=(unit @t)
5400+ ?~ origin.t ~
5401+ =/ alias=(unit term) ~
5402+ =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
5403+ =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
5404+ ?~ alias ~
5405+ `(crip "{(trip u.alias)}.{(trip face)}")
5406+ [%union (turn cases.t |=(c=itype (itype-in-import c iface face))) origin.t label]
5407+ %face [%face name.t $(t body.t)]
5408+ %fn [%fn $(t sample.t) $(t product.t)]
5409+ %cell [%cell $(t hed.t) $(t tal.t)]
5410+ * t
5411+ ==
5412+::
5413+++ label-direct-union
5414+ |= [typ=itype body=shape name=term state=istate]
5415+ ^- itype
5416+ ?. &(?=(%union -.body) ?=(%union -.typ)) typ
5417+ ?. (lien top-molds.state |=(n=term =(n name))) typ
5418+ [%union cases.typ `[at.state name] `name]
5419+::
53725420:: Generic mold parameters are lexical and distinct from the enclosing
53735421:: value's capital variables. Arguments are substituted only once, so
53745422:: an argument's variable ID cannot be captured by a template ID.
@@ -5433,6 +5481,8 @@
54335481 =/ out=(unit [typ=itype state=istate])
54345482 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
54355483 ?~ out ~
5484+ :: Generic union identity must include its arguments; defer that case.
5485+ ?: ?=(%union -.typ.u.out) ~
54365486 =/ used=(list @ud) (itype-vars typ.u.out)
54375487 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
54385488 `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state)]
@@ -5459,7 +5509,7 @@
54595509 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
54605510 ?~ cs ~
54615511 ?: (lien types.u.cs |=(t=itype ?=(^ (itype-vars t)))) ~
5462− `[[%union types.u.cs] state.u.cs]
5512+ `[[%union types.u.cs ~ ~] state.u.cs]
54635513 %cell (infer-simple-fields fields.sh state)
54645514 %fn
54655515 =/ arg=(unit [typ=itype state=istate]) $(sh sample.sh)
@@ -5477,7 +5527,7 @@
54775527 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
54785528 ?~ found ~
54795529 ?^ vars.u.found ~
5480− `[typ.u.found state]
5530+ `[(itype-in-import typ.u.found u.iface i.t.names.sh) state]
54815531 =/ found=(unit itype)
54825532 (find-imported-mold i.t.names.sh n externals.state surs.state)
54835533 ?~ found ~
@@ -5493,7 +5543,7 @@
54935543 =/ out=(unit [typ=itype state=istate])
54945544 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
54955545 ?~ out ~
5496− `[typ.u.out state.u.out(active active.state, in-mold in-mold.state, params params.state)]
5546+ `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state)]
54975547 %apply
54985548 ?~ ref.sh ~
54995549 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
@@ -5508,7 +5558,7 @@
55085558 ?~ vars.u.template ~
55095559 =/ applied=(unit itype) (template-apply u.template types.u.args)
55105560 ?~ applied ~
5511− `[u.applied state.u.args]
5561+ `[(itype-in-import u.applied u.iface i.t.ref.sh) state.u.args]
55125562 ?: (lien active.state.u.args |=(x=term =(x n))) ~
55135563 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
55145564 ?~ found ~
@@ -5519,6 +5569,7 @@
55195569 =/ out=(unit [typ=itype state=istate])
55205570 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
55215571 ?~ out ~
5572+ ?: ?=(%union -.typ.u.out) ~
55225573 `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args)]
55235574 %tvar
55245575 =/ param=(unit itype) (iparam-lookup name.sh params.state)
@@ -5759,6 +5810,7 @@
57595810 ?~ iface (infer-field-wing names.e env state)
57605811 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
57615812 ?~ member [%| ["module member is not available to partial inference" ~]]
5813+ =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e)
57625814 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
57635815 [%& typ.instance state.instance]
57645816 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
@@ -5940,9 +5992,9 @@
59405992 %flag "?"
59415993 %tag (trip txt.literal.t)
59425994 %const (trip txt.literal.t)
5943− %union "<union>"
5944− %face "[{(trip name.t)}={$(t body.t)}]"
5945− %fn "$-({$(t sample.t)} {$(t product.t)})"
5995+ %union ?~(label.t (show-itype-cases cases.t sub) (trip u.label.t))
5996+ %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
5997+ %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
59465998 %cell "[{(show-itype-item hed.t sub)} {(show-itype-item tal.t sub)}]"
59475999 ==
59486000::
@@ -5950,9 +6002,23 @@
59506002 |= [t=itype sub=isub]
59516003 ^- tape
59526004 =. t (itype-walk t sub)
5953− ?: ?=(%face -.t) "{(trip name.t)}={(show-itype body.t sub)}"
6005+ ?: ?=(%face -.t) "{(trip name.t)}={(show-itype-context body.t sub)}"
6006+ (show-itype-context t sub)
6007+::
6008+++ show-itype-context
6009+ |= [t=itype sub=isub]
6010+ ^- tape
6011+ =. t (itype-walk t sub)
6012+ ?: &(?=(%union -.t) ?=(~ label.t)) "({(show-itype t sub)})"
59546013 (show-itype t sub)
59556014::
6015+++ show-itype-cases
6016+ |= [cases=(list itype) sub=isub]
6017+ ^- tape
6018+ ?~ cases ""
6019+ ?~ t.cases (show-itype-context i.cases sub)
6020+ "{(show-itype-context i.cases sub)} {$(cases t.cases)}"
6021+::
59566022:: Include the type at a conflicting site where it can be printed.
59576023:: A lone unresolved variable or decimal variable keeps the neutral label.
59586024::
@@ -6090,14 +6156,15 @@
60906156 |
60916157::
60926158++ add-supported-defs
6093− |= [ds=(list def) env=ienv molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term)]
6159+ |= [ds=(list def) env=ienv molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) at=path]
60946160 ^- ienv
60956161 ?~ ds env
60966162 =/ d=def i.ds
60976163 ?: ?=(%mold -.d) $(ds t.ds)
60986164 ?. (unique-value-name name.d globals) $(ds t.ds)
60996165 ?^ (ienv-lookup name.d env) $(ds t.ds)
6100− =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ |])
6166+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
6167+ =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top])
61016168 ?: ?=(%| -.result) $(ds t.ds)
61026169 ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
61036170 =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
@@ -6108,11 +6175,11 @@
61086175 $(ds t.ds, env [[name.d [typ vars]] env])
61096176::
61106177++ resolve-supported-defs
6111− |= [ds=(list def) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term)]
6178+ |= [ds=(list def) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) at=path]
61126179 ^- ienv
61136180 =/ env=ienv ~
61146181 |-
6115− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds)
6182+ =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at)
61166183 ?: =(next env) env
61176184 $(env next)
61186185::
@@ -6345,6 +6412,7 @@
63456412 =/ t=(unit [template=ischeme state=istate])
63466413 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
63476414 ?~ t [%| 'module mold needs unsupported inference']
6415+ =. typ.template.u.t (label-direct-union typ.template.u.t body.m name.m state)
63486416 =/ rest=(each imold-types @t) $(molds t.molds)
63496417 ?: ?=(%| -.rest) rest
63506418 [%& [[name.m template.u.t] p.rest]]
@@ -6407,13 +6475,14 @@
64076475 =/ surs=(list term) (collect-sur-imports imports.mod)
64086476 =/ marks=(list term) (collect-mark-imports imports.mod)
64096477 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
6410− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ |]
6478+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
6479+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top]
64116480 =/ mts=(each imold-types @t) (module-mold-types molds state)
64126481 ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
6413− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved)
6482+ =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at)
64146483 ?. (module-values-complete defs.mod env)
64156484 [%| (crip "module definitions need unsupported inference: {(spud at)}")]
6416− [%& [[env p.mts] [[at [env p.mts]] cache.p.js]]]
6485+ [%& [[env p.mts at] [[at [env p.mts at]] cache.p.js]]]
64176486::
64186487:: +golden-types-with-modules fails closed for imports without prelude
64196488:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -6471,7 +6540,7 @@
64716540 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
64726541 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
64736542 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
6474− =/ env=ienv (resolve-supported-defs ds molds globals externals surs mark-externals marks jimports reserved-molds)
6543+ =/ env=ienv (resolve-supported-defs ds molds globals externals surs mark-externals marks jimports reserved-molds file)
64756544 =/ lines=(list @t) ~
64766545 |-
64776546 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -6480,7 +6549,8 @@
64806549 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
64816550 ?. (unique-value-name name.d globals)
64826551 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
6483− =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ |])
6552+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
6553+ =/ result=iresult (infer-fragment val.d env [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top])
64846554 ?: ?=(%| -.result)
64856555 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
64866556 ?: (constrained-capitals caps.state.p.result sub.state.p.result)
@@ -6488,8 +6558,6 @@
64886558 =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
64896559 ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ))
64906560 $(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])
64936561 ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result)
64946562 $(ds t.ds, lines [(crip "++ {(trip name.d)}: unresolved aura-variable inference") lines])
64956563 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))