@@ -4606,6 +4606,7 @@
46064606 [%atom aura=@ta]
46074607 [%any-atom ~]
46084608 [%flag ~]
4609+ [%face name=term body=itype]
46094610 [%fn sample=itype product=itype]
46104611 [%cell hed=itype tal=itype]
46114612 ==
@@ -4648,6 +4649,7 @@
46484649 %atom |
46494650 %any-atom |
46504651 %flag |
4652+ %face $(t body.t)
46514653 %fn |($(t sample.t) $(t product.t))
46524654 %cell |($(t hed.t) $(t tal.t))
46534655 ==
@@ -4687,6 +4689,9 @@
46874689 ?. |(?=(%atom -.a) ?=(%any-atom -.a) ?=(%flag -.a)) ~
46884690 `[[id.b a] sub]
46894691 ?: &(?=(%atom -.a) ?=(%atom -.b)) ~
4692+ ?: &(?=(%face -.a) ?=(%face -.b))
4693+ ?. =(name.a name.b) ~
4694+ $(a body.a, b body.b)
46904695 ?: &(?=(%fn -.a) ?=(%fn -.b))
46914696 =/ first=(unit isub) $(a sample.a, b sample.b)
46924697 ?~ first ~
@@ -4714,6 +4719,7 @@
47144719 %atom |
47154720 %any-atom &
47164721 %flag |
4722+ %face $(t body.t)
47174723 %fn |($(t sample.t) $(t product.t))
47184724 %cell |($(t hed.t) $(t tal.t))
47194725 ==
@@ -4744,6 +4750,9 @@
47444750 ?: &(?=(%atom -.a) ?=(%atom -.b))
47454751 ?. !=(aura.a aura.b) |
47464752 |((aura-prefix aura.a aura.b) (aura-prefix aura.b aura.a))
4753+ ?: &(?=(%face -.a) ?=(%face -.b))
4754+ ?. =(name.a name.b) |
4755+ $(a body.a, b body.b)
47474756 ?: &(?=(%cell -.a) ?=(%cell -.b))
47484757 |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
47494758 ?: &(?=(%fn -.a) ?=(%fn -.b))
@@ -4764,6 +4773,7 @@
47644773 %atom &
47654774 %any-atom &
47664775 %flag &
4776+ %face $(typ body.typ)
47674777 %fn |($(typ sample.typ) $(typ product.typ))
47684778 %cell |($(typ hed.typ) $(typ tal.typ))
47694779 ==
@@ -4781,6 +4791,63 @@
47814791 ?: &(?=(%any-atom -.b) |(?=(%atom -.a) ?=(%flag -.a))) `b
47824792 ~
47834793::
4794+:: Unifying an already-bound tuple with a faced position would need to
4795+:: update the bound type. Until substitutions can retain that information,
4796+:: variable-dependent face merges stay unresolved.
4797+::
4798+++ itype-has-face
4799+ |= [t=itype sub=isub]
4800+ ^- ?
4801+ =. t (itype-walk t sub)
4802+ ?- -.t
4803+ %face &
4804+ %cell |($(t hed.t) $(t tal.t))
4805+ %fn |($(t sample.t) $(t product.t))
4806+ * |
4807+ ==
4808+::
4809+++ itype-face-asym
4810+ |= [a=itype b=itype sub=isub]
4811+ ^- ?
4812+ =. a (itype-walk a sub)
4813+ =. b (itype-walk b sub)
4814+ ?: &(?=(%face -.a) ?=(%face -.b)) $(a body.a, b body.b)
4815+ ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%nvar -.b))
4816+ ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%nvar -.a))
4817+ ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
4818+ ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
4819+ |
4820+::
4821+:: A successful cast keeps any explicit faces from either side while
4822+:: retaining the target's aura choices. Both faces have already matched.
4823+::
4824+++ itype-merge-faces
4825+ |= [actual=itype expected=itype sub=isub]
4826+ ^- itype
4827+ =. actual (itype-walk actual sub)
4828+ =. expected (itype-walk expected sub)
4829+ ?: &(?=(%face -.actual) ?=(%face -.expected))
4830+ [%face name.expected $(actual body.actual, expected body.expected)]
4831+ ?: ?=(%face -.actual)
4832+ [%face name.actual $(actual body.actual)]
4833+ ?: ?=(%face -.expected)
4834+ [%face name.expected $(expected body.expected)]
4835+ ?: &(?=(%cell -.actual) ?=(%cell -.expected))
4836+ [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
4837+ expected
4838+::
4839+++ itype-output-may-be-cell
4840+ |= [t=itype sub=isub]
4841+ ^- ?
4842+ =. t (itype-walk t sub)
4843+ ?- -.t
4844+ %var &
4845+ %cell &
4846+ %face $(t body.t)
4847+ %fn |($(t sample.t) $(t product.t))
4848+ * |
4849+ ==
4850+::
47844851++ itype-fit
47854852 |= [actual=itype expected=itype sub=isub next=@ud]
47864853 ^- ifit
@@ -4789,6 +4856,7 @@
47894856 =. actual (itype-walk actual sub)
47904857 =. expected (itype-walk expected sub)
47914858 ?: =(actual expected) [%ok sub next]
4859+ ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
47924860 ?: ?=(%any-atom -.expected)
47934861 ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
47944862 ?: ?=(%var -.actual)
@@ -4819,6 +4887,12 @@
48194887 ?: (itype-family-related actual expected sub) [%unknown ~]
48204888 [%bad ~]
48214889 [%ok u.unified next]
4890+ ?: &(?=(%face -.actual) ?=(%face -.expected))
4891+ ?. =(name.actual name.expected) [%bad ~]
4892+ $(actual body.actual, expected body.expected)
4893+ ?: ?=(%face -.actual) $(actual body.actual)
4894+ ?: ?=(%face -.expected) $(expected body.expected)
4895+ ?: (itype-face-asym actual expected sub) [%unknown ~]
48224896 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
48234897 [%unknown ~]
48244898 =/ unified=(unit isub) (itype-unify actual expected sub)
@@ -4888,6 +4962,8 @@
48884962 |= [t=itype sub=isub]
48894963 ^- itype
48904964 =. t (itype-walk t sub)
4965+ ?: ?=(%face -.t)
4966+ [%face name.t $(t body.t)]
48914967 ?: ?=(%fn -.t)
48924968 [%fn $(t sample.t) $(t product.t)]
48934969 ?: ?=(%cell -.t)
@@ -4905,6 +4981,7 @@
49054981 ?- -.t
49064982 %fn &
49074983 %cell |($(t hed.t) $(t tal.t))
4984+ %face $(t body.t)
49084985 %var |
49094986 %avar |
49104987 %nvar |
@@ -4919,6 +4996,7 @@
49194996 ?: (itype-has-gate t) t
49204997 ?- -.t
49214998 %nvar [%atom %ud]
4999+ %face [%face name.t $(t body.t)]
49225000 %cell [%cell $(t hed.t) $(t tal.t)]
49235001 * t
49245002 ==
@@ -4933,6 +5011,7 @@
49335011 %atom ~
49345012 %any-atom ~
49355013 %flag ~
5014+ %face $(t body.t)
49365015 %fn (weld $(t sample.t) $(t product.t))
49375016 %cell (weld $(t hed.t) $(t tal.t))
49385017 ==
@@ -4965,6 +5044,7 @@
49655044 %atom t
49665045 %any-atom t
49675046 %flag t
5047+ %face [%face name.t $(t body.t)]
49685048 %fn [%fn $(t sample.t) $(t product.t)]
49695049 %cell [%cell $(t hed.t) $(t tal.t)]
49705050 ==
@@ -4982,6 +5062,7 @@
49825062 %atom |
49835063 %any-atom |
49845064 %flag |
5065+ %face $(t body.t)
49855066 %fn |($(t sample.t) $(t product.t))
49865067 %cell |($(t hed.t) $(t tal.t))
49875068 ==
@@ -5176,13 +5257,25 @@
51765257 |= [fields=(list field) state=istate]
51775258 ^- (unit [typ=itype state=istate])
51785259 ?~ fields ~
5179− ?. ?=(%bare -.i.fields) ~
5180− =/ head=(unit [typ=itype state=istate]) (infer-simple-shape shape.i.fields state)
5260+ =/ field-shape=shape
5261+ ?- -.i.fields
5262+ %bare shape.i.fields
5263+ %face shape.i.fields
5264+ %pun [%ref at.i.fields ~[name.i.fields]]
5265+ ==
5266+ =/ head=(unit [typ=itype state=istate]) (infer-simple-shape field-shape state)
51815267 ?~ head ~
5182− ?~ t.fields head
5268+ =/ t=itype typ.u.head
5269+ =. t
5270+ ?- -.i.fields
5271+ %bare t
5272+ %face [%face name.i.fields t]
5273+ %pun [%face name.i.fields t]
5274+ ==
5275+ ?~ t.fields `[t state.u.head]
51835276 =/ tail=(unit [typ=itype state=istate]) $(fields t.fields, state state.u.head)
51845277 ?~ tail ~
5185− `[[%cell typ.u.head typ.u.tail] state.u.tail]
5278+ `[[%cell t typ.u.tail] state.u.tail]
51865279::
51875280++ infer-sample
51885281 |= [s=sample env=ienv state=istate]
@@ -5203,9 +5296,34 @@
52035296 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
52045297 ?~ t [%| "sample mold is not supported by partial inference"]
52055298 [%& typ.u.t env state.u.t]
5206− * [%| "sample is not supported by partial inference"]
5299+ %pun
5300+ $(s [%face at.s name.s [%ref at.s ~[name.s]]])
5301+ %cell
5302+ (infer-sample-items items.s env state)
52075303 ==
52085304::
5305+:: Cell-sample binders are faces on their positions; at the top of a
5306+:: sample a binder only supplies a name for the whole sample.
5307+::
5308+++ infer-sample-items
5309+ |= [items=(list sample) env=ienv state=istate]
5310+ ^- isample-result
5311+ ?~ items [%| "empty sample is not supported by partial inference"]
5312+ =/ head=isample-result (infer-sample i.items env state)
5313+ ?: ?=(%| -.head) head
5314+ =/ ht=itype typ.p.head
5315+ =. ht
5316+ ?- -.i.items
5317+ %bind [%face name.i.items ht]
5318+ %face [%face name.i.items ht]
5319+ %pun [%face name.i.items ht]
5320+ * ht
5321+ ==
5322+ ?~ t.items [%& ht env.p.head state.p.head]
5323+ =/ tail=isample-result $(items t.items, env env.p.head, state state.p.head)
5324+ ?: ?=(%| -.tail) tail
5325+ [%& [%cell ht typ.p.tail] env.p.tail state.p.tail]
5326+::
52095327:: Local definitions generalize only variables outside their enclosing
52105328:: environment and explicit-capital scope. Unresolved groups stay
52115329:: unsupported: this fragment does not infer recursive definitions.
@@ -5300,6 +5418,38 @@
53005418 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
53015419 $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred, progressed &)
53025420::
5421+:: Read only fields of a known record. Unresolved field constraints and
5422+:: ambiguous repeated faces are outside this fragment.
5423+::
5424+++ record-fields-named
5425+ |= [name=term t=itype sub=isub]
5426+ ^- (list itype)
5427+ =. t (itype-walk t sub)
5428+ ?: ?=(%face -.t)
5429+ ?:(=(name name.t) ~[body.t] ~)
5430+ ?. ?=(%cell -.t) ~
5431+ =/ first=(list itype) ~
5432+ =/ head=itype (itype-walk hed.t sub)
5433+ =? first ?=(%face -.head) ?:(=(name name.head) ~[body.head] ~)
5434+ (weld first $(t tal.t))
5435+::
5436+++ infer-field-wing
5437+ |= [names=(list term) env=ienv state=istate]
5438+ ^- iresult
5439+ =/ reverse=(list term) (flop names)
5440+ ?~ reverse [%| ["empty wing" ~]]
5441+ =/ scheme=(unit ischeme) (ienv-lookup i.reverse env)
5442+ ?~ scheme [%| ["field access is not supported by partial inference" ~]]
5443+ =/ inst=[typ=itype state=istate] (instantiate-scheme u.scheme state)
5444+ =/ fields=(list term) t.reverse
5445+ =/ typ=itype typ.inst
5446+ |-
5447+ ?~ fields [%& typ state.inst]
5448+ =/ found=(list itype) (record-fields-named i.fields typ sub.state.inst)
5449+ ?~ found [%| ["field is not available to partial inference" ~]]
5450+ ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
5451+ $(fields t.fields, typ i.found)
5452+::
53035453++ infer-fragment
53045454 |= [e=expr env=ienv state=istate]
53055455 ^- iresult
@@ -5323,9 +5473,9 @@
53235473 %wing
53245474 ?~ names.e [%| ["empty wing" ~]]
53255475 ?^ t.names.e
5326− ?^ t.t.names.e [%| ["field access is not supported by partial inference" ~]]
5476+ ?^ t.t.names.e (infer-field-wing names.e env state)
53275477 =/ iface=(unit ifile) (find-jibb-interface i.t.names.e jimports.state)
5328− ?~ iface [%| ["field access is not supported by partial inference" ~]]
5478+ ?~ iface (infer-field-wing names.e env state)
53295479 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
53305480 ?~ member [%| ["module member is not available to partial inference" ~]]
53315481 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
@@ -5386,6 +5536,8 @@
53865536 ?~ joined
53875537 =/ common=(unit itype) (itype-concrete-join typ.p.left typ.p.right sub.state.p.right)
53885538 ?^ common [%& u.common state.p.right]
5539+ ?: |((itype-has-face typ.p.left sub.state.p.right) (itype-has-face typ.p.right sub.state.p.right))
5540+ [%| ["record branch matching is not supported by partial inference" ~]]
53895541 ?: |((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))
53905542 [%| ["branch widening is not supported by partial inference" ~]]
53915543 [%| ["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)]]]]
@@ -5399,7 +5551,8 @@
53995551 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
54005552 ?: ?=(%bad -.fit)
54015553 [%| ["cast mold and expression type do not unify" ~[[at.shape.e (site-type-note "cast mold" typ.u.target sub.state.p.value)] [(span-of val.e) (site-type-note "expression" typ.p.value sub.state.p.value)]]]]
5402− [%& typ.u.target state.p.value(sub sub.fit, next next.fit)]
5554+ =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
5555+ [%& merged state.p.value(sub sub.fit, next next.fit)]
54035556 %crash [%& [%var next.state] state(next +(next.state))]
54045557 %gate
54055558 =/ sam=isample-result (infer-sample sample.e env state)
@@ -5427,6 +5580,8 @@
54275580 ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
54285581 ?: ?=(%bad -.fit)
54295582 [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [(span-of i.args.e) (site-type-note "argument" typ.p.arg sub.st)]]]]
5583+ ?: &((itype-has-face typ.p.arg sub.fit) (itype-face-asym typ.p.arg sample.ht sub.fit) (itype-output-may-be-cell product.ht sub.fit))
5584+ [%| ["call result face propagation is not supported by partial inference" ~]]
54305585 [%& product.ht st(sub sub.fit, next next.fit)]
54315586 =/ result=itype [%var next.st]
54325587 =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
@@ -5443,13 +5598,14 @@
54435598 |= [items=(list item) env=ienv state=istate]
54445599 ^- iresult
54455600 ?~ items [%| ["empty cell is not supported by partial inference" ~]]
5446− ?^ face.i.items [%| ["record faces are not supported by partial inference" ~]]
54475601 =/ head=iresult (infer-fragment val.i.items env state)
54485602 ?: ?=(%| -.head) head
5449− ?~ t.items head
5603+ =/ ht=itype typ.p.head
5604+ =. ht ?~(face.i.items ht [%face u.face.i.items ht])
5605+ ?~ t.items [%& ht state.p.head]
54505606 =/ tail=iresult $(items t.items, state state.p.head)
54515607 ?: ?=(%| -.tail) tail
5452− [%& [%cell typ.p.head typ.p.tail] state.p.tail]
5608+ [%& [%cell ht typ.p.tail] state.p.tail]
54535609::
54545610:: A single two-binder cell pattern covers every value of a cell type.
54555611:: No other pattern matrix is implemented here.
@@ -5474,6 +5630,8 @@
54745630 =/ subject=iresult (infer-fragment subject.e env state)
54755631 ?: ?=(%| -.subject) subject
54765632 =/ st=istate state.p.subject
5633+ ?: (itype-has-face typ.p.subject sub.st)
5634+ [%| ["record patterns are not supported by partial inference" ~]]
54775635 =/ head=itype [%var next.st]
54785636 =/ tail=itype [%var +(next.st)]
54795637 =/ sub=(unit isub) (itype-unify typ.p.subject [%cell head tail] sub.st)
@@ -5497,10 +5655,18 @@
54975655 %atom "@{(trip aura.t)}"
54985656 %any-atom "@"
54995657 %flag "?"
5658+ %face "[{(trip name.t)}={$(t body.t)}]"
55005659 %fn "$-({$(t sample.t)} {$(t product.t)})"
5501− %cell "[{$(t hed.t)} {$(t tal.t)}]"
5660+ %cell "[{(show-itype-item hed.t sub)} {(show-itype-item tal.t sub)}]"
55025661 ==
55035662::
5663+++ show-itype-item
5664+ |= [t=itype sub=isub]
5665+ ^- tape
5666+ =. t (itype-walk t sub)
5667+ ?: ?=(%face -.t) "{(trip name.t)}={(show-itype body.t sub)}"
5668+ (show-itype t sub)
5669+::
55045670:: Include the type at a conflicting site where it can be printed.
55055671:: A lone unresolved variable or decimal variable keeps the neutral label.
55065672::
@@ -5514,6 +5680,7 @@
55145680 %atom |
55155681 %any-atom |
55165682 %flag |
5683+ %face $(typ body.typ)
55175684 %fn |($(typ sample.typ) $(typ product.typ))
55185685 %cell |($(typ hed.typ) $(typ tal.typ))
55195686 ==
@@ -5564,6 +5731,7 @@
55645731 %atom |
55655732 %any-atom |
55665733 %flag |
5734+ %face $(t body.t)
55675735 %fn |($(t sample.t) $(t product.t))
55685736 %cell |($(t hed.t) $(t tal.t))
55695737 ==