@@ -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,18 +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 ~]
4669+ [%noun ~]
4670+ [%empty ~]
46114671 [%tag id=@ud literal=lit constructor=?]
46124672 [%const literal=lit]
46134673 [%collection name=term args=(list itype)]
46144674 [%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)]
46154677 [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t) args=(list itype)]
46164678 [%face name=term body=itype]
46174679 [%fn sample=itype product=itype]
@@ -4635,21 +4697,117 @@
46354697 %var
46364698 =/ found=(unit itype) (itype-lookup id.t sub)
46374699 ?~ found t
4700+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46384701 $(t u.found)
46394702 %avar
46404703 =/ found=(unit itype) (itype-lookup id.t sub)
46414704 ?~ 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
46424711 $(t u.found)
46434712 %nvar
46444713 =/ found=(unit itype) (itype-lookup id.t sub)
46454714 ?~ 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
46464721 $(t u.found)
46474722 %tag
46484723 =/ found=(unit itype) (itype-lookup id.t sub)
46494724 ?~ found t
4725+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46504726 $(t u.found)
46514727 ==
46524728::
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+::
46534811++ itype-occurs
46544812 |= [n=@ud t=itype sub=isub]
46554813 ^- ?
@@ -4657,14 +4815,20 @@
46574815 ?- -.t
46584816 %var =(n id.t)
46594817 %avar =(n id.t)
4818+ %rvar =(n id.t)
46604819 %nvar =(n id.t)
4820+ %rnvar =(n id.t)
46614821 %atom |
46624822 %any-atom |
46634823 %flag |
4824+ %noun |
4825+ %empty |
46644826 %tag =(n id.t)
46654827 %const |
46664828 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
46674829 %recursive |
4830+ %jrec |
4831+ %grec (lien args.t |=(c=itype (itype-occurs n c sub)))
46684832 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
46694833 %face $(t body.t)
46704834 %fn |($(t sample.t) $(t product.t))
@@ -4683,6 +4847,11 @@
46834847 =. a (itype-walk a sub)
46844848 =. b (itype-walk b sub)
46854849 ?: =(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 ~)
46864855 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
46874856 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
46884857 ?: &(?=(%union -.a) ?=(%union -.b))
@@ -4699,6 +4868,32 @@
46994868 ?: ?=(%var -.b)
47004869 ?: (itype-occurs id.b a sub) ~
47014870 `[[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]
47024897 :: The narrower decimal constraint survives a match with an atom
47034898 :: variable; decimal syntax alone does not make it a loobean.
47044899 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
@@ -4753,14 +4948,20 @@
47534948 ?- -.t
47544949 %var |
47554950 %avar |
4951+ %rvar |
47564952 %nvar |
4953+ %rnvar |
47574954 %atom |
47584955 %any-atom &
47594956 %flag |
4957+ %noun |
4958+ %empty |
47604959 %tag |
47614960 %const |
47624961 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
47634962 %recursive |
4963+ %jrec |
4964+ %grec (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47644965 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47654966 %face $(t body.t)
47664967 %fn |($(t sample.t) $(t product.t))
@@ -4823,14 +5024,20 @@
48235024 ?- -.typ
48245025 %var |
48255026 %avar |
5027+ %rvar |
48265028 %nvar |
5029+ %rnvar |
48275030 %atom &
48285031 %any-atom &
48295032 %flag &
5033+ %noun |
5034+ %empty |
48305035 %tag &
48315036 %const &
48325037 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
48335038 %recursive |
5039+ %jrec |
5040+ %grec (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48345041 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48355042 %face $(typ body.typ)
48365043 %fn |($(typ sample.typ) $(typ product.typ))
@@ -4859,6 +5066,7 @@
48595066 ^- ?
48605067 =. t (itype-walk t sub)
48615068 ?- -.t
5069+ %grec (lien args.t |=(c=itype (itype-has-face c sub)))
48625070 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
48635071 %face &
48645072 %cell |($(t hed.t) $(t tal.t))
@@ -4866,6 +5074,42 @@
48665074 * |
48675075 ==
48685076::
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+::
48695113++ itype-face-asym-collection-args
48705114 |= [as=(list itype) bs=(list itype) sub=isub]
48715115 ^- ?
@@ -4879,12 +5123,15 @@
48795123 ^- ?
48805124 =. a (itype-walk a sub)
48815125 =. 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)
48825129 ?: &(?=(%collection -.a) ?=(%collection -.b))
48835130 ?. =(name.a name.b) |
48845131 (itype-face-asym-collection-args args.a args.b sub)
48855132 ?: &(?=(%face -.a) ?=(%face -.b)) $(a body.a, b body.b)
4886− ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%nvar -.b))
4887− ?: ?=(%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)))
48885135 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
48895136 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
48905137 |
@@ -4907,6 +5154,30 @@
49075154 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
49085155 expected
49095156::
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+::
49105181++ itype-output-may-be-cell
49115182 |= [t=itype sub=isub]
49125183 ^- ?
@@ -4916,6 +5187,9 @@
49165187 %cell &
49175188 %union &
49185189 %recursive &
5190+ %jrec &
5191+ %grec &
5192+ %noun &
49195193 %collection &
49205194 %face $(t body.t)
49215195 %fn |($(t sample.t) $(t product.t))
@@ -4944,6 +5218,7 @@
49445218 ^- ?
49455219 ?- -.t
49465220 %tag &
5221+ %grec (lien args.t |=(c=itype (itype-has-tag c)))
49475222 %collection (lien args.t |=(c=itype (itype-has-tag c)))
49485223 %face $(t body.t)
49495224 %fn |($(t sample.t) $(t product.t))
@@ -4957,6 +5232,7 @@
49575232 ^- ?
49585233 ?- -.t
49595234 %union &
5235+ %grec (lien args.t |=(c=itype (itype-has-union c)))
49605236 %collection (lien args.t |=(c=itype (itype-has-union c)))
49615237 %face $(t body.t)
49625238 %fn |($(t sample.t) $(t product.t))
@@ -4975,6 +5251,7 @@
49755251 %union
49765252 ?: &(?=(~ label.t) ?=(^ args.t)) &
49775253 (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))))
49785255 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
49795256 %face $(t body.t)
49805257 %fn |($(t sample.t) $(t product.t))
@@ -4987,6 +5264,8 @@
49875264 ^- ?
49885265 ?- -.t
49895266 %recursive &
5267+ %jrec &
5268+ %grec &
49905269 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
49915270 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
49925271 %face $(t body.t)
@@ -5000,6 +5279,8 @@
50005279 ^- ?
50015280 ?- -.t
50025281 %recursive ?=(~ label.t)
5282+ %jrec ?=(~ label.t)
5283+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-recursive c))))
50035284 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
50045285 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
50055286 %face $(t body.t)
@@ -5027,34 +5308,107 @@
50275308 $(cases t.cases, good `trial)
50285309 ==
50295310::
5030−:: A constructor needs a case with its tag at the head and a payload
5031−:: compatible with the expected gate sample. Other case forms do not
5032−:: 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.
50335314::
50345315++ itype-fit-ctor-cases
50355316 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
50365317 ^- ifit
50375318 =/ found=(unit ifit) ~
5319+ =/ pending=? |
50385320 |-
5039− ?~ cases ?~(found [%bad ~] u.found)
5040− =/ 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 &)
50415331 ?. ?=(%cell -.c) $(cases t.cases)
5042− =/ 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 &)
50435344 ?. ?=(%const -.head) $(cases t.cases)
5044− ?. =(%term form.literal.head) $(cases t.cases)
50455345 ?. =(val.literal.head val.tag) $(cases t.cases)
5046− ?^ 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.
50475348 =/ trial=ifit (itype-fit sample tal.c sub next)
5048− $(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+ ==
50495356::
50505357++ itype-fit
50515358 |= [actual=itype expected=itype sub=isub next=@ud]
50525359 ^- 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))
50535379 =/ uncertain=?
5054− |(?=(%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)))
50555383 =. actual (itype-walk actual sub)
50565384 =. expected (itype-walk expected sub)
50575385 ?: =(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 ~]
5390+ :: Any value can be used where a noun is expected. An unresolved
5391+ :: bare tag is fixed as a constant; a constructor still needs a gate.
5392+ ?: ?=(%noun -.expected)
5393+ ?: ?=(%tag -.actual)
5394+ ?: constructor.actual [%unknown ~]
5395+ [%ok [[id.actual expected] sub] next]
5396+ [%ok sub next]
5397+ :: An arbitrary noun is not known to fit a narrower type.
5398+ ?: &(?=(%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 ~]
50585412 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
50595413 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
50605414 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
@@ -5066,12 +5420,21 @@
50665420 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
50675421 ?^ unified [%ok u.unified next]
50685422 [%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]
50695432 :: A concrete union value in a tuple may acquire the expected field's
50705433 :: face. A variable-bound union still needs face propagation support.
50715434 ?: &(!uncertain ?=(%union -.actual) ?=(%face -.expected))
50725435 $(expected body.expected)
50735436 ?: ?=(%union -.actual) [%unknown ~]
5074− ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
5437+ ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))) [%unknown ~]
50755438 ?: &(?=(%union -.expected) !?=(%var -.actual))
50765439 (itype-fit-cases actual cases.expected sub next)
50775440 ?: ?=(%tag -.actual)
@@ -5079,7 +5442,7 @@
50795442 =/ u=(unit isub) (itype-unify actual expected sub)
50805443 ?~ u [%bad ~]
50815444 [%ok u.u next]
5082− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5445+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
50835446 ?: ?=(%face -.expected) $(expected body.expected)
50845447 ?: constructor.actual
50855448 ?. ?=(%fn -.expected) [%bad ~]
@@ -5107,13 +5470,17 @@
51075470 =/ u=(unit isub) (itype-unify actual expected sub)
51085471 ?~ u [%bad ~]
51095472 [%ok u.u next]
5110− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5473+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51115474 ?: ?=(%face -.expected) $(expected body.expected)
51125475 ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
51135476 [%unknown ~]
51145477 ?: ?=(%const -.expected)
51155478 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
51165479 ?: ?=(%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 ~]
51175484 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
51185485 [%bad ~]
51195486 ?: ?=(%flag -.expected)
@@ -5121,8 +5488,14 @@
51215488 ?: ?=(%any-atom -.expected) [%ok sub next]
51225489 [%bad ~]
51235490 ?: &(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 |)
51245497 ?: ?=(%any-atom -.expected)
5125− ?: |(?=(%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]
51265499 ?: ?=(%var -.actual)
51275500 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
51285501 ?~ unified [%bad ~]
@@ -5133,16 +5506,16 @@
51335506 =/ unified=(unit isub) (itype-unify actual expected sub)
51345507 ?~ unified [%bad ~]
51355508 [%ok u.unified next]
5136− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5509+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51375510 [%bad ~]
51385511 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
51395512 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
51405513 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
51415514 [%bad ~]
51425515 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5143− =/ first=ifit $(actual hed.actual, expected hed.expected)
5516+ =/ first=ifit $(actual hed.actual, expected hed.expected, skip-width |, spine-proof |)
51445517 ?. ?=(%ok -.first) first
5145− $(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)
51465519 :: A field may add a face to an occurrence of the very same type
51475520 :: variable. Binding that variable to a face around itself would fail
51485521 :: the occurs check, but its underlying type has already matched.
@@ -5164,9 +5537,10 @@
51645537 [%ok u.unified next]
51655538 ?: &(?=(%face -.actual) ?=(%face -.expected))
51665539 ?. =(name.actual name.expected) [%bad ~]
5167− $(actual body.actual, expected body.expected)
5168− ?: ?=(%face -.actual) $(actual body.actual)
5169− ?: ?=(%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]
51705544 ?: (itype-face-asym actual expected sub) [%unknown ~]
51715545 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
51725546 [%unknown ~]
@@ -5242,7 +5616,18 @@
52425616+$ ischeme [typ=itype vars=(list @ud)]
52435617+$ ienv (list [name=term scheme=ischeme])
52445618+$ imold-types (list [name=term template=ischeme])
5245−+$ ifile [values=ienv molds=imold-types at=path]
5619++$ iderived [name=term agent=term mark=term]
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)]
52465631+$ ijimports (list [face=term interface=ifile])
52475632+$ icap [name=@t id=@ud at=span]
52485633+$ icaps (list icap)
@@ -5252,7 +5637,170 @@
52525637:: This core has no Ford dependencies; unrecognized payloads fail closed.
52535638+$ iexternals (list [module=term name=term result=*])
52545639+$ imark-externals (list [mark=term result=*])
5255−+$ 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)]
52565804+$ idiag [msg=tape sites=(list [at=span note=tape])]
52575805+$ iresult (each [typ=itype state=istate] idiag)
52585806+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5272,6 +5820,7 @@
52725820 |= [t=itype sub=isub]
52735821 ^- itype
52745822 =. t (itype-walk t sub)
5823+ ?: ?=(%grec -.t) t(args (turn args.t |=(c=itype (itype-normalize c sub))))
52755824 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
52765825 ?: ?=(%union -.t)
52775826 [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t (turn args.t |=(c=itype (itype-normalize c sub)))]
@@ -5288,6 +5837,8 @@
52885837:: generalize an aura from its sample, which requires constraint analysis
52895838:: beyond this fragment; leave those cases unresolved.
52905839::
5840+:: This helper only controls decimal defaulting in visible types. A noun
5841+:: may contain gates and is not proof of a gate-free value.
52915842++ itype-has-gate
52925843 |= t=itype
52935844 ^- ?
@@ -5295,6 +5846,8 @@
52955846 %fn &
52965847 %cell |($(t hed.t) $(t tal.t))
52975848 %recursive |
5849+ %jrec |
5850+ %grec &
52985851 %collection (lien args.t |=(c=itype (itype-has-gate c)))
52995852 %face $(t body.t)
53005853 %union (lien cases.t |=(c=itype (itype-has-gate c)))
@@ -5302,10 +5855,14 @@
53025855 %const |
53035856 %var |
53045857 %avar |
5858+ %rvar |
53055859 %nvar |
5860+ %rnvar |
53065861 %atom |
53075862 %any-atom |
53085863 %flag |
5864+ %noun |
5865+ %empty |
53095866 ==
53105867::
53115868++ default-decimals
@@ -5314,26 +5871,136 @@
53145871 ?: (itype-has-gate t) t
53155872 ?- -.t
53165873 %nvar [%atom %ud]
5874+ %rnvar [%atom %ud]
5875+ %grec t(args (turn args.t |=(c=itype (default-decimals c))))
53175876 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
53185877 %face [%face name.t $(t body.t)]
53195878 %cell [%cell $(t hed.t) $(t tal.t)]
53205879 * t
53215880 ==
53225881::
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+::
53235984++ itype-vars
53245985 |= t=itype
53255986 ^- (list @ud)
53265987 ?- -.t
53275988 %var ~[id.t]
53285989 %avar ~[id.t]
5990+ %rvar ~[id.t]
53295991 %nvar ~[id.t]
5992+ %rnvar ~[id.t]
53305993 %atom ~
53315994 %any-atom ~
53325995 %flag ~
5996+ %noun ~
5997+ %empty ~
53335998 %tag ~
53345999 %const ~
53356000 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
53366001 %recursive ~
6002+ %jrec ~
6003+ %grec (zing (turn args.t |=(c=itype (itype-vars c))))
53376004 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
53386005 %face $(t body.t)
53396006 %fn (weld $(t sample.t) $(t product.t))
@@ -5361,17 +6028,29 @@
53616028 =/ found=(unit itype) (itype-lookup id.t ren)
53626029 ?~ found t
53636030 u.found
6031+ %rvar
6032+ =/ found=(unit itype) (itype-lookup id.t ren)
6033+ ?~ found t
6034+ u.found
53646035 %nvar
53656036 =/ found=(unit itype) (itype-lookup id.t ren)
53666037 ?~ found t
53676038 u.found
6039+ %rnvar
6040+ =/ found=(unit itype) (itype-lookup id.t ren)
6041+ ?~ found t
6042+ u.found
53686043 %atom t
53696044 %any-atom t
53706045 %flag t
6046+ %noun t
6047+ %empty t
53716048 %tag t
53726049 %const t
53736050 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
53746051 %recursive t
6052+ %jrec t
6053+ %grec t(args (turn args.t |=(c=itype (itype-rename c ren))))
53756054 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
53766055 %face [%face name.t $(t body.t)]
53776056 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5387,19 +6066,50 @@
53876066 ?- -.t
53886067 %var |
53896068 %avar =(n id.t)
6069+ %rvar =(n id.t)
53906070 %nvar =(n id.t)
6071+ %rnvar =(n id.t)
53916072 %atom |
53926073 %any-atom |
53936074 %flag |
6075+ %noun |
6076+ %empty |
53946077 %tag |
53956078 %const |
53966079 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
53976080 %recursive |
6081+ %jrec |
6082+ %grec (lien args.t |=(c=itype (itype-var-is-atom n c)))
53986083 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
53996084 %face $(t body.t)
54006085 %fn |($(t sample.t) $(t product.t))
54016086 %cell |($(t hed.t) $(t tal.t))
54026087 ==
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+ ==
54036113::
54046114:: Canonical numbering makes printed variables independent of the order
54056115:: the unifier happened to allocate intermediates.
@@ -5411,7 +6121,7 @@
54116121 =/ n=@ud 0
54126122 |-
54136123 ?~ vars (itype-rename t ren)
5414− =/ 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]))
54156125 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
54166126::
54176127++ instantiate-scheme
@@ -5422,11 +6132,11 @@
54226132 |-
54236133 ?~ vars [(itype-rename typ.scheme ren) state]
54246134 =/ replacement=itype
5425− ?:((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]))
54266136 :: A generalized atom variable is a valid origin for re-generalizing
54276137 :: an alias, just as a sample binder is.
54286138 =/ st=istate state(next +(next.state))
5429− =? binders.st ?=(%avar -.replacement) [next.state binders.state]
6139+ =? binders.st |(?=(%avar -.replacement) ?=(%rvar -.replacement)) [next.state binders.state]
54306140 $(vars t.vars, ren [[i.vars replacement] ren], state st)
54316141::
54326142++ icap-lookup
@@ -5497,6 +6207,11 @@
54976207 ?. ?=([%ref @ @] node) ~
54986208 ?. &(=(module +<.node) =(name +>.node)) ~
54996209 `[[%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]
55006215 %face
55016216 ?. ?=([%face @ *] node) ~
55026217 ?. (jibb-face-name +<.node) ~
@@ -5551,6 +6266,10 @@
55516266 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
55526267 %fork (imported-faces-valid-list +.node)
55536268 %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)
55546273 ==
55556274::
55566275++ imported-faces-valid-list
@@ -5582,7 +6301,14 @@
55826301 ^- (unit itype)
55836302 ?@ node ~
55846303 ?+ -.node ~
6304+ %noun ?:(=(node [%noun ~]) `[%noun ~] ~)
55856305 %atom
6306+ :: A Hoon loobean singleton is one of the two Jibb loobeans.
6307+ ?: ?=([%atom %f [~ @]] node)
6308+ =/ value=@ +>+.node
6309+ ?. |(=(value 0) =(value 1)) ~
6310+ =/ printed=@t ?:(=(value 0) '%.y' '%.n')
6311+ `[%const [%loobean %f value printed]]
55866312 :: Hoon's null singleton is the same noun as Jibb's `~` mold.
55876313 :: Other non-term singleton atoms remain unsupported here.
55886314 ?: ?=([%atom %n [~ @]] node)
@@ -5597,6 +6323,15 @@
55976323 =/ aura=@ta (@ta +<.node)
55986324 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
55996325 `[%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)}")]
56006335 %apply
56016336 ?. ?=([%apply @ *] node) ~
56026337 =/ name=term (@tas +<.node)
@@ -5610,10 +6345,15 @@
56106345 ?. =(arity (lent u.args)) ~
56116346 `[%collection name u.args]
56126347 %fork
5613− =/ cases=(unit (list itype)) (import-to-itypes +.node)
6348+ :: Hoon's ordinary ? mold is the fork of its two %f singletons.
6349+ =/ raw=* +.node
6350+ ?: |(=(raw ~[[%atom %f `0] [%atom %f `1]]) =(raw ~[[%atom %f `1] [%atom %f `0]]))
6351+ `[%flag ~]
6352+ =/ cases=(unit (list itype)) (import-to-itypes raw)
56146353 ?~ cases ~
56156354 ?~ u.cases ~
56166355 ?~ t.u.cases ~
6356+ ?: (import-has-loobean-singleton u.cases) ~
56176357 ?. (import-cases-disjoint u.cases) ~
56186358 `[%union u.cases ~ ~ ~]
56196359 %face
@@ -5632,6 +6372,20 @@
56326372 `[%cell u.left u.right]
56336373 ==
56346374::
6375+++ import-direct-loobean
6376+ |= t=itype
6377+ ^- ?
6378+ ?: ?=(%face -.t) $(t body.t)
6379+ ?: ?=(%union -.t) (import-has-loobean-singleton cases.t)
6380+ ?=([%const [%loobean *]] t)
6381+::
6382+++ import-has-loobean-singleton
6383+ |= cases=(list itype)
6384+ ^- ?
6385+ ?~ cases |
6386+ ?: (import-direct-loobean i.cases) &
6387+ $(cases t.cases)
6388+::
56356389++ import-to-itypes
56366390 |= nodes=*
56376391 ^- (unit (list itype))
@@ -5646,7 +6400,10 @@
56466400 |= typ=itype
56476401 ^- upat
56486402 ?- -.typ
6403+ %noun [%all ~]
6404+ %empty [%empty ~]
56496405 %atom [%atom ~]
6406+ %flag [%or ~[[%atom `0] [%atom `1]]]
56506407 %const [%atom `val.literal.typ]
56516408 %face $(typ body.typ)
56526409 %cell [%cell $(typ hed.typ) $(typ tal.typ)]
@@ -5741,25 +6498,85 @@
57416498 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
57426499 $(molds t.molds)
57436500::
5744−:: Only names exported by this directly imported module are visible through
5745−:: its face. Other origins retain identity but print as unnamed unions.
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)
6514+++ prelude-union-alias
6515+ |= [origin=[at=path name=term] args=(list itype) molds=imold-types]
6516+ ^- (unit term)
6517+ ?~ molds ~
6518+ =/ template=ischeme template.i.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
6526+ $(molds t.molds)
6527+::
6528+:: Names exported by the directly imported module are visible through its
6529+:: face; a matching prelude alias is also visible without a qualifier.
6530+::
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
57466548::
57476549++ itype-in-import
5748− |= [t=itype iface=ifile face=term]
6550+ |= [t=itype iface=ifile face=term prelude=(unit ifile)]
57496551 ^- itype
57506552 ?- -.t
57516553 %union
57526554 =/ label=(unit @t)
57536555 ?~ origin.t ~
57546556 ?: =(at.u.origin.t /lib/jibb/prelude/jibb) `name.u.origin.t
6557+ =/ public=(unit term)
6558+ ?~ prelude ~
6559+ (prelude-union-alias u.origin.t args.t molds.u.prelude)
6560+ ?^ public `u.public
57556561 =/ alias=(unit term) ~
57566562 =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
57576563 =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
57586564 ?~ alias ~
57596565 `(crip "{(trip u.alias)}.{(trip face)}")
5760− [%union (turn cases.t |=(c=itype (itype-in-import c iface face))) origin.t label (turn args.t |=(c=itype (itype-in-import c iface face)))]
6566+ [%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)))]
57616567 %recursive [%recursive module.t name.t ~]
5762− %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face)))]
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)}"))
6579+ %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
57636580 %face [%face name.t $(t body.t)]
57646581 %fn [%fn $(t sample.t) $(t product.t)]
57656582 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5832,9 +6649,66 @@
58326649 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
58336650 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
58346651::
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+
58356701++ infer-mold-template
58366702 |= [sh=shape state=istate]
58376703 ^- (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]
58386712 ?: ?=(%generic -.sh)
58396713 ?~ vars.sh ~
58406714 ?. (distinct-params vars.sh) ~
@@ -5842,17 +6716,19 @@
58426716 =/ out=(unit [typ=itype state=istate])
58436717 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
58446718 ?~ out ~
6719+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58456720 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
58466721 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
58476722 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
58486723 =/ used=(list @ud) (itype-vars typ.u.out)
58496724 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
5850− `[[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)]
58516726 =/ out=(unit [typ=itype state=istate])
58526727 (infer-simple-shape sh state(params ~, in-mold &))
58536728 ?~ out ~
6729+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58546730 ?: ?=(^ (itype-vars typ.u.out)) ~
5855− `[[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)]
58566732::
58576733:: A direct imported reference may carry definite reader evidence. Only
58586734:: uniquely supplied, declared inputs are used; unsupported data stay generic.
@@ -5886,7 +6762,7 @@
58866762 ?~ found ~
58876763 ?^ t.found ~
58886764 result.i.found
5889− ?. ?=([%invalid ?(%aura %core) @] raw) ~
6765+ ?. ?=([%invalid ?(%aura %core %overlap) @] raw) ~
58906766 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
58916767::
58926768:: Replay only the shape branches whose evaluation order we can prove.
@@ -5955,16 +6831,24 @@
59556831 |= [sh=shape state=istate]
59566832 ^- (unit [typ=itype state=istate])
59576833 ?- -.sh
6834+ %hole `[[%var next.state] state(next +(next.state), holes [[next.state at.sh] holes.state])]
59586835 %aura
59596836 ?: =(0 aura.sh) `[[%any-atom ~] state]
59606837 `[[%atom aura.sh] state]
59616838 %flag `[[%flag ~] state]
6839+ %noun `[[%noun ~] state]
6840+ %void `[[%empty ~] state]
59626841 %const
5963− ?. |(=(%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))) ~
59646844 `[[%const lit.sh] state]
59656845 %union
59666846 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
5967− ?. (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 ~
59686852 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
59696853 ?~ cs ~
59706854 `[[%union types.u.cs ~ ~ ~] state.u.cs]
@@ -5985,7 +6869,7 @@
59856869 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
59866870 ?~ found ~
59876871 ?^ vars.u.found ~
5988− `[(itype-in-import typ.u.found u.iface i.t.names.sh) state]
6872+ `[(itype-in-import typ.u.found u.iface i.t.names.sh prelude.state) state]
59896873 =/ found=(unit itype)
59906874 (find-imported-mold i.t.names.sh n externals.state surs.state)
59916875 ?~ found ~
@@ -6004,10 +6888,13 @@
60046888 ?~ prelude-entry ~
60056889 ?^ vars.u.prelude-entry ~
60066890 `[typ.u.prelude-entry state]
6891+ =/ direct=(unit itype) (simple-source-recursive n u.found state)
6892+ ?^ direct `[u.direct state]
60076893 =/ out=(unit [typ=itype state=istate])
60086894 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
60096895 ?~ out ~
6010− `[(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)]
60116898 %apply
60126899 ?~ ref.sh ~
60136900 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
@@ -6022,7 +6909,7 @@
60226909 ?~ vars.u.template ~
60236910 =/ applied=(unit itype) (template-apply u.template types.u.args)
60246911 ?~ applied ~
6025− `[(itype-in-import u.applied u.iface i.t.ref.sh) state.u.args]
6912+ `[(itype-in-import u.applied u.iface i.t.ref.sh prelude.state.u.args) state.u.args]
60266913 ?: (lien active.state.u.args |=(x=term =(x n))) ~
60276914 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
60286915 ?~ found
@@ -6035,17 +6922,20 @@
60356922 ?~ applied ~
60366923 `[u.applied state.u.args]
60376924 ?. ?=(%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]
60386927 ?. (distinct-params vars.u.found) ~
60396928 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
60406929 ?~ params ~
60416930 =/ out=(unit [typ=itype state=istate])
60426931 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
60436932 ?~ out ~
6933+ ?^ (unresolved-hole holes.state.u.out holes.state.u.args state.u.out) ~
60446934 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
60456935 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
60466936 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
60476937 (label-direct-union typ.u.out(args types.u.args) u.found n state.u.args)
6048− `[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)]
60496939 %tvar
60506940 =/ param=(unit itype) (iparam-lookup name.sh params.state)
60516941 ?^ param `[u.param state]
@@ -6085,12 +6975,12 @@
60856975 ^- isample-result
60866976 ?- -.s
60876977 %bind
6088− ?: |(?=(^ (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))))
60896979 [%| "sample shadows a name"]
60906980 =/ t=itype [%var next.state]
60916981 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
60926982 %face
6093− ?: |(?=(^ (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))))
60946984 [%| "sample shadows a name"]
60956985 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
60966986 ?~ t [%| "sample mold is not supported by partial inference"]
@@ -6158,6 +7048,7 @@
61587048 |-
61597049 ?~ ds &
61607050 ?: ?=(%mold -.i.ds) $(ds t.ds)
7051+ ?: =(name.i.ds %proj) |
61617052 ?. (unique-value-name name.i.ds names) |
61627053 ?: ?=(^ (ienv-lookup name.i.ds env)) |
61637054 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
@@ -6181,6 +7072,7 @@
61817072 |-
61827073 ?~ locals &
61837074 =/ n=term name.i.locals
7075+ ?: =(n %proj) |
61847076 ?. (unique-value-name n names) |
61857077 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
61867078 ?: (lien marks.state |=(m=term =(n m))) |
@@ -6360,6 +7252,11 @@
63607252 =/ retried=? ?=(%| -.inferred)
63617253 =? inferred retried (infer-recursive-gate d env local-state)
63627254 ?: ?=(%| -.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]
63637260 =/ merged=(unit [first=icap second=icap])
63647261 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
63657262 ?^ merged
@@ -6375,7 +7272,7 @@
63757272 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
63767273 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
63777274 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
6378− $(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 &)
63797276::
63807277:: Try complete cyclic local groups after individual definitions stall.
63817278:: Components with non-gates or unresolved constraints stay unavailable.
@@ -6419,17 +7316,29 @@
64197316 ^- iresult
64207317 =/ reverse=(list term) (flop names)
64217318 ?~ reverse [%| ["empty wing" ~]]
6422− =/ scheme=(unit ischeme) (ienv-lookup i.reverse env)
6423− ?~ scheme [%| ["field access is not supported by partial inference" ~]]
6424− =/ inst=[typ=itype state=istate] (instantiate-scheme u.scheme state)
7319+ =/ iface=(unit ifile) (find-jibb-interface i.reverse jimports.state)
64257320 =/ fields=(list term) t.reverse
7321+ ?~ fields [%| ["field access is not supported by partial inference" ~]]
7322+ =/ scheme=(unit ischeme)
7323+ ?~ iface
7324+ (ienv-lookup i.reverse env)
7325+ (ienv-lookup i.fields values.u.iface)
7326+ ?~ scheme
7327+ ?^ iface [%| ["module member is not available to partial inference" ~]]
7328+ [%| ["field access is not supported by partial inference" ~]]
7329+ =/ inst=[typ=itype state=istate]
7330+ ?~ iface (instantiate-scheme u.scheme state)
7331+ =/ imported=ischeme u.scheme
7332+ =. typ.imported (itype-in-import typ.imported u.iface i.reverse prelude.state)
7333+ (instantiate-scheme imported state)
7334+ =/ remaining=(list term) ?~(iface fields t.fields)
64267335 =/ typ=itype typ.inst
64277336 |-
6428− ?~ fields [%& typ state.inst]
6429− =/ found=(list itype) (record-fields-named i.fields typ sub.state.inst)
7337+ ?~ remaining [%& typ state.inst]
7338+ =/ found=(list itype) (record-fields-named i.remaining typ sub.state.inst)
64307339 ?~ found [%| ["field is not available to partial inference" ~]]
64317340 ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
6432− $(fields t.fields, typ i.found)
7341+ $(remaining t.remaining, typ i.found)
64337342::
64347343:: Propagate a known union or list through supported loobean, unit and list
64357344:: branches. Empty bodies and groups are transparent; bodies with definitions
@@ -6453,6 +7362,8 @@
64537362 ?: &(?=(%collection -.expected) =(%list name.expected) (context-list-expression e))
64547363 (infer-list-context e expected env state context)
64557364 ?: ?=(%branch -.e)
7365+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[expected context])
7366+ ?^ empty-list u.empty-list
64567367 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
64577368 ?~ t.arms.e [%| ["branch pattern is not supported by partial inference" ~]]
64587369 ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -6484,6 +7395,7 @@
64847395 ?: ?=(%unknown -.fit)
64857396 ?: &(?=(%collection -.expected) =(%list name.expected))
64867397 [%| ["branch list constraint is not supported by partial inference" ~]]
7398+ ?: ?=(%flag -.expected) [%| ["branch loobean constraint is not supported by partial inference" ~]]
64877399 [%| ["branch union constraint is not supported by partial inference" ~]]
64887400 ?: ?=(%bad -.fit)
64897401 =/ missing=(unit idiag) (missing-union-tag e expected sub.state.p.value context)
@@ -6492,6 +7404,8 @@
64927404 ?^ nested [%| u.nested]
64937405 ?: &(?=(%collection -.expected) =(%list name.expected))
64947406 [%| ["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"]]]]
64957409 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
64967410 [%& expected state.p.value(sub sub.fit, next next.fit)]
64977411::
@@ -6667,6 +7581,11 @@
66677581 [%| ["list pattern needs the standard prelude in partial inference" ~]]
66687582 ?~ args.typ [%| ["list pattern is not supported by partial inference" ~]]
66697583 ?^ 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" ~]]
66707589 ?~ arms.e [%| ["list branch is not supported by partial inference" ~]]
66717590 ?~ t.arms.e [%| ["list branch is not supported by partial inference" ~]]
66727591 ?^ t.t.arms.e [%| ["list branch is not supported by partial inference" ~]]
@@ -6679,7 +7598,7 @@
66797598 [%| ["list branch pattern is not supported by partial inference" ~]]
66807599 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
66817600 ?~ binder [%| ["list branch pattern is not supported by partial inference" ~]]
6682− ?: |(=(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)))))
66837602 [%| ["pattern binder shadows a name" ~]]
66847603 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
66857604 =/ left=iresult
@@ -6716,10 +7635,15 @@
67167635 [%| ["unit branch pattern is not supported by partial inference" ~]]
67177636 =/ binder=(unit term) ?:(first-empty second-name first-name)
67187637 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
6719− ?: |(?=(^ (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))))
67207639 [%| ["pattern binder shadows a name" ~]]
67217640 =/ payload=(unit itype) (unit-union-payload typ)
67227641 ?~ 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" ~]]
67237647 =/ extended=ienv [[u.binder [u.payload ~]] env]
67247648 =/ left=iresult
67257649 ?~ expected (infer-fragment val.x ?:(first-empty env extended) state.p.subject)
@@ -6748,12 +7672,14 @@
67487672 =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
67497673 ?: |(?=(%atom -.t) ?=(%any-atom -.t))
67507674 $(ps t.ps, state state.p.item)
6751− ?: &(?=(%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))
67527676 $(ps t.ps, state state.p.item)
67537677 ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
67547678 $(ps t.ps, state state.p.item)
67557679 ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
67567680 [%| ["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"]]]]
67577683 ?: ?=(%cell -.t)
67587684 [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
67597685 [%| ["interpolation type needs unsupported inference" ~]]
@@ -6816,7 +7742,7 @@
68167742 ^- (unit ienv)
68177743 =. t ?:(?=(%face -.t) body.t t)
68187744 ?: ?=(%bind -.p)
6819− ?: |(?=(^ (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)))) ~
68207746 `[[name.p [t ~]] env]
68217747 ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
68227748 `env
@@ -6864,14 +7790,15 @@
68647790 $(xs t.xs, out (weld out rows), origin +(origin))
68657791::
68667792++ infer-known-union-whole
6867− |= [e=expr env=ienv state=istate]
7793+ |= [e=expr env=ienv subject=iresult]
68687794 ^- (unit iresult)
68697795 ?> ?=(%branch -.e)
6870− =/ subject=iresult (infer-fragment subject.e env state)
68717796 ?: ?=(%| -.subject) `subject
68727797 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
68737798 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
6874− =/ 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
68757802 =/ remaining=(list itype) cases
68767803 =/ arms=(list arm) arms.e
68777804 =/ st=istate state.p.subject
@@ -6901,15 +7828,16 @@
69017828 ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
69027829 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
69037830::
6904−++ infer-known-union-context
6905− |= [e=expr expected=itype env=ienv state=istate context=span]
6906− ^- iresult
7831+++ infer-known-union-context-whole
7832+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
7833+ ^- (unit iresult)
69077834 ?> ?=(%branch -.e)
6908− =/ subject=iresult (infer-fragment subject.e env state)
6909− ?: ?=(%| -.subject) subject
7835+ ?: ?=(%| -.subject) `subject
69107836 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
6911− ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
6912− =/ cases=(list itype) cases.typ
7837+ ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
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
69137841 =/ remaining=(list itype) cases
69147842 =/ arms=(list arm) arms.e
69157843 =/ st=istate state.p.subject
@@ -6917,44 +7845,45 @@
69177845 |-
69187846 ?~ arms
69197847 ?^ remaining
6920− [%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
6921− ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
6922− [%& expected st]
7848+ `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
7849+ ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
7850+ `[%& expected st]
69237851 =/ a=arm i.arms
69247852 ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
6925− [%| ["partial union pattern is not supported by partial inference" ~]]
7853+ ~
69267854 =/ matching=(list itype) (skim remaining |=(c=itype =(%full (union-pattern pat.a c))))
69277855 ?~ matching
69287856 ?: (lien cases |=(c=itype =(%full (union-pattern pat.a c))))
6929− [%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
6930− [%| ["union pattern is not supported by partial inference" ~]]
7857+ `[%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
7858+ `[%| ["union pattern is not supported by partial inference" ~]]
69317859 ?: &(?=(^ t.matching) (union-pattern-has-bind pat.a))
6932− [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
7860+ `[%| ["a union pattern binding several cases is not supported by partial inference" ~]]
69337861 =/ bound=(unit ienv) (union-pattern-bind pat.a i.matching env globals.st)
6934− ?~ bound [%| ["pattern binder shadows a name" ~]]
7862+ ?~ bound `[%| ["pattern binder shadows a name" ~]]
69357863 =/ body=iresult (infer-call-context-arg val.a expected u.bound st context)
6936− ?: ?=(%| -.body) body
7864+ ?: ?=(%| -.body) `body
69377865 =/ fit=ifit (itype-fit typ.p.body expected sub.state.p.body next.state.p.body)
6938− ?: ?=(%unknown -.fit) [%| ["union branch result constraint is not supported by partial inference" ~]]
7866+ ?: ?=(%unknown -.fit) `[%| ["union branch result constraint is not supported by partial inference" ~]]
69397867 ?: ?=(%bad -.fit)
69407868 =/ missing=(unit idiag) (missing-union-tag val.a expected sub.state.p.body context)
6941− ?^ missing [%| u.missing]
7869+ ?^ missing `[%| u.missing]
69427870 =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body expected sub.state.p.body next.state.p.body context)
6943− ?^ nested [%| u.nested]
6944− [%| ["union branch arm does not fit its expected type" ~[[context "expected type"] [(span-of val.a) "branch arm"]]]]
7871+ ?^ nested `[%| u.nested]
7872+ `[%| ["union branch arm does not fit its expected type" ~[[context "expected type"] [(span-of val.a) "branch arm"]]]]
69457873 ?: (itype-has-tag (itype-normalize expected sub.fit))
6946− [%| ["union branch result needs context in partial inference" ~]]
7874+ `[%| ["union branch result needs context in partial inference" ~]]
69477875 $(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)
69487876::
69497877++ infer-known-union-finite
6950− |= [e=expr env=ienv state=istate]
7878+ |= [e=expr env=ienv subject=iresult expected=(unit [typ=itype context=span])]
69517879 ^- iresult
69527880 ?> ?=(%branch -.e)
6953− =/ subject=iresult (infer-fragment subject.e env state)
69547881 ?: ?=(%| -.subject) subject
69557882 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
69567883 ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
6957− =/ 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)
69587887 ?~ expanded [%| ["union pattern expansion needs unsupported inference" ~]]
69597888 =/ cases=(list ifinite) u.expanded
69607889 =/ remaining=(list ifinite) cases
@@ -6966,7 +7895,8 @@
69667895 ?^ remaining
69677896 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
69687897 ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
6969− [%& u.answer st]
7898+ ?~ expected [%& u.answer st]
7899+ [%& typ.u.expected st]
69707900 =/ a=arm i.arms
69717901 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
69727902 [%| ["partial union pattern is not supported by partial inference" ~]]
@@ -6979,30 +7909,289 @@
69797909 [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
69807910 =/ bound=(unit ienv) (union-pattern-bind pat.a base.i.matching env globals.st)
69817911 ?~ bound [%| ["pattern binder shadows a name" ~]]
6982− =/ body=iresult (infer-fragment val.a u.bound st)
7912+ =/ body=iresult
7913+ ?~ expected (infer-fragment val.a u.bound st)
7914+ (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
69837915 ?: ?=(%| -.body) body
7916+ ?^ expected
7917+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7918+ ?: ?=(%unknown -.fit) [%| ["union branch result constraint is not supported by partial inference" ~]]
7919+ ?: ?=(%bad -.fit)
7920+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7921+ ?^ missing [%| u.missing]
7922+ =/ 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)
7923+ ?^ nested [%| u.nested]
7924+ [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7925+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7926+ [%| ["union branch result needs context in partial inference" ~]]
7927+ $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body(sub sub.fit, next next.fit), answer `typ.u.expected)
69847928 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
69857929 =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
69867930 ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
69877931 $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
69887932::
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
8053+ |= [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]
8064+ ^- iresult
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 ~)
8069+ u.whole
8070+::
69898071++ infer-known-union-branch
69908072 |= [e=expr env=ienv state=istate]
69918073 ^- iresult
6992− =/ whole=(unit iresult) (infer-known-union-whole e env state)
6993− ?~ whole (infer-known-union-finite e env state)
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]
8079+ ^- iresult
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])
69948084 u.whole
69958085::
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+::
69968126++ known-union-subject
69978127 |= [e=expr env=ienv state=istate]
6998− ^- (unit itype)
6999− ?. ?=(%wing -.e) ~
8128+ ^- (unit iresult)
8129+ ?. (safe-union-subject e) ~
70008130 =/ 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)
70018159 ?: ?=(%| -.subject) ~
70028160 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7003− ?. ?=(%union -.typ) ~
7004− `typ
7005−::
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)
8181+ ?. ?=(%wing -.e) ~
8182+ ?. ?=([@ ~] names.e) ~
8183+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8184+ ?~ scheme ~
8185+ ?. (contextual-direct-union typ.u.scheme) ~
8186+ =/ subject=iresult (infer-fragment e env state)
8187+ ?: ?=(%| -.subject) ~
8188+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8189+ ?. ?=(%union -.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
8194+::
70068195:: Infer changes only against a fully known record spine. Retain the
70078196:: target type; unknown spines and repeated edits remain unsupported.
70088197++ change-spine-known
@@ -7108,7 +8297,7 @@
71088297 |= [e=expr actual=itype expected=itype sub=isub next=@ud context=span]
71098298 ^- (unit idiag)
71108299 =/ original=[left=itype right=itype] [actual expected]
7111− ?: |(?=(%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))) ~
71128301 =/ fit=ifit (itype-fit actual expected sub next)
71138302 ?. ?=(%bad -.fit) ~
71148303 =. actual (itype-walk actual sub)
@@ -7129,7 +8318,7 @@
71298318 ?~ items ~
71308319 ?~ t.items (nested-missing-tag val.i.items actual expected sub next context)
71318320 =/ original=[left=itype right=itype] [actual expected]
7132− ?: |(?=(%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))) ~
71338322 =. actual (itype-walk actual sub)
71348323 =. expected (itype-walk expected sub)
71358324 ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
@@ -7139,10 +8328,30 @@
71398328 ?. ?=(%ok -.first) ~
71408329 $(items t.items, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
71418330::
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+::
71428350++ infer-fragment
71438351 |= [e=expr env=ienv state=istate]
71448352 ^- iresult
71458353 ?- -.e
8354+ %pair $(e (pair-as-cell e))
71468355 %lit
71478356 ?- form.lit.e
71488357 %number ?: =(%ud aura.lit.e)
@@ -7180,6 +8389,21 @@
71808389 ?: ?=(%| -.result) result
71818390 [%& [%collection %list ~[element]] state.p.result]
71828391 %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)]
71838407 %wing
71848408 ?~ names.e [%| ["empty wing" ~]]
71858409 ?^ t.names.e
@@ -7188,7 +8412,7 @@
71888412 ?~ iface (infer-field-wing names.e env state)
71898413 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
71908414 ?~ member [%| ["module member is not available to partial inference" ~]]
7191− =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e)
8415+ =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e prelude.state)
71928416 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
71938417 [%& typ.instance state.instance]
71948418 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
@@ -7211,7 +8435,10 @@
72118435 =/ traced=iresult $(e val.e)
72128436 ?: ?=(%| -.traced) traced
72138437 $(e then.e, state state.p.traced)
7214− %tuple (infer-simple-items items.e env state)
8438+ %tuple
8439+ ?: &(?=(^ defer.state) ?=(^ prelude.state))
8440+ (dg-infer-tuple-items items.e env state)
8441+ (infer-simple-items items.e env state)
72158442 %body
72168443 ?~ defs.e $(e final.e)
72178444 =/ local-names=(list term) (global-value-names defs.e)
@@ -7222,6 +8449,9 @@
72228449 [%| ["local molds shadow a name" ~]]
72238450 =/ local-state=istate
72248451 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8452+ =/ mold-hole=(unit span) (simple-local-mold-hole defs.e)
8453+ ?^ mold-hole
8454+ [%| ["type hole needs a determined type" ~[[u.mold-hole "unresolved type hole"]]]]
72258455 ?. (local-molds-supported local-molds local-state)
72268456 [%| ["local molds need unsupported inference" ~]]
72278457 =/ values=(list def) (local-value-defs defs.e)
@@ -7231,12 +8461,22 @@
72318461 ?: ?=(%| -.result) result
72328462 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
72338463 %branch
8464+ ?^ defer.state (dg-boolean-branch e env state)
72348465 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
7235− ?~ t.arms.e (infer-cell-branch e env state)
8466+ ?~ t.arms.e
8467+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state ~)
8468+ ?^ empty-list u.empty-list
8469+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
8470+ ?^ empty-union (infer-known-union-branch-subject e env u.empty-union)
8471+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8472+ ?^ single (infer-known-union-branch-subject e env u.single)
8473+ ?: (single-structured-pattern e) (infer-single-case-branch e env state ~)
8474+ (infer-cell-branch e env state ~)
72368475 ?^ t.t.arms.e (infer-known-union-branch e env state)
7237− =/ known=(unit itype) (known-union-subject subject.e env state)
7238− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
7239− (infer-known-union-branch e env state)
8476+ =/ known=(unit iresult) (known-union-subject subject.e env state)
8477+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
8478+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
8479+ (infer-known-union-branch-subject e env u.known)
72408480 =/ x=arm i.arms.e
72418481 =/ y=arm i.t.arms.e
72428482 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
@@ -7245,7 +8485,7 @@
72458485 ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
72468486 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
72478487 (infer-known-union-branch e env state)
7248− ?^ known (infer-known-union-branch e env state)
8488+ ?: &(?=(^ known) ?=(%& -.u.known)) (infer-known-union-branch-subject e env u.known)
72498489 ?: =(val.lit.pat.x val.lit.pat.y)
72508490 [%| ["branch does not cover both loobeans" ~]]
72518491 =/ subject=iresult $(e subject.e)
@@ -7286,6 +8526,9 @@
72868526 =/ value=iresult
72878527 (infer-call-context-arg val.e typ.u.target env state.u.target at.shape.e)
72888528 ?: ?=(%| -.value) value
8529+ =/ shape=(unit [source=iwfields target=iwfields])
8530+ (width-shape typ.p.value typ.u.target sub.state.p.value)
8531+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
72898532 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
72908533 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
72918534 ?: ?=(%bad -.fit)
@@ -7294,6 +8537,8 @@
72948537 =/ 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)
72958538 ?^ nested [%| u.nested]
72968539 [%| ["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)]]]]
8540+ ?: &(?=(^ defer.state.p.value) !(dg-stable-fit typ.p.value typ.u.target sub.fit))
8541+ [%| ["deferred cast fit needs stable inference" ~]]
72978542 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
72988543 [%& merged state.p.value(sub sub.fit, next next.fit)]
72998544 %crash [%& [%var next.state] state(next +(next.state))]
@@ -7317,45 +8562,9 @@
73178562 [%& [%fn typ.p.sam typ.p.body] state.p.body]
73188563 %call
73198564 ?~ args.e [%| ["call has no argument" ~]]
7320− =/ head=iresult $(e head.e)
7321− ?: ?=(%| -.head) head
7322− =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
7323− =/ arg=iresult
7324− ?^ t.args.e
7325− ?: ?=(%fn -.head-type)
7326− (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
7327− (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
7328− ?: ?=(%fn -.head-type)
7329− (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
7330− $(e i.args.e, state state.p.head)
7331− ?: ?=(%| -.arg) arg
7332− =/ st=istate state.p.arg
7333− =/ ht=itype (itype-walk typ.p.head sub.st)
7334− ?: ?=(%fn -.ht)
7335− =/ fit=ifit (itype-fit typ.p.arg sample.ht sub.st next.st)
7336− ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
7337− ?: ?=(%bad -.fit)
7338− ?~ t.args.e
7339− =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
7340− ?^ missing [%| u.missing]
7341− =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
7342− ?^ nested [%| u.nested]
7343− [%| ["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)]]]]
7344− =/ bad=(unit [at=span typ=itype])
7345− (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
7346− =/ whole-args=span
7347− [beg:(span-of i.args.e) end:(span-of (rear args.e))]
7348− =/ arg-at=span ?~(bad whole-args at.u.bad)
7349− =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
7350− [%| ["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)]]]]
7351− ?: &((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))
7352− [%| ["call result face propagation is not supported by partial inference" ~]]
7353− [%& product.ht st(sub sub.fit, next next.fit)]
7354− =/ result=itype [%var next.st]
7355− =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
7356− ?~ uni
7357− [%| ["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)]]]]
7358− [%& result st(next +(next.st), sub u.uni)]
8565+ ?: (explicit-proj-call e env state)
8566+ [%| ["proj needs an expected record type" ~]]
8567+ (infer-call-with-head e env state (infer-fragment head.e env state))
73598568 * [%| ["expression is not supported by partial inference" ~]]
73608569 ==
73618570::
@@ -7363,12 +8572,322 @@
73638572:: failed. If an intermediate fit is uncertain, retain the whole argument
73648573:: span rather than assigning blame to a particular argument.
73658574::
8575+:: Check a call using the head already inferred in this state. Keeping
8576+:: this shared avoids evaluating or instantiating a contextual head twice.
8577+++ width-has-projections
8578+ |= ps=(list iwprojection)
8579+ ^- ?
8580+ ?~ ps |
8581+ &
8582+::
8583++$ iwidth-elaboration [original=expr typ=itype sub=isub projections=(list iwprojection)]
8584+++ infer-width-elaboration
8585+ |= [e=expr env=ienv state=istate]
8586+ ^- (each iwidth-elaboration idiag)
8587+ =/ out=iresult (infer-fragment e env state)
8588+ ?: ?=(%| -.out) [%| p.out]
8589+ [%& [e typ.p.out sub.state.p.out (flop projections.state.p.out)]]
8590+::
8591+:: Source-bound gate-layout evidence, confined to checked root gate
8592+:: definitions and direct unshadowed prelude calls. The prepared prelude
8593+:: interface and its retained source are trusted as a matching artifact.
8594+:: Layouts identify sample binder faces; they do not change call arity or
8595+:: authorize stripping nested value faces. Unknown origins use ordinary fit.
8596+++ direct-written-gates
8597+ |= [ds=(list def) out=ivisited]
8598+ ^- ivisited
8599+ ?~ ds out
8600+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8601+ ?. |(?=(%gate -.val.i.ds) ?=(%gate-wide -.val.i.ds)) $(ds t.ds)
8602+ $(ds t.ds, out (~(put by out) name.i.ds &))
8603+++ direct-may-use-prelude
8604+ |= [ds=(list def) root=ivisited heads=ivisited]
8605+ ^- ?
8606+ ?~ ds |
8607+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8608+ =/ refs=(list term) (dependency-expr val.i.ds)
8609+ =/ has-root=? (lien refs |=(n=term ?=(^ (~(get by root) n))))
8610+ =/ has-head=? (lien refs |=(n=term ?=(^ (~(get by heads) n))))
8611+ ?: &(has-root has-head) &
8612+ $(ds t.ds)
8613+++ direct-unique-names
8614+ |= [names=(list term) seen=ivisited]
8615+ ^- ?
8616+ ?~ names &
8617+ ?: ?=(^ (~(get by seen) i.names)) |
8618+ $(names t.names, seen (~(put by seen) i.names &))
8619+++ direct-prelude-evidence
8620+ |= [ds=(list def) prelude=(unit ifile)]
8621+ ^- (unit igate-prelude-evidence)
8622+ ?~ prelude ~
8623+ ?~ source.u.prelude ~
8624+ =/ root=ivisited (direct-written-gates ds ~)
8625+ =/ names=(list term) (turn values.u.prelude |=(e=[name=term scheme=ischeme] name.e))
8626+ =/ heads=ivisited (graph-nameset names ~)
8627+ ?. (direct-may-use-prelude ds root heads) ~
8628+ =/ parsed (parse at.u.prelude u.source.u.prelude)
8629+ ?: ?=(%| -.parsed) ~
8630+ ?^ (duplicate-defs defs.p.parsed) ~
8631+ ?. (direct-unique-names (global-value-names defs.p.parsed) ~) ~
8632+ =/ gates=(map term def) (direct-checked-gates defs.p.parsed values.u.prelude)
8633+ `[u.prelude gates]
8634+++ direct-checked-gates
8635+ |= [ds=(list def) env=ienv]
8636+ ^- (map term def)
8637+ =/ names=(list term) (turn env |=(e=[name=term scheme=ischeme] name.e))
8638+ =/ known=ivisited (graph-nameset names ~)
8639+ =/ out=(map term def) ~
8640+ |-
8641+ ?~ ds out
8642+ =/ d=def i.ds
8643+ ?: ?=(%mold -.d) $(ds t.ds)
8644+ ?. ?=(^ (~(get by known) name.d)) $(ds t.ds)
8645+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) $(ds t.ds)
8646+ $(ds t.ds, out (~(put by out) name.d d))
8647+++ direct-find-gate
8648+ |= [n=term ds=(list def)]
8649+ ^- (unit def)
8650+ ?~ ds ~
8651+ ?: &(?=(%value -.i.ds) =(n name.i.ds)) `i.ds
8652+ $(ds t.ds)
8653+++ direct-gate-sample
8654+ |= d=def
8655+ ^- (unit sample)
8656+ ?. ?=(%value -.d) ~
8657+ ?- -.val.d
8658+ %gate `sample.val.d
8659+ %gate-wide `sample.val.d
8660+ * ~
8661+ ==
8662+++ direct-sample-name
8663+ |= sam=sample
8664+ ^- (unit term)
8665+ ?- -.sam
8666+ %bind `name.sam
8667+ %face `name.sam
8668+ %pun `name.sam
8669+ * ~
8670+ ==
8671+++ direct-field-name
8672+ |= f=field
8673+ ^- (unit term)
8674+ ?- -.f
8675+ %face `name.f
8676+ %pun `name.f
8677+ * ~
8678+ ==
8679+++ direct-slot-body
8680+ |= [typ=itype name=(unit term)]
8681+ ^- (unit itype)
8682+ ?~ name `typ
8683+ ?. ?=(%face -.typ) ~
8684+ ?. =(name.typ u.name) ~
8685+ `body.typ
8686+++ direct-invariant
8687+ |= [a=itype b=itype sub=isub next=@ud]
8688+ ^- ifit
8689+ ?: (itype-face-asym a b sub) [%unknown ~]
8690+ =/ forward=ifit (itype-fit a b sub next)
8691+ ?. ?=(%ok -.forward) [%unknown ~]
8692+ ?: (itype-face-asym a b sub.forward) [%unknown ~]
8693+ =/ reverse=ifit (itype-fit b a sub.forward next.forward)
8694+ ?. ?=(%ok -.reverse) [%unknown ~]
8695+ reverse
8696+++ direct-function-fit
8697+ |= [a=itype b=itype sam=sample sh=shape sub=isub next=@ud]
8698+ ^- ifit
8699+ ?. &(?=(%fn -.a) ?=(%fn -.b) ?=(%cell -.sam) ?=(%fn -.sh)) [%unknown ~]
8700+ ?. ?=(%cell -.sample.sh) [%unknown ~]
8701+ =/ as=(list sample) items.sam
8702+ =/ bs=(list field) fields.sample.sh
8703+ ?~ as [%unknown ~]
8704+ ?~ t.as [%unknown ~]
8705+ ?^ t.t.as [%unknown ~]
8706+ ?~ bs [%unknown ~]
8707+ ?~ t.bs [%unknown ~]
8708+ ?^ t.t.bs [%unknown ~]
8709+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) [%unknown ~]
8710+ =/ an=(unit term) (direct-sample-name i.as)
8711+ =/ bn=(unit term) (direct-field-name i.bs)
8712+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8713+ =/ x=(unit itype) (direct-slot-body hed.sample.a an)
8714+ =/ y=(unit itype) (direct-slot-body hed.sample.b bn)
8715+ ?~ x [%unknown ~]
8716+ ?~ y [%unknown ~]
8717+ =/ first=ifit (direct-invariant u.x u.y sub next)
8718+ ?. ?=(%ok -.first) [%unknown ~]
8719+ =. an (direct-sample-name i.t.as)
8720+ =. bn (direct-field-name i.t.bs)
8721+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8722+ =/ x2=(unit itype) (direct-slot-body tal.sample.a an)
8723+ =/ y2=(unit itype) (direct-slot-body tal.sample.b bn)
8724+ ?~ x2 [%unknown ~]
8725+ ?~ y2 [%unknown ~]
8726+ =/ second=ifit (direct-invariant u.x2 u.y2 sub.first next.first)
8727+ ?. ?=(%ok -.second) [%unknown ~]
8728+ (direct-invariant product.a product.b sub.second next.second)
8729+:: This is a tentative proof: its caller must require closed call samples
8730+:: and repeat every positional check under the stable final substitution.
8731+++ direct-positional-fit
8732+ |= [args=(list expr) slots=(list sample) actual=itype expected=itype env=ienv state=istate sub=isub next=@ud]
8733+ ^- ifit
8734+ ?~ args [%unknown ~]
8735+ ?~ slots [%unknown ~]
8736+ =/ last=? ?=(~ t.args)
8737+ ?: !=(last ?=(~ t.slots)) [%unknown ~]
8738+ =/ split=(unit [left=itype right=itype])
8739+ ?: last `[actual expected]
8740+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8741+ `[hed.actual hed.expected]
8742+ ?~ split [%unknown ~]
8743+ =/ x=itype left.u.split
8744+ =/ y=itype right.u.split
8745+ =/ expected-name=(unit term) (direct-sample-name i.slots)
8746+ =/ expected-body=(unit itype) (direct-slot-body y expected-name)
8747+ ?~ expected-body [%unknown ~]
8748+ =. y u.expected-body
8749+ =/ fit=ifit (itype-fit x y sub next)
8750+ =/ accepted=? &(?=(%ok -.fit) !(itype-positional-slot-face-asym x y sub.fit))
8751+ =/ result=(unit ifit)
8752+ ?: accepted `fit
8753+ ?. &(?=(%face -.i.slots) ?=(%fn -.shape.i.slots)) ~
8754+ ?. ?=(%wing -.i.args) ~
8755+ ?. ?=([@ ~] names.i.args) ~
8756+ ?. (unique-value-name i.names.i.args globals.state) ~
8757+ =/ source=(unit def) (~(get by gate-defs.state) i.names.i.args)
8758+ ?~ source ~
8759+ =/ sample=(unit sample) (direct-gate-sample u.source)
8760+ ?~ sample ~
8761+ =/ trial=ifit (direct-function-fit x y u.sample shape.i.slots sub next)
8762+ ?. ?=(%ok -.trial) ~
8763+ `trial
8764+ ?~ result [%unknown ~]
8765+ =. fit u.result
8766+ ?: last fit
8767+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
8768+ ?. ?=(%ok -.fit) [%unknown ~]
8769+ $(args t.args, slots t.slots, actual tal.actual, expected tal.expected, sub sub.fit, next next.fit)
8770+++ direct-any-gate-arg
8771+ |= [args=(list expr) defs=(map term def)]
8772+ ^- ?
8773+ ?~ args |
8774+ =/ found=?
8775+ ?. ?=(%wing -.i.args) |
8776+ ?. ?=([@ ~] names.i.args) |
8777+ ?=(^ (~(get by defs) i.names.i.args))
8778+ ?: found &
8779+ $(args t.args)
8780+++ direct-gate-call-fit
8781+ |= [e=expr actual=itype expected=itype env=ienv state=istate]
8782+ ^- (unit ifit)
8783+ ?. ?=(%call -.e) ~
8784+ ?~ args.e ~
8785+ ?~ t.args.e ~
8786+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8787+ ?. ?=(%wing -.head.e) ~
8788+ ?. ?=([@ ~] names.head.e) ~
8789+ ?. ?=(~ (ienv-lookup i.names.head.e env)) ~
8790+ ?. (unique-value-name i.names.head.e globals.state) ~
8791+ ?. (direct-any-gate-arg args.e gate-defs.state) ~
8792+ ?~ prelude.state ~
8793+ ?~ source.u.prelude.state ~
8794+ ?~ head-evidence.state ~
8795+ ?. =(u.prelude.state iface.u.head-evidence.state) ~
8796+ ?. ?=(^ (ienv-lookup i.names.head.e values.u.prelude.state)) ~
8797+ =/ head=(unit def) (~(get by gates.u.head-evidence.state) i.names.head.e)
8798+ ?~ head ~
8799+ =/ sam=(unit sample) (direct-gate-sample u.head)
8800+ ?~ sam ~
8801+ ?. ?=(%cell -.u.sam) ~
8802+ =/ fit=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.state next.state)
8803+ ?. ?=(%ok -.fit) ~
8804+ :: Enclosing inference may add constraints after this call. Only a
8805+ :: closed call-sample proof can remain stable under those later bindings.
8806+ =/ actual-final=itype (itype-normalize actual sub.fit)
8807+ =/ expected-final=itype (itype-normalize expected sub.fit)
8808+ ?^ (itype-vars actual-final) ~
8809+ ?^ (itype-vars expected-final) ~
8810+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
8811+ :: A later argument may resolve a variable used by an earlier slot.
8812+ :: Recheck every fit and face against the completed substitution; no
8813+ :: additional binding or fresh variable is permitted in the second pass.
8814+ =/ verified=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.fit next.fit)
8815+ ?. ?=(%ok -.verified) ~
8816+ ?. &(=(sub.fit sub.verified) =(next.fit next.verified)) ~
8817+ `fit
8818+::
8819+++ infer-call-with-head
8820+ |= [e=expr env=ienv state=istate head=iresult]
8821+ ^- iresult
8822+ ?> ?=(%call -.e)
8823+ ?~ args.e [%| ["call has no argument" ~]]
8824+ ?: ?=(%| -.head) head
8825+ =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
8826+ =/ arg=iresult
8827+ ?^ t.args.e
8828+ ?: ?=(%fn -.head-type)
8829+ (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
8830+ (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
8831+ ?: ?=(%fn -.head-type)
8832+ (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
8833+ (infer-fragment i.args.e env state.p.head)
8834+ ?: ?=(%| -.arg) arg
8835+ =/ st=istate state.p.arg
8836+ =/ ht=itype (itype-walk typ.p.head sub.st)
8837+ ?: ?=(%fn -.ht)
8838+ =/ shape=(unit [source=iwfields target=iwfields])
8839+ ?^ t.args.e ~
8840+ (width-shape typ.p.arg sample.ht sub.st)
8841+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
8842+ =/ fit=ifit
8843+ ?^ t.args.e (itype-fit-inner typ.p.arg sample.ht sub.st next.st & |)
8844+ (itype-fit typ.p.arg sample.ht sub.st next.st)
8845+ =/ direct=(unit ifit)
8846+ ?: ?=(%ok -.fit) ~
8847+ (direct-gate-call-fit e typ.p.arg sample.ht env st)
8848+ =. fit ?~(direct fit u.direct)
8849+ ?: ?=(%unknown -.fit)
8850+ ?~ defer.st [%| ["call constraint is not supported by partial inference" ~]]
8851+ =/ edge=(unit dgo) (dg-eligible-ctor e typ.p.head typ.p.arg sample.ht st)
8852+ ?~ edge [%| ["call constraint is not supported by partial inference" ~]]
8853+ ?: (gth (lent obligations.st) 63) [%| ["call constraint is not supported by partial inference" ~]]
8854+ [%& product.ht st(obligations [u.edge obligations.st])]
8855+
8856+ ?: ?=(%bad -.fit)
8857+ ?~ t.args.e
8858+ =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
8859+ ?^ missing [%| u.missing]
8860+ =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
8861+ ?^ nested [%| u.nested]
8862+ [%| ["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)]]]]
8863+ =/ bad=(unit [at=span typ=itype])
8864+ (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
8865+ =/ whole-args=span
8866+ [beg:(span-of i.args.e) end:(span-of (rear args.e))]
8867+ =/ arg-at=span ?~(bad whole-args at.u.bad)
8868+ =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
8869+ [%| ["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)]]]]
8870+ ?: &(?=(^ defer.st) !(dg-stable-call-fit typ.p.arg sample.ht product.ht sub.fit ?=(^ t.args.e)))
8871+ [%| ["deferred call fit needs stable inference" ~]]
8872+ =/ face-asym=?
8873+ ?^ direct |
8874+ ?^ t.args.e (itype-positional-face-asym args.e typ.p.arg sample.ht sub.fit)
8875+ (itype-face-asym typ.p.arg sample.ht sub.fit)
8876+ ?: &((itype-has-face typ.p.arg sub.fit) face-asym (itype-output-may-be-cell product.ht sub.fit))
8877+ [%| ["call result face propagation is not supported by partial inference" ~]]
8878+ [%& product.ht st(sub sub.fit, next next.fit)]
8879+ =/ result=itype [%var next.st]
8880+ =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
8881+ ?~ uni
8882+ [%| ["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)]]]]
8883+ [%& result st(next +(next.st), sub u.uni)]
8884+::
73668885++ call-error-site
73678886 |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
73688887 ^- (unit [at=span typ=itype])
73698888 ?~ args ~
73708889 =/ original=[left=itype right=itype] [actual expected]
7371− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
8890+ ?: |(?=(%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))) ~
73728891 =. actual (itype-walk actual sub)
73738892 =. expected (itype-walk expected sub)
73748893 ?: &(?=(%face -.expected) !?=(%face -.actual))
@@ -7418,9 +8937,316 @@
74188937 [%| ["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)]]]]
74198938 [%& expected state.p.value(sub sub.fit, next next.fit)]
74208939::
8940+:: A known gate may receive an enclosing target before its argument is
8941+:: inferred when its result is open or a direct, matching named generic
8942+:: union. Opaque, recursive, tag-constrained and variable-bound union
8943+:: results keep the existing directional path.
8944+++ infer-contextual-call
8945+ |= [e=expr expected=itype env=ienv state=istate]
8946+ ^- iresult
8947+ ?> ?=(%call -.e)
8948+ ?~ args.e [%| ["call has no argument" ~]]
8949+ =/ head=iresult (infer-fragment head.e env state)
8950+ ?: ?=(%| -.head) head
8951+ =/ ht=itype (itype-walk typ.p.head sub.state.p.head)
8952+ ?. ?=(%fn -.ht) (infer-call-with-head e env state head)
8953+ =/ result=itype (itype-walk product.ht sub.state.p.head)
8954+ =/ eligible=?
8955+ ?: ?=(%var -.result) &
8956+ :: A direct known generic union may receive the same nominal result
8957+ :: context before its arguments are checked. Variable-bound origins,
8958+ :: pending tags, recursive identities and unknown atoms stay open.
8959+ ?. &(?=(%union -.product.ht) ?=(%union -.result) ?=(%union -.expected)) |
8960+ ?~ origin.result |
8961+ ?. =(origin.result origin.expected) |
8962+ ?~ args.result |
8963+ ?. =((lent args.result) (lent args.expected)) |
8964+ ?: |((itype-has-tag (itype-normalize result sub.state.p.head)) (itype-has-tag (itype-normalize expected sub.state.p.head))) |
8965+ ?: |((itype-has-recursive (itype-normalize result sub.state.p.head)) (itype-has-recursive (itype-normalize expected sub.state.p.head))) |
8966+ ?: |((itype-has-any-atom result sub.state.p.head) (itype-has-any-atom expected sub.state.p.head)) |
8967+ &
8968+ ?. eligible (infer-call-with-head e env state head)
8969+ ?: |(?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)) (itype-has-tag (itype-normalize expected sub.state.p.head)))
8970+ (infer-call-with-head e env state head)
8971+ =/ sub=(unit isub) (itype-unify result expected sub.state.p.head)
8972+ ?~ sub (infer-call-with-head e env state head)
8973+ (infer-call-with-head e env state [%& typ.p.head state.p.head(sub u.sub)])
8974+::
8975+:: An eligible fully faced literal receives context by name, in source order.
8976+++ width-literal-fields
8977+ |= [items=(list item) axis=@ud fuel=@ud]
8978+ ^- (unit iwfields)
8979+ =/ order=(list iwfield) ~
8980+ =/ index=(map term iwfield) *(map term iwfield)
8981+ |-
8982+ ?~ items ~
8983+ ?: =(0 fuel) ~
8984+ ?~ face.i.items ~
8985+ =/ at-axis=@ud ?~(t.items axis (mul 2 axis))
8986+ =/ entry=iwfield [u.face.i.items at-axis [%noun ~]]
8987+ ?: ?=(^ (~(get by index) name.entry)) ~
8988+ =. index (~(put by index) name.entry entry)
8989+ =. order [entry order]
8990+ ?~ t.items `[(flop order) index]
8991+ $(items t.items, axis +((mul 2 axis)), fuel (dec fuel))
8992+++ width-infer-items
8993+ |= [items=(list item) expected=(map term iwfield) env=ienv state=istate context=span]
8994+ ^- iresult
8995+ ?~ items [%| ["empty record is not supported" ~]]
8996+ ?~ face.i.items [%| ["record face needs unsupported inference" ~]]
8997+ =/ field=(unit iwfield) (~(get by expected) u.face.i.items)
8998+ =/ head=iresult
8999+ ?~ field (infer-fragment val.i.items env state)
9000+ (infer-call-context-arg val.i.items typ.u.field env state context)
9001+ ?: ?=(%| -.head) head
9002+ =/ typ=itype [%face u.face.i.items typ.p.head]
9003+ ?~ t.items [%& typ state.p.head]
9004+ =/ tail=iresult $(items t.items, state state.p.head)
9005+ ?: ?=(%| -.tail) tail
9006+ [%& [%cell typ typ.p.tail] state.p.tail]
9007+++ width-infer-literal
9008+ |= [e=expr expected=itype env=ienv state=istate context=span]
9009+ ^- (unit iresult)
9010+ ?. ?=(%tuple -.e) ~
9011+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) ~
9012+ =/ source=(unit iwfields) (width-literal-fields items.e 1 4.096)
9013+ =/ target=(unit iwfields) (width-scan expected sub.state 1 4.096)
9014+ ?~ source ~
9015+ ?~ target ~
9016+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
9017+ ?. (width-in-order order.u.source order.u.target)
9018+ `(infer-simple-items items.e env state)
9019+ `(width-infer-items items.e index.u.target env state context)
9020+::
9021+:: Experimental intrinsic recognition; real bindings retain normal calls.
9022+++ explicit-proj-call
9023+ |= [e=expr env=ienv state=istate]
9024+ ^- ?
9025+ ?. ?=(%call -.e) |
9026+ ?. ?=([* ~] args.e) |
9027+ ?. ?=(%wing -.head.e) |
9028+ ?. =(names.head.e ~[%proj]) |
9029+ ?: ?=(^ (ienv-lookup %proj env)) |
9030+ ?: (lien globals.state |=(n=term =(n %proj))) |
9031+ ?~ prelude.state &
9032+ ?:(?=(^ (ienv-lookup %proj values.u.prelude.state)) | &)
9033+++ infer-proj-source
9034+ |= [e=expr expected=itype env=ienv state=istate context=span]
9035+ ^- iresult
9036+ ?: ?=(%group -.e) $(e inner.e)
9037+ =/ literal=(unit iresult) (width-infer-literal e expected env state context)
9038+ ?^ literal u.literal
9039+ (infer-fragment e env state)
9040+++ infer-proj-context
9041+ |= [e=expr expected=itype env=ienv state=istate context=span]
9042+ ^- iresult
9043+ ?> ?=(%call -.e)
9044+ ?~ args.e [%| ["proj needs one record" ~]]
9045+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) [%| ["proj needs an expected record type" ~]]
9046+ =/ value=iresult (infer-proj-source i.args.e expected env state context)
9047+ ?: ?=(%| -.value) value
9048+ =/ shape=(unit [source=iwfields target=iwfields])
9049+ (width-proj-shape typ.p.value expected sub.state.p.value)
9050+ ?~ shape [%| ["proj needs a known record containing its expected fields" ~]]
9051+ =/ project=(unit iwidth-result) (width-project u.shape sub.state.p.value next.state.p.value)
9052+ ?~ project [%| ["proj constraint needs unsupported inference" ~]]
9053+ =/ st=istate state.p.value(sub sub.u.project, next next.u.project)
9054+ [%& expected st(projections [[at.e e typ.p.value expected steps.u.project] projections.st])]
9055+::
9056+:: A known literal singleton in a direct union can contextualize a
9057+:: loobean literal of the same noun. Only explicit singleton and cell
9058+:: competitors are considered; opaque or variable cases stay unknown.
9059+++ explicit-singleton-in-union
9060+ |= [t=itype noun=@]
9061+ ^- ?
9062+ ?. ?=(%union -.t) |
9063+ =/ cases=(list itype) cases.t
9064+ =/ found=? |
9065+ |-
9066+ ?~ cases found
9067+ =/ c=itype i.cases
9068+ ?: ?=(%cell -.c) $(cases t.cases)
9069+ ?. ?=(%const -.c) |
9070+ ?: =(noun val.literal.c)
9071+ ?: found |
9072+ $(cases t.cases, found &)
9073+ $(cases t.cases)
9074+::
9075+:: Select a written literal-headed case only when every competing case is
9076+:: also an explicit singleton-headed cell and exactly one matches. Opaque,
9077+:: variable-bound and differently shaped cases keep inference unchanged.
9078+:: This first slice supplies context to a directly called payload. Plain
9079+:: literal data and other expressions retain their existing inference path.
9080+++ contextual-atomic-arguments
9081+ |= args=(list expr)
9082+ ^- ?
9083+ ?~ args &
9084+ ?. ?=(?(%lit %wing %ctor) -.i.args) |
9085+ $(args t.args)
9086+++ contextual-direct-payload-call
9087+ |= e=expr
9088+ ^- ?
9089+ ?: ?=(%group -.e) $(e inner.e)
9090+ ?. ?=(%call -.e) |
9091+ ?. ?=(%wing -.head.e) |
9092+ ?~ args.e |
9093+ (contextual-atomic-arguments args.e)
9094+::
9095+:: A walked variable may have concealed a union inside a substituted
9096+:: structure before this arm was called. Decline in that case rather than
9097+:: deriving provenance from the already-walked type.
9098+++ contextual-simple-sub
9099+ |= sub=isub
9100+ ^- ?
9101+ ?~ sub &
9102+ ?: ?=(?(%cell %face %fn %union %collection) -.val.i.sub) |
9103+ $(sub t.sub)
9104+::
9105+:: Check the syntactic root before scanning; scan substitutions once.
9106+++ grec-direct-context
9107+ |= [expected=itype sub=isub]
9108+ ^- ?
9109+ =/ left=@ud 4.096
9110+ |-
9111+ ?: ?=(%face -.expected)
9112+ ?: =(0 left) |
9113+ $(expected body.expected, left (dec left))
9114+ ?. ?=(%grec -.expected) |
9115+ ?~ sub &
9116+ ?: =(0 left) |
9117+ ?: ?=(?(%cell %face %fn %union %collection %grec) -.val.i.sub) |
9118+ $(sub t.sub, left (dec left))
9119+++ contextual-direct-union
9120+ |= target=itype
9121+ ^- ?
9122+ ?: ?=(%face -.target) $(target body.target)
9123+ ?=(%union -.target)
9124+++ contextual-tagged-case
9125+ |= [target=itype tag=@ sub=isub]
9126+ ^- (unit itype)
9127+ ?. ?=(%union -.target) ~
9128+ =/ remaining=(list itype) cases.target
9129+ =/ found=(unit itype) ~
9130+ =/ seen=(set @) *(set @)
9131+ |-
9132+ ?~ remaining found
9133+ =/ c=itype i.remaining
9134+ ?. ?=(%cell -.c) ~
9135+ =/ head=itype hed.c
9136+ ?. ?=(%const -.head) ~
9137+ ?: (~(has in:..zuse seen) val.literal.head) ~
9138+ =. seen (~(put in:..zuse seen) val.literal.head)
9139+ ?: =(tag val.literal.head)
9140+ $(remaining t.remaining, found `c)
9141+ $(remaining t.remaining)
9142+::
9143+:: A bounded syntactic screen: no nested branch, cast, gate or local body
9144+:: can re-enter cell-branch retry during either inference attempt.
9145+++ closed-cell-retry-safe
9146+ |= [todo=(list expr) fuel=@ud]
9147+ ^- ?
9148+ ?~ todo &
9149+ ?: =(0 fuel) |
9150+ =/ e=expr i.todo
9151+ =. fuel (dec fuel)
9152+ ?+ -.e |
9153+ %lit $(todo t.todo)
9154+ %wing $(todo t.todo)
9155+ %ctor $(todo t.todo)
9156+ %path $(todo t.todo)
9157+ %crash $(todo t.todo)
9158+ %str
9159+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) |
9160+ $(todo t.todo)
9161+ %group $(todo [inner.e t.todo])
9162+ %pair $(todo [val.e t.todo])
9163+ %unit $(todo [val.e t.todo])
9164+ %list $(todo (weld items.e t.todo))
9165+ %tuple $(todo (weld (turn items.e |=(i=item val.i)) t.todo))
9166+ %change $(todo (weld (turn edits.e |=(ed=edit val.ed)) t.todo))
9167+ %call $(todo [head.e (weld args.e t.todo)])
9168+ %trace $(todo [val.e then.e t.todo])
9169+ ==
9170+::
9171+++ closed-cell-sub-safe
9172+ |= [sub=isub fuel=@ud]
9173+ ^- ?
9174+ ?~ sub &
9175+ ?: =(0 fuel) |
9176+ ?: ?=(?(%cell %face %fn %union %collection %grec %jrec %recursive) -.val.i.sub) |
9177+ $(sub t.sub, fuel (dec fuel))
9178+::
9179+++ closed-cell-branch-eligible
9180+ |= [e=expr expected=itype sub=isub]
9181+ ^- ?
9182+ ?. &(?=(%branch -.e) ?=(%cell -.expected) (closed-cell-sub-safe sub 512)) |
9183+ ?~ arms.e |
9184+ ?~ t.arms.e |
9185+ ?^ t.t.arms.e |
9186+ =/ x=arm i.arms.e
9187+ =/ y=arm i.t.arms.e
9188+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
9189+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
9190+ ?: =(val.lit.pat.x val.lit.pat.y) |
9191+ (closed-cell-retry-safe ~[subject.e val.x val.y] 512)
9192+::
9193+:: Attempt ordinary inference first; retry from the same state only for
9194+:: the bounded non-reentrant syntax above. Preserve original value faces.
9195+++ infer-closed-cell-branch
9196+ |= [e=expr expected=itype env=ienv state=istate context=span]
9197+ ^- iresult
9198+ ?> (closed-cell-branch-eligible e expected sub.state)
9199+ ?> ?=(%branch -.e)
9200+ ?> ?=(^ arms.e)
9201+ ?> ?=(^ t.arms.e)
9202+ =/ ordinary=iresult (infer-fragment e env state)
9203+ =/ ordinary-good=?
9204+ ?: ?=(%| -.ordinary) |
9205+ =/ fit=ifit (itype-fit typ.p.ordinary expected sub.state.p.ordinary next.state.p.ordinary)
9206+ ?=(%ok -.fit)
9207+ ?: ordinary-good ordinary
9208+ =/ attempt=(unit iresult)
9209+ =/ x=arm i.arms.e
9210+ =/ y=arm i.t.arms.e
9211+ =/ subject=iresult (infer-fragment subject.e env state)
9212+ ?: ?=(%| -.subject) ~
9213+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
9214+ ?: ?=(%union -.subject-type) ~
9215+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
9216+ ?~ su ~
9217+ =/ left=iresult (infer-call-context-arg val.x expected env state.p.subject(sub u.su) context)
9218+ ?: ?=(%| -.left) ~
9219+ =/ lf=ifit (itype-fit typ.p.left expected sub.state.p.left next.state.p.left)
9220+ ?. ?=(%ok -.lf) ~
9221+ =/ right=iresult (infer-call-context-arg val.y expected env state.p.left(sub sub.lf, next next.lf) context)
9222+ ?: ?=(%| -.right) ~
9223+ =/ rf=ifit (itype-fit typ.p.right expected sub.state.p.right next.state.p.right)
9224+ ?. ?=(%ok -.rf) ~
9225+ =/ sub=isub sub.rf
9226+ =/ next=@ud next.rf
9227+ =/ lt=itype (itype-normalize typ.p.left sub)
9228+ =/ rt=itype (itype-normalize typ.p.right sub)
9229+ =/ et=itype (itype-normalize expected sub)
9230+ ?. =(lt rt) ~
9231+ ?: |(?=(^ (itype-vars lt)) ?=(^ (itype-vars rt)) ?=(^ (itype-vars et))) ~
9232+ ?: |((itype-has-tag lt) (itype-has-tag rt) (itype-has-tag et)) ~
9233+ =/ lcheck=ifit (itype-fit typ.p.left expected sub next)
9234+ ?. ?=(%ok -.lcheck) ~
9235+ ?. &(=(sub.lcheck sub) =(next.lcheck next)) ~
9236+ =/ rcheck=ifit (itype-fit typ.p.right expected sub next)
9237+ ?. ?=(%ok -.rcheck) ~
9238+ ?. &(=(sub.rcheck sub) =(next.rcheck next)) ~
9239+ `[%& typ.p.left state.p.right(sub sub, next next)]
9240+ ?~ attempt ordinary
9241+ u.attempt
9242+::
74219243++ infer-call-context-arg
74229244 |= [e=expr expected=itype env=ienv state=istate context=span]
74239245 ^- iresult
9246+ ?: &(?=(^ defer.state) ?=(%branch -.e)) (infer-fragment e env state)
9247+ ?: &(?=(^ defer.state) ?=(^ prelude.state) ?=(%tuple -.e))
9248+ (infer-fragment e env state)
9249+ ?: ?=(%pair -.e) $(e (pair-as-cell e))
74249250 ?: ?=(%group -.e) $(e inner.e)
74259251 ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
74269252 ?: ?=(%trace -.e)
@@ -7430,30 +9256,126 @@
74309256 =/ target=itype (itype-walk expected sub.state)
74319257 |-
74329258 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
7433− =/ known=(unit itype)
9259+ ?: (explicit-proj-call e env state)
9260+ (infer-proj-context e expected env state context)
9261+ :: Experimental construction only for a source-proven direct target.
9262+ :: Decline any walked structural binding to retain raw-variable provenance.
9263+ ?: &(?=(%grec -.target) ?=(%tuple -.e) (grec-direct-context expected sub.state))
9264+ =/ unfolded=(unit [view=itype left=@ud]) (grec-unfold-view target jrec-fuel.state)
9265+ ?~ unfolded [%| ["recursive mold unfolding needs unsupported inference" ~]]
9266+ ?~ items.e [%| ["recursive mold constructor needs unsupported inference" ~]]
9267+ =/ first=item i.items.e
9268+ ?. &(?=(~ face.first) ?=(%lit -.val.first) =(%term form.lit.val.first))
9269+ [%| ["recursive mold constructor needs unsupported inference" ~]]
9270+ =/ chosen=(unit itype) (contextual-tagged-case view.u.unfolded val.lit.val.first sub.state)
9271+ ?~ chosen [%| ["recursive mold constructor has no matching case" ~]]
9272+ =/ value=iresult (infer-call-context-items items.e u.chosen env state(jrec-fuel left.u.unfolded) context)
9273+ ?: ?=(%| -.value) value
9274+ =/ fit=ifit (itype-fit typ.p.value u.chosen sub.state.p.value next.state.p.value)
9275+ ?: ?=(%unknown -.fit) [%| ["recursive mold case needs unsupported inference" ~]]
9276+ ?: ?=(%bad -.fit) [%| ["recursive mold case does not fit its source shape" ~]]
9277+ [%& target state.p.value(sub sub.fit, next next.fit)]
9278+ :: Only the source-proven one-layer cell is exposed. Each recursive
9279+ :: descent consumes one written tuple; named values use ordinary fit.
9280+ ?: &(?=(%jrec -.target) ?=(%lit -.e) =(%null form.lit.e))
9281+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9282+ [%& target state(jrec-fuel (dec jrec-fuel.state))]
9283+ ?: &(?=(%jrec -.target) ?=(%tuple -.e))
9284+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9285+ =. state state(jrec-fuel (dec jrec-fuel.state))
9286+ =/ shape=itype
9287+ [%cell [%face head.target [%atom aura.target]] [%face tail.target target]]
9288+ =/ value=iresult (infer-call-context-items items.e shape env state context)
9289+ ?: ?=(%| -.value) value
9290+ =/ fit=ifit (itype-fit typ.p.value shape sub.state.p.value next.state.p.value)
9291+ ?: ?=(%unknown -.fit) [%| ["recursive mold cell constraint needs unsupported inference" ~]]
9292+ ?: ?=(%bad -.fit) [%| ["recursive mold cell does not fit its source shape" ~]]
9293+ [%& target state.p.value(sub sub.fit, next next.fit)]
9294+ ?: ?=(%call -.e) (infer-contextual-call e target env state)
9295+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[target context])
9296+ ?^ empty-list u.empty-list
9297+ ?: (single-structured-pattern e)
9298+ ?> ?=(%branch -.e)
9299+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
9300+ ?^ empty-union (infer-known-union-context-subject e target env u.empty-union context)
9301+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
9302+ ?^ single (infer-known-union-context-subject e target env u.single context)
9303+ (infer-single-case-branch e env state `[target context])
9304+ ?: (cell-binder-pattern e)
9305+ (infer-cell-branch e env state `[target context])
9306+ :: In an explicit singleton context retain the written loobean noun;
9307+ :: the ordinary singleton fit compares its noun, not its spelling.
9308+ =/ singleton=(unit itype)
9309+ ?. ?=(%lit -.e) ~
9310+ ?. =(%loobean form.lit.e) ~
9311+ ?. |(?=(%const -.target) &(?=(%union -.expected) (explicit-singleton-in-union expected val.lit.e))) ~
9312+ `[%const lit.e]
9313+ ?^ singleton [%& u.singleton state]
9314+ =/ known=(unit iresult)
74349315 ?: ?=(%branch -.e) (known-union-subject subject.e env state)
74359316 ~
7436− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
7437− (infer-known-union-context e target env state context)
9317+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
9318+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
9319+ (infer-known-union-context-subject e target env u.known context)
74389320 ?: &(?=(%union -.target) ?=(%unit -.e))
74399321 (infer-unit-context e target env state context)
9322+ ?: (closed-cell-branch-eligible e expected sub.state)
9323+ (infer-closed-cell-branch e expected env state context)
9324+ ?: &(?=(%flag -.target) (context-union-branch e))
9325+ (infer-union-context e target env state context)
74409326 ?: &(?=(%union -.target) (context-union-branch e))
74419327 (infer-union-context e target env state context)
74429328 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
74439329 (infer-union-context e target env state context)
74449330 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
74459331 (infer-list-context e target env state context)
9332+ :: A literal-headed tuple can receive the unique case's payload
9333+ :: context. The ordinary final fit still checks the complete union.
9334+ =/ selected=(unit itype)
9335+ ?. &((contextual-simple-sub sub.state) (contextual-direct-union expected) ?=(%union -.target) ?=(%tuple -.e) ?=(^ items.e)) ~
9336+ ?~ t.items.e ~
9337+ ?^ t.t.items.e ~
9338+ ?. (contextual-direct-payload-call val.i.t.items.e) ~
9339+ =/ first=item i.items.e
9340+ ?. &(?=(~ face.first) ?=(%lit -.val.first) |(=(%term form.lit.val.first) =(%null form.lit.val.first) =(%loobean form.lit.val.first))) ~
9341+ (contextual-tagged-case target val.lit.val.first sub.state)
9342+ ?^ selected
9343+ ?> ?=(%tuple -.e)
9344+ :: On this bounded shallow-call shape, preserve any inference that
9345+ :: already fits before trying the new contextual path. Neither pass
9346+ :: can recursively select a nested tuple from the atomic arguments.
9347+ =/ ordinary=(unit iresult)
9348+ =/ initial=iresult (infer-fragment e env state)
9349+ ?: ?=(%| -.initial) ~
9350+ =/ fit=ifit (itype-fit typ.p.initial target sub.state.p.initial next.state.p.initial)
9351+ ?. ?=(%ok -.fit) ~
9352+ `initial
9353+ ?^ ordinary u.ordinary
9354+ =/ value=iresult (infer-call-context-items items.e u.selected env state context)
9355+ ?: ?=(%| -.value) value
9356+ =/ fit=ifit (itype-fit typ.p.value u.selected sub.state.p.value next.state.p.value)
9357+ ?: ?=(%unknown -.fit) [%| ["tagged case needs unsupported inference" ~]]
9358+ ?: ?=(%bad -.fit) [%| ["tagged case does not fit its expected type" ~[[context "expected union case"] [(span-of e) "value"]]]]
9359+ [%& typ.p.value state.p.value(sub sub.fit, next next.fit)]
74469360 ?: &(?=(%cell -.target) ?=(%tuple -.e))
74479361 (infer-call-context-items items.e target env state context)
74489362 (infer-fragment e env state)
74499363::
74509364:: Preserve each written face; the final complete sample fit checks faces.
9365+:: A tuple or positional field face belongs to the enclosing sample,
9366+:: not to the expression at that position. A second face, if present,
9367+:: is part of the value's own expected type.
9368+++ projection-field-target
9369+ |= expected=itype
9370+ ^- itype
9371+ ?:(?=(%face -.expected) body.expected expected)
9372+::
74519373++ infer-call-context-items
74529374 |= [items=(list item) expected=itype env=ienv state=istate context=span]
74539375 ^- iresult
74549376 ?~ items [%| ["empty cell is not supported by partial inference" ~]]
74559377 ?~ t.items
7456− =/ last=iresult (infer-call-context-arg val.i.items expected env state context)
9378+ =/ last=iresult (infer-call-context-arg val.i.items (projection-field-target expected) env state context)
74579379 ?: ?=(%| -.last) last
74589380 =/ typ=itype typ.p.last
74599381 =. typ ?~(face.i.items typ [%face u.face.i.items typ])
@@ -7462,7 +9384,7 @@
74629384 |-
74639385 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
74649386 ?. ?=(%cell -.target) (infer-simple-items items env state)
7465− =/ head=iresult (infer-call-context-arg val.i.items hed.target env state context)
9387+ =/ head=iresult (infer-call-context-arg val.i.items (projection-field-target hed.target) env state context)
74669388 ?: ?=(%| -.head) head
74679389 =/ typ=itype typ.p.head
74689390 =. typ ?~(face.i.items typ [%face u.face.i.items typ])
@@ -7474,13 +9396,13 @@
74749396 |= [args=(list expr) expected=itype env=ienv state=istate context=span]
74759397 ^- iresult
74769398 ?~ args [%| ["call has no argument" ~]]
7477− ?~ t.args (infer-call-context-arg i.args expected env state context)
9399+ ?~ t.args (infer-call-context-arg i.args (projection-field-target expected) env state context)
74789400 =/ target=itype (itype-walk expected sub.state)
74799401 |-
74809402 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
74819403 ?. ?=(%cell -.target)
74829404 (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
7483− =/ head=iresult (infer-call-context-arg i.args hed.target env state context)
9405+ =/ head=iresult (infer-call-context-arg i.args (projection-field-target hed.target) env state context)
74849406 ?: ?=(%| -.head) head
74859407 =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
74869408 ?: ?=(%| -.tail) tail
@@ -7512,7 +9434,7 @@
75129434 ?~ pats [%& ~]
75139435 ?. ?=(%bind -.i.pats) [%| 'branch pattern is not supported by partial inference']
75149436 =/ name=term name.i.pats
7515− ?: |(?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
9437+ ?: |(=(name %proj) ?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
75169438 [%| 'pattern shadows a name']
75179439 =/ rest=(each (list term) @t) $(pats t.pats, seen [name seen])
75189440 ?: ?=(%| -.rest) rest
@@ -7537,10 +9459,19 @@
75379459 ?~ t.names |
75389460 =. typ (itype-walk typ sub)
75399461 ?: ?=(%cell -.typ) $(typ tal.typ, names t.names)
7540− |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9462+ |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%jrec -.typ) ?=(%grec -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9463+::
9464+++ cell-binder-pattern
9465+ |= e=expr
9466+ ^- ?
9467+ ?. ?=(%branch -.e) |
9468+ ?~ arms.e |
9469+ ?^ t.arms.e |
9470+ ?. ?=(%cell -.pat.i.arms.e) |
9471+ !(single-structured-pattern e)
75419472::
75429473++ infer-cell-branch
7543− |= [e=expr env=ienv state=istate]
9474+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
75449475 ^- iresult
75459476 ?> ?=(%branch -.e)
75469477 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -7564,7 +9495,16 @@
75649495 =/ binders=[typ=itype env=ienv next=@ud] (cell-pattern-types p.names env next.st)
75659496 =/ sub=(unit isub) (itype-unify typ.p.subject typ.binders sub.st)
75669497 ?~ sub [%| ["cell pattern does not match the subject type" ~]]
7567− (infer-fragment val.arm env.binders st(next next.binders, sub u.sub))
9498+ =. st st(next next.binders, sub u.sub)
9499+ ?~ expected (infer-fragment val.arm env.binders st)
9500+ =/ body=iresult (infer-call-context-arg val.arm typ.u.expected env.binders st context.u.expected)
9501+ ?: ?=(%| -.body) body
9502+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
9503+ ?: ?=(%unknown -.fit) [%| ["cell branch result constraint is not supported by partial inference" ~]]
9504+ ?: ?=(%bad -.fit) [%| ["cell branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.arm) "branch arm"]]]]
9505+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
9506+ [%| ["cell branch result needs context in partial inference" ~]]
9507+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
75689508::
75699509++ show-itype
75709510 |= [t=itype sub=isub]
@@ -7577,12 +9517,20 @@
75779517 %avar
75789518 ?: (lth id.t 26) [(add 65 id.t) ~]
75799519 "T{<id.t>}"
9520+ %rvar
9521+ ?: (lth id.t 26) [(add 65 id.t) ~]
9522+ "T{<id.t>}"
75809523 %nvar
75819524 ?: (lth id.t 26) [(add 65 id.t) ~]
75829525 "T{<id.t>}"
9526+ %rnvar
9527+ ?: (lth id.t 26) [(add 65 id.t) ~]
9528+ "T{<id.t>}"
75839529 %atom "@{(trip aura.t)}"
75849530 %any-atom "@"
75859531 %flag "?"
9532+ %noun "*"
9533+ %empty "!!"
75869534 %tag (trip txt.literal.t)
75879535 %const (trip txt.literal.t)
75889536 %union
@@ -7590,6 +9538,8 @@
75909538 ?~ args.t (trip u.label.t)
75919539 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
75929540 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9541+ %jrec ?~(label.t "recursive mold" (trip u.label.t))
9542+ %grec ?~(label.t "recursive mold" "({(trip u.label.t)} {(show-itype-cases args.t sub)})")
75939543 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
75949544 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
75959545 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
@@ -7625,15 +9575,21 @@
76259575 ^- ?
76269576 ?- -.typ
76279577 %nvar &
9578+ %rnvar &
76289579 %var |
76299580 %avar |
9581+ %rvar |
76309582 %atom |
76319583 %any-atom |
76329584 %flag |
9585+ %noun |
9586+ %empty |
76339587 %tag |
76349588 %const |
76359589 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
76369590 %recursive |
9591+ %jrec |
9592+ %grec (lien args.typ |=(c=itype (itype-has-nvar c)))
76379593 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
76389594 %face $(typ body.typ)
76399595 %fn |($(typ sample.typ) $(typ product.typ))
@@ -7644,7 +9600,7 @@
76449600 |= [label=tape typ=itype sub=isub]
76459601 ^- tape
76469602 =/ normalized=itype (itype-normalize typ sub)
7647− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
9603+ ?: |(?=(%var -.normalized) ?=(%avar -.normalized) ?=(%rvar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
76489604 ?: (itype-has-hidden-recursive normalized) label
76499605 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
76509606 ?: (gth (lent vars) 26) label
@@ -7666,6 +9622,7 @@
76669622 ?+ -.resolved ~
76679623 %var `id.resolved
76689624 %avar `id.resolved
9625+ %rvar `id.resolved
76699626 ==
76709627 ?~ ident $(caps t.caps)
76719628 ?: =(n u.ident) &
@@ -7680,6 +9637,7 @@
76809637 ?+ -.resolved ~
76819638 %var `id.resolved
76829639 %avar `id.resolved
9640+ %rvar `id.resolved
76839641 ==
76849642 ?~ ident $(caps t.caps)
76859643 ?: =(n u.ident) `i.caps
@@ -7694,6 +9652,7 @@
76949652 ?+ -.resolved ~
76959653 %var `id.resolved
76969654 %avar `id.resolved
9655+ %rvar `id.resolved
76979656 ==
76989657 ?~ ident $(caps t.caps)
76999658 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
@@ -7709,6 +9668,7 @@
77099668 ?+ -.resolved ~
77109669 %var `id.resolved
77119670 %avar `id.resolved
9671+ %rvar `id.resolved
77129672 ==
77139673 ?~ ident &
77149674 ?: (cap-id-in u.ident t.caps sub) &
@@ -7723,8 +9683,8 @@
77239683 ^- ?
77249684 ?~ caps |
77259685 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
7726− ?: ?=(%avar -.resolved)
7727− ?: =(n id.resolved) &
9686+ ?: |(?=(%avar -.resolved) ?=(%rvar -.resolved))
9687+ ?: =(n +.resolved) &
77289688 $(caps t.caps)
77299689 $(caps t.caps)
77309690::
@@ -7734,14 +9694,20 @@
77349694 ?- -.t
77359695 %var |
77369696 %avar =(n id.t)
9697+ %rvar =(n id.t)
77379698 %nvar |
9699+ %rnvar |
77389700 %atom |
77399701 %any-atom |
77409702 %flag |
9703+ %noun |
9704+ %empty |
77419705 %tag |
77429706 %const |
77439707 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
77449708 %recursive |
9709+ %jrec |
9710+ %grec (lien args.t |=(c=itype (has-atom-var n c)))
77459711 %collection (lien args.t |=(c=itype (has-atom-var n c)))
77469712 %face $(t body.t)
77479713 %fn |($(t sample.t) $(t product.t))
@@ -7781,6 +9747,10 @@
77819747 =/ out=tape ""
77829748 |-
77839749 ?~ vars out
9750+ ?: (itype-var-is-restricted i.vars t)
9751+ =/ sep=tape ?:(printed ", " " where ")
9752+ =/ clause=tape "{sep}{(show-itype [%rvar i.vars] ~)} is an atom other than ?"
9753+ $(vars t.vars, printed &, out (weld out clause))
77849754 ?: (itype-var-is-atom i.vars t)
77859755 =/ sep=tape ?:(printed ", " " where ")
77869756 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
@@ -7881,6 +9851,8 @@
78819851++ infer-recursive-gate
78829852 |= [d=def env=ienv state=istate]
78839853 ^- iresult
9854+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
9855+ =. gate-defs.state ~
78849856 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
78859857 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
78869858 [%| ["recursive definition is not a gate" ~]]
@@ -8090,6 +10062,7 @@
809010062 ?: (constrained-capitals caps.entry sub.state)
809110063 [%| ["explicit capital constraints are not supported by partial inference" ~]]
809210064 =/ typ=itype (itype-normalize typ.entry sub.state)
10065+ ?: (itype-has-nvar typ) [%| ["recursive group needs unsupported inference" ~]]
809310066 ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
809410067 [%| ["recursive group needs unsupported inference" ~]]
809510068 =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
@@ -8103,46 +10076,52 @@
810310076++ infer-gate-group
810410077 |= [ds=(list def) env=ienv state=istate]
810510078 ^- ilocal-result
10079+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
810610080 =/ names=(list term) (global-value-names ds)
810710081 ?. (levy names |=(n=term (unique-value-name n names)))
810810082 [%| ["recursive group contains duplicate names" ~]]
810910083 ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
811010084 [%| ["recursive group shadows a name" ~]]
8111− =/ scoped=istate state(globals (weld names globals.state))
10085+ =/ scoped=istate state(globals (weld names globals.state), gate-defs ~)
811210086 =/ seeded=igate-seeds (seed-gate-group ds env scoped)
811310087 ?: ?=(%| -.seeded) seeded
811410088 =/ seeds=ienv (group-seed-env entries.p.seeded ~)
811510089 =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
811610090 ?: ?=(%| -.body) body
10091+ :: Per-member ownership through mutual recursion is not implemented.
10092+ ?: !=(projections.state.p.body projections.state)
10093+ [%| ["record projection in recursive groups needs unsupported inference" ~]]
10094+ ?: !=(holes.state.p.body holes.state)
10095+ [%| ["holes in recursive groups need unsupported inference" ~]]
811710096 ?: (pending-tags tags.state.p.body sub.state.p.body)
811810097 [%| ["recursive group has unresolved literal constraints" ~]]
811910098 =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
812010099 ?: ?=(%| -.schemes) schemes
812110100 [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
812210101::
10102+++ width-finalize
10103+ |= [ps=(list iwprojection) sub=isub visible=(list @ud)]
10104+ ^- (unit (list iwprojection))
10105+ ?~ ps `~
10106+ ?: (lien t.ps |=(p=iwprojection =(at.p at.i.ps))) ~
10107+ =/ src=itype (default-decimals (itype-normalize source.i.ps sub))
10108+ =/ dst=itype (default-decimals (itype-normalize target.i.ps sub))
10109+ ?: |((itype-has-nvar src) (itype-has-nvar dst) (itype-has-tag src) (itype-has-tag dst)) ~
10110+ =/ vars=(list @ud) (weld (itype-vars src) (itype-vars dst))
10111+ ?. (levy vars |=(n=@ud (lien visible |=(v=@ud =(n v))))) ~
10112+ =/ rest=(unit (list iwprojection)) $(ps t.ps)
10113+ ?~ rest ~
10114+ =/ entry=iwprojection i.ps
10115+ =. entry entry(source src, target dst)
10116+ `[entry u.rest]
10117+::
812310118++ add-supported-defs
8124− |= [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)]
8125− ^- ienv
8126− ?~ ds env
8127− =/ d=def i.ds
8128− ?: ?=(%mold -.d) $(ds t.ds)
8129− ?. (unique-value-name name.d globals) $(ds t.ds)
8130− ?^ (ienv-lookup name.d env) $(ds t.ds)
8131− =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8132− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
8133− =. initial (reserve-def-caps val.d initial)
8134− =/ result=iresult (infer-fragment val.d env initial)
8135− =? result ?=(%| -.result) (infer-recursive-gate d env initial)
8136− ?: ?=(%| -.result) $(ds t.ds)
8137− ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
8138− =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
8139− ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
8140− ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
8141− =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
8142− ?: (gth (lent vars) 26) $(ds t.ds)
8143− $(ds t.ds, env [[name.d [typ vars]] env])
10119+ |= [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)]
10120+ ^- [env=ienv artifacts=(list iwidth-definition)]
10121+ (add-supported-defs-core ds all-defs checked heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts ~)
814410122::
8145−+$ iresolved [env=ienv grouped=(list term)]
10123+
10124++$ iresolved [env=ienv grouped=(list term) artifacts=(list iwidth-definition)]
814610125+$ iadj (map term (list term))
814710126+$ ivisited (map term ?)
814810127+$ iwork (list [name=term done=?])
@@ -8236,9 +10215,9 @@
823610215 (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
823710216::
823810217++ add-groups
8239− |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) state=istate]
10218+ |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) artifacts=(list iwidth-definition) state=istate]
824010219 ^- iresolved
8241− ?~ components [env grouped]
10220+ ?~ components [env grouped artifacts]
824210221 =/ component=(list term) i.components
824310222 ?. (graph-cycle component graph) $(components t.components)
824410223 ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
@@ -8255,25 +10234,186 @@
825510234++ resolve-groups
825610235 |= [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)]
825710236 ^- iresolved
10237+ (resolve-groups-core ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude ~)
10238+::
10239+
10240+++ add-supported-defs-core
10241+ |= [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)])]
10242+ ^- [env=ienv artifacts=(list iwidth-definition)]
10243+ ?~ ds [env artifacts]
10244+ =/ d=def i.ds
10245+ ?: ?=(%mold -.d) $(ds t.ds)
10246+ ?. (unique-value-name name.d globals) $(ds t.ds)
10247+ ?^ (ienv-lookup name.d env) $(ds t.ds)
10248+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10249+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10250+ =. grec-index.initial index
10251+ =. gate-defs.initial checked
10252+ =. head-evidence.initial heads
10253+ =. initial (reserve-def-caps val.d initial)
10254+ =/ result=iresult (infer-fragment val.d env initial)
10255+ =? result ?=(%| -.result) (infer-recursive-gate d env initial)
10256+ ?: ?=(%| -.result) $(ds t.ds)
10257+ =. state.p.result (promote-restricted-numbers state.p.result env)
10258+ =. 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)))
10259+ ?^ (unresolved-hole holes.state.p.result holes.initial state.p.result) $(ds t.ds)
10260+ ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
10261+ =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
10262+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
10263+ ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
10264+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
10265+ ?: (gth (lent vars) 26) $(ds t.ds)
10266+ =/ finalized=(unit (list iwprojection))
10267+ (width-finalize projections.state.p.result sub.state.p.result vars)
10268+ ?~ finalized $(ds t.ds)
10269+ =? artifacts ?=(^ u.finalized)
10270+ [[name.d val.d typ sub.state.p.result (flop u.finalized)] artifacts]
10271+ =? checked |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) (~(put by checked) name.d d)
10272+ $(ds t.ds, env [[name.d [typ vars]] env], checked checked)
10273+::
10274+++ resolve-groups-core
10275+ |= [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)])]
10276+ ^- iresolved
825810277 =/ env=ienv ~
825910278 =/ grouped=(list term) ~
10279+ =/ artifacts=(list iwidth-definition) ~
826010280 =/ names=(list term) (global-value-names ds)
826110281 =/ nameset=ivisited (graph-nameset names ~)
826210282 =/ graph=iadj (graph-make-forward ds nameset ~)
826310283 =/ components=icomponents (graph-components ds names)
826410284 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10285+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
826510286 |-
8266− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
8267− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
8268− =/ out=iresolved (add-groups ds components graph next grouped initial)
10287+ =/ next=[env=ienv artifacts=(list iwidth-definition)]
10288+ (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)
10289+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10290+ =. grec-index.initial index
10291+ =/ out=iresolved (add-groups ds components graph env.next grouped artifacts.next initial)
826910292 ?: =(env env.out) out
8270− $(env env.out, grouped grouped.out)
10293+ $(env env.out, grouped grouped.out, artifacts artifacts.out)
827110294::
827210295++ resolve-supported-defs
827310296 |= [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)]
827410297 ^- ienv
827510298 env:(resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
827610299::
10300+:: A diagnostic-only proof for a narrow syntactic value cycle. Every
10301+:: edge is an unqualified wing in a supported expression, and samples
10302+:: may not shadow global bindings. Unknown forms yield no conclusion.
10303++$ icyclesite [name=term at=span]
10304++$ icycle [name=term first=span next=span]
10305+++ cycle-sites-list
10306+ |= [xs=(list expr) globals=(list term) locals=(list term)]
10307+ ^- (unit (list icyclesite))
10308+ ?~ xs `~
10309+ =/ first=(unit (list icyclesite)) (cycle-sites i.xs globals locals)
10310+ ?~ first ~
10311+ =/ tail=(unit (list icyclesite)) $(xs t.xs)
10312+ ?~ tail ~
10313+ `(weld u.first u.tail)
10314+::
10315+++ cycle-sample-name
10316+ |= [sam=sample globals=(list term) locals=(list term)]
10317+ ^- (unit (unit term))
10318+ ?- -.sam
10319+ %bind
10320+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10321+ ``name.sam
10322+ %face
10323+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10324+ ``name.sam
10325+ %bare `~
10326+ * ~
10327+ ==
10328+::
10329+++ cycle-sites
10330+ |= [e=expr globals=(list term) locals=(list term)]
10331+ ^- (unit (list icyclesite))
10332+ ?- -.e
10333+ %wing
10334+ ?. ?=([@ ~] names.e) ~
10335+ `~[[i.names.e at.e]]
10336+ %lit `~
10337+ %str
10338+ ?: (lien pieces.e |=(p=piece ?=(%expr -.p))) ~
10339+ `~
10340+ %group $(e inner.e)
10341+ %body ?~(defs.e $(e final.e) ~)
10342+ %cast $(e val.e)
10343+ %gate
10344+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10345+ ?~ binder ~
10346+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10347+ $(e body.e, locals nested)
10348+ %gate-wide
10349+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10350+ ?~ binder ~
10351+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10352+ $(e body.e, locals nested)
10353+ %call
10354+ =/ first=(unit (list icyclesite)) $(e head.e)
10355+ ?~ first ~
10356+ =/ tail=(unit (list icyclesite)) (cycle-sites-list args.e globals locals)
10357+ ?~ tail ~
10358+ `(weld u.first u.tail)
10359+ * ~
10360+ ==
10361+::
10362+++ cycle-definitely-atom
10363+ |= e=expr
10364+ ^- ?
10365+ ?: ?=(%group -.e) $(e inner.e)
10366+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
10367+ ?. ?=(%cast -.e) |
10368+ |(?=(%aura -.shape.e) ?=(%flag -.shape.e))
10369+::
10370+++ cycle-proof-group
10371+ |= [members=(list def) globals=(list term)]
10372+ ^- ?
10373+ ?~ members &
10374+ ?. ?=(%value -.i.members) |
10375+ ?. (unique-value-name name.i.members globals) |
10376+ ?. ?=(^ (cycle-sites val.i.members globals ~)) |
10377+ $(members t.members)
10378+::
10379+++ cycle-find-site
10380+ |= [sites=(list icyclesite) component=(list term)]
10381+ ^- (unit span)
10382+ ?~ sites ~
10383+ ?: (lien component |=(n=term =(n name.i.sites))) `at.i.sites
10384+ $(sites t.sites)
10385+::
10386+++ cycle-group-errors
10387+ |= [members=(list def) component=(list term) globals=(list term)]
10388+ ^- (list icycle)
10389+ ?~ members ~
10390+ =/ d=def i.members
10391+ ?> ?=(%value -.d)
10392+ =/ tail=(list icycle) $(members t.members)
10393+ ?. (cycle-definitely-atom val.d) tail
10394+ =/ sites=(unit (list icyclesite)) (cycle-sites val.d globals ~)
10395+ ?~ sites tail
10396+ =/ found=(unit span) (cycle-find-site u.sites component)
10397+ ?~ found tail
10398+ [[name.d at.d u.found] tail]
10399+::
10400+++ definite-value-cycles
10401+ |= [ds=(list def) globals=(list term)]
10402+ ^- (list icycle)
10403+ =/ names=(list term) (global-value-names ds)
10404+ =/ graph=iadj (graph-make-forward ds (graph-nameset names ~) ~)
10405+ =/ components=icomponents (graph-components ds names)
10406+ =/ out=(list icycle) ~
10407+ |-
10408+ ?~ components out
10409+ =/ component=(list term) i.components
10410+ ?. (graph-cycle component graph) $(components t.components)
10411+ =/ members=(list def)
10412+ (skim ds |=(d=def &(?=(%value -.d) (lien component |=(n=term =(n name.d))))))
10413+ ?. =((lent members) (lent component)) $(components t.components)
10414+ ?. (cycle-proof-group members globals) $(components t.components)
10415+ $(components t.components, out (weld (cycle-group-errors members component globals) out))
10416+::
827710417+| %union-analysis
827810418::
827910419:: A conservative projection of written molds onto noun shapes. The
@@ -8396,6 +10536,257 @@
839610536 %overlap
839710537 %unknown
839810538::
10539+:: A source-only fallback for literal-tagged cells and one-hop local
10540+:: generic applications. It screens all work before ordinary inference.
10541+++ union-simple-shape-budget
10542+ |= [s=shape fuel=@ud vars=(unit (list @t))]
10543+ ^- (unit @ud)
10544+ ?: =(0 fuel) ~
10545+ =. fuel (dec fuel)
10546+ ?- -.s
10547+ ?(%aura %noun %void %flag) `fuel
10548+ %tvar
10549+ ?~ vars `fuel
10550+ ?:((lien u.vars |=(n=@t =(n name.s))) `fuel ~)
10551+ %const
10552+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10553+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10554+ `fuel
10555+ %cell (union-simple-fields-budget fields.s fuel vars)
10556+ %fn
10557+ =/ left=(unit @ud) $(s sample.s, fuel fuel)
10558+ ?~ left ~
10559+ $(s product.s, fuel u.left)
10560+ * ~
10561+ ==
10562+++ union-simple-fields-budget
10563+ |= [fields=(list field) fuel=@ud vars=(unit (list @t))]
10564+ ^- (unit @ud)
10565+ ?~ fields `fuel
10566+ ?: =(0 fuel) ~
10567+ =/ field-shape=shape
10568+ ?- -.i.fields
10569+ %bare shape.i.fields
10570+ %face shape.i.fields
10571+ %pun [%ref at.i.fields ~[name.i.fields]]
10572+ ==
10573+ =/ head=(unit @ud) (union-simple-shape-budget field-shape (dec fuel) vars)
10574+ ?~ head ~
10575+ $(fields t.fields, fuel u.head)
10576+++ union-source-find
10577+ |= [n=term molds=imolds fuel=@ud]
10578+ ^- (unit [body=shape left=@ud])
10579+ =/ found=(unit shape) ~
10580+ |-
10581+ ?~ molds
10582+ ?~ found ~
10583+ `[u.found fuel]
10584+ ?: =(0 fuel) ~
10585+ ?: =(n name.i.molds)
10586+ ?^ found ~
10587+ $(molds t.molds, fuel (dec fuel), found `body.i.molds)
10588+ $(molds t.molds, fuel (dec fuel))
10589+++ union-source-args-budget
10590+ |= [vars=(list @t) args=(list shape) fuel=@ud]
10591+ ^- (unit @ud)
10592+ =/ seen=(set @t) *(set @t)
10593+ |-
10594+ ?~ vars ?~(args `fuel ~)
10595+ ?~ args ~
10596+ ?: =(0 fuel) ~
10597+ ?: (~(has in:..zuse seen) i.vars) ~
10598+ =/ arg=(unit @ud) (union-simple-shape-budget i.args (dec fuel) ~)
10599+ ?~ arg ~
10600+ $(vars t.vars, args t.args, fuel u.arg, seen (~(put in:..zuse seen) i.vars))
10601+++ union-source-cell-tag
10602+ |= s=shape
10603+ ^- (unit @)
10604+ ?. ?=(%cell -.s) ~
10605+ ?~ fields.s ~
10606+ ?~ t.fields.s ~
10607+ ?. ?=(%bare -.i.fields.s) ~
10608+ =/ head=shape shape.i.fields.s
10609+ ?. ?=(%const -.head) ~
10610+ ?. |(=(%term form.lit.head) =(%null form.lit.head) =(%loobean form.lit.head)) ~
10611+ ?: &(=(%loobean form.lit.head) !|(=(0 val.lit.head) =(1 val.lit.head))) ~
10612+ `val.lit.head
10613+++ union-source-case-tag
10614+ |= [s=shape molds=imolds fuel=@ud]
10615+ ^- (unit [tag=@ left=@ud])
10616+ ?: ?=(%cell -.s)
10617+ =/ tag=(unit @) (union-source-cell-tag s)
10618+ ?~ tag ~
10619+ =/ left=(unit @ud) (union-simple-shape-budget s fuel ~)
10620+ ?~ left ~
10621+ `[u.tag u.left]
10622+ ?. ?=(%apply -.s) ~
10623+ ?. ?=([@ ~] ref.s) ~
10624+ ?: =(0 fuel) ~
10625+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10626+ ?~ found ~
10627+ ?. ?=(%generic -.body.u.found) ~
10628+ ?~ vars.body.u.found ~
10629+ =/ tag=(unit @) (union-source-cell-tag body.body.u.found)
10630+ ?~ tag ~
10631+ =/ args=(unit @ud) (union-source-args-budget vars.body.u.found args.s left.u.found)
10632+ ?~ args ~
10633+ =/ left=(unit @ud) (union-simple-shape-budget body.body.u.found u.args `vars.body.u.found)
10634+ ?~ left ~
10635+ `[u.tag u.left]
10636+++ union-source-distinct-tags
10637+ |= [cases=(list shape) molds=imolds fuel=@ud]
10638+ ^- ?
10639+ =/ seen=(set @) *(set @)
10640+ =/ has-application=? |
10641+ |-
10642+ ?~ cases has-application
10643+ ?: =(0 fuel) |
10644+ =/ item=(unit [tag=@ left=@ud]) (union-source-case-tag i.cases molds (dec fuel))
10645+ ?~ item |
10646+ ?: (~(has in:..zuse seen) tag.u.item) |
10647+ $(cases t.cases, fuel left.u.item, seen (~(put in:..zuse seen) tag.u.item), has-application |(has-application ?=(%apply -.i.cases)))
10648+::
10649+:: This inference-only screen bounds inherited work that the small source
10650+:: slice may consult. It does not authenticate a caller-created state.
10651+++ union-state-leaf
10652+ |= t=itype
10653+ ^- ?
10654+ ?=(?(%var %avar %rvar %nvar %rnvar %atom %any-atom %flag %noun %empty %const) -.t)
10655+++ union-state-params-budget
10656+ |= [params=iparams fuel=@ud]
10657+ ^- (unit @ud)
10658+ ?~ params `fuel
10659+ ?: =(0 fuel) ~
10660+ ?. (union-state-leaf typ.i.params) ~
10661+ $(params t.params, fuel (dec fuel))
10662+++ union-state-sub-budget
10663+ |= [sub=isub fuel=@ud]
10664+ ^- (unit @ud)
10665+ ?~ sub `fuel
10666+ ?: =(0 fuel) ~
10667+ ?. (union-state-leaf val.i.sub) ~
10668+ $(sub t.sub, fuel (dec fuel))
10669+++ union-state-caps-budget
10670+ |= [caps=icaps fuel=@ud]
10671+ ^- (unit @ud)
10672+ ?~ caps `fuel
10673+ ?: =(0 fuel) ~
10674+ $(caps t.caps, fuel (dec fuel))
10675+++ union-state-active-budget
10676+ |= [active=(list term) fuel=@ud]
10677+ ^- (unit @ud)
10678+ ?~ active `fuel
10679+ ?: =(0 fuel) ~
10680+ $(active t.active, fuel (dec fuel))
10681+++ union-state-tags-budget
10682+ |= [tags=(list ipending) fuel=@ud]
10683+ ^- (unit @ud)
10684+ ?~ tags `fuel
10685+ ?: =(0 fuel) ~
10686+ $(tags t.tags, fuel (dec fuel))
10687+++ union-source-state-safe
10688+ |= [state=istate fuel=@ud]
10689+ ^- ?
10690+ ?^ grec-index.state |
10691+ ?^ holes.state |
10692+ ?^ defer.state |
10693+ ?^ obligations.state |
10694+ =/ params=(unit @ud) (union-state-params-budget params.state fuel)
10695+ ?~ params |
10696+ =/ sub=(unit @ud) (union-state-sub-budget sub.state u.params)
10697+ ?~ sub |
10698+ =/ caps=(unit @ud) (union-state-caps-budget caps.state u.sub)
10699+ ?~ caps |
10700+ =/ active=(unit @ud) (union-state-active-budget active.state u.caps)
10701+ ?~ active |
10702+ ?=(^ (union-state-tags-budget tags.state u.active))
10703+::
10704+:: Positive overlap witnesses from parsed, one-hop local source only.
10705+:: Unknown or exhausted work returns no witness, never disjointness.
10706++$ uow-case [at=span head=@ payload=upat]
10707+++ union-overlap-primitive
10708+ |= s=shape
10709+ ^- (unit upat)
10710+ ?- -.s
10711+ %aura `[%atom ~]
10712+ %noun `[%all ~]
10713+ %void `[%empty ~]
10714+ %flag `[%flag ~]
10715+ %const
10716+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10717+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10718+ `[%atom `val.lit.s]
10719+ * ~
10720+ ==
10721+++ union-overlap-case
10722+ |= [s=shape molds=imolds fuel=@ud]
10723+ ^- (unit [item=uow-case left=@ud])
10724+ ?: =(0 fuel) ~
10725+ =. fuel (dec fuel)
10726+ :: Each body has exactly two fields; an application has exactly one
10727+ :: parameter and one concrete primitive argument. The full mold table
10728+ :: is scanned to establish unique ownership.
10729+ =/ expanded=(unit [body=shape param=(unit [name=@t pat=upat]) left=@ud])
10730+ ?: ?=(%cell -.s) `[s ~ fuel]
10731+ ?. ?=(%apply -.s) ~
10732+ ?. ?=([@ ~] ref.s) ~
10733+ ?. ?=([* ~] args.s) ~
10734+ ?: =(0 fuel) ~
10735+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10736+ ?~ found ~
10737+ ?. ?=(%generic -.body.u.found) ~
10738+ ?. ?=([@ ~] vars.body.u.found) ~
10739+ ?: =(0 left.u.found) ~
10740+ =/ argument=(unit upat) (union-overlap-primitive i.args.s)
10741+ ?~ argument ~
10742+ `[body.body.u.found `[i.vars.body.u.found u.argument] (dec left.u.found)]
10743+ ?~ expanded ~
10744+ =/ body=shape body.u.expanded
10745+ ?. ?=(%cell -.body) ~
10746+ ?. ?=([* * ~] fields.body) ~
10747+ :: Charge the cell, two fields, and the head and payload nodes.
10748+ ?: (lth left.u.expanded 5) ~
10749+ =/ head=(unit @) (union-source-cell-tag body)
10750+ ?~ head ~
10751+ =/ field=field i.t.fields.body
10752+ =/ payload=shape
10753+ ?- -.field
10754+ %bare shape.field
10755+ %face shape.field
10756+ %pun [%ref at.field ~[name.field]]
10757+ ==
10758+ =/ pattern=(unit upat)
10759+ ?: ?=(%tvar -.payload)
10760+ ?~ param.u.expanded ~
10761+ ?. =(name.payload name.u.param.u.expanded) ~
10762+ `pat.u.param.u.expanded
10763+ (union-overlap-primitive payload)
10764+ ?~ pattern ~
10765+ `[[at.s u.head u.pattern] (sub left.u.expanded 5)]
10766+++ union-overlap-against
10767+ |= [first=uow-case rest=(list shape) molds=imolds fuel=@ud]
10768+ ^- (unit [witness=(unit upair) left=@ud])
10769+ ?~ rest `[~ fuel]
10770+ ?: =(0 fuel) ~
10771+ =/ other=(unit [item=uow-case left=@ud]) (union-overlap-case i.rest molds (dec fuel))
10772+ ?~ other ~
10773+ ?: &(=(head.first head.item.u.other) =(%overlap (union-relate payload.first payload.item.u.other)))
10774+ `[`[at.first at.item.u.other %overlap] left.u.other]
10775+ $(rest t.rest, fuel left.u.other)
10776+++ union-source-overlap
10777+ |= [cases=(list shape) molds=imolds fuel=@ud]
10778+ ^- (unit upair)
10779+ ?~ cases ~
10780+ ?~ t.cases ~
10781+ ?: =(0 fuel) ~
10782+ =/ first=(unit [item=uow-case left=@ud]) (union-overlap-case i.cases molds (dec fuel))
10783+ ?~ first ~
10784+ =/ found=(unit [witness=(unit upair) left=@ud])
10785+ (union-overlap-against item.u.first t.cases molds left.u.first)
10786+ ?~ found ~
10787+ ?^ witness.u.found witness.u.found
10788+ $(cases t.cases, fuel left.u.found)
10789+::
839910790++ union-pairs
840010791 |= [cases=(list shape) molds=imolds]
840110792 ^- (list upair)
@@ -8409,15 +10800,151 @@
840910800 [at.first at.second (union-relate a (project-union-mold second molds ~))]
841010801 (weld pairs $(cases t.cases))
841110802::
8412−++ show-partial-mold
8413− |= [file=path src=@t d=def molds=imolds]
10803+:: A closed structural mold supplies no equation to determine a hole.
10804+:: Applications, references, unbound capitals and unions are unproved.
10805+++ simple-mold-hole
10806+ |= sh=shape
10807+ ^- (unit (unit span))
10808+ ?: ?=(%generic -.sh)
10809+ ?~ vars.sh ~
10810+ ?. (distinct-params vars.sh) ~
10811+ (simple-mold-hole-in body.sh vars.sh)
10812+ (simple-mold-hole-in sh ~)
10813+++ simple-mold-hole-in
10814+ |= [sh=shape vars=(list @t)]
10815+ ^- (unit (unit span))
10816+ ?- -.sh
10817+ %hole ``at.sh
10818+ ?(%aura %noun %void %flag %const) `~
10819+ %tvar ?:((lien vars |=(v=@t =(v name.sh))) `~ ~)
10820+ %cell (simple-mold-field-holes fields.sh vars)
10821+ %fn
10822+ =/ a=(unit (unit span)) $(sh sample.sh)
10823+ ?~ a ~
10824+ =/ b=(unit (unit span)) $(sh product.sh)
10825+ ?~ b ~
10826+ `?~(u.a u.b u.a)
10827+ %generic ~
10828+ * ~
10829+ ==
10830+++ simple-mold-field-holes
10831+ |= [fields=(list field) vars=(list @t)]
10832+ ^- (unit (unit span))
10833+ ?~ fields `~
10834+ =/ f=field i.fields
10835+ =/ first=(unit (unit span))
10836+ ?- -.f
10837+ %face (simple-mold-hole-in shape.f vars)
10838+ %bare (simple-mold-hole-in shape.f vars)
10839+ %pun ~
10840+ ==
10841+ ?~ first ~
10842+ =/ rest=(unit (unit span)) $(fields t.fields)
10843+ ?~ rest ~
10844+ `?~(u.first u.rest u.first)
10845+++ simple-local-mold-hole
10846+ |= defs=(list def)
10847+ ^- (unit span)
10848+ ?~ defs ~
10849+ ?. ?=(%mold -.i.defs) $(defs t.defs)
10850+ =/ found=(unit (unit span)) (simple-mold-hole shape.i.defs)
10851+ ?~ found $(defs t.defs)
10852+ ?^ u.found u.found
10853+ $(defs t.defs)
10854+::
10855+:: A partial prelude may omit unsupported declarations, but may not
10856+:: publish an interface while a named mold's hole remains unchecked.
10857+++ shape-has-hole
10858+ |= sh=shape
10859+ ^- ?
10860+ ?- -.sh
10861+ %hole &
10862+ %path (lien segs.sh |=(s=pseg ?=(%inferred -.s)))
10863+ %apply (lien args.sh shape-has-hole)
10864+ %union (lien cases.sh shape-has-hole)
10865+ %cell (lien fields.sh field-has-hole)
10866+ %fn |($(sh sample.sh) $(sh product.sh))
10867+ %generic $(sh body.sh)
10868+ * |
10869+ ==
10870+++ field-has-hole
10871+ |= f=field
10872+ ^- ?
10873+ ?- -.f
10874+ %face (shape-has-hole shape.f)
10875+ %bare (shape-has-hole shape.f)
10876+ %pun |
10877+ ==
10878+++ named-mold-has-hole
10879+ |= ds=(list def)
10880+ ^- ?
10881+ ?~ ds |
10882+ ?: &(?=(%mold -.i.ds) (shape-has-hole shape.i.ds)) &
10883+ $(ds t.ds)
10884+::
10885+++ sample-has-hole
10886+ |= sam=sample
10887+ ^- ?
10888+ ?- -.sam
10889+ %face (shape-has-hole shape.sam)
10890+ %bare (shape-has-hole shape.sam)
10891+ %cell (lien items.sam sample-has-hole)
10892+ * |
10893+ ==
10894+++ def-has-hole
10895+ |= d=def
10896+ ^- ?
10897+ ?- -.d
10898+ %mold (shape-has-hole shape.d)
10899+ %value (expr-has-hole val.d)
10900+ ==
10901+++ expr-has-hole
10902+ |= e=expr
10903+ ^- ?
10904+ ?- -.e
10905+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10906+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10907+ %change (lien edits.e |=(p=edit (expr-has-hole val.p)))
10908+ %pair $(e val.e)
10909+ %unit $(e val.e)
10910+ %group $(e inner.e)
10911+ %list (lien items.e expr-has-hole)
10912+ %tuple (lien items.e |=(i=item (expr-has-hole val.i)))
10913+ ?(%gate %gate-wide) |((sample-has-hole sample.e) $(e body.e))
10914+ %cast |((shape-has-hole shape.e) $(e val.e))
10915+ %call |($(e head.e) (lien args.e expr-has-hole))
10916+ %trace |($(e val.e) $(e then.e))
10917+ %branch |($(e subject.e) (lien arms.e |=(a=arm (expr-has-hole val.a))))
10918+ %body |((lien defs.e def-has-hole) $(e final.e))
10919+ * |
10920+ ==
10921+++ hole-values-present
10922+ |= [ds=(list def) env=ienv]
10923+ ^- ?
10924+ ?~ ds &
10925+ ?. ?=(%value -.i.ds) $(ds t.ds)
10926+ ?: (expr-has-hole val.i.ds)
10927+ ?. ?=(^ (ienv-lookup name.i.ds env)) |
10928+ $(ds t.ds)
10929+ $(ds t.ds)
10930+++ show-partial-mold
10931+ |= [file=path src=@t d=def molds=imolds]
841410932 ^- @t
841510933 ?> ?=(%mold -.d)
841610934 =/ sh=shape shape.d
10935+ =/ hole=(unit (unit span)) (simple-mold-hole sh)
10936+ ?: &(?=(^ hole) ?=(^ u.hole))
10937+ =/ text=@t (show-error src [file line.beg.u.u.hole col.beg.u.u.hole "unresolved type hole"])
10938+ (of-wain:format ~[(crip "+$ {(trip name.d)}: type hole needs a determined type") text])
841710939 =? sh ?=(%generic -.sh) body.sh
841810940 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
841910941 =/ pairs=(list upair) (union-pairs cases.sh molds)
842010942 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
10943+ =. overlapping
10944+ ?^ overlapping overlapping
10945+ ?. (lien pairs |=(p=upair =(%unknown relation.p))) ~
10946+ =/ witness=(unit upair) (union-source-overlap cases.sh molds 256)
10947+ ?~(witness ~ ~[u.witness])
842110948 ?^ overlapping
842210949 =/ p=upair i.overlapping
842310950 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
@@ -8425,7 +10952,9 @@
842510952 =/ second=@t (show-error src [file line.beg.second.p col.beg.second.p "overlapping case"])
842610953 (of-wain:format ~[summary first second])
842710954 ?: (lien pairs |=(p=upair =(%unknown relation.p)))
8428− (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10955+ ?. (union-source-distinct-tags cases.sh molds 256)
10956+ (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10957+ (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
842910958 (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
843010959::
843110960:: +show-inference-diagnostic: a partial report with both source sites
@@ -8440,6 +10969,21 @@
844010969 (show-error src [file line.beg.at.site col.beg.at.site note.site])
844110970 (of-wain:format [summary excerpts])
844210971::
10972+:: Both written field sites are shown in the source that declares them.
10973+++ show-duplicate-fields
10974+ |= [file=path src=@t diagnostic=idiag]
10975+ ^- @t
10976+ =/ excerpts=(list @t)
10977+ %+ turn sites.diagnostic
10978+ |= site=[at=span note=tape]
10979+ (show-error src [file line.beg.at.site col.beg.at.site note.site])
10980+ (of-wain:format [(crip msg.diagnostic) excerpts])
10981+::
10982+++ duplicate-fields-report
10983+ |= [file=path src=@t diagnostic=idiag]
10984+ ^- @t
10985+ (of-wain:format ~['partial inference; module not checked' (show-duplicate-fields file src diagnostic)])
10986+::
844310987:: +golden-types: a partial report; it does not claim the module checks
844410988::
844510989++ golden-types
@@ -8467,8 +11011,189 @@
846711011+$ jbundle (list jsource)
846811012+$ jcache (list [at=path iface=ifile])
846911013+$ jfile-result (each [iface=ifile cache=jcache] @t)
11014+:: Overlap evidence retains the exact source that supplied its spans.
11015+:: Ordinary Jibb imports preserve this evidence through the resolver.
11016++$ jfile-overlap [file=path source=@t name=term cases=upair]
11017++$ jfile-failure [message=@t overlap=(unit jfile-overlap)]
11018++$ jfile-detailed-result (each [iface=ifile cache=jcache] jfile-failure)
847011019+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
11020+:: Preserve an imported overlap's original file and source across the graph.
11021++$ jimports-detailed-result (each [resolved=ijimports cache=jcache] jfile-failure)
847111022::
11023+:: Written record fields each have their own lexical record scope.
11024++$ written-fields (map term span)
11025+++ duplicate-written-field
11026+ |= [name=term at=span seen=written-fields]
11027+ ^- (unit idiag)
11028+ =/ prior=(unit span) (~(get by seen) name)
11029+ ?~ prior ~
11030+ `["record field `{(trip name)}` is repeated" ~[[u.prior "first field"] [at "repeated field"]]]
11031+++ duplicate-shapes
11032+ |= xs=(list shape)
11033+ ^- (unit idiag)
11034+ ?~ xs ~
11035+ =/ first (duplicate-shape i.xs)
11036+ ?^ first first
11037+ $(xs t.xs)
11038+++ duplicate-fields
11039+ |= [fields=(list field) seen=written-fields]
11040+ ^- (unit idiag)
11041+ ?~ fields ~
11042+ =/ f=field i.fields
11043+ =/ n=(unit term)
11044+ ?- -.f
11045+ %face `name.f
11046+ %pun `name.f
11047+ %bare ~
11048+ ==
11049+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.f seen))
11050+ ?^ dup dup
11051+ =/ inner=(unit idiag)
11052+ ?- -.f
11053+ %face (duplicate-shape shape.f)
11054+ %pun ~
11055+ %bare (duplicate-shape shape.f)
11056+ ==
11057+ ?^ inner inner
11058+ $(fields t.fields, seen ?~(n seen (~(put by seen) u.n at.f)))
11059+++ duplicate-shape
11060+ |= s=shape
11061+ ^- (unit idiag)
11062+ ?- -.s
11063+ %cell (duplicate-fields fields.s ~)
11064+ %apply (duplicate-shapes args.s)
11065+ %union (duplicate-shapes cases.s)
11066+ %fn
11067+ =/ left (duplicate-shape sample.s)
11068+ ?^ left left
11069+ (duplicate-shape product.s)
11070+ %generic (duplicate-shape body.s)
11071+ * ~
11072+ ==
11073+++ duplicate-samples
11074+ |= [items=(list sample) seen=written-fields]
11075+ ^- (unit idiag)
11076+ ?~ items ~
11077+ =/ a=sample i.items
11078+ =/ n=(unit term)
11079+ ?- -.a
11080+ %bind `name.a
11081+ %face `name.a
11082+ %pun `name.a
11083+ * ~
11084+ ==
11085+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.a seen))
11086+ ?^ dup dup
11087+ =/ inner (duplicate-sample a)
11088+ ?^ inner inner
11089+ $(items t.items, seen ?~(n seen (~(put by seen) u.n at.a)))
11090+++ duplicate-sample
11091+ |= s=sample
11092+ ^- (unit idiag)
11093+ ?- -.s
11094+ %cell (duplicate-samples items.s ~)
11095+ %face (duplicate-shape shape.s)
11096+ %bare (duplicate-shape shape.s)
11097+ * ~
11098+ ==
11099+++ duplicate-exprs
11100+ |= xs=(list expr)
11101+ ^- (unit idiag)
11102+ ?~ xs ~
11103+ =/ first (duplicate-expr i.xs)
11104+ ?^ first first
11105+ $(xs t.xs)
11106+++ duplicate-items
11107+ |= [items=(list item) seen=written-fields]
11108+ ^- (unit idiag)
11109+ ?~ items ~
11110+ =/ a=item i.items
11111+ =/ dup=(unit idiag) ?~(face.a ~ (duplicate-written-field u.face.a at.a seen))
11112+ ?^ dup dup
11113+ =/ inner (duplicate-expr val.a)
11114+ ?^ inner inner
11115+ $(items t.items, seen ?~(face.a seen (~(put by seen) u.face.a at.a)))
11116+++ duplicate-pieces
11117+ |= pieces=(list piece)
11118+ ^- (unit idiag)
11119+ ?~ pieces ~
11120+ =/ first=(unit idiag) ?:(?=(%expr -.i.pieces) (duplicate-expr p.i.pieces) ~)
11121+ ?^ first first
11122+ $(pieces t.pieces)
11123+++ duplicate-qsegs
11124+ |= segs=(list qseg)
11125+ ^- (unit idiag)
11126+ ?~ segs ~
11127+ =/ first=(unit idiag) ?:(?=(%expr -.i.segs) (duplicate-expr p.i.segs) ~)
11128+ ?^ first first
11129+ $(segs t.segs)
11130+++ duplicate-edits
11131+ |= edits=(list edit)
11132+ ^- (unit idiag)
11133+ ?~ edits ~
11134+ =/ first (duplicate-expr val.i.edits)
11135+ ?^ first first
11136+ $(edits t.edits)
11137+++ duplicate-arms
11138+ |= arms=(list arm)
11139+ ^- (unit idiag)
11140+ ?~ arms ~
11141+ =/ first (duplicate-expr val.i.arms)
11142+ ?^ first first
11143+ $(arms t.arms)
11144+++ duplicate-defs
11145+ |= defs=(list def)
11146+ ^- (unit idiag)
11147+ ?~ defs ~
11148+ =/ first=(unit idiag)
11149+ ?- -.i.defs
11150+ %mold (duplicate-shape shape.i.defs)
11151+ %value (duplicate-expr val.i.defs)
11152+ ==
11153+ ?^ first first
11154+ $(defs t.defs)
11155+++ duplicate-expr
11156+ |= e=expr
11157+ ^- (unit idiag)
11158+ ?- -.e
11159+ %str (duplicate-pieces pieces.e)
11160+ %qath (duplicate-qsegs segs.e)
11161+ %change (duplicate-edits edits.e)
11162+ %pair (duplicate-expr val.e)
11163+ %unit (duplicate-expr val.e)
11164+ %group (duplicate-expr inner.e)
11165+ %list (duplicate-exprs items.e)
11166+ %tuple (duplicate-items items.e ~)
11167+ %gate-wide
11168+ =/ first (duplicate-sample sample.e)
11169+ ?^ first first
11170+ (duplicate-expr body.e)
11171+ %gate
11172+ =/ first (duplicate-sample sample.e)
11173+ ?^ first first
11174+ (duplicate-expr body.e)
11175+ %cast
11176+ =/ first (duplicate-shape shape.e)
11177+ ?^ first first
11178+ (duplicate-expr val.e)
11179+ %call
11180+ =/ first (duplicate-expr head.e)
11181+ ?^ first first
11182+ (duplicate-exprs args.e)
11183+ %trace
11184+ =/ first (duplicate-expr val.e)
11185+ ?^ first first
11186+ (duplicate-expr then.e)
11187+ %branch
11188+ =/ first (duplicate-expr subject.e)
11189+ ?^ first first
11190+ (duplicate-arms arms.e)
11191+ %body
11192+ =/ first (duplicate-defs defs.e)
11193+ ?^ first first
11194+ (duplicate-expr final.e)
11195+ * ~
11196+ ==
847211197++ import-binding-names
847311198 |= imports=(list import)
847411199 ^- (list term)
@@ -8481,6 +11206,60 @@
848111206 ==
848211207 [n $(imports t.imports)]
848311208::
11209+++ reserved-proj-sample
11210+ |= sam=sample
11211+ ^- ?
11212+ ?- -.sam
11213+ %bind =(name.sam %proj)
11214+ %face =(name.sam %proj)
11215+ %pun =(name.sam %proj)
11216+ %cell (lien items.sam reserved-proj-sample)
11217+ * |
11218+ ==
11219+++ reserved-proj-pattern
11220+ |= p=pattern
11221+ ^- ?
11222+ ?- -.p
11223+ %bind =(name.p %proj)
11224+ %cell (lien items.p reserved-proj-pattern)
11225+ * |
11226+ ==
11227+++ reserved-proj-def
11228+ |= d=def
11229+ ^- ?
11230+ ?: =(name.d %proj) &
11231+ ?: ?=(%value -.d) (reserved-proj-expr val.d)
11232+ |
11233+++ reserved-proj-expr
11234+ |= e=expr
11235+ ^- ?
11236+ ?- -.e
11237+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11238+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11239+ %change (lien edits.e |=(p=edit (reserved-proj-expr val.p)))
11240+ %pair $(e val.e)
11241+ %unit $(e val.e)
11242+ %group $(e inner.e)
11243+ %list (lien items.e reserved-proj-expr)
11244+ %tuple (lien items.e |=(i=item (reserved-proj-expr val.i)))
11245+ ?(%gate %gate-wide) |((reserved-proj-sample sample.e) $(e body.e))
11246+ %cast $(e val.e)
11247+ %call |($(e head.e) (lien args.e reserved-proj-expr))
11248+ %trace |($(e val.e) $(e then.e))
11249+ %branch |($(e subject.e) (lien arms.e |=(a=arm |((reserved-proj-pattern pat.a) (reserved-proj-expr val.a)))))
11250+ %body |((lien defs.e reserved-proj-def) $(e final.e))
11251+ * |
11252+ ==
11253+::
11254+++ module-has-reserved-proj
11255+ |= mod=module
11256+ ^- ?
11257+ =/ imported=(list term) (import-binding-names imports.mod)
11258+ =/ vals=(list term) (global-value-names defs.mod)
11259+ =/ molds=imolds (collect-simple-molds defs.mod)
11260+ =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11261+ |((lien (weld imported (weld vals mold-names)) |=(n=term =(n %proj))) (lien defs.mod reserved-proj-def))
11262+::
848411263++ module-scope-valid
848511264 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
848611265 ^- ?
@@ -8488,6 +11267,7 @@
848811267 =/ vals=(list term) (global-value-names defs.mod)
848911268 =/ molds=imolds (collect-simple-molds defs.mod)
849011269 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11270+ ?: (module-has-reserved-proj mod) |
849111271 ?. %+ levy imported
849211272 |= n=term
849311273 &((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))))
@@ -8495,6 +11275,59 @@
849511275 ?. (levy vals |=(n=term &((unique-value-name n vals) !(lien prelude-values |=(v=term =(n v)))))) |
849611276 (levy mold-names |=(n=term &((unique-value-name n mold-names) !(lien prelude-molds |=(m=term =(n m))))))
849711277::
11278+:: In an API file or before main's kind is known, a lone `+$ poke`
11279+:: may be a declaration rather than a mold that shadows the prelude. Do not call
11280+:: that one collision definite, and do not hide unrelated scope errors.
11281+++ pending-declared-poke
11282+ |= [at=path mod=module prelude-values=(list term) prelude-molds=(list term)]
11283+ ^- ?
11284+ ?. (lien prelude-molds |=(n=term =(%poke n))) |
11285+ ?. |(?=([%ui %api @ %jibb ~] at) (lien defs.mod |=(d=def &(?=(%value -.d) =(%main name.d))))) |
11286+ =/ pokes=(list def)
11287+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11288+ ?~ pokes |
11289+ ?^ t.pokes |
11290+ =/ remaining=(list def)
11291+ (skim defs.mod |=(d=def !&(?=(%mold -.d) =(%poke name.d))))
11292+ (module-scope-valid mod(defs remaining) prelude-values prelude-molds)
11293+::
11294+:: A detailed failure is attached only to the first mold that actually
11295+:: failed in this check, using that module's checked source mold table.
11296++$ imold-failure [message=@t overlap=(unit [name=term cases=upair])]
11297+:: Validate a generic wrapper without an unbounded duplicate-name pass.
11298+++ module-mold-params-valid
11299+ |= [vars=(list @t) seen=(set @t) fuel=@ud]
11300+ ^- ?
11301+ ?~ vars &
11302+ ?: =(0 fuel) |
11303+ ?: (~(has in:..zuse seen) i.vars) |
11304+ $(vars t.vars, seen (~(put in:..zuse seen) i.vars), fuel (dec fuel))
11305+++ module-mold-overlap
11306+ |= [m=[name=term body=shape] molds=imolds]
11307+ ^- (unit upair)
11308+ =/ sh=shape body.m
11309+ =/ valid=?
11310+ ?. ?=(%generic -.sh) &
11311+ ?~ vars.sh |
11312+ (module-mold-params-valid vars.sh *(set @t) 256)
11313+ ?. valid ~
11314+ =? sh ?=(%generic -.sh) body.sh
11315+ ?. ?=(%union -.sh) ~
11316+ (union-source-overlap cases.sh molds 256)
11317+++ module-mold-types-detail
11318+ |= [molds=imolds state=istate]
11319+ ^- (each imold-types imold-failure)
11320+ ?~ molds [%& ~]
11321+ =/ m=[name=term body=shape] i.molds
11322+ =/ t=(unit [template=ischeme state=istate])
11323+ (infer-mold-template body.m state(active [name.m active.state], in-mold &))
11324+ ?~ t
11325+ =/ overlap=(unit upair) (module-mold-overlap m molds.state)
11326+ [%| ['module mold needs unsupported inference' ?~(overlap ~ `[name.m u.overlap])]]
11327+ =. typ.template.u.t (label-direct-union typ.template.u.t body.m name.m state)
11328+ =/ rest=(each imold-types imold-failure) $(molds t.molds)
11329+ ?: ?=(%| -.rest) rest
11330+ [%& [[name.m template.u.t] p.rest]]
849811331++ module-mold-types
849911332 |= [molds=imolds state=istate]
850011333 ^- (each imold-types @t)
@@ -8510,9 +11343,9 @@
851011343::
851111344:: Prepare a provisional interface from the trusted vendored source.
851211345:: Every declared name remains reserved, but only molds and values this
8513−:: fragment can infer are usable. Unsupported bodies are not validated,
8514−:: and imports into the prelude are not supported yet. The fixed origin
8515−:: gives its named unions the same identity in every importing module.
11346+:: fragment can infer are usable. Unsupported bodies are not validated.
11347+:: An optional internal source supplies the prelude's one supported import;
11348+:: clients cannot import that path directly. Named unions retain their origin.
851611349::
851711350:: Recognize only the complete standard prelude list shape. Its recursive
851811351:: tail uses the same parameter and the unqualified list name. The reader
@@ -8552,6 +11385,20 @@
855211385 ?. ?=(%tvar -.i.args.tail) |
855311386 =(var name.i.args.tail)
855411387::
11388+++ prelude-label
11389+ |= [typ=itype name=term vars=(list @ud)]
11390+ ^- itype
11391+ ?: ?=(%jrec -.typ) typ(label `name)
11392+ ?: ?=(%grec -.typ)
11393+ ?. (identity-union-parameters vars args.typ) typ(label ~)
11394+ typ(label `name)
11395+ ?. ?=(%union -.typ) typ
11396+ ?. (identity-union-parameters vars args.typ)
11397+ ?~ origin.typ typ
11398+ ?: =(at.u.origin.typ /lib/jibb/internal/jibb) typ(label ~)
11399+ typ
11400+ typ(label `name)
11401+::
855511402++ partial-prelude-molds
855611403 |= [molds=imolds state=istate]
855711404 ^- imold-types
@@ -8564,22 +11411,129 @@
856411411 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
856511412 ?~ out $(molds t.molds)
856611413 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
11414+ =. typ.template.u.out (prelude-label typ.template.u.out name.m vars.template.u.out)
856711415 [[name.m template.u.out] $(molds t.molds)]
856811416::
8569−++ partial-prelude-interface
8570− |= src=@t
11417+:: A compiler-owned interface available only to the dedicated
11418+:: internal-prelude preparation path, never the ordinary module resolver.
11419+++ private-primitive-interface
11420+ ^- ifile
11421+ =/ a=itype [%avar 0]
11422+ =/ pair=itype [%cell a a]
11423+ =/ b=itype [%rvar 0]
11424+ =/ plus=ischeme [[%fn [%cell b b] b] ~[0]]
11425+ =/ minus=ischeme [[%fn b b] ~[0]]
11426+ =/ greater=ischeme [[%fn pair [%flag ~]] ~[0]]
11427+ =/ utf8=itype [%atom 'tD']
11428+ =/ tape=itype [%collection %list ~[utf8]]
11429+ =/ codepoints=itype [%collection %list ~[[%atom %c]]]
11430+ =/ text-trip=ischeme [[%fn [%atom %t] tape] ~]
11431+ =/ text-tuba=ischeme [[%fn tape codepoints] ~]
11432+ [~[[%raw-add plus] [%raw-dec minus] [%raw-gth greater] [%raw-trip text-trip] [%raw-tuba text-tuba]] ~ /lib/jibb/primitives/jibb ~ ~ ~ ~ ~]
11433+::
11434+++ infer-private-internal
11435+ |= [src=@t public-source=@t]
11436+ ^- (unit ifile)
11437+ =/ at=path /lib/jibb/internal/jibb
11438+ =/ parsed (parse at src)
11439+ ?: ?=(%| -.parsed) ~
11440+ =/ mod=module p.parsed
11441+ ?^ (duplicate-defs defs.mod) ~
11442+ ?~ imports.mod
11443+ =/ built=jfile-result (infer-jibb-file at src ~ ~ ~ ~[at] ~ ~ ~ ~)
11444+ ?: ?=(%| -.built) ~
11445+ `iface.p.built
11446+ ?. ?=([[%jibb *] ~] imports.mod) ~
11447+ ?. =(path.i.imports.mod /lib/jibb/primitives) ~
11448+ ?. (module-scope-valid mod ~ ~) ~
11449+ =/ vals=(list term) (global-value-names defs.mod)
11450+ ?: (lien vals |=(n=term =(n %main))) ~
11451+ =/ molds=imolds (collect-simple-molds defs.mod)
11452+ =/ globals=(list term) (weld (import-binding-names imports.mod) vals)
11453+ :: The private source can use the public list and unit molds before the
11454+ :: prelude is otherwise prepared. Re-read the trusted public source here
11455+ :: and admit only its validated canonical templates; do not accept schemes
11456+ :: supplied independently by the caller.
11457+ =/ public=(each module error) (parse /lib/jibb/prelude/jibb public-source)
11458+ ?: ?=(%| -.public) ~
11459+ ?^ (duplicate-defs defs.p.public) ~
11460+ ?. (module-scope-valid p.public ~ ~) ~
11461+ =/ source-molds=imolds (collect-simple-molds defs.p.public)
11462+ =/ written-list=(unit shape) (find-simple-mold %list source-molds)
11463+ =/ source-list=(unit ischeme)
11464+ ?~ written-list ~
11465+ ?. (standard-prelude-list u.written-list) ~
11466+ `[[%collection %list ~[[%var 0]]] ~[0]]
11467+ :: Derive the public unit template from its actual source, then compare
11468+ :: the complete nominal template before making it available privately.
11469+ =/ unit-decl=(unit shape) (find-simple-mold %unit source-molds)
11470+ =/ source-unit=(unit ischeme)
11471+ ?~ unit-decl ~
11472+ =/ unit-molds=imolds ~[[%unit u.unit-decl]]
11473+ =/ unit-state=istate [0 ~ ~ ~ unit-molds ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | /lib/jibb/prelude/jibb ~[%unit] ~ ~ 256 ~ ~ ~ ~ ~ ~]
11474+ =/ unit-types=imold-types (partial-prelude-molds unit-molds unit-state)
11475+ =/ unit-iface=ifile [~ unit-types /lib/jibb/prelude/jibb ~ ~ ~ ~ ~]
11476+ =/ found=(unit ischeme) (find-jibb-mold %unit unit-iface)
11477+ ?~ found ~
11478+ ?. (standard-unit-template u.found /lib/jibb/prelude/jibb) ~
11479+ found
11480+ =/ primitive=ifile private-primitive-interface
11481+ =? primitive ?=(^ source-list)
11482+ primitive(molds [[%list u.source-list] molds.primitive])
11483+ =? primitive ?=(^ source-unit)
11484+ primitive(molds [[%unit u.source-unit] molds.primitive])
11485+ =/ js=ijimports ~[[face.i.imports.mod primitive]]
11486+ =/ reserved=(list term) ~[face.i.imports.mod]
11487+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11488+ =/ state=istate [0 ~ ~ ~ molds globals ~ ~ ~ ~ js reserved ~ ~ ~ | at top ~ ~ 256 ~ ~ ~ ~ ~ ~]
11489+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11490+ =/ usable=(unit imold-types)
11491+ ?: ?=(%& -.mts) `p.mts
11492+ :: Missing public templates may make an unrelated internal mold
11493+ :: unavailable. Validate all molds once with isolated canonical
11494+ :: templates before admitting only those inferred using the actual
11495+ :: source-backed templates. The proof interface is never exported.
11496+ ?. |(?=(~ source-list) ?=(~ source-unit)) ~
11497+ =/ nil=itype [%const [%null %n 0 '~']]
11498+ =/ canonical-unit=ischeme
11499+ [[%union ~[nil [%cell nil [%face %u [%var 0]]]] `[/lib/jibb/prelude/jibb %unit] `%unit ~[[%var 0]]] ~[0]]
11500+ =/ canonical-list=ischeme [[%collection %list ~[[%var 0]]] ~[0]]
11501+ =/ proof-primitive=ifile private-primitive-interface
11502+ =. molds.proof-primitive ~[[%list canonical-list] [%unit canonical-unit]]
11503+ =/ proof-imports=ijimports ~[[face.i.imports.mod proof-primitive]]
11504+ =/ proof=(each imold-types @t) (module-mold-types molds state(jimports proof-imports))
11505+ ?: ?=(%| -.proof) ~
11506+ `(partial-prelude-molds molds state)
11507+ ?~ usable ~
11508+ =/ resolution=iresolved (resolve-groups defs.mod molds globals ~ ~ ~ ~ js reserved at ~)
11509+ =/ env=ienv env.resolution
11510+ ?. (module-values-complete defs.mod env) ~
11511+ `[env u.usable at ~ artifacts.resolution ~ `src ~]
11512+::
11513+++ partial-prelude-interface-with-internal
11514+ |= [src=@t internal-source=(unit @t)]
857111515 ^- (unit ifile)
857211516 ?: =(0 src) ~
857311517 =/ at=path /lib/jibb/prelude/jibb
857411518 =/ parsed (parse at src)
857511519 ?: ?=(%| -.parsed) ~
8576− ?^ imports.p.parsed ~
11520+ ?: (named-mold-has-hole defs.p.parsed) ~
11521+ ?^ (duplicate-defs defs.p.parsed) ~
11522+ =/ private=(unit ijimports)
11523+ ?~ imports.p.parsed `~
11524+ ?. ?=([[%jibb *] ~] imports.p.parsed) ~
11525+ ?. =(path.i.imports.p.parsed /lib/jibb/internal) ~
11526+ ?~ internal-source ~
11527+ =/ built=(unit ifile) (infer-private-internal u.internal-source src)
11528+ ?~ built ~
11529+ `~[[face.i.imports.p.parsed u.built]]
11530+ ?~ private ~
857711531 ?~ defs.p.parsed ~
857811532 ?. (module-scope-valid p.parsed ~ ~) ~
857911533 =/ ds=(list def) defs.p.parsed
858011534 =/ molds=imolds (collect-simple-molds ds)
858111535 =/ names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8582− =/ globals=(list term) (global-value-names ds)
11536+ =/ globals=(list term) (weld (import-binding-names imports.p.parsed) (global-value-names ds))
858311537 :: Remove raw list before inferring any template, so an altered list
858411538 :: cannot leak through an alias. Its name remains reserved either way.
858511539 =/ declared=? (lien names |=(name=term =(%list name)))
@@ -8587,11 +11541,38 @@
858711541 =? env-molds declared
858811542 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
858911543 =/ reserved=(list term) ?:(declared ~[%list] ~)
8590− =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ ~ reserved ~ ~ ~ | at names ~]
8591− =/ mt=imold-types (partial-prelude-molds molds state)
8592− =/ partial=ifile [~ mt at]
8593− =/ env=ienv (resolve-supported-defs ds env-molds globals ~ ~ ~ ~ ~ reserved at `partial)
8594− `[env mt at]
11544+ =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~ ~ 256 ~ ~ ~ ~ ~ ~]
11545+ :: Other prelude molds may use list only after its source has passed
11546+ :: the standard-list check. The raw declaration remains removed.
11547+ =/ declared-list=(unit shape) (find-simple-mold %list molds)
11548+ =/ mold-prelude=(unit ifile)
11549+ ?~ declared-list ~
11550+ ?. (standard-prelude-list u.declared-list) ~
11551+ `[~ ~[[%list [[%collection %list ~[[%var 0]]] ~[0]]]] at ~ ~ ~ ~ ~]
11552+ =/ mt=imold-types (partial-prelude-molds molds state(prelude mold-prelude))
11553+ =/ partial=ifile [~ mt at ~ ~ ~ ~ ~]
11554+ :: An explicitly qualified re-export must resolve. Other unsupported
11555+ :: prelude declarations remain reserved but absent from the interface.
11556+ =/ required=imolds
11557+ %+ skim molds
11558+ |= m=[name=term body=shape]
11559+ =/ sh=shape body.m
11560+ ?. ?=(%ref -.sh) |
11561+ ?~ names.sh |
11562+ ?=(^ t.names.sh)
11563+ ?. (levy required |=(m=[name=term body=shape] ?=(^ (find-jibb-mold name.m partial)))) ~
11564+ =/ resolution=iresolved (resolve-groups ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
11565+ =/ env=ienv env.resolution
11566+ ?. (hole-values-present ds env) ~
11567+ =/ deps=(list iwidth-dependency)
11568+ ?~ u.private ~
11569+ ~[[at.interface.i.u.private source.interface.i.u.private elaborations.interface.i.u.private]]
11570+ `[env mt at ~ artifacts.resolution deps `src ~]
11571+::
11572+++ partial-prelude-interface
11573+ |= src=@t
11574+ ^- (unit ifile)
11575+ (partial-prelude-interface-with-internal src ~)
859511576::
859611577+$ iprelude [iface=ifile values=(list term) molds=(list term)]
859711578::
@@ -8606,6 +11587,17 @@
860611587 =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
860711588 `[u.iface vals ms]
860811589::
11590+++ prepare-prelude-with-internal
11591+ |= [src=@t internal-source=@t]
11592+ ^- (unit iprelude)
11593+ =/ iface=(unit ifile) (partial-prelude-interface-with-internal src `internal-source)
11594+ ?~ iface ~
11595+ =/ parsed (parse /lib/jibb/prelude/jibb src)
11596+ ?: ?=(%| -.parsed) ~
11597+ =/ vals=(list term) (global-value-names defs.p.parsed)
11598+ =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
11599+ `[u.iface vals ms]
11600+::
860911601++ module-values-complete
861011602 |= [ds=(list def) env=ienv]
861111603 ^- ?
@@ -8626,52 +11618,1088 @@
862611618 ?: =(at at.i.cache) `iface.i.cache
862711619 $(cache t.cache)
862811620::
11621+:: These certificates retain the complete checked source closure. The
11622+:: trusted host must supply the identical prepared prelude and reader nouns.
11623+:: Exact bundle equality binds all source paths and versions; the set
11624+:: retains transitive paths for active-cycle checks. Request-bearing graphs
11625+:: alone have a size limit; incompatible diamond evidence fails closed.
11626+++ request-graph-requests-add
11627+ |= [pending=(list irequest-evidence) acc=(list irequest-evidence) fuel=@ud]
11628+ ^- (unit (list irequest-evidence))
11629+ ?~ pending `acc
11630+ ?: =(0 fuel) ~
11631+ =/ hit=(list irequest-evidence)
11632+ (skim acc |=(x=irequest-evidence &(=(api-at.x api-at.i.pending) =(name.x name.i.pending))))
11633+ ?^ hit
11634+ ?. ?=([* ~] hit) ~
11635+ ?. =(i.hit i.pending) ~
11636+ $(pending t.pending, fuel (dec fuel))
11637+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11638+++ request-graph-inputs-match
11639+ |= [g=irequest-graph externals=iexternals marks=imark-externals modules=jbundle values=(list term) molds=(list term) prelude=(unit ifile)]
11640+ ^- ?
11641+ ?& =(bundle-input.g modules)
11642+ =(prelude-input.g prelude)
11643+ =(prelude-values.g values)
11644+ =(prelude-molds.g molds)
11645+ =(externals.g externals)
11646+ =(marks.g marks)
11647+ ==
11648+++ request-graph-merge
11649+ |= [imports=ijimports g=irequest-graph fuel=@ud]
11650+ ^- (unit irequest-graph)
11651+ ?~ imports `g
11652+ ?: =(0 fuel) ~
11653+ =/ child=ifile interface.i.imports
11654+ ?~ graph.child ~
11655+ =/ cg=irequest-graph u.graph.child
11656+ ?. ?& =(bundle-input.g bundle-input.cg)
11657+ =(prelude-input.g prelude-input.cg)
11658+ =(prelude-values.g prelude-values.cg)
11659+ =(prelude-molds.g prelude-molds.cg)
11660+ =(externals.g externals.cg)
11661+ =(marks.g marks.cg)
11662+ ==
11663+ ~
11664+ =/ merged=(set path) (~(uni in:..zuse paths.g) paths.cg)
11665+ =/ rs=(unit (list irequest-evidence))
11666+ (request-graph-requests-add requests.cg requests.g (add 1 (lent requests.cg)))
11667+ ?~ rs ~
11668+ ?: &(?=(^ u.rs) |((gth (lent ~(tap in:..zuse merged)) 256) (gth (lent u.rs) 256))) ~
11669+ $(imports t.imports, g g(paths merged, requests u.rs), fuel (dec fuel))
11670+++ request-graph-reusable
11671+ |= [f=ifile src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) values=(list term) molds=(list term) prelude=(unit ifile)]
11672+ ^- ?
11673+ ?~ source.f |
11674+ ?. =(u.source.f src) |
11675+ ?~ graph.f |
11676+ =/ g=irequest-graph u.graph.f
11677+ ?. (request-graph-inputs-match g externals marks modules values molds prelude) |
11678+ ?. (~(has in:..zuse paths.g) at.f) |
11679+ !(lien active |=(p=path (~(has in:..zuse paths.g) p)))
11680+::
862911681++ resolve-jibb-imports
863011682 |= [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)]
863111683 ^- jimports-result
11684+ =/ result=jimports-detailed-result
11685+ (resolve-jibb-imports-detailed imports externals mark-externals modules active prelude-values prelude-molds cache prelude)
11686+ ?: ?=(%| -.result) [%| message.p.result]
11687+ [%& p.result]
11688+++ resolve-jibb-imports-detailed
11689+ |= [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)]
11690+ ^- jimports-detailed-result
863211691 ?~ imports [%& [~ cache]]
863311692 ?. ?=(%jibb -.i.imports) $(imports t.imports)
863411693 =/ at=path (weld path.i.imports `path`~[%jibb])
11694+ ?: =(at /lib/jibb/internal/jibb)
11695+ [%| ['the prelude internal module is private' ~]]
11696+ ?: =(at /lib/jibb/primitives/jibb)
11697+ [%| ['the prelude primitive interface is private' ~]]
863511698 ?: (lien active |=(p=path =(p at)))
8636− [%| (crip "import cycle at {(spud at)}")]
11699+ [%| [(crip "import cycle at {(spud at)}") ~]]
863711700 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
8638− ?~ found [%| (crip "module source missing: {(spud at)}")]
8639− ?^ t.found [%| (crip "duplicate module sources: {(spud at)}")]
11701+ ?~ found [%| [(crip "module source missing: {(spud at)}") ~]]
11702+ ?^ t.found [%| [(crip "duplicate module sources: {(spud at)}") ~]]
864011703 =/ cached=(unit ifile) (find-jibb-cache at cache)
8641− =/ iface=jfile-result
8642− ?^ cached [%& [u.cached cache]]
8643− (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
11704+ =/ iface=jfile-detailed-result
11705+ ?^ cached
11706+ ?. =(at.u.cached at) [%| ['cached module identity needs unsupported inference' ~]]
11707+ ?~ graph.u.cached
11708+ :: A detached legacy interface has unknown evidence. Rebuild it
11709+ :: against the current graph, without retaining any stale entry.
11710+ =/ clean=jcache (skim cache |=(x=[at=path iface=ifile] !=(at.x at)))
11711+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds clean prelude)
11712+ ?. (request-graph-reusable u.cached source.i.found externals mark-externals modules active prelude-values prelude-molds prelude)
11713+ [%| ['cached module evidence needs unsupported inference' ~]]
11714+ [%& [u.cached cache]]
11715+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
864411716 ?: ?=(%| -.iface) [%| p.iface]
8645− =/ rest=jimports-result $(imports t.imports, cache cache.p.iface)
11717+ =/ rest=jimports-detailed-result $(imports t.imports, cache cache.p.iface)
864611718 ?: ?=(%| -.rest) rest
864711719 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
864811720::
11721+:: Provisional declaration extraction only; this does not derive asks,
11722+:: validate imported types, or claim that an API module has checked.
11723++$ iapi-path [at=span name=term segments=(list pseg) full=term diffs=(list term) scry=(unit (list pseg))]
11724+++ api-path-mark
11725+ |= [sh=shape marks=(list term)]
11726+ ^- (unit term)
11727+ ?. ?=(%ref -.sh) ~
11728+ ?. ?=([@ ~] names.sh) ~
11729+ ?. (unique-value-name i.names.sh marks) ~
11730+ `i.names.sh
11731+::
11732+++ api-path-diffs
11733+ |= [shapes=(list shape) marks=(list term) used=(list term)]
11734+ ^- (unit (list term))
11735+ ?~ shapes `~
11736+ =/ n=(unit term) (api-path-mark i.shapes marks)
11737+ ?~ n ~
11738+ ?: (lien used |=(x=term =(x u.n))) ~
11739+ =/ rest=(unit (list term)) $(shapes t.shapes, used [u.n used])
11740+ ?~ rest ~
11741+ `[u.n u.rest]
11742+::
11743+++ api-path-payload
11744+ |= [sh=shape marks=(list term)]
11745+ ^- (unit [full=term diffs=(list term)])
11746+ =/ direct=(unit term) (api-path-mark sh marks)
11747+ ?^ direct `[u.direct ~]
11748+ ?. ?=(%apply -.sh) ~
11749+ ?. =(~[%facts] ref.sh) ~
11750+ ?~ args.sh ~
11751+ ?~ t.args.sh ~
11752+ =/ full=(unit term) (api-path-mark i.args.sh marks)
11753+ ?~ full ~
11754+ =/ diffs=(unit (list term)) (api-path-diffs t.args.sh marks ~[u.full])
11755+ ?~ diffs ~
11756+ `[u.full u.diffs]
11757+::
11758++$ iapi-parameter [name=term aura=@ta at=span]
11759+++ api-path-parameters
11760+ |= [segments=(list pseg) seen=(list term)]
11761+ ^- (unit (list iapi-parameter))
11762+ ?~ segments `~
11763+ ?: ?=(%knot -.i.segments) $(segments t.segments)
11764+ =/ seg=pseg i.segments
11765+ ?. ?=(%typed -.seg) ~
11766+ ?: =(0 aura.seg) ~
11767+ ?: (lien seen |=(n=term =(n name.seg))) ~
11768+ =/ rest=(unit (list iapi-parameter)) $(segments t.segments, seen [name.seg seen])
11769+ ?~ rest ~
11770+ `[[name.seg aura.seg at.seg] u.rest]
11771+::
11772+++ api-scry-parameters-compatible
11773+ |= [scry=(list iapi-parameter) watch=(list iapi-parameter)]
11774+ ^- ?
11775+ ?~ scry &
11776+ ?. (lien watch |=(p=iapi-parameter &(=(name.p name.i.scry) =(aura.p aura.i.scry)))) |
11777+ $(scry t.scry)
11778+::
11779+++ api-path-one
11780+ |= [sh=shape marks=(list term)]
11781+ ^- (unit iapi-path)
11782+ ?. ?=(%cell -.sh) ~
11783+ =/ fs=(list field) fields.sh
11784+ ?~ fs ~
11785+ ?~ t.fs ~
11786+ ?~ t.t.fs ~
11787+ ?: (gth (lent fs) 4) ~
11788+ ?. ?=(%bare -.i.fs) ~
11789+ =/ tag=shape shape.i.fs
11790+ ?. ?=(%const -.tag) ~
11791+ ?. =(%term form.lit.tag) ~
11792+ =/ name=term val.lit.tag
11793+ ?. (jibb-face-name name) ~
11794+ ?. ?=(%bare -.i.t.fs) ~
11795+ =/ path-shape=shape shape.i.t.fs
11796+ ?. ?=(%path -.path-shape) ~
11797+ ?. ?=(%bare -.i.t.t.fs) ~
11798+ =/ payload=(unit [full=term diffs=(list term)]) (api-path-payload shape.i.t.t.fs marks)
11799+ ?~ payload ~
11800+ =/ scry=(unit (unit (list pseg)))
11801+ ?~ t.t.t.fs `~
11802+ =/ entry=field i.t.t.t.fs
11803+ ?. ?=(%face -.entry) ~
11804+ ?. =(%scry name.entry) ~
11805+ ?. ?=(%path -.shape.entry) ~
11806+ ``segs.shape.entry
11807+ ?~ scry ~
11808+ =/ params=(unit (list iapi-parameter)) (api-path-parameters segs.path-shape ~)
11809+ ?~ params ~
11810+ ?^ u.scry
11811+ =/ scry-params=(unit (list iapi-parameter)) (api-path-parameters u.u.scry ~)
11812+ ?~ scry-params ~
11813+ ?. (api-scry-parameters-compatible u.scry-params u.params) ~
11814+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11815+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11816+::
11817+++ api-path-many
11818+ |= [shapes=(list shape) marks=(list term) seen=(list term)]
11819+ ^- (unit (list iapi-path))
11820+ ?~ shapes `~
11821+ =/ one=(unit iapi-path) (api-path-one i.shapes marks)
11822+ ?~ one ~
11823+ ?: (lien seen |=(n=term =(n name.u.one))) ~
11824+ =/ rest=(unit (list iapi-path)) $(shapes t.shapes, seen [name.u.one seen])
11825+ ?~ rest ~
11826+ `[u.one u.rest]
11827+::
11828+++ api-path-declaration
11829+ |= [sh=shape marks=(list term)]
11830+ ^- (unit (list iapi-path))
11831+ ?: ?=(%union -.sh) (api-path-many cases.sh marks ~)
11832+ (api-path-many ~[sh] marks ~)
11833+::
11834+:: Derived gates share the value namespace. /% marks name molds; /- and
11835+:: /= also introduce faces that cannot be shadowed by a derived value.
11836+++ api-import-faces
11837+ |= imports=(list import)
11838+ ^- (list term)
11839+ ?~ imports ~
11840+ ?- -.i.imports
11841+ %mark $(imports t.imports)
11842+ %sur [name.i.imports $(imports t.imports)]
11843+ %jibb [face.i.imports $(imports t.imports)]
11844+ ==
11845+::
11846+++ api-derived-names-valid
11847+ |= [paths=(list iapi-path) poke-names=(list term) mod=module prelude-values=(list term)]
11848+ ^- ?
11849+ =/ path-names=(list term) (turn paths |=(p=iapi-path name.p))
11850+ =/ derived=(list term) (weld path-names poke-names)
11851+ ?: (lien derived |=(n=term =(n %proj))) |
11852+ =/ outer=(list term) (weld prelude-values (weld (global-value-names defs.mod) (api-import-faces imports.mod)))
11853+ (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x))))))
11854+::
11855+:: Analysis only. Successful external entries must be unchanged results
11856+:: produced for the declared marks; no request interface is produced.
11857++$ iapi-mark-type [name=term typ=itype]
11858++$ iapi-path-typed [path=iapi-path full=itype diffs=(list iapi-mark-type)]
11859+++ api-diff-types
11860+ |= [names=(list term) externals=imark-externals declared=(list term)]
11861+ ^- (unit (list iapi-mark-type))
11862+ ?~ names `~
11863+ =/ typ=(unit itype) (find-imported-mark i.names externals declared)
11864+ ?~ typ ~
11865+ =/ tail=(unit (list iapi-mark-type)) $(names t.names)
11866+ ?~ tail ~
11867+ `[[i.names u.typ] u.tail]
11868+::
11869+++ api-path-types
11870+ |= [paths=(list iapi-path) externals=imark-externals declared=(list term)]
11871+ ^- (unit (list iapi-path-typed))
11872+ ?~ paths `~
11873+ =/ full=(unit itype) (find-imported-mark full.i.paths externals declared)
11874+ ?~ full ~
11875+ =/ diffs=(unit (list iapi-mark-type)) (api-diff-types diffs.i.paths externals declared)
11876+ ?~ diffs ~
11877+ =/ tail=(unit (list iapi-path-typed)) $(paths t.paths)
11878+ ?~ tail ~
11879+ `[[i.paths u.full u.diffs] u.tail]
11880+::
11881+++ api-poke-mark-names
11882+ |= [pokes=(list def) declared=(list term)]
11883+ ^- (unit (list term))
11884+ ?~ pokes `~
11885+ ?^ t.pokes ~
11886+ =/ d=def i.pokes
11887+ ?. ?=(%mold -.d) ~
11888+ =/ sh=shape shape.d
11889+ ?: ?=(%union -.sh) (api-path-diffs cases.sh declared ~)
11890+ =/ name=(unit term) (api-path-mark sh declared)
11891+ ?~ name ~
11892+ `~[u.name]
11893+::
11894+++ api-path-analysis
11895+ |= [mod=module externals=imark-externals prelude-values=(list term) prelude-molds=(list term)]
11896+ ^- (unit (list iapi-path-typed))
11897+ ?: (lien defs.mod def-has-hole) ~
11898+ ?^ (duplicate-defs defs.mod) ~
11899+ =/ ds=(list def) defs.mod
11900+ =/ declarations=(list def)
11901+ (skim ds |=(d=def &(?=(%mold -.d) =(%paths name.d))))
11902+ ?. ?=([* ~] declarations) ~
11903+ =/ pokes=(list def)
11904+ (skim ds |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11905+ ?: (gth (lent pokes) 1) ~
11906+ =/ ordinary=(list def)
11907+ (skim ds |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
11908+ ?. (module-scope-valid mod(defs ordinary) prelude-values prelude-molds) ~
11909+ =/ declared=(list term) (collect-mark-imports imports.mod)
11910+ =/ poke-names=(unit (list term)) (api-poke-mark-names pokes declared)
11911+ ?~ poke-names ~
11912+ =/ decl=def i.declarations
11913+ ?> ?=(%mold -.decl)
11914+ =/ paths=(unit (list iapi-path)) (api-path-declaration shape.decl declared)
11915+ ?~ paths ~
11916+ ?. (api-derived-names-valid u.paths u.poke-names mod prelude-values) ~
11917+ (api-path-types u.paths externals declared)
11918+::
11919+:: Source/graph entry for path analysis only. The returned paths retain
11920+:: reader-derived mark types and import resolution has checked reachable
11921+:: Jibb dependencies. This is not an API interface or a module check.
11922+++ api-path-analysis-source
11923+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11924+ ^- (each (list iapi-path-typed) @t)
11925+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path analysis requires /ui/api/<agent>.jibb']
11926+ =/ parsed (parse file src)
11927+ ?: ?=(%| -.parsed) [%| 'API path source does not parse']
11928+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11929+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11930+ ?~ prepared [%| 'API path analysis needs the prepared prelude']
11931+ =/ prelude=(unit ifile) `iface.u.prepared
11932+ =/ deps=jimports-result
11933+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ prelude)
11934+ ?: ?=(%| -.deps) [%| p.deps]
11935+ =/ paths=(unit (list iapi-path-typed))
11936+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11937+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11938+ [%& u.paths]
11939+::
11940+:: Analysis evidence retains the API source, the prepared interface, the
11941+:: caller's reader results and the resolved Jibb dependency cache alongside
11942+:: the typed path declarations. Reader results and prepared interfaces are
11943+:: trusted inputs: this does not verify their underlying Hoon source/version,
11944+:: create requests or check the provenance of arbitrary values.
11945++$ iapi-path-evidence
11946+ [at=path source=@t prepared=iprelude externals=iexternals marks=imark-externals dependencies=jcache paths=(list iapi-path-typed)]
11947+++ api-path-evidence-source
11948+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11949+ ^- (each iapi-path-evidence @t)
11950+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11951+ =/ parsed (parse file src)
11952+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11953+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11954+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11955+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11956+ =/ public=ifile iface.u.prepared
11957+ =/ deps=jimports-result
11958+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
11959+ ?: ?=(%| -.deps) [%| p.deps]
11960+ =/ paths=(unit (list iapi-path-typed))
11961+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11962+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11963+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11964+:: Graph-aware variant preserves the caller active stack and cache.
11965+++ api-path-evidence-graph
11966+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11967+ ^- (each iapi-path-evidence @t)
11968+ ?~ active [%| 'API analysis needs an active graph']
11969+ ?. =(i.active file) [%| 'API analysis active graph does not start at the source']
11970+ ?: (lien t.active |=(p=path =(p file))) [%| 'API analysis active graph contains a cycle']
11971+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11972+ =/ parsed (parse file src)
11973+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11974+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11975+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11976+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11977+ =/ public=ifile iface.u.prepared
11978+ =/ deps=jimports-result
11979+ (resolve-jibb-imports imports.p.parsed externals marks modules active values.u.prepared molds.u.prepared cache `public)
11980+ ?: ?=(%| -.deps) [%| p.deps]
11981+ =/ paths=(unit (list iapi-path-typed))
11982+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11983+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11984+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11985+::
11986+:: This query classifies a unique path declaration only. Missing evidence
11987+:: or a nonunique name is unknown; it proves nothing about an ask value.
11988+:: Like prepared interfaces, the supplied evidence is a trusted host input.
11989+++ api-path-watchability
11990+ |= [evidence=(unit iapi-path-evidence) case-name=term]
11991+ ^- ?(%watchable %not-watchable %unknown)
11992+ ?~ evidence %unknown
11993+ =/ found=(list iapi-path-typed)
11994+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
11995+ ?. ?=([* ~] found) %unknown
11996+ ?~ scry.path.i.found %watchable
11997+ %not-watchable
11998+::
11999+:: These are declaration-derived request components, not a callable gate,
12000+:: an ask value, or proof of a value's provenance. Keep the exact trusted
12001+:: source/reader evidence until a later checked interface and lowerer can
12002+:: attach it to a generated request. No argument ordering is claimed here.
12003++$ iapi-request-parameter [name=term typ=itype at=span]
12004++$ iapi-request-parts
12005+ [evidence=iapi-path-evidence path=iapi-path-typed parameters=(list iapi-request-parameter) reply-sample=itype fold=(unit itype) watchability=?(%watchable %not-watchable)]
12006+++ api-request-parameter-types
12007+ |= params=(list iapi-parameter)
12008+ ^- (unit (list iapi-request-parameter))
12009+ ?~ params `~
12010+ =/ aura=@ta aura.i.params
12011+ ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
12012+ =/ rest=(unit (list iapi-request-parameter)) $(params t.params)
12013+ ?~ rest ~
12014+ `[[name.i.params [%atom aura] at.i.params] u.rest]
12015+::
12016+:: A single diff's fold consumes the tagged diff and the previous full value.
12017+:: Multiple-diff unions need a checked union representation and remain open.
12018+++ api-request-fold-type
12019+ |= p=iapi-path-typed
12020+ ^- (unit (unit itype))
12021+ ?~ diffs.p `~
12022+ ?^ t.diffs.p ~
12023+ =/ d=iapi-mark-type i.diffs.p
12024+ =/ literal=lit [%term %tas name.d (crip ['%' (trip name.d)])]
12025+ =/ sample=itype [%cell [%cell [%const literal] typ.d] full.p]
12026+ ``[%fn sample full.p]
12027+::
12028+++ api-request-parts
12029+ |= [evidence=(unit iapi-path-evidence) case-name=term]
12030+ ^- (unit iapi-request-parts)
12031+ ?~ evidence ~
12032+ =/ found=(list iapi-path-typed)
12033+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
12034+ ?. ?=([* ~] found) ~
12035+ =/ p=iapi-path-typed i.found
12036+ =/ raw=(unit (list iapi-parameter)) (api-path-parameters segments.path.p ~)
12037+ ?~ raw ~
12038+ =/ params=(unit (list iapi-request-parameter)) (api-request-parameter-types u.raw)
12039+ ?~ params ~
12040+ =/ fold=(unit (unit itype)) (api-request-fold-type p)
12041+ ?~ fold ~
12042+ =/ watch=?(%watchable %not-watchable) ?~(scry.path.p %watchable %not-watchable)
12043+ `[u.evidence p u.params full.p u.fold watch]
12044+::
12045+:: Check ordinary API molds and values plus every declared mark type using
12046+:: the same trusted source, prepared prelude and reader inputs as path
12047+:: evidence. Keep elaborations with those inputs for a later interface.
12048+:: This is partial analysis: an unused /- core is not independently checked,
12049+:: definitions needing derived values remain unsupported, and no complete
12050+:: API, request or constructor is exported or given runtime behavior.
12051++$ iapi-support-evidence
12052+ [paths=iapi-path-evidence values=ienv molds=imold-types marks=(list iapi-mark-type) elaborations=(list iwidth-definition)]
12053+++ api-support-analysis-source
12054+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12055+ ^- (each iapi-support-evidence @t)
12056+ =/ path-result (api-path-evidence-source file src externals marks modules prepared)
12057+ ?: ?=(%| -.path-result) [%| p.path-result]
12058+ =/ evidence=iapi-path-evidence p.path-result
12059+ =/ parsed (parse file src)
12060+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12061+ =/ mod=module p.parsed
12062+ =/ ordinary=(list def)
12063+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12064+ =/ prep=iprelude prepared.evidence
12065+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12066+ =/ vals=(list term) (global-value-names ordinary)
12067+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12068+ =/ declared=(list term) (collect-mark-imports imports.mod)
12069+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12070+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12071+ =/ prelude=(unit ifile) `iface.prep
12072+ =/ deps=jimports-result
12073+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.prep molds.prep dependencies.evidence prelude)
12074+ ?: ?=(%| -.deps) [%| p.deps]
12075+ =/ molds=imolds (collect-simple-molds ordinary)
12076+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12077+ =/ surs=(list term) (collect-sur-imports imports.mod)
12078+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12079+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12080+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12081+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12082+ ?: ?=(%| -.mts) [%| p.mts]
12083+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12084+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12085+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12086+:: Preserve the same graph context through supporting definitions.
12087+++ api-support-analysis-graph
12088+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12089+ ^- (each iapi-support-evidence @t)
12090+ =/ path-result (api-path-evidence-graph file src externals marks modules active cache prepared)
12091+ ?: ?=(%| -.path-result) [%| p.path-result]
12092+ =/ evidence=iapi-path-evidence p.path-result
12093+ =/ parsed (parse file src)
12094+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12095+ =/ mod=module p.parsed
12096+ =/ ordinary=(list def)
12097+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12098+ =/ prep=iprelude prepared.evidence
12099+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12100+ =/ vals=(list term) (global-value-names ordinary)
12101+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12102+ =/ declared=(list term) (collect-mark-imports imports.mod)
12103+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12104+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12105+ =/ prelude=(unit ifile) `iface.prep
12106+ =/ deps=jimports-result
12107+ (resolve-jibb-imports imports.mod externals marks modules active values.prep molds.prep dependencies.evidence prelude)
12108+ ?: ?=(%| -.deps) [%| p.deps]
12109+ =/ molds=imolds (collect-simple-molds ordinary)
12110+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12111+ =/ surs=(list term) (collect-sur-imports imports.mod)
12112+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12113+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12114+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12115+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12116+ ?: ?=(%| -.mts) [%| p.mts]
12117+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12118+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12119+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12120+::
12121+:: Type-analysis artifact for one plain request. The resolver may publish
12122+:: its interface only together with trusted source and reader evidence.
12123+:: No lowering or runtime validator exists.
12124+:: Value watchability remains unproved even for a watchable declaration.
12125++$ ione-request-interface
12126+ [support=iapi-support-evidence parts=iapi-request-parts iface=ifile]
12127+++ request-compatible-ask
12128+ |= prelude=iprelude
12129+ ^- (unit ischeme)
12130+ =/ public=ifile iface.prelude
12131+ ?. =(at.public /lib/jibb/prelude/jibb) ~
12132+ =/ ask=(unit ischeme) (find-jibb-mold %ask public)
12133+ ?~ ask ~
12134+ ?. ?=([@ ~] vars.u.ask) ~
12135+ ?. ?=(%union -.typ.u.ask) ~
12136+ ?. =(origin.typ.u.ask `[/lib/jibb/internal/jibb %ask]) ~
12137+ ?. (identity-union-parameters vars.u.ask args.typ.u.ask) ~
12138+ =/ m=@ud i.vars.u.ask
12139+ ?: (itype-var-is-atom m typ.u.ask) ~
12140+ ?. (levy (itype-vars typ.u.ask) |=(n=@ud =(n m))) ~
12141+ ?: (itype-has-tag typ.u.ask) ~
12142+ =/ private=(list iwidth-dependency)
12143+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12144+ ?. ?=([* ~] private) ~
12145+ ?~ source.i.private ~
12146+ =/ path=(unit ischeme) (find-jibb-mold %path public)
12147+ ?~ path ~
12148+ ?^ vars.u.path ~
12149+ =/ path-type=itype [%collection %list ~[[%atom %ta]]]
12150+ ?. =(typ.u.path path-type) ~
12151+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit public)
12152+ ?~ unit-template ~
12153+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
12154+ =/ state-unit=(unit itype) (template-apply u.unit-template ~[[%noun ~]])
12155+ ?~ state-unit ~
12156+ =/ path-unit=(unit itype) (template-apply u.unit-template ~[path-type])
12157+ ?~ path-unit ~
12158+ =/ output=itype [%cell [%face %state [%noun ~]] [%face %message [%var m]]]
12159+ =/ agent-input=itype [%cell [%face %mark [%atom %tas]] [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]]
12160+ =/ store-input=itype [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]
12161+ =/ pure-case=itype [%cell [%const [%term %tas %pure '%pure']] [%face %value [%var m]]]
12162+ =/ agent-case=itype
12163+ [%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]]]]]]]]
12164+ =/ store-case=itype
12165+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %name [%atom %tas]] [%face %receive [%fn store-input output]]]]]
12166+ ?. =(cases.typ.u.ask ~[pure-case agent-case store-case]) ~
12167+ ask
12168+::
12169+:: The first supported standalone API has exactly one mark import and one
12170+:: plain path declaration, with no other definitions or imports. No partial
12171+:: success is published when source, schema, or a required mold is unknown.
12172+++ one-request-interface-source
12173+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12174+ ^- (each ione-request-interface @t)
12175+ =/ out (api-support-analysis-source file src externals marks modules prepared)
12176+ ?: ?=(%| -.out) [%| p.out]
12177+ =/ support=iapi-support-evidence p.out
12178+ =/ ev=iapi-path-evidence paths.support
12179+ =/ parsed (parse file src)
12180+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12181+ =/ mod=module p.parsed
12182+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12183+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12184+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12185+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12186+ =/ p=iapi-path-typed i.paths.ev
12187+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12188+ ?~ parts [%| 'request components need unsupported inference']
12189+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12190+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12191+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12192+ =/ valid-marks=?
12193+ ?~ fold.u.parts ?=([* ~] marks.support)
12194+ ?=([* [* ~]] marks.support)
12195+ ?. valid-marks [%| 'request marks need unsupported inference']
12196+ =/ fold-open=?
12197+ ?~ fold.u.parts |
12198+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12199+ ?: fold-open [%| 'request fold needs unsupported inference']
12200+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12201+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12202+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12203+ ?~ ask [%| 'request ask needs unsupported inference']
12204+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12205+ ?~ result [%| 'request ask needs unsupported inference']
12206+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12207+ =/ sample=itype
12208+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12209+ ?~ parameters.u.parts callback
12210+ [%cell typ.i.parameters.u.parts callback]
12211+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12212+ =/ exports=imold-types
12213+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12214+ =/ prelude=iprelude prepared.ev
12215+ =/ public=ifile iface.prelude
12216+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12217+ =/ private=(list iwidth-dependency)
12218+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12219+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12220+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12221+ =/ req=irequest-evidence
12222+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12223+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12224+ [%& [support u.parts interface]]
12225+:: Graph-aware request artifact; resolver use remains type-only.
12226+++ one-request-interface-graph
12227+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12228+ ^- (each ione-request-interface @t)
12229+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12230+ ?: ?=(%| -.out) [%| p.out]
12231+ =/ support=iapi-support-evidence p.out
12232+ =/ ev=iapi-path-evidence paths.support
12233+ =/ parsed (parse file src)
12234+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12235+ =/ mod=module p.parsed
12236+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12237+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12238+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12239+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12240+ =/ p=iapi-path-typed i.paths.ev
12241+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12242+ ?~ parts [%| 'request components need unsupported inference']
12243+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12244+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12245+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12246+ =/ valid-marks=?
12247+ ?~ fold.u.parts ?=([* ~] marks.support)
12248+ ?=([* [* ~]] marks.support)
12249+ ?. valid-marks [%| 'request marks need unsupported inference']
12250+ =/ fold-open=?
12251+ ?~ fold.u.parts |
12252+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12253+ ?: fold-open [%| 'request fold needs unsupported inference']
12254+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12255+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12256+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12257+ ?~ ask [%| 'request ask needs unsupported inference']
12258+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12259+ ?~ result [%| 'request ask needs unsupported inference']
12260+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12261+ =/ sample=itype
12262+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12263+ ?~ parameters.u.parts callback
12264+ [%cell typ.i.parameters.u.parts callback]
12265+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12266+ =/ exports=imold-types
12267+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12268+ =/ prelude=iprelude prepared.ev
12269+ =/ public=ifile iface.prelude
12270+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12271+ =/ private=(list iwidth-dependency)
12272+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12273+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12274+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12275+ =/ req=irequest-evidence
12276+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12277+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12278+ [%& [support u.parts interface]]
12279+::
12280+++ api-mark-exports
12281+ |= [marks=(list term) all=(list term) externals=imark-externals]
12282+ ^- imold-types
12283+ ?~ marks ~
12284+ =/ t=(unit itype) (find-imported-mark i.marks externals all)
12285+ ?~ t $(marks t.marks)
12286+ [[i.marks [u.t ~]] $(marks t.marks)]
12287+::
12288+:: Experimental direct poke-only API. Unsupported API declarations fail
12289+:: as a whole; supplied mark reader results retain their existing boundary.
12290+++ api-poke-interface
12291+ |= [at=path mod=module mark-externals=imark-externals prelude-values=(list term) prelude-molds=(list term) prelude=(unit ifile)]
12292+ ^- (unit ifile)
12293+ ?: (lien defs.mod def-has-hole) ~
12294+ ?. ?=([%ui %api @ %jibb ~] at) ~
12295+ ?^ (duplicate-defs defs.mod) ~
12296+ ?~ prelude ~
12297+ ?. =(at.u.prelude /lib/jibb/prelude/jibb) ~
12298+ =/ poke=(unit ischeme) (find-jibb-mold %poke u.prelude)
12299+ ?~ poke ~
12300+ ?. ?=(%union -.typ.u.poke) ~
12301+ ?^ vars.u.poke ~
12302+ =/ compatible=?
12303+ %+ lien cases.typ.u.poke
12304+ |= c=itype
12305+ ?=([%cell [%const [%term %tas %agent *]] [%cell [%face %agent [%atom %tas]] [%cell [%face %mark [%atom %tas]] [%face %payload [%noun ~]]]]] c)
12306+ ?. compatible ~
12307+ ?. (module-scope-valid mod(defs ~) prelude-values prelude-molds) ~
12308+ ?. (levy imports.mod |=(i=import ?=(%mark -.i))) ~
12309+ =/ marks=(list term) (collect-mark-imports imports.mod)
12310+ ?. ?=([@ ~] marks) ~
12311+ =/ ds=(list def) defs.mod
12312+ ?. ?=([[%mold *] ~] ds) ~
12313+ ?. =(%poke name.i.ds) ~
12314+ =/ sh=shape shape.i.ds
12315+ ?. ?=([%ref *] sh) ~
12316+ ?. ?=([@ ~] names.sh) ~
12317+ =/ n=term i.names.sh
12318+ ?. (unique-value-name n marks) ~
12319+ ?: |((lien prelude-values |=(x=term =(n x))) (lien prelude-molds |=(x=term =(n x)))) ~
12320+ =/ mark=(unit itype) (find-imported-mark n mark-externals marks)
12321+ ?~ mark ~
12322+ =/ sc=ischeme [[%fn u.mark typ.u.poke] ~]
12323+ `[~[[n sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]] ~ ~ ~ ~]
12324+::
12325+:: Source-proven ordinary helpers validate each selected /sur dependency.
12326+:: Unused or less direct cores remain unsupported by this first interface.
12327+++ api-sur-covered
12328+ |= [surs=(list term) defs=(list def) externals=iexternals all=(list term)]
12329+ ^- ?
12330+ ?~ surs &
12331+ =/ found=(list def)
12332+ %+ skim defs
12333+ |= d=def
12334+ ?. ?=(%mold -.d) |
12335+ ?. ?=(%ref -.shape.d) |
12336+ ?. ?=([@ [@ ~]] names.shape.d) |
12337+ =(i.t.names.shape.d i.surs)
12338+ ?~ found |
12339+ =/ selected=def i.found
12340+ ?. ?=(%mold -.selected) |
12341+ =/ sh=shape shape.selected
12342+ ?. ?=(%ref -.sh) |
12343+ ?. ?=([@ [@ ~]] names.sh) |
12344+ =/ checked=(unit itype) (find-imported-mold i.surs i.names.sh externals all)
12345+ ?~ checked |
12346+ $(surs t.surs)
12347+::
12348++$ imulti-request-gates [values=ienv requests=(list irequest-evidence)]
12349+++ api-request-gates
12350+ |= [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]
12351+ ^- (unit imulti-request-gates)
12352+ ?~ paths `[~ ~]
12353+ ?: =(0 fuel) ~
12354+ =/ p=iapi-path-typed i.paths
12355+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12356+ ?~ parts ~
12357+ ?. ?=(?(~ [* ~]) parameters.u.parts) ~
12358+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) ~
12359+ ?^ scry.path.p ~
12360+ ?^ (itype-vars reply-sample.u.parts) ~
12361+ ?: (itype-has-tag reply-sample.u.parts) ~
12362+ =/ open-fold=?
12363+ ?~ fold.u.parts |
12364+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12365+ ?: open-fold ~
12366+ =/ result=(unit itype) (template-apply ask ~[[%var 0]])
12367+ ?~ result ~
12368+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12369+ =/ sample=itype
12370+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12371+ ?~ parameters.u.parts callback
12372+ [%cell typ.i.parameters.u.parts callback]
12373+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12374+ =/ prep=iprelude prepared.ev
12375+ =/ req=irequest-evidence
12376+ [file name.path.p p src public internal values.prep molds.prep externals marks]
12377+ =/ rest=(unit imulti-request-gates)
12378+ $(paths t.paths, fuel (dec fuel))
12379+ ?~ rest ~
12380+ `[[[name.path.p scheme] values.u.rest] [req requests.u.rest]]
12381+::
12382+++ api-poke-from-checked
12383+ |= [file=path mod=module marks=imark-externals values=(list term) molds=(list term) prelude=(unit ifile)]
12384+ ^- (unit [values=ienv derived=(list iderived)])
12385+ =/ pokes=(list def)
12386+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12387+ ?~ pokes `[~ ~]
12388+ ?. ?=([* ~] pokes) ~
12389+ =/ declared=(list term) (collect-mark-imports imports.mod)
12390+ =/ ns=(unit (list term)) (api-poke-mark-names pokes declared)
12391+ ?~ ns ~
12392+ ?. ?=([@ ~] u.ns) ~
12393+ =/ matching=(list import)
12394+ %+ skim imports.mod
12395+ |= i=import
12396+ ?. ?=(%mark -.i) |
12397+ =(mark.i i.u.ns)
12398+ ?. ?=([* ~] matching) ~
12399+ =/ checked=(unit ifile)
12400+ (api-poke-interface file mod(defs pokes, imports matching) marks values molds prelude)
12401+ ?~ checked ~
12402+ `[values.u.checked derived.u.checked]
12403+::
12404+:: The partial interface is published atomically: all paths, ordinary
12405+:: source definitions, declared marks and the poke must check. Unselected
12406+:: /sur bindings, runtime validation and value watchability remain unproved.
12407+++ multi-request-interface-graph
12408+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12409+ ^- (each [iface=ifile cache=jcache] @t)
12410+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12411+ ?: ?=(%| -.out) [%| p.out]
12412+ =/ support=iapi-support-evidence p.out
12413+ =/ ev=iapi-path-evidence paths.support
12414+ =/ parsed (parse file src)
12415+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12416+ =/ mod=module p.parsed
12417+ ?. (levy imports.mod |=(i=import ?=(?(%mark %sur) -.i)))
12418+ [%| 'request imports need unsupported inference']
12419+ =/ surs=(list term) (collect-sur-imports imports.mod)
12420+ ?. (api-sur-covered surs defs.mod externals surs)
12421+ [%| 'API source dependency needs unsupported inference']
12422+ ?~ paths.ev [%| 'request count needs unsupported inference']
12423+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12424+ ?~ ask [%| 'request ask needs unsupported inference']
12425+ =/ prep=iprelude prepared.ev
12426+ =/ public=ifile iface.prep
12427+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12428+ =/ private=(list iwidth-dependency)
12429+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12430+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12431+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12432+ =/ gates=(unit imulti-request-gates)
12433+ (api-request-gates paths.ev ev u.ask file src u.source.public u.source.i.private externals marks 256)
12434+ ?~ gates [%| 'request paths need unsupported inference']
12435+ =/ poke=(unit [values=ienv derived=(list iderived)])
12436+ (api-poke-from-checked file mod marks values.prep molds.prep `public)
12437+ ?~ poke [%| 'API poke needs unsupported inference']
12438+ =/ mark-molds=imold-types
12439+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12440+ =/ exports=imold-types (weld mark-molds molds.support)
12441+ =/ names=(list term) (turn exports |=(m=[name=term template=ischeme] name.m))
12442+ ?. (levy names |=(n=term (unique-value-name n names)))
12443+ [%| 'API exported molds need unsupported inference']
12444+ =/ env=ienv (weld values.u.gates (weld values.u.poke values.support))
12445+ =/ graph=irequest-graph
12446+ [(silt `(list path)`~[file]) requests.u.gates modules `public values.prep molds.prep externals marks]
12447+ =/ iface=ifile
12448+ [env exports file derived.u.poke elaborations.support ~ `src `graph]
12449+ [%& [iface dependencies.ev]]
12450+::
12451+:: A checked program main is only the direct four-component source call.
12452+:: Grouping is transparent, but aliases, qualified wings and other module
12453+:: kinds remain outside this slice.
12454+++ program-main-def
12455+ |= ds=(list def)
12456+ ^- (unit def)
12457+ ?~ ds ~
12458+ ?: &(?=(%value -.i.ds) =(%main name.i.ds)) `i.ds
12459+ $(ds t.ds)
12460+::
12461+++ program-main-wing
12462+ |= e=expr
12463+ ^- (unit term)
12464+ ?: ?=(%group -.e) $(e inner.e)
12465+ ?. ?=(%wing -.e) ~
12466+ ?. ?=([@ ~] names.e) ~
12467+ `i.names.e
12468+::
12469+++ program-main-parts
12470+ |= d=def
12471+ ^- (unit [init=term update=term view=term subs=term])
12472+ ?. ?=(%value -.d) ~
12473+ |-
12474+ ?: ?=(%group -.val.d) $(val.d inner.val.d)
12475+ ?. ?=(%call -.val.d) ~
12476+ =/ head=(unit term) (program-main-wing head.val.d)
12477+ ?~ head ~
12478+ ?. =(%program u.head) ~
12479+ ?. ?=([* * * * ~] args.val.d) ~
12480+ =/ args=(list expr) args.val.d
12481+ ?> ?=([* * * * ~] args)
12482+ =/ init=(unit term) (program-main-wing i.args)
12483+ =/ update=(unit term) (program-main-wing i.t.args)
12484+ =/ view=(unit term) (program-main-wing i.t.t.args)
12485+ =/ subs=(unit term) (program-main-wing i.t.t.t.args)
12486+ ?~ init ~
12487+ ?~ update ~
12488+ ?~ view ~
12489+ ?~ subs ~
12490+ `[u.init u.update u.view u.subs]
12491+::
12492+++ program-empty-null
12493+ |= e=expr
12494+ ^- ?
12495+ ?- -.e
12496+ %lit =(%null form.lit.e)
12497+ %cast $(e val.e)
12498+ %group $(e inner.e)
12499+ %body ?~(defs.e $(e final.e) |)
12500+ * |
12501+ ==
12502+::
12503+++ program-subs-empty
12504+ |= d=def
12505+ ^- ?
12506+ ?. ?=(%value -.d) |
12507+ ?- -.val.d
12508+ %gate (program-empty-null body.val.d)
12509+ %gate-wide (program-empty-null body.val.d)
12510+ * |
12511+ ==
12512+::
12513+++ program-main-closed
12514+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) env=ienv prelude=(unit ifile)]
12515+ ^- ?
12516+ ?~ prelude |
12517+ ?~ (ienv-lookup %program values.u.prelude) |
12518+ =/ program=(unit ischeme) (find-jibb-mold %program u.prelude)
12519+ ?~ program |
12520+ =/ main=(unit ischeme) (ienv-lookup %main env)
12521+ ?~ main |
12522+ ?. ?=(~ vars.u.main) |
12523+ ?. ?=(~ (itype-vars typ.u.main)) |
12524+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.program *istate)
12525+ =/ main-fit=ifit (direct-invariant typ.u.main typ.instance ~ next.state.instance)
12526+ ?. ?=(%ok -.main-fit) |
12527+ =/ init=(unit ischeme) (ienv-lookup init.parts env)
12528+ ?~ init |
12529+ ?. ?=(~ vars.u.init) |
12530+ ?. ?=(%fn -.typ.u.init) |
12531+ ?. ?=(~ (itype-vars sample.typ.u.init)) |
12532+ ?. ?=(~ (itype-vars product.typ.u.init)) |
12533+ =/ data=igate-free (gate-free-type sample.typ.u.init 256 ~)
12534+ ?. =(%yes verdict.data) |
12535+ =/ model=igate-free (gate-free-type product.typ.u.init left.data ~)
12536+ ?. =(%yes verdict.model) |
12537+ =/ subs=(list def)
12538+ (skim ds |=(d=def &(?=(%value -.d) =(subs.parts name.d))))
12539+ ?. ?=([* ~] subs) |
12540+ (program-subs-empty i.subs)
12541+::
864912542++ infer-jibb-file
865012543 |= [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)]
865112544 ^- jfile-result
8652− ?: ?=([%ui %api *] at) [%| (crip "API module needs unsupported inference: {(spud at)}")]
12545+ =/ out=jfile-detailed-result
12546+ (infer-jibb-file-detailed at src externals mark-externals modules active prelude-values prelude-molds cache prelude)
12547+ ?: ?=(%| -.out) [%| message.p.out]
12548+ [%& p.out]
12549+:: Returns structured root-source overlap evidence after the same full check.
12550+++ infer-jibb-file-detailed
12551+ |= [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)]
12552+ ^- jfile-detailed-result
865312553 =/ parsed (parse at src)
8654− ?: ?=(%| -.parsed) [%| (crip "module source does not parse: {(spud at)}")]
12554+ ?: ?=(%| -.parsed) [%| [(crip "module source does not parse: {(spud at)}") ~]]
865512555 =/ mod=module p.parsed
8656− ?. (module-scope-valid mod prelude-values prelude-molds) [%| (crip "module has conflicting names: {(spud at)}")]
12556+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12557+ ?^ duplicate [%| [(show-duplicate-fields at src u.duplicate) ~]]
12558+ ?: &(?=([%ui %api *] at) ?=(^ (program-main-def defs.mod)))
12559+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
12560+ ?: ?=([%ui %api *] at)
12561+ =/ iface=(unit ifile) (api-poke-interface at mod mark-externals prelude-values prelude-molds prelude)
12562+ ?^ iface
12563+ =/ checked=ifile u.iface(source `src, graph `[(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals])
12564+ [%& [checked [[at checked] cache]]]
12565+ ?~ prelude [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12566+ =/ prepared=iprelude [u.prelude prelude-values prelude-molds]
12567+ =/ narrow=?
12568+ ?. ?=([[%mark *] ~] imports.mod) |
12569+ ?. ?=([[%mold *] ~] defs.mod) |
12570+ ?. =(%paths name.i.defs.mod) |
12571+ !?=(%union -.shape.i.defs.mod)
12572+ ?: narrow
12573+ =/ request=(each ione-request-interface @t)
12574+ (one-request-interface-graph at src externals mark-externals modules active cache `prepared)
12575+ ?: ?=(%| -.request) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12576+ =/ checked=ifile iface.p.request
12577+ [%& [checked [[at checked] dependencies.paths.support.p.request]]]
12578+ =/ multi=(each [iface=ifile cache=jcache] @t)
12579+ (multi-request-interface-graph at src externals mark-externals modules active cache `prepared)
12580+ ?: ?=(%| -.multi) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12581+ [%& [iface.p.multi [[at iface.p.multi] cache.p.multi]]]
12582+ ?. (module-scope-valid mod prelude-values prelude-molds)
12583+ ?: (pending-declared-poke at mod prelude-values prelude-molds)
12584+ [%| [(crip "module kind or scope needs unsupported inference: {(spud at)}") ~]]
12585+ [%| [(crip "module has conflicting names: {(spud at)}") ~]]
865712586 =/ vals=(list term) (global-value-names defs.mod)
8658− ?: (lien vals |=(n=term =(n %main)))
8659− [%| (crip "module kind needs unsupported inference: {(spud at)}")]
8660− =/ js=jimports-result (resolve-jibb-imports imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
12587+ =/ main=(unit def) (program-main-def defs.mod)
12588+ =/ main-parts=(unit [init=term update=term view=term subs=term])
12589+ ?~(main ~ (program-main-parts u.main))
12590+ ?. ?~(main & &(!?=([%ui %stores *] at) ?=(^ main-parts)))
12591+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
12592+ =/ js=jimports-detailed-result (resolve-jibb-imports-detailed imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
866112593 ?: ?=(%| -.js) [%| p.js]
8662− =/ molds=imolds (collect-simple-molds defs.mod)
12594+ =/ collected=grec-collected
12595+ ?^ imports.mod [(collect-simple-molds defs.mod) *(map term shape)]
12596+ (grec-collect-molds defs.mod)
12597+ =/ molds=imolds molds.collected
866312598 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
866412599 =/ surs=(list term) (collect-sur-imports imports.mod)
866512600 =/ marks=(list term) (collect-mark-imports imports.mod)
866612601 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
866712602 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8668− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude]
8669− =/ mts=(each imold-types @t) (module-mold-types molds state)
8670− ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
8671− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12603+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12604+ :: Source and scope were checked above; preserve that exact root and prelude.
12605+ :: This first integration only indexes import-free library sources.
12606+ =/ index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])
12607+ ?^ imports.mod ~
12608+ ?~ prelude ~
12609+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude)
12610+ ?~ standard ~
12611+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
12612+ =/ index=(map term shape) proofs.collected
12613+ ?. !=(index *(map term shape)) ~
12614+ ?: (lien molds |=(m=[name=term body=shape] =(%list name.m))) ~
12615+ `[at src u.prelude index]
12616+ =. grec-index.state index
12617+ =/ mts=(each imold-types imold-failure) (module-mold-types-detail molds state)
12618+ ?: ?=(%| -.mts)
12619+ ?~ overlap.p.mts [%| [(crip "{(trip message.p.mts)}: {(spud at)}") ~]]
12620+ =/ witness=[name=term cases=upair] u.overlap.p.mts
12621+ =/ first=@t (show-error src [at line.beg.first.cases.witness col.beg.first.cases.witness "first union case"])
12622+ =/ second=@t (show-error src [at line.beg.second.cases.witness col.beg.second.cases.witness "overlapping case"])
12623+ =/ msg=@t (of-wain:format ~[(crip "module mold {(trip name.witness)} has overlapping cases") first second])
12624+ [%| [msg `[at src name.witness cases.witness]]]
12625+ =/ resolution=iresolved
12626+ ?~ index
12627+ (resolve-groups defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12628+ (resolve-groups-core defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude index)
12629+ =/ env=ienv env.resolution
12630+ =. env
12631+ ?: (module-values-complete defs.mod env) env
12632+ ?: |(?=([%ui %stores *] at) ?=(^ imports.mod) ?=(^ prelude) ?=(^ prelude-values) ?=(^ prelude-molds)) env
12633+ ?: (gth (met 3 src) 65.536) env
12634+ ?: (gth (lent defs.mod) 64) env
12635+ ?. (dg-source-candidate defs.mod 64) env
12636+ =/ transaction=(unit dgcommit) (dg-root-source at src)
12637+ ?~ transaction env
12638+ ?: (dg-interface-safe env.u.transaction) env.u.transaction
12639+ env
867212640 ?. (module-values-complete defs.mod env)
8673− [%| (crip "module definitions need unsupported inference: {(spud at)}")]
8674− [%& [[env p.mts at] [[at [env p.mts at]] cache.p.js]]]
12641+ [%| [(crip "module definitions need unsupported inference: {(spud at)}") ~]]
12642+ ?. ?~(main & ?~(main-parts | (program-main-closed u.main-parts defs.mod env prelude)))
12643+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
12644+ =/ initial=irequest-graph [(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals]
12645+ =/ graph=(unit irequest-graph) (request-graph-merge resolved.p.js initial (add 1 (lent resolved.p.js)))
12646+ ?~ graph [%| ['module request evidence needs unsupported inference' ~]]
12647+ =/ iface=ifile [env p.mts at ~ artifacts.resolution ~ `src graph]
12648+ [%& [iface [[at iface] cache.p.js]]]
12649+::
12650+:: A source-bound analysis of one named mold, not a module, island,
12651+:: request, watchability or runtime check. The host owns the trusted
12652+:: prepared prelude, canonical paths and reader/source version identities.
12653+:: The 256-node cap covers only classification, not source/graph work.
12654++$ igate-free-mold
12655+ [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]
12656+++ gate-free-mold-source
12657+ |= [file=path src=@t name=term externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude) fuel=@ud]
12658+ ^- (each igate-free-mold @t)
12659+ ?~ file [%| 'mold analysis needs a path ending in jibb']
12660+ ?. =(%jibb (rear file)) [%| 'mold analysis needs a path ending in jibb']
12661+ ?: |(=(file /lib/jibb/internal/jibb) =(file /lib/jibb/primitives/jibb))
12662+ [%| 'the prelude internal modules are private']
12663+ ?: ?=([%ui %api *] file) [%| 'API declarations need unsupported mold analysis']
12664+ ?: ?=([%ui %stores *] file) [%| 'store declarations need unsupported mold analysis']
12665+ =/ entries=jbundle (skim modules |=(m=jsource =(file at.m)))
12666+ ?: (gth (lent entries) 1) [%| 'duplicate root module sources']
12667+ =/ wrong-root=? ?~(entries | !=(source.i.entries src))
12668+ ?: wrong-root [%| 'root module source does not match bundle']
12669+ =/ parsed (parse file src)
12670+ ?: ?=(%| -.parsed) [%| 'mold source does not parse']
12671+ =/ mod=module p.parsed
12672+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12673+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12674+ ?~ prepared [%| 'mold analysis needs the prepared prelude']
12675+ ?. (module-scope-valid mod values.u.prepared molds.u.prepared)
12676+ [%| 'mold source has conflicting or unsupported scope']
12677+ =/ selected=(list def)
12678+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(name.d name))))
12679+ ?~ selected [%| 'selected mold is not declared']
12680+ ?^ t.selected [%| 'selected mold is not unique']
12681+ ?> ?=(%mold -.i.selected)
12682+ =/ public=ifile iface.u.prepared
12683+ =/ js=jimports-result
12684+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
12685+ ?: ?=(%| -.js) [%| p.js]
12686+ =/ ms=imolds (collect-simple-molds defs.mod)
12687+ =/ vals=(list term) (global-value-names defs.mod)
12688+ =/ globals=(list term) (weld values.u.prepared (weld (import-binding-names imports.mod) vals))
12689+ =/ surs=(list term) (collect-sur-imports imports.mod)
12690+ =/ declared=(list term) (collect-mark-imports imports.mod)
12691+ =/ reserved=(list term) (weld molds.u.prepared (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
12692+ =/ top=(list term) (turn ms |=(m=[name=term body=shape] name.m))
12693+ =/ state=istate [0 ~ ~ ~ ms globals externals surs marks declared resolved.p.js reserved ~ ~ ~ | file top `public ~ 256 ~ ~ ~ ~ ~ ~]
12694+ =/ inferred=(unit [template=ischeme state=istate])
12695+ (infer-mold-template shape.i.selected state(active ~[name], in-mold &))
12696+ ?~ inferred [%| 'selected mold needs unsupported inference']
12697+ =/ template=ischeme template.u.inferred
12698+ =. typ.template (label-direct-union typ.template shape.i.selected name state)
12699+ =. typ.template (itype-normalize typ.template sub.state.u.inferred)
12700+ =/ cap=@ud (min fuel 256)
12701+ =/ analysis=igate-free (gate-free-type typ.template cap ~)
12702+ [%& [file src name u.prepared externals marks modules cache.p.js template fuel cap analysis]]
867512703::
867612704:: +golden-types-with-modules fails closed for imports without prelude
867712705:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -8682,6 +12710,8 @@
868212710 ^- @t
868312711 =/ parsed (parse file src)
868412712 ?: ?=(%| -.parsed) (show-error src p.parsed)
12713+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12714+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
868512715 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
868612716 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
868712717 (golden-types-with-marks file src externals mark-externals)
@@ -8696,6 +12726,8 @@
869612726 ^- @t
869712727 =/ parsed (parse file src)
869812728 ?: ?=(%| -.parsed) (show-error src p.parsed)
12729+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12730+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
869912731 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
870012732 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
870112733 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
@@ -8703,23 +12735,33 @@
870312735 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
870412736 (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
870512737::
12738+++ golden-types-with-prelude-and-internal
12739+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prelude-source=@t internal-source=@t]
12740+ ^- @t
12741+ =/ prepared=(unit iprelude) (prepare-prelude-with-internal prelude-source internal-source)
12742+ (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
12743+::
870612744++ golden-types-with-prepared-prelude
870712745 |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prepared=(unit iprelude)]
870812746 ^- @t
870912747 =/ parsed (parse file src)
871012748 ?: ?=(%| -.parsed) (show-error src p.parsed)
12749+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12750+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
871112751 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
871212752 =/ prelude-values=(list term) values.u.prepared
871312753 =/ prelude-molds=(list term) molds.u.prepared
871412754 =/ iface=(unit ifile) `iface.u.prepared
871512755 ?. (module-scope-valid p.parsed prelude-values prelude-molds)
12756+ ?: (pending-declared-poke file p.parsed prelude-values prelude-molds)
12757+ 'partial inference; module not checked\0amodule kind or scope needs unsupported inference'
871612758 'partial inference; module not checked\0amodule has conflicting names'
871712759 =/ js=jimports-result
871812760 (resolve-jibb-imports imports.p.parsed externals mark-externals modules ~[file] prelude-values prelude-molds ~ iface)
871912761 ?: ?=(%| -.js) (of-wain:format ~['partial inference; module not checked' p.js])
872012762 =/ scope-values=(list term)
872112763 (weld prelude-values (weld (collect-sur-imports imports.p.parsed) (collect-mark-imports imports.p.parsed)))
8722− (golden-types-in-context file src externals mark-externals resolved.p.js scope-values prelude-molds iface)
12764+ (golden-types-in-context-core file src externals mark-externals resolved.p.js scope-values prelude-molds iface prepared)
872312765::
872412766:: +golden-types-with-marks: supply declared mark types separately from /sur
872512767:: entries, as [mark result] with the result from +read-mark:jibb-import.
@@ -8750,16 +12792,60 @@
875012792++ golden-types-in-context
875112793 |= [file=path src=@t externals=iexternals mark-externals=imark-externals jimports=ijimports prelude-values=(list term) reserved-molds=(list term) prelude=(unit ifile)]
875212794 ^- @t
12795+ (golden-types-in-context-core file src externals mark-externals jimports prelude-values reserved-molds prelude ~)
12796+++ golden-types-in-context-core
12797+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals jimports=ijimports prelude-values=(list term) reserved-molds=(list term) prelude=(unit ifile) prepared=(unit iprelude)]
12798+ ^- @t
875312799 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
875412800 =/ parsed (parse file src)
875512801 ?: ?=(%| -.parsed) (show-error src p.parsed)
12802+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12803+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
12804+ ?: (module-has-reserved-proj p.parsed)
12805+ 'module has reserved proj name'
875612806 =/ ds=(list def) defs.p.parsed
875712807 =/ molds=imolds (collect-simple-molds ds)
875812808 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
875912809 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
876012810 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
876112811 =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
12812+ =/ cycles=(list icycle) (definite-value-cycles ds globals)
876212813 =/ env=ienv env.resolution
12814+ =/ recovered=(list term) ~
12815+ =/ eligible=?
12816+ ?& ?=(~ imports.p.parsed)
12817+ ?=(~ jimports)
12818+ !?=([%ui %api *] file)
12819+ !?=([%ui %stores *] file)
12820+ !(lien (global-value-names ds) |=(n=term =(n %main)))
12821+ !(module-values-complete ds env)
12822+ (lte (met 3 src) 65.536)
12823+ (lte (lent ds) 64)
12824+ ?| &(?=(~ prepared) ?=(~ prelude) ?=(~ prelude-values) ?=(~ reserved-molds) (module-scope-valid p.parsed ~ ~) (dg-source-candidate ds 64))
12825+ ?& ?=(^ prepared)
12826+ ?=(^ prelude)
12827+ =(u.prelude iface.u.prepared)
12828+ =(prelude-values values.u.prepared)
12829+ =(reserved-molds molds.u.prepared)
12830+ (module-scope-valid p.parsed values.u.prepared molds.u.prepared)
12831+ (dg-prepared-candidate ds 64)
12832+ ==
12833+ ==
12834+ ==
12835+ =/ transaction=(unit dgcommit)
12836+ ?. eligible ~
12837+ ?~ prepared (dg-root-source file src)
12838+ (dg-root-prepared file src u.prepared)
12839+ =. recovered
12840+ ?~ transaction ~
12841+ ?. &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) ~
12842+ (turn (skim env.u.transaction |=(entry=[name=term scheme=ischeme] ?=(~ (ienv-lookup name.entry env)))) |=(entry=[name=term scheme=ischeme] name.entry))
12843+ =. env
12844+ ?~ transaction env
12845+ ?: &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) env.u.transaction
12846+ env
12847+ =/ source-defs=(map term def) (direct-checked-gates ds env)
12848+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
876312849 =/ lines=(list @t) ~
876412850 |-
876512851 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -8768,6 +12854,20 @@
876812854 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
876912855 ?. (unique-value-name name.d globals)
877012856 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
12857+ =/ cycle=(list icycle) (skim cycles |=(c=icycle =(name.c name.d)))
12858+ ?^ cycle
12859+ =/ diag=idiag ["non-gate value depends on itself through a cycle" ~[[first.i.cycle "value in cycle"] [next.i.cycle "dependency in cycle"]]]
12860+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d diag) lines])
12861+ ?: (lien recovered |=(n=term =(n name.d)))
12862+ =/ found=(unit ischeme) (ienv-lookup name.d env)
12863+ ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: committed definition unavailable") lines])
12864+ ?: (itype-has-hidden-recursive typ.u.found)
12865+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive mold name is not available in this scope") lines])
12866+ ?: (itype-has-hidden-generic typ.u.found)
12867+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: generic union name is not available in this scope") lines])
12868+ =/ typ=itype (canonical-itype typ.u.found vars.u.found)
12869+ =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
12870+ $(ds t.ds, lines [line lines])
877112871 ?: (lien grouped.resolution |=(n=term =(n name.d)))
877212872 =/ found=(unit ischeme) (ienv-lookup name.d env)
877312873 ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
@@ -8775,7 +12875,9 @@
877512875 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
877612876 $(ds t.ds, lines [line lines])
877712877 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8778− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude]
12878+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12879+ =. gate-defs.initial source-defs
12880+ =. head-evidence.initial heads
877912881 =. initial (reserve-def-caps val.d initial)
878012882 =/ result=iresult
878112883 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
@@ -8783,6 +12885,11 @@
878312885 (infer-fragment val.d env initial)
878412886 ?: ?=(%| -.result)
878512887 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
12888+ =. state.p.result (promote-restricted-numbers state.p.result env)
12889+ =. 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)))
12890+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.result holes.initial state.p.result)
12891+ ?^ hole
12892+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d u.hole) lines])
878612893 =/ merged=(unit [first=icap second=icap])
878712894 (merged-capitals caps.state.p.result sub.state.p.result)
878812895 ?^ merged
@@ -8805,7 +12912,672 @@
880512912 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
880612913 ?: (gth (lent vars) 26)
880712914 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
12915+ ?~ (width-finalize projections.state.p.result sub.state.p.result vars)
12916+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: record projection elaboration needs unsupported inference") lines])
880812917 =/ printable=itype (canonical-itype typ vars)
880912918 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
881012919 $(ds t.ds, lines [line lines])
12920+:: Experimental module-owned pending-constraint generalization only.
12921+:: Inputs, IDs and substitution come from one checker-owned transaction.
12922++$ dgscan [ids=(list @ud) fuel=@ud]
12923+++ dg-scan
12924+ |= [todo=(list itype) sub=isub fuel=@ud ids=(list @ud)]
12925+ ^- (unit dgscan)
12926+ ?~ todo `[ids fuel]
12927+ ?: =(0 fuel) ~
12928+ =. fuel (dec fuel)
12929+ =/ t=itype i.todo
12930+ ?: ?=(?(%var %avar %rvar %nvar %rnvar %tag) -.t)
12931+ =/ node-id=@ud ?:(?=(%tag -.t) id.t +.t)
12932+ =/ found=(unit itype) (itype-lookup node-id sub)
12933+ ?~ found $(todo t.todo, ids [node-id ids])
12934+ ?: &(?=(?(%rvar %rnvar) -.u.found) =(node-id +.u.found))
12935+ $(todo t.todo, ids [node-id ids])
12936+ $(todo [u.found t.todo])
12937+ ?: ?=(%jrec -.t) $(todo t.todo)
12938+ ?+ -.t ~
12939+ %collection $(todo (weld args.t t.todo))
12940+ %union $(todo (weld args.t (weld cases.t t.todo)))
12941+ %face $(todo [body.t t.todo])
12942+ %fn $(todo [sample.t product.t t.todo])
12943+ %cell $(todo [hed.t tal.t t.todo])
12944+ %atom $(todo t.todo)
12945+ %any-atom $(todo t.todo)
12946+ %flag $(todo t.todo)
12947+ %noun $(todo t.todo)
12948+ %empty $(todo t.todo)
12949+ %const $(todo t.todo)
12950+ ==
12951+::
12952+++ dg-scan-ids
12953+ |= [ids=(list @ud) sub=isub fuel=@ud blocked=(list @ud)]
12954+ ^- (unit dgscan)
12955+ ?~ ids `[blocked fuel]
12956+ =/ one=(unit dgscan) (dg-scan ~[[%var i.ids]] sub fuel blocked)
12957+ ?~ one ~
12958+ $(ids t.ids, fuel fuel.u.one, blocked ids.u.one)
12959+::
12960+++ dg-env
12961+ |= [env=ienv sub=isub fuel=@ud blocked=(list @ud)]
12962+ ^- (unit dgscan)
12963+ ?~ env `[blocked fuel]
12964+ =/ sc=ischeme scheme.i.env
12965+ :: Quantifiers are local to the scheme: first find raw free IDs, then
12966+ :: follow those IDs in the module substitution without capturing them.
12967+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ fuel ~)
12968+ ?~ raw ~
12969+ =/ free=(list @ud) (skim ids.u.raw |=(n=@ud !(lien vars.sc |=(q=@ud =(q n)))))
12970+ =/ resolved=(unit dgscan) (dg-scan-ids free sub fuel.u.raw blocked)
12971+ ?~ resolved ~
12972+ $(env t.env, fuel fuel.u.resolved, blocked ids.u.resolved)
12973+::
12974+++ dg-obligations
12975+ |= [pending=(list dgo) sub=isub fuel=@ud blocked=(list @ud)]
12976+ ^- (unit dgscan)
12977+ ?~ pending `[blocked fuel]
12978+ =/ found=(unit dgscan) (dg-scan ~[left.i.pending right.i.pending] sub fuel blocked)
12979+ ?~ found ~
12980+ $(pending t.pending, fuel fuel.u.found, blocked ids.u.found)
12981+::
12982+++ dg-tags
12983+ |= [tags=(list ipending) sub=isub fuel=@ud blocked=(list @ud)]
12984+ ^- (unit dgscan)
12985+ ?~ tags `[blocked fuel]
12986+ ?: =(0 fuel) ~
12987+ =/ found=(unit itype) (itype-lookup id.i.tags sub)
12988+ ?~ found $(tags t.tags, fuel (dec fuel), blocked [id.i.tags blocked])
12989+ :: Until this entry is explicitly discharged, retain variables reachable
12990+ :: through its binding; mere existence of a substitution is not proof.
12991+ =/ reached=(unit dgscan) (dg-scan ~[u.found] sub (dec fuel) blocked)
12992+ ?~ reached ~
12993+ $(tags t.tags, fuel fuel.u.reached, blocked ids.u.reached)
12994+::
12995+++ dg-generalize
12996+ |= [typ=itype env=ienv pending=(list dgo) tags=(list ipending) captured=(list @ud) state=istate fuel=@ud]
12997+ ^- (unit ischeme)
12998+ :: Bound the obligation list and all graph/substitution walks. The
12999+ :: substitution is assumed checker-owned and occurs-checked.
13000+ ?: (gth (lent pending) 64) ~
13001+ =/ capt=(unit dgscan) (dg-scan-ids captured sub.state fuel ~)
13002+ ?~ capt ~
13003+ =/ env-free=(unit dgscan) (dg-env env sub.state fuel.u.capt ids.u.capt)
13004+ ?~ env-free ~
13005+ =/ obligations=(unit dgscan) (dg-obligations pending sub.state fuel.u.env-free ids.u.env-free)
13006+ ?~ obligations ~
13007+ =/ tagged=(unit dgscan) (dg-tags tags sub.state fuel.u.obligations ids.u.obligations)
13008+ ?~ tagged ~
13009+ =/ bounded=(unit dgscan) (dg-scan ~[typ] sub.state fuel.u.tagged ~)
13010+ ?~ bounded ~
13011+ =/ normalized=itype (itype-normalize typ sub.state)
13012+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
13013+ =/ quantified=(list @ud) (skim vars |=(n=@ud !(lien ids.u.tagged |=(b=@ud =(b n)))))
13014+ `[[normalized quantified]]
13015+::
13016++$ dgcommit [env=ienv state=istate]
13017+:: A branch literal must not acquire a value face through replay.
13018+++ dg-literal-target-safe
13019+ |= target=itype
13020+ ^- ?
13021+ ?: ?=(%union -.target)
13022+ (levy cases.target |=(c=itype ?=(?(%const %cell) -.c)))
13023+ ?=(?(%const %atom %any-atom %flag %noun) -.target)
13024+::
13025+++ dg-replay-edges
13026+ |= [edges=(list dgo) state=istate fuel=@ud]
13027+ ^- (unit istate)
13028+ ?~ edges `state
13029+ ?: =(0 fuel) ~
13030+ =/ trial=ifit (itype-fit left.i.edges right.i.edges sub.state next.state)
13031+ ?. ?=(%ok -.trial) ~
13032+ =/ valid=?
13033+ ?: ?=(%tag -.left.i.edges)
13034+ ?. constructor.left.i.edges
13035+ =/ closed=(unit dgscan) (dg-scan ~[right.i.edges] sub.trial 512 ~)
13036+ ?~ closed |
13037+ ?^ ids.u.closed |
13038+ (dg-literal-target-safe (itype-normalize right.i.edges sub.trial))
13039+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
13040+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
13041+ ?. valid ~
13042+ $(edges t.edges, state state(sub sub.trial, next next.trial), fuel (dec fuel))
13043+::
13044+++ dg-close-env
13045+ |= [env=ienv sub=isub fuel=@ud]
13046+ ^- (unit ienv)
13047+ ?~ env `~
13048+ ?: =(0 fuel) ~
13049+ =/ s=ischeme scheme.i.env
13050+ :: Quantified IDs are scheme-local and cannot be rewritten on publication.
13051+ ?. (levy vars.s |=(n=@ud ?=(~ (itype-lookup n sub)))) ~
13052+ =/ bounded=(unit dgscan) (dg-scan ~[typ.s] sub (dec fuel) ~)
13053+ ?~ bounded ~
13054+ =/ normalized=itype (itype-normalize typ.s sub)
13055+ ?: (itype-has-tag normalized) ~
13056+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
13057+ ?. (levy vars |=(n=@ud (lien vars.s |=(v=@ud =(v n))))) ~
13058+ =/ rest=(unit ienv) (dg-close-env t.env sub fuel.u.bounded)
13059+ ?~ rest ~
13060+ `[[name.i.env [normalized vars.s]] u.rest]
13061+::
13062+:: A deferred boolean branch has exactly the two literal flag patterns.
13063+:: Arms are inferred in order. Equal types are retained; two direct pending
13064+:: literals may instead retain source-owned obligations for later context.
13065+++ dg-boolean-patterns
13066+ |= e=expr
13067+ ^- ?
13068+ ?. ?=(%branch -.e) |
13069+ ?~ arms.e |
13070+ ?~ t.arms.e |
13071+ ?^ t.t.arms.e |
13072+ =/ x=arm i.arms.e
13073+ =/ y=arm i.t.arms.e
13074+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
13075+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
13076+ !=(val.lit.pat.x val.lit.pat.y)
13077+:: Only a direct source literal which created its own unbound pending tag
13078+:: may create a branch edge. The caller must retain the exact source and state.
13079+++ dg-owned-arm-literal
13080+ |= [e=expr t=itype tags=(list ipending) sub=isub initial=@ud]
13081+ ^- ?
13082+ ?. ?=(%lit -.e) |
13083+ ?. ?=(%tag -.t) |
13084+ ?: constructor.t |
13085+ ?. =(lit.e literal.t) |
13086+ ?: (lth id.t initial) |
13087+ ?^ (itype-lookup id.t sub) |
13088+ (lien tags |=(x=ipending &(=(id.x id.t) =(literal.x literal.t))))
13089+++ dg-boolean-branch
13090+ |= [e=expr env=ienv state=istate]
13091+ ^- iresult
13092+ ?. (dg-boolean-patterns e) [%| ["deferred branch patterns need unsupported inference" ~]]
13093+ ?> ?=(%branch -.e)
13094+ ?> ?=(^ arms.e)
13095+ ?> ?=(^ t.arms.e)
13096+ =/ x=arm i.arms.e
13097+ =/ y=arm i.t.arms.e
13098+ =/ subject=iresult (infer-fragment subject.e env state)
13099+ ?: ?=(%| -.subject) subject
13100+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
13101+ ?~ su [%| ["deferred branch subject does not unify with ?" ~]]
13102+ =/ left=iresult (infer-fragment val.x env state.p.subject(sub u.su))
13103+ ?: ?=(%| -.left) left
13104+ =/ right=iresult (infer-fragment val.y env state.p.left)
13105+ ?: ?=(%| -.right) right
13106+ ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
13107+ =/ st=istate state.p.right
13108+ ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
13109+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13110+ ?. (dg-owned-arm-literal val.y typ.p.right tags.st sub.st next.state)
13111+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13112+ ?> ?=(%tag -.typ.p.left)
13113+ ?> ?=(%tag -.typ.p.right)
13114+ ?: =(id.typ.p.left id.typ.p.right)
13115+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13116+ ?: (gth (lent obligations.st) 62)
13117+ [%| ["deferred branch arm context needs unsupported inference" ~]]
13118+ =/ result=itype [%var next.st]
13119+ =/ ex=dgo [typ.p.left result (span-of val.x) (span-of e)]
13120+ =/ ey=dgo [typ.p.right result (span-of val.y) (span-of e)]
13121+ [%& result st(next +(next.st), obligations [ex ey obligations.st])]
13122+ [%& typ.p.left state.p.right]
13123+::
13124+:: A direct tuple literal may wait for a later exact result context.
13125+:: Each pending literal retains its source tag and its own fit obligation.
13126+++ dg-infer-tuple-items
13127+ |= [items=(list item) env=ienv state=istate]
13128+ ^- iresult
13129+ ?~ items [%| ["empty cell is not supported by partial inference" ~]]
13130+ =/ head=iresult (infer-fragment val.i.items env state)
13131+ ?: ?=(%| -.head) head
13132+ =/ typ=itype typ.p.head
13133+ =/ st=istate state.p.head
13134+ =/ adjusted=(unit [typ=itype state=istate])
13135+ ?. (dg-owned-arm-literal val.i.items typ tags.st sub.st next.state) `[typ st]
13136+ ?: (gth (lent obligations.st) 63) ~
13137+ =/ pending=itype [%var next.st]
13138+ =/ edge=dgo [typ pending (span-of val.i.items) at.i.items]
13139+ `[pending st(next +(next.st), obligations [edge obligations.st])]
13140+ ?~ adjusted [%| ["deferred tuple context needs unsupported inference" ~]]
13141+ =. typ typ.u.adjusted
13142+ =. st state.u.adjusted
13143+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
13144+ ?~ t.items [%& typ st]
13145+ =/ tail=iresult $(items t.items, state st)
13146+ ?: ?=(%| -.tail) tail
13147+ [%& [%cell typ typ.p.tail] state.p.tail]
13148+::
13149+:: Deferred inference uses only source forms whose successful fit sites are
13150+:: guarded below; a shared source-node budget bounds this screen.
13151+++ dg-safe-expressions
13152+ |= [todo=(list expr) fuel=@ud]
13153+ ^- (unit @ud)
13154+ ?~ todo `fuel
13155+ =/ first=(unit @ud) (dg-safe-expression i.todo fuel)
13156+ ?~ first ~
13157+ $(todo t.todo, fuel u.first)
13158+++ dg-safe-items
13159+ |= [items=(list item) fuel=@ud]
13160+ ^- (unit @ud)
13161+ ?~ items `fuel
13162+ =/ first=(unit @ud) (dg-safe-expression val.i.items fuel)
13163+ ?~ first ~
13164+ $(items t.items, fuel u.first)
13165+++ dg-safe-expression
13166+ |= [e=expr fuel=@ud]
13167+ ^- (unit @ud)
13168+ ?: =(0 fuel) ~
13169+ =. fuel (dec fuel)
13170+ ?+ -.e ~
13171+ ?(%lit %ctor) `fuel
13172+ %wing ?:(?=([@ ~] names.e) `fuel ~)
13173+ %str
13174+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) ~
13175+ `fuel
13176+ %group $(e inner.e, fuel fuel)
13177+ %body
13178+ ?^ defs.e ~
13179+ $(e final.e, fuel fuel)
13180+ %gate $(e body.e, fuel fuel)
13181+ %gate-wide $(e body.e, fuel fuel)
13182+ %tuple (dg-safe-items items.e fuel)
13183+ %branch
13184+ ?. (dg-boolean-patterns e) ~
13185+ ?> ?=(^ arms.e)
13186+ ?> ?=(^ t.arms.e)
13187+ =/ subject=(unit @ud) $(e subject.e, fuel fuel)
13188+ ?~ subject ~
13189+ (dg-safe-expressions ~[val.i.arms.e val.i.t.arms.e] u.subject)
13190+ %cast $(e val.e, fuel fuel)
13191+ %call
13192+ =/ head=(unit @ud) $(e head.e, fuel fuel)
13193+ ?~ head ~
13194+ (dg-safe-expressions args.e u.head)
13195+ ==
13196+:: Exact normalized equality is preserved by all later substitutions.
13197+:: The bounded scan declines opaque types and oversized inputs.
13198+++ dg-stable-fit
13199+ |= [actual=itype expected=itype sub=isub]
13200+ ^- ?
13201+ ?~ (dg-scan ~[actual expected] sub 512 ~) |
13202+ =((itype-normalize actual sub) (itype-normalize expected sub))
13203+::
13204+:: A positional call peels sample-slot faces during its separate face check.
13205+:: Require its argument, sample and result closed so that check stays valid.
13206+++ dg-stable-call-fit
13207+ |= [actual=itype expected=itype product=itype sub=isub positional=?]
13208+ ^- ?
13209+ =/ checked=(unit dgscan) (dg-scan ~[actual expected product] sub 512 ~)
13210+ ?~ checked |
13211+ ?: &(positional ?=(^ ids.u.checked)) |
13212+ =((itype-normalize actual sub) (itype-normalize expected sub))
13213+::
13214+:: One definition attempt retains state only when inference succeeds.
13215++$ dg-step [env=ienv state=istate pending=(list dgo)]
13216+++ dg-stage-one
13217+ |= [d=def env=ienv state=istate]
13218+ ^- (unit dg-step)
13219+ ?> ?=(%value -.d)
13220+ ?~ (dg-safe-expression val.d 512) ~
13221+ =/ local=istate (reserve-def-caps val.d state)
13222+ :: This first slice declines all written capitals and holes/projections.
13223+ ?^ caps.local ~
13224+ =/ ordinary=iresult (infer-fragment val.d env local)
13225+ ?: ?=(%| -.ordinary) ~
13226+ =/ typ=itype typ.p.ordinary
13227+ =/ after=istate state.p.ordinary
13228+ =/ edges=(list dgo) obligations.after
13229+ ?. =(binders.after binders.state) ~
13230+ ?. =(molds.after molds.state) ~
13231+ ?. =(globals.after globals.state) ~
13232+ ?. =(externals.after externals.state) ~
13233+ ?. =(surs.after surs.state) ~
13234+ ?. =(mark-externals.after mark-externals.state) ~
13235+ ?. =(marks.after marks.state) ~
13236+ ?. =(jimports.after jimports.state) ~
13237+ ?. =(reserved-molds.after reserved-molds.state) ~
13238+ ?. =(params.after params.state) ~
13239+ ?. =(active.after active.state) ~
13240+ ?. =(in-mold.after in-mold.state) ~
13241+ ?. =(at.after at.state) ~
13242+ ?. =(top-molds.after top-molds.state) ~
13243+ ?. =(prelude.after prelude.state) ~
13244+ ?. =(gate-defs.after gate-defs.state) ~
13245+ ?. =(head-evidence.after head-evidence.state) ~
13246+ ?. =(grec-index.after grec-index.state) ~
13247+ ?. =(defer.after defer.state) ~
13248+ ?. =(holes.after holes.state) ~
13249+ ?. =(caps.after caps.state) ~
13250+ ?. =(projections.after projections.state) ~
13251+ ?: (unsupported-atom-vars (itype-normalize typ sub.after) caps.after binders.after sub.after) ~
13252+ ?: (itype-has-nvar (itype-normalize typ sub.after)) ~
13253+ =/ scheme=(unit ischeme) (dg-generalize typ env edges tags.after ~ after 32.768)
13254+ ?~ scheme ~
13255+ `[[[name.d u.scheme] env] after edges]
13256+:: Retry only definitions that did not infer. Successful definitions are
13257+:: committed into the local transaction, never published until all close.
13258+++ dg-stage
13259+ |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
13260+ ^- (unit dgcommit)
13261+ ?: (gth fuel 64) ~
13262+ ?: (gth (lent ds) fuel) ~
13263+ =/ remaining=(list def) ds
13264+ =/ waiting=(list def) ~
13265+ =/ progress=? |
13266+ =/ attempts=@ud (mul fuel fuel)
13267+ |-
13268+ ?~ remaining
13269+ ?^ waiting
13270+ ?. progress ~
13271+ $(remaining (flop waiting), waiting ~, progress |)
13272+ =/ replayed=(unit istate) (dg-replay-edges pending state 64)
13273+ ?~ replayed ~
13274+ ?: (pending-tags tags.u.replayed sub.u.replayed) ~
13275+ =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
13276+ ?~ closed-edges ~
13277+ ?^ ids.u.closed-edges ~
13278+ =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
13279+ ?~ rechecked ~
13280+ ?. =(sub.u.rechecked sub.u.replayed) ~
13281+ ?. =(next.u.rechecked next.u.replayed) ~
13282+ =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
13283+ ?~ closed ~
13284+ `[[u.closed u.replayed(defer ~, obligations ~)]]
13285+ ?: =(0 attempts) ~
13286+ =. attempts (dec attempts)
13287+ =/ d=def i.remaining
13288+ ?: ?=(%mold -.d) $(remaining t.remaining)
13289+ ?^ (ienv-lookup name.d base) $(remaining t.remaining)
13290+ ?^ (ienv-lookup name.d env) ~
13291+ =/ done=(unit dg-step) (dg-stage-one d env state)
13292+ ?~ done $(remaining t.remaining, waiting [d waiting])
13293+ $(remaining t.remaining, env env.u.done, state state.u.done, pending pending.u.done, progress &)
13294+::
13295+:: Cheap bounded eligibility check on the already parsed source. This
13296+:: deliberately covers only direct constructor calls beneath transparent
13297+:: groups, gates, casts and definition-free bodies. Other shapes decline
13298+:: this fallback without a second parse or resolution pass.
13299+++ dg-direct-source
13300+ |= [e=expr fuel=@ud]
13301+ ^- ?
13302+ ?: =(0 fuel) |
13303+ ?+ -.e |
13304+ %group $(e inner.e, fuel (dec fuel))
13305+ %gate $(e body.e, fuel (dec fuel))
13306+ %gate-wide $(e body.e, fuel (dec fuel))
13307+ %cast $(e val.e, fuel (dec fuel))
13308+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
13309+ %call
13310+ ?. ?=([* ~] args.e) |
13311+ ?=(%ctor -.i.args.e)
13312+ ==
13313+++ dg-source-candidate
13314+ |= [ds=(list def) fuel=@ud]
13315+ ^- ?
13316+ ?~ ds |
13317+ ?: =(0 fuel) |
13318+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
13319+ ?: (dg-direct-source val.i.ds 64) &
13320+ $(ds t.ds, fuel (dec fuel))
13321+::
13322+++ dg-prepared-source
13323+ |= [e=expr fuel=@ud]
13324+ ^- ?
13325+ ?: (dg-direct-source e fuel) &
13326+ ?: =(0 fuel) |
13327+ ?+ -.e |
13328+ %group $(e inner.e, fuel (dec fuel))
13329+ %gate $(e body.e, fuel (dec fuel))
13330+ %gate-wide $(e body.e, fuel (dec fuel))
13331+ %cast $(e val.e, fuel (dec fuel))
13332+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
13333+ %tuple &
13334+ ==
13335+++ dg-prepared-candidate
13336+ |= [ds=(list def) fuel=@ud]
13337+ ^- ?
13338+ ?~ ds |
13339+ ?: =(0 fuel) |
13340+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
13341+ ?: (dg-prepared-source val.i.ds 64) &
13342+ $(ds t.ds, fuel (dec fuel))
13343+::
13344+++ dg-interface-safe
13345+ |= [env=ienv]
13346+ ^- ?
13347+ ?~ env &
13348+ =/ sc=ischeme scheme.i.env
13349+ ?: |((itype-has-hidden-recursive typ.sc) (itype-has-hidden-generic typ.sc)) |
13350+ ?: (gth (lent vars.sc) 26) |
13351+ $(env t.env)
13352+:: Parse status and the transaction result come from the same source parse.
13353++$ dgparse [parsed=? result=(unit dgcommit)]
13354+++ dg-root-source
13355+ |= [at=path src=@t]
13356+ ^- (unit dgcommit)
13357+ result:(dg-root-detail at src)
13358+++ dg-root-detail
13359+ |= [at=path src=@t]
13360+ ^- dgparse
13361+ =/ parsed (parse at src)
13362+ ?: ?=(%| -.parsed) [| ~]
13363+ =/ transact
13364+ |.
13365+ ?^ imports.p.parsed ~
13366+ ?. (module-scope-valid p.parsed ~ ~) ~
13367+ ?^ (duplicate-defs defs.p.parsed) ~
13368+ =/ defs=(list def) defs.p.parsed
13369+ ?: (gth (lent defs) 64) ~
13370+ =/ molds=imolds (collect-simple-molds defs)
13371+ =/ globals=(list term) (global-value-names defs)
13372+ =/ resolution=iresolved (resolve-groups defs molds globals ~ ~ ~ ~ ~ ~ at ~)
13373+ ?^ grouped.resolution ~
13374+ ?^ artifacts.resolution ~
13375+ =/ base=ienv env.resolution
13376+ =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
13377+ ?~ free ~
13378+ ?^ ids.u.free ~
13379+ =/ all=(unit dgscan) (dg-all-env-ids base 32.768 ~)
13380+ ?~ all ~
13381+ =/ fresh=@ud (dg-next-id ids.u.all 0)
13382+ =/ st=istate *istate
13383+ =. 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)
13384+ =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
13385+ ?: ?=(%| -.checked-molds) ~
13386+ (dg-stage defs base base st ~ 64)
13387+ ::
13388+ [& (transact)]
13389+:: The caller supplies the trusted prepared prelude. This transaction is
13390+:: only report evidence; the ordinary module resolver does not publish it.
13391+++ dg-root-prepared
13392+ |= [at=path src=@t prepared=iprelude]
13393+ ^- (unit dgcommit)
13394+ ?: ?=([%ui %api *] at) ~
13395+ ?: ?=([%ui %stores *] at) ~
13396+ ?: (gth (met 3 src) 65.536) ~
13397+ =/ parsed (parse at src)
13398+ ?: ?=(%| -.parsed) ~
13399+ ?^ imports.p.parsed ~
13400+ ?. (module-scope-valid p.parsed values.prepared molds.prepared) ~
13401+ ?^ (duplicate-defs defs.p.parsed) ~
13402+ =/ defs=(list def) defs.p.parsed
13403+ ?: (gth (lent defs) 64) ~
13404+ ?: (lien (global-value-names defs) |=(n=term =(n %main))) ~
13405+ ?. (dg-prepared-candidate defs 64) ~
13406+ =/ local-molds=imolds (collect-simple-molds defs)
13407+ =/ globals=(list term) (weld values.prepared (global-value-names defs))
13408+ =/ iface=ifile iface.prepared
13409+ =/ prelude=(unit ifile) `iface
13410+ =/ resolution=iresolved
13411+ (resolve-groups defs local-molds globals ~ ~ ~ ~ ~ molds.prepared at prelude)
13412+ ?^ grouped.resolution ~
13413+ ?^ artifacts.resolution ~
13414+ =/ base=ienv env.resolution
13415+ =/ templates=ienv
13416+ (turn molds.iface |=(x=[name=term template=ischeme] [name.x template.x]))
13417+ =/ all-env=ienv (weld base (weld values.iface templates))
13418+ =/ free=(unit dgscan) (dg-env all-env ~ 32.768 ~)
13419+ ?~ free ~
13420+ ?^ ids.u.free ~
13421+ =/ all=(unit dgscan) (dg-all-env-ids all-env 32.768 ~)
13422+ ?~ all ~
13423+ =/ fresh=@ud (dg-next-id ids.u.all 0)
13424+ =/ st=istate *istate
13425+ =. st st(next fresh, defer `~, molds local-molds, globals globals, at at, reserved-molds molds.prepared, prelude prelude, top-molds (turn local-molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
13426+ =/ checked-molds=(each imold-types @t) (module-mold-types local-molds st)
13427+ ?: ?=(%| -.checked-molds) ~
13428+ (dg-stage defs base base st ~ 64)
13429+::
13430+++ dg-all-env-ids
13431+ |= [env=ienv fuel=@ud ids=(list @ud)]
13432+ ^- (unit dgscan)
13433+ ?~ env `[ids fuel]
13434+ ?: =(0 fuel) ~
13435+ =/ sc=ischeme scheme.i.env
13436+ ?: (itype-has-tag typ.sc) ~
13437+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ (dec fuel) ids)
13438+ ?~ raw ~
13439+ =/ quant=(unit dgscan) (dg-scan-ids vars.sc ~ fuel.u.raw ids.u.raw)
13440+ ?~ quant ~
13441+ $(env t.env, fuel fuel.u.quant, ids ids.u.quant)
13442+::
13443+++ dg-next-id
13444+ |= [ids=(list @ud) largest=@ud]
13445+ ^- @ud
13446+ ?~ ids +(largest)
13447+ $(ids t.ids, largest (max largest i.ids))
13448+::
13449+++ dg-eligible-ctor
13450+ |= [e=expr head=itype actual=itype expected=itype state=istate]
13451+ ^- (unit dgo)
13452+ ?. ?=(%call -.e) ~
13453+ ?. ?=([* ~] args.e) ~
13454+ ?. ?=(%ctor -.i.args.e) ~
13455+ ?. ?=(%fn -.head) ~
13456+ ?. ?=(%fn -.expected) ~
13457+ ?. ?=(%tag -.actual) ~
13458+ ?. constructor.actual ~
13459+ ?. ?=(%var -.product.expected) ~
13460+ ?^ (itype-lookup id.product.expected sub.state) ~
13461+ =/ bounded=(unit dgscan) (dg-scan ~[sample.expected] sub.state 256 ~)
13462+ ?~ bounded ~
13463+ ?^ ids.u.bounded ~
13464+ `[[actual expected (span-of i.args.e) (span-of head.e)]]
13465+::
13466+:: Experimental per-module, source-derived recursive tree index.
13467+:: The two tags and the exact children/list/self layout are fixed-shape
13468+:: checks, so ordinary definitions incur no type-tree or source scans.
13469+++ grec-tagged-fields
13470+ |= sh=shape
13471+ ^- (unit [tag=@ fields=(list field)])
13472+ ?. ?=(%cell -.sh) ~
13473+ ?~ fields.sh ~
13474+ =/ head=field i.fields.sh
13475+ ?. ?=(%bare -.head) ~
13476+ ?. ?=(%const -.shape.head) ~
13477+ ?. &(?=(%term form.lit.shape.head) =(%tas aura.lit.shape.head)) ~
13478+ `[val.lit.shape.head t.fields.sh]
13479+++ grec-tree-children
13480+ |= [fs=(list field) param=@t]
13481+ ^- (unit field)
13482+ ?~ fs ~
13483+ ?~ t.fs `i.fs
13484+ ?^ t.t.fs ~
13485+ =/ event=field i.fs
13486+ =/ kids=field i.t.fs
13487+ ?. &(?=(%face -.event) ?=(%face -.kids)) ~
13488+ ?. !=(name.event name.kids) ~
13489+ ?. ?=(%fn -.shape.event) ~
13490+ ?. ?=(%aura -.sample.shape.event) ~
13491+ ?. =(%t aura.sample.shape.event) ~
13492+ ?. ?=(%tvar -.product.shape.event) ~
13493+ ?. =(param name.product.shape.event) ~
13494+ `kids
13495+::
13496+++ grec-tree-proof
13497+ |= [name=term sh=shape]
13498+ ^- ?
13499+ ?. ?=(%generic -.sh) |
13500+ ?. ?=([@ ~] vars.sh) |
13501+ =/ param=@t i.vars.sh
13502+ ?. ?=(%union -.body.sh) |
13503+ ?. ?=([* [* ~]] cases.body.sh) |
13504+ =/ a=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.cases.body.sh)
13505+ =/ b=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.t.cases.body.sh)
13506+ ?~ a |
13507+ ?~ b |
13508+ ?. !=(tag.u.a tag.u.b) |
13509+ ?. ?=([* ~] fields.u.a) |
13510+ =/ value=field i.fields.u.a
13511+ ?. ?=(%face -.value) |
13512+ ?. ?=(%aura -.shape.value) |
13513+ ?. =(%t aura.shape.value) |
13514+ =/ selected=(unit field) (grec-tree-children fields.u.b param)
13515+ ?~ selected |
13516+ =/ kids=field u.selected
13517+ ?. ?=(%face -.kids) |
13518+ ?. ?=(%apply -.shape.kids) |
13519+ ?. =(ref.shape.kids ~[%list]) |
13520+ ?. ?=([* ~] args.shape.kids) |
13521+ =/ self=shape i.args.shape.kids
13522+ ?. ?=(%apply -.self) |
13523+ ?. =(ref.self ~[name]) |
13524+ ?. ?=([* ~] args.self) |
13525+ ?. ?=(%tvar -.i.args.self) |
13526+ =(name.i.args.self param)
13527++$ grec-collected [molds=imolds proofs=(map term shape)]
13528+:: Experimental one-layer analysis view, never an exported mold identity.
13529+++ grec-unfold-view
13530+ |= [typ=itype fuel=@ud]
13531+ ^- (unit [view=itype left=@ud])
13532+ ?. ?=(%grec -.typ) ~
13533+ ?: =(fuel 0) ~
13534+ ?. ?=([* ~] args.typ) ~
13535+ =/ sh=shape proof.typ
13536+ ?. (grec-tree-proof name.typ sh) ~
13537+ ?> ?=(%generic -.sh)
13538+ ?> ?=([@ ~] vars.sh)
13539+ ?> ?=(%union -.body.sh)
13540+ ?> ?=([* [* ~]] cases.body.sh)
13541+ =/ ca=shape i.cases.body.sh
13542+ =/ cb=shape i.t.cases.body.sh
13543+ ?> ?=(%cell -.ca)
13544+ ?> ?=(%cell -.cb)
13545+ ?> ?=([* [* ~]] fields.ca)
13546+ ?> ?=([* *] fields.cb)
13547+ =/ tag-a=field i.fields.ca
13548+ =/ tag-b=field i.fields.cb
13549+ ?> ?=(%bare -.tag-a)
13550+ ?> ?=(%bare -.tag-b)
13551+ ?> ?=(%const -.shape.tag-a)
13552+ ?> ?=(%const -.shape.tag-b)
13553+ =/ text-field=field i.t.fields.ca
13554+ ?> ?=(%face -.text-field)
13555+ =/ branch=(list field) t.fields.cb
13556+ =/ kids=(unit field) (grec-tree-children branch i.vars.sh)
13557+ ?~ kids ~
13558+ ?> ?=(%face -.u.kids)
13559+ =/ children=itype [%face name.u.kids [%collection %list ~[typ]]]
13560+ ?> ?=(^ branch)
13561+ =/ payload=itype
13562+ ?~ t.branch children
13563+ =/ event=field i.branch
13564+ ?> ?=(%face -.event)
13565+ [%cell [%face name.event [%fn [%atom %t] i.args.typ]] children]
13566+ =/ leaf=itype [%cell [%const lit.shape.tag-a] [%face name.text-field [%atom %t]]]
13567+ =/ node=itype [%cell [%const lit.shape.tag-b] payload]
13568+ `[[%union ~[leaf node] ~ ~ ~] (dec fuel)]
13569+::
13570+++ grec-collect-molds
13571+ |= ds=(list def)
13572+ ^- grec-collected
13573+ ?~ ds [~ *(map term shape)]
13574+ =/ rest=grec-collected $(ds t.ds)
13575+ ?. ?=(%mold -.i.ds) rest
13576+ =/ name=term name.i.ds
13577+ =/ body=shape shape.i.ds
13578+ =/ proofs=(map term shape) proofs.rest
13579+ =? proofs (grec-tree-proof name body) (~(put by proofs) name body)
13580+ [[[name body] molds.rest] proofs]
13581+::
13582+
881113583--