@@ -874,7 +874,7 @@
874874 %'~[' %'|=(' %'$-(' :: openers
875875 %'%/' %'/' :: paths
876876 %'+' %'`' %'=' :: pair, unit, face
877− %'*' %'?' :: noun, loobean mold
877+ %'*' %'?' %'_' :: noun, loobean, type hole
878878 %'++' %'+$' %'|=' %'|$' :: runes
879879 %'^-' %'~&' %'?-' %'!!' :: runes
880880 %'/-' %'/%' %'/=' :: imports
@@ -1016,6 +1016,7 @@
10161016 [%const at=span =lit] :: ~ %add %.y
10171017 [%ref at=span names=(list term)] :: state item.todo
10181018 [%tvar at=span name=@t] :: M
1019+ [%hole at=span ~] :: _
10191020 [%path at=span segs=(list pseg)] :: / /todos /todo/[id=@ud]
10201021 [%apply at=span ref=(list term) args=(list shape)] :: (list @t)
10211022 [%cell at=span fields=(list field)] :: [text=@t done=?]
@@ -1024,9 +1025,9 @@
10241025 [%generic at=span vars=(list @t) body=shape] :: +$ name |$ [M] …
10251026 ==
10261027::
1027−:: +pseg: a path mold's segment, a knot or [name=aura]
1028+:: +pseg: a path mold's segment, a knot, [name=aura], or [name=_]
10281029::
1029−+$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta])
1030++$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta] [%inferred at=span name=term hole-at=span])
10301031::
10311032+| %api
10321033::
@@ -1295,6 +1296,7 @@
12951296 (emit 1 %'=')
12961297 ?: =('`' a) (emit 1 %'`')
12971298 ?: =('*' a) (emit 1 %'*')
1299+ ?: =('_' a) (emit 1 %'_')
12981300 ?: =('~' a)
12991301 ?: =('[' b) (emit 2 %'~[')
13001302 ?: =('&' b) (emit 2 %'~&')
@@ -1670,14 +1672,14 @@
16701672:: What may begin each place the parser reads (section 3, Errors):
16711673:: an expression a-z 0-9 " ( [ ~ % / ` | ^ ? !
16721674:: an operand a-z 0-9 " ( [ ~ % / ` | !
1673−:: a mold a-z A-Z @ * ! ? ~ % / ( [ $
1675+:: a mold a-z A-Z @ * ! ? ~ % / ( [ $ _
16741676:: a pattern a-z 0-9 " ~ % * [
16751677:: and what may go tight after an operand: . ( + = after a name, a
16761678:: closer ) ] }, or the : of a comment
16771679::
16781680++ expr-mask 0x57ff.ffff.4800.0000.83ff.8126.0000.0000
16791681++ operand-mask 0x57ff.ffff.0800.0000.03ff.8126.0000.0000
1680−++ mold-mask 0x47ff.fffe.0fff.ffff.8000.8532.0000.0000
1682+++ mold-mask 0x47ff.fffe.8fff.ffff.8000.8532.0000.0000
16811683++ bar-mask 0x1000.0000.0000.0000.0000.0000.0000.0000
16821684++ pattern-mask 0x47ff.fffe.0800.0000.03ff.0424.0000.0000
16831685++ after-mask 0x2000.0000.2000.0000.2400.4b00.0000.0000
@@ -2107,6 +2109,7 @@
21072109 ?- -.s
21082110 %knot (weld "/" (trip p.s))
21092111 %typed "/[{(trip name.s)}=@{(trip aura.s)}]"
2112+ %inferred "/[{(trip name.s)}=_]"
21102113 ==
21112114::
21122115++ show-tvars
@@ -2318,6 +2321,7 @@
23182321 %const (nod "const" at.s (show-lit lit.s) ~)
23192322 %ref (nod "ref" at.s (show-names names.s) ~)
23202323 %tvar (nod "tvar" at.s (trip name.s) ~)
2324+ %hole (nod "hole" at.s "" ~)
23212325 %path (nod "path" at.s (show-psegs segs.s) ~)
23222326 %apply (nod "apply" at.s (show-names ref.s) (turn args.s sexp-shape))
23232327 %cell (nod "cell" at.s "" (turn fields.s sexp-field))
@@ -3842,6 +3846,7 @@
38423846 %'*' [%& [%noun at.t ~] t.ts]
38433847 %'!!' [%& [%void at.t ~] t.ts]
38443848 %'?' [%& [%flag at.t ~] t.ts]
3849+ %'_' [%& [%hole at.t ~] t.ts]
38453850 [%name *] [%& [%ref at.t ~[p.lex.t]] t.ts]
38463851 [%wing *] [%& [%ref at.t p.lex.t] t.ts]
38473852 [%tvar *] [%& [%tvar at.t p.lex.t] t.ts]
@@ -4058,7 +4063,7 @@
40584063 ?: &(?=(^ nex) tight.i.nex) (bad nex "a path segment")
40594064 (bad-space i.after nex "a path segment")
40604065 ::
4061− :: +read-pseg: a path mold's segment, a knot or [name=aura] with no
4066+ :: +read-pseg: a path mold's knot, [name=aura], or [name=_] with no
40624067 :: spaces, and where it ends
40634068 ::
40644069 ++ read-pseg
@@ -4075,13 +4080,16 @@
40754080 ?: |(?=(~ r2) !tight.i.r2) (bad-space i.r1 r2 "`=`")
40764081 ?. ?=([[* * %'='] *] r2) (bad-in r2 "`=`" tis-mask)
40774082 =/ r3=(list token) t.r2
4078− ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura")
4079− ?. ?=([[* * [%aura *]] *] r3) (bad-in r3 "an aura" pat-mask)
4083+ ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura or type hole")
4084+ ?. ?=([[* * ?([%aura *] %'_')] *] r3) (bad-in r3 "an aura or type hole" (con pat-mask (bex 95)))
40804085 =/ r4=(list token) t.r3
40814086 ?: |(?=(~ r4) !tight.i.r4) (bad-space i.r3 r4 "`]`")
40824087 ?. ?=([[* * %']'] *] r4) (bad-in r4 "`]`" ser-mask)
40834088 =/ at=span [beg.at.op end.at.i.r4]
4084− [%& [[%typed at p.lex.i.r1 p.lex.i.r3] end.at.i.r4] t.r4]
4089+ =/ seg=pseg
4090+ ?: ?=(%'_' lex.i.r3) [%inferred at p.lex.i.r1 at.i.r3]
4091+ [%typed at p.lex.i.r1 p.lex.i.r3]
4092+ [%& [seg end.at.i.r4] t.r4]
40854093 --
40864094::
40874095+| %span-check
@@ -4465,6 +4473,7 @@
44654473 %const [%const at.s ~[%lit] %one ~]
44664474 %ref [%ref at.s ~[%name %wing] %one ~]
44674475 %tvar [%tvar at.s ~[%tvar] %one ~]
4476+ %hole [%hole at.s ~[%'_'] %one ~]
44684477 %apply [%apply at.s ~[%'('] %shut (turn args.s outline-shape)]
44694478 %cell [%cell at.s ~[%'['] %shut (turn fields.s outline-sample)]
44704479 ::
@@ -4473,8 +4482,11 @@
44734482 %+ murn segs.s
44744483 |= g=pseg
44754484 ^- (unit outline)
4476− ?. ?=(%typed -.g) ~
4477− `[%typed at.g ~[%'['] %shut ~]
4485+ ?- -.g
4486+ %knot ~
4487+ %typed `[%typed at.g ~[%'['] %shut ~]
4488+ %inferred `[%typed at.g ~[%'['] %shut ~[[%hole hole-at.g ~[%'_'] %one ~]]]
4489+ ==
44784490 [%path at.s ~[%'/'] %run ks]
44794491 ::
44804492 %union
@@ -4534,6 +4546,8 @@
45344546 [%path [1 9] [1 9] [1 21]]
45354547 [%face [1 7] [1 7] [1 21]]
45364548 ==
4549+ :: an inferred path aura's hole spanning its = as well
4550+ ['+$ x /a/[id=_]' ~[[%hole [1 13] [1 12] [1 14]]]]
45374551 :: an import's path cut short
45384552 ['/= c /ui/c' ~[[%jibb [1 1] [1 1] [1 11]]]]
45394553 :: brackets that close with the deeper lines, cut at their line's
@@ -4593,6 +4607,8 @@
45934607:: Atom constraints tied to an explicit capital or an inferred sample
45944608:: are generalized and printed. Other aura variables remain unsupported until
45954609:: their defaulting and inferred generalization are implemented.
4610+:: Restricted-number promotion considers written capitals only; if there
4611+:: are none, it skips the otherwise unnecessary environment traversal.
45964612:: Bare @ is a separate unrestricted atom type. A directional fit check
45974613:: permits concrete atoms to widen to it, never the reverse. A fit that
45984614:: needs a not-yet-implemented constraint remains unsupported. Named unions
@@ -4600,19 +4616,64 @@
46004616:: from their display name. Generic cases must be disjoint for all arguments.
46014617:: Unnamed union printing is informational; it is not Jibb syntax.
46024618::
4619+:: `proj` is a reserved, type-directed operation, not an ordinary gate.
4620+:: The supported fragment selects uniquely faced fields from a known record
4621+:: in source order (reordering is a doc question). It records the original
4622+:: call, source and target types, and source axes with its definition;
4623+:: A single selected field keeps its face and uses one source axis.
4624+:: Checked module interfaces retain that evidence and their source, including
4625+:: the private prelude dependency. A later lowerer must replace the call by
4626+:: an inline gate applied to the operand once; no lowering is implemented yet.
4627+:: Ordinary fits never insert a projection. Unknown or variable-origin record
4628+:: spines, nested projected fields and projections in
4629+:: recursive groups remain unsupported. Directional fits bound faced-spine
4630+:: proofs to fewer than 1,024 cells; the projection planner has a separate
4631+:: 4,096-step bound. These are inference limits, not language limits.
4632+::
4633+:: Supported API imports derive request-gate types atomically for multiple
4634+:: paths, including one typed segment or one diff fold per case. Their checked
4635+:: ordinary definitions, mark molds and supported poke constructor are also
4636+:: exported. A selected /sur mold is checked through its trusted reader result;
4637+:: unused cores and other bindings are not independently validated. APIs
4638+:: with /= imports, separate scry paths, multiple parameters or diffs, or a
4639+:: parameter together with a fold remain unsupported. The unchanged todo API
4640+:: fits this fragment, including named closed fold gates.
4641+::
4642+:: Each case's source-derived schema and canonical API identity travel in a
4643+:: dependency closure bound to the exact supplied bundle, prelude, scope and
4644+:: trusted reader results. Unknown cached entries are rebuilt. Request-bearing
4645+:: closures are limited to 256 source paths and requests. This is type
4646+:: inference only: no request lowering, runtime schema validator or proof that
4647+:: an arbitrary ask value is watchable is supplied.
4648+::
4649+:: A closed gate sample may omit one outer face from a known input slot when
4650+:: its product is identical. Distinct written names, nested value faces,
4651+:: ambiguous cell tails and raw-variable-origin fits retain their prior rules.
4652+::
4653+:: In one synthetic eval of a 48-module deep and 48-module wide request-free
4654+:: graph, baseline versus certificate inference took 21.53 s versus 23.10 s
4655+:: elapsed (21.10 s versus 22.34 s CPU), including startup. The deep cache's
4656+:: jam grew from 2,402 to 4,209 bytes (+1,807 bytes). These single-run figures
4657+:: are not production memory or performance benchmarks.
4658+::
46034659+$ itype
46044660 $~ [%var 0]
46054661 $% [%var id=@ud]
46064662 [%avar id=@ud]
4663+ [%rvar id=@ud]
46074664 [%nvar id=@ud]
4665+ [%rnvar id=@ud]
46084666 [%atom aura=@ta]
46094667 [%any-atom ~]
46104668 [%flag ~]
46114669 [%noun ~]
4670+ [%empty ~]
46124671 [%tag id=@ud literal=lit constructor=?]
46134672 [%const literal=lit]
46144673 [%collection name=term args=(list itype)]
46154674 [%recursive module=term name=term label=(unit @t)]
4675+ [%jrec at=path name=term label=(unit @t) head=term aura=@ta tail=term]
4676+ [%grec at=path name=term label=(unit @t) proof=shape args=(list itype)]
46164677 [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t) args=(list itype)]
46174678 [%face name=term body=itype]
46184679 [%fn sample=itype product=itype]
@@ -4636,21 +4697,117 @@
46364697 %var
46374698 =/ found=(unit itype) (itype-lookup id.t sub)
46384699 ?~ found t
4700+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46394701 $(t u.found)
46404702 %avar
46414703 =/ found=(unit itype) (itype-lookup id.t sub)
46424704 ?~ found t
4705+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4706+ $(t u.found)
4707+ %rvar
4708+ =/ found=(unit itype) (itype-lookup id.t sub)
4709+ ?~ found t
4710+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46434711 $(t u.found)
46444712 %nvar
46454713 =/ found=(unit itype) (itype-lookup id.t sub)
46464714 ?~ found t
4715+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4716+ $(t u.found)
4717+ %rnvar
4718+ =/ found=(unit itype) (itype-lookup id.t sub)
4719+ ?~ found t
4720+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46474721 $(t u.found)
46484722 %tag
46494723 =/ found=(unit itype) (itype-lookup id.t sub)
46504724 ?~ found t
4725+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46514726 $(t u.found)
46524727 ==
46534728::
4729+:: Prove only emptiness; unknown types are never treated as empty.
4730+:: A shared node budget bounds each proof attempt.
4731+++ itype-empty-cases
4732+ |= [xs=(list itype) sub=isub fuel=@ud]
4733+ ^- (unit [empty=? left=@ud])
4734+ ?~ xs `[& fuel]
4735+ =/ first=(unit [empty=? left=@ud]) (itype-empty-proof i.xs sub fuel)
4736+ ?~ first ~
4737+ ?. empty.u.first `[| left.u.first]
4738+ $(xs t.xs, fuel left.u.first)
4739+++ itype-empty-proof
4740+ |= [typ=itype sub=isub fuel=@ud]
4741+ ^- (unit [empty=? left=@ud])
4742+ ?: =(0 fuel) ~
4743+ =. fuel (dec fuel)
4744+ =. typ (itype-walk typ sub)
4745+ ?- -.typ
4746+ %empty `[& fuel]
4747+ %face $(typ body.typ)
4748+ %cell
4749+ =/ left=(unit [empty=? left=@ud]) $(typ hed.typ)
4750+ ?~ left ~
4751+ ?: empty.u.left `[& left.u.left]
4752+ $(typ tal.typ, fuel left.u.left)
4753+ %union (itype-empty-cases cases.typ sub fuel)
4754+ * `[| fuel]
4755+ ==
4756+:: Prove reachability separately from emptiness. An unresolved fixed
4757+:: recursive type is not presumed inhabited. A written, still-unconstrained
4758+:: capital is existentially inhabited for pattern reachability; the normal
4759+:: definition-boundary checks reject subsequently constrained capitals.
4760+++ itype-inhabited-cases
4761+ |= [xs=(list itype) sub=isub caps=icaps fuel=@ud pending=?]
4762+ ^- (unit [result=?(%yes %no %unknown) left=@ud])
4763+ ?~ xs `[?:(pending %unknown %no) fuel]
4764+ =/ first=(unit [result=?(%yes %no %unknown) left=@ud])
4765+ (itype-inhabited-proof i.xs sub caps fuel)
4766+ ?~ first ~
4767+ ?: =(%yes result.u.first) first
4768+ $(xs t.xs, fuel left.u.first, pending |(pending =(%unknown result.u.first)))
4769+++ itype-inhabited-proof
4770+ |= [typ=itype sub=isub caps=icaps fuel=@ud]
4771+ ^- (unit [result=?(%yes %no %unknown) left=@ud])
4772+ ?: =(0 fuel) ~
4773+ =. fuel (dec fuel)
4774+ =. typ (itype-walk typ sub)
4775+ ?- -.typ
4776+ %empty `[%no fuel]
4777+ ?(%atom %any-atom %flag %const %noun %avar %rvar %nvar %rnvar %fn %jrec) `[%yes fuel]
4778+ %var
4779+ ?: (lien caps |=(c=icap (hole-same-variable typ (itype-walk [%var id.c] sub)))) `[%yes fuel]
4780+ `[%unknown fuel]
4781+ %face $(typ body.typ)
4782+ %cell
4783+ =/ head=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ hed.typ)
4784+ ?~ head ~
4785+ ?: =(%no result.u.head) head
4786+ =/ tail=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ tal.typ, fuel left.u.head)
4787+ ?~ tail ~
4788+ ?: =(%no result.u.tail) tail
4789+ ?: |(=(%unknown result.u.head) =(%unknown result.u.tail)) `[%unknown left.u.tail]
4790+ `[%yes left.u.tail]
4791+ %union (itype-inhabited-cases cases.typ sub caps fuel |)
4792+ %collection
4793+ ?. &(|(=(%list name.typ) =(%unit name.typ)) ?=([* ~] args.typ)) `[%unknown fuel]
4794+ `[%yes fuel]
4795+ %grec ?:((grec-tree-proof name.typ proof.typ) `[%yes fuel] `[%unknown fuel])
4796+ * `[%unknown fuel]
4797+ ==
4798+++ itype-live-cases
4799+ |= [xs=(list itype) sub=isub caps=icaps fuel=@ud]
4800+ ^- (unit (list itype))
4801+ ?~ xs `~
4802+ =/ first=(unit [result=?(%yes %no %unknown) left=@ud])
4803+ (itype-inhabited-proof i.xs sub caps fuel)
4804+ ?~ first ~
4805+ ?: =(%unknown result.u.first) ~
4806+ =/ rest=(unit (list itype)) $(xs t.xs, fuel left.u.first)
4807+ ?~ rest ~
4808+ ?: =(%no result.u.first) rest
4809+ `[i.xs u.rest]
4810+::
46544811++ itype-occurs
46554812 |= [n=@ud t=itype sub=isub]
46564813 ^- ?
@@ -4658,15 +4815,20 @@
46584815 ?- -.t
46594816 %var =(n id.t)
46604817 %avar =(n id.t)
4818+ %rvar =(n id.t)
46614819 %nvar =(n id.t)
4820+ %rnvar =(n id.t)
46624821 %atom |
46634822 %any-atom |
46644823 %flag |
46654824 %noun |
4825+ %empty |
46664826 %tag =(n id.t)
46674827 %const |
46684828 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
46694829 %recursive |
4830+ %jrec |
4831+ %grec (lien args.t |=(c=itype (itype-occurs n c sub)))
46704832 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
46714833 %face $(t body.t)
46724834 %fn |($(t sample.t) $(t product.t))
@@ -4685,6 +4847,11 @@
46854847 =. a (itype-walk a sub)
46864848 =. b (itype-walk b sub)
46874849 ?: =(a b) `sub
4850+ ?: &(?=(%grec -.a) ?=(%grec -.b))
4851+ ?. &(=(at.a at.b) =(name.a name.b)) ~
4852+ (itype-unify-args args.a args.b sub)
4853+ ?: &(?=(%jrec -.a) ?=(%jrec -.b))
4854+ ?:(&(=(at.a at.b) =(name.a name.b) =(head.a head.b) =(aura.a aura.b) =(tail.a tail.b)) `sub ~)
46884855 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
46894856 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
46904857 ?: &(?=(%union -.a) ?=(%union -.b))
@@ -4701,6 +4868,32 @@
47014868 ?: ?=(%var -.b)
47024869 ?: (itype-occurs id.b a sub) ~
47034870 `[[id.b a] sub]
4871+ :: Arithmetic's aura variable excludes loobeans; decimal literals
4872+ :: remain defaultable until a later constraint makes them concrete.
4873+ ?: &(?=(%nvar -.a) ?=(%rvar -.b))
4874+ `[[id.b [%rnvar id.a]] [id.a [%rnvar id.a]] sub]
4875+ ?: &(?=(%rvar -.a) ?=(%nvar -.b))
4876+ `[[id.a [%rnvar id.b]] [id.b [%rnvar id.b]] sub]
4877+ ?: &(?=(%rnvar -.a) ?=(%rvar -.b)) `[[id.b a] sub]
4878+ ?: &(?=(%rvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4879+ ?: &(?=(%rnvar -.a) ?=(%nvar -.b)) `[[id.b a] sub]
4880+ ?: &(?=(%nvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4881+ ?: &(?=(%rnvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4882+ ?: &(?=(%avar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4883+ ?: ?=(%rnvar -.a)
4884+ ?. |(?=(%rnvar -.b) ?=(%atom -.b)) ~
4885+ `[[id.a b] sub]
4886+ ?: ?=(%rnvar -.b)
4887+ ?. ?=(%atom -.a) ~
4888+ `[[id.b a] sub]
4889+ ?: &(?=(%avar -.a) ?=(%rvar -.b)) `[[id.a b] sub]
4890+ ?: &(?=(%rvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4891+ ?: ?=(%rvar -.a)
4892+ ?. |(?=(%rvar -.b) ?=(%atom -.b)) ~
4893+ `[[id.a b] sub]
4894+ ?: ?=(%rvar -.b)
4895+ ?. ?=(%atom -.a) ~
4896+ `[[id.b a] sub]
47044897 :: The narrower decimal constraint survives a match with an atom
47054898 :: variable; decimal syntax alone does not make it a loobean.
47064899 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
@@ -4755,15 +4948,20 @@
47554948 ?- -.t
47564949 %var |
47574950 %avar |
4951+ %rvar |
47584952 %nvar |
4953+ %rnvar |
47594954 %atom |
47604955 %any-atom &
47614956 %flag |
47624957 %noun |
4958+ %empty |
47634959 %tag |
47644960 %const |
47654961 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
47664962 %recursive |
4963+ %jrec |
4964+ %grec (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47674965 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47684966 %face $(t body.t)
47694967 %fn |($(t sample.t) $(t product.t))
@@ -4826,15 +5024,20 @@
48265024 ?- -.typ
48275025 %var |
48285026 %avar |
5027+ %rvar |
48295028 %nvar |
5029+ %rnvar |
48305030 %atom &
48315031 %any-atom &
48325032 %flag &
48335033 %noun |
5034+ %empty |
48345035 %tag &
48355036 %const &
48365037 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
48375038 %recursive |
5039+ %jrec |
5040+ %grec (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48385041 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48395042 %face $(typ body.typ)
48405043 %fn |($(typ sample.typ) $(typ product.typ))
@@ -4863,6 +5066,7 @@
48635066 ^- ?
48645067 =. t (itype-walk t sub)
48655068 ?- -.t
5069+ %grec (lien args.t |=(c=itype (itype-has-face c sub)))
48665070 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
48675071 %face &
48685072 %cell |($(t hed.t) $(t tal.t))
@@ -4870,6 +5074,42 @@
48705074 * |
48715075 ==
48725076::
5077+:: Closed function samples may omit a slot face, but a known name must
5078+:: match another known name. Keep nested value faces and require exact
5079+:: invariant compatibility; a faced tail against a cell is ambiguous.
5080+++ itype-closed-slot-match
5081+ |= [a=itype b=itype]
5082+ ^- ?
5083+ ?: &(?=(%face -.a) ?=(%face -.b))
5084+ ?. =(name.a name.b) |
5085+ ?=(^ (itype-unify body.a body.b ~))
5086+ ?: ?=(%face -.a) ?=(^ (itype-unify body.a b ~))
5087+ ?: ?=(%face -.b) ?=(^ (itype-unify a body.b ~))
5088+ ?=(^ (itype-unify a b ~))
5089+++ itype-closed-sample-match
5090+ |= [a=itype b=itype fuel=@ud]
5091+ ^- ?
5092+ ?: =(0 fuel) |
5093+ ?. &(?=(%cell -.a) ?=(%cell -.b)) |
5094+ ?. (itype-closed-slot-match hed.a hed.b) |
5095+ =/ x=itype tal.a
5096+ =/ y=itype tal.b
5097+ ?: &(?=(%cell -.x) ?=(%cell -.y))
5098+ ?=(^ (itype-unify x y ~))
5099+ ?: |(&(?=(%face -.x) ?=(%cell -.y)) &(?=(%cell -.x) ?=(%face -.y))) |
5100+ (itype-closed-slot-match x y)
5101+++ itype-closed-gates-match
5102+ |= [a=itype b=itype]
5103+ ^- ?
5104+ ?. &(?=(%fn -.a) ?=(%fn -.b)) |
5105+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) |
5106+ ?. =(product.a product.b) |
5107+ ?^ (itype-vars a) |
5108+ ?^ (itype-vars b) |
5109+ ?: |((itype-has-tag a) (itype-has-tag b)) |
5110+ ?. (itype-closed-sample-match sample.a sample.b 1.024) |
5111+ ?=(^ (itype-unify product.a product.b ~))
5112+::
48735113++ itype-face-asym-collection-args
48745114 |= [as=(list itype) bs=(list itype) sub=isub]
48755115 ^- ?
@@ -4883,12 +5123,15 @@
48835123 ^- ?
48845124 =. a (itype-walk a sub)
48855125 =. b (itype-walk b sub)
5126+ ?: &(?=(%grec -.a) ?=(%grec -.b))
5127+ ?. &(=(at.a at.b) =(name.a name.b)) |
5128+ (itype-face-asym-collection-args args.a args.b sub)
48865129 ?: &(?=(%collection -.a) ?=(%collection -.b))
48875130 ?. =(name.a name.b) |
48885131 (itype-face-asym-collection-args args.a args.b sub)
48895132 ?: &(?=(%face -.a) ?=(%face -.b)) $(a body.a, b body.b)
4890− ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%nvar -.b))
4891− ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%nvar -.a))
5133+ ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%rvar -.b) |(?=(%nvar -.b) ?=(%rnvar -.b)))
5134+ ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%rvar -.a) |(?=(%nvar -.a) ?=(%rnvar -.a)))
48925135 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
48935136 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
48945137 |
@@ -4911,6 +5154,30 @@
49115154 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
49125155 expected
49135156::
5157+:: Positional call arguments do not write the sample's enclosing field
5158+:: labels. Ignore one raw sample-slot face per written argument while
5159+:: checking value faces as usual. An unknown or variable-bound cell spine
5160+:: cannot justify this distinction, so keep the existing conservative guard.
5161+++ itype-positional-slot-face-asym
5162+ |= [actual=itype expected=itype sub=isub]
5163+ ^- ?
5164+ ?: &(?=(%fn -.actual) ?=(%fn -.expected) (itype-closed-gates-match actual expected)) |
5165+ (itype-face-asym actual expected sub)
5166+::
5167+++ itype-positional-face-asym
5168+ |= [args=(list expr) actual=itype expected=itype sub=isub]
5169+ ^- ?
5170+ ?~ args &
5171+ ?~ t.args
5172+ =/ slot=itype expected
5173+ =? slot ?=(%face -.slot) body.slot
5174+ (itype-positional-slot-face-asym actual slot sub)
5175+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) &
5176+ =/ slot=itype hed.expected
5177+ =? slot ?=(%face -.slot) body.slot
5178+ ?: (itype-positional-slot-face-asym hed.actual slot sub) &
5179+ $(args t.args, actual tal.actual, expected tal.expected)
5180+::
49145181++ itype-output-may-be-cell
49155182 |= [t=itype sub=isub]
49165183 ^- ?
@@ -4920,6 +5187,8 @@
49205187 %cell &
49215188 %union &
49225189 %recursive &
5190+ %jrec &
5191+ %grec &
49235192 %noun &
49245193 %collection &
49255194 %face $(t body.t)
@@ -4949,6 +5218,7 @@
49495218 ^- ?
49505219 ?- -.t
49515220 %tag &
5221+ %grec (lien args.t |=(c=itype (itype-has-tag c)))
49525222 %collection (lien args.t |=(c=itype (itype-has-tag c)))
49535223 %face $(t body.t)
49545224 %fn |($(t sample.t) $(t product.t))
@@ -4962,6 +5232,7 @@
49625232 ^- ?
49635233 ?- -.t
49645234 %union &
5235+ %grec (lien args.t |=(c=itype (itype-has-union c)))
49655236 %collection (lien args.t |=(c=itype (itype-has-union c)))
49665237 %face $(t body.t)
49675238 %fn |($(t sample.t) $(t product.t))
@@ -4980,6 +5251,7 @@
49805251 %union
49815252 ?: &(?=(~ label.t) ?=(^ args.t)) &
49825253 (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-generic c)))
5254+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-generic c))))
49835255 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
49845256 %face $(t body.t)
49855257 %fn |($(t sample.t) $(t product.t))
@@ -4992,6 +5264,8 @@
49925264 ^- ?
49935265 ?- -.t
49945266 %recursive &
5267+ %jrec &
5268+ %grec &
49955269 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
49965270 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
49975271 %face $(t body.t)
@@ -5005,6 +5279,8 @@
50055279 ^- ?
50065280 ?- -.t
50075281 %recursive ?=(~ label.t)
5282+ %jrec ?=(~ label.t)
5283+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-recursive c))))
50085284 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
50095285 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
50105286 %face $(t body.t)
@@ -5032,34 +5308,85 @@
50325308 $(cases t.cases, good `trial)
50335309 ==
50345310::
5035−:: A constructor needs a case with its tag at the head and a payload
5036−:: compatible with the expected gate sample. Other case forms do not
5037−:: identify a constructor.
5311+:: A constructor needs a case whose head has the same literal noun as its
5312+:: tag. An unresolved or opaque case may reveal one later, so it cannot
5313+:: prove a mismatch or a unique match. A broad atom mold is not a case.
50385314::
50395315++ itype-fit-ctor-cases
50405316 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
50415317 ^- ifit
50425318 =/ found=(unit ifit) ~
5319+ =/ pending=? |
50435320 |-
5044− ?~ cases ?~(found [%bad ~] u.found)
5045− =/ c=itype (itype-walk i.cases sub)
5321+ ?~ cases
5322+ ?: pending [%unknown ~]
5323+ ?~ found [%bad ~]
5324+ u.found
5325+ =/ raw=itype i.cases
5326+ ?: ?=(%var -.raw)
5327+ $(cases t.cases, pending &)
5328+ =/ c=itype (itype-walk raw sub)
5329+ ?: ?=(?(%var %tag %recursive %jrec %grec %union %face) -.c)
5330+ $(cases t.cases, pending &)
50465331 ?. ?=(%cell -.c) $(cases t.cases)
5047− =/ head=itype (itype-walk hed.c sub)
5332+ =/ raw-head=itype hed.c
5333+ ?: ?=(%var -.raw-head)
5334+ $(cases t.cases, pending &)
5335+ =/ head=itype (itype-walk raw-head sub)
5336+ :: A single faced, explicitly atom-only head cannot be the tag case.
5337+ :: Do not follow variables or peel nested faces for this negative proof.
5338+ ?: ?=(%face -.head)
5339+ ?: ?=(?(%atom %any-atom %flag %avar %rvar %nvar %rnvar) -.body.head)
5340+ $(cases t.cases)
5341+ $(cases t.cases, pending &)
5342+ ?: ?=(?(%var %tag %recursive %jrec %grec %union) -.head)
5343+ $(cases t.cases, pending &)
50485344 ?. ?=(%const -.head) $(cases t.cases)
5049− ?. =(%term form.literal.head) $(cases t.cases)
50505345 ?. =(val.literal.head val.tag) $(cases t.cases)
5051− ?^ found [%unknown ~]
5346+ :: Equal heads can have disjoint payloads. Test each from the original
5347+ :: substitution; a unique success is usable only with no unknown rival.
50525348 =/ trial=ifit (itype-fit sample tal.c sub next)
5053− $(cases t.cases, found `trial)
5349+ ?- -.trial
5350+ %bad $(cases t.cases)
5351+ %unknown $(cases t.cases, pending &)
5352+ %ok
5353+ ?^ found [%unknown ~]
5354+ $(cases t.cases, found `trial)
5355+ ==
50545356::
50555357++ itype-fit
50565358 |= [actual=itype expected=itype sub=isub next=@ud]
50575359 ^- ifit
5360+ =/ result=ifit (itype-fit-inner actual expected sub next | |)
5361+ ?: ?=(%ok -.result) result
5362+ =/ source=itype (itype-walk actual sub)
5363+ ?. ?=(?(%empty %face %cell %union) -.source) result
5364+ =/ empty=(unit [empty=? left=@ud]) (itype-empty-proof actual sub 256)
5365+ ?~ empty [%unknown ~]
5366+ ?: empty.u.empty [%ok sub next]
5367+ result
5368+++ itype-fit-inner
5369+ |= [actual=itype expected=itype sub=isub next=@ud skip-width=? spine-proof=?]
5370+ ^- ifit
5371+ ?: &(!skip-width ?=(%cell -.actual) ?=(%cell -.expected) |((width-spine-exhausted actual 1.024) (width-spine-exhausted expected 1.024)))
5372+ [%unknown ~]
5373+ =/ known=(unit [source=iwfields target=iwfields])
5374+ ?: skip-width ~
5375+ (width-known-shape actual expected sub)
5376+ =/ too-wide=? ?~(known | (gth (lent order.source.u.known) (lent order.target.u.known)))
5377+ ?: too-wide [%unknown ~]
5378+ =/ spine-checked=? |(spine-proof ?=(^ known))
50585379 =/ uncertain=?
5059− |(?=(%var -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%var -.expected) ?=(%avar -.expected) ?=(%nvar -.expected))
5380+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)))
5381+ =/ actual-open=?
5382+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))
50605383 =. actual (itype-walk actual sub)
50615384 =. expected (itype-walk expected sub)
50625385 ?: =(actual expected) [%ok sub next]
5386+ ?: &(?=(%empty -.expected) |(?=(%cell -.actual) ?=(%face -.actual) ?=(%union -.actual) ?=(%grec -.actual) ?=(%recursive -.actual))) [%unknown ~]
5387+ :: The relation of the source loobean mold to explicit @f is not yet
5388+ :: established. Keep it unsupported rather than asserting a mismatch.
5389+ ?: &(?=(%flag -.actual) ?=(%atom -.expected) =(%f aura.expected)) [%unknown ~]
50635390 :: Any value can be used where a noun is expected. An unresolved
50645391 :: bare tag is fixed as a constant; a constructor still needs a gate.
50655392 ?: ?=(%noun -.expected)
@@ -5069,6 +5396,19 @@
50695396 [%ok sub next]
50705397 :: An arbitrary noun is not known to fit a narrower type.
50715398 ?: &(?=(%noun -.actual) !?=(%var -.expected)) [%unknown ~]
5399+ ?: &(!uncertain ?=(%grec -.actual) ?=(%face -.expected)) $(expected body.expected)
5400+ ?: &(!uncertain ?=(%face -.actual) ?=(%grec -.expected)) $(actual body.actual)
5401+ ?: &(?=(%grec -.actual) ?=(%grec -.expected))
5402+ ?. &(=(at.actual at.expected) =(name.actual name.expected)) [%unknown ~]
5403+ =/ matched=(unit isub) (itype-unify-args args.actual args.expected sub)
5404+ ?~ matched [%unknown ~]
5405+ [%ok u.matched next]
5406+ ?: &(|(?=(%grec -.actual) ?=(%grec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5407+ ?: &(!uncertain ?=(%jrec -.actual) ?=(%face -.expected)) $(expected body.expected)
5408+ ?: &(!uncertain ?=(%face -.actual) ?=(%jrec -.expected)) $(actual body.actual)
5409+ ?: &(?=(%jrec -.actual) ?=(%jrec -.expected))
5410+ ?:(&(=(at.actual at.expected) =(name.actual name.expected) =(head.actual head.expected) =(aura.actual aura.expected) =(tail.actual tail.expected)) [%ok sub next] [%bad ~])
5411+ ?: &(|(?=(%jrec -.actual) ?=(%jrec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
50725412 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
50735413 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
50745414 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
@@ -5080,12 +5420,21 @@
50805420 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
50815421 ?^ unified [%ok u.unified next]
50825422 [%unknown ~]
5423+ :: A known union can instantiate an unconstrained sample directly;
5424+ :: preserve unknown results for variable-bound union origins.
5425+ ?: &(!actual-open ?=(%union -.actual) ?=(%var -.expected))
5426+ ?~ origin.actual [%unknown ~]
5427+ =/ normalized=itype (itype-normalize actual sub)
5428+ ?: |((itype-has-tag normalized) (itype-has-recursive normalized) (itype-has-any-atom actual sub)) [%unknown ~]
5429+ =/ unified=(unit isub) (itype-unify actual expected sub)
5430+ ?~ unified [%unknown ~]
5431+ [%ok u.unified next]
50835432 :: A concrete union value in a tuple may acquire the expected field's
50845433 :: face. A variable-bound union still needs face propagation support.
50855434 ?: &(!uncertain ?=(%union -.actual) ?=(%face -.expected))
50865435 $(expected body.expected)
50875436 ?: ?=(%union -.actual) [%unknown ~]
5088− ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
5437+ ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))) [%unknown ~]
50895438 ?: &(?=(%union -.expected) !?=(%var -.actual))
50905439 (itype-fit-cases actual cases.expected sub next)
50915440 ?: ?=(%tag -.actual)
@@ -5093,7 +5442,7 @@
50935442 =/ u=(unit isub) (itype-unify actual expected sub)
50945443 ?~ u [%bad ~]
50955444 [%ok u.u next]
5096− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5445+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
50975446 ?: ?=(%face -.expected) $(expected body.expected)
50985447 ?: constructor.actual
50995448 ?. ?=(%fn -.expected) [%bad ~]
@@ -5121,13 +5470,17 @@
51215470 =/ u=(unit isub) (itype-unify actual expected sub)
51225471 ?~ u [%bad ~]
51235472 [%ok u.u next]
5124− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5473+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51255474 ?: ?=(%face -.expected) $(expected body.expected)
51265475 ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
51275476 [%unknown ~]
51285477 ?: ?=(%const -.expected)
51295478 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
51305479 ?: ?=(%atom -.expected)
5480+ :: A loobean singleton must not silently widen into another aura.
5481+ ?: =(%loobean form.literal.actual)
5482+ ?: =(%f aura.expected) [%unknown ~]
5483+ [%bad ~]
51315484 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
51325485 [%bad ~]
51335486 ?: ?=(%flag -.expected)
@@ -5135,8 +5488,14 @@
51355488 ?: ?=(%any-atom -.expected) [%ok sub next]
51365489 [%bad ~]
51375490 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
5491+ :: A known face labels the same noun. Peel it before applying the
5492+ :: directional unrestricted-atom rule, preserving raw-variable guards.
5493+ ?: &(!uncertain ?=(%any-atom -.actual) ?=(%face -.expected))
5494+ $(expected body.expected, skip-width |, spine-proof |)
5495+ ?: &(!uncertain ?=(%any-atom -.expected) ?=(%face -.actual))
5496+ $(actual body.actual, skip-width |, spine-proof |)
51385497 ?: ?=(%any-atom -.expected)
5139− ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
5498+ ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%flag -.actual)) [%ok sub next]
51405499 ?: ?=(%var -.actual)
51415500 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
51425501 ?~ unified [%bad ~]
@@ -5147,16 +5506,16 @@
51475506 =/ unified=(unit isub) (itype-unify actual expected sub)
51485507 ?~ unified [%bad ~]
51495508 [%ok u.unified next]
5150− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5509+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51515510 [%bad ~]
51525511 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
51535512 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
51545513 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
51555514 [%bad ~]
51565515 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5157− =/ first=ifit $(actual hed.actual, expected hed.expected)
5516+ =/ first=ifit $(actual hed.actual, expected hed.expected, skip-width |, spine-proof |)
51585517 ?. ?=(%ok -.first) first
5159− $(actual tal.actual, expected tal.expected, sub sub.first, next next.first)
5518+ $(actual tal.actual, expected tal.expected, sub sub.first, next next.first, skip-width spine-checked, spine-proof spine-checked)
51605519 :: A field may add a face to an occurrence of the very same type
51615520 :: variable. Binding that variable to a face around itself would fail
51625521 :: the occurs check, but its underlying type has already matched.
@@ -5178,9 +5537,10 @@
51785537 [%ok u.unified next]
51795538 ?: &(?=(%face -.actual) ?=(%face -.expected))
51805539 ?. =(name.actual name.expected) [%bad ~]
5181− $(actual body.actual, expected body.expected)
5182− ?: ?=(%face -.actual) $(actual body.actual)
5183− ?: ?=(%face -.expected) $(expected body.expected)
5540+ $(actual body.actual, expected body.expected, skip-width |, spine-proof |)
5541+ ?: ?=(%face -.actual) $(actual body.actual, skip-width |, spine-proof |)
5542+ ?: ?=(%face -.expected) $(expected body.expected, skip-width |, spine-proof |)
5543+ ?: &(!uncertain (itype-closed-gates-match actual expected)) [%ok sub next]
51845544 ?: (itype-face-asym actual expected sub) [%unknown ~]
51855545 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
51865546 [%unknown ~]
@@ -5257,7 +5617,17 @@
52575617+$ ienv (list [name=term scheme=ischeme])
52585618+$ imold-types (list [name=term template=ischeme])
52595619+$ iderived [name=term agent=term mark=term]
5260−+$ ifile [values=ienv molds=imold-types at=path derived=(list iderived)]
5620++$ iwidth-definition [name=term original=expr typ=itype sub=isub projections=(list iwprojection)]
5621++$ iwidth-dependency [at=path source=(unit @t) definitions=(list iwidth-definition)]
5622+:: Nonrecursive request evidence is compiler-owned metadata, not a property
5623+:: of an arbitrary ask value. Reader graphs and source inputs are trusted.
5624++$ irequest-evidence
5625+ [api-at=path name=term path=iapi-path-typed api-source=@t public-source=@t internal-source=@t prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5626+:: A unit distinguishes a verified empty closure from a detached legacy file.
5627+:: The opaque prelude is an exact trusted input, not a recursive interface mold.
5628++$ irequest-graph
5629+ [paths=(set path) requests=(list irequest-evidence) bundle-input=* prelude-input=* prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5630++$ ifile [values=ienv molds=imold-types at=path derived=(list iderived) elaborations=(list iwidth-definition) dependencies=(list iwidth-dependency) source=(unit @t) graph=(unit irequest-graph)]
52615631+$ ijimports (list [face=term interface=ifile])
52625632+$ icap [name=@t id=@ud at=span]
52635633+$ icaps (list icap)
@@ -5267,7 +5637,170 @@
52675637:: This core has no Ford dependencies; unrecognized payloads fail closed.
52685638+$ iexternals (list [module=term name=term result=*])
52695639+$ imark-externals (list [mark=term result=*])
5270−+$ 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 ipending) in-mold=? at=path top-molds=(list term) prelude=(unit ifile)]
5640+:: Hole obligations survive discarded expressions until their owning
5641+:: definition has inferred; their source spans support unresolved reports.
5642++$ ihole [id=@ud at=span]
5643+:: Recursive-mold unfolding spends fuel in the threaded inference state.
5644+:: Retries can restart from an earlier state, so this bounds an attempt,
5645+:: not all parsing or module-checking work.
5646+:: Experimental: only closed, uniquely faced records have known axes.
5647++$ iwfield [name=term axis=@ud typ=itype]
5648++$ iwfields [order=(list iwfield) index=(map term iwfield)]
5649++$ iwstep [name=term axis=@ud]
5650++$ iwidth-result [steps=(list iwstep) sub=isub next=@ud]
5651++$ iwprojection [at=span original=expr source=itype target=itype steps=(list iwstep)]
5652+++ width-scan
5653+ |= [typ=itype sub=isub axis=@ud fuel=@ud]
5654+ ^- (unit iwfields)
5655+ =/ order=(list iwfield) ~
5656+ =/ index=(map term iwfield) *(map term iwfield)
5657+ |-
5658+ ?: =(0 fuel) ~
5659+ ?: |(?=(%var -.typ) ?=(%avar -.typ) ?=(%rvar -.typ) ?=(%nvar -.typ) ?=(%rnvar -.typ)) ~
5660+ ?: ?=(%face -.typ)
5661+ =/ entry=iwfield [name.typ axis body.typ]
5662+ ?: ?=(^ (~(get by index) name.entry)) ~
5663+ `[(flop [entry order]) (~(put by index) name.entry entry)]
5664+ ?. ?=(%cell -.typ) ~
5665+ =/ head=itype hed.typ
5666+ ?: |(?=(%var -.head) ?=(%avar -.head) ?=(%rvar -.head) ?=(%nvar -.head) ?=(%rnvar -.head)) ~
5667+ ?. ?=(%face -.head) ~
5668+ =/ entry=iwfield [name.head (mul 2 axis) body.head]
5669+ ?: ?=(^ (~(get by index) name.entry)) ~
5670+ $(typ tal.typ, axis +((mul 2 axis)), fuel (dec fuel), order [entry order], index (~(put by index) name.entry entry))
5671+++ width-in-order
5672+ |= [source=(list iwfield) target=(list iwfield)]
5673+ ^- ?
5674+ ?~ target &
5675+ ?~ source |
5676+ ?: =(name.i.source name.i.target) $(source t.source, target t.target)
5677+ $(source t.source)
5678+++ width-fit-fields
5679+ |= [source=(map term iwfield) target=(list iwfield) sub=isub next=@ud]
5680+ ^- (unit iwidth-result)
5681+ ?~ target `[~ sub next]
5682+ =/ found=(unit iwfield) (~(get by source) name.i.target)
5683+ ?~ found ~
5684+ =/ fit=ifit (itype-fit typ.u.found typ.i.target sub next)
5685+ ?. ?=(%ok -.fit) ~
5686+ =/ rest=(unit iwidth-result) $(target t.target, sub sub.fit, next next.fit)
5687+ ?~ rest ~
5688+ `[[[name.i.target axis.u.found] steps.u.rest] sub.u.rest next.u.rest]
5689+++ width-spine-exhausted
5690+ |= [t=itype fuel=@ud]
5691+ ^- ?
5692+ ?: =(0 fuel) &
5693+ ?. ?=(%cell -.t) |
5694+ ?. ?=(%face -.hed.t) |
5695+ $(t tal.t, fuel (dec fuel))
5696+++ width-known-shape
5697+ |= [actual=itype expected=itype sub=isub]
5698+ ^- (unit [source=iwfields target=iwfields])
5699+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5700+ =/ source=(unit iwfields) (width-scan actual sub 1 1.024)
5701+ =/ target=(unit iwfields) (width-scan expected sub 1 1.024)
5702+ ?~ source ~
5703+ ?~ target ~
5704+ `[u.source u.target]
5705+::
5706+++ width-shape
5707+ |= [actual=itype expected=itype sub=isub]
5708+ ^- (unit [source=iwfields target=iwfields])
5709+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5710+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5711+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5712+ ?~ source ~
5713+ ?~ target ~
5714+ ?. (gth (lent order.u.source) (lent order.u.target)) ~
5715+ `[u.source u.target]
5716+++ width-proj-shape
5717+ |= [actual=itype expected=itype sub=isub]
5718+ ^- (unit [source=iwfields target=iwfields])
5719+ ?. &(|(?=(%cell -.actual) ?=(%face -.actual)) |(?=(%cell -.expected) ?=(%face -.expected))) ~
5720+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5721+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5722+ ?~ source ~
5723+ ?~ target ~
5724+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
5725+ `[u.source u.target]
5726+::
5727+++ width-project
5728+ |= [shape=[source=iwfields target=iwfields] sub=isub next=@ud]
5729+ ^- (unit iwidth-result)
5730+ ?. (width-in-order order.source.shape order.target.shape) ~
5731+ (width-fit-fields index.source.shape order.target.shape sub next)
5732+::
5733+:: Provisional, globally budgeted gate-free proof. %no includes a
5734+:: gate-bearing witness; an uninhabited sibling could invalidate it.
5735+:: Input types must be resolved and normalized under valid substitutions,
5736+:: from trusted source-backed interfaces and reader results. Collection
5737+:: list/unit names rely on their existing identity invariant; this arm
5738+:: does not validate fabricated internal types.
5739++$ igf-segment
5740+ $% [%field name=term]
5741+ [%head ~]
5742+ [%tail ~]
5743+ [%item ~]
5744+ [%case index=@ud]
5745+ ==
5746++$ igate-free [verdict=?(%yes %no %unknown) inhabited=? left=@ud path=(unit (list igf-segment))]
5747+++ gate-free-types
5748+ |= [types=(list itype) fuel=@ud path=(list igf-segment) index=@ud]
5749+ ^- igate-free
5750+ ?~ types [%yes | fuel ~]
5751+ ?: =(0 fuel) [%unknown | 0 ~]
5752+ =/ first=igate-free (gate-free-type i.types fuel [[%case index] path])
5753+ ?: =(%no verdict.first) first
5754+ =/ rest=igate-free $(types t.types, fuel left.first, index +(index))
5755+ ?: =(%no verdict.rest) rest
5756+ =/ inhabited=? |(inhabited.first inhabited.rest)
5757+ ?: |(=(%unknown verdict.first) =(%unknown verdict.rest)) [%unknown inhabited left.rest ~]
5758+ [%yes inhabited left.rest ~]
5759+++ gate-free-type
5760+ |= [typ=itype fuel=@ud path=(list igf-segment)]
5761+ ^- igate-free
5762+ ?: =(0 fuel) [%unknown | 0 ~]
5763+ =. fuel (dec fuel)
5764+ ?- -.typ
5765+ %fn [%no & fuel `(flop path)]
5766+ %atom [%yes & fuel ~]
5767+ %any-atom [%yes & fuel ~]
5768+ %flag [%yes & fuel ~]
5769+ %const [%yes & fuel ~]
5770+ %face $(typ body.typ, path [[%field name.typ] path])
5771+ %cell
5772+ =/ head=igate-free $(typ hed.typ, path [[%head ~] path])
5773+ =/ tail=igate-free $(typ tal.typ, fuel left.head, path [[%tail ~] path])
5774+ =/ inhabited=? &(inhabited.head inhabited.tail)
5775+ ?: |(&(=(%yes verdict.head) !inhabited.head) &(=(%yes verdict.tail) !inhabited.tail)) [%yes | left.tail ~]
5776+ ?: &(=(%no verdict.head) inhabited.tail) head(left left.tail)
5777+ ?: &(=(%no verdict.tail) inhabited.head) tail
5778+ ?: |(!=(%yes verdict.head) !=(%yes verdict.tail)) [%unknown inhabited left.tail ~]
5779+ [%yes inhabited left.tail ~]
5780+ %collection
5781+ ?. |(=(%list name.typ) =(%unit name.typ)) [%unknown | fuel ~]
5782+ ?. ?=([* ~] args.typ) [%unknown | fuel ~]
5783+ =/ item=igate-free $(typ i.args.typ, path [[%item ~] path])
5784+ item(inhabited &)
5785+ %union
5786+ ?~ cases.typ [%unknown | fuel ~]
5787+ (gate-free-types cases.typ fuel path 0)
5788+ %noun [%unknown & fuel ~]
5789+ %empty [%yes | fuel ~]
5790+ %var [%unknown | fuel ~]
5791+ %avar [%yes & fuel ~]
5792+ %rvar [%yes & fuel ~]
5793+ %nvar [%yes & fuel ~]
5794+ %rnvar [%yes & fuel ~]
5795+ %tag [%unknown | fuel ~]
5796+ %recursive [%unknown | fuel ~]
5797+ %jrec [%yes & fuel ~]
5798+ %grec [%unknown | fuel ~]
5799+ ==
5800+::
5801++$ igate-prelude-evidence [iface=ifile gates=(map term def)]
5802++$ dgo [left=itype right=itype at=span context=span]
5803++$ 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 ipending) in-mold=? at=path top-molds=(list term) prelude=(unit ifile) holes=(list ihole) jrec-fuel=@ud projections=(list iwprojection) gate-defs=(map term def) head-evidence=(unit igate-prelude-evidence) grec-index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)]) defer=(unit ~) obligations=(list dgo)]
52715804+$ idiag [msg=tape sites=(list [at=span note=tape])]
52725805+$ iresult (each [typ=itype state=istate] idiag)
52735806+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5287,6 +5820,7 @@
52875820 |= [t=itype sub=isub]
52885821 ^- itype
52895822 =. t (itype-walk t sub)
5823+ ?: ?=(%grec -.t) t(args (turn args.t |=(c=itype (itype-normalize c sub))))
52905824 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
52915825 ?: ?=(%union -.t)
52925826 [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t (turn args.t |=(c=itype (itype-normalize c sub)))]
@@ -5312,6 +5846,8 @@
53125846 %fn &
53135847 %cell |($(t hed.t) $(t tal.t))
53145848 %recursive |
5849+ %jrec |
5850+ %grec &
53155851 %collection (lien args.t |=(c=itype (itype-has-gate c)))
53165852 %face $(t body.t)
53175853 %union (lien cases.t |=(c=itype (itype-has-gate c)))
@@ -5319,11 +5855,14 @@
53195855 %const |
53205856 %var |
53215857 %avar |
5858+ %rvar |
53225859 %nvar |
5860+ %rnvar |
53235861 %atom |
53245862 %any-atom |
53255863 %flag |
53265864 %noun |
5865+ %empty |
53275866 ==
53285867::
53295868++ default-decimals
@@ -5332,27 +5871,136 @@
53325871 ?: (itype-has-gate t) t
53335872 ?- -.t
53345873 %nvar [%atom %ud]
5874+ %rnvar [%atom %ud]
5875+ %grec t(args (turn args.t |=(c=itype (default-decimals c))))
53355876 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
53365877 %face [%face name.t $(t body.t)]
53375878 %cell [%cell $(t hed.t) $(t tal.t)]
53385879 * t
53395880 ==
53405881::
5882+:: A hole is solved only by a fully determined type or a written
5883+:: in-scope type variable. Ordinary fresh variables are not evidence.
5884+:: Compare representatives after substitution, since unification can
5885+:: orient a written capital toward the hole rather than the reverse.
5886+++ hole-variable-id
5887+ |= t=itype
5888+ ^- (unit @ud)
5889+ ?- -.t
5890+ %var `id.t
5891+ %avar `id.t
5892+ %rvar `id.t
5893+ %nvar `id.t
5894+ %rnvar `id.t
5895+ %tag `id.t
5896+ * ~
5897+ ==
5898+++ hole-same-variable
5899+ |= [a=itype b=itype]
5900+ ^- ?
5901+ =/ x=(unit @ud) (hole-variable-id a)
5902+ ?~ x |
5903+ =/ y=(unit @ud) (hole-variable-id b)
5904+ ?~ y |
5905+ =(u.x u.y)
5906+++ hole-known
5907+ |= [t=itype state=istate]
5908+ ^- ?
5909+ =. t (itype-walk t sub.state)
5910+ ?- -.t
5911+ ?(%var %avar %rvar %nvar %rnvar)
5912+ ?: (lien caps.state |=(c=icap (hole-same-variable t (itype-walk [%var id.c] sub.state)))) &
5913+ (lien params.state |=(p=[name=@t typ=itype] (hole-same-variable t (itype-walk typ.p sub.state))))
5914+ %tag |
5915+ %any-atom &
5916+ %union &((levy cases.t |=(c=itype (hole-known c state))) (levy args.t |=(c=itype (hole-known c state))))
5917+ %grec (levy args.t |=(c=itype (hole-known c state)))
5918+ %collection (levy args.t |=(c=itype (hole-known c state)))
5919+ %face $(t body.t)
5920+ %fn &($(t sample.t) $(t product.t))
5921+ %cell &($(t hed.t) $(t tal.t))
5922+ * &
5923+ ==
5924+++ promote-restricted-numbers
5925+ |= [state=istate env=ienv]
5926+ ^- istate
5927+ :: With no written capitals, there is nothing to promote.
5928+ ?~ caps.state state
5929+ =/ ids=(list @ud) (turn caps.state |=(c=icap id.c))
5930+ =/ free=(list @ud) (free-env-vars env sub.state)
5931+ |-
5932+ ?~ ids state
5933+ =/ t=itype (itype-walk [%var i.ids] sub.state)
5934+ ?: &(?=(%rnvar -.t) !(lien free |=(n=@ud =(n +.t))))
5935+ $(ids t.ids, state state(sub [[+.t [%rvar +.t]] sub.state]))
5936+ $(ids t.ids)
5937+::
5938+++ default-hole-numbers
5939+ |= [all=(list ihole) prior=(list ihole) state=istate env=ienv permit=?]
5940+ ^- istate
5941+ :: Do not default a named capital or a variable captured from env.
5942+ ?. permit state
5943+ ?: =(all prior) state
5944+ ?~ all state
5945+ =/ t=itype (itype-walk [%var id.i.all] sub.state)
5946+ =/ free=(list @ud) (free-env-vars env sub.state)
5947+ =? state &(?=(?(%nvar %rnvar) -.t) !(hole-known t state) !(lien free |=(id=@ud =(id id.t))))
5948+ state(sub [[id.t [%atom %ud]] sub.state])
5949+ $(all t.all)
5950+::
5951+:: Only obligations created inside this definition belong to it.
5952+++ holes-created
5953+ |= [all=(list ihole) prior=(list ihole)]
5954+ ^- (list ihole)
5955+ ?: =(all prior) ~
5956+ ?~ all ~
5957+ [i.all $(all t.all)]
5958+++ hole-uncertain
5959+ |= [t=itype state=istate]
5960+ ^- ?
5961+ =. t (itype-walk t sub.state)
5962+ ?- -.t
5963+ ?(%tag %nvar %rnvar %avar %rvar) !(hole-known t state)
5964+ %union |((lien cases.t |=(c=itype (hole-uncertain c state))) (lien args.t |=(c=itype (hole-uncertain c state))))
5965+ %grec (lien args.t |=(c=itype (hole-uncertain c state)))
5966+ %collection (lien args.t |=(c=itype (hole-uncertain c state)))
5967+ %face $(t body.t)
5968+ %fn |($(t sample.t) $(t product.t))
5969+ %cell |($(t hed.t) $(t tal.t))
5970+ * |
5971+ ==
5972+::
5973+++ unresolved-hole
5974+ |= [all=(list ihole) prior=(list ihole) state=istate]
5975+ ^- (unit idiag)
5976+ =/ work=(list ihole) (flop (holes-created all prior))
5977+ |-
5978+ ?~ work ~
5979+ ?: (hole-known [%var id.i.work] state) $(work t.work)
5980+ ?: (hole-uncertain [%var id.i.work] state)
5981+ `["type hole needs unsupported inference" ~[[at.i.work "type hole"]]]
5982+ `["type hole needs a determined type" ~[[at.i.work "unresolved type hole"]]]
5983+::
53415984++ itype-vars
53425985 |= t=itype
53435986 ^- (list @ud)
53445987 ?- -.t
53455988 %var ~[id.t]
53465989 %avar ~[id.t]
5990+ %rvar ~[id.t]
53475991 %nvar ~[id.t]
5992+ %rnvar ~[id.t]
53485993 %atom ~
53495994 %any-atom ~
53505995 %flag ~
53515996 %noun ~
5997+ %empty ~
53525998 %tag ~
53535999 %const ~
53546000 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
53556001 %recursive ~
6002+ %jrec ~
6003+ %grec (zing (turn args.t |=(c=itype (itype-vars c))))
53566004 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
53576005 %face $(t body.t)
53586006 %fn (weld $(t sample.t) $(t product.t))
@@ -5380,18 +6028,29 @@
53806028 =/ found=(unit itype) (itype-lookup id.t ren)
53816029 ?~ found t
53826030 u.found
6031+ %rvar
6032+ =/ found=(unit itype) (itype-lookup id.t ren)
6033+ ?~ found t
6034+ u.found
53836035 %nvar
53846036 =/ found=(unit itype) (itype-lookup id.t ren)
53856037 ?~ found t
53866038 u.found
6039+ %rnvar
6040+ =/ found=(unit itype) (itype-lookup id.t ren)
6041+ ?~ found t
6042+ u.found
53876043 %atom t
53886044 %any-atom t
53896045 %flag t
53906046 %noun t
6047+ %empty t
53916048 %tag t
53926049 %const t
53936050 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
53946051 %recursive t
6052+ %jrec t
6053+ %grec t(args (turn args.t |=(c=itype (itype-rename c ren))))
53956054 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
53966055 %face [%face name.t $(t body.t)]
53976056 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5407,20 +6066,50 @@
54076066 ?- -.t
54086067 %var |
54096068 %avar =(n id.t)
6069+ %rvar =(n id.t)
54106070 %nvar =(n id.t)
6071+ %rnvar =(n id.t)
54116072 %atom |
54126073 %any-atom |
54136074 %flag |
54146075 %noun |
6076+ %empty |
54156077 %tag |
54166078 %const |
54176079 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
54186080 %recursive |
6081+ %jrec |
6082+ %grec (lien args.t |=(c=itype (itype-var-is-atom n c)))
54196083 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
54206084 %face $(t body.t)
54216085 %fn |($(t sample.t) $(t product.t))
54226086 %cell |($(t hed.t) $(t tal.t))
54236087 ==
6088+++ itype-var-is-restricted
6089+ |= [n=@ud t=itype]
6090+ ^- ?
6091+ ?- -.t
6092+ %var |
6093+ %avar |
6094+ %rvar =(n id.t)
6095+ %nvar |
6096+ %rnvar |
6097+ %atom |
6098+ %any-atom |
6099+ %flag |
6100+ %noun |
6101+ %empty |
6102+ %tag |
6103+ %const |
6104+ %union |((lien cases.t |=(c=itype (itype-var-is-restricted n c))) (lien args.t |=(c=itype (itype-var-is-restricted n c))))
6105+ %recursive |
6106+ %jrec |
6107+ %grec (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6108+ %collection (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6109+ %face $(t body.t)
6110+ %fn |($(t sample.t) $(t product.t))
6111+ %cell |($(t hed.t) $(t tal.t))
6112+ ==
54246113::
54256114:: Canonical numbering makes printed variables independent of the order
54266115:: the unifier happened to allocate intermediates.
@@ -5432,7 +6121,7 @@
54326121 =/ n=@ud 0
54336122 |-
54346123 ?~ vars (itype-rename t ren)
5435− =/ replacement=itype ?:((itype-var-is-atom i.vars t) [%avar n] [%var n])
6124+ =/ replacement=itype ?:((itype-var-is-restricted i.vars t) [%rvar n] ?:((itype-var-is-atom i.vars t) [%avar n] [%var n]))
54366125 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
54376126::
54386127++ instantiate-scheme
@@ -5443,11 +6132,11 @@
54436132 |-
54446133 ?~ vars [(itype-rename typ.scheme ren) state]
54456134 =/ replacement=itype
5446− ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state])
6135+ ?:((itype-var-is-restricted i.vars typ.scheme) [%rvar next.state] ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state]))
54476136 :: A generalized atom variable is a valid origin for re-generalizing
54486137 :: an alias, just as a sample binder is.
54496138 =/ st=istate state(next +(next.state))
5450− =? binders.st ?=(%avar -.replacement) [next.state binders.state]
6139+ =? binders.st |(?=(%avar -.replacement) ?=(%rvar -.replacement)) [next.state binders.state]
54516140 $(vars t.vars, ren [[i.vars replacement] ren], state st)
54526141::
54536142++ icap-lookup
@@ -5518,6 +6207,11 @@
55186207 ?. ?=([%ref @ @] node) ~
55196208 ?. &(=(module +<.node) =(name +>.node)) ~
55206209 `[[%unknown ~] &]
6210+ %apply
6211+ ?. ?=([%apply %list [* ~]] node) ~
6212+ =/ item $(node -.+>.node)
6213+ ?~ item ~
6214+ `[[%or ~[[%atom `0] [%cell pat.u.item [%unknown ~]]]] has.u.item]
55216215 %face
55226216 ?. ?=([%face @ *] node) ~
55236217 ?. (jibb-face-name +<.node) ~
@@ -5572,6 +6266,10 @@
55726266 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
55736267 %fork (imported-faces-valid-list +.node)
55746268 %apply ?:(?=([%apply @ *] node) (imported-faces-valid-list +>.node) |)
6269+ %named
6270+ ?. ?=([%named @ @ *] node) |
6271+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6272+ (imported-faces-valid body.n)
55756273 ==
55766274::
55776275++ imported-faces-valid-list
@@ -5625,6 +6323,15 @@
56256323 =/ aura=@ta (@ta +<.node)
56266324 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
56276325 `[%atom aura]
6326+ %named
6327+ ?. ?=([%named @ @ *] node) ~
6328+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6329+ ?. &((jibb-face-name module.n) (jibb-face-name name.n)) ~
6330+ ?. ?=([%fork *] body.n) ~
6331+ =/ proof=(unit irec-pattern) (rec-pattern body.n (@tas module.n) (@tas name.n))
6332+ ?~ proof ~
6333+ ?. has.u.proof ~
6334+ `[%recursive (@tas module.n) (@tas name.n) `(crip "{(trip name.n)}.{(trip module.n)}")]
56286335 %apply
56296336 ?. ?=([%apply @ *] node) ~
56306337 =/ name=term (@tas +<.node)
@@ -5694,6 +6401,7 @@
56946401 ^- upat
56956402 ?- -.typ
56966403 %noun [%all ~]
6404+ %empty [%empty ~]
56976405 %atom [%atom ~]
56986406 %flag [%or ~[[%atom `0] [%atom `1]]]
56996407 %const [%atom `val.literal.typ]
@@ -5790,21 +6498,54 @@
57906498 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
57916499 $(molds t.molds)
57926500::
5793−:: A public non-generic alias names exactly its origin and arguments.
5794−:: Reusing only an origin could print a different generic instantiation.
6501+:: A prelude union alias is a display name, not a new union identity. An
6502+:: identity-generic alias can carry the origin's arguments only when the
6503+:: origin, arity and ordered parameters match. Swapped, repeated, fixed
6504+:: or phantom parameters cannot be printed that way and remain unsupported
6505+:: when their only available name is private. A nongeneric alias of a
6506+:: generic instantiation cannot be printed with the origin's arguments.
6507+++ identity-union-parameters
6508+ |= [vars=(list @ud) args=(list itype)]
6509+ ^- ?
6510+ ?~ vars ?=(~ args)
6511+ ?~ args |
6512+ ?. =([%var i.vars] i.args) |
6513+ $(vars t.vars, args t.args)
57956514++ prelude-union-alias
57966515 |= [origin=[at=path name=term] args=(list itype) molds=imold-types]
57976516 ^- (unit term)
5798− ?^ args ~
57996517 ?~ molds ~
58006518 =/ template=ischeme template.i.molds
5801− ?: &(?=(~ vars.template) ?=(%union -.typ.template))
5802− ?:(&(=(`origin origin.typ.template) =(args args.typ.template)) `name.i.molds $(molds t.molds))
6519+ ?. ?=(%union -.typ.template) $(molds t.molds)
6520+ ?. =(`origin origin.typ.template) $(molds t.molds)
6521+ ?~ vars.template
6522+ ?^ args $(molds t.molds)
6523+ ?:(=(args args.typ.template) `name.i.molds $(molds t.molds))
6524+ ?: &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args)))
6525+ `name.i.molds
58036526 $(molds t.molds)
58046527::
58056528:: Names exported by the directly imported module are visible through its
58066529:: face; a matching prelude alias is also visible without a qualifier.
58076530::
6531+++ jrec-alias
6532+ |= [origin=path name=term molds=imold-types]
6533+ ^- (unit term)
6534+ ?~ molds ~
6535+ =/ template=ischeme template.i.molds
6536+ ?: &(?=(~ vars.template) ?=(%jrec -.typ.template) =(at.typ.template origin) =(name.typ.template name)) `name.i.molds
6537+ $(molds t.molds)
6538+::
6539+++ grec-visible-alias
6540+ |= [origin=path name=term proof=shape args=(list itype) molds=imold-types]
6541+ ^- (unit term)
6542+ ?~ molds ~
6543+ =/ template=ischeme template.i.molds
6544+ ?. ?=(%grec -.typ.template) $(molds t.molds)
6545+ ?. &(=(at.typ.template origin) =(name.typ.template name) =(proof.typ.template proof)) $(molds t.molds)
6546+ ?. &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args))) $(molds t.molds)
6547+ `name.i.molds
6548+::
58086549++ itype-in-import
58096550 |= [t=itype iface=ifile face=term prelude=(unit ifile)]
58106551 ^- itype
@@ -5824,6 +6565,17 @@
58246565 `(crip "{(trip u.alias)}.{(trip face)}")
58256566 [%union (turn cases.t |=(c=itype (itype-in-import c iface face prelude))) origin.t label (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
58266567 %recursive [%recursive module.t name.t ~]
6568+ %grec
6569+ =/ public=(unit term) ?~(prelude ~ (grec-visible-alias at.t name.t proof.t args.t molds.u.prelude))
6570+ =/ alias=(unit term) ?~(public (grec-visible-alias at.t name.t proof.t args.t molds.iface) public)
6571+ =/ label=(unit @t) ?~(alias ~ ?~(public `(crip "{(trip u.alias)}.{(trip face)}") `u.alias))
6572+ t(label label, args (turn args.t |=(c=itype (itype-in-import c iface face prelude))))
6573+ %jrec
6574+ =/ public=(unit term) ?~(prelude ~ (jrec-alias at.t name.t molds.u.prelude))
6575+ ?^ public t(label `u.public)
6576+ =/ alias=(unit term) (jrec-alias at.t name.t molds.iface)
6577+ ?~ alias t(label ~)
6578+ t(label `(crip "{(trip u.alias)}.{(trip face)}"))
58276579 %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
58286580 %face [%face name.t $(t body.t)]
58296581 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5897,9 +6649,66 @@
58976649 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
58986650 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
58996651::
6652+:: Recognize a unique top-level source mold with exactly a null case and a
6653+:: faced atom-headed cell whose faced tail names that same mold. Its Jibb
6654+:: path and name provide nominal identity. Other recursive shapes fail closed;
6655+:: construction and matching expose the proven shape one layer at a time.
6656+++ simple-source-recursive
6657+ |= [name=term sh=shape state=istate]
6658+ ^- (unit itype)
6659+ ?. (lien top-molds.state |=(n=term =(n name))) ~
6660+ =/ original=(unit shape) (find-simple-mold name molds.state)
6661+ ?~ original ~
6662+ ?. =(u.original sh) ~
6663+ ?. ?=(%union -.sh) ~
6664+ =/ cs=(list shape) cases.sh
6665+ ?~ cs ~
6666+ ?~ t.cs ~
6667+ ?^ t.t.cs ~
6668+ ?. ?=(%const -.i.cs) ~
6669+ ?. =(%null form.lit.i.cs) ~
6670+ ?. ?=(%cell -.i.t.cs) ~
6671+ =/ fs=(list field) fields.i.t.cs
6672+ ?~ fs ~
6673+ ?~ t.fs ~
6674+ ?^ t.t.fs ~
6675+ ?. ?=(%face -.i.fs) ~
6676+ ?. ?=(%aura -.shape.i.fs) ~
6677+ ?. !=(0 aura.shape.i.fs) ~
6678+ ?. ?=(%face -.i.t.fs) ~
6679+ ?. !=(name.i.fs name.i.t.fs) ~
6680+ =/ tail=shape shape.i.t.fs
6681+ ?. ?=(%ref -.tail) ~
6682+ ?. =(names.tail ~[name]) ~
6683+ `[%jrec at.state name `name name.i.fs aura.shape.i.fs name.i.t.fs]
6684+::
6685+++ simple-source-generic-recursive
6686+ |= [name=term sh=shape args=(list itype) state=istate]
6687+ ^- (unit itype)
6688+ ?. ?=(%generic -.sh) ~
6689+ ?. ?=([@ ~] vars.sh) ~
6690+ ?. ?=([* ~] args) ~
6691+ ?~ grec-index.state ~
6692+ ?. =(at.u.grec-index.state at.state) ~
6693+ ?~ prelude.state ~
6694+ ?. =(prelude.u.grec-index.state u.prelude.state) ~
6695+ =/ proof=(unit shape) (~(get by shapes.u.grec-index.state) name)
6696+ ?~ proof ~
6697+ ?. =(u.proof sh) ~
6698+ `[%grec at.state name `name sh args]
6699+::
6700+
59006701++ infer-mold-template
59016702 |= [sh=shape state=istate]
59026703 ^- (unit [template=ischeme state=istate])
6704+ =/ generic=(unit itype)
6705+ ?. ?=([@ ~] active.state) ~
6706+ (simple-source-generic-recursive i.active.state sh ~[[%var next.state]] state)
6707+ ?^ generic `[[u.generic ~[next.state]] state(next +(next.state))]
6708+ =/ direct=(unit itype)
6709+ ?. ?=([@ ~] active.state) ~
6710+ (simple-source-recursive i.active.state sh state)
6711+ ?^ direct `[[u.direct ~] state]
59036712 ?: ?=(%generic -.sh)
59046713 ?~ vars.sh ~
59056714 ?. (distinct-params vars.sh) ~
@@ -5907,17 +6716,19 @@
59076716 =/ out=(unit [typ=itype state=istate])
59086717 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
59096718 ?~ out ~
6719+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
59106720 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
59116721 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
59126722 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
59136723 =/ used=(list @ud) (itype-vars typ.u.out)
59146724 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
5915− `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state)]
6725+ `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
59166726 =/ out=(unit [typ=itype state=istate])
59176727 (infer-simple-shape sh state(params ~, in-mold &))
59186728 ?~ out ~
6729+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
59196730 ?: ?=(^ (itype-vars typ.u.out)) ~
5920− `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state)]
6731+ `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
59216732::
59226733:: A direct imported reference may carry definite reader evidence. Only
59236734:: uniquely supplied, declared inputs are used; unsupported data stay generic.
@@ -5951,7 +6762,7 @@
59516762 ?~ found ~
59526763 ?^ t.found ~
59536764 result.i.found
5954− ?. ?=([%invalid ?(%aura %core) @] raw) ~
6765+ ?. ?=([%invalid ?(%aura %core %overlap) @] raw) ~
59556766 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
59566767::
59576768:: Replay only the shape branches whose evaluation order we can prove.
@@ -6020,17 +6831,24 @@
60206831 |= [sh=shape state=istate]
60216832 ^- (unit [typ=itype state=istate])
60226833 ?- -.sh
6834+ %hole `[[%var next.state] state(next +(next.state), holes [[next.state at.sh] holes.state])]
60236835 %aura
60246836 ?: =(0 aura.sh) `[[%any-atom ~] state]
60256837 `[[%atom aura.sh] state]
60266838 %flag `[[%flag ~] state]
60276839 %noun `[[%noun ~] state]
6840+ %void `[[%empty ~] state]
60286841 %const
6029− ?. |(=(%term form.lit.sh) =(%null form.lit.sh)) ~
6842+ ?. |(=(%term form.lit.sh) =(%null form.lit.sh) =(%loobean form.lit.sh)) ~
6843+ ?: &(=(%loobean form.lit.sh) !|(=(0 val.lit.sh) =(1 val.lit.sh))) ~
60306844 `[[%const lit.sh] state]
60316845 %union
60326846 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
6033− ?. (levy pairs |=(p=upair =(%disjoint relation.p))) ~
6847+ ?: (lien pairs |=(p=upair =(%overlap relation.p))) ~
6848+ =/ source-proof=?
6849+ ?: (levy pairs |=(p=upair =(%disjoint relation.p))) &
6850+ &((union-source-state-safe state 256) (union-source-distinct-tags cases.sh molds.state 256))
6851+ ?. source-proof ~
60346852 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
60356853 ?~ cs ~
60366854 `[[%union types.u.cs ~ ~ ~] state.u.cs]
@@ -6070,10 +6888,13 @@
60706888 ?~ prelude-entry ~
60716889 ?^ vars.u.prelude-entry ~
60726890 `[typ.u.prelude-entry state]
6891+ =/ direct=(unit itype) (simple-source-recursive n u.found state)
6892+ ?^ direct `[u.direct state]
60736893 =/ out=(unit [typ=itype state=istate])
60746894 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
60756895 ?~ out ~
6076− `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state)]
6896+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
6897+ `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state, holes holes.state)]
60776898 %apply
60786899 ?~ ref.sh ~
60796900 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
@@ -6101,17 +6922,20 @@
61016922 ?~ applied ~
61026923 `[u.applied state.u.args]
61036924 ?. ?=(%generic -.u.found) ~
6925+ =/ grec=(unit itype) (simple-source-generic-recursive n u.found types.u.args state.u.args)
6926+ ?^ grec `[u.grec state.u.args]
61046927 ?. (distinct-params vars.u.found) ~
61056928 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
61066929 ?~ params ~
61076930 =/ out=(unit [typ=itype state=istate])
61086931 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
61096932 ?~ out ~
6933+ ?^ (unresolved-hole holes.state.u.out holes.state.u.args state.u.out) ~
61106934 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
61116935 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
61126936 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
61136937 (label-direct-union typ.u.out(args types.u.args) u.found n state.u.args)
6114− `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args)]
6938+ `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args, holes holes.state.u.args)]
61156939 %tvar
61166940 =/ param=(unit itype) (iparam-lookup name.sh params.state)
61176941 ?^ param `[u.param state]
@@ -6151,12 +6975,12 @@
61516975 ^- isample-result
61526976 ?- -.s
61536977 %bind
6154− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6978+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
61556979 [%| "sample shadows a name"]
61566980 =/ t=itype [%var next.state]
61576981 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
61586982 %face
6159− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6983+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
61606984 [%| "sample shadows a name"]
61616985 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
61626986 ?~ t [%| "sample mold is not supported by partial inference"]
@@ -6224,6 +7048,7 @@
62247048 |-
62257049 ?~ ds &
62267050 ?: ?=(%mold -.i.ds) $(ds t.ds)
7051+ ?: =(name.i.ds %proj) |
62277052 ?. (unique-value-name name.i.ds names) |
62287053 ?: ?=(^ (ienv-lookup name.i.ds env)) |
62297054 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
@@ -6247,6 +7072,7 @@
62477072 |-
62487073 ?~ locals &
62497074 =/ n=term name.i.locals
7075+ ?: =(n %proj) |
62507076 ?. (unique-value-name n names) |
62517077 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
62527078 ?: (lien marks.state |=(m=term =(n m))) |
@@ -6426,6 +7252,11 @@
64267252 =/ retried=? ?=(%| -.inferred)
64277253 =? inferred retried (infer-recursive-gate d env local-state)
64287254 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
7255+ ?: !=(obligations.state.p.inferred obligations.state) [%| ["deferred local definition needs unsupported inference" ~]]
7256+ =. state.p.inferred (promote-restricted-numbers state.p.inferred env)
7257+ =. state.p.inferred (default-hole-numbers holes.state.p.inferred holes.state state.p.inferred env !(itype-has-gate (itype-normalize typ.p.inferred sub.state.p.inferred)))
7258+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.inferred holes.state state.p.inferred)
7259+ ?^ hole [%| u.hole]
64297260 =/ merged=(unit [first=icap second=icap])
64307261 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
64317262 ?^ merged
@@ -6441,7 +7272,7 @@
64417272 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
64427273 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
64437274 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
6444− $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state), progressed &)
7275+ $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state, holes holes.state), progressed &)
64457276::
64467277:: Try complete cyclic local groups after individual definitions stall.
64477278:: Components with non-gates or unresolved constraints stay unavailable.
@@ -6531,6 +7362,8 @@
65317362 ?: &(?=(%collection -.expected) =(%list name.expected) (context-list-expression e))
65327363 (infer-list-context e expected env state context)
65337364 ?: ?=(%branch -.e)
7365+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[expected context])
7366+ ?^ empty-list u.empty-list
65347367 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
65357368 ?~ t.arms.e [%| ["branch pattern is not supported by partial inference" ~]]
65367369 ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -6562,6 +7395,7 @@
65627395 ?: ?=(%unknown -.fit)
65637396 ?: &(?=(%collection -.expected) =(%list name.expected))
65647397 [%| ["branch list constraint is not supported by partial inference" ~]]
7398+ ?: ?=(%flag -.expected) [%| ["branch loobean constraint is not supported by partial inference" ~]]
65657399 [%| ["branch union constraint is not supported by partial inference" ~]]
65667400 ?: ?=(%bad -.fit)
65677401 =/ missing=(unit idiag) (missing-union-tag e expected sub.state.p.value context)
@@ -6570,6 +7404,8 @@
65707404 ?^ nested [%| u.nested]
65717405 ?: &(?=(%collection -.expected) =(%list name.expected))
65727406 [%| ["branch arm does not fit its expected list" ~[[context "expected list"] [(span-of e) "branch arm"]]]]
7407+ ?: ?=(%flag -.expected)
7408+ [%| ["branch arm does not fit its expected loobean" ~[[context "expected loobean"] [(span-of e) "branch arm"]]]]
65737409 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
65747410 [%& expected state.p.value(sub sub.fit, next next.fit)]
65757411::
@@ -6745,6 +7581,11 @@
67457581 [%| ["list pattern needs the standard prelude in partial inference" ~]]
67467582 ?~ args.typ [%| ["list pattern is not supported by partial inference" ~]]
67477583 ?^ t.args.typ [%| ["list pattern is not supported by partial inference" ~]]
7584+ =/ item-live=(unit [result=?(%yes %no %unknown) left=@ud])
7585+ (itype-inhabited-proof i.args.typ sub.state caps.state 256)
7586+ ?~ item-live [%| ["list element reachability needs unsupported inference" ~]]
7587+ ?: =(%unknown result.u.item-live) [%| ["list element reachability needs unsupported inference" ~]]
7588+ ?: =(%no result.u.item-live) [%| ["list nonempty pattern is unreachable" ~]]
67487589 ?~ arms.e [%| ["list branch is not supported by partial inference" ~]]
67497590 ?~ t.arms.e [%| ["list branch is not supported by partial inference" ~]]
67507591 ?^ t.t.arms.e [%| ["list branch is not supported by partial inference" ~]]
@@ -6757,7 +7598,7 @@
67577598 [%| ["list branch pattern is not supported by partial inference" ~]]
67587599 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
67597600 ?~ binder [%| ["list branch pattern is not supported by partial inference" ~]]
6760− ?: |(=(head.u.binder tail.u.binder) ?=(^ (ienv-lookup head.u.binder env)) ?=(^ (ienv-lookup tail.u.binder env)) (lien globals.state |=(n=term |(=(n head.u.binder) =(n tail.u.binder)))))
7601+ ?: |(=(head.u.binder %proj) =(tail.u.binder %proj) =(head.u.binder tail.u.binder) ?=(^ (ienv-lookup head.u.binder env)) ?=(^ (ienv-lookup tail.u.binder env)) (lien globals.state |=(n=term |(=(n head.u.binder) =(n tail.u.binder)))))
67617602 [%| ["pattern binder shadows a name" ~]]
67627603 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
67637604 =/ left=iresult
@@ -6794,10 +7635,15 @@
67947635 [%| ["unit branch pattern is not supported by partial inference" ~]]
67957636 =/ binder=(unit term) ?:(first-empty second-name first-name)
67967637 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
6797− ?: |(?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
7638+ ?: |(=(u.binder %proj) ?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
67987639 [%| ["pattern binder shadows a name" ~]]
67997640 =/ payload=(unit itype) (unit-union-payload typ)
68007641 ?~ payload [%| ["unit branch subject is not supported by partial inference" ~]]
7642+ =/ payload-live=(unit [result=?(%yes %no %unknown) left=@ud])
7643+ (itype-inhabited-proof u.payload sub.state.p.subject caps.state.p.subject 256)
7644+ ?~ payload-live [%| ["unit payload reachability needs unsupported inference" ~]]
7645+ ?: =(%unknown result.u.payload-live) [%| ["unit payload reachability needs unsupported inference" ~]]
7646+ ?: =(%no result.u.payload-live) [%| ["unit present pattern is unreachable" ~]]
68017647 =/ extended=ienv [[u.binder [u.payload ~]] env]
68027648 =/ left=iresult
68037649 ?~ expected (infer-fragment val.x ?:(first-empty env extended) state.p.subject)
@@ -6826,12 +7672,14 @@
68267672 =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
68277673 ?: |(?=(%atom -.t) ?=(%any-atom -.t))
68287674 $(ps t.ps, state state.p.item)
6829− ?: &(?=(%nvar -.t) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
7675+ ?: &(|(?=(%nvar -.t) ?=(%rnvar -.t)) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
68307676 $(ps t.ps, state state.p.item)
68317677 ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
68327678 $(ps t.ps, state state.p.item)
68337679 ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
68347680 [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7681+ ?: &(?=(%rvar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7682+ [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
68357683 ?: ?=(%cell -.t)
68367684 [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
68377685 [%| ["interpolation type needs unsupported inference" ~]]
@@ -6894,7 +7742,7 @@
68947742 ^- (unit ienv)
68957743 =. t ?:(?=(%face -.t) body.t t)
68967744 ?: ?=(%bind -.p)
6897− ?: |(?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
7745+ ?: |(=(name.p %proj) ?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
68987746 `[[name.p [t ~]] env]
68997747 ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
69007748 `env
@@ -6942,14 +7790,15 @@
69427790 $(xs t.xs, out (weld out rows), origin +(origin))
69437791::
69447792++ infer-known-union-whole
6945− |= [e=expr env=ienv state=istate]
7793+ |= [e=expr env=ienv subject=iresult]
69467794 ^- (unit iresult)
69477795 ?> ?=(%branch -.e)
6948− =/ subject=iresult (infer-fragment subject.e env state)
69497796 ?: ?=(%| -.subject) `subject
69507797 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
69517798 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
6952− =/ cases=(list itype) cases.typ
7799+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7800+ ?~ live ~
7801+ =/ cases=(list itype) u.live
69537802 =/ remaining=(list itype) cases
69547803 =/ arms=(list arm) arms.e
69557804 =/ st=istate state.p.subject
@@ -6980,14 +7829,15 @@
69807829 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
69817830::
69827831++ infer-known-union-context-whole
6983− |= [e=expr expected=itype env=ienv state=istate context=span]
7832+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
69847833 ^- (unit iresult)
69857834 ?> ?=(%branch -.e)
6986− =/ subject=iresult (infer-fragment subject.e env state)
69877835 ?: ?=(%| -.subject) `subject
69887836 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
69897837 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
6990− =/ cases=(list itype) cases.typ
7838+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7839+ ?~ live ~
7840+ =/ cases=(list itype) u.live
69917841 =/ remaining=(list itype) cases
69927842 =/ arms=(list arm) arms.e
69937843 =/ st=istate state.p.subject
@@ -7025,14 +7875,15 @@
70257875 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body(sub sub.fit, next next.fit), answer `expected)
70267876::
70277877++ infer-known-union-finite
7028− |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
7878+ |= [e=expr env=ienv subject=iresult expected=(unit [typ=itype context=span])]
70297879 ^- iresult
70307880 ?> ?=(%branch -.e)
7031− =/ subject=iresult (infer-fragment subject.e env state)
70327881 ?: ?=(%| -.subject) subject
70337882 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
70347883 ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
7035− =/ expanded=(unit (list ifinite)) (finite-cases cases.typ ~ 0)
7884+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7885+ ?~ live [%| ["union emptiness needs unsupported inference" ~]]
7886+ =/ expanded=(unit (list ifinite)) (finite-cases u.live ~ 0)
70367887 ?~ expanded [%| ["union pattern expansion needs unsupported inference" ~]]
70377888 =/ cases=(list ifinite) u.expanded
70387889 =/ remaining=(list ifinite) cases
@@ -7079,29 +7930,267 @@
70797930 ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
70807931 $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
70817932::
7082−++ infer-known-union-branch
7933+:: Prove a one-arm record pattern covers a known, non-union subject.
7934+:: Variable or partial matches stay unsupported; binding uses the same
7935+:: scope and original payload types as the existing union matcher.
7936+++ single-structured-pattern
7937+ |= e=expr
7938+ ^- ?
7939+ ?. ?=(%branch -.e) |
7940+ ?~ arms.e |
7941+ ?^ t.arms.e |
7942+ =/ p=pattern pat.i.arms.e
7943+ ?. ?=(%cell -.p) |
7944+ !(levy items.p |=(x=pattern ?=(%bind -.x)))
7945+::
7946+++ infer-single-case-branch
7947+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
7948+ ^- iresult
7949+ ?> (single-structured-pattern e)
7950+ ?> ?=(%branch -.e)
7951+ ?> ?=(^ arms.e)
7952+ =/ a=arm i.arms.e
7953+ =/ subject=iresult (infer-fragment subject.e env state)
7954+ ?: ?=(%| -.subject) subject
7955+ =/ st=istate state.p.subject
7956+ =/ typ=itype (itype-normalize typ.p.subject sub.st)
7957+ ?: ?=(%union -.typ) [%| ["single-case pattern needs unsupported inference" ~]]
7958+ ?. =(%full (union-pattern pat.a typ))
7959+ [%| ["single-case pattern needs unsupported inference" ~]]
7960+ =/ bound=(unit ienv) (union-pattern-bind pat.a typ env globals.st)
7961+ ?~ bound [%| ["pattern binder shadows a name" ~]]
7962+ ?~ expected (infer-fragment val.a u.bound st)
7963+ =/ body=iresult (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
7964+ ?: ?=(%| -.body) body
7965+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7966+ ?: ?=(%unknown -.fit) [%| ["single-case branch result constraint is not supported by partial inference" ~]]
7967+ ?: ?=(%bad -.fit)
7968+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7969+ ?^ missing [%| u.missing]
7970+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body typ.u.expected sub.state.p.body next.state.p.body context.u.expected)
7971+ ?^ nested [%| u.nested]
7972+ [%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7973+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7974+ [%| ["single-case branch result needs context in partial inference" ~]]
7975+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
7976+::
7977+:: This view is used only by pattern analysis, never exported or bound as
7978+:: the subject. Only null plus a two-binder/wildcard cell is supported; its
7979+:: tail keeps the original recursive type. Other patterns fail closed.
7980+++ jrec-match-view
7981+ |= [e=expr subject=iresult]
7982+ ^- iresult
7983+ ?: ?=(%| -.subject) subject
7984+ ?. ?=(%branch -.e) subject
7985+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7986+ ?. ?=(%jrec -.typ) subject
7987+ ?~ arms.e subject
7988+ ?~ t.arms.e subject
7989+ ?^ t.t.arms.e subject
7990+ =/ x=pattern pat.i.arms.e
7991+ =/ y=pattern pat.i.t.arms.e
7992+ =/ empty=? &(?=(%lit -.x) =(%null form.lit.x))
7993+ =/ full=pattern ?:(empty y x)
7994+ ?. |(empty &(?=(%lit -.y) =(%null form.lit.y))) subject
7995+ ?. ?=(%cell -.full) subject
7996+ ?~ items.full subject
7997+ ?~ t.items.full subject
7998+ ?^ t.t.items.full subject
7999+ ?. |(?=(%bind -.i.items.full) ?=(%any -.i.items.full)) subject
8000+ ?. |(?=(%bind -.i.t.items.full) ?=(%any -.i.t.items.full)) subject
8001+ ?: =(0 jrec-fuel.state.p.subject)
8002+ [%| ["recursive mold unfolding needs unsupported inference" ~]]
8003+ =/ nil=itype [%const [%null %n 0 '~']]
8004+ =/ cell=itype [%cell [%face head.typ [%atom aura.typ]] [%face tail.typ typ]]
8005+ [%& [%union ~[nil cell] ~ ~ ~] state.p.subject(jrec-fuel (dec jrec-fuel.state.p.subject))]
8006+::
8007+:: A bounded source-proven tree match permits flat tag patterns and
8008+:: nonbinding catch-alls. Whole-case binders cannot consume the temporary
8009+:: structural view. Pattern count and field arity are checked first.
8010+++ grec-simple-pattern
8011+ |= [pat=pattern view=itype]
8012+ ^- ?
8013+ ?. ?=(%cell -.pat) |
8014+ ?~ items.pat |
8015+ =/ first=pattern i.items.pat
8016+ ?. ?=(%lit -.first) |
8017+ ?. =(%term form.lit.first) |
8018+ =/ chosen=(unit itype) (contextual-tagged-case view val.lit.first ~)
8019+ ?~ chosen |
8020+ ?> ?=(%cell -.u.chosen)
8021+ =/ rest=(list pattern) t.items.pat
8022+ =/ arity=? ?:(?=(%cell -.tal.u.chosen) ?=([* [* ~]] rest) ?=([* ~] rest))
8023+ ?. arity |
8024+ (levy rest |=(p=pattern |(?=(%bind -.p) ?=(%any -.p))))
8025+::
8026+:: A catch-all with no binder is safe even when it covers both cases.
8027+:: A bound whole case still declines to avoid exporting the analysis view.
8028+++ grec-patterns-eligible
8029+ |= [arms=(list arm) view=itype left=@ud]
8030+ ^- ?
8031+ ?~ arms &
8032+ ?: =(0 left) |
8033+ =/ pat=pattern pat.i.arms
8034+ ?. |(?=(%any -.pat) (grec-simple-pattern pat view)) |
8035+ $(arms t.arms, left (dec left))
8036+++ grec-match-view
8037+ |= [e=expr subject=iresult]
8038+ ^- iresult
8039+ ?: ?=(%| -.subject) subject
8040+ ?. ?=(%branch -.e) subject
8041+ ?. (grec-direct-context typ.p.subject sub.state.p.subject) subject
8042+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8043+ ?. ?=(%grec -.typ) subject
8044+ ?~ arms.e subject
8045+ =/ view=(unit [view=itype left=@ud]) (grec-unfold-view typ jrec-fuel.state.p.subject)
8046+ ?~ view [%| ["recursive mold unfolding needs unsupported inference" ~]]
8047+ ?. (grec-patterns-eligible arms.e view.u.view 128) subject
8048+ [%& view.u.view state.p.subject(jrec-fuel left.u.view)]
8049+::
8050+:: A single-arm diagnostic only probes a direct, source-typed in-scope wing;
8051+:: other subjects retain the prior single-pattern inference path.
8052+++ grec-single-wing-subject
70838053 |= [e=expr env=ienv state=istate]
8054+ ^- (unit iresult)
8055+ ?. ?=(%wing -.e) ~
8056+ ?. ?=([@ ~] names.e) ~
8057+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8058+ ?~ scheme ~
8059+ ?. (grec-direct-context typ.u.scheme sub.state) ~
8060+ `(infer-fragment e env state)
8061+::
8062+++ infer-known-union-branch-subject
8063+ |= [e=expr env=ienv subject=iresult]
70848064 ^- iresult
7085− =/ whole=(unit iresult) (infer-known-union-whole e env state)
7086− ?~ whole (infer-known-union-finite e env state ~)
8065+ =. subject (grec-match-view e subject)
8066+ =. subject (jrec-match-view e subject)
8067+ =/ whole=(unit iresult) (infer-known-union-whole e env subject)
8068+ ?~ whole (infer-known-union-finite e env subject ~)
70878069 u.whole
70888070::
7089−++ infer-known-union-context
7090− |= [e=expr expected=itype env=ienv state=istate context=span]
8071+++ infer-known-union-branch
8072+ |= [e=expr env=ienv state=istate]
8073+ ^- iresult
8074+ ?> ?=(%branch -.e)
8075+ (infer-known-union-branch-subject e env (infer-fragment subject.e env state))
8076+::
8077+++ infer-known-union-context-subject
8078+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
70918079 ^- iresult
7092− =/ whole=(unit iresult) (infer-known-union-context-whole e expected env state context)
7093− ?~ whole (infer-known-union-finite e env state `[expected context])
8080+ =. subject (grec-match-view e subject)
8081+ =. subject (jrec-match-view e subject)
8082+ =/ whole=(unit iresult) (infer-known-union-context-whole e expected env subject context)
8083+ ?~ whole (infer-known-union-finite e env subject `[expected context])
70948084 u.whole
70958085::
8086+:: Limit speculative subject inference to wings and shallow calls;
8087+:: grouping is peeled linearly and cannot introduce a nested branch.
8088+++ simple-union-subject-arg
8089+ |= e=expr
8090+ ^- ?
8091+ ?- -.e
8092+ %wing &
8093+ %lit &
8094+ %str !(lien pieces.e |=(p=piece ?=(%expr -.p)))
8095+ * |
8096+ ==
8097+::
8098+++ safe-union-subject
8099+ |= e=expr
8100+ ^- ?
8101+ ?: ?=(%group -.e) $(e inner.e)
8102+ ?: ?=(%wing -.e) &
8103+ ?. ?=(%call -.e) |
8104+ ?. ?=(%wing -.head.e) |
8105+ (levy args.e simple-union-subject-arg)
8106+::
8107+++ duplicate-loobean-arms
8108+ |= e=expr
8109+ ^- ?
8110+ ?. ?=(%branch -.e) |
8111+ ?~ arms.e |
8112+ ?~ t.arms.e |
8113+ ?^ t.t.arms.e |
8114+ =/ x=pattern pat.i.arms.e
8115+ =/ y=pattern pat.i.t.arms.e
8116+ ?. &(?=(%lit -.x) ?=(%lit -.y)) |
8117+ ?. &(=(%loobean form.lit.x) =(%loobean form.lit.y)) |
8118+ =(val.lit.x val.lit.y)
8119+::
8120+++ union-subject-call
8121+ |= e=expr
8122+ ^- ?
8123+ ?: ?=(%group -.e) $(e inner.e)
8124+ ?=(%call -.e)
8125+::
70968126++ known-union-subject
70978127 |= [e=expr env=ienv state=istate]
7098− ^- (unit itype)
8128+ ^- (unit iresult)
8129+ ?. (safe-union-subject e) ~
8130+ =/ subject=iresult (infer-fragment e env state)
8131+ ?: ?=(%| -.subject) ?:((union-subject-call e) `subject ~)
8132+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8133+ ?. |(?=(%union -.typ) ?=(%jrec -.typ) &(?=(%grec -.typ) (grec-direct-context typ.p.subject sub.state.p.subject))) ~
8134+ `subject
8135+::
8136+:: A direct wing with an already-known union may skip genuinely empty cases
8137+:: when checking a one-arm match. Other subjects keep their existing path.
8138+:: A directly known canonical list of an empty element contains only null.
8139+:: This helper never refines an opaque or variable-bound subject.
8140+++ empty-list-null-branch
8141+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
8142+ ^- (unit iresult)
8143+ ?. ?=(%branch -.e) ~
8144+ ?~ arms.e ~
8145+ ?^ t.arms.e ~
8146+ ?. (unit-empty-pattern pat.i.arms.e) ~
8147+ ?. ?=(%wing -.subject.e) ~
8148+ ?. ?=([@ ~] names.subject.e) ~
8149+ =/ scheme=(unit ischeme) (ienv-lookup i.names.subject.e env)
8150+ ?~ scheme ~
8151+ ?. ?=(%collection -.typ.u.scheme) ~
8152+ ?. =(%list name.typ.u.scheme) ~
8153+ ?~ prelude.state ~
8154+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb) ~
8155+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8156+ ?~ standard ~
8157+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
8158+ =/ subject=iresult (infer-fragment subject.e env state)
8159+ ?: ?=(%| -.subject) ~
8160+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8161+ ?. ?=(%collection -.typ) ~
8162+ ?. =(%list name.typ) ~
8163+ ?~ args.typ ~
8164+ ?^ t.args.typ ~
8165+ =/ proof=(unit [empty=? left=@ud]) (itype-empty-proof i.args.typ sub.state.p.subject 256)
8166+ ?~ proof ~
8167+ ?. empty.u.proof ~
8168+ ?~ expected `(infer-fragment val.i.arms.e env state.p.subject)
8169+ =/ body=iresult (infer-call-context-arg val.i.arms.e typ.u.expected env state.p.subject context.u.expected)
8170+ ?: ?=(%| -.body) `body
8171+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
8172+ ?: ?=(%unknown -.fit) `[%| ["single-case branch result constraint is not supported by partial inference" ~]]
8173+ ?: ?=(%bad -.fit) `[%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.i.arms.e) "branch arm"]]]]
8174+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8175+ `[%| ["single-case branch result needs context in partial inference" ~]]
8176+ `[%& typ.p.body state.p.body(sub sub.fit, next next.fit)]
8177+::
8178+++ known-empty-union-wing
8179+ |= [e=expr env=ienv state=istate]
8180+ ^- (unit iresult)
70998181 ?. ?=(%wing -.e) ~
8182+ ?. ?=([@ ~] names.e) ~
8183+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8184+ ?~ scheme ~
8185+ ?. (contextual-direct-union typ.u.scheme) ~
71008186 =/ subject=iresult (infer-fragment e env state)
71018187 ?: ?=(%| -.subject) ~
71028188 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
71038189 ?. ?=(%union -.typ) ~
7104− `typ
8190+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
8191+ ?~ live ~
8192+ ?: =(u.live cases.typ) ~
8193+ `subject
71058194::
71068195:: Infer changes only against a fully known record spine. Retain the
71078196:: target type; unknown spines and repeated edits remain unsupported.
@@ -7208,7 +8297,7 @@
72088297 |= [e=expr actual=itype expected=itype sub=isub next=@ud context=span]
72098298 ^- (unit idiag)
72108299 =/ original=[left=itype right=itype] [actual expected]
7211− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
8300+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
72128301 =/ fit=ifit (itype-fit actual expected sub next)
72138302 ?. ?=(%bad -.fit) ~
72148303 =. actual (itype-walk actual sub)
@@ -7229,7 +8318,7 @@
72298318 ?~ items ~
72308319 ?~ t.items (nested-missing-tag val.i.items actual expected sub next context)
72318320 =/ original=[left=itype right=itype] [actual expected]
7232− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
8321+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
72338322 =. actual (itype-walk actual sub)
72348323 =. expected (itype-walk expected sub)
72358324 ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
@@ -7239,10 +8328,30 @@
72398328 ?. ?=(%ok -.first) ~
72408329 $(items t.items, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
72418330::
8331+:: A term-headed pair is the same noun as a two-item cell. Preserve the
8332+:: whole pair span for the synthetic head and the value's own span for
8333+:: the payload; unresolved term constraints follow ordinary cell inference.
8334+++ pair-as-cell
8335+ |= e=expr
8336+ ^- expr
8337+ ?> ?=(%pair -.e)
8338+ =/ head=expr [%lit at.e [%term %tas tag.e (crip ['%' (trip tag.e)])]]
8339+ [%tuple at.e ~[[at.e ~ head] [(span-of val.e) ~ val.e]]]
8340+::
8341+:: A segment costs one shared step; dynamic segments are not handled yet.
8342+++ qath-static-fuel
8343+ |= [segs=(list qseg) fuel=@ud]
8344+ ^- (unit @ud)
8345+ ?~ segs `fuel
8346+ ?: =(0 fuel) ~
8347+ ?. ?=(%knot -.i.segs) ~
8348+ $(segs t.segs, fuel (dec fuel))
8349+::
72428350++ infer-fragment
72438351 |= [e=expr env=ienv state=istate]
72448352 ^- iresult
72458353 ?- -.e
8354+ %pair $(e (pair-as-cell e))
72468355 %lit
72478356 ?- form.lit.e
72488357 %number ?: =(%ud aura.lit.e)
@@ -7280,6 +8389,21 @@
72808389 ?: ?=(%| -.result) result
72818390 [%& [%collection %list ~[element]] state.p.result]
72828391 %str (infer-string-pieces pieces.e env state)
8392+ %qath
8393+ ?~ prelude.state [%| ["application path needs the standard prelude in partial inference" ~]]
8394+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8395+ [%| ["application path needs the standard prelude in partial inference" ~]]
8396+ =/ standard=(unit ischeme) (find-jibb-mold %qath u.prelude.state)
8397+ ?~ standard [%| ["application path needs the standard prelude in partial inference" ~]]
8398+ ?. ?=(~ vars.u.standard) [%| ["application path mold needs unsupported inference" ~]]
8399+ =/ typ=itype typ.u.standard
8400+ ?. ?=(%jrec -.typ) [%| ["application path mold needs unsupported inference" ~]]
8401+ ?. &(=(at.typ /lib/jibb/internal/jibb) =(%qath name.typ) =(%i head.typ) =(%ta aura.typ) =(%t tail.typ))
8402+ [%| ["application path mold needs unsupported inference" ~]]
8403+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8404+ =/ remain=(unit @ud) (qath-static-fuel segs.e (dec jrec-fuel.state))
8405+ ?~ remain [%| ["application path segments need unsupported inference" ~]]
8406+ [%& typ state(jrec-fuel u.remain)]
72838407 %wing
72848408 ?~ names.e [%| ["empty wing" ~]]
72858409 ?^ t.names.e
@@ -7322,6 +8446,9 @@
73228446 [%| ["local molds shadow a name" ~]]
73238447 =/ local-state=istate
73248448 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8449+ =/ mold-hole=(unit span) (simple-local-mold-hole defs.e)
8450+ ?^ mold-hole
8451+ [%| ["type hole needs a determined type" ~[[u.mold-hole "unresolved type hole"]]]]
73258452 ?. (local-molds-supported local-molds local-state)
73268453 [%| ["local molds need unsupported inference" ~]]
73278454 =/ values=(list def) (local-value-defs defs.e)
@@ -7331,12 +8458,22 @@
73318458 ?: ?=(%| -.result) result
73328459 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
73338460 %branch
8461+ ?^ defer.state (dg-boolean-branch e env state)
73348462 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
7335− ?~ t.arms.e (infer-cell-branch e env state)
8463+ ?~ t.arms.e
8464+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state ~)
8465+ ?^ empty-list u.empty-list
8466+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
8467+ ?^ empty-union (infer-known-union-branch-subject e env u.empty-union)
8468+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8469+ ?^ single (infer-known-union-branch-subject e env u.single)
8470+ ?: (single-structured-pattern e) (infer-single-case-branch e env state ~)
8471+ (infer-cell-branch e env state ~)
73368472 ?^ t.t.arms.e (infer-known-union-branch e env state)
7337− =/ known=(unit itype) (known-union-subject subject.e env state)
7338− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
7339− (infer-known-union-branch e env state)
8473+ =/ known=(unit iresult) (known-union-subject subject.e env state)
8474+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
8475+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
8476+ (infer-known-union-branch-subject e env u.known)
73408477 =/ x=arm i.arms.e
73418478 =/ y=arm i.t.arms.e
73428479 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
@@ -7345,7 +8482,7 @@
73458482 ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
73468483 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
73478484 (infer-known-union-branch e env state)
7348− ?^ known (infer-known-union-branch e env state)
8485+ ?: &(?=(^ known) ?=(%& -.u.known)) (infer-known-union-branch-subject e env u.known)
73498486 ?: =(val.lit.pat.x val.lit.pat.y)
73508487 [%| ["branch does not cover both loobeans" ~]]
73518488 =/ subject=iresult $(e subject.e)
@@ -7386,6 +8523,9 @@
73868523 =/ value=iresult
73878524 (infer-call-context-arg val.e typ.u.target env state.u.target at.shape.e)
73888525 ?: ?=(%| -.value) value
8526+ =/ shape=(unit [source=iwfields target=iwfields])
8527+ (width-shape typ.p.value typ.u.target sub.state.p.value)
8528+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
73898529 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
73908530 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
73918531 ?: ?=(%bad -.fit)
@@ -7394,6 +8534,8 @@
73948534 =/ nested=(unit idiag) (nested-missing-tag val.e typ.p.value typ.u.target sub.state.p.value next.state.p.value at.shape.e)
73958535 ?^ nested [%| u.nested]
73968536 [%| ["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)]]]]
8537+ ?: &(?=(^ defer.state.p.value) !(dg-stable-fit typ.p.value typ.u.target sub.fit))
8538+ [%| ["deferred cast fit needs stable inference" ~]]
73978539 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
73988540 [%& merged state.p.value(sub sub.fit, next next.fit)]
73998541 %crash [%& [%var next.state] state(next +(next.state))]
@@ -7417,45 +8559,9 @@
74178559 [%& [%fn typ.p.sam typ.p.body] state.p.body]
74188560 %call
74198561 ?~ args.e [%| ["call has no argument" ~]]
7420− =/ head=iresult $(e head.e)
7421− ?: ?=(%| -.head) head
7422− =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
7423− =/ arg=iresult
7424− ?^ t.args.e
7425− ?: ?=(%fn -.head-type)
7426− (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
7427− (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
7428− ?: ?=(%fn -.head-type)
7429− (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
7430− $(e i.args.e, state state.p.head)
7431− ?: ?=(%| -.arg) arg
7432− =/ st=istate state.p.arg
7433− =/ ht=itype (itype-walk typ.p.head sub.st)
7434− ?: ?=(%fn -.ht)
7435− =/ fit=ifit (itype-fit typ.p.arg sample.ht sub.st next.st)
7436− ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
7437− ?: ?=(%bad -.fit)
7438− ?~ t.args.e
7439− =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
7440− ?^ missing [%| u.missing]
7441− =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
7442− ?^ nested [%| u.nested]
7443− [%| ["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)]]]]
7444− =/ bad=(unit [at=span typ=itype])
7445− (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
7446− =/ whole-args=span
7447− [beg:(span-of i.args.e) end:(span-of (rear args.e))]
7448− =/ arg-at=span ?~(bad whole-args at.u.bad)
7449− =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
7450− [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [arg-at (site-type-note "argument" arg-type sub.st)]]]]
7451− ?: &((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))
7452− [%| ["call result face propagation is not supported by partial inference" ~]]
7453− [%& product.ht st(sub sub.fit, next next.fit)]
7454− =/ result=itype [%var next.st]
7455− =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
7456− ?~ uni
7457− [%| ["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)]]]]
7458− [%& result st(next +(next.st), sub u.uni)]
8562+ ?: (explicit-proj-call e env state)
8563+ [%| ["proj needs an expected record type" ~]]
8564+ (infer-call-with-head e env state (infer-fragment head.e env state))
74598565 * [%| ["expression is not supported by partial inference" ~]]
74608566 ==
74618567::
@@ -7463,28 +8569,338 @@
74638569:: failed. If an intermediate fit is uncertain, retain the whole argument
74648570:: span rather than assigning blame to a particular argument.
74658571::
7466−++ call-error-site
7467− |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
7468− ^- (unit [at=span typ=itype])
7469− ?~ args ~
7470− =/ original=[left=itype right=itype] [actual expected]
7471− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
7472− =. actual (itype-walk actual sub)
7473− =. expected (itype-walk expected sub)
7474− ?: &(?=(%face -.expected) !?=(%face -.actual))
7475− $(expected body.expected)
7476− ?~ t.args
7477− =/ fit=ifit (itype-fit actual expected sub next)
7478− ?. ?=(%bad -.fit) ~
7479− `[(span-of i.args) (itype-normalize actual sub)]
7480− ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
7481− =/ first=ifit (itype-fit hed.actual hed.expected sub next)
7482− ?: ?=(%bad -.first) `[(span-of i.args) (itype-normalize hed.actual sub)]
7483− ?: ?=(%unknown -.first) ~
7484− $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
7485−::
7486−:: Context can help a call argument or cast value while the final fit
7487−:: checks the complete right-nested type, including any written faces.
8572+:: Check a call using the head already inferred in this state. Keeping
8573+:: this shared avoids evaluating or instantiating a contextual head twice.
8574+++ width-has-projections
8575+ |= ps=(list iwprojection)
8576+ ^- ?
8577+ ?~ ps |
8578+ &
8579+::
8580++$ iwidth-elaboration [original=expr typ=itype sub=isub projections=(list iwprojection)]
8581+++ infer-width-elaboration
8582+ |= [e=expr env=ienv state=istate]
8583+ ^- (each iwidth-elaboration idiag)
8584+ =/ out=iresult (infer-fragment e env state)
8585+ ?: ?=(%| -.out) [%| p.out]
8586+ [%& [e typ.p.out sub.state.p.out (flop projections.state.p.out)]]
8587+::
8588+:: Source-bound gate-layout evidence, confined to checked root gate
8589+:: definitions and direct unshadowed prelude calls. The prepared prelude
8590+:: interface and its retained source are trusted as a matching artifact.
8591+:: Layouts identify sample binder faces; they do not change call arity or
8592+:: authorize stripping nested value faces. Unknown origins use ordinary fit.
8593+++ direct-written-gates
8594+ |= [ds=(list def) out=ivisited]
8595+ ^- ivisited
8596+ ?~ ds out
8597+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8598+ ?. |(?=(%gate -.val.i.ds) ?=(%gate-wide -.val.i.ds)) $(ds t.ds)
8599+ $(ds t.ds, out (~(put by out) name.i.ds &))
8600+++ direct-may-use-prelude
8601+ |= [ds=(list def) root=ivisited heads=ivisited]
8602+ ^- ?
8603+ ?~ ds |
8604+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8605+ =/ refs=(list term) (dependency-expr val.i.ds)
8606+ =/ has-root=? (lien refs |=(n=term ?=(^ (~(get by root) n))))
8607+ =/ has-head=? (lien refs |=(n=term ?=(^ (~(get by heads) n))))
8608+ ?: &(has-root has-head) &
8609+ $(ds t.ds)
8610+++ direct-unique-names
8611+ |= [names=(list term) seen=ivisited]
8612+ ^- ?
8613+ ?~ names &
8614+ ?: ?=(^ (~(get by seen) i.names)) |
8615+ $(names t.names, seen (~(put by seen) i.names &))
8616+++ direct-prelude-evidence
8617+ |= [ds=(list def) prelude=(unit ifile)]
8618+ ^- (unit igate-prelude-evidence)
8619+ ?~ prelude ~
8620+ ?~ source.u.prelude ~
8621+ =/ root=ivisited (direct-written-gates ds ~)
8622+ =/ names=(list term) (turn values.u.prelude |=(e=[name=term scheme=ischeme] name.e))
8623+ =/ heads=ivisited (graph-nameset names ~)
8624+ ?. (direct-may-use-prelude ds root heads) ~
8625+ =/ parsed (parse at.u.prelude u.source.u.prelude)
8626+ ?: ?=(%| -.parsed) ~
8627+ ?^ (duplicate-defs defs.p.parsed) ~
8628+ ?. (direct-unique-names (global-value-names defs.p.parsed) ~) ~
8629+ =/ gates=(map term def) (direct-checked-gates defs.p.parsed values.u.prelude)
8630+ `[u.prelude gates]
8631+++ direct-checked-gates
8632+ |= [ds=(list def) env=ienv]
8633+ ^- (map term def)
8634+ =/ names=(list term) (turn env |=(e=[name=term scheme=ischeme] name.e))
8635+ =/ known=ivisited (graph-nameset names ~)
8636+ =/ out=(map term def) ~
8637+ |-
8638+ ?~ ds out
8639+ =/ d=def i.ds
8640+ ?: ?=(%mold -.d) $(ds t.ds)
8641+ ?. ?=(^ (~(get by known) name.d)) $(ds t.ds)
8642+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) $(ds t.ds)
8643+ $(ds t.ds, out (~(put by out) name.d d))
8644+++ direct-find-gate
8645+ |= [n=term ds=(list def)]
8646+ ^- (unit def)
8647+ ?~ ds ~
8648+ ?: &(?=(%value -.i.ds) =(n name.i.ds)) `i.ds
8649+ $(ds t.ds)
8650+++ direct-gate-sample
8651+ |= d=def
8652+ ^- (unit sample)
8653+ ?. ?=(%value -.d) ~
8654+ ?- -.val.d
8655+ %gate `sample.val.d
8656+ %gate-wide `sample.val.d
8657+ * ~
8658+ ==
8659+++ direct-sample-name
8660+ |= sam=sample
8661+ ^- (unit term)
8662+ ?- -.sam
8663+ %bind `name.sam
8664+ %face `name.sam
8665+ %pun `name.sam
8666+ * ~
8667+ ==
8668+++ direct-field-name
8669+ |= f=field
8670+ ^- (unit term)
8671+ ?- -.f
8672+ %face `name.f
8673+ %pun `name.f
8674+ * ~
8675+ ==
8676+++ direct-slot-body
8677+ |= [typ=itype name=(unit term)]
8678+ ^- (unit itype)
8679+ ?~ name `typ
8680+ ?. ?=(%face -.typ) ~
8681+ ?. =(name.typ u.name) ~
8682+ `body.typ
8683+++ direct-invariant
8684+ |= [a=itype b=itype sub=isub next=@ud]
8685+ ^- ifit
8686+ ?: (itype-face-asym a b sub) [%unknown ~]
8687+ =/ forward=ifit (itype-fit a b sub next)
8688+ ?. ?=(%ok -.forward) [%unknown ~]
8689+ ?: (itype-face-asym a b sub.forward) [%unknown ~]
8690+ =/ reverse=ifit (itype-fit b a sub.forward next.forward)
8691+ ?. ?=(%ok -.reverse) [%unknown ~]
8692+ reverse
8693+++ direct-function-fit
8694+ |= [a=itype b=itype sam=sample sh=shape sub=isub next=@ud]
8695+ ^- ifit
8696+ ?. &(?=(%fn -.a) ?=(%fn -.b) ?=(%cell -.sam) ?=(%fn -.sh)) [%unknown ~]
8697+ ?. ?=(%cell -.sample.sh) [%unknown ~]
8698+ =/ as=(list sample) items.sam
8699+ =/ bs=(list field) fields.sample.sh
8700+ ?~ as [%unknown ~]
8701+ ?~ t.as [%unknown ~]
8702+ ?^ t.t.as [%unknown ~]
8703+ ?~ bs [%unknown ~]
8704+ ?~ t.bs [%unknown ~]
8705+ ?^ t.t.bs [%unknown ~]
8706+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) [%unknown ~]
8707+ =/ an=(unit term) (direct-sample-name i.as)
8708+ =/ bn=(unit term) (direct-field-name i.bs)
8709+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8710+ =/ x=(unit itype) (direct-slot-body hed.sample.a an)
8711+ =/ y=(unit itype) (direct-slot-body hed.sample.b bn)
8712+ ?~ x [%unknown ~]
8713+ ?~ y [%unknown ~]
8714+ =/ first=ifit (direct-invariant u.x u.y sub next)
8715+ ?. ?=(%ok -.first) [%unknown ~]
8716+ =. an (direct-sample-name i.t.as)
8717+ =. bn (direct-field-name i.t.bs)
8718+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8719+ =/ x2=(unit itype) (direct-slot-body tal.sample.a an)
8720+ =/ y2=(unit itype) (direct-slot-body tal.sample.b bn)
8721+ ?~ x2 [%unknown ~]
8722+ ?~ y2 [%unknown ~]
8723+ =/ second=ifit (direct-invariant u.x2 u.y2 sub.first next.first)
8724+ ?. ?=(%ok -.second) [%unknown ~]
8725+ (direct-invariant product.a product.b sub.second next.second)
8726+:: This is a tentative proof: its caller must require closed call samples
8727+:: and repeat every positional check under the stable final substitution.
8728+++ direct-positional-fit
8729+ |= [args=(list expr) slots=(list sample) actual=itype expected=itype env=ienv state=istate sub=isub next=@ud]
8730+ ^- ifit
8731+ ?~ args [%unknown ~]
8732+ ?~ slots [%unknown ~]
8733+ =/ last=? ?=(~ t.args)
8734+ ?: !=(last ?=(~ t.slots)) [%unknown ~]
8735+ =/ split=(unit [left=itype right=itype])
8736+ ?: last `[actual expected]
8737+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8738+ `[hed.actual hed.expected]
8739+ ?~ split [%unknown ~]
8740+ =/ x=itype left.u.split
8741+ =/ y=itype right.u.split
8742+ =/ expected-name=(unit term) (direct-sample-name i.slots)
8743+ =/ expected-body=(unit itype) (direct-slot-body y expected-name)
8744+ ?~ expected-body [%unknown ~]
8745+ =. y u.expected-body
8746+ =/ fit=ifit (itype-fit x y sub next)
8747+ =/ accepted=? &(?=(%ok -.fit) !(itype-positional-slot-face-asym x y sub.fit))
8748+ =/ result=(unit ifit)
8749+ ?: accepted `fit
8750+ ?. &(?=(%face -.i.slots) ?=(%fn -.shape.i.slots)) ~
8751+ ?. ?=(%wing -.i.args) ~
8752+ ?. ?=([@ ~] names.i.args) ~
8753+ ?. (unique-value-name i.names.i.args globals.state) ~
8754+ =/ source=(unit def) (~(get by gate-defs.state) i.names.i.args)
8755+ ?~ source ~
8756+ =/ sample=(unit sample) (direct-gate-sample u.source)
8757+ ?~ sample ~
8758+ =/ trial=ifit (direct-function-fit x y u.sample shape.i.slots sub next)
8759+ ?. ?=(%ok -.trial) ~
8760+ `trial
8761+ ?~ result [%unknown ~]
8762+ =. fit u.result
8763+ ?: last fit
8764+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
8765+ ?. ?=(%ok -.fit) [%unknown ~]
8766+ $(args t.args, slots t.slots, actual tal.actual, expected tal.expected, sub sub.fit, next next.fit)
8767+++ direct-any-gate-arg
8768+ |= [args=(list expr) defs=(map term def)]
8769+ ^- ?
8770+ ?~ args |
8771+ =/ found=?
8772+ ?. ?=(%wing -.i.args) |
8773+ ?. ?=([@ ~] names.i.args) |
8774+ ?=(^ (~(get by defs) i.names.i.args))
8775+ ?: found &
8776+ $(args t.args)
8777+++ direct-gate-call-fit
8778+ |= [e=expr actual=itype expected=itype env=ienv state=istate]
8779+ ^- (unit ifit)
8780+ ?. ?=(%call -.e) ~
8781+ ?~ args.e ~
8782+ ?~ t.args.e ~
8783+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8784+ ?. ?=(%wing -.head.e) ~
8785+ ?. ?=([@ ~] names.head.e) ~
8786+ ?. ?=(~ (ienv-lookup i.names.head.e env)) ~
8787+ ?. (unique-value-name i.names.head.e globals.state) ~
8788+ ?. (direct-any-gate-arg args.e gate-defs.state) ~
8789+ ?~ prelude.state ~
8790+ ?~ source.u.prelude.state ~
8791+ ?~ head-evidence.state ~
8792+ ?. =(u.prelude.state iface.u.head-evidence.state) ~
8793+ ?. ?=(^ (ienv-lookup i.names.head.e values.u.prelude.state)) ~
8794+ =/ head=(unit def) (~(get by gates.u.head-evidence.state) i.names.head.e)
8795+ ?~ head ~
8796+ =/ sam=(unit sample) (direct-gate-sample u.head)
8797+ ?~ sam ~
8798+ ?. ?=(%cell -.u.sam) ~
8799+ =/ fit=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.state next.state)
8800+ ?. ?=(%ok -.fit) ~
8801+ :: Enclosing inference may add constraints after this call. Only a
8802+ :: closed call-sample proof can remain stable under those later bindings.
8803+ =/ actual-final=itype (itype-normalize actual sub.fit)
8804+ =/ expected-final=itype (itype-normalize expected sub.fit)
8805+ ?^ (itype-vars actual-final) ~
8806+ ?^ (itype-vars expected-final) ~
8807+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
8808+ :: A later argument may resolve a variable used by an earlier slot.
8809+ :: Recheck every fit and face against the completed substitution; no
8810+ :: additional binding or fresh variable is permitted in the second pass.
8811+ =/ verified=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.fit next.fit)
8812+ ?. ?=(%ok -.verified) ~
8813+ ?. &(=(sub.fit sub.verified) =(next.fit next.verified)) ~
8814+ `fit
8815+::
8816+++ infer-call-with-head
8817+ |= [e=expr env=ienv state=istate head=iresult]
8818+ ^- iresult
8819+ ?> ?=(%call -.e)
8820+ ?~ args.e [%| ["call has no argument" ~]]
8821+ ?: ?=(%| -.head) head
8822+ =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
8823+ =/ arg=iresult
8824+ ?^ t.args.e
8825+ ?: ?=(%fn -.head-type)
8826+ (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
8827+ (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
8828+ ?: ?=(%fn -.head-type)
8829+ (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
8830+ (infer-fragment i.args.e env state.p.head)
8831+ ?: ?=(%| -.arg) arg
8832+ =/ st=istate state.p.arg
8833+ =/ ht=itype (itype-walk typ.p.head sub.st)
8834+ ?: ?=(%fn -.ht)
8835+ =/ shape=(unit [source=iwfields target=iwfields])
8836+ ?^ t.args.e ~
8837+ (width-shape typ.p.arg sample.ht sub.st)
8838+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
8839+ =/ fit=ifit
8840+ ?^ t.args.e (itype-fit-inner typ.p.arg sample.ht sub.st next.st & |)
8841+ (itype-fit typ.p.arg sample.ht sub.st next.st)
8842+ =/ direct=(unit ifit)
8843+ ?: ?=(%ok -.fit) ~
8844+ (direct-gate-call-fit e typ.p.arg sample.ht env st)
8845+ =. fit ?~(direct fit u.direct)
8846+ ?: ?=(%unknown -.fit)
8847+ ?~ defer.st [%| ["call constraint is not supported by partial inference" ~]]
8848+ =/ edge=(unit dgo) (dg-eligible-ctor e typ.p.head typ.p.arg sample.ht st)
8849+ ?~ edge [%| ["call constraint is not supported by partial inference" ~]]
8850+ ?: (gth (lent obligations.st) 63) [%| ["call constraint is not supported by partial inference" ~]]
8851+ [%& product.ht st(obligations [u.edge obligations.st])]
8852+
8853+ ?: ?=(%bad -.fit)
8854+ ?~ t.args.e
8855+ =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
8856+ ?^ missing [%| u.missing]
8857+ =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
8858+ ?^ nested [%| u.nested]
8859+ [%| ["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)]]]]
8860+ =/ bad=(unit [at=span typ=itype])
8861+ (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
8862+ =/ whole-args=span
8863+ [beg:(span-of i.args.e) end:(span-of (rear args.e))]
8864+ =/ arg-at=span ?~(bad whole-args at.u.bad)
8865+ =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
8866+ [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [arg-at (site-type-note "argument" arg-type sub.st)]]]]
8867+ ?: &(?=(^ defer.st) !(dg-stable-call-fit typ.p.arg sample.ht product.ht sub.fit ?=(^ t.args.e)))
8868+ [%| ["deferred call fit needs stable inference" ~]]
8869+ =/ face-asym=?
8870+ ?^ direct |
8871+ ?^ t.args.e (itype-positional-face-asym args.e typ.p.arg sample.ht sub.fit)
8872+ (itype-face-asym typ.p.arg sample.ht sub.fit)
8873+ ?: &((itype-has-face typ.p.arg sub.fit) face-asym (itype-output-may-be-cell product.ht sub.fit))
8874+ [%| ["call result face propagation is not supported by partial inference" ~]]
8875+ [%& product.ht st(sub sub.fit, next next.fit)]
8876+ =/ result=itype [%var next.st]
8877+ =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
8878+ ?~ uni
8879+ [%| ["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)]]]]
8880+ [%& result st(next +(next.st), sub u.uni)]
8881+::
8882+++ call-error-site
8883+ |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
8884+ ^- (unit [at=span typ=itype])
8885+ ?~ args ~
8886+ =/ original=[left=itype right=itype] [actual expected]
8887+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
8888+ =. actual (itype-walk actual sub)
8889+ =. expected (itype-walk expected sub)
8890+ ?: &(?=(%face -.expected) !?=(%face -.actual))
8891+ $(expected body.expected)
8892+ ?~ t.args
8893+ =/ fit=ifit (itype-fit actual expected sub next)
8894+ ?. ?=(%bad -.fit) ~
8895+ `[(span-of i.args) (itype-normalize actual sub)]
8896+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8897+ =/ first=ifit (itype-fit hed.actual hed.expected sub next)
8898+ ?: ?=(%bad -.first) `[(span-of i.args) (itype-normalize hed.actual sub)]
8899+ ?: ?=(%unknown -.first) ~
8900+ $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
8901+::
8902+:: Context can help a call argument or cast value while the final fit
8903+:: checks the complete right-nested type, including any written faces.
74888904::
74898905:: Context can resolve the payload of a canonical prelude unit, but an
74908906:: unrelated union with a similar noun shape is not the same mold.
@@ -7518,9 +8934,314 @@
75188934 [%| ["unit payload does not fit its expected type" ~[[context (site-type-note "expected unit payload" payload sub.state.p.value)] [(span-of val.e) (site-type-note "payload" typ.p.value sub.state.p.value)]]]]
75198935 [%& expected state.p.value(sub sub.fit, next next.fit)]
75208936::
8937+:: A known gate may receive an enclosing target before its argument is
8938+:: inferred when its result is open or a direct, matching named generic
8939+:: union. Opaque, recursive, tag-constrained and variable-bound union
8940+:: results keep the existing directional path.
8941+++ infer-contextual-call
8942+ |= [e=expr expected=itype env=ienv state=istate]
8943+ ^- iresult
8944+ ?> ?=(%call -.e)
8945+ ?~ args.e [%| ["call has no argument" ~]]
8946+ =/ head=iresult (infer-fragment head.e env state)
8947+ ?: ?=(%| -.head) head
8948+ =/ ht=itype (itype-walk typ.p.head sub.state.p.head)
8949+ ?. ?=(%fn -.ht) (infer-call-with-head e env state head)
8950+ =/ result=itype (itype-walk product.ht sub.state.p.head)
8951+ =/ eligible=?
8952+ ?: ?=(%var -.result) &
8953+ :: A direct known generic union may receive the same nominal result
8954+ :: context before its arguments are checked. Variable-bound origins,
8955+ :: pending tags, recursive identities and unknown atoms stay open.
8956+ ?. &(?=(%union -.product.ht) ?=(%union -.result) ?=(%union -.expected)) |
8957+ ?~ origin.result |
8958+ ?. =(origin.result origin.expected) |
8959+ ?~ args.result |
8960+ ?. =((lent args.result) (lent args.expected)) |
8961+ ?: |((itype-has-tag (itype-normalize result sub.state.p.head)) (itype-has-tag (itype-normalize expected sub.state.p.head))) |
8962+ ?: |((itype-has-recursive (itype-normalize result sub.state.p.head)) (itype-has-recursive (itype-normalize expected sub.state.p.head))) |
8963+ ?: |((itype-has-any-atom result sub.state.p.head) (itype-has-any-atom expected sub.state.p.head)) |
8964+ &
8965+ ?. eligible (infer-call-with-head e env state head)
8966+ ?: |(?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)) (itype-has-tag (itype-normalize expected sub.state.p.head)))
8967+ (infer-call-with-head e env state head)
8968+ =/ sub=(unit isub) (itype-unify result expected sub.state.p.head)
8969+ ?~ sub (infer-call-with-head e env state head)
8970+ (infer-call-with-head e env state [%& typ.p.head state.p.head(sub u.sub)])
8971+::
8972+:: An eligible fully faced literal receives context by name, in source order.
8973+++ width-literal-fields
8974+ |= [items=(list item) axis=@ud fuel=@ud]
8975+ ^- (unit iwfields)
8976+ =/ order=(list iwfield) ~
8977+ =/ index=(map term iwfield) *(map term iwfield)
8978+ |-
8979+ ?~ items ~
8980+ ?: =(0 fuel) ~
8981+ ?~ face.i.items ~
8982+ =/ at-axis=@ud ?~(t.items axis (mul 2 axis))
8983+ =/ entry=iwfield [u.face.i.items at-axis [%noun ~]]
8984+ ?: ?=(^ (~(get by index) name.entry)) ~
8985+ =. index (~(put by index) name.entry entry)
8986+ =. order [entry order]
8987+ ?~ t.items `[(flop order) index]
8988+ $(items t.items, axis +((mul 2 axis)), fuel (dec fuel))
8989+++ width-infer-items
8990+ |= [items=(list item) expected=(map term iwfield) env=ienv state=istate context=span]
8991+ ^- iresult
8992+ ?~ items [%| ["empty record is not supported" ~]]
8993+ ?~ face.i.items [%| ["record face needs unsupported inference" ~]]
8994+ =/ field=(unit iwfield) (~(get by expected) u.face.i.items)
8995+ =/ head=iresult
8996+ ?~ field (infer-fragment val.i.items env state)
8997+ (infer-call-context-arg val.i.items typ.u.field env state context)
8998+ ?: ?=(%| -.head) head
8999+ =/ typ=itype [%face u.face.i.items typ.p.head]
9000+ ?~ t.items [%& typ state.p.head]
9001+ =/ tail=iresult $(items t.items, state state.p.head)
9002+ ?: ?=(%| -.tail) tail
9003+ [%& [%cell typ typ.p.tail] state.p.tail]
9004+++ width-infer-literal
9005+ |= [e=expr expected=itype env=ienv state=istate context=span]
9006+ ^- (unit iresult)
9007+ ?. ?=(%tuple -.e) ~
9008+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) ~
9009+ =/ source=(unit iwfields) (width-literal-fields items.e 1 4.096)
9010+ =/ target=(unit iwfields) (width-scan expected sub.state 1 4.096)
9011+ ?~ source ~
9012+ ?~ target ~
9013+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
9014+ ?. (width-in-order order.u.source order.u.target)
9015+ `(infer-simple-items items.e env state)
9016+ `(width-infer-items items.e index.u.target env state context)
9017+::
9018+:: Experimental intrinsic recognition; real bindings retain normal calls.
9019+++ explicit-proj-call
9020+ |= [e=expr env=ienv state=istate]
9021+ ^- ?
9022+ ?. ?=(%call -.e) |
9023+ ?. ?=([* ~] args.e) |
9024+ ?. ?=(%wing -.head.e) |
9025+ ?. =(names.head.e ~[%proj]) |
9026+ ?: ?=(^ (ienv-lookup %proj env)) |
9027+ ?: (lien globals.state |=(n=term =(n %proj))) |
9028+ ?~ prelude.state &
9029+ ?:(?=(^ (ienv-lookup %proj values.u.prelude.state)) | &)
9030+++ infer-proj-source
9031+ |= [e=expr expected=itype env=ienv state=istate context=span]
9032+ ^- iresult
9033+ ?: ?=(%group -.e) $(e inner.e)
9034+ =/ literal=(unit iresult) (width-infer-literal e expected env state context)
9035+ ?^ literal u.literal
9036+ (infer-fragment e env state)
9037+++ infer-proj-context
9038+ |= [e=expr expected=itype env=ienv state=istate context=span]
9039+ ^- iresult
9040+ ?> ?=(%call -.e)
9041+ ?~ args.e [%| ["proj needs one record" ~]]
9042+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) [%| ["proj needs an expected record type" ~]]
9043+ =/ value=iresult (infer-proj-source i.args.e expected env state context)
9044+ ?: ?=(%| -.value) value
9045+ =/ shape=(unit [source=iwfields target=iwfields])
9046+ (width-proj-shape typ.p.value expected sub.state.p.value)
9047+ ?~ shape [%| ["proj needs a known record containing its expected fields" ~]]
9048+ =/ project=(unit iwidth-result) (width-project u.shape sub.state.p.value next.state.p.value)
9049+ ?~ project [%| ["proj constraint needs unsupported inference" ~]]
9050+ =/ st=istate state.p.value(sub sub.u.project, next next.u.project)
9051+ [%& expected st(projections [[at.e e typ.p.value expected steps.u.project] projections.st])]
9052+::
9053+:: A known literal singleton in a direct union can contextualize a
9054+:: loobean literal of the same noun. Only explicit singleton and cell
9055+:: competitors are considered; opaque or variable cases stay unknown.
9056+++ explicit-singleton-in-union
9057+ |= [t=itype noun=@]
9058+ ^- ?
9059+ ?. ?=(%union -.t) |
9060+ =/ cases=(list itype) cases.t
9061+ =/ found=? |
9062+ |-
9063+ ?~ cases found
9064+ =/ c=itype i.cases
9065+ ?: ?=(%cell -.c) $(cases t.cases)
9066+ ?. ?=(%const -.c) |
9067+ ?: =(noun val.literal.c)
9068+ ?: found |
9069+ $(cases t.cases, found &)
9070+ $(cases t.cases)
9071+::
9072+:: Select a written literal-headed case only when every competing case is
9073+:: also an explicit singleton-headed cell and exactly one matches. Opaque,
9074+:: variable-bound and differently shaped cases keep inference unchanged.
9075+:: This first slice supplies context to a directly called payload. Plain
9076+:: literal data and other expressions retain their existing inference path.
9077+++ contextual-atomic-arguments
9078+ |= args=(list expr)
9079+ ^- ?
9080+ ?~ args &
9081+ ?. ?=(?(%lit %wing %ctor) -.i.args) |
9082+ $(args t.args)
9083+++ contextual-direct-payload-call
9084+ |= e=expr
9085+ ^- ?
9086+ ?: ?=(%group -.e) $(e inner.e)
9087+ ?. ?=(%call -.e) |
9088+ ?. ?=(%wing -.head.e) |
9089+ ?~ args.e |
9090+ (contextual-atomic-arguments args.e)
9091+::
9092+:: A walked variable may have concealed a union inside a substituted
9093+:: structure before this arm was called. Decline in that case rather than
9094+:: deriving provenance from the already-walked type.
9095+++ contextual-simple-sub
9096+ |= sub=isub
9097+ ^- ?
9098+ ?~ sub &
9099+ ?: ?=(?(%cell %face %fn %union %collection) -.val.i.sub) |
9100+ $(sub t.sub)
9101+::
9102+:: Check the syntactic root before scanning; scan substitutions once.
9103+++ grec-direct-context
9104+ |= [expected=itype sub=isub]
9105+ ^- ?
9106+ =/ left=@ud 4.096
9107+ |-
9108+ ?: ?=(%face -.expected)
9109+ ?: =(0 left) |
9110+ $(expected body.expected, left (dec left))
9111+ ?. ?=(%grec -.expected) |
9112+ ?~ sub &
9113+ ?: =(0 left) |
9114+ ?: ?=(?(%cell %face %fn %union %collection %grec) -.val.i.sub) |
9115+ $(sub t.sub, left (dec left))
9116+++ contextual-direct-union
9117+ |= target=itype
9118+ ^- ?
9119+ ?: ?=(%face -.target) $(target body.target)
9120+ ?=(%union -.target)
9121+++ contextual-tagged-case
9122+ |= [target=itype tag=@ sub=isub]
9123+ ^- (unit itype)
9124+ ?. ?=(%union -.target) ~
9125+ =/ remaining=(list itype) cases.target
9126+ =/ found=(unit itype) ~
9127+ =/ seen=(set @) *(set @)
9128+ |-
9129+ ?~ remaining found
9130+ =/ c=itype i.remaining
9131+ ?. ?=(%cell -.c) ~
9132+ =/ head=itype hed.c
9133+ ?. ?=(%const -.head) ~
9134+ ?: (~(has in:..zuse seen) val.literal.head) ~
9135+ =. seen (~(put in:..zuse seen) val.literal.head)
9136+ ?: =(tag val.literal.head)
9137+ $(remaining t.remaining, found `c)
9138+ $(remaining t.remaining)
9139+::
9140+:: A bounded syntactic screen: no nested branch, cast, gate or local body
9141+:: can re-enter cell-branch retry during either inference attempt.
9142+++ closed-cell-retry-safe
9143+ |= [todo=(list expr) fuel=@ud]
9144+ ^- ?
9145+ ?~ todo &
9146+ ?: =(0 fuel) |
9147+ =/ e=expr i.todo
9148+ =. fuel (dec fuel)
9149+ ?+ -.e |
9150+ %lit $(todo t.todo)
9151+ %wing $(todo t.todo)
9152+ %ctor $(todo t.todo)
9153+ %path $(todo t.todo)
9154+ %crash $(todo t.todo)
9155+ %str
9156+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) |
9157+ $(todo t.todo)
9158+ %group $(todo [inner.e t.todo])
9159+ %pair $(todo [val.e t.todo])
9160+ %unit $(todo [val.e t.todo])
9161+ %list $(todo (weld items.e t.todo))
9162+ %tuple $(todo (weld (turn items.e |=(i=item val.i)) t.todo))
9163+ %change $(todo (weld (turn edits.e |=(ed=edit val.ed)) t.todo))
9164+ %call $(todo [head.e (weld args.e t.todo)])
9165+ %trace $(todo [val.e then.e t.todo])
9166+ ==
9167+::
9168+++ closed-cell-sub-safe
9169+ |= [sub=isub fuel=@ud]
9170+ ^- ?
9171+ ?~ sub &
9172+ ?: =(0 fuel) |
9173+ ?: ?=(?(%cell %face %fn %union %collection %grec %jrec %recursive) -.val.i.sub) |
9174+ $(sub t.sub, fuel (dec fuel))
9175+::
9176+++ closed-cell-branch-eligible
9177+ |= [e=expr expected=itype sub=isub]
9178+ ^- ?
9179+ ?. &(?=(%branch -.e) ?=(%cell -.expected) (closed-cell-sub-safe sub 512)) |
9180+ ?~ arms.e |
9181+ ?~ t.arms.e |
9182+ ?^ t.t.arms.e |
9183+ =/ x=arm i.arms.e
9184+ =/ y=arm i.t.arms.e
9185+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
9186+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
9187+ ?: =(val.lit.pat.x val.lit.pat.y) |
9188+ (closed-cell-retry-safe ~[subject.e val.x val.y] 512)
9189+::
9190+:: Attempt ordinary inference first; retry from the same state only for
9191+:: the bounded non-reentrant syntax above. Preserve original value faces.
9192+++ infer-closed-cell-branch
9193+ |= [e=expr expected=itype env=ienv state=istate context=span]
9194+ ^- iresult
9195+ ?> (closed-cell-branch-eligible e expected sub.state)
9196+ ?> ?=(%branch -.e)
9197+ ?> ?=(^ arms.e)
9198+ ?> ?=(^ t.arms.e)
9199+ =/ ordinary=iresult (infer-fragment e env state)
9200+ =/ ordinary-good=?
9201+ ?: ?=(%| -.ordinary) |
9202+ =/ fit=ifit (itype-fit typ.p.ordinary expected sub.state.p.ordinary next.state.p.ordinary)
9203+ ?=(%ok -.fit)
9204+ ?: ordinary-good ordinary
9205+ =/ attempt=(unit iresult)
9206+ =/ x=arm i.arms.e
9207+ =/ y=arm i.t.arms.e
9208+ =/ subject=iresult (infer-fragment subject.e env state)
9209+ ?: ?=(%| -.subject) ~
9210+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
9211+ ?: ?=(%union -.subject-type) ~
9212+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
9213+ ?~ su ~
9214+ =/ left=iresult (infer-call-context-arg val.x expected env state.p.subject(sub u.su) context)
9215+ ?: ?=(%| -.left) ~
9216+ =/ lf=ifit (itype-fit typ.p.left expected sub.state.p.left next.state.p.left)
9217+ ?. ?=(%ok -.lf) ~
9218+ =/ right=iresult (infer-call-context-arg val.y expected env state.p.left(sub sub.lf, next next.lf) context)
9219+ ?: ?=(%| -.right) ~
9220+ =/ rf=ifit (itype-fit typ.p.right expected sub.state.p.right next.state.p.right)
9221+ ?. ?=(%ok -.rf) ~
9222+ =/ sub=isub sub.rf
9223+ =/ next=@ud next.rf
9224+ =/ lt=itype (itype-normalize typ.p.left sub)
9225+ =/ rt=itype (itype-normalize typ.p.right sub)
9226+ =/ et=itype (itype-normalize expected sub)
9227+ ?. =(lt rt) ~
9228+ ?: |(?=(^ (itype-vars lt)) ?=(^ (itype-vars rt)) ?=(^ (itype-vars et))) ~
9229+ ?: |((itype-has-tag lt) (itype-has-tag rt) (itype-has-tag et)) ~
9230+ =/ lcheck=ifit (itype-fit typ.p.left expected sub next)
9231+ ?. ?=(%ok -.lcheck) ~
9232+ ?. &(=(sub.lcheck sub) =(next.lcheck next)) ~
9233+ =/ rcheck=ifit (itype-fit typ.p.right expected sub next)
9234+ ?. ?=(%ok -.rcheck) ~
9235+ ?. &(=(sub.rcheck sub) =(next.rcheck next)) ~
9236+ `[%& typ.p.left state.p.right(sub sub, next next)]
9237+ ?~ attempt ordinary
9238+ u.attempt
9239+::
75219240++ infer-call-context-arg
75229241 |= [e=expr expected=itype env=ienv state=istate context=span]
75239242 ^- iresult
9243+ ?: &(?=(^ defer.state) ?=(%branch -.e)) (infer-fragment e env state)
9244+ ?: ?=(%pair -.e) $(e (pair-as-cell e))
75249245 ?: ?=(%group -.e) $(e inner.e)
75259246 ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
75269247 ?: ?=(%trace -.e)
@@ -7530,39 +9251,126 @@
75309251 =/ target=itype (itype-walk expected sub.state)
75319252 |-
75329253 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
7533− :: In a loobean-singleton context retain the written loobean noun;
7534− :: the usual final fit decides whether that value is permitted.
9254+ ?: (explicit-proj-call e env state)
9255+ (infer-proj-context e expected env state context)
9256+ :: Experimental construction only for a source-proven direct target.
9257+ :: Decline any walked structural binding to retain raw-variable provenance.
9258+ ?: &(?=(%grec -.target) ?=(%tuple -.e) (grec-direct-context expected sub.state))
9259+ =/ unfolded=(unit [view=itype left=@ud]) (grec-unfold-view target jrec-fuel.state)
9260+ ?~ unfolded [%| ["recursive mold unfolding needs unsupported inference" ~]]
9261+ ?~ items.e [%| ["recursive mold constructor needs unsupported inference" ~]]
9262+ =/ first=item i.items.e
9263+ ?. &(?=(~ face.first) ?=(%lit -.val.first) =(%term form.lit.val.first))
9264+ [%| ["recursive mold constructor needs unsupported inference" ~]]
9265+ =/ chosen=(unit itype) (contextual-tagged-case view.u.unfolded val.lit.val.first sub.state)
9266+ ?~ chosen [%| ["recursive mold constructor has no matching case" ~]]
9267+ =/ value=iresult (infer-call-context-items items.e u.chosen env state(jrec-fuel left.u.unfolded) context)
9268+ ?: ?=(%| -.value) value
9269+ =/ fit=ifit (itype-fit typ.p.value u.chosen sub.state.p.value next.state.p.value)
9270+ ?: ?=(%unknown -.fit) [%| ["recursive mold case needs unsupported inference" ~]]
9271+ ?: ?=(%bad -.fit) [%| ["recursive mold case does not fit its source shape" ~]]
9272+ [%& target state.p.value(sub sub.fit, next next.fit)]
9273+ :: Only the source-proven one-layer cell is exposed. Each recursive
9274+ :: descent consumes one written tuple; named values use ordinary fit.
9275+ ?: &(?=(%jrec -.target) ?=(%lit -.e) =(%null form.lit.e))
9276+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9277+ [%& target state(jrec-fuel (dec jrec-fuel.state))]
9278+ ?: &(?=(%jrec -.target) ?=(%tuple -.e))
9279+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9280+ =. state state(jrec-fuel (dec jrec-fuel.state))
9281+ =/ shape=itype
9282+ [%cell [%face head.target [%atom aura.target]] [%face tail.target target]]
9283+ =/ value=iresult (infer-call-context-items items.e shape env state context)
9284+ ?: ?=(%| -.value) value
9285+ =/ fit=ifit (itype-fit typ.p.value shape sub.state.p.value next.state.p.value)
9286+ ?: ?=(%unknown -.fit) [%| ["recursive mold cell constraint needs unsupported inference" ~]]
9287+ ?: ?=(%bad -.fit) [%| ["recursive mold cell does not fit its source shape" ~]]
9288+ [%& target state.p.value(sub sub.fit, next next.fit)]
9289+ ?: ?=(%call -.e) (infer-contextual-call e target env state)
9290+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[target context])
9291+ ?^ empty-list u.empty-list
9292+ ?: (single-structured-pattern e)
9293+ ?> ?=(%branch -.e)
9294+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
9295+ ?^ empty-union (infer-known-union-context-subject e target env u.empty-union context)
9296+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
9297+ ?^ single (infer-known-union-context-subject e target env u.single context)
9298+ (infer-single-case-branch e env state `[target context])
9299+ ?: (cell-binder-pattern e)
9300+ (infer-cell-branch e env state `[target context])
9301+ :: In an explicit singleton context retain the written loobean noun;
9302+ :: the ordinary singleton fit compares its noun, not its spelling.
75359303 =/ singleton=(unit itype)
75369304 ?. ?=(%lit -.e) ~
75379305 ?. =(%loobean form.lit.e) ~
7538− ?. ?=(%const -.target) ~
7539− ?. =(%loobean form.literal.target) ~
9306+ ?. |(?=(%const -.target) &(?=(%union -.expected) (explicit-singleton-in-union expected val.lit.e))) ~
75409307 `[%const lit.e]
75419308 ?^ singleton [%& u.singleton state]
7542− =/ known=(unit itype)
9309+ =/ known=(unit iresult)
75439310 ?: ?=(%branch -.e) (known-union-subject subject.e env state)
75449311 ~
7545− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
7546− (infer-known-union-context e target env state context)
9312+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
9313+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
9314+ (infer-known-union-context-subject e target env u.known context)
75479315 ?: &(?=(%union -.target) ?=(%unit -.e))
75489316 (infer-unit-context e target env state context)
9317+ ?: (closed-cell-branch-eligible e expected sub.state)
9318+ (infer-closed-cell-branch e expected env state context)
9319+ ?: &(?=(%flag -.target) (context-union-branch e))
9320+ (infer-union-context e target env state context)
75499321 ?: &(?=(%union -.target) (context-union-branch e))
75509322 (infer-union-context e target env state context)
75519323 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
75529324 (infer-union-context e target env state context)
75539325 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
75549326 (infer-list-context e target env state context)
9327+ :: A literal-headed tuple can receive the unique case's payload
9328+ :: context. The ordinary final fit still checks the complete union.
9329+ =/ selected=(unit itype)
9330+ ?. &((contextual-simple-sub sub.state) (contextual-direct-union expected) ?=(%union -.target) ?=(%tuple -.e) ?=(^ items.e)) ~
9331+ ?~ t.items.e ~
9332+ ?^ t.t.items.e ~
9333+ ?. (contextual-direct-payload-call val.i.t.items.e) ~
9334+ =/ first=item i.items.e
9335+ ?. &(?=(~ face.first) ?=(%lit -.val.first) |(=(%term form.lit.val.first) =(%null form.lit.val.first) =(%loobean form.lit.val.first))) ~
9336+ (contextual-tagged-case target val.lit.val.first sub.state)
9337+ ?^ selected
9338+ ?> ?=(%tuple -.e)
9339+ :: On this bounded shallow-call shape, preserve any inference that
9340+ :: already fits before trying the new contextual path. Neither pass
9341+ :: can recursively select a nested tuple from the atomic arguments.
9342+ =/ ordinary=(unit iresult)
9343+ =/ initial=iresult (infer-fragment e env state)
9344+ ?: ?=(%| -.initial) ~
9345+ =/ fit=ifit (itype-fit typ.p.initial target sub.state.p.initial next.state.p.initial)
9346+ ?. ?=(%ok -.fit) ~
9347+ `initial
9348+ ?^ ordinary u.ordinary
9349+ =/ value=iresult (infer-call-context-items items.e u.selected env state context)
9350+ ?: ?=(%| -.value) value
9351+ =/ fit=ifit (itype-fit typ.p.value u.selected sub.state.p.value next.state.p.value)
9352+ ?: ?=(%unknown -.fit) [%| ["tagged case needs unsupported inference" ~]]
9353+ ?: ?=(%bad -.fit) [%| ["tagged case does not fit its expected type" ~[[context "expected union case"] [(span-of e) "value"]]]]
9354+ [%& typ.p.value state.p.value(sub sub.fit, next next.fit)]
75559355 ?: &(?=(%cell -.target) ?=(%tuple -.e))
75569356 (infer-call-context-items items.e target env state context)
75579357 (infer-fragment e env state)
75589358::
75599359:: Preserve each written face; the final complete sample fit checks faces.
9360+:: A tuple or positional field face belongs to the enclosing sample,
9361+:: not to the expression at that position. A second face, if present,
9362+:: is part of the value's own expected type.
9363+++ projection-field-target
9364+ |= expected=itype
9365+ ^- itype
9366+ ?:(?=(%face -.expected) body.expected expected)
9367+::
75609368++ infer-call-context-items
75619369 |= [items=(list item) expected=itype env=ienv state=istate context=span]
75629370 ^- iresult
75639371 ?~ items [%| ["empty cell is not supported by partial inference" ~]]
75649372 ?~ t.items
7565− =/ last=iresult (infer-call-context-arg val.i.items expected env state context)
9373+ =/ last=iresult (infer-call-context-arg val.i.items (projection-field-target expected) env state context)
75669374 ?: ?=(%| -.last) last
75679375 =/ typ=itype typ.p.last
75689376 =. typ ?~(face.i.items typ [%face u.face.i.items typ])
@@ -7571,7 +9379,7 @@
75719379 |-
75729380 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
75739381 ?. ?=(%cell -.target) (infer-simple-items items env state)
7574− =/ head=iresult (infer-call-context-arg val.i.items hed.target env state context)
9382+ =/ head=iresult (infer-call-context-arg val.i.items (projection-field-target hed.target) env state context)
75759383 ?: ?=(%| -.head) head
75769384 =/ typ=itype typ.p.head
75779385 =. typ ?~(face.i.items typ [%face u.face.i.items typ])
@@ -7583,13 +9391,13 @@
75839391 |= [args=(list expr) expected=itype env=ienv state=istate context=span]
75849392 ^- iresult
75859393 ?~ args [%| ["call has no argument" ~]]
7586− ?~ t.args (infer-call-context-arg i.args expected env state context)
9394+ ?~ t.args (infer-call-context-arg i.args (projection-field-target expected) env state context)
75879395 =/ target=itype (itype-walk expected sub.state)
75889396 |-
75899397 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
75909398 ?. ?=(%cell -.target)
75919399 (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
7592− =/ head=iresult (infer-call-context-arg i.args hed.target env state context)
9400+ =/ head=iresult (infer-call-context-arg i.args (projection-field-target hed.target) env state context)
75939401 ?: ?=(%| -.head) head
75949402 =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
75959403 ?: ?=(%| -.tail) tail
@@ -7621,7 +9429,7 @@
76219429 ?~ pats [%& ~]
76229430 ?. ?=(%bind -.i.pats) [%| 'branch pattern is not supported by partial inference']
76239431 =/ name=term name.i.pats
7624− ?: |(?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
9432+ ?: |(=(name %proj) ?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
76259433 [%| 'pattern shadows a name']
76269434 =/ rest=(each (list term) @t) $(pats t.pats, seen [name seen])
76279435 ?: ?=(%| -.rest) rest
@@ -7646,10 +9454,19 @@
76469454 ?~ t.names |
76479455 =. typ (itype-walk typ sub)
76489456 ?: ?=(%cell -.typ) $(typ tal.typ, names t.names)
7649− |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9457+ |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%jrec -.typ) ?=(%grec -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9458+::
9459+++ cell-binder-pattern
9460+ |= e=expr
9461+ ^- ?
9462+ ?. ?=(%branch -.e) |
9463+ ?~ arms.e |
9464+ ?^ t.arms.e |
9465+ ?. ?=(%cell -.pat.i.arms.e) |
9466+ !(single-structured-pattern e)
76509467::
76519468++ infer-cell-branch
7652− |= [e=expr env=ienv state=istate]
9469+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
76539470 ^- iresult
76549471 ?> ?=(%branch -.e)
76559472 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -7673,7 +9490,16 @@
76739490 =/ binders=[typ=itype env=ienv next=@ud] (cell-pattern-types p.names env next.st)
76749491 =/ sub=(unit isub) (itype-unify typ.p.subject typ.binders sub.st)
76759492 ?~ sub [%| ["cell pattern does not match the subject type" ~]]
7676− (infer-fragment val.arm env.binders st(next next.binders, sub u.sub))
9493+ =. st st(next next.binders, sub u.sub)
9494+ ?~ expected (infer-fragment val.arm env.binders st)
9495+ =/ body=iresult (infer-call-context-arg val.arm typ.u.expected env.binders st context.u.expected)
9496+ ?: ?=(%| -.body) body
9497+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
9498+ ?: ?=(%unknown -.fit) [%| ["cell branch result constraint is not supported by partial inference" ~]]
9499+ ?: ?=(%bad -.fit) [%| ["cell branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.arm) "branch arm"]]]]
9500+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
9501+ [%| ["cell branch result needs context in partial inference" ~]]
9502+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
76779503::
76789504++ show-itype
76799505 |= [t=itype sub=isub]
@@ -7686,13 +9512,20 @@
76869512 %avar
76879513 ?: (lth id.t 26) [(add 65 id.t) ~]
76889514 "T{<id.t>}"
9515+ %rvar
9516+ ?: (lth id.t 26) [(add 65 id.t) ~]
9517+ "T{<id.t>}"
76899518 %nvar
76909519 ?: (lth id.t 26) [(add 65 id.t) ~]
76919520 "T{<id.t>}"
9521+ %rnvar
9522+ ?: (lth id.t 26) [(add 65 id.t) ~]
9523+ "T{<id.t>}"
76929524 %atom "@{(trip aura.t)}"
76939525 %any-atom "@"
76949526 %flag "?"
76959527 %noun "*"
9528+ %empty "!!"
76969529 %tag (trip txt.literal.t)
76979530 %const (trip txt.literal.t)
76989531 %union
@@ -7700,6 +9533,8 @@
77009533 ?~ args.t (trip u.label.t)
77019534 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
77029535 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9536+ %jrec ?~(label.t "recursive mold" (trip u.label.t))
9537+ %grec ?~(label.t "recursive mold" "({(trip u.label.t)} {(show-itype-cases args.t sub)})")
77039538 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
77049539 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
77059540 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
@@ -7735,16 +9570,21 @@
77359570 ^- ?
77369571 ?- -.typ
77379572 %nvar &
9573+ %rnvar &
77389574 %var |
77399575 %avar |
9576+ %rvar |
77409577 %atom |
77419578 %any-atom |
77429579 %flag |
77439580 %noun |
9581+ %empty |
77449582 %tag |
77459583 %const |
77469584 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
77479585 %recursive |
9586+ %jrec |
9587+ %grec (lien args.typ |=(c=itype (itype-has-nvar c)))
77489588 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
77499589 %face $(typ body.typ)
77509590 %fn |($(typ sample.typ) $(typ product.typ))
@@ -7755,7 +9595,7 @@
77559595 |= [label=tape typ=itype sub=isub]
77569596 ^- tape
77579597 =/ normalized=itype (itype-normalize typ sub)
7758− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
9598+ ?: |(?=(%var -.normalized) ?=(%avar -.normalized) ?=(%rvar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
77599599 ?: (itype-has-hidden-recursive normalized) label
77609600 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
77619601 ?: (gth (lent vars) 26) label
@@ -7777,6 +9617,7 @@
77779617 ?+ -.resolved ~
77789618 %var `id.resolved
77799619 %avar `id.resolved
9620+ %rvar `id.resolved
77809621 ==
77819622 ?~ ident $(caps t.caps)
77829623 ?: =(n u.ident) &
@@ -7791,6 +9632,7 @@
77919632 ?+ -.resolved ~
77929633 %var `id.resolved
77939634 %avar `id.resolved
9635+ %rvar `id.resolved
77949636 ==
77959637 ?~ ident $(caps t.caps)
77969638 ?: =(n u.ident) `i.caps
@@ -7805,6 +9647,7 @@
78059647 ?+ -.resolved ~
78069648 %var `id.resolved
78079649 %avar `id.resolved
9650+ %rvar `id.resolved
78089651 ==
78099652 ?~ ident $(caps t.caps)
78109653 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
@@ -7820,6 +9663,7 @@
78209663 ?+ -.resolved ~
78219664 %var `id.resolved
78229665 %avar `id.resolved
9666+ %rvar `id.resolved
78239667 ==
78249668 ?~ ident &
78259669 ?: (cap-id-in u.ident t.caps sub) &
@@ -7834,8 +9678,8 @@
78349678 ^- ?
78359679 ?~ caps |
78369680 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
7837− ?: ?=(%avar -.resolved)
7838− ?: =(n id.resolved) &
9681+ ?: |(?=(%avar -.resolved) ?=(%rvar -.resolved))
9682+ ?: =(n +.resolved) &
78399683 $(caps t.caps)
78409684 $(caps t.caps)
78419685::
@@ -7845,15 +9689,20 @@
78459689 ?- -.t
78469690 %var |
78479691 %avar =(n id.t)
9692+ %rvar =(n id.t)
78489693 %nvar |
9694+ %rnvar |
78499695 %atom |
78509696 %any-atom |
78519697 %flag |
78529698 %noun |
9699+ %empty |
78539700 %tag |
78549701 %const |
78559702 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
78569703 %recursive |
9704+ %jrec |
9705+ %grec (lien args.t |=(c=itype (has-atom-var n c)))
78579706 %collection (lien args.t |=(c=itype (has-atom-var n c)))
78589707 %face $(t body.t)
78599708 %fn |($(t sample.t) $(t product.t))
@@ -7893,6 +9742,10 @@
78939742 =/ out=tape ""
78949743 |-
78959744 ?~ vars out
9745+ ?: (itype-var-is-restricted i.vars t)
9746+ =/ sep=tape ?:(printed ", " " where ")
9747+ =/ clause=tape "{sep}{(show-itype [%rvar i.vars] ~)} is an atom other than ?"
9748+ $(vars t.vars, printed &, out (weld out clause))
78969749 ?: (itype-var-is-atom i.vars t)
78979750 =/ sep=tape ?:(printed ", " " where ")
78989751 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
@@ -7993,6 +9846,8 @@
79939846++ infer-recursive-gate
79949847 |= [d=def env=ienv state=istate]
79959848 ^- iresult
9849+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
9850+ =. gate-defs.state ~
79969851 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
79979852 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
79989853 [%| ["recursive definition is not a gate" ~]]
@@ -8202,6 +10057,7 @@
820210057 ?: (constrained-capitals caps.entry sub.state)
820310058 [%| ["explicit capital constraints are not supported by partial inference" ~]]
820410059 =/ typ=itype (itype-normalize typ.entry sub.state)
10060+ ?: (itype-has-nvar typ) [%| ["recursive group needs unsupported inference" ~]]
820510061 ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
820610062 [%| ["recursive group needs unsupported inference" ~]]
820710063 =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
@@ -8215,46 +10071,52 @@
821510071++ infer-gate-group
821610072 |= [ds=(list def) env=ienv state=istate]
821710073 ^- ilocal-result
10074+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
821810075 =/ names=(list term) (global-value-names ds)
821910076 ?. (levy names |=(n=term (unique-value-name n names)))
822010077 [%| ["recursive group contains duplicate names" ~]]
822110078 ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
822210079 [%| ["recursive group shadows a name" ~]]
8223− =/ scoped=istate state(globals (weld names globals.state))
10080+ =/ scoped=istate state(globals (weld names globals.state), gate-defs ~)
822410081 =/ seeded=igate-seeds (seed-gate-group ds env scoped)
822510082 ?: ?=(%| -.seeded) seeded
822610083 =/ seeds=ienv (group-seed-env entries.p.seeded ~)
822710084 =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
822810085 ?: ?=(%| -.body) body
10086+ :: Per-member ownership through mutual recursion is not implemented.
10087+ ?: !=(projections.state.p.body projections.state)
10088+ [%| ["record projection in recursive groups needs unsupported inference" ~]]
10089+ ?: !=(holes.state.p.body holes.state)
10090+ [%| ["holes in recursive groups need unsupported inference" ~]]
822910091 ?: (pending-tags tags.state.p.body sub.state.p.body)
823010092 [%| ["recursive group has unresolved literal constraints" ~]]
823110093 =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
823210094 ?: ?=(%| -.schemes) schemes
823310095 [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
823410096::
10097+++ width-finalize
10098+ |= [ps=(list iwprojection) sub=isub visible=(list @ud)]
10099+ ^- (unit (list iwprojection))
10100+ ?~ ps `~
10101+ ?: (lien t.ps |=(p=iwprojection =(at.p at.i.ps))) ~
10102+ =/ src=itype (default-decimals (itype-normalize source.i.ps sub))
10103+ =/ dst=itype (default-decimals (itype-normalize target.i.ps sub))
10104+ ?: |((itype-has-nvar src) (itype-has-nvar dst) (itype-has-tag src) (itype-has-tag dst)) ~
10105+ =/ vars=(list @ud) (weld (itype-vars src) (itype-vars dst))
10106+ ?. (levy vars |=(n=@ud (lien visible |=(v=@ud =(n v))))) ~
10107+ =/ rest=(unit (list iwprojection)) $(ps t.ps)
10108+ ?~ rest ~
10109+ =/ entry=iwprojection i.ps
10110+ =. entry entry(source src, target dst)
10111+ `[entry u.rest]
10112+::
823510113++ add-supported-defs
8236− |= [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 prelude=(unit ifile)]
8237− ^- ienv
8238− ?~ ds env
8239− =/ d=def i.ds
8240− ?: ?=(%mold -.d) $(ds t.ds)
8241− ?. (unique-value-name name.d globals) $(ds t.ds)
8242− ?^ (ienv-lookup name.d env) $(ds t.ds)
8243− =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8244− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
8245− =. initial (reserve-def-caps val.d initial)
8246− =/ result=iresult (infer-fragment val.d env initial)
8247− =? result ?=(%| -.result) (infer-recursive-gate d env initial)
8248− ?: ?=(%| -.result) $(ds t.ds)
8249− ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
8250− =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
8251− ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
8252− ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
8253− =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
8254− ?: (gth (lent vars) 26) $(ds t.ds)
8255− $(ds t.ds, env [[name.d [typ vars]] env])
10114+ |= [ds=(list def) all-defs=(list def) checked=(map term def) heads=(unit igate-prelude-evidence) 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 prelude=(unit ifile) artifacts=(list iwidth-definition)]
10115+ ^- [env=ienv artifacts=(list iwidth-definition)]
10116+ (add-supported-defs-core ds all-defs checked heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts ~)
825610117::
8257−+$ iresolved [env=ienv grouped=(list term)]
10118+
10119++$ iresolved [env=ienv grouped=(list term) artifacts=(list iwidth-definition)]
825810120+$ iadj (map term (list term))
825910121+$ ivisited (map term ?)
826010122+$ iwork (list [name=term done=?])
@@ -8348,9 +10210,9 @@
834810210 (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
834910211::
835010212++ add-groups
8351− |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) state=istate]
10213+ |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) artifacts=(list iwidth-definition) state=istate]
835210214 ^- iresolved
8353− ?~ components [env grouped]
10215+ ?~ components [env grouped artifacts]
835410216 =/ component=(list term) i.components
835510217 ?. (graph-cycle component graph) $(components t.components)
835610218 ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
@@ -8367,19 +10229,63 @@
836710229++ resolve-groups
836810230 |= [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 prelude=(unit ifile)]
836910231 ^- iresolved
10232+ (resolve-groups-core ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude ~)
10233+::
10234+
10235+++ add-supported-defs-core
10236+ |= [ds=(list def) all-defs=(list def) checked=(map term def) heads=(unit igate-prelude-evidence) 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 prelude=(unit ifile) artifacts=(list iwidth-definition) index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])]
10237+ ^- [env=ienv artifacts=(list iwidth-definition)]
10238+ ?~ ds [env artifacts]
10239+ =/ d=def i.ds
10240+ ?: ?=(%mold -.d) $(ds t.ds)
10241+ ?. (unique-value-name name.d globals) $(ds t.ds)
10242+ ?^ (ienv-lookup name.d env) $(ds t.ds)
10243+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10244+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10245+ =. grec-index.initial index
10246+ =. gate-defs.initial checked
10247+ =. head-evidence.initial heads
10248+ =. initial (reserve-def-caps val.d initial)
10249+ =/ result=iresult (infer-fragment val.d env initial)
10250+ =? result ?=(%| -.result) (infer-recursive-gate d env initial)
10251+ ?: ?=(%| -.result) $(ds t.ds)
10252+ =. state.p.result (promote-restricted-numbers state.p.result env)
10253+ =. state.p.result (default-hole-numbers holes.state.p.result holes.initial state.p.result env !(itype-has-gate (itype-normalize typ.p.result sub.state.p.result)))
10254+ ?^ (unresolved-hole holes.state.p.result holes.initial state.p.result) $(ds t.ds)
10255+ ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
10256+ =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
10257+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
10258+ ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
10259+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
10260+ ?: (gth (lent vars) 26) $(ds t.ds)
10261+ =/ finalized=(unit (list iwprojection))
10262+ (width-finalize projections.state.p.result sub.state.p.result vars)
10263+ ?~ finalized $(ds t.ds)
10264+ =? artifacts ?=(^ u.finalized)
10265+ [[name.d val.d typ sub.state.p.result (flop u.finalized)] artifacts]
10266+ =? checked |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) (~(put by checked) name.d d)
10267+ $(ds t.ds, env [[name.d [typ vars]] env], checked checked)
10268+::
10269+++ resolve-groups-core
10270+ |= [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 prelude=(unit ifile) index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])]
10271+ ^- iresolved
837010272 =/ env=ienv ~
837110273 =/ grouped=(list term) ~
10274+ =/ artifacts=(list iwidth-definition) ~
837210275 =/ names=(list term) (global-value-names ds)
837310276 =/ nameset=ivisited (graph-nameset names ~)
837410277 =/ graph=iadj (graph-make-forward ds nameset ~)
837510278 =/ components=icomponents (graph-components ds names)
837610279 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10280+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
837710281 |-
8378− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
8379− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
8380− =/ out=iresolved (add-groups ds components graph next grouped initial)
10282+ =/ next=[env=ienv artifacts=(list iwidth-definition)]
10283+ (add-supported-defs-core ds ds (direct-checked-gates ds env) heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts index)
10284+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10285+ =. grec-index.initial index
10286+ =/ out=iresolved (add-groups ds components graph env.next grouped artifacts.next initial)
838110287 ?: =(env env.out) out
8382− $(env env.out, grouped grouped.out)
10288+ $(env env.out, grouped grouped.out, artifacts artifacts.out)
838310289::
838410290++ resolve-supported-defs
838510291 |= [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 prelude=(unit ifile)]
@@ -8625,6 +10531,257 @@
862510531 %overlap
862610532 %unknown
862710533::
10534+:: A source-only fallback for literal-tagged cells and one-hop local
10535+:: generic applications. It screens all work before ordinary inference.
10536+++ union-simple-shape-budget
10537+ |= [s=shape fuel=@ud vars=(unit (list @t))]
10538+ ^- (unit @ud)
10539+ ?: =(0 fuel) ~
10540+ =. fuel (dec fuel)
10541+ ?- -.s
10542+ ?(%aura %noun %void %flag) `fuel
10543+ %tvar
10544+ ?~ vars `fuel
10545+ ?:((lien u.vars |=(n=@t =(n name.s))) `fuel ~)
10546+ %const
10547+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10548+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10549+ `fuel
10550+ %cell (union-simple-fields-budget fields.s fuel vars)
10551+ %fn
10552+ =/ left=(unit @ud) $(s sample.s, fuel fuel)
10553+ ?~ left ~
10554+ $(s product.s, fuel u.left)
10555+ * ~
10556+ ==
10557+++ union-simple-fields-budget
10558+ |= [fields=(list field) fuel=@ud vars=(unit (list @t))]
10559+ ^- (unit @ud)
10560+ ?~ fields `fuel
10561+ ?: =(0 fuel) ~
10562+ =/ field-shape=shape
10563+ ?- -.i.fields
10564+ %bare shape.i.fields
10565+ %face shape.i.fields
10566+ %pun [%ref at.i.fields ~[name.i.fields]]
10567+ ==
10568+ =/ head=(unit @ud) (union-simple-shape-budget field-shape (dec fuel) vars)
10569+ ?~ head ~
10570+ $(fields t.fields, fuel u.head)
10571+++ union-source-find
10572+ |= [n=term molds=imolds fuel=@ud]
10573+ ^- (unit [body=shape left=@ud])
10574+ =/ found=(unit shape) ~
10575+ |-
10576+ ?~ molds
10577+ ?~ found ~
10578+ `[u.found fuel]
10579+ ?: =(0 fuel) ~
10580+ ?: =(n name.i.molds)
10581+ ?^ found ~
10582+ $(molds t.molds, fuel (dec fuel), found `body.i.molds)
10583+ $(molds t.molds, fuel (dec fuel))
10584+++ union-source-args-budget
10585+ |= [vars=(list @t) args=(list shape) fuel=@ud]
10586+ ^- (unit @ud)
10587+ =/ seen=(set @t) *(set @t)
10588+ |-
10589+ ?~ vars ?~(args `fuel ~)
10590+ ?~ args ~
10591+ ?: =(0 fuel) ~
10592+ ?: (~(has in:..zuse seen) i.vars) ~
10593+ =/ arg=(unit @ud) (union-simple-shape-budget i.args (dec fuel) ~)
10594+ ?~ arg ~
10595+ $(vars t.vars, args t.args, fuel u.arg, seen (~(put in:..zuse seen) i.vars))
10596+++ union-source-cell-tag
10597+ |= s=shape
10598+ ^- (unit @)
10599+ ?. ?=(%cell -.s) ~
10600+ ?~ fields.s ~
10601+ ?~ t.fields.s ~
10602+ ?. ?=(%bare -.i.fields.s) ~
10603+ =/ head=shape shape.i.fields.s
10604+ ?. ?=(%const -.head) ~
10605+ ?. |(=(%term form.lit.head) =(%null form.lit.head) =(%loobean form.lit.head)) ~
10606+ ?: &(=(%loobean form.lit.head) !|(=(0 val.lit.head) =(1 val.lit.head))) ~
10607+ `val.lit.head
10608+++ union-source-case-tag
10609+ |= [s=shape molds=imolds fuel=@ud]
10610+ ^- (unit [tag=@ left=@ud])
10611+ ?: ?=(%cell -.s)
10612+ =/ tag=(unit @) (union-source-cell-tag s)
10613+ ?~ tag ~
10614+ =/ left=(unit @ud) (union-simple-shape-budget s fuel ~)
10615+ ?~ left ~
10616+ `[u.tag u.left]
10617+ ?. ?=(%apply -.s) ~
10618+ ?. ?=([@ ~] ref.s) ~
10619+ ?: =(0 fuel) ~
10620+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10621+ ?~ found ~
10622+ ?. ?=(%generic -.body.u.found) ~
10623+ ?~ vars.body.u.found ~
10624+ =/ tag=(unit @) (union-source-cell-tag body.body.u.found)
10625+ ?~ tag ~
10626+ =/ args=(unit @ud) (union-source-args-budget vars.body.u.found args.s left.u.found)
10627+ ?~ args ~
10628+ =/ left=(unit @ud) (union-simple-shape-budget body.body.u.found u.args `vars.body.u.found)
10629+ ?~ left ~
10630+ `[u.tag u.left]
10631+++ union-source-distinct-tags
10632+ |= [cases=(list shape) molds=imolds fuel=@ud]
10633+ ^- ?
10634+ =/ seen=(set @) *(set @)
10635+ =/ has-application=? |
10636+ |-
10637+ ?~ cases has-application
10638+ ?: =(0 fuel) |
10639+ =/ item=(unit [tag=@ left=@ud]) (union-source-case-tag i.cases molds (dec fuel))
10640+ ?~ item |
10641+ ?: (~(has in:..zuse seen) tag.u.item) |
10642+ $(cases t.cases, fuel left.u.item, seen (~(put in:..zuse seen) tag.u.item), has-application |(has-application ?=(%apply -.i.cases)))
10643+::
10644+:: This inference-only screen bounds inherited work that the small source
10645+:: slice may consult. It does not authenticate a caller-created state.
10646+++ union-state-leaf
10647+ |= t=itype
10648+ ^- ?
10649+ ?=(?(%var %avar %rvar %nvar %rnvar %atom %any-atom %flag %noun %empty %const) -.t)
10650+++ union-state-params-budget
10651+ |= [params=iparams fuel=@ud]
10652+ ^- (unit @ud)
10653+ ?~ params `fuel
10654+ ?: =(0 fuel) ~
10655+ ?. (union-state-leaf typ.i.params) ~
10656+ $(params t.params, fuel (dec fuel))
10657+++ union-state-sub-budget
10658+ |= [sub=isub fuel=@ud]
10659+ ^- (unit @ud)
10660+ ?~ sub `fuel
10661+ ?: =(0 fuel) ~
10662+ ?. (union-state-leaf val.i.sub) ~
10663+ $(sub t.sub, fuel (dec fuel))
10664+++ union-state-caps-budget
10665+ |= [caps=icaps fuel=@ud]
10666+ ^- (unit @ud)
10667+ ?~ caps `fuel
10668+ ?: =(0 fuel) ~
10669+ $(caps t.caps, fuel (dec fuel))
10670+++ union-state-active-budget
10671+ |= [active=(list term) fuel=@ud]
10672+ ^- (unit @ud)
10673+ ?~ active `fuel
10674+ ?: =(0 fuel) ~
10675+ $(active t.active, fuel (dec fuel))
10676+++ union-state-tags-budget
10677+ |= [tags=(list ipending) fuel=@ud]
10678+ ^- (unit @ud)
10679+ ?~ tags `fuel
10680+ ?: =(0 fuel) ~
10681+ $(tags t.tags, fuel (dec fuel))
10682+++ union-source-state-safe
10683+ |= [state=istate fuel=@ud]
10684+ ^- ?
10685+ ?^ grec-index.state |
10686+ ?^ holes.state |
10687+ ?^ defer.state |
10688+ ?^ obligations.state |
10689+ =/ params=(unit @ud) (union-state-params-budget params.state fuel)
10690+ ?~ params |
10691+ =/ sub=(unit @ud) (union-state-sub-budget sub.state u.params)
10692+ ?~ sub |
10693+ =/ caps=(unit @ud) (union-state-caps-budget caps.state u.sub)
10694+ ?~ caps |
10695+ =/ active=(unit @ud) (union-state-active-budget active.state u.caps)
10696+ ?~ active |
10697+ ?=(^ (union-state-tags-budget tags.state u.active))
10698+::
10699+:: Positive overlap witnesses from parsed, one-hop local source only.
10700+:: Unknown or exhausted work returns no witness, never disjointness.
10701++$ uow-case [at=span head=@ payload=upat]
10702+++ union-overlap-primitive
10703+ |= s=shape
10704+ ^- (unit upat)
10705+ ?- -.s
10706+ %aura `[%atom ~]
10707+ %noun `[%all ~]
10708+ %void `[%empty ~]
10709+ %flag `[%flag ~]
10710+ %const
10711+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10712+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10713+ `[%atom `val.lit.s]
10714+ * ~
10715+ ==
10716+++ union-overlap-case
10717+ |= [s=shape molds=imolds fuel=@ud]
10718+ ^- (unit [item=uow-case left=@ud])
10719+ ?: =(0 fuel) ~
10720+ =. fuel (dec fuel)
10721+ :: Each body has exactly two fields; an application has exactly one
10722+ :: parameter and one concrete primitive argument. The full mold table
10723+ :: is scanned to establish unique ownership.
10724+ =/ expanded=(unit [body=shape param=(unit [name=@t pat=upat]) left=@ud])
10725+ ?: ?=(%cell -.s) `[s ~ fuel]
10726+ ?. ?=(%apply -.s) ~
10727+ ?. ?=([@ ~] ref.s) ~
10728+ ?. ?=([* ~] args.s) ~
10729+ ?: =(0 fuel) ~
10730+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10731+ ?~ found ~
10732+ ?. ?=(%generic -.body.u.found) ~
10733+ ?. ?=([@ ~] vars.body.u.found) ~
10734+ ?: =(0 left.u.found) ~
10735+ =/ argument=(unit upat) (union-overlap-primitive i.args.s)
10736+ ?~ argument ~
10737+ `[body.body.u.found `[i.vars.body.u.found u.argument] (dec left.u.found)]
10738+ ?~ expanded ~
10739+ =/ body=shape body.u.expanded
10740+ ?. ?=(%cell -.body) ~
10741+ ?. ?=([* * ~] fields.body) ~
10742+ :: Charge the cell, two fields, and the head and payload nodes.
10743+ ?: (lth left.u.expanded 5) ~
10744+ =/ head=(unit @) (union-source-cell-tag body)
10745+ ?~ head ~
10746+ =/ field=field i.t.fields.body
10747+ =/ payload=shape
10748+ ?- -.field
10749+ %bare shape.field
10750+ %face shape.field
10751+ %pun [%ref at.field ~[name.field]]
10752+ ==
10753+ =/ pattern=(unit upat)
10754+ ?: ?=(%tvar -.payload)
10755+ ?~ param.u.expanded ~
10756+ ?. =(name.payload name.u.param.u.expanded) ~
10757+ `pat.u.param.u.expanded
10758+ (union-overlap-primitive payload)
10759+ ?~ pattern ~
10760+ `[[at.s u.head u.pattern] (sub left.u.expanded 5)]
10761+++ union-overlap-against
10762+ |= [first=uow-case rest=(list shape) molds=imolds fuel=@ud]
10763+ ^- (unit [witness=(unit upair) left=@ud])
10764+ ?~ rest `[~ fuel]
10765+ ?: =(0 fuel) ~
10766+ =/ other=(unit [item=uow-case left=@ud]) (union-overlap-case i.rest molds (dec fuel))
10767+ ?~ other ~
10768+ ?: &(=(head.first head.item.u.other) =(%overlap (union-relate payload.first payload.item.u.other)))
10769+ `[`[at.first at.item.u.other %overlap] left.u.other]
10770+ $(rest t.rest, fuel left.u.other)
10771+++ union-source-overlap
10772+ |= [cases=(list shape) molds=imolds fuel=@ud]
10773+ ^- (unit upair)
10774+ ?~ cases ~
10775+ ?~ t.cases ~
10776+ ?: =(0 fuel) ~
10777+ =/ first=(unit [item=uow-case left=@ud]) (union-overlap-case i.cases molds (dec fuel))
10778+ ?~ first ~
10779+ =/ found=(unit [witness=(unit upair) left=@ud])
10780+ (union-overlap-against item.u.first t.cases molds left.u.first)
10781+ ?~ found ~
10782+ ?^ witness.u.found witness.u.found
10783+ $(cases t.cases, fuel left.u.found)
10784+::
862810785++ union-pairs
862910786 |= [cases=(list shape) molds=imolds]
863010787 ^- (list upair)
@@ -8638,15 +10795,151 @@
863810795 [at.first at.second (union-relate a (project-union-mold second molds ~))]
863910796 (weld pairs $(cases t.cases))
864010797::
10798+:: A closed structural mold supplies no equation to determine a hole.
10799+:: Applications, references, unbound capitals and unions are unproved.
10800+++ simple-mold-hole
10801+ |= sh=shape
10802+ ^- (unit (unit span))
10803+ ?: ?=(%generic -.sh)
10804+ ?~ vars.sh ~
10805+ ?. (distinct-params vars.sh) ~
10806+ (simple-mold-hole-in body.sh vars.sh)
10807+ (simple-mold-hole-in sh ~)
10808+++ simple-mold-hole-in
10809+ |= [sh=shape vars=(list @t)]
10810+ ^- (unit (unit span))
10811+ ?- -.sh
10812+ %hole ``at.sh
10813+ ?(%aura %noun %void %flag %const) `~
10814+ %tvar ?:((lien vars |=(v=@t =(v name.sh))) `~ ~)
10815+ %cell (simple-mold-field-holes fields.sh vars)
10816+ %fn
10817+ =/ a=(unit (unit span)) $(sh sample.sh)
10818+ ?~ a ~
10819+ =/ b=(unit (unit span)) $(sh product.sh)
10820+ ?~ b ~
10821+ `?~(u.a u.b u.a)
10822+ %generic ~
10823+ * ~
10824+ ==
10825+++ simple-mold-field-holes
10826+ |= [fields=(list field) vars=(list @t)]
10827+ ^- (unit (unit span))
10828+ ?~ fields `~
10829+ =/ f=field i.fields
10830+ =/ first=(unit (unit span))
10831+ ?- -.f
10832+ %face (simple-mold-hole-in shape.f vars)
10833+ %bare (simple-mold-hole-in shape.f vars)
10834+ %pun ~
10835+ ==
10836+ ?~ first ~
10837+ =/ rest=(unit (unit span)) $(fields t.fields)
10838+ ?~ rest ~
10839+ `?~(u.first u.rest u.first)
10840+++ simple-local-mold-hole
10841+ |= defs=(list def)
10842+ ^- (unit span)
10843+ ?~ defs ~
10844+ ?. ?=(%mold -.i.defs) $(defs t.defs)
10845+ =/ found=(unit (unit span)) (simple-mold-hole shape.i.defs)
10846+ ?~ found $(defs t.defs)
10847+ ?^ u.found u.found
10848+ $(defs t.defs)
10849+::
10850+:: A partial prelude may omit unsupported declarations, but may not
10851+:: publish an interface while a named mold's hole remains unchecked.
10852+++ shape-has-hole
10853+ |= sh=shape
10854+ ^- ?
10855+ ?- -.sh
10856+ %hole &
10857+ %path (lien segs.sh |=(s=pseg ?=(%inferred -.s)))
10858+ %apply (lien args.sh shape-has-hole)
10859+ %union (lien cases.sh shape-has-hole)
10860+ %cell (lien fields.sh field-has-hole)
10861+ %fn |($(sh sample.sh) $(sh product.sh))
10862+ %generic $(sh body.sh)
10863+ * |
10864+ ==
10865+++ field-has-hole
10866+ |= f=field
10867+ ^- ?
10868+ ?- -.f
10869+ %face (shape-has-hole shape.f)
10870+ %bare (shape-has-hole shape.f)
10871+ %pun |
10872+ ==
10873+++ named-mold-has-hole
10874+ |= ds=(list def)
10875+ ^- ?
10876+ ?~ ds |
10877+ ?: &(?=(%mold -.i.ds) (shape-has-hole shape.i.ds)) &
10878+ $(ds t.ds)
10879+::
10880+++ sample-has-hole
10881+ |= sam=sample
10882+ ^- ?
10883+ ?- -.sam
10884+ %face (shape-has-hole shape.sam)
10885+ %bare (shape-has-hole shape.sam)
10886+ %cell (lien items.sam sample-has-hole)
10887+ * |
10888+ ==
10889+++ def-has-hole
10890+ |= d=def
10891+ ^- ?
10892+ ?- -.d
10893+ %mold (shape-has-hole shape.d)
10894+ %value (expr-has-hole val.d)
10895+ ==
10896+++ expr-has-hole
10897+ |= e=expr
10898+ ^- ?
10899+ ?- -.e
10900+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10901+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10902+ %change (lien edits.e |=(p=edit (expr-has-hole val.p)))
10903+ %pair $(e val.e)
10904+ %unit $(e val.e)
10905+ %group $(e inner.e)
10906+ %list (lien items.e expr-has-hole)
10907+ %tuple (lien items.e |=(i=item (expr-has-hole val.i)))
10908+ ?(%gate %gate-wide) |((sample-has-hole sample.e) $(e body.e))
10909+ %cast |((shape-has-hole shape.e) $(e val.e))
10910+ %call |($(e head.e) (lien args.e expr-has-hole))
10911+ %trace |($(e val.e) $(e then.e))
10912+ %branch |($(e subject.e) (lien arms.e |=(a=arm (expr-has-hole val.a))))
10913+ %body |((lien defs.e def-has-hole) $(e final.e))
10914+ * |
10915+ ==
10916+++ hole-values-present
10917+ |= [ds=(list def) env=ienv]
10918+ ^- ?
10919+ ?~ ds &
10920+ ?. ?=(%value -.i.ds) $(ds t.ds)
10921+ ?: (expr-has-hole val.i.ds)
10922+ ?. ?=(^ (ienv-lookup name.i.ds env)) |
10923+ $(ds t.ds)
10924+ $(ds t.ds)
864110925++ show-partial-mold
864210926 |= [file=path src=@t d=def molds=imolds]
864310927 ^- @t
864410928 ?> ?=(%mold -.d)
864510929 =/ sh=shape shape.d
10930+ =/ hole=(unit (unit span)) (simple-mold-hole sh)
10931+ ?: &(?=(^ hole) ?=(^ u.hole))
10932+ =/ text=@t (show-error src [file line.beg.u.u.hole col.beg.u.u.hole "unresolved type hole"])
10933+ (of-wain:format ~[(crip "+$ {(trip name.d)}: type hole needs a determined type") text])
864610934 =? sh ?=(%generic -.sh) body.sh
864710935 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
864810936 =/ pairs=(list upair) (union-pairs cases.sh molds)
864910937 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
10938+ =. overlapping
10939+ ?^ overlapping overlapping
10940+ ?. (lien pairs |=(p=upair =(%unknown relation.p))) ~
10941+ =/ witness=(unit upair) (union-source-overlap cases.sh molds 256)
10942+ ?~(witness ~ ~[u.witness])
865010943 ?^ overlapping
865110944 =/ p=upair i.overlapping
865210945 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
@@ -8654,7 +10947,9 @@
865410947 =/ second=@t (show-error src [file line.beg.second.p col.beg.second.p "overlapping case"])
865510948 (of-wain:format ~[summary first second])
865610949 ?: (lien pairs |=(p=upair =(%unknown relation.p)))
8657− (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10950+ ?. (union-source-distinct-tags cases.sh molds 256)
10951+ (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10952+ (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
865810953 (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
865910954::
866010955:: +show-inference-diagnostic: a partial report with both source sites
@@ -8669,6 +10964,21 @@
866910964 (show-error src [file line.beg.at.site col.beg.at.site note.site])
867010965 (of-wain:format [summary excerpts])
867110966::
10967+:: Both written field sites are shown in the source that declares them.
10968+++ show-duplicate-fields
10969+ |= [file=path src=@t diagnostic=idiag]
10970+ ^- @t
10971+ =/ excerpts=(list @t)
10972+ %+ turn sites.diagnostic
10973+ |= site=[at=span note=tape]
10974+ (show-error src [file line.beg.at.site col.beg.at.site note.site])
10975+ (of-wain:format [(crip msg.diagnostic) excerpts])
10976+::
10977+++ duplicate-fields-report
10978+ |= [file=path src=@t diagnostic=idiag]
10979+ ^- @t
10980+ (of-wain:format ~['partial inference; module not checked' (show-duplicate-fields file src diagnostic)])
10981+::
867210982:: +golden-types: a partial report; it does not claim the module checks
867310983::
867410984++ golden-types
@@ -8696,8 +11006,189 @@
869611006+$ jbundle (list jsource)
869711007+$ jcache (list [at=path iface=ifile])
869811008+$ jfile-result (each [iface=ifile cache=jcache] @t)
11009+:: Overlap evidence retains the exact source that supplied its spans.
11010+:: Ordinary Jibb imports preserve this evidence through the resolver.
11011++$ jfile-overlap [file=path source=@t name=term cases=upair]
11012++$ jfile-failure [message=@t overlap=(unit jfile-overlap)]
11013++$ jfile-detailed-result (each [iface=ifile cache=jcache] jfile-failure)
869911014+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
11015+:: Preserve an imported overlap's original file and source across the graph.
11016++$ jimports-detailed-result (each [resolved=ijimports cache=jcache] jfile-failure)
870011017::
11018+:: Written record fields each have their own lexical record scope.
11019++$ written-fields (map term span)
11020+++ duplicate-written-field
11021+ |= [name=term at=span seen=written-fields]
11022+ ^- (unit idiag)
11023+ =/ prior=(unit span) (~(get by seen) name)
11024+ ?~ prior ~
11025+ `["record field `{(trip name)}` is repeated" ~[[u.prior "first field"] [at "repeated field"]]]
11026+++ duplicate-shapes
11027+ |= xs=(list shape)
11028+ ^- (unit idiag)
11029+ ?~ xs ~
11030+ =/ first (duplicate-shape i.xs)
11031+ ?^ first first
11032+ $(xs t.xs)
11033+++ duplicate-fields
11034+ |= [fields=(list field) seen=written-fields]
11035+ ^- (unit idiag)
11036+ ?~ fields ~
11037+ =/ f=field i.fields
11038+ =/ n=(unit term)
11039+ ?- -.f
11040+ %face `name.f
11041+ %pun `name.f
11042+ %bare ~
11043+ ==
11044+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.f seen))
11045+ ?^ dup dup
11046+ =/ inner=(unit idiag)
11047+ ?- -.f
11048+ %face (duplicate-shape shape.f)
11049+ %pun ~
11050+ %bare (duplicate-shape shape.f)
11051+ ==
11052+ ?^ inner inner
11053+ $(fields t.fields, seen ?~(n seen (~(put by seen) u.n at.f)))
11054+++ duplicate-shape
11055+ |= s=shape
11056+ ^- (unit idiag)
11057+ ?- -.s
11058+ %cell (duplicate-fields fields.s ~)
11059+ %apply (duplicate-shapes args.s)
11060+ %union (duplicate-shapes cases.s)
11061+ %fn
11062+ =/ left (duplicate-shape sample.s)
11063+ ?^ left left
11064+ (duplicate-shape product.s)
11065+ %generic (duplicate-shape body.s)
11066+ * ~
11067+ ==
11068+++ duplicate-samples
11069+ |= [items=(list sample) seen=written-fields]
11070+ ^- (unit idiag)
11071+ ?~ items ~
11072+ =/ a=sample i.items
11073+ =/ n=(unit term)
11074+ ?- -.a
11075+ %bind `name.a
11076+ %face `name.a
11077+ %pun `name.a
11078+ * ~
11079+ ==
11080+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.a seen))
11081+ ?^ dup dup
11082+ =/ inner (duplicate-sample a)
11083+ ?^ inner inner
11084+ $(items t.items, seen ?~(n seen (~(put by seen) u.n at.a)))
11085+++ duplicate-sample
11086+ |= s=sample
11087+ ^- (unit idiag)
11088+ ?- -.s
11089+ %cell (duplicate-samples items.s ~)
11090+ %face (duplicate-shape shape.s)
11091+ %bare (duplicate-shape shape.s)
11092+ * ~
11093+ ==
11094+++ duplicate-exprs
11095+ |= xs=(list expr)
11096+ ^- (unit idiag)
11097+ ?~ xs ~
11098+ =/ first (duplicate-expr i.xs)
11099+ ?^ first first
11100+ $(xs t.xs)
11101+++ duplicate-items
11102+ |= [items=(list item) seen=written-fields]
11103+ ^- (unit idiag)
11104+ ?~ items ~
11105+ =/ a=item i.items
11106+ =/ dup=(unit idiag) ?~(face.a ~ (duplicate-written-field u.face.a at.a seen))
11107+ ?^ dup dup
11108+ =/ inner (duplicate-expr val.a)
11109+ ?^ inner inner
11110+ $(items t.items, seen ?~(face.a seen (~(put by seen) u.face.a at.a)))
11111+++ duplicate-pieces
11112+ |= pieces=(list piece)
11113+ ^- (unit idiag)
11114+ ?~ pieces ~
11115+ =/ first=(unit idiag) ?:(?=(%expr -.i.pieces) (duplicate-expr p.i.pieces) ~)
11116+ ?^ first first
11117+ $(pieces t.pieces)
11118+++ duplicate-qsegs
11119+ |= segs=(list qseg)
11120+ ^- (unit idiag)
11121+ ?~ segs ~
11122+ =/ first=(unit idiag) ?:(?=(%expr -.i.segs) (duplicate-expr p.i.segs) ~)
11123+ ?^ first first
11124+ $(segs t.segs)
11125+++ duplicate-edits
11126+ |= edits=(list edit)
11127+ ^- (unit idiag)
11128+ ?~ edits ~
11129+ =/ first (duplicate-expr val.i.edits)
11130+ ?^ first first
11131+ $(edits t.edits)
11132+++ duplicate-arms
11133+ |= arms=(list arm)
11134+ ^- (unit idiag)
11135+ ?~ arms ~
11136+ =/ first (duplicate-expr val.i.arms)
11137+ ?^ first first
11138+ $(arms t.arms)
11139+++ duplicate-defs
11140+ |= defs=(list def)
11141+ ^- (unit idiag)
11142+ ?~ defs ~
11143+ =/ first=(unit idiag)
11144+ ?- -.i.defs
11145+ %mold (duplicate-shape shape.i.defs)
11146+ %value (duplicate-expr val.i.defs)
11147+ ==
11148+ ?^ first first
11149+ $(defs t.defs)
11150+++ duplicate-expr
11151+ |= e=expr
11152+ ^- (unit idiag)
11153+ ?- -.e
11154+ %str (duplicate-pieces pieces.e)
11155+ %qath (duplicate-qsegs segs.e)
11156+ %change (duplicate-edits edits.e)
11157+ %pair (duplicate-expr val.e)
11158+ %unit (duplicate-expr val.e)
11159+ %group (duplicate-expr inner.e)
11160+ %list (duplicate-exprs items.e)
11161+ %tuple (duplicate-items items.e ~)
11162+ %gate-wide
11163+ =/ first (duplicate-sample sample.e)
11164+ ?^ first first
11165+ (duplicate-expr body.e)
11166+ %gate
11167+ =/ first (duplicate-sample sample.e)
11168+ ?^ first first
11169+ (duplicate-expr body.e)
11170+ %cast
11171+ =/ first (duplicate-shape shape.e)
11172+ ?^ first first
11173+ (duplicate-expr val.e)
11174+ %call
11175+ =/ first (duplicate-expr head.e)
11176+ ?^ first first
11177+ (duplicate-exprs args.e)
11178+ %trace
11179+ =/ first (duplicate-expr val.e)
11180+ ?^ first first
11181+ (duplicate-expr then.e)
11182+ %branch
11183+ =/ first (duplicate-expr subject.e)
11184+ ?^ first first
11185+ (duplicate-arms arms.e)
11186+ %body
11187+ =/ first (duplicate-defs defs.e)
11188+ ?^ first first
11189+ (duplicate-expr final.e)
11190+ * ~
11191+ ==
870111192++ import-binding-names
870211193 |= imports=(list import)
870311194 ^- (list term)
@@ -8710,6 +11201,60 @@
871011201 ==
871111202 [n $(imports t.imports)]
871211203::
11204+++ reserved-proj-sample
11205+ |= sam=sample
11206+ ^- ?
11207+ ?- -.sam
11208+ %bind =(name.sam %proj)
11209+ %face =(name.sam %proj)
11210+ %pun =(name.sam %proj)
11211+ %cell (lien items.sam reserved-proj-sample)
11212+ * |
11213+ ==
11214+++ reserved-proj-pattern
11215+ |= p=pattern
11216+ ^- ?
11217+ ?- -.p
11218+ %bind =(name.p %proj)
11219+ %cell (lien items.p reserved-proj-pattern)
11220+ * |
11221+ ==
11222+++ reserved-proj-def
11223+ |= d=def
11224+ ^- ?
11225+ ?: =(name.d %proj) &
11226+ ?: ?=(%value -.d) (reserved-proj-expr val.d)
11227+ |
11228+++ reserved-proj-expr
11229+ |= e=expr
11230+ ^- ?
11231+ ?- -.e
11232+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11233+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11234+ %change (lien edits.e |=(p=edit (reserved-proj-expr val.p)))
11235+ %pair $(e val.e)
11236+ %unit $(e val.e)
11237+ %group $(e inner.e)
11238+ %list (lien items.e reserved-proj-expr)
11239+ %tuple (lien items.e |=(i=item (reserved-proj-expr val.i)))
11240+ ?(%gate %gate-wide) |((reserved-proj-sample sample.e) $(e body.e))
11241+ %cast $(e val.e)
11242+ %call |($(e head.e) (lien args.e reserved-proj-expr))
11243+ %trace |($(e val.e) $(e then.e))
11244+ %branch |($(e subject.e) (lien arms.e |=(a=arm |((reserved-proj-pattern pat.a) (reserved-proj-expr val.a)))))
11245+ %body |((lien defs.e reserved-proj-def) $(e final.e))
11246+ * |
11247+ ==
11248+::
11249+++ module-has-reserved-proj
11250+ |= mod=module
11251+ ^- ?
11252+ =/ imported=(list term) (import-binding-names imports.mod)
11253+ =/ vals=(list term) (global-value-names defs.mod)
11254+ =/ molds=imolds (collect-simple-molds defs.mod)
11255+ =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11256+ |((lien (weld imported (weld vals mold-names)) |=(n=term =(n %proj))) (lien defs.mod reserved-proj-def))
11257+::
871311258++ module-scope-valid
871411259 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
871511260 ^- ?
@@ -8717,6 +11262,7 @@
871711262 =/ vals=(list term) (global-value-names defs.mod)
871811263 =/ molds=imolds (collect-simple-molds defs.mod)
871911264 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11265+ ?: (module-has-reserved-proj mod) |
872011266 ?. %+ levy imported
872111267 |= n=term
872211268 &((unique-value-name n imported) !(lien vals |=(v=term =(n v))) !(lien mold-names |=(m=term =(n m))) !(lien prelude-values |=(v=term =(n v))) !(lien prelude-molds |=(m=term =(n m))))
@@ -8740,6 +11286,43 @@
874011286 (skim defs.mod |=(d=def !&(?=(%mold -.d) =(%poke name.d))))
874111287 (module-scope-valid mod(defs remaining) prelude-values prelude-molds)
874211288::
11289+:: A detailed failure is attached only to the first mold that actually
11290+:: failed in this check, using that module's checked source mold table.
11291++$ imold-failure [message=@t overlap=(unit [name=term cases=upair])]
11292+:: Validate a generic wrapper without an unbounded duplicate-name pass.
11293+++ module-mold-params-valid
11294+ |= [vars=(list @t) seen=(set @t) fuel=@ud]
11295+ ^- ?
11296+ ?~ vars &
11297+ ?: =(0 fuel) |
11298+ ?: (~(has in:..zuse seen) i.vars) |
11299+ $(vars t.vars, seen (~(put in:..zuse seen) i.vars), fuel (dec fuel))
11300+++ module-mold-overlap
11301+ |= [m=[name=term body=shape] molds=imolds]
11302+ ^- (unit upair)
11303+ =/ sh=shape body.m
11304+ =/ valid=?
11305+ ?. ?=(%generic -.sh) &
11306+ ?~ vars.sh |
11307+ (module-mold-params-valid vars.sh *(set @t) 256)
11308+ ?. valid ~
11309+ =? sh ?=(%generic -.sh) body.sh
11310+ ?. ?=(%union -.sh) ~
11311+ (union-source-overlap cases.sh molds 256)
11312+++ module-mold-types-detail
11313+ |= [molds=imolds state=istate]
11314+ ^- (each imold-types imold-failure)
11315+ ?~ molds [%& ~]
11316+ =/ m=[name=term body=shape] i.molds
11317+ =/ t=(unit [template=ischeme state=istate])
11318+ (infer-mold-template body.m state(active [name.m active.state], in-mold &))
11319+ ?~ t
11320+ =/ overlap=(unit upair) (module-mold-overlap m molds.state)
11321+ [%| ['module mold needs unsupported inference' ?~(overlap ~ `[name.m u.overlap])]]
11322+ =. typ.template.u.t (label-direct-union typ.template.u.t body.m name.m state)
11323+ =/ rest=(each imold-types imold-failure) $(molds t.molds)
11324+ ?: ?=(%| -.rest) rest
11325+ [%& [[name.m template.u.t] p.rest]]
874311326++ module-mold-types
874411327 |= [molds=imolds state=istate]
874511328 ^- (each imold-types @t)
@@ -8798,10 +11381,17 @@
879811381 =(var name.i.args.tail)
879911382::
880011383++ prelude-label
8801− |= [typ=itype name=term]
11384+ |= [typ=itype name=term vars=(list @ud)]
880211385 ^- itype
11386+ ?: ?=(%jrec -.typ) typ(label `name)
11387+ ?: ?=(%grec -.typ)
11388+ ?. (identity-union-parameters vars args.typ) typ(label ~)
11389+ typ(label `name)
880311390 ?. ?=(%union -.typ) typ
8804− ?^ args.typ typ
11391+ ?. (identity-union-parameters vars args.typ)
11392+ ?~ origin.typ typ
11393+ ?: =(at.u.origin.typ /lib/jibb/internal/jibb) typ(label ~)
11394+ typ
880511395 typ(label `name)
880611396::
880711397++ partial-prelude-molds
@@ -8816,9 +11406,105 @@
881611406 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
881711407 ?~ out $(molds t.molds)
881811408 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
8819− =. typ.template.u.out (prelude-label typ.template.u.out name.m)
11409+ =. typ.template.u.out (prelude-label typ.template.u.out name.m vars.template.u.out)
882011410 [[name.m template.u.out] $(molds t.molds)]
882111411::
11412+:: A compiler-owned interface available only to the dedicated
11413+:: internal-prelude preparation path, never the ordinary module resolver.
11414+++ private-primitive-interface
11415+ ^- ifile
11416+ =/ a=itype [%avar 0]
11417+ =/ pair=itype [%cell a a]
11418+ =/ b=itype [%rvar 0]
11419+ =/ plus=ischeme [[%fn [%cell b b] b] ~[0]]
11420+ =/ minus=ischeme [[%fn b b] ~[0]]
11421+ =/ greater=ischeme [[%fn pair [%flag ~]] ~[0]]
11422+ =/ utf8=itype [%atom 'tD']
11423+ =/ tape=itype [%collection %list ~[utf8]]
11424+ =/ codepoints=itype [%collection %list ~[[%atom %c]]]
11425+ =/ text-trip=ischeme [[%fn [%atom %t] tape] ~]
11426+ =/ text-tuba=ischeme [[%fn tape codepoints] ~]
11427+ [~[[%raw-add plus] [%raw-dec minus] [%raw-gth greater] [%raw-trip text-trip] [%raw-tuba text-tuba]] ~ /lib/jibb/primitives/jibb ~ ~ ~ ~ ~]
11428+::
11429+++ infer-private-internal
11430+ |= [src=@t public-source=@t]
11431+ ^- (unit ifile)
11432+ =/ at=path /lib/jibb/internal/jibb
11433+ =/ parsed (parse at src)
11434+ ?: ?=(%| -.parsed) ~
11435+ =/ mod=module p.parsed
11436+ ?^ (duplicate-defs defs.mod) ~
11437+ ?~ imports.mod
11438+ =/ built=jfile-result (infer-jibb-file at src ~ ~ ~ ~[at] ~ ~ ~ ~)
11439+ ?: ?=(%| -.built) ~
11440+ `iface.p.built
11441+ ?. ?=([[%jibb *] ~] imports.mod) ~
11442+ ?. =(path.i.imports.mod /lib/jibb/primitives) ~
11443+ ?. (module-scope-valid mod ~ ~) ~
11444+ =/ vals=(list term) (global-value-names defs.mod)
11445+ ?: (lien vals |=(n=term =(n %main))) ~
11446+ =/ molds=imolds (collect-simple-molds defs.mod)
11447+ =/ globals=(list term) (weld (import-binding-names imports.mod) vals)
11448+ :: The private source can use the public list and unit molds before the
11449+ :: prelude is otherwise prepared. Re-read the trusted public source here
11450+ :: and admit only its validated canonical templates; do not accept schemes
11451+ :: supplied independently by the caller.
11452+ =/ public=(each module error) (parse /lib/jibb/prelude/jibb public-source)
11453+ ?: ?=(%| -.public) ~
11454+ ?^ (duplicate-defs defs.p.public) ~
11455+ ?. (module-scope-valid p.public ~ ~) ~
11456+ =/ source-molds=imolds (collect-simple-molds defs.p.public)
11457+ =/ written-list=(unit shape) (find-simple-mold %list source-molds)
11458+ =/ source-list=(unit ischeme)
11459+ ?~ written-list ~
11460+ ?. (standard-prelude-list u.written-list) ~
11461+ `[[%collection %list ~[[%var 0]]] ~[0]]
11462+ :: Derive the public unit template from its actual source, then compare
11463+ :: the complete nominal template before making it available privately.
11464+ =/ unit-decl=(unit shape) (find-simple-mold %unit source-molds)
11465+ =/ source-unit=(unit ischeme)
11466+ ?~ unit-decl ~
11467+ =/ unit-molds=imolds ~[[%unit u.unit-decl]]
11468+ =/ unit-state=istate [0 ~ ~ ~ unit-molds ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | /lib/jibb/prelude/jibb ~[%unit] ~ ~ 256 ~ ~ ~ ~ ~ ~]
11469+ =/ unit-types=imold-types (partial-prelude-molds unit-molds unit-state)
11470+ =/ unit-iface=ifile [~ unit-types /lib/jibb/prelude/jibb ~ ~ ~ ~ ~]
11471+ =/ found=(unit ischeme) (find-jibb-mold %unit unit-iface)
11472+ ?~ found ~
11473+ ?. (standard-unit-template u.found /lib/jibb/prelude/jibb) ~
11474+ found
11475+ =/ primitive=ifile private-primitive-interface
11476+ =? primitive ?=(^ source-list)
11477+ primitive(molds [[%list u.source-list] molds.primitive])
11478+ =? primitive ?=(^ source-unit)
11479+ primitive(molds [[%unit u.source-unit] molds.primitive])
11480+ =/ js=ijimports ~[[face.i.imports.mod primitive]]
11481+ =/ reserved=(list term) ~[face.i.imports.mod]
11482+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11483+ =/ state=istate [0 ~ ~ ~ molds globals ~ ~ ~ ~ js reserved ~ ~ ~ | at top ~ ~ 256 ~ ~ ~ ~ ~ ~]
11484+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11485+ =/ usable=(unit imold-types)
11486+ ?: ?=(%& -.mts) `p.mts
11487+ :: Missing public templates may make an unrelated internal mold
11488+ :: unavailable. Validate all molds once with isolated canonical
11489+ :: templates before admitting only those inferred using the actual
11490+ :: source-backed templates. The proof interface is never exported.
11491+ ?. |(?=(~ source-list) ?=(~ source-unit)) ~
11492+ =/ nil=itype [%const [%null %n 0 '~']]
11493+ =/ canonical-unit=ischeme
11494+ [[%union ~[nil [%cell nil [%face %u [%var 0]]]] `[/lib/jibb/prelude/jibb %unit] `%unit ~[[%var 0]]] ~[0]]
11495+ =/ canonical-list=ischeme [[%collection %list ~[[%var 0]]] ~[0]]
11496+ =/ proof-primitive=ifile private-primitive-interface
11497+ =. molds.proof-primitive ~[[%list canonical-list] [%unit canonical-unit]]
11498+ =/ proof-imports=ijimports ~[[face.i.imports.mod proof-primitive]]
11499+ =/ proof=(each imold-types @t) (module-mold-types molds state(jimports proof-imports))
11500+ ?: ?=(%| -.proof) ~
11501+ `(partial-prelude-molds molds state)
11502+ ?~ usable ~
11503+ =/ resolution=iresolved (resolve-groups defs.mod molds globals ~ ~ ~ ~ js reserved at ~)
11504+ =/ env=ienv env.resolution
11505+ ?. (module-values-complete defs.mod env) ~
11506+ `[env u.usable at ~ artifacts.resolution ~ `src ~]
11507+::
882211508++ partial-prelude-interface-with-internal
882311509 |= [src=@t internal-source=(unit @t)]
882411510 ^- (unit ifile)
@@ -8826,15 +11512,16 @@
882611512 =/ at=path /lib/jibb/prelude/jibb
882711513 =/ parsed (parse at src)
882811514 ?: ?=(%| -.parsed) ~
11515+ ?: (named-mold-has-hole defs.p.parsed) ~
11516+ ?^ (duplicate-defs defs.p.parsed) ~
882911517 =/ private=(unit ijimports)
883011518 ?~ imports.p.parsed `~
883111519 ?. ?=([[%jibb *] ~] imports.p.parsed) ~
883211520 ?. =(path.i.imports.p.parsed /lib/jibb/internal) ~
883311521 ?~ internal-source ~
8834− =/ built=jfile-result
8835− (infer-jibb-file /lib/jibb/internal/jibb u.internal-source ~ ~ ~ ~[/lib/jibb/internal/jibb] ~ ~ ~ ~)
8836− ?: ?=(%| -.built) ~
8837− `~[[face.i.imports.p.parsed iface.p.built]]
11522+ =/ built=(unit ifile) (infer-private-internal u.internal-source src)
11523+ ?~ built ~
11524+ `~[[face.i.imports.p.parsed u.built]]
883811525 ?~ private ~
883911526 ?~ defs.p.parsed ~
884011527 ?. (module-scope-valid p.parsed ~ ~) ~
@@ -8849,9 +11536,16 @@
884911536 =? env-molds declared
885011537 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
885111538 =/ reserved=(list term) ?:(declared ~[%list] ~)
8852− =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~]
8853− =/ mt=imold-types (partial-prelude-molds molds state)
8854− =/ partial=ifile [~ mt at ~]
11539+ =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~ ~ 256 ~ ~ ~ ~ ~ ~]
11540+ :: Other prelude molds may use list only after its source has passed
11541+ :: the standard-list check. The raw declaration remains removed.
11542+ =/ declared-list=(unit shape) (find-simple-mold %list molds)
11543+ =/ mold-prelude=(unit ifile)
11544+ ?~ declared-list ~
11545+ ?. (standard-prelude-list u.declared-list) ~
11546+ `[~ ~[[%list [[%collection %list ~[[%var 0]]] ~[0]]]] at ~ ~ ~ ~ ~]
11547+ =/ mt=imold-types (partial-prelude-molds molds state(prelude mold-prelude))
11548+ =/ partial=ifile [~ mt at ~ ~ ~ ~ ~]
885511549 :: An explicitly qualified re-export must resolve. Other unsupported
885611550 :: prelude declarations remain reserved but absent from the interface.
885711551 =/ required=imolds
@@ -8862,8 +11556,13 @@
886211556 ?~ names.sh |
886311557 ?=(^ t.names.sh)
886411558 ?. (levy required |=(m=[name=term body=shape] ?=(^ (find-jibb-mold name.m partial)))) ~
8865− =/ env=ienv (resolve-supported-defs ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
8866− `[env mt at ~]
11559+ =/ resolution=iresolved (resolve-groups ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
11560+ =/ env=ienv env.resolution
11561+ ?. (hole-values-present ds env) ~
11562+ =/ deps=(list iwidth-dependency)
11563+ ?~ u.private ~
11564+ ~[[at.interface.i.u.private source.interface.i.u.private elaborations.interface.i.u.private]]
11565+ `[env mt at ~ artifacts.resolution deps `src ~]
886711566::
886811567++ partial-prelude-interface
886911568 |= src=@t
@@ -8914,25 +11613,103 @@
891411613 ?: =(at at.i.cache) `iface.i.cache
891511614 $(cache t.cache)
891611615::
11616+:: These certificates retain the complete checked source closure. The
11617+:: trusted host must supply the identical prepared prelude and reader nouns.
11618+:: Exact bundle equality binds all source paths and versions; the set
11619+:: retains transitive paths for active-cycle checks. Request-bearing graphs
11620+:: alone have a size limit; incompatible diamond evidence fails closed.
11621+++ request-graph-requests-add
11622+ |= [pending=(list irequest-evidence) acc=(list irequest-evidence) fuel=@ud]
11623+ ^- (unit (list irequest-evidence))
11624+ ?~ pending `acc
11625+ ?: =(0 fuel) ~
11626+ =/ hit=(list irequest-evidence)
11627+ (skim acc |=(x=irequest-evidence &(=(api-at.x api-at.i.pending) =(name.x name.i.pending))))
11628+ ?^ hit
11629+ ?. ?=([* ~] hit) ~
11630+ ?. =(i.hit i.pending) ~
11631+ $(pending t.pending, fuel (dec fuel))
11632+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11633+++ request-graph-inputs-match
11634+ |= [g=irequest-graph externals=iexternals marks=imark-externals modules=jbundle values=(list term) molds=(list term) prelude=(unit ifile)]
11635+ ^- ?
11636+ ?& =(bundle-input.g modules)
11637+ =(prelude-input.g prelude)
11638+ =(prelude-values.g values)
11639+ =(prelude-molds.g molds)
11640+ =(externals.g externals)
11641+ =(marks.g marks)
11642+ ==
11643+++ request-graph-merge
11644+ |= [imports=ijimports g=irequest-graph fuel=@ud]
11645+ ^- (unit irequest-graph)
11646+ ?~ imports `g
11647+ ?: =(0 fuel) ~
11648+ =/ child=ifile interface.i.imports
11649+ ?~ graph.child ~
11650+ =/ cg=irequest-graph u.graph.child
11651+ ?. ?& =(bundle-input.g bundle-input.cg)
11652+ =(prelude-input.g prelude-input.cg)
11653+ =(prelude-values.g prelude-values.cg)
11654+ =(prelude-molds.g prelude-molds.cg)
11655+ =(externals.g externals.cg)
11656+ =(marks.g marks.cg)
11657+ ==
11658+ ~
11659+ =/ merged=(set path) (~(uni in:..zuse paths.g) paths.cg)
11660+ =/ rs=(unit (list irequest-evidence))
11661+ (request-graph-requests-add requests.cg requests.g (add 1 (lent requests.cg)))
11662+ ?~ rs ~
11663+ ?: &(?=(^ u.rs) |((gth (lent ~(tap in:..zuse merged)) 256) (gth (lent u.rs) 256))) ~
11664+ $(imports t.imports, g g(paths merged, requests u.rs), fuel (dec fuel))
11665+++ request-graph-reusable
11666+ |= [f=ifile src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) values=(list term) molds=(list term) prelude=(unit ifile)]
11667+ ^- ?
11668+ ?~ source.f |
11669+ ?. =(u.source.f src) |
11670+ ?~ graph.f |
11671+ =/ g=irequest-graph u.graph.f
11672+ ?. (request-graph-inputs-match g externals marks modules values molds prelude) |
11673+ ?. (~(has in:..zuse paths.g) at.f) |
11674+ !(lien active |=(p=path (~(has in:..zuse paths.g) p)))
11675+::
891711676++ resolve-jibb-imports
891811677 |= [imports=(list import) externals=iexternals mark-externals=imark-externals modules=jbundle active=(list path) prelude-values=(list term) prelude-molds=(list term) cache=jcache prelude=(unit ifile)]
891911678 ^- jimports-result
11679+ =/ result=jimports-detailed-result
11680+ (resolve-jibb-imports-detailed imports externals mark-externals modules active prelude-values prelude-molds cache prelude)
11681+ ?: ?=(%| -.result) [%| message.p.result]
11682+ [%& p.result]
11683+++ resolve-jibb-imports-detailed
11684+ |= [imports=(list import) externals=iexternals mark-externals=imark-externals modules=jbundle active=(list path) prelude-values=(list term) prelude-molds=(list term) cache=jcache prelude=(unit ifile)]
11685+ ^- jimports-detailed-result
892011686 ?~ imports [%& [~ cache]]
892111687 ?. ?=(%jibb -.i.imports) $(imports t.imports)
892211688 =/ at=path (weld path.i.imports `path`~[%jibb])
892311689 ?: =(at /lib/jibb/internal/jibb)
8924− [%| 'the prelude internal module is private']
11690+ [%| ['the prelude internal module is private' ~]]
11691+ ?: =(at /lib/jibb/primitives/jibb)
11692+ [%| ['the prelude primitive interface is private' ~]]
892511693 ?: (lien active |=(p=path =(p at)))
8926− [%| (crip "import cycle at {(spud at)}")]
11694+ [%| [(crip "import cycle at {(spud at)}") ~]]
892711695 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
8928− ?~ found [%| (crip "module source missing: {(spud at)}")]
8929− ?^ t.found [%| (crip "duplicate module sources: {(spud at)}")]
11696+ ?~ found [%| [(crip "module source missing: {(spud at)}") ~]]
11697+ ?^ t.found [%| [(crip "duplicate module sources: {(spud at)}") ~]]
893011698 =/ cached=(unit ifile) (find-jibb-cache at cache)
8931− =/ iface=jfile-result
8932− ?^ cached [%& [u.cached cache]]
8933− (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
11699+ =/ iface=jfile-detailed-result
11700+ ?^ cached
11701+ ?. =(at.u.cached at) [%| ['cached module identity needs unsupported inference' ~]]
11702+ ?~ graph.u.cached
11703+ :: A detached legacy interface has unknown evidence. Rebuild it
11704+ :: against the current graph, without retaining any stale entry.
11705+ =/ clean=jcache (skim cache |=(x=[at=path iface=ifile] !=(at.x at)))
11706+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds clean prelude)
11707+ ?. (request-graph-reusable u.cached source.i.found externals mark-externals modules active prelude-values prelude-molds prelude)
11708+ [%| ['cached module evidence needs unsupported inference' ~]]
11709+ [%& [u.cached cache]]
11710+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
893411711 ?: ?=(%| -.iface) [%| p.iface]
8935− =/ rest=jimports-result $(imports t.imports, cache cache.p.iface)
11712+ =/ rest=jimports-detailed-result $(imports t.imports, cache cache.p.iface)
893611713 ?: ?=(%| -.rest) rest
893711714 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
893811715::
@@ -8980,7 +11757,7 @@
898011757 ?~ segments `~
898111758 ?: ?=(%knot -.i.segments) $(segments t.segments)
898211759 =/ seg=pseg i.segments
8983− ?> ?=(%typed -.seg)
11760+ ?. ?=(%typed -.seg) ~
898411761 ?: =(0 aura.seg) ~
898511762 ?: (lien seen |=(n=term =(n name.seg))) ~
898611763 =/ rest=(unit (list iapi-parameter)) $(segments t.segments, seen [name.seg seen])
@@ -9066,6 +11843,7 @@
906611843 ^- ?
906711844 =/ path-names=(list term) (turn paths |=(p=iapi-path name.p))
906811845 =/ derived=(list term) (weld path-names poke-names)
11846+ ?: (lien derived |=(n=term =(n %proj))) |
906911847 =/ outer=(list term) (weld prelude-values (weld (global-value-names defs.mod) (api-import-faces imports.mod)))
907011848 (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x))))))
907111849::
@@ -9111,6 +11889,8 @@
911111889++ api-path-analysis
911211890 |= [mod=module externals=imark-externals prelude-values=(list term) prelude-molds=(list term)]
911311891 ^- (unit (list iapi-path-typed))
11892+ ?: (lien defs.mod def-has-hole) ~
11893+ ?^ (duplicate-defs defs.mod) ~
911411894 =/ ds=(list def) defs.mod
911511895 =/ declarations=(list def)
911611896 (skim ds |=(d=def &(?=(%mold -.d) =(%paths name.d))))
@@ -9138,9 +11918,11 @@
913811918 |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
913911919 ^- (each (list iapi-path-typed) @t)
914011920 ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path analysis requires /ui/api/<agent>.jibb']
9141− ?~ prepared [%| 'API path analysis needs the prepared prelude']
914211921 =/ parsed (parse file src)
914311922 ?: ?=(%| -.parsed) [%| 'API path source does not parse']
11923+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11924+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11925+ ?~ prepared [%| 'API path analysis needs the prepared prelude']
914411926 =/ prelude=(unit ifile) `iface.u.prepared
914511927 =/ deps=jimports-result
914611928 (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ prelude)
@@ -9150,6 +11932,346 @@
915011932 ?~ paths [%| 'API path declaration needs unsupported analysis']
915111933 [%& u.paths]
915211934::
11935+:: Analysis evidence retains the API source, the prepared interface, the
11936+:: caller's reader results and the resolved Jibb dependency cache alongside
11937+:: the typed path declarations. Reader results and prepared interfaces are
11938+:: trusted inputs: this does not verify their underlying Hoon source/version,
11939+:: create requests or check the provenance of arbitrary values.
11940++$ iapi-path-evidence
11941+ [at=path source=@t prepared=iprelude externals=iexternals marks=imark-externals dependencies=jcache paths=(list iapi-path-typed)]
11942+++ api-path-evidence-source
11943+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11944+ ^- (each iapi-path-evidence @t)
11945+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11946+ =/ parsed (parse file src)
11947+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11948+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11949+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11950+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11951+ =/ public=ifile iface.u.prepared
11952+ =/ deps=jimports-result
11953+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
11954+ ?: ?=(%| -.deps) [%| p.deps]
11955+ =/ paths=(unit (list iapi-path-typed))
11956+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11957+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11958+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11959+:: Graph-aware variant preserves the caller active stack and cache.
11960+++ api-path-evidence-graph
11961+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11962+ ^- (each iapi-path-evidence @t)
11963+ ?~ active [%| 'API analysis needs an active graph']
11964+ ?. =(i.active file) [%| 'API analysis active graph does not start at the source']
11965+ ?: (lien t.active |=(p=path =(p file))) [%| 'API analysis active graph contains a cycle']
11966+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11967+ =/ parsed (parse file src)
11968+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11969+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11970+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11971+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11972+ =/ public=ifile iface.u.prepared
11973+ =/ deps=jimports-result
11974+ (resolve-jibb-imports imports.p.parsed externals marks modules active values.u.prepared molds.u.prepared cache `public)
11975+ ?: ?=(%| -.deps) [%| p.deps]
11976+ =/ paths=(unit (list iapi-path-typed))
11977+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11978+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11979+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11980+::
11981+:: This query classifies a unique path declaration only. Missing evidence
11982+:: or a nonunique name is unknown; it proves nothing about an ask value.
11983+:: Like prepared interfaces, the supplied evidence is a trusted host input.
11984+++ api-path-watchability
11985+ |= [evidence=(unit iapi-path-evidence) case-name=term]
11986+ ^- ?(%watchable %not-watchable %unknown)
11987+ ?~ evidence %unknown
11988+ =/ found=(list iapi-path-typed)
11989+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
11990+ ?. ?=([* ~] found) %unknown
11991+ ?~ scry.path.i.found %watchable
11992+ %not-watchable
11993+::
11994+:: These are declaration-derived request components, not a callable gate,
11995+:: an ask value, or proof of a value's provenance. Keep the exact trusted
11996+:: source/reader evidence until a later checked interface and lowerer can
11997+:: attach it to a generated request. No argument ordering is claimed here.
11998++$ iapi-request-parameter [name=term typ=itype at=span]
11999++$ iapi-request-parts
12000+ [evidence=iapi-path-evidence path=iapi-path-typed parameters=(list iapi-request-parameter) reply-sample=itype fold=(unit itype) watchability=?(%watchable %not-watchable)]
12001+++ api-request-parameter-types
12002+ |= params=(list iapi-parameter)
12003+ ^- (unit (list iapi-request-parameter))
12004+ ?~ params `~
12005+ =/ aura=@ta aura.i.params
12006+ ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
12007+ =/ rest=(unit (list iapi-request-parameter)) $(params t.params)
12008+ ?~ rest ~
12009+ `[[name.i.params [%atom aura] at.i.params] u.rest]
12010+::
12011+:: A single diff's fold consumes the tagged diff and the previous full value.
12012+:: Multiple-diff unions need a checked union representation and remain open.
12013+++ api-request-fold-type
12014+ |= p=iapi-path-typed
12015+ ^- (unit (unit itype))
12016+ ?~ diffs.p `~
12017+ ?^ t.diffs.p ~
12018+ =/ d=iapi-mark-type i.diffs.p
12019+ =/ literal=lit [%term %tas name.d (crip ['%' (trip name.d)])]
12020+ =/ sample=itype [%cell [%cell [%const literal] typ.d] full.p]
12021+ ``[%fn sample full.p]
12022+::
12023+++ api-request-parts
12024+ |= [evidence=(unit iapi-path-evidence) case-name=term]
12025+ ^- (unit iapi-request-parts)
12026+ ?~ evidence ~
12027+ =/ found=(list iapi-path-typed)
12028+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
12029+ ?. ?=([* ~] found) ~
12030+ =/ p=iapi-path-typed i.found
12031+ =/ raw=(unit (list iapi-parameter)) (api-path-parameters segments.path.p ~)
12032+ ?~ raw ~
12033+ =/ params=(unit (list iapi-request-parameter)) (api-request-parameter-types u.raw)
12034+ ?~ params ~
12035+ =/ fold=(unit (unit itype)) (api-request-fold-type p)
12036+ ?~ fold ~
12037+ =/ watch=?(%watchable %not-watchable) ?~(scry.path.p %watchable %not-watchable)
12038+ `[u.evidence p u.params full.p u.fold watch]
12039+::
12040+:: Check ordinary API molds and values plus every declared mark type using
12041+:: the same trusted source, prepared prelude and reader inputs as path
12042+:: evidence. Keep elaborations with those inputs for a later interface.
12043+:: This is partial analysis: an unused /- core is not independently checked,
12044+:: definitions needing derived values remain unsupported, and no complete
12045+:: API, request or constructor is exported or given runtime behavior.
12046++$ iapi-support-evidence
12047+ [paths=iapi-path-evidence values=ienv molds=imold-types marks=(list iapi-mark-type) elaborations=(list iwidth-definition)]
12048+++ api-support-analysis-source
12049+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12050+ ^- (each iapi-support-evidence @t)
12051+ =/ path-result (api-path-evidence-source file src externals marks modules prepared)
12052+ ?: ?=(%| -.path-result) [%| p.path-result]
12053+ =/ evidence=iapi-path-evidence p.path-result
12054+ =/ parsed (parse file src)
12055+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12056+ =/ mod=module p.parsed
12057+ =/ ordinary=(list def)
12058+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12059+ =/ prep=iprelude prepared.evidence
12060+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12061+ =/ vals=(list term) (global-value-names ordinary)
12062+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12063+ =/ declared=(list term) (collect-mark-imports imports.mod)
12064+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12065+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12066+ =/ prelude=(unit ifile) `iface.prep
12067+ =/ deps=jimports-result
12068+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.prep molds.prep dependencies.evidence prelude)
12069+ ?: ?=(%| -.deps) [%| p.deps]
12070+ =/ molds=imolds (collect-simple-molds ordinary)
12071+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12072+ =/ surs=(list term) (collect-sur-imports imports.mod)
12073+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12074+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12075+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12076+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12077+ ?: ?=(%| -.mts) [%| p.mts]
12078+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12079+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12080+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12081+:: Preserve the same graph context through supporting definitions.
12082+++ api-support-analysis-graph
12083+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12084+ ^- (each iapi-support-evidence @t)
12085+ =/ path-result (api-path-evidence-graph file src externals marks modules active cache prepared)
12086+ ?: ?=(%| -.path-result) [%| p.path-result]
12087+ =/ evidence=iapi-path-evidence p.path-result
12088+ =/ parsed (parse file src)
12089+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12090+ =/ mod=module p.parsed
12091+ =/ ordinary=(list def)
12092+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12093+ =/ prep=iprelude prepared.evidence
12094+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12095+ =/ vals=(list term) (global-value-names ordinary)
12096+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12097+ =/ declared=(list term) (collect-mark-imports imports.mod)
12098+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12099+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12100+ =/ prelude=(unit ifile) `iface.prep
12101+ =/ deps=jimports-result
12102+ (resolve-jibb-imports imports.mod externals marks modules active values.prep molds.prep dependencies.evidence prelude)
12103+ ?: ?=(%| -.deps) [%| p.deps]
12104+ =/ molds=imolds (collect-simple-molds ordinary)
12105+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12106+ =/ surs=(list term) (collect-sur-imports imports.mod)
12107+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12108+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12109+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12110+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12111+ ?: ?=(%| -.mts) [%| p.mts]
12112+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12113+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12114+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12115+::
12116+:: Type-analysis artifact for one plain request. The resolver may publish
12117+:: its interface only together with trusted source and reader evidence.
12118+:: No lowering or runtime validator exists.
12119+:: Value watchability remains unproved even for a watchable declaration.
12120++$ ione-request-interface
12121+ [support=iapi-support-evidence parts=iapi-request-parts iface=ifile]
12122+++ request-compatible-ask
12123+ |= prelude=iprelude
12124+ ^- (unit ischeme)
12125+ =/ public=ifile iface.prelude
12126+ ?. =(at.public /lib/jibb/prelude/jibb) ~
12127+ =/ ask=(unit ischeme) (find-jibb-mold %ask public)
12128+ ?~ ask ~
12129+ ?. ?=([@ ~] vars.u.ask) ~
12130+ ?. ?=(%union -.typ.u.ask) ~
12131+ ?. =(origin.typ.u.ask `[/lib/jibb/internal/jibb %ask]) ~
12132+ ?. (identity-union-parameters vars.u.ask args.typ.u.ask) ~
12133+ =/ m=@ud i.vars.u.ask
12134+ ?: (itype-var-is-atom m typ.u.ask) ~
12135+ ?. (levy (itype-vars typ.u.ask) |=(n=@ud =(n m))) ~
12136+ ?: (itype-has-tag typ.u.ask) ~
12137+ =/ private=(list iwidth-dependency)
12138+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12139+ ?. ?=([* ~] private) ~
12140+ ?~ source.i.private ~
12141+ =/ path=(unit ischeme) (find-jibb-mold %path public)
12142+ ?~ path ~
12143+ ?^ vars.u.path ~
12144+ =/ path-type=itype [%collection %list ~[[%atom %ta]]]
12145+ ?. =(typ.u.path path-type) ~
12146+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit public)
12147+ ?~ unit-template ~
12148+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
12149+ =/ state-unit=(unit itype) (template-apply u.unit-template ~[[%noun ~]])
12150+ ?~ state-unit ~
12151+ =/ path-unit=(unit itype) (template-apply u.unit-template ~[path-type])
12152+ ?~ path-unit ~
12153+ =/ output=itype [%cell [%face %state [%noun ~]] [%face %message [%var m]]]
12154+ =/ agent-input=itype [%cell [%face %mark [%atom %tas]] [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]]
12155+ =/ store-input=itype [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]
12156+ =/ pure-case=itype [%cell [%const [%term %tas %pure '%pure']] [%face %value [%var m]]]
12157+ =/ agent-case=itype
12158+ [%cell [%const [%term %tas %agent '%agent']] [%cell [%face %api [%atom %t]] [%cell [%face %case [%atom %tas]] [%cell [%face %agent [%atom %tas]] [%cell [%face %path path-type] [%cell [%face %scry u.path-unit] [%face %receive [%fn agent-input output]]]]]]]]
12159+ =/ store-case=itype
12160+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %name [%atom %tas]] [%face %receive [%fn store-input output]]]]]
12161+ ?. =(cases.typ.u.ask ~[pure-case agent-case store-case]) ~
12162+ ask
12163+::
12164+:: The first supported standalone API has exactly one mark import and one
12165+:: plain path declaration, with no other definitions or imports. No partial
12166+:: success is published when source, schema, or a required mold is unknown.
12167+++ one-request-interface-source
12168+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12169+ ^- (each ione-request-interface @t)
12170+ =/ out (api-support-analysis-source file src externals marks modules prepared)
12171+ ?: ?=(%| -.out) [%| p.out]
12172+ =/ support=iapi-support-evidence p.out
12173+ =/ ev=iapi-path-evidence paths.support
12174+ =/ parsed (parse file src)
12175+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12176+ =/ mod=module p.parsed
12177+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12178+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12179+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12180+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12181+ =/ p=iapi-path-typed i.paths.ev
12182+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12183+ ?~ parts [%| 'request components need unsupported inference']
12184+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12185+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12186+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12187+ =/ valid-marks=?
12188+ ?~ fold.u.parts ?=([* ~] marks.support)
12189+ ?=([* [* ~]] marks.support)
12190+ ?. valid-marks [%| 'request marks need unsupported inference']
12191+ =/ fold-open=?
12192+ ?~ fold.u.parts |
12193+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12194+ ?: fold-open [%| 'request fold needs unsupported inference']
12195+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12196+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12197+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12198+ ?~ ask [%| 'request ask needs unsupported inference']
12199+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12200+ ?~ result [%| 'request ask needs unsupported inference']
12201+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12202+ =/ sample=itype
12203+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12204+ ?~ parameters.u.parts callback
12205+ [%cell typ.i.parameters.u.parts callback]
12206+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12207+ =/ exports=imold-types
12208+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12209+ =/ prelude=iprelude prepared.ev
12210+ =/ public=ifile iface.prelude
12211+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12212+ =/ private=(list iwidth-dependency)
12213+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12214+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12215+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12216+ =/ req=irequest-evidence
12217+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12218+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12219+ [%& [support u.parts interface]]
12220+:: Graph-aware request artifact; resolver use remains type-only.
12221+++ one-request-interface-graph
12222+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12223+ ^- (each ione-request-interface @t)
12224+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12225+ ?: ?=(%| -.out) [%| p.out]
12226+ =/ support=iapi-support-evidence p.out
12227+ =/ ev=iapi-path-evidence paths.support
12228+ =/ parsed (parse file src)
12229+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12230+ =/ mod=module p.parsed
12231+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12232+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12233+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12234+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12235+ =/ p=iapi-path-typed i.paths.ev
12236+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12237+ ?~ parts [%| 'request components need unsupported inference']
12238+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12239+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12240+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12241+ =/ valid-marks=?
12242+ ?~ fold.u.parts ?=([* ~] marks.support)
12243+ ?=([* [* ~]] marks.support)
12244+ ?. valid-marks [%| 'request marks need unsupported inference']
12245+ =/ fold-open=?
12246+ ?~ fold.u.parts |
12247+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12248+ ?: fold-open [%| 'request fold needs unsupported inference']
12249+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12250+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12251+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12252+ ?~ ask [%| 'request ask needs unsupported inference']
12253+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12254+ ?~ result [%| 'request ask needs unsupported inference']
12255+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12256+ =/ sample=itype
12257+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12258+ ?~ parameters.u.parts callback
12259+ [%cell typ.i.parameters.u.parts callback]
12260+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12261+ =/ exports=imold-types
12262+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12263+ =/ prelude=iprelude prepared.ev
12264+ =/ public=ifile iface.prelude
12265+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12266+ =/ private=(list iwidth-dependency)
12267+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12268+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12269+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12270+ =/ req=irequest-evidence
12271+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12272+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12273+ [%& [support u.parts interface]]
12274+::
915312275++ api-mark-exports
915412276 |= [marks=(list term) all=(list term) externals=imark-externals]
915512277 ^- imold-types
@@ -9163,7 +12285,9 @@
916312285++ api-poke-interface
916412286 |= [at=path mod=module mark-externals=imark-externals prelude-values=(list term) prelude-molds=(list term) prelude=(unit ifile)]
916512287 ^- (unit ifile)
12288+ ?: (lien defs.mod def-has-hole) ~
916612289 ?. ?=([%ui %api @ %jibb ~] at) ~
12290+ ?^ (duplicate-defs defs.mod) ~
916712291 ?~ prelude ~
916812292 ?. =(at.u.prelude /lib/jibb/prelude/jibb) ~
916912293 =/ poke=(unit ischeme) (find-jibb-mold %poke u.prelude)
@@ -9191,40 +12315,288 @@
919112315 =/ mark=(unit itype) (find-imported-mark n mark-externals marks)
919212316 ?~ mark ~
919312317 =/ sc=ischeme [[%fn u.mark typ.u.poke] ~]
9194− `[~[[n sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]]]
12318+ `[~[[n sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]] ~ ~ ~ ~]
12319+::
12320+:: Source-proven ordinary helpers validate each selected /sur dependency.
12321+:: Unused or less direct cores remain unsupported by this first interface.
12322+++ api-sur-covered
12323+ |= [surs=(list term) defs=(list def) externals=iexternals all=(list term)]
12324+ ^- ?
12325+ ?~ surs &
12326+ =/ found=(list def)
12327+ %+ skim defs
12328+ |= d=def
12329+ ?. ?=(%mold -.d) |
12330+ ?. ?=(%ref -.shape.d) |
12331+ ?. ?=([@ [@ ~]] names.shape.d) |
12332+ =(i.t.names.shape.d i.surs)
12333+ ?~ found |
12334+ =/ selected=def i.found
12335+ ?. ?=(%mold -.selected) |
12336+ =/ sh=shape shape.selected
12337+ ?. ?=(%ref -.sh) |
12338+ ?. ?=([@ [@ ~]] names.sh) |
12339+ =/ checked=(unit itype) (find-imported-mold i.surs i.names.sh externals all)
12340+ ?~ checked |
12341+ $(surs t.surs)
12342+::
12343++$ imulti-request-gates [values=ienv requests=(list irequest-evidence)]
12344+++ api-request-gates
12345+ |= [paths=(list iapi-path-typed) ev=iapi-path-evidence ask=ischeme file=path src=@t public=@t internal=@t externals=iexternals marks=imark-externals fuel=@ud]
12346+ ^- (unit imulti-request-gates)
12347+ ?~ paths `[~ ~]
12348+ ?: =(0 fuel) ~
12349+ =/ p=iapi-path-typed i.paths
12350+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12351+ ?~ parts ~
12352+ ?. ?=(?(~ [* ~]) parameters.u.parts) ~
12353+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) ~
12354+ ?^ scry.path.p ~
12355+ ?^ (itype-vars reply-sample.u.parts) ~
12356+ ?: (itype-has-tag reply-sample.u.parts) ~
12357+ =/ open-fold=?
12358+ ?~ fold.u.parts |
12359+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12360+ ?: open-fold ~
12361+ =/ result=(unit itype) (template-apply ask ~[[%var 0]])
12362+ ?~ result ~
12363+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12364+ =/ sample=itype
12365+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12366+ ?~ parameters.u.parts callback
12367+ [%cell typ.i.parameters.u.parts callback]
12368+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12369+ =/ prep=iprelude prepared.ev
12370+ =/ req=irequest-evidence
12371+ [file name.path.p p src public internal values.prep molds.prep externals marks]
12372+ =/ rest=(unit imulti-request-gates)
12373+ $(paths t.paths, fuel (dec fuel))
12374+ ?~ rest ~
12375+ `[[[name.path.p scheme] values.u.rest] [req requests.u.rest]]
12376+::
12377+++ api-poke-from-checked
12378+ |= [file=path mod=module marks=imark-externals values=(list term) molds=(list term) prelude=(unit ifile)]
12379+ ^- (unit [values=ienv derived=(list iderived)])
12380+ =/ pokes=(list def)
12381+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12382+ ?~ pokes `[~ ~]
12383+ ?. ?=([* ~] pokes) ~
12384+ =/ declared=(list term) (collect-mark-imports imports.mod)
12385+ =/ ns=(unit (list term)) (api-poke-mark-names pokes declared)
12386+ ?~ ns ~
12387+ ?. ?=([@ ~] u.ns) ~
12388+ =/ matching=(list import)
12389+ %+ skim imports.mod
12390+ |= i=import
12391+ ?. ?=(%mark -.i) |
12392+ =(mark.i i.u.ns)
12393+ ?. ?=([* ~] matching) ~
12394+ =/ checked=(unit ifile)
12395+ (api-poke-interface file mod(defs pokes, imports matching) marks values molds prelude)
12396+ ?~ checked ~
12397+ `[values.u.checked derived.u.checked]
12398+::
12399+:: The partial interface is published atomically: all paths, ordinary
12400+:: source definitions, declared marks and the poke must check. Unselected
12401+:: /sur bindings, runtime validation and value watchability remain unproved.
12402+++ multi-request-interface-graph
12403+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12404+ ^- (each [iface=ifile cache=jcache] @t)
12405+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12406+ ?: ?=(%| -.out) [%| p.out]
12407+ =/ support=iapi-support-evidence p.out
12408+ =/ ev=iapi-path-evidence paths.support
12409+ =/ parsed (parse file src)
12410+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12411+ =/ mod=module p.parsed
12412+ ?. (levy imports.mod |=(i=import ?=(?(%mark %sur) -.i)))
12413+ [%| 'request imports need unsupported inference']
12414+ =/ surs=(list term) (collect-sur-imports imports.mod)
12415+ ?. (api-sur-covered surs defs.mod externals surs)
12416+ [%| 'API source dependency needs unsupported inference']
12417+ ?~ paths.ev [%| 'request count needs unsupported inference']
12418+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12419+ ?~ ask [%| 'request ask needs unsupported inference']
12420+ =/ prep=iprelude prepared.ev
12421+ =/ public=ifile iface.prep
12422+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12423+ =/ private=(list iwidth-dependency)
12424+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12425+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12426+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12427+ =/ gates=(unit imulti-request-gates)
12428+ (api-request-gates paths.ev ev u.ask file src u.source.public u.source.i.private externals marks 256)
12429+ ?~ gates [%| 'request paths need unsupported inference']
12430+ =/ poke=(unit [values=ienv derived=(list iderived)])
12431+ (api-poke-from-checked file mod marks values.prep molds.prep `public)
12432+ ?~ poke [%| 'API poke needs unsupported inference']
12433+ =/ mark-molds=imold-types
12434+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12435+ =/ exports=imold-types (weld mark-molds molds.support)
12436+ =/ names=(list term) (turn exports |=(m=[name=term template=ischeme] name.m))
12437+ ?. (levy names |=(n=term (unique-value-name n names)))
12438+ [%| 'API exported molds need unsupported inference']
12439+ =/ env=ienv (weld values.u.gates (weld values.u.poke values.support))
12440+ =/ graph=irequest-graph
12441+ [(silt `(list path)`~[file]) requests.u.gates modules `public values.prep molds.prep externals marks]
12442+ =/ iface=ifile
12443+ [env exports file derived.u.poke elaborations.support ~ `src `graph]
12444+ [%& [iface dependencies.ev]]
919512445::
919612446++ infer-jibb-file
919712447 |= [at=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle active=(list path) prelude-values=(list term) prelude-molds=(list term) cache=jcache prelude=(unit ifile)]
919812448 ^- jfile-result
12449+ =/ out=jfile-detailed-result
12450+ (infer-jibb-file-detailed at src externals mark-externals modules active prelude-values prelude-molds cache prelude)
12451+ ?: ?=(%| -.out) [%| message.p.out]
12452+ [%& p.out]
12453+:: Returns structured root-source overlap evidence after the same full check.
12454+++ infer-jibb-file-detailed
12455+ |= [at=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle active=(list path) prelude-values=(list term) prelude-molds=(list term) cache=jcache prelude=(unit ifile)]
12456+ ^- jfile-detailed-result
919912457 =/ parsed (parse at src)
9200− ?: ?=(%| -.parsed) [%| (crip "module source does not parse: {(spud at)}")]
12458+ ?: ?=(%| -.parsed) [%| [(crip "module source does not parse: {(spud at)}") ~]]
920112459 =/ mod=module p.parsed
12460+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12461+ ?^ duplicate [%| [(show-duplicate-fields at src u.duplicate) ~]]
920212462 ?: ?=([%ui %api *] at)
920312463 =/ iface=(unit ifile) (api-poke-interface at mod mark-externals prelude-values prelude-molds prelude)
9204− ?~ iface [%| (crip "API module needs unsupported inference: {(spud at)}")]
9205− [%& [u.iface [[at u.iface] cache]]]
12464+ ?^ iface
12465+ =/ checked=ifile u.iface(source `src, graph `[(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals])
12466+ [%& [checked [[at checked] cache]]]
12467+ ?~ prelude [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12468+ =/ prepared=iprelude [u.prelude prelude-values prelude-molds]
12469+ =/ narrow=?
12470+ ?. ?=([[%mark *] ~] imports.mod) |
12471+ ?. ?=([[%mold *] ~] defs.mod) |
12472+ ?. =(%paths name.i.defs.mod) |
12473+ !?=(%union -.shape.i.defs.mod)
12474+ ?: narrow
12475+ =/ request=(each ione-request-interface @t)
12476+ (one-request-interface-graph at src externals mark-externals modules active cache `prepared)
12477+ ?: ?=(%| -.request) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12478+ =/ checked=ifile iface.p.request
12479+ [%& [checked [[at checked] dependencies.paths.support.p.request]]]
12480+ =/ multi=(each [iface=ifile cache=jcache] @t)
12481+ (multi-request-interface-graph at src externals mark-externals modules active cache `prepared)
12482+ ?: ?=(%| -.multi) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12483+ [%& [iface.p.multi [[at iface.p.multi] cache.p.multi]]]
920612484 ?. (module-scope-valid mod prelude-values prelude-molds)
920712485 ?: (pending-declared-poke at mod prelude-values prelude-molds)
9208− [%| (crip "module kind or scope needs unsupported inference: {(spud at)}")]
9209− [%| (crip "module has conflicting names: {(spud at)}")]
12486+ [%| [(crip "module kind or scope needs unsupported inference: {(spud at)}") ~]]
12487+ [%| [(crip "module has conflicting names: {(spud at)}") ~]]
921012488 =/ vals=(list term) (global-value-names defs.mod)
921112489 ?: (lien vals |=(n=term =(n %main)))
9212− [%| (crip "module kind needs unsupported inference: {(spud at)}")]
9213− =/ js=jimports-result (resolve-jibb-imports imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
12490+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
12491+ =/ js=jimports-detailed-result (resolve-jibb-imports-detailed imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
921412492 ?: ?=(%| -.js) [%| p.js]
9215− =/ molds=imolds (collect-simple-molds defs.mod)
12493+ =/ collected=grec-collected
12494+ ?^ imports.mod [(collect-simple-molds defs.mod) *(map term shape)]
12495+ (grec-collect-molds defs.mod)
12496+ =/ molds=imolds molds.collected
921612497 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
921712498 =/ surs=(list term) (collect-sur-imports imports.mod)
921812499 =/ marks=(list term) (collect-mark-imports imports.mod)
921912500 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
922012501 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
9221− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude]
9222− =/ mts=(each imold-types @t) (module-mold-types molds state)
9223− ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
9224− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12502+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12503+ :: Source and scope were checked above; preserve that exact root and prelude.
12504+ :: This first integration only indexes import-free library sources.
12505+ =/ index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])
12506+ ?^ imports.mod ~
12507+ ?~ prelude ~
12508+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude)
12509+ ?~ standard ~
12510+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
12511+ =/ index=(map term shape) proofs.collected
12512+ ?. !=(index *(map term shape)) ~
12513+ ?: (lien molds |=(m=[name=term body=shape] =(%list name.m))) ~
12514+ `[at src u.prelude index]
12515+ =. grec-index.state index
12516+ =/ mts=(each imold-types imold-failure) (module-mold-types-detail molds state)
12517+ ?: ?=(%| -.mts)
12518+ ?~ overlap.p.mts [%| [(crip "{(trip message.p.mts)}: {(spud at)}") ~]]
12519+ =/ witness=[name=term cases=upair] u.overlap.p.mts
12520+ =/ first=@t (show-error src [at line.beg.first.cases.witness col.beg.first.cases.witness "first union case"])
12521+ =/ second=@t (show-error src [at line.beg.second.cases.witness col.beg.second.cases.witness "overlapping case"])
12522+ =/ msg=@t (of-wain:format ~[(crip "module mold {(trip name.witness)} has overlapping cases") first second])
12523+ [%| [msg `[at src name.witness cases.witness]]]
12524+ =/ resolution=iresolved
12525+ ?~ index
12526+ (resolve-groups defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12527+ (resolve-groups-core defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude index)
12528+ =/ env=ienv env.resolution
12529+ =. env
12530+ ?: (module-values-complete defs.mod env) env
12531+ ?: |(?=([%ui %stores *] at) ?=(^ imports.mod) ?=(^ prelude) ?=(^ prelude-values) ?=(^ prelude-molds)) env
12532+ ?: (gth (met 3 src) 65.536) env
12533+ ?: (gth (lent defs.mod) 64) env
12534+ ?. (dg-source-candidate defs.mod 64) env
12535+ =/ transaction=(unit dgcommit) (dg-root-source at src)
12536+ ?~ transaction env
12537+ ?: (dg-interface-safe env.u.transaction) env.u.transaction
12538+ env
922512539 ?. (module-values-complete defs.mod env)
9226− [%| (crip "module definitions need unsupported inference: {(spud at)}")]
9227− [%& [[env p.mts at ~] [[at [env p.mts at ~]] cache.p.js]]]
12540+ [%| [(crip "module definitions need unsupported inference: {(spud at)}") ~]]
12541+ =/ initial=irequest-graph [(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals]
12542+ =/ graph=(unit irequest-graph) (request-graph-merge resolved.p.js initial (add 1 (lent resolved.p.js)))
12543+ ?~ graph [%| ['module request evidence needs unsupported inference' ~]]
12544+ =/ iface=ifile [env p.mts at ~ artifacts.resolution ~ `src graph]
12545+ [%& [iface [[at iface] cache.p.js]]]
12546+::
12547+:: A source-bound analysis of one named mold, not a module, island,
12548+:: request, watchability or runtime check. The host owns the trusted
12549+:: prepared prelude, canonical paths and reader/source version identities.
12550+:: The 256-node cap covers only classification, not source/graph work.
12551++$ igate-free-mold
12552+ [at=path source=@t name=term prepared=iprelude externals=iexternals marks=imark-externals modules=jbundle dependencies=jcache mold=ischeme requested=@ud budget=@ud result=igate-free]
12553+++ gate-free-mold-source
12554+ |= [file=path src=@t name=term externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude) fuel=@ud]
12555+ ^- (each igate-free-mold @t)
12556+ ?~ file [%| 'mold analysis needs a path ending in jibb']
12557+ ?. =(%jibb (rear file)) [%| 'mold analysis needs a path ending in jibb']
12558+ ?: |(=(file /lib/jibb/internal/jibb) =(file /lib/jibb/primitives/jibb))
12559+ [%| 'the prelude internal modules are private']
12560+ ?: ?=([%ui %api *] file) [%| 'API declarations need unsupported mold analysis']
12561+ ?: ?=([%ui %stores *] file) [%| 'store declarations need unsupported mold analysis']
12562+ =/ entries=jbundle (skim modules |=(m=jsource =(file at.m)))
12563+ ?: (gth (lent entries) 1) [%| 'duplicate root module sources']
12564+ =/ wrong-root=? ?~(entries | !=(source.i.entries src))
12565+ ?: wrong-root [%| 'root module source does not match bundle']
12566+ =/ parsed (parse file src)
12567+ ?: ?=(%| -.parsed) [%| 'mold source does not parse']
12568+ =/ mod=module p.parsed
12569+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12570+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12571+ ?~ prepared [%| 'mold analysis needs the prepared prelude']
12572+ ?. (module-scope-valid mod values.u.prepared molds.u.prepared)
12573+ [%| 'mold source has conflicting or unsupported scope']
12574+ =/ selected=(list def)
12575+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(name.d name))))
12576+ ?~ selected [%| 'selected mold is not declared']
12577+ ?^ t.selected [%| 'selected mold is not unique']
12578+ ?> ?=(%mold -.i.selected)
12579+ =/ public=ifile iface.u.prepared
12580+ =/ js=jimports-result
12581+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
12582+ ?: ?=(%| -.js) [%| p.js]
12583+ =/ ms=imolds (collect-simple-molds defs.mod)
12584+ =/ vals=(list term) (global-value-names defs.mod)
12585+ =/ globals=(list term) (weld values.u.prepared (weld (import-binding-names imports.mod) vals))
12586+ =/ surs=(list term) (collect-sur-imports imports.mod)
12587+ =/ declared=(list term) (collect-mark-imports imports.mod)
12588+ =/ reserved=(list term) (weld molds.u.prepared (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
12589+ =/ top=(list term) (turn ms |=(m=[name=term body=shape] name.m))
12590+ =/ state=istate [0 ~ ~ ~ ms globals externals surs marks declared resolved.p.js reserved ~ ~ ~ | file top `public ~ 256 ~ ~ ~ ~ ~ ~]
12591+ =/ inferred=(unit [template=ischeme state=istate])
12592+ (infer-mold-template shape.i.selected state(active ~[name], in-mold &))
12593+ ?~ inferred [%| 'selected mold needs unsupported inference']
12594+ =/ template=ischeme template.u.inferred
12595+ =. typ.template (label-direct-union typ.template shape.i.selected name state)
12596+ =. typ.template (itype-normalize typ.template sub.state.u.inferred)
12597+ =/ cap=@ud (min fuel 256)
12598+ =/ analysis=igate-free (gate-free-type typ.template cap ~)
12599+ [%& [file src name u.prepared externals marks modules cache.p.js template fuel cap analysis]]
922812600::
922912601:: +golden-types-with-modules fails closed for imports without prelude
923012602:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -9235,6 +12607,8 @@
923512607 ^- @t
923612608 =/ parsed (parse file src)
923712609 ?: ?=(%| -.parsed) (show-error src p.parsed)
12610+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12611+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
923812612 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
923912613 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
924012614 (golden-types-with-marks file src externals mark-externals)
@@ -9249,6 +12623,8 @@
924912623 ^- @t
925012624 =/ parsed (parse file src)
925112625 ?: ?=(%| -.parsed) (show-error src p.parsed)
12626+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12627+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
925212628 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
925312629 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
925412630 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
@@ -9267,6 +12643,8 @@
926712643 ^- @t
926812644 =/ parsed (parse file src)
926912645 ?: ?=(%| -.parsed) (show-error src p.parsed)
12646+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12647+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
927012648 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
927112649 =/ prelude-values=(list term) values.u.prepared
927212650 =/ prelude-molds=(list term) molds.u.prepared
@@ -9314,6 +12692,10 @@
931412692 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
931512693 =/ parsed (parse file src)
931612694 ?: ?=(%| -.parsed) (show-error src p.parsed)
12695+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12696+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
12697+ ?: (module-has-reserved-proj p.parsed)
12698+ 'module has reserved proj name'
931712699 =/ ds=(list def) defs.p.parsed
931812700 =/ molds=imolds (collect-simple-molds ds)
931912701 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
@@ -9322,6 +12704,33 @@
932212704 =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
932312705 =/ cycles=(list icycle) (definite-value-cycles ds globals)
932412706 =/ env=ienv env.resolution
12707+ =/ recovered=(list term) ~
12708+ =/ eligible=?
12709+ ?& ?=(~ imports.p.parsed)
12710+ ?=(~ jimports)
12711+ ?=(~ prelude)
12712+ ?=(~ prelude-values)
12713+ ?=(~ reserved-molds)
12714+ !?=([%ui %api *] file)
12715+ !?=([%ui %stores *] file)
12716+ !(lien (global-value-names ds) |=(n=term =(n %main)))
12717+ (module-scope-valid p.parsed ~ ~)
12718+ !(module-values-complete ds env)
12719+ (lte (met 3 src) 65.536)
12720+ (lte (lent ds) 64)
12721+ (dg-source-candidate ds 64)
12722+ ==
12723+ =/ transaction=(unit dgcommit) ?:(eligible (dg-root-source file src) ~)
12724+ =. recovered
12725+ ?~ transaction ~
12726+ ?. &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) ~
12727+ (turn (skim env.u.transaction |=(entry=[name=term scheme=ischeme] ?=(~ (ienv-lookup name.entry env)))) |=(entry=[name=term scheme=ischeme] name.entry))
12728+ =. env
12729+ ?~ transaction env
12730+ ?: &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) env.u.transaction
12731+ env
12732+ =/ source-defs=(map term def) (direct-checked-gates ds env)
12733+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
932512734 =/ lines=(list @t) ~
932612735 |-
932712736 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -9334,6 +12743,16 @@
933412743 ?^ cycle
933512744 =/ diag=idiag ["non-gate value depends on itself through a cycle" ~[[first.i.cycle "value in cycle"] [next.i.cycle "dependency in cycle"]]]
933612745 $(ds t.ds, lines [(show-inference-diagnostic file src name.d diag) lines])
12746+ ?: (lien recovered |=(n=term =(n name.d)))
12747+ =/ found=(unit ischeme) (ienv-lookup name.d env)
12748+ ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: committed definition unavailable") lines])
12749+ ?: (itype-has-hidden-recursive typ.u.found)
12750+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive mold name is not available in this scope") lines])
12751+ ?: (itype-has-hidden-generic typ.u.found)
12752+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: generic union name is not available in this scope") lines])
12753+ =/ typ=itype (canonical-itype typ.u.found vars.u.found)
12754+ =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
12755+ $(ds t.ds, lines [line lines])
933712756 ?: (lien grouped.resolution |=(n=term =(n name.d)))
933812757 =/ found=(unit ischeme) (ienv-lookup name.d env)
933912758 ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
@@ -9341,7 +12760,9 @@
934112760 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
934212761 $(ds t.ds, lines [line lines])
934312762 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
9344− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude]
12763+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12764+ =. gate-defs.initial source-defs
12765+ =. head-evidence.initial heads
934512766 =. initial (reserve-def-caps val.d initial)
934612767 =/ result=iresult
934712768 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
@@ -9349,6 +12770,11 @@
934912770 (infer-fragment val.d env initial)
935012771 ?: ?=(%| -.result)
935112772 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
12773+ =. state.p.result (promote-restricted-numbers state.p.result env)
12774+ =. state.p.result (default-hole-numbers holes.state.p.result holes.initial state.p.result env !(itype-has-gate (itype-normalize typ.p.result sub.state.p.result)))
12775+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.result holes.initial state.p.result)
12776+ ?^ hole
12777+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d u.hole) lines])
935212778 =/ merged=(unit [first=icap second=icap])
935312779 (merged-capitals caps.state.p.result sub.state.p.result)
935412780 ?^ merged
@@ -9371,7 +12797,576 @@
937112797 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
937212798 ?: (gth (lent vars) 26)
937312799 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
12800+ ?~ (width-finalize projections.state.p.result sub.state.p.result vars)
12801+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: record projection elaboration needs unsupported inference") lines])
937412802 =/ printable=itype (canonical-itype typ vars)
937512803 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
937612804 $(ds t.ds, lines [line lines])
12805+:: Experimental module-owned pending-constraint generalization only.
12806+:: Inputs, IDs and substitution come from one checker-owned transaction.
12807++$ dgscan [ids=(list @ud) fuel=@ud]
12808+++ dg-scan
12809+ |= [todo=(list itype) sub=isub fuel=@ud ids=(list @ud)]
12810+ ^- (unit dgscan)
12811+ ?~ todo `[ids fuel]
12812+ ?: =(0 fuel) ~
12813+ =. fuel (dec fuel)
12814+ =/ t=itype i.todo
12815+ ?: ?=(?(%var %avar %rvar %nvar %rnvar %tag) -.t)
12816+ =/ node-id=@ud ?:(?=(%tag -.t) id.t +.t)
12817+ =/ found=(unit itype) (itype-lookup node-id sub)
12818+ ?~ found $(todo t.todo, ids [node-id ids])
12819+ ?: &(?=(?(%rvar %rnvar) -.u.found) =(node-id +.u.found))
12820+ $(todo t.todo, ids [node-id ids])
12821+ $(todo [u.found t.todo])
12822+ ?: ?=(%jrec -.t) $(todo t.todo)
12823+ ?+ -.t ~
12824+ %collection $(todo (weld args.t t.todo))
12825+ %union $(todo (weld args.t (weld cases.t t.todo)))
12826+ %face $(todo [body.t t.todo])
12827+ %fn $(todo [sample.t product.t t.todo])
12828+ %cell $(todo [hed.t tal.t t.todo])
12829+ %atom $(todo t.todo)
12830+ %any-atom $(todo t.todo)
12831+ %flag $(todo t.todo)
12832+ %noun $(todo t.todo)
12833+ %empty $(todo t.todo)
12834+ %const $(todo t.todo)
12835+ ==
12836+::
12837+++ dg-scan-ids
12838+ |= [ids=(list @ud) sub=isub fuel=@ud blocked=(list @ud)]
12839+ ^- (unit dgscan)
12840+ ?~ ids `[blocked fuel]
12841+ =/ one=(unit dgscan) (dg-scan ~[[%var i.ids]] sub fuel blocked)
12842+ ?~ one ~
12843+ $(ids t.ids, fuel fuel.u.one, blocked ids.u.one)
12844+::
12845+++ dg-env
12846+ |= [env=ienv sub=isub fuel=@ud blocked=(list @ud)]
12847+ ^- (unit dgscan)
12848+ ?~ env `[blocked fuel]
12849+ =/ sc=ischeme scheme.i.env
12850+ :: Quantifiers are local to the scheme: first find raw free IDs, then
12851+ :: follow those IDs in the module substitution without capturing them.
12852+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ fuel ~)
12853+ ?~ raw ~
12854+ =/ free=(list @ud) (skim ids.u.raw |=(n=@ud !(lien vars.sc |=(q=@ud =(q n)))))
12855+ =/ resolved=(unit dgscan) (dg-scan-ids free sub fuel.u.raw blocked)
12856+ ?~ resolved ~
12857+ $(env t.env, fuel fuel.u.resolved, blocked ids.u.resolved)
12858+::
12859+++ dg-obligations
12860+ |= [pending=(list dgo) sub=isub fuel=@ud blocked=(list @ud)]
12861+ ^- (unit dgscan)
12862+ ?~ pending `[blocked fuel]
12863+ =/ found=(unit dgscan) (dg-scan ~[left.i.pending right.i.pending] sub fuel blocked)
12864+ ?~ found ~
12865+ $(pending t.pending, fuel fuel.u.found, blocked ids.u.found)
12866+::
12867+++ dg-tags
12868+ |= [tags=(list ipending) sub=isub fuel=@ud blocked=(list @ud)]
12869+ ^- (unit dgscan)
12870+ ?~ tags `[blocked fuel]
12871+ ?: =(0 fuel) ~
12872+ =/ found=(unit itype) (itype-lookup id.i.tags sub)
12873+ ?~ found $(tags t.tags, fuel (dec fuel), blocked [id.i.tags blocked])
12874+ :: Until this entry is explicitly discharged, retain variables reachable
12875+ :: through its binding; mere existence of a substitution is not proof.
12876+ =/ reached=(unit dgscan) (dg-scan ~[u.found] sub (dec fuel) blocked)
12877+ ?~ reached ~
12878+ $(tags t.tags, fuel fuel.u.reached, blocked ids.u.reached)
12879+::
12880+++ dg-generalize
12881+ |= [typ=itype env=ienv pending=(list dgo) tags=(list ipending) captured=(list @ud) state=istate fuel=@ud]
12882+ ^- (unit ischeme)
12883+ :: Bound the obligation list and all graph/substitution walks. The
12884+ :: substitution is assumed checker-owned and occurs-checked.
12885+ ?: (gth (lent pending) 64) ~
12886+ =/ capt=(unit dgscan) (dg-scan-ids captured sub.state fuel ~)
12887+ ?~ capt ~
12888+ =/ env-free=(unit dgscan) (dg-env env sub.state fuel.u.capt ids.u.capt)
12889+ ?~ env-free ~
12890+ =/ obligations=(unit dgscan) (dg-obligations pending sub.state fuel.u.env-free ids.u.env-free)
12891+ ?~ obligations ~
12892+ =/ tagged=(unit dgscan) (dg-tags tags sub.state fuel.u.obligations ids.u.obligations)
12893+ ?~ tagged ~
12894+ =/ bounded=(unit dgscan) (dg-scan ~[typ] sub.state fuel.u.tagged ~)
12895+ ?~ bounded ~
12896+ =/ normalized=itype (itype-normalize typ sub.state)
12897+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
12898+ =/ quantified=(list @ud) (skim vars |=(n=@ud !(lien ids.u.tagged |=(b=@ud =(b n)))))
12899+ `[[normalized quantified]]
12900+::
12901++$ dgcommit [env=ienv state=istate]
12902+:: A branch literal must not acquire a value face through replay.
12903+++ dg-literal-target-safe
12904+ |= target=itype
12905+ ^- ?
12906+ ?: ?=(%union -.target)
12907+ (levy cases.target |=(c=itype ?=(?(%const %cell) -.c)))
12908+ ?=(?(%const %atom %any-atom %flag %noun) -.target)
12909+::
12910+++ dg-replay-edges
12911+ |= [edges=(list dgo) state=istate fuel=@ud]
12912+ ^- (unit istate)
12913+ ?~ edges `state
12914+ ?: =(0 fuel) ~
12915+ =/ trial=ifit (itype-fit left.i.edges right.i.edges sub.state next.state)
12916+ ?. ?=(%ok -.trial) ~
12917+ =/ valid=?
12918+ ?: ?=(%tag -.left.i.edges)
12919+ ?. constructor.left.i.edges
12920+ =/ closed=(unit dgscan) (dg-scan ~[right.i.edges] sub.trial 512 ~)
12921+ ?~ closed |
12922+ ?^ ids.u.closed |
12923+ (dg-literal-target-safe (itype-normalize right.i.edges sub.trial))
12924+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12925+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12926+ ?. valid ~
12927+ $(edges t.edges, state state(sub sub.trial, next next.trial), fuel (dec fuel))
12928+::
12929+++ dg-close-env
12930+ |= [env=ienv sub=isub fuel=@ud]
12931+ ^- (unit ienv)
12932+ ?~ env `~
12933+ ?: =(0 fuel) ~
12934+ =/ s=ischeme scheme.i.env
12935+ :: Quantified IDs are scheme-local and cannot be rewritten on publication.
12936+ ?. (levy vars.s |=(n=@ud ?=(~ (itype-lookup n sub)))) ~
12937+ =/ bounded=(unit dgscan) (dg-scan ~[typ.s] sub (dec fuel) ~)
12938+ ?~ bounded ~
12939+ =/ normalized=itype (itype-normalize typ.s sub)
12940+ ?: (itype-has-tag normalized) ~
12941+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
12942+ ?. (levy vars |=(n=@ud (lien vars.s |=(v=@ud =(v n))))) ~
12943+ =/ rest=(unit ienv) (dg-close-env t.env sub fuel.u.bounded)
12944+ ?~ rest ~
12945+ `[[name.i.env [normalized vars.s]] u.rest]
12946+::
12947+:: A deferred boolean branch has exactly the two literal flag patterns.
12948+:: Arms are inferred in order. Equal types are retained; two direct pending
12949+:: literals may instead retain source-owned obligations for later context.
12950+++ dg-boolean-patterns
12951+ |= e=expr
12952+ ^- ?
12953+ ?. ?=(%branch -.e) |
12954+ ?~ arms.e |
12955+ ?~ t.arms.e |
12956+ ?^ t.t.arms.e |
12957+ =/ x=arm i.arms.e
12958+ =/ y=arm i.t.arms.e
12959+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
12960+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
12961+ !=(val.lit.pat.x val.lit.pat.y)
12962+:: Only a direct source literal which created its own unbound pending tag
12963+:: may create a branch edge. The caller must retain the exact source and state.
12964+++ dg-owned-arm-literal
12965+ |= [e=expr t=itype tags=(list ipending) sub=isub initial=@ud]
12966+ ^- ?
12967+ ?. ?=(%lit -.e) |
12968+ ?. ?=(%tag -.t) |
12969+ ?: constructor.t |
12970+ ?. =(lit.e literal.t) |
12971+ ?: (lth id.t initial) |
12972+ ?^ (itype-lookup id.t sub) |
12973+ (lien tags |=(x=ipending &(=(id.x id.t) =(literal.x literal.t))))
12974+++ dg-boolean-branch
12975+ |= [e=expr env=ienv state=istate]
12976+ ^- iresult
12977+ ?. (dg-boolean-patterns e) [%| ["deferred branch patterns need unsupported inference" ~]]
12978+ ?> ?=(%branch -.e)
12979+ ?> ?=(^ arms.e)
12980+ ?> ?=(^ t.arms.e)
12981+ =/ x=arm i.arms.e
12982+ =/ y=arm i.t.arms.e
12983+ =/ subject=iresult (infer-fragment subject.e env state)
12984+ ?: ?=(%| -.subject) subject
12985+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
12986+ ?~ su [%| ["deferred branch subject does not unify with ?" ~]]
12987+ =/ left=iresult (infer-fragment val.x env state.p.subject(sub u.su))
12988+ ?: ?=(%| -.left) left
12989+ =/ right=iresult (infer-fragment val.y env state.p.left)
12990+ ?: ?=(%| -.right) right
12991+ ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
12992+ =/ st=istate state.p.right
12993+ ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
12994+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12995+ ?. (dg-owned-arm-literal val.y typ.p.right tags.st sub.st next.state)
12996+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12997+ ?> ?=(%tag -.typ.p.left)
12998+ ?> ?=(%tag -.typ.p.right)
12999+ ?: =(id.typ.p.left id.typ.p.right)
13000+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13001+ ?: (gth (lent obligations.st) 62)
13002+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13003+ =/ result=itype [%var next.st]
13004+ =/ ex=dgo [typ.p.left result (span-of val.x) (span-of e)]
13005+ =/ ey=dgo [typ.p.right result (span-of val.y) (span-of e)]
13006+ [%& result st(next +(next.st), obligations [ex ey obligations.st])]
13007+ [%& typ.p.left state.p.right]
13008+::
13009+:: Deferred inference uses only source forms whose successful fit sites are
13010+:: guarded below; a shared source-node budget bounds this screen.
13011+++ dg-safe-expressions
13012+ |= [todo=(list expr) fuel=@ud]
13013+ ^- (unit @ud)
13014+ ?~ todo `fuel
13015+ =/ first=(unit @ud) (dg-safe-expression i.todo fuel)
13016+ ?~ first ~
13017+ $(todo t.todo, fuel u.first)
13018+++ dg-safe-expression
13019+ |= [e=expr fuel=@ud]
13020+ ^- (unit @ud)
13021+ ?: =(0 fuel) ~
13022+ =. fuel (dec fuel)
13023+ ?+ -.e ~
13024+ ?(%lit %ctor) `fuel
13025+ %wing ?:(?=([@ ~] names.e) `fuel ~)
13026+ %str
13027+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) ~
13028+ `fuel
13029+ %group $(e inner.e, fuel fuel)
13030+ %body
13031+ ?^ defs.e ~
13032+ $(e final.e, fuel fuel)
13033+ %gate $(e body.e, fuel fuel)
13034+ %gate-wide $(e body.e, fuel fuel)
13035+ %branch
13036+ ?. (dg-boolean-patterns e) ~
13037+ ?> ?=(^ arms.e)
13038+ ?> ?=(^ t.arms.e)
13039+ =/ subject=(unit @ud) $(e subject.e, fuel fuel)
13040+ ?~ subject ~
13041+ (dg-safe-expressions ~[val.i.arms.e val.i.t.arms.e] u.subject)
13042+ %cast $(e val.e, fuel fuel)
13043+ %call
13044+ =/ head=(unit @ud) $(e head.e, fuel fuel)
13045+ ?~ head ~
13046+ (dg-safe-expressions args.e u.head)
13047+ ==
13048+:: Exact normalized equality is preserved by all later substitutions.
13049+:: The bounded scan declines opaque types and oversized inputs.
13050+++ dg-stable-fit
13051+ |= [actual=itype expected=itype sub=isub]
13052+ ^- ?
13053+ ?~ (dg-scan ~[actual expected] sub 512 ~) |
13054+ =((itype-normalize actual sub) (itype-normalize expected sub))
13055+::
13056+:: A positional call peels sample-slot faces during its separate face check.
13057+:: Require its argument, sample and result closed so that check stays valid.
13058+++ dg-stable-call-fit
13059+ |= [actual=itype expected=itype product=itype sub=isub positional=?]
13060+ ^- ?
13061+ =/ checked=(unit dgscan) (dg-scan ~[actual expected product] sub 512 ~)
13062+ ?~ checked |
13063+ ?: &(positional ?=(^ ids.u.checked)) |
13064+ =((itype-normalize actual sub) (itype-normalize expected sub))
13065+::
13066+:: One definition attempt retains state only when inference succeeds.
13067++$ dg-step [env=ienv state=istate pending=(list dgo)]
13068+++ dg-stage-one
13069+ |= [d=def env=ienv state=istate]
13070+ ^- (unit dg-step)
13071+ ?> ?=(%value -.d)
13072+ ?~ (dg-safe-expression val.d 512) ~
13073+ =/ local=istate (reserve-def-caps val.d state)
13074+ :: This first slice declines all written capitals and holes/projections.
13075+ ?^ caps.local ~
13076+ =/ ordinary=iresult (infer-fragment val.d env local)
13077+ ?: ?=(%| -.ordinary) ~
13078+ =/ typ=itype typ.p.ordinary
13079+ =/ after=istate state.p.ordinary
13080+ =/ edges=(list dgo) obligations.after
13081+ ?. =(binders.after binders.state) ~
13082+ ?. =(molds.after molds.state) ~
13083+ ?. =(globals.after globals.state) ~
13084+ ?. =(externals.after externals.state) ~
13085+ ?. =(surs.after surs.state) ~
13086+ ?. =(mark-externals.after mark-externals.state) ~
13087+ ?. =(marks.after marks.state) ~
13088+ ?. =(jimports.after jimports.state) ~
13089+ ?. =(reserved-molds.after reserved-molds.state) ~
13090+ ?. =(params.after params.state) ~
13091+ ?. =(active.after active.state) ~
13092+ ?. =(in-mold.after in-mold.state) ~
13093+ ?. =(at.after at.state) ~
13094+ ?. =(top-molds.after top-molds.state) ~
13095+ ?. =(prelude.after prelude.state) ~
13096+ ?. =(gate-defs.after gate-defs.state) ~
13097+ ?. =(head-evidence.after head-evidence.state) ~
13098+ ?. =(grec-index.after grec-index.state) ~
13099+ ?. =(defer.after defer.state) ~
13100+ ?. =(holes.after holes.state) ~
13101+ ?. =(caps.after caps.state) ~
13102+ ?. =(projections.after projections.state) ~
13103+ ?: (unsupported-atom-vars (itype-normalize typ sub.after) caps.after binders.after sub.after) ~
13104+ ?: (itype-has-nvar (itype-normalize typ sub.after)) ~
13105+ =/ scheme=(unit ischeme) (dg-generalize typ env edges tags.after ~ after 32.768)
13106+ ?~ scheme ~
13107+ `[[[name.d u.scheme] env] after edges]
13108+:: Retry only definitions that did not infer. Successful definitions are
13109+:: committed into the local transaction, never published until all close.
13110+++ dg-stage
13111+ |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
13112+ ^- (unit dgcommit)
13113+ ?: (gth fuel 64) ~
13114+ ?: (gth (lent ds) fuel) ~
13115+ =/ remaining=(list def) ds
13116+ =/ waiting=(list def) ~
13117+ =/ progress=? |
13118+ =/ attempts=@ud (mul fuel fuel)
13119+ |-
13120+ ?~ remaining
13121+ ?^ waiting
13122+ ?. progress ~
13123+ $(remaining (flop waiting), waiting ~, progress |)
13124+ =/ replayed=(unit istate) (dg-replay-edges pending state 64)
13125+ ?~ replayed ~
13126+ ?: (pending-tags tags.u.replayed sub.u.replayed) ~
13127+ =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
13128+ ?~ closed-edges ~
13129+ ?^ ids.u.closed-edges ~
13130+ =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
13131+ ?~ rechecked ~
13132+ ?. =(sub.u.rechecked sub.u.replayed) ~
13133+ ?. =(next.u.rechecked next.u.replayed) ~
13134+ =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
13135+ ?~ closed ~
13136+ `[[u.closed u.replayed(defer ~, obligations ~)]]
13137+ ?: =(0 attempts) ~
13138+ =. attempts (dec attempts)
13139+ =/ d=def i.remaining
13140+ ?: ?=(%mold -.d) $(remaining t.remaining)
13141+ ?^ (ienv-lookup name.d base) $(remaining t.remaining)
13142+ ?^ (ienv-lookup name.d env) ~
13143+ =/ done=(unit dg-step) (dg-stage-one d env state)
13144+ ?~ done $(remaining t.remaining, waiting [d waiting])
13145+ $(remaining t.remaining, env env.u.done, state state.u.done, pending pending.u.done, progress &)
13146+::
13147+:: Cheap bounded eligibility check on the already parsed source. This
13148+:: deliberately covers only direct constructor calls beneath transparent
13149+:: groups, gates, casts and definition-free bodies. Other shapes decline
13150+:: this fallback without a second parse or resolution pass.
13151+++ dg-direct-source
13152+ |= [e=expr fuel=@ud]
13153+ ^- ?
13154+ ?: =(0 fuel) |
13155+ ?+ -.e |
13156+ %group $(e inner.e, fuel (dec fuel))
13157+ %gate $(e body.e, fuel (dec fuel))
13158+ %gate-wide $(e body.e, fuel (dec fuel))
13159+ %cast $(e val.e, fuel (dec fuel))
13160+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
13161+ %call
13162+ ?. ?=([* ~] args.e) |
13163+ ?=(%ctor -.i.args.e)
13164+ ==
13165+++ dg-source-candidate
13166+ |= [ds=(list def) fuel=@ud]
13167+ ^- ?
13168+ ?~ ds |
13169+ ?: =(0 fuel) |
13170+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
13171+ ?: (dg-direct-source val.i.ds 64) &
13172+ $(ds t.ds, fuel (dec fuel))
13173+::
13174+++ dg-interface-safe
13175+ |= [env=ienv]
13176+ ^- ?
13177+ ?~ env &
13178+ =/ sc=ischeme scheme.i.env
13179+ ?: |((itype-has-hidden-recursive typ.sc) (itype-has-hidden-generic typ.sc)) |
13180+ ?: (gth (lent vars.sc) 26) |
13181+ $(env t.env)
13182+:: Parse status and the transaction result come from the same source parse.
13183++$ dgparse [parsed=? result=(unit dgcommit)]
13184+++ dg-root-source
13185+ |= [at=path src=@t]
13186+ ^- (unit dgcommit)
13187+ result:(dg-root-detail at src)
13188+++ dg-root-detail
13189+ |= [at=path src=@t]
13190+ ^- dgparse
13191+ =/ parsed (parse at src)
13192+ ?: ?=(%| -.parsed) [| ~]
13193+ =/ transact
13194+ |.
13195+ ?^ imports.p.parsed ~
13196+ ?. (module-scope-valid p.parsed ~ ~) ~
13197+ ?^ (duplicate-defs defs.p.parsed) ~
13198+ =/ defs=(list def) defs.p.parsed
13199+ ?: (gth (lent defs) 64) ~
13200+ =/ molds=imolds (collect-simple-molds defs)
13201+ =/ globals=(list term) (global-value-names defs)
13202+ =/ resolution=iresolved (resolve-groups defs molds globals ~ ~ ~ ~ ~ ~ at ~)
13203+ ?^ grouped.resolution ~
13204+ ?^ artifacts.resolution ~
13205+ =/ base=ienv env.resolution
13206+ =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
13207+ ?~ free ~
13208+ ?^ ids.u.free ~
13209+ =/ all=(unit dgscan) (dg-all-env-ids base 32.768 ~)
13210+ ?~ all ~
13211+ =/ fresh=@ud (dg-next-id ids.u.all 0)
13212+ =/ st=istate *istate
13213+ =. st st(next fresh, defer `~, molds molds, globals globals, at at, top-molds (turn molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
13214+ =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
13215+ ?: ?=(%| -.checked-molds) ~
13216+ (dg-stage defs base base st ~ 64)
13217+ ::
13218+ [& (transact)]
13219+++ dg-all-env-ids
13220+ |= [env=ienv fuel=@ud ids=(list @ud)]
13221+ ^- (unit dgscan)
13222+ ?~ env `[ids fuel]
13223+ ?: =(0 fuel) ~
13224+ =/ sc=ischeme scheme.i.env
13225+ ?: (itype-has-tag typ.sc) ~
13226+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ (dec fuel) ids)
13227+ ?~ raw ~
13228+ =/ quant=(unit dgscan) (dg-scan-ids vars.sc ~ fuel.u.raw ids.u.raw)
13229+ ?~ quant ~
13230+ $(env t.env, fuel fuel.u.quant, ids ids.u.quant)
13231+::
13232+++ dg-next-id
13233+ |= [ids=(list @ud) largest=@ud]
13234+ ^- @ud
13235+ ?~ ids +(largest)
13236+ $(ids t.ids, largest (max largest i.ids))
13237+::
13238+++ dg-eligible-ctor
13239+ |= [e=expr head=itype actual=itype expected=itype state=istate]
13240+ ^- (unit dgo)
13241+ ?. ?=(%call -.e) ~
13242+ ?. ?=([* ~] args.e) ~
13243+ ?. ?=(%ctor -.i.args.e) ~
13244+ ?. ?=(%fn -.head) ~
13245+ ?. ?=(%fn -.expected) ~
13246+ ?. ?=(%tag -.actual) ~
13247+ ?. constructor.actual ~
13248+ ?. ?=(%var -.product.expected) ~
13249+ ?^ (itype-lookup id.product.expected sub.state) ~
13250+ =/ bounded=(unit dgscan) (dg-scan ~[sample.expected] sub.state 256 ~)
13251+ ?~ bounded ~
13252+ ?^ ids.u.bounded ~
13253+ `[[actual expected (span-of i.args.e) (span-of head.e)]]
13254+::
13255+:: Experimental per-module, source-derived recursive tree index.
13256+:: The two tags and the exact children/list/self layout are fixed-shape
13257+:: checks, so ordinary definitions incur no type-tree or source scans.
13258+++ grec-tagged-fields
13259+ |= sh=shape
13260+ ^- (unit [tag=@ fields=(list field)])
13261+ ?. ?=(%cell -.sh) ~
13262+ ?~ fields.sh ~
13263+ =/ head=field i.fields.sh
13264+ ?. ?=(%bare -.head) ~
13265+ ?. ?=(%const -.shape.head) ~
13266+ ?. &(?=(%term form.lit.shape.head) =(%tas aura.lit.shape.head)) ~
13267+ `[val.lit.shape.head t.fields.sh]
13268+++ grec-tree-children
13269+ |= [fs=(list field) param=@t]
13270+ ^- (unit field)
13271+ ?~ fs ~
13272+ ?~ t.fs `i.fs
13273+ ?^ t.t.fs ~
13274+ =/ event=field i.fs
13275+ =/ kids=field i.t.fs
13276+ ?. &(?=(%face -.event) ?=(%face -.kids)) ~
13277+ ?. !=(name.event name.kids) ~
13278+ ?. ?=(%fn -.shape.event) ~
13279+ ?. ?=(%aura -.sample.shape.event) ~
13280+ ?. =(%t aura.sample.shape.event) ~
13281+ ?. ?=(%tvar -.product.shape.event) ~
13282+ ?. =(param name.product.shape.event) ~
13283+ `kids
13284+::
13285+++ grec-tree-proof
13286+ |= [name=term sh=shape]
13287+ ^- ?
13288+ ?. ?=(%generic -.sh) |
13289+ ?. ?=([@ ~] vars.sh) |
13290+ =/ param=@t i.vars.sh
13291+ ?. ?=(%union -.body.sh) |
13292+ ?. ?=([* [* ~]] cases.body.sh) |
13293+ =/ a=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.cases.body.sh)
13294+ =/ b=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.t.cases.body.sh)
13295+ ?~ a |
13296+ ?~ b |
13297+ ?. !=(tag.u.a tag.u.b) |
13298+ ?. ?=([* ~] fields.u.a) |
13299+ =/ value=field i.fields.u.a
13300+ ?. ?=(%face -.value) |
13301+ ?. ?=(%aura -.shape.value) |
13302+ ?. =(%t aura.shape.value) |
13303+ =/ selected=(unit field) (grec-tree-children fields.u.b param)
13304+ ?~ selected |
13305+ =/ kids=field u.selected
13306+ ?. ?=(%face -.kids) |
13307+ ?. ?=(%apply -.shape.kids) |
13308+ ?. =(ref.shape.kids ~[%list]) |
13309+ ?. ?=([* ~] args.shape.kids) |
13310+ =/ self=shape i.args.shape.kids
13311+ ?. ?=(%apply -.self) |
13312+ ?. =(ref.self ~[name]) |
13313+ ?. ?=([* ~] args.self) |
13314+ ?. ?=(%tvar -.i.args.self) |
13315+ =(name.i.args.self param)
13316++$ grec-collected [molds=imolds proofs=(map term shape)]
13317+:: Experimental one-layer analysis view, never an exported mold identity.
13318+++ grec-unfold-view
13319+ |= [typ=itype fuel=@ud]
13320+ ^- (unit [view=itype left=@ud])
13321+ ?. ?=(%grec -.typ) ~
13322+ ?: =(fuel 0) ~
13323+ ?. ?=([* ~] args.typ) ~
13324+ =/ sh=shape proof.typ
13325+ ?. (grec-tree-proof name.typ sh) ~
13326+ ?> ?=(%generic -.sh)
13327+ ?> ?=([@ ~] vars.sh)
13328+ ?> ?=(%union -.body.sh)
13329+ ?> ?=([* [* ~]] cases.body.sh)
13330+ =/ ca=shape i.cases.body.sh
13331+ =/ cb=shape i.t.cases.body.sh
13332+ ?> ?=(%cell -.ca)
13333+ ?> ?=(%cell -.cb)
13334+ ?> ?=([* [* ~]] fields.ca)
13335+ ?> ?=([* *] fields.cb)
13336+ =/ tag-a=field i.fields.ca
13337+ =/ tag-b=field i.fields.cb
13338+ ?> ?=(%bare -.tag-a)
13339+ ?> ?=(%bare -.tag-b)
13340+ ?> ?=(%const -.shape.tag-a)
13341+ ?> ?=(%const -.shape.tag-b)
13342+ =/ text-field=field i.t.fields.ca
13343+ ?> ?=(%face -.text-field)
13344+ =/ branch=(list field) t.fields.cb
13345+ =/ kids=(unit field) (grec-tree-children branch i.vars.sh)
13346+ ?~ kids ~
13347+ ?> ?=(%face -.u.kids)
13348+ =/ children=itype [%face name.u.kids [%collection %list ~[typ]]]
13349+ ?> ?=(^ branch)
13350+ =/ payload=itype
13351+ ?~ t.branch children
13352+ =/ event=field i.branch
13353+ ?> ?=(%face -.event)
13354+ [%cell [%face name.event [%fn [%atom %t] i.args.typ]] children]
13355+ =/ leaf=itype [%cell [%const lit.shape.tag-a] [%face name.text-field [%atom %t]]]
13356+ =/ node=itype [%cell [%const lit.shape.tag-b] payload]
13357+ `[[%union ~[leaf node] ~ ~ ~] (dec fuel)]
13358+::
13359+++ grec-collect-molds
13360+ |= ds=(list def)
13361+ ^- grec-collected
13362+ ?~ ds [~ *(map term shape)]
13363+ =/ rest=grec-collected $(ds t.ds)
13364+ ?. ?=(%mold -.i.ds) rest
13365+ =/ name=term name.i.ds
13366+ =/ body=shape shape.i.ds
13367+ =/ proofs=(map term shape) proofs.rest
13368+ =? proofs (grec-tree-proof name body) (~(put by proofs) name body)
13369+ [[[name body] molds.rest] proofs]
13370+::
13371+
937713372--