@@ -5131,10 +5131,84 @@
51315131 ?: (aura-prefix aura.a aura.b) `a
51325132 ?: (aura-prefix aura.b aura.a) `b
51335133 ~
5134− ?: &(?=(%any-atom -.a) |(?=(%atom -.b) ?=(%flag -.b))) `a
5135− ?: &(?=(%any-atom -.b) |(?=(%atom -.a) ?=(%flag -.a))) `b
5134+ ?: &(?=(%any-atom -.a) |(?=(%atom -.b) ?=(%flag -.b) ?=(%const -.b) ?=(%avar -.b) ?=(%rvar -.b) ?=(%nvar -.b) ?=(%rnvar -.b))) `a
5135+ ?: &(?=(%any-atom -.b) |(?=(%atom -.a) ?=(%flag -.a) ?=(%const -.a) ?=(%avar -.a) ?=(%rvar -.a) ?=(%nvar -.a) ?=(%rnvar -.a))) `b
51365136 ~
51375137::
5138+++ itype-branch-join
5139+ |= [a=itype b=itype sub=isub]
5140+ ^- (unit [typ=itype sub=isub])
5141+ =/ unified=(unit isub) (itype-unify a b sub)
5142+ ?^ unified `[(itype-normalize a u.unified) u.unified]
5143+ =/ common=(unit itype) (itype-concrete-join a b sub)
5144+ ?~ common ~
5145+ `[u.common sub]
5146+::
5147+++ itype-branch-join-with
5148+ |= [candidate=itype types=(list itype) sub=isub]
5149+ ^- (unit [typ=itype sub=isub])
5150+ ?~ types `[(itype-normalize candidate sub) sub]
5151+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join candidate i.types sub)
5152+ ?~ joined ~
5153+ $(candidate typ.u.joined, types t.types, sub sub.u.joined)
5154+::
5155+++ itype-branch-unify-list
5156+ |= [types=(list itype) sub=isub]
5157+ ^- (unit [typ=itype sub=isub])
5158+ ?~ types ~
5159+ =/ candidate=itype i.types
5160+ =/ rest=(list itype) t.types
5161+ |-
5162+ ?~ rest `[(itype-normalize candidate sub) sub]
5163+ =/ unified=(unit isub) (itype-unify candidate i.rest sub)
5164+ ?~ unified ~
5165+ $(candidate (itype-normalize candidate u.unified), rest t.rest, sub u.unified)
5166+::
5167+++ itype-branch-any-atom
5168+ |= [types=(list itype) sub=isub]
5169+ ^- (unit itype)
5170+ ?~ types ~
5171+ =/ typ=itype (itype-walk i.types sub)
5172+ ?: ?=(%any-atom -.typ) `typ
5173+ $(types t.types)
5174+::
5175+++ itype-branch-atom-parent
5176+ |= [candidate=itype types=(list itype) sub=isub]
5177+ ^- (unit itype)
5178+ ?~ types `candidate
5179+ =/ typ=itype (itype-walk i.types sub)
5180+ ?. ?=(%atom -.typ) $(types t.types)
5181+ =/ joined=(unit itype) (itype-concrete-join candidate typ sub)
5182+ ?~ joined ~
5183+ $(candidate u.joined, types t.types)
5184+::
5185+++ itype-branch-atom-candidates
5186+ |= [candidates=(list itype) types=(list itype) sub=isub]
5187+ ^- (unit itype)
5188+ ?~ candidates ~
5189+ =/ candidate=itype (itype-walk i.candidates sub)
5190+ ?. ?=(%atom -.candidate) $(candidates t.candidates)
5191+ =/ parent=(unit itype) (itype-branch-atom-parent candidate types sub)
5192+ ?^ parent parent
5193+ $(candidates t.candidates)
5194+::
5195+++ itype-branch-parent
5196+ |= [types=(list itype) sub=isub]
5197+ ^- (unit itype)
5198+ =/ unrestricted=(unit itype) (itype-branch-any-atom types sub)
5199+ ?^ unrestricted unrestricted
5200+ (itype-branch-atom-candidates types types sub)
5201+::
5202+++ itype-branch-join-list
5203+ |= [types=(list itype) sub=isub]
5204+ ^- (unit [typ=itype sub=isub])
5205+ ?~ types ~
5206+ =/ unified=(unit [typ=itype sub=isub]) (itype-branch-unify-list types sub)
5207+ ?^ unified unified
5208+ =/ parent=(unit itype) (itype-branch-parent types sub)
5209+ ?~ parent ~
5210+ (itype-branch-join-with u.parent types sub)
5211+::
51385212:: Unifying an already-bound tuple with a faced position would need to
51395213:: update the bound type. Until substitutions can retain that information,
51405214:: variable-dependent face merges stay unresolved.
@@ -7952,9 +8026,9 @@
79528026 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
79538027 ?: ?=(%| -.right) right
79548028 ?^ expected [%& typ.u.expected state.p.right]
7955− =/ joined=(unit isub) (itype-unify typ.p.left typ.p.right sub.state.p.right)
8029+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join typ.p.left typ.p.right sub.state.p.right)
79568030 ?~ joined [%| ["list branch results need unsupported inference" ~]]
7957− [%& typ.p.left state.p.right(sub u.joined)]
8031+ [%& typ.u.joined state.p.right(sub sub.u.joined)]
79588032::
79598033++ infer-unit-branch
79608034 |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
@@ -7996,9 +8070,9 @@
79968070 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
79978071 ?: ?=(%| -.right) right
79988072 ?^ expected [%& typ.u.expected state.p.right]
7999− =/ joined=(unit isub) (itype-unify typ.p.left typ.p.right sub.state.p.right)
8073+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join typ.p.left typ.p.right sub.state.p.right)
80008074 ?~ joined [%| ["unit branch results need unsupported inference" ~]]
8001− [%& typ.p.left state.p.right(sub u.joined)]
8075+ [%& typ.u.joined state.p.right(sub sub.u.joined)]
80028076::
80038077:: Infer pieces in order, retaining their substitutions and pending tags.
80048078:: A bare decimal literal has no outside type constraint, so it takes its
@@ -8144,13 +8218,14 @@
81448218 =/ remaining=(list itype) cases
81458219 =/ arms=(list arm) arms.e
81468220 =/ st=istate state.p.subject
8147− =/ answer=(unit itype) ~
8221+ =/ results=(list itype) ~
81488222 |-
81498223 ?~ arms
81508224 ?^ remaining
81518225 `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
8152− ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
8153− `[%& u.answer st]
8226+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join-list (flop results) sub.st)
8227+ ?~ joined `[%| ["union branch result matching needs unsupported inference" ~]]
8228+ `[%& typ.u.joined st(sub sub.u.joined)]
81548229 =/ a=arm i.arms
81558230 ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
81568231 ~
@@ -8166,9 +8241,7 @@
81668241 =/ body=iresult (infer-fragment val.a u.bound st)
81678242 ?: ?=(%| -.body) `body
81688243 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8169− =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
8170− ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
8171− $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
8244+ $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, results [result results])
81728245::
81738246++ infer-known-union-context-whole
81748247 |= [e=expr expected=itype env=ienv subject=iresult context=span]
@@ -8231,14 +8304,16 @@
82318304 =/ remaining=(list ifinite) cases
82328305 =/ arms=(list arm) arms.e
82338306 =/ st=istate state.p.subject
8234− =/ answer=(unit itype) ~
8307+ =/ results=(list itype) ~
82358308 |-
82368309 ?~ arms
82378310 ?^ remaining
82388311 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
8239− ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
8240− ?~ expected [%& u.answer st]
8241− [%& typ.u.expected st]
8312+ ?~ results [%| ["empty union branch is not supported by partial inference" ~]]
8313+ ?^ expected [%& typ.u.expected st]
8314+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join-list (flop results) sub.st)
8315+ ?~ joined [%| ["union branch result matching needs unsupported inference" ~]]
8316+ [%& typ.u.joined st(sub sub.u.joined)]
82428317 =/ a=arm i.arms
82438318 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
82448319 [%| ["partial union pattern is not supported by partial inference" ~]]
@@ -8266,11 +8341,9 @@
82668341 [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
82678342 ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
82688343 [%| ["union branch result needs context in partial inference" ~]]
8269− $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body(sub sub.fit, next next.fit), answer `typ.u.expected)
8344+ $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body(sub sub.fit, next next.fit), results [typ.p.body results])
82708345 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8271− =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
8272− ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
8273− $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
8346+ $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, results [result results])
82748347::
82758348:: Prove a one-arm record pattern covers a known, non-union subject.
82768349:: Variable or partial matches stay unsupported; binding uses the same
@@ -8843,22 +8916,18 @@
88438916 ?: ?=(%| -.right) right
88448917 =/ ltype=itype (itype-normalize typ.p.left sub.state.p.right)
88458918 =/ rtype=itype (itype-normalize typ.p.right sub.state.p.right)
8846− ?: &(!=(ltype rtype) |(?=(^ (itype-vars ltype)) ?=(^ (itype-vars rtype))) |((itype-has-fixed-atom ltype) (itype-has-fixed-atom rtype)))
8847− [%| ["branch widening is not supported by partial inference" ~]]
8848− =/ joined=(unit isub) (itype-unify typ.p.left typ.p.right sub.state.p.right)
8919+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join typ.p.left typ.p.right sub.state.p.right)
88498920 ?~ joined
88508921 ?: |((itype-has-recursive ltype) (itype-has-recursive rtype))
88518922 [%| ["recursive branch matching is not supported by partial inference" ~]]
88528923 ?: |((itype-has-tag ltype) (itype-has-tag rtype) (itype-has-union ltype) (itype-has-union rtype))
88538924 [%| ["branch tag or union context is not supported by partial inference" ~]]
8854− =/ common=(unit itype) (itype-concrete-join typ.p.left typ.p.right sub.state.p.right)
8855− ?^ common [%& u.common state.p.right]
88568925 ?: |((itype-has-face typ.p.left sub.state.p.right) (itype-has-face typ.p.right sub.state.p.right))
88578926 [%| ["record branch matching is not supported by partial inference" ~]]
88588927 ?: |((itype-has-any-atom typ.p.left sub.state.p.right) (itype-has-any-atom typ.p.right sub.state.p.right) (itype-family-related typ.p.left typ.p.right sub.state.p.right))
88598928 [%| ["branch widening is not supported by partial inference" ~]]
88608929 [%| ["branch arms have incompatible types" ~[[(span-of val.x) (site-type-note "first arm" typ.p.left sub.state.p.right)] [(span-of val.y) (site-type-note "second arm" typ.p.right sub.state.p.right)]]]]
8861− [%& typ.p.left state.p.right(sub u.joined)]
8930+ [%& typ.u.joined state.p.right(sub sub.u.joined)]
88628931 %cast
88638932 =/ target=(unit [typ=itype state=istate]) (infer-simple-shape shape.e state)
88648933 ?~ target
@@ -15293,6 +15362,8 @@
1529315362 ?: ?=(%| -.left) left
1529415363 =/ right=iresult (infer-fragment val.y env state.p.left)
1529515364 ?: ?=(%| -.right) right
15365+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join typ.p.left typ.p.right sub.state.p.right)
15366+ ?^ joined [%& typ.u.joined state.p.right(sub sub.u.joined)]
1529615367 ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
1529715368 =/ st=istate state.p.right
1529815369 ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)