@@ -5131,10 +5131,84 @@
5131 ?: (aura-prefix aura.a aura.b) `a
5131 ?: (aura-prefix aura.a aura.b) `a
5132 ?: (aura-prefix aura.b aura.a) `b
5132 ?: (aura-prefix aura.b aura.a) `b
5134− ?: &(?=(%any-atom -.a) |(?=(%atom -.b) ?=(%flag -.b))) `a
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))) `b
5135+ ?: &(?=(%any-atom -.b) |(?=(%atom -.a) ?=(%flag -.a) ?=(%const -.a) ?=(%avar -.a) ?=(%rvar -.a) ?=(%nvar -.a) ?=(%rnvar -.a))) `b
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)
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)
5153+ $(candidate typ.u.joined, types t.types, sub sub.u.joined)
5155+++ itype-branch-unify-list
5156+ |= [types=(list itype) sub=isub]
5157+ ^- (unit [typ=itype sub=isub])
5159+ =/ candidate=itype i.types
5160+ =/ rest=(list itype) t.types
5162+ ?~ rest `[(itype-normalize candidate sub) sub]
5163+ =/ unified=(unit isub) (itype-unify candidate i.rest sub)
5165+ $(candidate (itype-normalize candidate u.unified), rest t.rest, sub u.unified)
5167+++ itype-branch-any-atom
5168+ |= [types=(list itype) sub=isub]
5171+ =/ typ=itype (itype-walk i.types sub)
5172+ ?: ?=(%any-atom -.typ) `typ
5175+++ itype-branch-atom-parent
5176+ |= [candidate=itype types=(list itype) sub=isub]
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)
5183+ $(candidate u.joined, types t.types)
5185+++ itype-branch-atom-candidates
5186+ |= [candidates=(list itype) types=(list itype) sub=isub]
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)
5193+ $(candidates t.candidates)
5195+++ itype-branch-parent
5196+ |= [types=(list itype) sub=isub]
5198+ =/ unrestricted=(unit itype) (itype-branch-any-atom types sub)
5199+ ?^ unrestricted unrestricted
5200+ (itype-branch-atom-candidates types types sub)
5202+++ itype-branch-join-list
5203+ |= [types=(list itype) sub=isub]
5204+ ^- (unit [typ=itype sub=isub])
5206+ =/ unified=(unit [typ=itype sub=isub]) (itype-branch-unify-list types sub)
5208+ =/ parent=(unit itype) (itype-branch-parent types sub)
5210+ (itype-branch-join-with u.parent types sub)
5138:: Unifying an already-bound tuple with a faced position would need to
5212:: Unifying an already-bound tuple with a faced position would need to
5139:: update the bound type. Until substitutions can retain that information,
5213:: update the bound type. Until substitutions can retain that information,
5140:: variable-dependent face merges stay unresolved.
5214:: variable-dependent face merges stay unresolved.
@@ -7952,9 +8026,9 @@
7952 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
8026 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
7953 ?: ?=(%| -.right) right
8027 ?: ?=(%| -.right) right
7954 ?^ expected [%& typ.u.expected state.p.right]
8028 ?^ 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)
7956 ?~ joined [%| ["list branch results need unsupported inference" ~]]
8030 ?~ 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)]
7959++ infer-unit-branch
8033++ infer-unit-branch
7960 |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
8034 |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
@@ -7996,9 +8070,9 @@
7996 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
8070 (infer-union-context val.y typ.u.expected ?:(first-empty extended env) state.p.left context.u.expected)
7997 ?: ?=(%| -.right) right
8071 ?: ?=(%| -.right) right
7998 ?^ expected [%& typ.u.expected state.p.right]
8072 ?^ 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)
8000 ?~ joined [%| ["unit branch results need unsupported inference" ~]]
8074 ?~ 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)]
8003:: Infer pieces in order, retaining their substitutions and pending tags.
8077:: Infer pieces in order, retaining their substitutions and pending tags.
8004:: A bare decimal literal has no outside type constraint, so it takes its
8078:: A bare decimal literal has no outside type constraint, so it takes its
@@ -8144,13 +8218,14 @@
8144 =/ remaining=(list itype) cases
8218 =/ remaining=(list itype) cases
8145 =/ arms=(list arm) arms.e
8219 =/ arms=(list arm) arms.e
8146 =/ st=istate state.p.subject
8220 =/ st=istate state.p.subject
8147− =/ answer=(unit itype) ~
8221+ =/ results=(list itype) ~
8150 ?^ remaining
8224 ?^ remaining
8151 `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
8225 `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
8152− ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
8226+ =/ joined=(unit [typ=itype sub=isub]) (itype-branch-join-list (flop results) sub.st)
8153− `[%& u.answer st]
8227+ ?~ joined `[%| ["union branch result matching needs unsupported inference" ~]]
8228+ `[%& typ.u.joined st(sub sub.u.joined)]
8154 =/ a=arm i.arms
8229 =/ a=arm i.arms
8155 ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
8230 ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
@@ -8166,9 +8241,7 @@
8166 =/ body=iresult (infer-fragment val.a u.bound st)
8241 =/ body=iresult (infer-fragment val.a u.bound st)
8167 ?: ?=(%| -.body) `body
8242 ?: ?=(%| -.body) `body
8168 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8243 =/ 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])
8173++ infer-known-union-context-whole
8246++ infer-known-union-context-whole
8174 |= [e=expr expected=itype env=ienv subject=iresult context=span]
8247 |= [e=expr expected=itype env=ienv subject=iresult context=span]
@@ -8231,14 +8304,16 @@
8231 =/ remaining=(list ifinite) cases
8304 =/ remaining=(list ifinite) cases
8232 =/ arms=(list arm) arms.e
8305 =/ arms=(list arm) arms.e
8233 =/ st=istate state.p.subject
8306 =/ st=istate state.p.subject
8234− =/ answer=(unit itype) ~
8307+ =/ results=(list itype) ~
8237 ?^ remaining
8310 ?^ remaining
8238 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
8311 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
8239− ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
8312+ ?~ results [%| ["empty union branch is not supported by partial inference" ~]]
8240− ?~ expected [%& u.answer st]
8313+ ?^ expected [%& typ.u.expected st]
8241− [%& 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)]
8242 =/ a=arm i.arms
8317 =/ a=arm i.arms
8243 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
8318 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
8244 [%| ["partial union pattern is not supported by partial inference" ~]]
8319 [%| ["partial union pattern is not supported by partial inference" ~]]
@@ -8266,11 +8341,9 @@
8266 [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
8341 [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
8267 ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8342 ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8268 [%| ["union branch result needs context in partial inference" ~]]
8343 [%| ["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])
8270 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8345 =/ 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])
8275:: Prove a one-arm record pattern covers a known, non-union subject.
8348:: Prove a one-arm record pattern covers a known, non-union subject.
8276:: Variable or partial matches stay unsupported; binding uses the same
8349:: Variable or partial matches stay unsupported; binding uses the same
@@ -8843,22 +8916,18 @@
8843 ?: ?=(%| -.right) right
8916 ?: ?=(%| -.right) right
8844 =/ ltype=itype (itype-normalize typ.p.left sub.state.p.right)
8917 =/ ltype=itype (itype-normalize typ.p.left sub.state.p.right)
8845 =/ rtype=itype (itype-normalize typ.p.right sub.state.p.right)
8918 =/ 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)
8849 ?~ joined
8920 ?~ joined
8850 ?: |((itype-has-recursive ltype) (itype-has-recursive rtype))
8921 ?: |((itype-has-recursive ltype) (itype-has-recursive rtype))
8851 [%| ["recursive branch matching is not supported by partial inference" ~]]
8922 [%| ["recursive branch matching is not supported by partial inference" ~]]
8852 ?: |((itype-has-tag ltype) (itype-has-tag rtype) (itype-has-union ltype) (itype-has-union rtype))
8923 ?: |((itype-has-tag ltype) (itype-has-tag rtype) (itype-has-union ltype) (itype-has-union rtype))
8853 [%| ["branch tag or union context is not supported by partial inference" ~]]
8924 [%| ["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]
8856 ?: |((itype-has-face typ.p.left sub.state.p.right) (itype-has-face typ.p.right sub.state.p.right))
8925 ?: |((itype-has-face typ.p.left sub.state.p.right) (itype-has-face typ.p.right sub.state.p.right))
8857 [%| ["record branch matching is not supported by partial inference" ~]]
8926 [%| ["record branch matching is not supported by partial inference" ~]]
8858 ?: |((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))
8927 ?: |((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))
8859 [%| ["branch widening is not supported by partial inference" ~]]
8928 [%| ["branch widening is not supported by partial inference" ~]]
8860 [%| ["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)]]]]
8929 [%| ["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)]
8863 =/ target=(unit [typ=itype state=istate]) (infer-simple-shape shape.e state)
8932 =/ target=(unit [typ=itype state=istate]) (infer-simple-shape shape.e state)
8864 ?~ target
8933 ?~ target
@@ -15293,6 +15362,8 @@
15293 ?: ?=(%| -.left) left
15362 ?: ?=(%| -.left) left
15294 =/ right=iresult (infer-fragment val.y env state.p.left)
15363 =/ right=iresult (infer-fragment val.y env state.p.left)
15295 ?: ?=(%| -.right) right
15364 ?: ?=(%| -.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)]
15296 ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
15367 ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
15297 =/ st=istate state.p.right
15368 =/ st=istate state.p.right
15298 ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
15369 ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)