@@ -774,39 +774,38 @@
774774:: (face 2:11 items
775775:: (apply 2:17 list (aura 2:23 @t)))
776776:: (face 2:27 open (flag 2:32))))
777−:: (mold 3:1 cart-action
777+:: (mold 3:1 poke
778778:: (union 4:3
779779:: (cell 4:3
780780:: (const 4:4 %add)
781781:: (face 4:9 item (aura 4:14 @t)))
782782:: (const 5:3 %toggle)))
783−:: (mold 6:1 poke (ref 6:9 cart-action))
784−:: (value 8:1 main
785−:: (group 8:9
786−:: (call 8:10 (wing 8:10 store) (wing 8:16 init) (wing 8:21 update))))
787−:: (value 9:1 init
788−:: (cast 9:9
789−:: (ref 9:12 state)
790−:: (tuple 9:18 (lit 9:19 ~) (lit 9:21 %.n))))
791−:: (value 10:1 update
792−:: (gate 10:11
793−:: (cell 10:14
794−:: (face 10:15 a (ref 10:17 cart-action))
795−:: (face 10:29 s (ref 10:31 state)))
796−:: (body 11:3
797−:: (branch 11:3
798−:: (wing 11:6 a)
783+:: (value 7:1 main
784+:: (group 7:9
785+:: (call 7:10 (wing 7:10 store) (wing 7:16 init) (wing 7:21 update))))
786+:: (value 8:1 init
787+:: (cast 8:9
788+:: (ref 8:12 state)
789+:: (tuple 8:18 (lit 8:19 ~) (lit 8:21 %.n))))
790+:: (value 9:1 update
791+:: (gate 9:11
792+:: (cell 9:14
793+:: (face 9:15 a (ref 9:17 poke))
794+:: (face 9:22 s (ref 9:24 state)))
795+:: (body 10:3
796+:: (branch 10:3
797+:: (wing 10:6 a)
798+:: (arm 11:5
799+:: (cell 11:5 (lit 11:6 %add) (bind 11:11 item))
800+:: (change 11:18 s
801+:: (edit 11:20 items
802+:: (tuple 11:26 (wing 11:27 item) (wing 11:32 items.s)))))
799803:: (arm 12:5
800−:: (cell 12:5 (lit 12:6 %add) (bind 12:11 item))
804+:: (lit 12:5 %toggle)
801805:: (change 12:18 s
802−:: (edit 12:20 items
803−:: (tuple 12:26 (wing 12:27 item) (wing 12:32 items.s)))))
804−:: (arm 13:5
805−:: (lit 13:5 %toggle)
806−:: (change 13:18 s
807−:: (edit 13:20 open
808−:: (group 13:25
809−:: (call 13:26 (wing 13:26 not) (wing 13:30 open.s)))))))))))
806+:: (edit 12:20 open
807+:: (group 12:25
808+:: (call 12:26 (wing 12:26 not) (wing 12:30 open.s)))))))))))
810809::
811810:: 4.3 Errors (+show-error): "<file>:<line>:<col>: <message>", then the
812811:: source line, then a caret under the column (col - 1 spaces, then ^).
@@ -874,7 +873,7 @@
874873 %'~[' %'|=(' %'$-(' :: openers
875874 %'%/' %'/' :: paths
876875 %'+' %'`' %'=' :: pair, unit, face
877− %'*' %'?' :: noun, loobean mold
876+ %'*' %'?' %'_' :: noun, loobean, type hole
878877 %'++' %'+$' %'|=' %'|$' :: runes
879878 %'^-' %'~&' %'?-' %'!!' :: runes
880879 %'/-' %'/%' %'/=' :: imports
@@ -1016,6 +1015,7 @@
10161015 [%const at=span =lit] :: ~ %add %.y
10171016 [%ref at=span names=(list term)] :: state item.todo
10181017 [%tvar at=span name=@t] :: M
1018+ [%hole at=span ~] :: _
10191019 [%path at=span segs=(list pseg)] :: / /todos /todo/[id=@ud]
10201020 [%apply at=span ref=(list term) args=(list shape)] :: (list @t)
10211021 [%cell at=span fields=(list field)] :: [text=@t done=?]
@@ -1024,9 +1024,9 @@
10241024 [%generic at=span vars=(list @t) body=shape] :: +$ name |$ [M] …
10251025 ==
10261026::
1027−:: +pseg: a path mold's segment, a knot or [name=aura]
1027+:: +pseg: a path mold's segment, a knot, [name=aura], or [name=_]
10281028::
1029−+$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta])
1029++$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta] [%inferred at=span name=term hole-at=span])
10301030::
10311031+| %api
10321032::
@@ -1295,6 +1295,7 @@
12951295 (emit 1 %'=')
12961296 ?: =('`' a) (emit 1 %'`')
12971297 ?: =('*' a) (emit 1 %'*')
1298+ ?: =('_' a) (emit 1 %'_')
12981299 ?: =('~' a)
12991300 ?: =('[' b) (emit 2 %'~[')
13001301 ?: =('&' b) (emit 2 %'~&')
@@ -1670,14 +1671,14 @@
16701671:: What may begin each place the parser reads (section 3, Errors):
16711672:: an expression a-z 0-9 " ( [ ~ % / ` | ^ ? !
16721673:: an operand a-z 0-9 " ( [ ~ % / ` | !
1673−:: a mold a-z A-Z @ * ! ? ~ % / ( [ $
1674+:: a mold a-z A-Z @ * ! ? ~ % / ( [ $ _
16741675:: a pattern a-z 0-9 " ~ % * [
16751676:: and what may go tight after an operand: . ( + = after a name, a
16761677:: closer ) ] }, or the : of a comment
16771678::
16781679++ expr-mask 0x57ff.ffff.4800.0000.83ff.8126.0000.0000
16791680++ operand-mask 0x57ff.ffff.0800.0000.03ff.8126.0000.0000
1680−++ mold-mask 0x47ff.fffe.0fff.ffff.8000.8532.0000.0000
1681+++ mold-mask 0x47ff.fffe.8fff.ffff.8000.8532.0000.0000
16811682++ bar-mask 0x1000.0000.0000.0000.0000.0000.0000.0000
16821683++ pattern-mask 0x47ff.fffe.0800.0000.03ff.0424.0000.0000
16831684++ after-mask 0x2000.0000.2000.0000.2400.4b00.0000.0000
@@ -2107,6 +2108,7 @@
21072108 ?- -.s
21082109 %knot (weld "/" (trip p.s))
21092110 %typed "/[{(trip name.s)}=@{(trip aura.s)}]"
2111+ %inferred "/[{(trip name.s)}=_]"
21102112 ==
21112113::
21122114++ show-tvars
@@ -2318,6 +2320,7 @@
23182320 %const (nod "const" at.s (show-lit lit.s) ~)
23192321 %ref (nod "ref" at.s (show-names names.s) ~)
23202322 %tvar (nod "tvar" at.s (trip name.s) ~)
2323+ %hole (nod "hole" at.s "" ~)
23212324 %path (nod "path" at.s (show-psegs segs.s) ~)
23222325 %apply (nod "apply" at.s (show-names ref.s) (turn args.s sexp-shape))
23232326 %cell (nod "cell" at.s "" (turn fields.s sexp-field))
@@ -3842,6 +3845,7 @@
38423845 %'*' [%& [%noun at.t ~] t.ts]
38433846 %'!!' [%& [%void at.t ~] t.ts]
38443847 %'?' [%& [%flag at.t ~] t.ts]
3848+ %'_' [%& [%hole at.t ~] t.ts]
38453849 [%name *] [%& [%ref at.t ~[p.lex.t]] t.ts]
38463850 [%wing *] [%& [%ref at.t p.lex.t] t.ts]
38473851 [%tvar *] [%& [%tvar at.t p.lex.t] t.ts]
@@ -4058,7 +4062,7 @@
40584062 ?: &(?=(^ nex) tight.i.nex) (bad nex "a path segment")
40594063 (bad-space i.after nex "a path segment")
40604064 ::
4061− :: +read-pseg: a path mold's segment, a knot or [name=aura] with no
4065+ :: +read-pseg: a path mold's knot, [name=aura], or [name=_] with no
40624066 :: spaces, and where it ends
40634067 ::
40644068 ++ read-pseg
@@ -4075,13 +4079,16 @@
40754079 ?: |(?=(~ r2) !tight.i.r2) (bad-space i.r1 r2 "`=`")
40764080 ?. ?=([[* * %'='] *] r2) (bad-in r2 "`=`" tis-mask)
40774081 =/ 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)
4082+ ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura or type hole")
4083+ ?. ?=([[* * ?([%aura *] %'_')] *] r3) (bad-in r3 "an aura or type hole" (con pat-mask (bex 95)))
40804084 =/ r4=(list token) t.r3
40814085 ?: |(?=(~ r4) !tight.i.r4) (bad-space i.r3 r4 "`]`")
40824086 ?. ?=([[* * %']'] *] r4) (bad-in r4 "`]`" ser-mask)
40834087 =/ 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]
4088+ =/ seg=pseg
4089+ ?: ?=(%'_' lex.i.r3) [%inferred at p.lex.i.r1 at.i.r3]
4090+ [%typed at p.lex.i.r1 p.lex.i.r3]
4091+ [%& [seg end.at.i.r4] t.r4]
40854092 --
40864093::
40874094+| %span-check
@@ -4465,6 +4472,7 @@
44654472 %const [%const at.s ~[%lit] %one ~]
44664473 %ref [%ref at.s ~[%name %wing] %one ~]
44674474 %tvar [%tvar at.s ~[%tvar] %one ~]
4475+ %hole [%hole at.s ~[%'_'] %one ~]
44684476 %apply [%apply at.s ~[%'('] %shut (turn args.s outline-shape)]
44694477 %cell [%cell at.s ~[%'['] %shut (turn fields.s outline-sample)]
44704478 ::
@@ -4473,8 +4481,11 @@
44734481 %+ murn segs.s
44744482 |= g=pseg
44754483 ^- (unit outline)
4476− ?. ?=(%typed -.g) ~
4477− `[%typed at.g ~[%'['] %shut ~]
4484+ ?- -.g
4485+ %knot ~
4486+ %typed `[%typed at.g ~[%'['] %shut ~]
4487+ %inferred `[%typed at.g ~[%'['] %shut ~[[%hole hole-at.g ~[%'_'] %one ~]]]
4488+ ==
44784489 [%path at.s ~[%'/'] %run ks]
44794490 ::
44804491 %union
@@ -4534,6 +4545,8 @@
45344545 [%path [1 9] [1 9] [1 21]]
45354546 [%face [1 7] [1 7] [1 21]]
45364547 ==
4548+ :: an inferred path aura's hole spanning its = as well
4549+ ['+$ x /a/[id=_]' ~[[%hole [1 13] [1 12] [1 14]]]]
45374550 :: an import's path cut short
45384551 ['/= c /ui/c' ~[[%jibb [1 1] [1 1] [1 11]]]]
45394552 :: brackets that close with the deeper lines, cut at their line's
@@ -4593,6 +4606,8 @@
45934606:: Atom constraints tied to an explicit capital or an inferred sample
45944607:: are generalized and printed. Other aura variables remain unsupported until
45954608:: their defaulting and inferred generalization are implemented.
4609+:: Restricted-number promotion considers written capitals only; if there
4610+:: are none, it skips the otherwise unnecessary environment traversal.
45964611:: Bare @ is a separate unrestricted atom type. A directional fit check
45974612:: permits concrete atoms to widen to it, never the reverse. A fit that
45984613:: needs a not-yet-implemented constraint remains unsupported. Named unions
@@ -4600,18 +4615,65 @@
46004615:: from their display name. Generic cases must be disjoint for all arguments.
46014616:: Unnamed union printing is informational; it is not Jibb syntax.
46024617::
4618+:: `proj` is a reserved, type-directed operation, not an ordinary gate.
4619+:: The supported fragment selects uniquely faced fields from a known record
4620+:: in source order (reordering is a doc question). It records the original
4621+:: call, source and target types, and source axes with its definition;
4622+:: A single selected field keeps its face and uses one source axis.
4623+:: Checked module interfaces retain that evidence and their source, including
4624+:: the private prelude dependency. A later lowerer must replace the call by
4625+:: an inline gate applied to the operand once; no lowering is implemented yet.
4626+:: Ordinary fits never insert a projection. Unknown or variable-origin record
4627+:: spines, nested projected fields and projections in
4628+:: recursive groups remain unsupported. Directional fits bound faced-spine
4629+:: proofs to fewer than 1,024 cells; the projection planner has a separate
4630+:: 4,096-step bound. These are inference limits, not language limits.
4631+::
4632+:: Supported API imports derive request-gate types atomically for multiple
4633+:: paths, including one typed segment or one diff fold per case. Their checked
4634+:: ordinary definitions, mark molds and supported poke constructor are also
4635+:: exported. A selected /sur mold is checked through its trusted reader result;
4636+:: unused cores and other bindings are not independently validated. APIs
4637+:: with /= imports, separate scry paths, multiple parameters or diffs, or a
4638+:: parameter together with a fold remain unsupported. The unchanged todo API
4639+:: fits this fragment, including named closed fold gates.
4640+::
4641+:: Each case's source-derived schema and canonical API identity travel in a
4642+:: dependency closure bound to the exact supplied bundle, prelude, scope and
4643+:: trusted reader results. Unknown cached entries are rebuilt. Request-bearing
4644+:: closures are limited to 256 source paths and requests. This is type
4645+:: inference only: no request lowering, runtime schema validator or proof that
4646+:: an arbitrary ask value is watchable is supplied.
4647+::
4648+:: A closed gate sample may omit one outer face from a known input slot when
4649+:: its product is identical. Distinct written names, nested value faces,
4650+:: ambiguous cell tails and raw-variable-origin fits retain their prior rules.
4651+::
4652+:: In one synthetic eval of a 48-module deep and 48-module wide request-free
4653+:: graph, baseline versus certificate inference took 21.53 s versus 23.10 s
4654+:: elapsed (21.10 s versus 22.34 s CPU), including startup. The deep cache's
4655+:: jam grew from 2,402 to 4,209 bytes (+1,807 bytes). These single-run figures
4656+:: are not production memory or performance benchmarks.
4657+::
46034658+$ itype
46044659 $~ [%var 0]
4605− $% [%var id=@ud]
4660+ $% [%var id=@ud]
4661+ [%fvar 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]
@@ -4619,7 +4681,7 @@
46194681 ==
46204682+$ ibinding [id=@ud val=itype]
46214683+$ isub (list ibinding)
4622−+$ ipending [id=@ud literal=lit]
4684++$ ipending [id=@ud literal=lit at=span]
46234685::
46244686++ itype-lookup
46254687 |= [n=@ud sub=isub]
@@ -4632,39 +4694,143 @@
46324694 |= [t=itype sub=isub]
46334695 ^- itype
46344696 ?+ -.t t
4635− %var
4697+ ?(%var %fvar)
46364698 =/ found=(unit itype) (itype-lookup id.t sub)
46374699 ?~ found t
4700+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ ?: &(|(?=(%fvar -.u.found) ?=(%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+ %fvar `[%unknown fuel]
4779+ %var
4780+ ?: (lien caps |=(c=icap (hole-same-variable typ (itype-walk [%var id.c] sub)))) `[%yes fuel]
4781+ `[%unknown fuel]
4782+ %face $(typ body.typ)
4783+ %cell
4784+ =/ head=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ hed.typ)
4785+ ?~ head ~
4786+ ?: =(%no result.u.head) head
4787+ =/ tail=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ tal.typ, fuel left.u.head)
4788+ ?~ tail ~
4789+ ?: =(%no result.u.tail) tail
4790+ ?: |(=(%unknown result.u.head) =(%unknown result.u.tail)) `[%unknown left.u.tail]
4791+ `[%yes left.u.tail]
4792+ %union (itype-inhabited-cases cases.typ sub caps fuel |)
4793+ %collection
4794+ ?. &(|(=(%list name.typ) =(%unit name.typ)) ?=([* ~] args.typ)) `[%unknown fuel]
4795+ `[%yes fuel]
4796+ %grec ?:((grec-tree-proof name.typ proof.typ) `[%yes fuel] `[%unknown fuel])
4797+ * `[%unknown fuel]
4798+ ==
4799+++ itype-live-cases
4800+ |= [xs=(list itype) sub=isub caps=icaps fuel=@ud]
4801+ ^- (unit (list itype))
4802+ ?~ xs `~
4803+ =/ first=(unit [result=?(%yes %no %unknown) left=@ud])
4804+ (itype-inhabited-proof i.xs sub caps fuel)
4805+ ?~ first ~
4806+ ?: =(%unknown result.u.first) ~
4807+ =/ rest=(unit (list itype)) $(xs t.xs, fuel left.u.first)
4808+ ?~ rest ~
4809+ ?: =(%no result.u.first) rest
4810+ `[i.xs u.rest]
4811+::
46534812++ itype-occurs
46544813 |= [n=@ud t=itype sub=isub]
46554814 ^- ?
46564815 =. t (itype-walk t sub)
46574816 ?- -.t
46584817 %var =(n id.t)
4818+ %fvar =(n id.t)
46594819 %avar =(n id.t)
4820+ %rvar =(n id.t)
46604821 %nvar =(n id.t)
4822+ %rnvar =(n id.t)
46614823 %atom |
46624824 %any-atom |
46634825 %flag |
4826+ %noun |
4827+ %empty |
46644828 %tag =(n id.t)
46654829 %const |
46664830 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
46674831 %recursive |
4832+ %jrec |
4833+ %grec (lien args.t |=(c=itype (itype-occurs n c sub)))
46684834 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
46694835 %face $(t body.t)
46704836 %fn |($(t sample.t) $(t product.t))
@@ -4683,6 +4849,11 @@
46834849 =. a (itype-walk a sub)
46844850 =. b (itype-walk b sub)
46854851 ?: =(a b) `sub
4852+ ?: &(?=(%grec -.a) ?=(%grec -.b))
4853+ ?. &(=(at.a at.b) =(name.a name.b)) ~
4854+ (itype-unify-args args.a args.b sub)
4855+ ?: &(?=(%jrec -.a) ?=(%jrec -.b))
4856+ ?:(&(=(at.a at.b) =(name.a name.b) =(head.a head.b) =(aura.a aura.b) =(tail.a tail.b)) `sub ~)
46864857 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
46874858 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
46884859 ?: &(?=(%union -.a) ?=(%union -.b))
@@ -4699,6 +4870,38 @@
46994870 ?: ?=(%var -.b)
47004871 ?: (itype-occurs id.b a sub) ~
47014872 `[[id.b a] sub]
4873+ ?: ?=(%fvar -.a)
4874+ ?: (itype-occurs id.a b sub) ~
4875+ (itype-bind-gate-free id.a b sub)
4876+ ?: ?=(%fvar -.b)
4877+ ?: (itype-occurs id.b a sub) ~
4878+ (itype-bind-gate-free id.b a sub)
4879+ :: Arithmetic's aura variable excludes loobeans; decimal literals
4880+ :: remain defaultable until a later constraint makes them concrete.
4881+ ?: &(?=(%nvar -.a) ?=(%rvar -.b))
4882+ `[[id.b [%rnvar id.a]] [id.a [%rnvar id.a]] sub]
4883+ ?: &(?=(%rvar -.a) ?=(%nvar -.b))
4884+ `[[id.a [%rnvar id.b]] [id.b [%rnvar id.b]] sub]
4885+ ?: &(?=(%rnvar -.a) ?=(%rvar -.b)) `[[id.b a] sub]
4886+ ?: &(?=(%rvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4887+ ?: &(?=(%rnvar -.a) ?=(%nvar -.b)) `[[id.b a] sub]
4888+ ?: &(?=(%nvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4889+ ?: &(?=(%rnvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4890+ ?: &(?=(%avar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4891+ ?: ?=(%rnvar -.a)
4892+ ?. |(?=(%rnvar -.b) ?=(%atom -.b)) ~
4893+ `[[id.a b] sub]
4894+ ?: ?=(%rnvar -.b)
4895+ ?. ?=(%atom -.a) ~
4896+ `[[id.b a] sub]
4897+ ?: &(?=(%avar -.a) ?=(%rvar -.b)) `[[id.a b] sub]
4898+ ?: &(?=(%rvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4899+ ?: ?=(%rvar -.a)
4900+ ?. |(?=(%rvar -.b) ?=(%atom -.b)) ~
4901+ `[[id.a b] sub]
4902+ ?: ?=(%rvar -.b)
4903+ ?. ?=(%atom -.a) ~
4904+ `[[id.b a] sub]
47024905 :: The narrower decimal constraint survives a match with an atom
47034906 :: variable; decimal syntax alone does not make it a loobean.
47044907 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
@@ -4731,6 +4934,69 @@
47314934 $(a tal.a, b tal.b, sub u.first)
47324935 ~
47334936::
4937++$ igf-form [typ=itype sub=isub left=@ud]
4938++$ igf-forms [types=(list itype) sub=isub left=@ud]
4939+++ itype-gate-free-forms
4940+ |= [xs=(list itype) sub=isub fuel=@ud]
4941+ ^- (unit igf-forms)
4942+ ?~ xs `[~ sub fuel]
4943+ =/ head=(unit igf-form) (itype-gate-free-form i.xs sub fuel)
4944+ ?~ head ~
4945+ =/ tail=(unit igf-forms) $(xs t.xs, sub sub.u.head, fuel left.u.head)
4946+ ?~ tail ~
4947+ `[[typ.u.head types.u.tail] sub.u.tail left.u.tail]
4948+::
4949+++ itype-gate-free-form
4950+ |= [t=itype sub=isub fuel=@ud]
4951+ ^- (unit igf-form)
4952+ ?: =(0 fuel) ~
4953+ =. fuel (dec fuel)
4954+ =. t (itype-walk t sub)
4955+ ?- -.t
4956+ %var
4957+ =/ free=itype [%fvar id.t]
4958+ `[free [[id.t free] sub] fuel]
4959+ %fvar `[t sub fuel]
4960+ ?(%atom %any-atom %flag %const %empty %avar %rvar %nvar %rnvar %jrec) `[t sub fuel]
4961+ %face
4962+ =/ body=(unit igf-form) $(t body.t, sub sub, fuel fuel)
4963+ ?~ body ~
4964+ `[[%face name.t typ.u.body] sub.u.body left.u.body]
4965+ %cell
4966+ =/ head=(unit igf-form) $(t hed.t, sub sub, fuel fuel)
4967+ ?~ head ~
4968+ =/ tail=(unit igf-form) $(t tal.t, sub sub.u.head, fuel left.u.head)
4969+ ?~ tail ~
4970+ `[[%cell typ.u.head typ.u.tail] sub.u.tail left.u.tail]
4971+ %collection
4972+ =/ args=(unit igf-forms) (itype-gate-free-forms args.t sub fuel)
4973+ ?~ args ~
4974+ `[[%collection name.t types.u.args] sub.u.args left.u.args]
4975+ %union
4976+ =/ cases=(unit igf-forms) (itype-gate-free-forms cases.t sub fuel)
4977+ ?~ cases ~
4978+ =/ args=(unit igf-forms) (itype-gate-free-forms args.t sub.u.cases left.u.cases)
4979+ ?~ args ~
4980+ `[[%union types.u.cases origin.t label.t types.u.args] sub.u.args left.u.args]
4981+ * ~
4982+ ==
4983+::
4984+++ itype-collection-keys
4985+ |= [name=term args=(list itype) sub=isub]
4986+ ^- (unit [types=(list itype) sub=isub])
4987+ ?~ args `[~ sub]
4988+ ?. |(?=(?(%set %map %mop %jar %jug) name)) `[args sub]
4989+ =/ key=(unit igf-form) (itype-gate-free-form i.args sub 256)
4990+ ?~ key ~
4991+ `[[typ.u.key t.args] sub.u.key]
4992+::
4993+++ itype-bind-gate-free
4994+ |= [n=@ud t=itype sub=isub]
4995+ ^- (unit isub)
4996+ =/ constrained=(unit igf-form) (itype-gate-free-form t sub 256)
4997+ ?~ constrained ~
4998+ `[[n typ.u.constrained] sub.u.constrained]
4999+::
47345000++ itype-unify-args
47355001 |= [as=(list itype) bs=(list itype) sub=isub]
47365002 ^- (unit isub)
@@ -4752,15 +5018,22 @@
47525018 =. t (itype-walk t sub)
47535019 ?- -.t
47545020 %var |
5021+ %fvar |
47555022 %avar |
5023+ %rvar |
47565024 %nvar |
5025+ %rnvar |
47575026 %atom |
47585027 %any-atom &
47595028 %flag |
5029+ %noun |
5030+ %empty |
47605031 %tag |
47615032 %const |
47625033 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
47635034 %recursive |
5035+ %jrec |
5036+ %grec (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47645037 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47655038 %face $(t body.t)
47665039 %fn |($(t sample.t) $(t product.t))
@@ -4822,15 +5095,22 @@
48225095 ^- ?
48235096 ?- -.typ
48245097 %var |
5098+ %fvar |
48255099 %avar |
5100+ %rvar |
48265101 %nvar |
5102+ %rnvar |
48275103 %atom &
48285104 %any-atom &
48295105 %flag &
5106+ %noun |
5107+ %empty |
48305108 %tag &
48315109 %const &
48325110 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
48335111 %recursive |
5112+ %jrec |
5113+ %grec (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48345114 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48355115 %face $(typ body.typ)
48365116 %fn |($(typ sample.typ) $(typ product.typ))
@@ -4859,6 +5139,7 @@
48595139 ^- ?
48605140 =. t (itype-walk t sub)
48615141 ?- -.t
5142+ %grec (lien args.t |=(c=itype (itype-has-face c sub)))
48625143 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
48635144 %face &
48645145 %cell |($(t hed.t) $(t tal.t))
@@ -4866,6 +5147,42 @@
48665147 * |
48675148 ==
48685149::
5150+:: Closed function samples may omit a slot face, but a known name must
5151+:: match another known name. Keep nested value faces and require exact
5152+:: invariant compatibility; a faced tail against a cell is ambiguous.
5153+++ itype-closed-slot-match
5154+ |= [a=itype b=itype]
5155+ ^- ?
5156+ ?: &(?=(%face -.a) ?=(%face -.b))
5157+ ?. =(name.a name.b) |
5158+ ?=(^ (itype-unify body.a body.b ~))
5159+ ?: ?=(%face -.a) ?=(^ (itype-unify body.a b ~))
5160+ ?: ?=(%face -.b) ?=(^ (itype-unify a body.b ~))
5161+ ?=(^ (itype-unify a b ~))
5162+++ itype-closed-sample-match
5163+ |= [a=itype b=itype fuel=@ud]
5164+ ^- ?
5165+ ?: =(0 fuel) |
5166+ ?. &(?=(%cell -.a) ?=(%cell -.b)) |
5167+ ?. (itype-closed-slot-match hed.a hed.b) |
5168+ =/ x=itype tal.a
5169+ =/ y=itype tal.b
5170+ ?: &(?=(%cell -.x) ?=(%cell -.y))
5171+ ?=(^ (itype-unify x y ~))
5172+ ?: |(&(?=(%face -.x) ?=(%cell -.y)) &(?=(%cell -.x) ?=(%face -.y))) |
5173+ (itype-closed-slot-match x y)
5174+++ itype-closed-gates-match
5175+ |= [a=itype b=itype]
5176+ ^- ?
5177+ ?. &(?=(%fn -.a) ?=(%fn -.b)) |
5178+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) |
5179+ ?. =(product.a product.b) |
5180+ ?^ (itype-vars a) |
5181+ ?^ (itype-vars b) |
5182+ ?: |((itype-has-tag a) (itype-has-tag b)) |
5183+ ?. (itype-closed-sample-match sample.a sample.b 1.024) |
5184+ ?=(^ (itype-unify product.a product.b ~))
5185+::
48695186++ itype-face-asym-collection-args
48705187 |= [as=(list itype) bs=(list itype) sub=isub]
48715188 ^- ?
@@ -4879,12 +5196,15 @@
48795196 ^- ?
48805197 =. a (itype-walk a sub)
48815198 =. b (itype-walk b sub)
5199+ ?: &(?=(%grec -.a) ?=(%grec -.b))
5200+ ?. &(=(at.a at.b) =(name.a name.b)) |
5201+ (itype-face-asym-collection-args args.a args.b sub)
48825202 ?: &(?=(%collection -.a) ?=(%collection -.b))
48835203 ?. =(name.a name.b) |
48845204 (itype-face-asym-collection-args args.a args.b sub)
48855205 ?: &(?=(%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))
5206+ ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%fvar -.b) ?=(%avar -.b) ?=(%rvar -.b) |(?=(%nvar -.b) ?=(%rnvar -.b)))
5207+ ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%fvar -.a) ?=(%avar -.a) ?=(%rvar -.a) |(?=(%nvar -.a) ?=(%rnvar -.a)))
48885208 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
48895209 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
48905210 |
@@ -4907,6 +5227,30 @@
49075227 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
49085228 expected
49095229::
5230+:: Positional call arguments do not write the sample's enclosing field
5231+:: labels. Ignore one raw sample-slot face per written argument while
5232+:: checking value faces as usual. An unknown or variable-bound cell spine
5233+:: cannot justify this distinction, so keep the existing conservative guard.
5234+++ itype-positional-slot-face-asym
5235+ |= [actual=itype expected=itype sub=isub]
5236+ ^- ?
5237+ ?: &(?=(%fn -.actual) ?=(%fn -.expected) (itype-closed-gates-match actual expected)) |
5238+ (itype-face-asym actual expected sub)
5239+::
5240+++ itype-positional-face-asym
5241+ |= [args=(list expr) actual=itype expected=itype sub=isub]
5242+ ^- ?
5243+ ?~ args &
5244+ ?~ t.args
5245+ =/ slot=itype expected
5246+ =? slot ?=(%face -.slot) body.slot
5247+ (itype-positional-slot-face-asym actual slot sub)
5248+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) &
5249+ =/ slot=itype hed.expected
5250+ =? slot ?=(%face -.slot) body.slot
5251+ ?: (itype-positional-slot-face-asym hed.actual slot sub) &
5252+ $(args t.args, actual tal.actual, expected tal.expected)
5253+::
49105254++ itype-output-may-be-cell
49115255 |= [t=itype sub=isub]
49125256 ^- ?
@@ -4916,6 +5260,9 @@
49165260 %cell &
49175261 %union &
49185262 %recursive &
5263+ %jrec &
5264+ %grec &
5265+ %noun &
49195266 %collection &
49205267 %face $(t body.t)
49215268 %fn |($(t sample.t) $(t product.t))
@@ -4929,6 +5276,13 @@
49295276 ?~ (itype-lookup id.i.tags sub) &
49305277 $(tags t.tags)
49315278::
5279+++ pending-tag-diagnostic
5280+ |= [tags=(list ipending) sub=isub]
5281+ ^- (unit [at=span msg=tape])
5282+ ?~ tags ~
5283+ ?^ (itype-lookup id.i.tags sub) $(tags t.tags)
5284+ `[at.i.tags (weld "nothing fixes the union of " (show-lit literal.i.tags))]
5285+::
49325286++ pending-null
49335287 |= [tags=(list ipending) sub=isub]
49345288 ^- ?
@@ -4944,6 +5298,7 @@
49445298 ^- ?
49455299 ?- -.t
49465300 %tag &
5301+ %grec (lien args.t |=(c=itype (itype-has-tag c)))
49475302 %collection (lien args.t |=(c=itype (itype-has-tag c)))
49485303 %face $(t body.t)
49495304 %fn |($(t sample.t) $(t product.t))
@@ -4957,6 +5312,7 @@
49575312 ^- ?
49585313 ?- -.t
49595314 %union &
5315+ %grec (lien args.t |=(c=itype (itype-has-union c)))
49605316 %collection (lien args.t |=(c=itype (itype-has-union c)))
49615317 %face $(t body.t)
49625318 %fn |($(t sample.t) $(t product.t))
@@ -4975,6 +5331,7 @@
49755331 %union
49765332 ?: &(?=(~ label.t) ?=(^ args.t)) &
49775333 (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-generic c)))
5334+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-generic c))))
49785335 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
49795336 %face $(t body.t)
49805337 %fn |($(t sample.t) $(t product.t))
@@ -4987,6 +5344,8 @@
49875344 ^- ?
49885345 ?- -.t
49895346 %recursive &
5347+ %jrec &
5348+ %grec &
49905349 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
49915350 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
49925351 %face $(t body.t)
@@ -5000,6 +5359,8 @@
50005359 ^- ?
50015360 ?- -.t
50025361 %recursive ?=(~ label.t)
5362+ %jrec ?=(~ label.t)
5363+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-recursive c))))
50035364 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
50045365 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
50055366 %face $(t body.t)
@@ -5027,34 +5388,107 @@
50275388 $(cases t.cases, good `trial)
50285389 ==
50295390::
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.
5391+:: A constructor needs a case whose head has the same literal noun as its
5392+:: tag. An unresolved or opaque case may reveal one later, so it cannot
5393+:: prove a mismatch or a unique match. A broad atom mold is not a case.
50335394::
50345395++ itype-fit-ctor-cases
50355396 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
50365397 ^- ifit
50375398 =/ found=(unit ifit) ~
5399+ =/ pending=? |
50385400 |-
5039− ?~ cases ?~(found [%bad ~] u.found)
5040− =/ c=itype (itype-walk i.cases sub)
5401+ ?~ cases
5402+ ?: pending [%unknown ~]
5403+ ?~ found [%bad ~]
5404+ u.found
5405+ =/ raw=itype i.cases
5406+ ?: ?=(%var -.raw)
5407+ $(cases t.cases, pending &)
5408+ =/ c=itype (itype-walk raw sub)
5409+ ?: ?=(?(%var %tag %recursive %jrec %grec %union %face) -.c)
5410+ $(cases t.cases, pending &)
50415411 ?. ?=(%cell -.c) $(cases t.cases)
5042− =/ head=itype (itype-walk hed.c sub)
5412+ =/ raw-head=itype hed.c
5413+ ?: ?=(%var -.raw-head)
5414+ $(cases t.cases, pending &)
5415+ =/ head=itype (itype-walk raw-head sub)
5416+ :: A single faced, explicitly atom-only head cannot be the tag case.
5417+ :: Do not follow variables or peel nested faces for this negative proof.
5418+ ?: ?=(%face -.head)
5419+ ?: ?=(?(%atom %any-atom %flag %avar %rvar %nvar %rnvar) -.body.head)
5420+ $(cases t.cases)
5421+ $(cases t.cases, pending &)
5422+ ?: ?=(?(%var %tag %recursive %jrec %grec %union) -.head)
5423+ $(cases t.cases, pending &)
50435424 ?. ?=(%const -.head) $(cases t.cases)
5044− ?. =(%term form.literal.head) $(cases t.cases)
50455425 ?. =(val.literal.head val.tag) $(cases t.cases)
5046− ?^ found [%unknown ~]
5426+ :: Equal heads can have disjoint payloads. Test each from the original
5427+ :: substitution; a unique success is usable only with no unknown rival.
50475428 =/ trial=ifit (itype-fit sample tal.c sub next)
5048− $(cases t.cases, found `trial)
5429+ ?- -.trial
5430+ %bad $(cases t.cases)
5431+ %unknown $(cases t.cases, pending &)
5432+ %ok
5433+ ?^ found [%unknown ~]
5434+ $(cases t.cases, found `trial)
5435+ ==
50495436::
50505437++ itype-fit
50515438 |= [actual=itype expected=itype sub=isub next=@ud]
50525439 ^- ifit
5440+ =/ result=ifit (itype-fit-inner actual expected sub next | |)
5441+ ?: ?=(%ok -.result) result
5442+ =/ source=itype (itype-walk actual sub)
5443+ ?. ?=(?(%empty %face %cell %union) -.source) result
5444+ =/ empty=(unit [empty=? left=@ud]) (itype-empty-proof actual sub 256)
5445+ ?~ empty [%unknown ~]
5446+ ?: empty.u.empty [%ok sub next]
5447+ result
5448+++ itype-fit-inner
5449+ |= [actual=itype expected=itype sub=isub next=@ud skip-width=? spine-proof=?]
5450+ ^- ifit
5451+ ?: &(!skip-width ?=(%cell -.actual) ?=(%cell -.expected) |((width-spine-exhausted actual 1.024) (width-spine-exhausted expected 1.024)))
5452+ [%unknown ~]
5453+ =/ known=(unit [source=iwfields target=iwfields])
5454+ ?: skip-width ~
5455+ (width-known-shape actual expected sub)
5456+ =/ too-wide=? ?~(known | (gth (lent order.source.u.known) (lent order.target.u.known)))
5457+ ?: too-wide [%unknown ~]
5458+ =/ spine-checked=? |(spine-proof ?=(^ known))
50535459 =/ uncertain=?
5054− |(?=(%var -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%var -.expected) ?=(%avar -.expected) ?=(%nvar -.expected))
5460+ |(?=(%var -.actual) ?=(%fvar -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%var -.expected) ?=(%fvar -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)))
5461+ =/ actual-open=?
5462+ |(?=(%var -.actual) ?=(%fvar -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))
50555463 =. actual (itype-walk actual sub)
50565464 =. expected (itype-walk expected sub)
50575465 ?: =(actual expected) [%ok sub next]
5466+ ?: &(?=(%empty -.expected) |(?=(%cell -.actual) ?=(%face -.actual) ?=(%union -.actual) ?=(%grec -.actual) ?=(%recursive -.actual))) [%unknown ~]
5467+ :: The relation of the source loobean mold to explicit @f is not yet
5468+ :: established. Keep it unsupported rather than asserting a mismatch.
5469+ ?: &(?=(%flag -.actual) ?=(%atom -.expected) =(%f aura.expected)) [%unknown ~]
5470+ :: Any value can be used where a noun is expected. An unresolved
5471+ :: bare tag is fixed as a constant; a constructor still needs a gate.
5472+ ?: ?=(%noun -.expected)
5473+ ?: ?=(%tag -.actual)
5474+ ?: constructor.actual [%unknown ~]
5475+ [%ok [[id.actual expected] sub] next]
5476+ [%ok sub next]
5477+ :: An arbitrary noun is not known to fit a narrower type.
5478+ ?: &(?=(%noun -.actual) !?=(%var -.expected)) [%unknown ~]
5479+ ?: &(!uncertain ?=(%grec -.actual) ?=(%face -.expected)) $(expected body.expected)
5480+ ?: &(!uncertain ?=(%face -.actual) ?=(%grec -.expected)) $(actual body.actual)
5481+ ?: &(?=(%grec -.actual) ?=(%grec -.expected))
5482+ ?. &(=(at.actual at.expected) =(name.actual name.expected)) [%unknown ~]
5483+ =/ matched=(unit isub) (itype-unify-args args.actual args.expected sub)
5484+ ?~ matched [%unknown ~]
5485+ [%ok u.matched next]
5486+ ?: &(|(?=(%grec -.actual) ?=(%grec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5487+ ?: &(!uncertain ?=(%jrec -.actual) ?=(%face -.expected)) $(expected body.expected)
5488+ ?: &(!uncertain ?=(%face -.actual) ?=(%jrec -.expected)) $(actual body.actual)
5489+ ?: &(?=(%jrec -.actual) ?=(%jrec -.expected))
5490+ ?:(&(=(at.actual at.expected) =(name.actual name.expected) =(head.actual head.expected) =(aura.actual aura.expected) =(tail.actual tail.expected)) [%ok sub next] [%bad ~])
5491+ ?: &(|(?=(%jrec -.actual) ?=(%jrec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
50585492 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
50595493 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
50605494 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
@@ -5066,8 +5500,21 @@
50665500 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
50675501 ?^ unified [%ok u.unified next]
50685502 [%unknown ~]
5503+ :: A known union can instantiate an unconstrained sample directly;
5504+ :: preserve unknown results for variable-bound union origins.
5505+ ?: &(!actual-open ?=(%union -.actual) ?=(%var -.expected))
5506+ ?~ origin.actual [%unknown ~]
5507+ =/ normalized=itype (itype-normalize actual sub)
5508+ ?: |((itype-has-tag normalized) (itype-has-recursive normalized) (itype-has-any-atom actual sub)) [%unknown ~]
5509+ =/ unified=(unit isub) (itype-unify actual expected sub)
5510+ ?~ unified [%unknown ~]
5511+ [%ok u.unified next]
5512+ :: A concrete union value in a tuple may acquire the expected field's
5513+ :: face. A variable-bound union still needs face propagation support.
5514+ ?: &(!uncertain ?=(%union -.actual) ?=(%face -.expected))
5515+ $(expected body.expected)
50695516 ?: ?=(%union -.actual) [%unknown ~]
5070− ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
5517+ ?: &(?=(%union -.expected) |(?=(%fvar -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))) [%unknown ~]
50715518 ?: &(?=(%union -.expected) !?=(%var -.actual))
50725519 (itype-fit-cases actual cases.expected sub next)
50735520 ?: ?=(%tag -.actual)
@@ -5075,7 +5522,7 @@
50755522 =/ u=(unit isub) (itype-unify actual expected sub)
50765523 ?~ u [%bad ~]
50775524 [%ok u.u next]
5078− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5525+ ?: |(?=(%fvar -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
50795526 ?: ?=(%face -.expected) $(expected body.expected)
50805527 ?: constructor.actual
50815528 ?. ?=(%fn -.expected) [%bad ~]
@@ -5084,6 +5531,10 @@
50845531 =/ trial=ifit (itype-fit-ctor-cases literal.actual sample.expected cases sub next)
50855532 ?. ?=(%ok -.trial) trial
50865533 [%ok [[id.actual expected] sub.trial] next.trial]
5534+ :: Zero may be the empty list. A nested cell fit lacks the context
5535+ :: needed to resolve it here, so do not report a definite mismatch.
5536+ ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
5537+ [%unknown ~]
50875538 ?: ?=(%const -.expected)
50885539 ?:(=(val.literal.actual val.literal.expected) [%ok [[id.actual expected] sub] next] [%bad ~])
50895540 ?: ?=(%atom -.expected)
@@ -5099,20 +5550,39 @@
50995550 =/ u=(unit isub) (itype-unify actual expected sub)
51005551 ?~ u [%bad ~]
51015552 [%ok u.u next]
5102− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5553+ ?: |(?=(%fvar -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51035554 ?: ?=(%face -.expected) $(expected body.expected)
5555+ ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
5556+ [%unknown ~]
51045557 ?: ?=(%const -.expected)
51055558 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
51065559 ?: ?=(%atom -.expected)
5560+ :: A loobean singleton must not silently widen into another aura.
5561+ ?: =(%loobean form.literal.actual)
5562+ ?: =(%f aura.expected) [%unknown ~]
5563+ [%bad ~]
51075564 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
51085565 [%bad ~]
51095566 ?: ?=(%flag -.expected)
51105567 ?:(|(=(0 val.literal.actual) =(1 val.literal.actual)) [%ok sub next] [%bad ~])
51115568 ?: ?=(%any-atom -.expected) [%ok sub next]
51125569 [%bad ~]
5570+ :: A field on an expected sample slot labels the value's type; it does
5571+ :: not become a face on the actual argument. Unify with the slot body
5572+ :: rather than binding either variable to the face around the other.
5573+ ?: &(?=(%var -.actual) ?=(%face -.expected))
5574+ =/ unified=(unit isub) (itype-unify actual body.expected sub)
5575+ ?~ unified [%unknown ~]
5576+ [%ok u.unified next]
51135577 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
5578+ :: A known face labels the same noun. Peel it before applying the
5579+ :: directional unrestricted-atom rule, preserving raw-variable guards.
5580+ ?: &(!uncertain ?=(%any-atom -.actual) ?=(%face -.expected))
5581+ $(expected body.expected, skip-width |, spine-proof |)
5582+ ?: &(!uncertain ?=(%any-atom -.expected) ?=(%face -.actual))
5583+ $(actual body.actual, skip-width |, spine-proof |)
51145584 ?: ?=(%any-atom -.expected)
5115− ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
5585+ ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%flag -.actual)) [%ok sub next]
51165586 ?: ?=(%var -.actual)
51175587 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
51185588 ?~ unified [%bad ~]
@@ -5123,28 +5593,20 @@
51235593 =/ unified=(unit isub) (itype-unify actual expected sub)
51245594 ?~ unified [%bad ~]
51255595 [%ok u.unified next]
5126− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5596+ ?: |(?=(%fvar -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51275597 [%bad ~]
51285598 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
51295599 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
51305600 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
51315601 [%bad ~]
51325602 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5133− =/ first=ifit $(actual hed.actual, expected hed.expected)
5603+ =/ first=ifit $(actual hed.actual, expected hed.expected, skip-width |, spine-proof |)
51345604 ?. ?=(%ok -.first) first
5135− $(actual tal.actual, expected tal.expected, sub sub.first, next next.first)
5136− :: A field may add a face to an occurrence of the very same type
5137− :: variable. Binding that variable to a face around itself would fail
5138− :: the occurs check, but its underlying type has already matched.
5139− ?: &(?=(%var -.actual) ?=(%face -.expected) =(actual (itype-walk body.expected sub)))
5140− [%ok sub next]
5141− :: Differing variables and faces need propagation that is not yet
5142− :: represented. Binding one to the face can create a false mismatch.
5143− ?: &(?=(%var -.actual) ?=(%face -.expected)) [%unknown ~]
5605+ $(actual tal.actual, expected tal.expected, sub sub.first, next next.first, skip-width spine-checked, spine-proof spine-checked)
51445606 ?: &(?=(%face -.actual) ?=(%var -.expected)) [%unknown ~]
51455607 ?: &(?=(%var -.actual) (itype-has-any-atom expected sub))
51465608 [%unknown ~]
5147− ?: |(?=(%var -.actual) ?=(%var -.expected))
5609+ ?: |(?=(%var -.actual) ?=(%var -.expected) ?=(%fvar -.expected))
51485610 =/ unified=(unit isub) (itype-unify actual expected sub)
51495611 ?~ unified
51505612 ?: |(?=(%face -.actual) ?=(%face -.expected)) [%unknown ~]
@@ -5154,9 +5616,10 @@
51545616 [%ok u.unified next]
51555617 ?: &(?=(%face -.actual) ?=(%face -.expected))
51565618 ?. =(name.actual name.expected) [%bad ~]
5157− $(actual body.actual, expected body.expected)
5158− ?: ?=(%face -.actual) $(actual body.actual)
5159− ?: ?=(%face -.expected) $(expected body.expected)
5619+ $(actual body.actual, expected body.expected, skip-width |, spine-proof |)
5620+ ?: ?=(%face -.actual) $(actual body.actual, skip-width |, spine-proof |)
5621+ ?: ?=(%face -.expected) $(expected body.expected, skip-width |, spine-proof |)
5622+ ?: &(!uncertain (itype-closed-gates-match actual expected)) [%ok sub next]
51605623 ?: (itype-face-asym actual expected sub) [%unknown ~]
51615624 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
51625625 [%unknown ~]
@@ -5223,16 +5686,61 @@
52235686 (itype-fit [%collection %list ~[a]] list-t ~[[0 recursive]] 1)
52245687 =? problems !?=(%unknown -.nested-fit)
52255688 ["recursive types behind substitutions should remain uncertain" problems]
5689+ =/ free=itype [%fvar 40]
5690+ =/ open-cell=itype [%cell [%var 41] [%face %x [%var 42]]]
5691+ =/ constrained=(unit isub) (itype-unify free open-cell ~)
5692+ =/ expected-cell=itype [%cell [%fvar 41] [%face %x [%fvar 42]]]
5693+ =? problems !=(constrained [~ [[40 expected-cell] [[42 [%fvar 42]] [[41 [%fvar 41]] ~]]]])
5694+ ["gate-free constraints should propagate through cells and faces" problems]
5695+ =? problems ?=(^ (itype-unify free open-cell ~[[41 [%fn txt txt]]]))
5696+ ["an existing nested gate substitution should be rejected" problems]
5697+ =/ shared-sub=isub [[42 [%fvar 42]] [[41 [%fvar 41]] ~]]
5698+ =? problems ?=(^ (itype-unify [%var 41] [%fn txt txt] shared-sub))
5699+ ["a later nested gate substitution should be rejected" problems]
5700+ =? problems ?=(^ (itype-unify free [%fn txt txt] ~))
5701+ ["a gate-free variable should reject a gate" problems]
5702+ =? problems ?=(^ (itype-unify free [%noun ~] ~))
5703+ ["a gate-free variable should reject an opaque noun" problems]
5704+ =/ atom-strong=(unit isub) (itype-unify [%avar 43] free ~)
5705+ =? problems !=(atom-strong [~ [[40 [%avar 43]] ~]])
5706+ ["the atom constraint should be stronger than gate-free" problems]
5707+ =/ free-fit=ifit (itype-fit txt free ~ 44)
5708+ =? problems !?=(%ok -.free-fit)
5709+ ["a concrete atom should fit a gate-free variable" problems]
5710+ =/ gate-fit=ifit (itype-fit [%fn txt txt] free ~ 44)
5711+ =? problems !?=(%bad -.gate-fit)
5712+ ["a gate should not fit a gate-free variable" problems]
5713+ =/ free-scheme=ischeme [[%fn free free] ~[40]]
5714+ =/ canonical-free=itype (canonical-itype typ.free-scheme vars.free-scheme)
5715+ =? problems !=(canonical-free [%fn [%fvar 0] [%fvar 0]])
5716+ ["canonicalization should retain gate-free variables" problems]
5717+ =? problems !=((show-atom-constraint canonical-free) " where A contains no gates")
5718+ ["the printer should show gate-free constraints" problems]
52265719 problems
52275720::
52285721:: The expression inference below is deliberately a fragment: bindings,
5229−:: simple gates, calls, fixed-aura literals, and plain strings. The
5722+:: simple gates, calls, fixed-aura literals, and some interpolated strings. The
52305723:: result for unsupported syntax is a diagnostic, never a checked module.
52315724::
52325725+$ ischeme [typ=itype vars=(list @ud)]
52335726+$ ienv (list [name=term scheme=ischeme])
52345727+$ imold-types (list [name=term template=ischeme])
5235−+$ ifile [values=ienv molds=imold-types at=path]
5728++$ iderived [name=term agent=term mark=term]
5729++$ iwidth-definition [name=term original=expr typ=itype sub=isub projections=(list iwprojection)]
5730++$ iwidth-dependency [at=path source=(unit @t) definitions=(list iwidth-definition)]
5731+:: Nonrecursive request evidence is compiler-owned metadata, not a property
5732+:: of an arbitrary ask value. Reader graphs and source inputs are trusted.
5733++$ irequest-evidence
5734+ [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]
5735+:: Store requests have their own source-bound evidence. In particular, an
5736+:: API path certificate cannot make a store state member watchable, or vice versa.
5737++$ istore-request-evidence
5738+ [store-at=path source=@t state=itype action-name=term action=itype]
5739+:: A unit distinguishes a verified empty closure from a detached legacy file.
5740+:: The opaque prelude is an exact trusted input, not a recursive interface mold.
5741++$ irequest-graph
5742+ [paths=(set path) requests=(list irequest-evidence) stores=(list istore-request-evidence) bundle-input=* prelude-input=* prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5743++$ 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)]
52365744+$ ijimports (list [face=term interface=ifile])
52375745+$ icap [name=@t id=@ud at=span]
52385746+$ icaps (list icap)
@@ -5242,7 +5750,171 @@
52425750:: This core has no Ford dependencies; unrecognized payloads fail closed.
52435751+$ iexternals (list [module=term name=term result=*])
52445752+$ imark-externals (list [mark=term result=*])
5245−+$ 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)]
5753+:: Hole obligations survive discarded expressions until their owning
5754+:: definition has inferred; their source spans support unresolved reports.
5755++$ ihole [id=@ud at=span]
5756+:: Recursive-mold unfolding spends fuel in the threaded inference state.
5757+:: Retries can restart from an earlier state, so this bounds an attempt,
5758+:: not all parsing or module-checking work.
5759+:: Experimental: only closed, uniquely faced records have known axes.
5760++$ iwfield [name=term axis=@ud typ=itype]
5761++$ iwfields [order=(list iwfield) index=(map term iwfield)]
5762++$ iwstep [name=term axis=@ud]
5763++$ iwidth-result [steps=(list iwstep) sub=isub next=@ud]
5764++$ iwprojection [at=span original=expr source=itype target=itype steps=(list iwstep)]
5765+++ width-scan
5766+ |= [typ=itype sub=isub axis=@ud fuel=@ud]
5767+ ^- (unit iwfields)
5768+ =/ order=(list iwfield) ~
5769+ =/ index=(map term iwfield) *(map term iwfield)
5770+ |-
5771+ ?: =(0 fuel) ~
5772+ ?: |(?=(%var -.typ) ?=(%avar -.typ) ?=(%rvar -.typ) ?=(%nvar -.typ) ?=(%rnvar -.typ)) ~
5773+ ?: ?=(%face -.typ)
5774+ =/ entry=iwfield [name.typ axis body.typ]
5775+ ?: ?=(^ (~(get by index) name.entry)) ~
5776+ `[(flop [entry order]) (~(put by index) name.entry entry)]
5777+ ?. ?=(%cell -.typ) ~
5778+ =/ head=itype hed.typ
5779+ ?: |(?=(%var -.head) ?=(%avar -.head) ?=(%rvar -.head) ?=(%nvar -.head) ?=(%rnvar -.head)) ~
5780+ ?. ?=(%face -.head) ~
5781+ =/ entry=iwfield [name.head (mul 2 axis) body.head]
5782+ ?: ?=(^ (~(get by index) name.entry)) ~
5783+ $(typ tal.typ, axis +((mul 2 axis)), fuel (dec fuel), order [entry order], index (~(put by index) name.entry entry))
5784+++ width-in-order
5785+ |= [source=(list iwfield) target=(list iwfield)]
5786+ ^- ?
5787+ ?~ target &
5788+ ?~ source |
5789+ ?: =(name.i.source name.i.target) $(source t.source, target t.target)
5790+ $(source t.source)
5791+++ width-fit-fields
5792+ |= [source=(map term iwfield) target=(list iwfield) sub=isub next=@ud]
5793+ ^- (unit iwidth-result)
5794+ ?~ target `[~ sub next]
5795+ =/ found=(unit iwfield) (~(get by source) name.i.target)
5796+ ?~ found ~
5797+ =/ fit=ifit (itype-fit typ.u.found typ.i.target sub next)
5798+ ?. ?=(%ok -.fit) ~
5799+ =/ rest=(unit iwidth-result) $(target t.target, sub sub.fit, next next.fit)
5800+ ?~ rest ~
5801+ `[[[name.i.target axis.u.found] steps.u.rest] sub.u.rest next.u.rest]
5802+++ width-spine-exhausted
5803+ |= [t=itype fuel=@ud]
5804+ ^- ?
5805+ ?: =(0 fuel) &
5806+ ?. ?=(%cell -.t) |
5807+ ?. ?=(%face -.hed.t) |
5808+ $(t tal.t, fuel (dec fuel))
5809+++ width-known-shape
5810+ |= [actual=itype expected=itype sub=isub]
5811+ ^- (unit [source=iwfields target=iwfields])
5812+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5813+ =/ source=(unit iwfields) (width-scan actual sub 1 1.024)
5814+ =/ target=(unit iwfields) (width-scan expected sub 1 1.024)
5815+ ?~ source ~
5816+ ?~ target ~
5817+ `[u.source u.target]
5818+::
5819+++ width-shape
5820+ |= [actual=itype expected=itype sub=isub]
5821+ ^- (unit [source=iwfields target=iwfields])
5822+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5823+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5824+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5825+ ?~ source ~
5826+ ?~ target ~
5827+ ?. (gth (lent order.u.source) (lent order.u.target)) ~
5828+ `[u.source u.target]
5829+++ width-proj-shape
5830+ |= [actual=itype expected=itype sub=isub]
5831+ ^- (unit [source=iwfields target=iwfields])
5832+ ?. &(|(?=(%cell -.actual) ?=(%face -.actual)) |(?=(%cell -.expected) ?=(%face -.expected))) ~
5833+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5834+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5835+ ?~ source ~
5836+ ?~ target ~
5837+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
5838+ `[u.source u.target]
5839+::
5840+++ width-project
5841+ |= [shape=[source=iwfields target=iwfields] sub=isub next=@ud]
5842+ ^- (unit iwidth-result)
5843+ ?. (width-in-order order.source.shape order.target.shape) ~
5844+ (width-fit-fields index.source.shape order.target.shape sub next)
5845+::
5846+:: Provisional, globally budgeted gate-free proof. %no includes a
5847+:: gate-bearing witness; an uninhabited sibling could invalidate it.
5848+:: Input types must be resolved and normalized under valid substitutions,
5849+:: from trusted source-backed interfaces and reader results. Collection
5850+:: list/unit names rely on their existing identity invariant; this arm
5851+:: does not validate fabricated internal types.
5852++$ igf-segment
5853+ $% [%field name=term]
5854+ [%head ~]
5855+ [%tail ~]
5856+ [%item ~]
5857+ [%case index=@ud]
5858+ ==
5859++$ igate-free [verdict=?(%yes %no %unknown) inhabited=? left=@ud path=(unit (list igf-segment))]
5860+++ gate-free-types
5861+ |= [types=(list itype) fuel=@ud path=(list igf-segment) index=@ud]
5862+ ^- igate-free
5863+ ?~ types [%yes | fuel ~]
5864+ ?: =(0 fuel) [%unknown | 0 ~]
5865+ =/ first=igate-free (gate-free-type i.types fuel [[%case index] path])
5866+ ?: =(%no verdict.first) first
5867+ =/ rest=igate-free $(types t.types, fuel left.first, index +(index))
5868+ ?: =(%no verdict.rest) rest
5869+ =/ inhabited=? |(inhabited.first inhabited.rest)
5870+ ?: |(=(%unknown verdict.first) =(%unknown verdict.rest)) [%unknown inhabited left.rest ~]
5871+ [%yes inhabited left.rest ~]
5872+++ gate-free-type
5873+ |= [typ=itype fuel=@ud path=(list igf-segment)]
5874+ ^- igate-free
5875+ ?: =(0 fuel) [%unknown | 0 ~]
5876+ =. fuel (dec fuel)
5877+ ?- -.typ
5878+ %fn [%no & fuel `(flop path)]
5879+ %atom [%yes & fuel ~]
5880+ %any-atom [%yes & fuel ~]
5881+ %flag [%yes & fuel ~]
5882+ %const [%yes & fuel ~]
5883+ %face $(typ body.typ, path [[%field name.typ] path])
5884+ %cell
5885+ =/ head=igate-free $(typ hed.typ, path [[%head ~] path])
5886+ =/ tail=igate-free $(typ tal.typ, fuel left.head, path [[%tail ~] path])
5887+ =/ inhabited=? &(inhabited.head inhabited.tail)
5888+ ?: |(&(=(%yes verdict.head) !inhabited.head) &(=(%yes verdict.tail) !inhabited.tail)) [%yes | left.tail ~]
5889+ ?: &(=(%no verdict.head) inhabited.tail) head(left left.tail)
5890+ ?: &(=(%no verdict.tail) inhabited.head) tail
5891+ ?: |(!=(%yes verdict.head) !=(%yes verdict.tail)) [%unknown inhabited left.tail ~]
5892+ [%yes inhabited left.tail ~]
5893+ %collection
5894+ ?. |(=(%list name.typ) =(%unit name.typ)) [%unknown | fuel ~]
5895+ ?. ?=([* ~] args.typ) [%unknown | fuel ~]
5896+ =/ item=igate-free $(typ i.args.typ, path [[%item ~] path])
5897+ item(inhabited &)
5898+ %union
5899+ ?~ cases.typ [%unknown | fuel ~]
5900+ (gate-free-types cases.typ fuel path 0)
5901+ %noun [%unknown & fuel ~]
5902+ %empty [%yes | fuel ~]
5903+ %var [%unknown | fuel ~]
5904+ %fvar [%yes & fuel ~]
5905+ %avar [%yes & fuel ~]
5906+ %rvar [%yes & fuel ~]
5907+ %nvar [%yes & fuel ~]
5908+ %rnvar [%yes & fuel ~]
5909+ %tag [%unknown | fuel ~]
5910+ %recursive [%unknown | fuel ~]
5911+ %jrec [%yes & fuel ~]
5912+ %grec [%unknown | fuel ~]
5913+ ==
5914+::
5915++$ igate-prelude-evidence [iface=ifile gates=(map term def)]
5916++$ dgo [left=itype right=itype at=span context=span]
5917++$ 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)]
52465918+$ idiag [msg=tape sites=(list [at=span note=tape])]
52475919+$ iresult (each [typ=itype state=istate] idiag)
52485920+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5262,6 +5934,7 @@
52625934 |= [t=itype sub=isub]
52635935 ^- itype
52645936 =. t (itype-walk t sub)
5937+ ?: ?=(%grec -.t) t(args (turn args.t |=(c=itype (itype-normalize c sub))))
52655938 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
52665939 ?: ?=(%union -.t)
52675940 [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t (turn args.t |=(c=itype (itype-normalize c sub)))]
@@ -5278,6 +5951,8 @@
52785951:: generalize an aura from its sample, which requires constraint analysis
52795952:: beyond this fragment; leave those cases unresolved.
52805953::
5954+:: This helper only controls decimal defaulting in visible types. A noun
5955+:: may contain gates and is not proof of a gate-free value.
52815956++ itype-has-gate
52825957 |= t=itype
52835958 ^- ?
@@ -5285,17 +5960,24 @@
52855960 %fn &
52865961 %cell |($(t hed.t) $(t tal.t))
52875962 %recursive |
5963+ %jrec |
5964+ %grec &
52885965 %collection (lien args.t |=(c=itype (itype-has-gate c)))
52895966 %face $(t body.t)
52905967 %union (lien cases.t |=(c=itype (itype-has-gate c)))
52915968 %tag |
52925969 %const |
52935970 %var |
5971+ %fvar |
52945972 %avar |
5973+ %rvar |
52955974 %nvar |
5975+ %rnvar |
52965976 %atom |
52975977 %any-atom |
52985978 %flag |
5979+ %noun |
5980+ %empty |
52995981 ==
53005982::
53015983++ default-decimals
@@ -5304,26 +5986,138 @@
53045986 ?: (itype-has-gate t) t
53055987 ?- -.t
53065988 %nvar [%atom %ud]
5989+ %rnvar [%atom %ud]
5990+ %grec t(args (turn args.t |=(c=itype (default-decimals c))))
53075991 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
53085992 %face [%face name.t $(t body.t)]
53095993 %cell [%cell $(t hed.t) $(t tal.t)]
53105994 * t
53115995 ==
53125996::
5997+:: A hole is solved only by a fully determined type or a written
5998+:: in-scope type variable. Ordinary fresh variables are not evidence.
5999+:: Compare representatives after substitution, since unification can
6000+:: orient a written capital toward the hole rather than the reverse.
6001+++ hole-variable-id
6002+ |= t=itype
6003+ ^- (unit @ud)
6004+ ?- -.t
6005+ %var `id.t
6006+ %fvar `id.t
6007+ %avar `id.t
6008+ %rvar `id.t
6009+ %nvar `id.t
6010+ %rnvar `id.t
6011+ %tag `id.t
6012+ * ~
6013+ ==
6014+++ hole-same-variable
6015+ |= [a=itype b=itype]
6016+ ^- ?
6017+ =/ x=(unit @ud) (hole-variable-id a)
6018+ ?~ x |
6019+ =/ y=(unit @ud) (hole-variable-id b)
6020+ ?~ y |
6021+ =(u.x u.y)
6022+++ hole-known
6023+ |= [t=itype state=istate]
6024+ ^- ?
6025+ =. t (itype-walk t sub.state)
6026+ ?- -.t
6027+ ?(%var %fvar %avar %rvar %nvar %rnvar)
6028+ ?: (lien caps.state |=(c=icap (hole-same-variable t (itype-walk [%var id.c] sub.state)))) &
6029+ (lien params.state |=(p=[name=@t typ=itype] (hole-same-variable t (itype-walk typ.p sub.state))))
6030+ %tag |
6031+ %any-atom &
6032+ %union &((levy cases.t |=(c=itype (hole-known c state))) (levy args.t |=(c=itype (hole-known c state))))
6033+ %grec (levy args.t |=(c=itype (hole-known c state)))
6034+ %collection (levy args.t |=(c=itype (hole-known c state)))
6035+ %face $(t body.t)
6036+ %fn &($(t sample.t) $(t product.t))
6037+ %cell &($(t hed.t) $(t tal.t))
6038+ * &
6039+ ==
6040+++ promote-restricted-numbers
6041+ |= [state=istate env=ienv]
6042+ ^- istate
6043+ :: With no written capitals, there is nothing to promote.
6044+ ?~ caps.state state
6045+ =/ ids=(list @ud) (turn caps.state |=(c=icap id.c))
6046+ =/ free=(list @ud) (free-env-vars env sub.state)
6047+ |-
6048+ ?~ ids state
6049+ =/ t=itype (itype-walk [%var i.ids] sub.state)
6050+ ?: &(?=(%rnvar -.t) !(lien free |=(n=@ud =(n +.t))))
6051+ $(ids t.ids, state state(sub [[+.t [%rvar +.t]] sub.state]))
6052+ $(ids t.ids)
6053+::
6054+++ default-hole-numbers
6055+ |= [all=(list ihole) prior=(list ihole) state=istate env=ienv permit=?]
6056+ ^- istate
6057+ :: Do not default a named capital or a variable captured from env.
6058+ ?. permit state
6059+ ?: =(all prior) state
6060+ ?~ all state
6061+ =/ t=itype (itype-walk [%var id.i.all] sub.state)
6062+ =/ free=(list @ud) (free-env-vars env sub.state)
6063+ =? state &(?=(?(%nvar %rnvar) -.t) !(hole-known t state) !(lien free |=(id=@ud =(id id.t))))
6064+ state(sub [[id.t [%atom %ud]] sub.state])
6065+ $(all t.all)
6066+::
6067+:: Only obligations created inside this definition belong to it.
6068+++ holes-created
6069+ |= [all=(list ihole) prior=(list ihole)]
6070+ ^- (list ihole)
6071+ ?: =(all prior) ~
6072+ ?~ all ~
6073+ [i.all $(all t.all)]
6074+++ hole-uncertain
6075+ |= [t=itype state=istate]
6076+ ^- ?
6077+ =. t (itype-walk t sub.state)
6078+ ?- -.t
6079+ ?(%tag %nvar %rnvar %fvar %avar %rvar) !(hole-known t state)
6080+ %union |((lien cases.t |=(c=itype (hole-uncertain c state))) (lien args.t |=(c=itype (hole-uncertain c state))))
6081+ %grec (lien args.t |=(c=itype (hole-uncertain c state)))
6082+ %collection (lien args.t |=(c=itype (hole-uncertain c state)))
6083+ %face $(t body.t)
6084+ %fn |($(t sample.t) $(t product.t))
6085+ %cell |($(t hed.t) $(t tal.t))
6086+ * |
6087+ ==
6088+::
6089+++ unresolved-hole
6090+ |= [all=(list ihole) prior=(list ihole) state=istate]
6091+ ^- (unit idiag)
6092+ =/ work=(list ihole) (flop (holes-created all prior))
6093+ |-
6094+ ?~ work ~
6095+ ?: (hole-known [%var id.i.work] state) $(work t.work)
6096+ ?: (hole-uncertain [%var id.i.work] state)
6097+ `["type hole needs unsupported inference" ~[[at.i.work "type hole"]]]
6098+ `["type hole needs a determined type" ~[[at.i.work "unresolved type hole"]]]
6099+::
53136100++ itype-vars
53146101 |= t=itype
53156102 ^- (list @ud)
53166103 ?- -.t
53176104 %var ~[id.t]
6105+ %fvar ~[id.t]
53186106 %avar ~[id.t]
6107+ %rvar ~[id.t]
53196108 %nvar ~[id.t]
6109+ %rnvar ~[id.t]
53206110 %atom ~
53216111 %any-atom ~
53226112 %flag ~
6113+ %noun ~
6114+ %empty ~
53236115 %tag ~
53246116 %const ~
53256117 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
53266118 %recursive ~
6119+ %jrec ~
6120+ %grec (zing (turn args.t |=(c=itype (itype-vars c))))
53276121 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
53286122 %face $(t body.t)
53296123 %fn (weld $(t sample.t) $(t product.t))
@@ -5347,21 +6141,37 @@
53476141 =/ found=(unit itype) (itype-lookup id.t ren)
53486142 ?~ found t
53496143 u.found
6144+ %fvar
6145+ =/ found=(unit itype) (itype-lookup id.t ren)
6146+ ?~ found t
6147+ u.found
53506148 %avar
53516149 =/ found=(unit itype) (itype-lookup id.t ren)
53526150 ?~ found t
53536151 u.found
6152+ %rvar
6153+ =/ found=(unit itype) (itype-lookup id.t ren)
6154+ ?~ found t
6155+ u.found
53546156 %nvar
53556157 =/ found=(unit itype) (itype-lookup id.t ren)
53566158 ?~ found t
53576159 u.found
6160+ %rnvar
6161+ =/ found=(unit itype) (itype-lookup id.t ren)
6162+ ?~ found t
6163+ u.found
53586164 %atom t
53596165 %any-atom t
53606166 %flag t
6167+ %noun t
6168+ %empty t
53616169 %tag t
53626170 %const t
53636171 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
53646172 %recursive t
6173+ %jrec t
6174+ %grec t(args (turn args.t |=(c=itype (itype-rename c ren))))
53656175 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
53666176 %face [%face name.t $(t body.t)]
53676177 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5376,24 +6186,79 @@
53766186 ^- ?
53776187 ?- -.t
53786188 %var |
6189+ %fvar |
53796190 %avar =(n id.t)
6191+ %rvar =(n id.t)
53806192 %nvar =(n id.t)
6193+ %rnvar =(n id.t)
53816194 %atom |
53826195 %any-atom |
53836196 %flag |
6197+ %noun |
6198+ %empty |
53846199 %tag |
53856200 %const |
53866201 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
53876202 %recursive |
6203+ %jrec |
6204+ %grec (lien args.t |=(c=itype (itype-var-is-atom n c)))
53886205 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
53896206 %face $(t body.t)
53906207 %fn |($(t sample.t) $(t product.t))
53916208 %cell |($(t hed.t) $(t tal.t))
53926209 ==
6210+++ itype-var-is-restricted
6211+ |= [n=@ud t=itype]
6212+ ^- ?
6213+ ?- -.t
6214+ %var |
6215+ %fvar |
6216+ %avar |
6217+ %rvar =(n id.t)
6218+ %nvar |
6219+ %rnvar |
6220+ %atom |
6221+ %any-atom |
6222+ %flag |
6223+ %noun |
6224+ %empty |
6225+ %tag |
6226+ %const |
6227+ %union |((lien cases.t |=(c=itype (itype-var-is-restricted n c))) (lien args.t |=(c=itype (itype-var-is-restricted n c))))
6228+ %recursive |
6229+ %jrec |
6230+ %grec (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6231+ %collection (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6232+ %face $(t body.t)
6233+ %fn |($(t sample.t) $(t product.t))
6234+ %cell |($(t hed.t) $(t tal.t))
6235+ ==
53936236::
53946237:: Canonical numbering makes printed variables independent of the order
53956238:: the unifier happened to allocate intermediates.
53966239::
6240+++ itype-var-is-gate-free-fuel
6241+ |= [n=@ud t=itype fuel=@ud]
6242+ ^- ?
6243+ ?: =(0 fuel) &
6244+ =. fuel (dec fuel)
6245+ ?- -.t
6246+ %var |
6247+ %fvar =(n id.t)
6248+ %union |((lien cases.t |=(c=itype (itype-var-is-gate-free-fuel n c fuel))) (lien args.t |=(c=itype (itype-var-is-gate-free-fuel n c fuel))))
6249+ %grec (lien args.t |=(c=itype (itype-var-is-gate-free-fuel n c fuel)))
6250+ %collection (lien args.t |=(c=itype (itype-var-is-gate-free-fuel n c fuel)))
6251+ %face $(t body.t, fuel fuel)
6252+ %fn |($(t sample.t, fuel fuel) $(t product.t, fuel fuel))
6253+ %cell |($(t hed.t, fuel fuel) $(t tal.t, fuel fuel))
6254+ * |
6255+ ==
6256+::
6257+++ itype-var-is-gate-free
6258+ |= [n=@ud t=itype]
6259+ ^- ?
6260+ (itype-var-is-gate-free-fuel n t 256)
6261+::
53976262++ canonical-itype
53986263 |= [t=itype vars=(list @ud)]
53996264 ^- itype
@@ -5401,7 +6266,7 @@
54016266 =/ n=@ud 0
54026267 |-
54036268 ?~ vars (itype-rename t ren)
5404− =/ replacement=itype ?:((itype-var-is-atom i.vars t) [%avar n] [%var n])
6269+ =/ replacement=itype ?:((itype-var-is-restricted i.vars t) [%rvar n] ?:((itype-var-is-atom i.vars t) [%avar n] ?:((itype-var-is-gate-free i.vars t) [%fvar n] [%var n])))
54056270 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
54066271::
54076272++ instantiate-scheme
@@ -5412,11 +6277,11 @@
54126277 |-
54136278 ?~ vars [(itype-rename typ.scheme ren) state]
54146279 =/ replacement=itype
5415− ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state])
6280+ ?:((itype-var-is-restricted i.vars typ.scheme) [%rvar next.state] ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] ?:((itype-var-is-gate-free i.vars typ.scheme) [%fvar next.state] [%var next.state])))
54166281 :: A generalized atom variable is a valid origin for re-generalizing
54176282 :: an alias, just as a sample binder is.
54186283 =/ st=istate state(next +(next.state))
5419− =? binders.st ?=(%avar -.replacement) [next.state binders.state]
6284+ =? binders.st |(?=(%fvar -.replacement) ?=(%avar -.replacement) ?=(%rvar -.replacement)) [next.state binders.state]
54206285 $(vars t.vars, ren [[i.vars replacement] ren], state st)
54216286::
54226287++ icap-lookup
@@ -5487,6 +6352,11 @@
54876352 ?. ?=([%ref @ @] node) ~
54886353 ?. &(=(module +<.node) =(name +>.node)) ~
54896354 `[[%unknown ~] &]
6355+ %apply
6356+ ?. ?=([%apply %list [* ~]] node) ~
6357+ =/ item $(node -.+>.node)
6358+ ?~ item ~
6359+ `[[%or ~[[%atom `0] [%cell pat.u.item [%unknown ~]]]] has.u.item]
54906360 %face
54916361 ?. ?=([%face @ *] node) ~
54926362 ?. (jibb-face-name +<.node) ~
@@ -5541,6 +6411,10 @@
55416411 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
55426412 %fork (imported-faces-valid-list +.node)
55436413 %apply ?:(?=([%apply @ *] node) (imported-faces-valid-list +>.node) |)
6414+ %named
6415+ ?. ?=([%named @ @ *] node) |
6416+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6417+ (imported-faces-valid body.n)
55446418 ==
55456419::
55466420++ imported-faces-valid-list
@@ -5572,7 +6446,19 @@
55726446 ^- (unit itype)
55736447 ?@ node ~
55746448 ?+ -.node ~
6449+ %noun ?:(=(node [%noun ~]) `[%noun ~] ~)
55756450 %atom
6451+ :: A Hoon loobean singleton is one of the two Jibb loobeans.
6452+ ?: ?=([%atom %f [~ @]] node)
6453+ =/ value=@ +>+.node
6454+ ?. |(=(value 0) =(value 1)) ~
6455+ =/ printed=@t ?:(=(value 0) '%.y' '%.n')
6456+ `[%const [%loobean %f value printed]]
6457+ :: Hoon's null singleton is the same noun as Jibb's `~` mold.
6458+ :: Other non-term singleton atoms remain unsupported here.
6459+ ?: ?=([%atom %n [~ @]] node)
6460+ ?. =(0 +>+.node) ~
6461+ `[%const [%null %n 0 '~']]
55766462 ?: ?=([%atom %tas [~ @]] node)
55776463 =/ value=@ +>+.node
55786464 ?. |(=(value 0) (jibb-face-name value)) ~
@@ -5582,6 +6468,15 @@
55826468 =/ aura=@ta (@ta +<.node)
55836469 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
55846470 `[%atom aura]
6471+ %named
6472+ ?. ?=([%named @ @ *] node) ~
6473+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6474+ ?. &((jibb-face-name module.n) (jibb-face-name name.n)) ~
6475+ ?. ?=([%fork *] body.n) ~
6476+ =/ proof=(unit irec-pattern) (rec-pattern body.n (@tas module.n) (@tas name.n))
6477+ ?~ proof ~
6478+ ?. has.u.proof ~
6479+ `[%recursive (@tas module.n) (@tas name.n) `(crip "{(trip name.n)}.{(trip module.n)}")]
55856480 %apply
55866481 ?. ?=([%apply @ *] node) ~
55876482 =/ name=term (@tas +<.node)
@@ -5593,12 +6488,19 @@
55936488 =/ args=(unit (list itype)) (import-to-itypes +>.node)
55946489 ?~ args ~
55956490 ?. =(arity (lent u.args)) ~
5596− `[%collection name u.args]
6491+ =/ keyed=(unit [types=(list itype) sub=isub]) (itype-collection-keys name u.args ~)
6492+ ?~ keyed ~
6493+ `[%collection name types.u.keyed]
55976494 %fork
5598− =/ cases=(unit (list itype)) (import-to-itypes +.node)
6495+ :: Hoon's ordinary ? mold is the fork of its two %f singletons.
6496+ =/ raw=* +.node
6497+ ?: |(=(raw ~[[%atom %f `0] [%atom %f `1]]) =(raw ~[[%atom %f `1] [%atom %f `0]]))
6498+ `[%flag ~]
6499+ =/ cases=(unit (list itype)) (import-to-itypes raw)
55996500 ?~ cases ~
56006501 ?~ u.cases ~
56016502 ?~ t.u.cases ~
6503+ ?: (import-has-loobean-singleton u.cases) ~
56026504 ?. (import-cases-disjoint u.cases) ~
56036505 `[%union u.cases ~ ~ ~]
56046506 %face
@@ -5617,6 +6519,20 @@
56176519 `[%cell u.left u.right]
56186520 ==
56196521::
6522+++ import-direct-loobean
6523+ |= t=itype
6524+ ^- ?
6525+ ?: ?=(%face -.t) $(t body.t)
6526+ ?: ?=(%union -.t) (import-has-loobean-singleton cases.t)
6527+ ?=([%const [%loobean *]] t)
6528+::
6529+++ import-has-loobean-singleton
6530+ |= cases=(list itype)
6531+ ^- ?
6532+ ?~ cases |
6533+ ?: (import-direct-loobean i.cases) &
6534+ $(cases t.cases)
6535+::
56206536++ import-to-itypes
56216537 |= nodes=*
56226538 ^- (unit (list itype))
@@ -5631,7 +6547,10 @@
56316547 |= typ=itype
56326548 ^- upat
56336549 ?- -.typ
6550+ %noun [%all ~]
6551+ %empty [%empty ~]
56346552 %atom [%atom ~]
6553+ %flag [%or ~[[%atom `0] [%atom `1]]]
56356554 %const [%atom `val.literal.typ]
56366555 %face $(typ body.typ)
56376556 %cell [%cell $(typ hed.typ) $(typ tal.typ)]
@@ -5726,25 +6645,85 @@
57266645 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
57276646 $(molds t.molds)
57286647::
5729−:: Only names exported by this directly imported module are visible through
5730−:: its face. Other origins retain identity but print as unnamed unions.
6648+:: A prelude union alias is a display name, not a new union identity. An
6649+:: identity-generic alias can carry the origin's arguments only when the
6650+:: origin, arity and ordered parameters match. Swapped, repeated, fixed
6651+:: or phantom parameters cannot be printed that way and remain unsupported
6652+:: when their only available name is private. A nongeneric alias of a
6653+:: generic instantiation cannot be printed with the origin's arguments.
6654+++ identity-union-parameters
6655+ |= [vars=(list @ud) args=(list itype)]
6656+ ^- ?
6657+ ?~ vars ?=(~ args)
6658+ ?~ args |
6659+ ?. =([%var i.vars] i.args) |
6660+ $(vars t.vars, args t.args)
6661+++ prelude-union-alias
6662+ |= [origin=[at=path name=term] args=(list itype) molds=imold-types]
6663+ ^- (unit term)
6664+ ?~ molds ~
6665+ =/ template=ischeme template.i.molds
6666+ ?. ?=(%union -.typ.template) $(molds t.molds)
6667+ ?. =(`origin origin.typ.template) $(molds t.molds)
6668+ ?~ vars.template
6669+ ?^ args $(molds t.molds)
6670+ ?:(=(args args.typ.template) `name.i.molds $(molds t.molds))
6671+ ?: &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args)))
6672+ `name.i.molds
6673+ $(molds t.molds)
6674+::
6675+:: Names exported by the directly imported module are visible through its
6676+:: face; a matching prelude alias is also visible without a qualifier.
6677+::
6678+++ jrec-alias
6679+ |= [origin=path name=term molds=imold-types]
6680+ ^- (unit term)
6681+ ?~ molds ~
6682+ =/ template=ischeme template.i.molds
6683+ ?: &(?=(~ vars.template) ?=(%jrec -.typ.template) =(at.typ.template origin) =(name.typ.template name)) `name.i.molds
6684+ $(molds t.molds)
6685+::
6686+++ grec-visible-alias
6687+ |= [origin=path name=term proof=shape args=(list itype) molds=imold-types]
6688+ ^- (unit term)
6689+ ?~ molds ~
6690+ =/ template=ischeme template.i.molds
6691+ ?. ?=(%grec -.typ.template) $(molds t.molds)
6692+ ?. &(=(at.typ.template origin) =(name.typ.template name) =(proof.typ.template proof)) $(molds t.molds)
6693+ ?. &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args))) $(molds t.molds)
6694+ `name.i.molds
57316695::
57326696++ itype-in-import
5733− |= [t=itype iface=ifile face=term]
6697+ |= [t=itype iface=ifile face=term prelude=(unit ifile)]
57346698 ^- itype
57356699 ?- -.t
57366700 %union
57376701 =/ label=(unit @t)
57386702 ?~ origin.t ~
57396703 ?: =(at.u.origin.t /lib/jibb/prelude/jibb) `name.u.origin.t
6704+ =/ public=(unit term)
6705+ ?~ prelude ~
6706+ (prelude-union-alias u.origin.t args.t molds.u.prelude)
6707+ ?^ public `u.public
57406708 =/ alias=(unit term) ~
57416709 =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
57426710 =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
57436711 ?~ alias ~
57446712 `(crip "{(trip u.alias)}.{(trip face)}")
5745− [%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)))]
6713+ [%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)))]
57466714 %recursive [%recursive module.t name.t ~]
5747− %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face)))]
6715+ %grec
6716+ =/ public=(unit term) ?~(prelude ~ (grec-visible-alias at.t name.t proof.t args.t molds.u.prelude))
6717+ =/ alias=(unit term) ?~(public (grec-visible-alias at.t name.t proof.t args.t molds.iface) public)
6718+ =/ label=(unit @t) ?~(alias ~ ?~(public `(crip "{(trip u.alias)}.{(trip face)}") `u.alias))
6719+ t(label label, args (turn args.t |=(c=itype (itype-in-import c iface face prelude))))
6720+ %jrec
6721+ =/ public=(unit term) ?~(prelude ~ (jrec-alias at.t name.t molds.u.prelude))
6722+ ?^ public t(label `u.public)
6723+ =/ alias=(unit term) (jrec-alias at.t name.t molds.iface)
6724+ ?~ alias t(label ~)
6725+ t(label `(crip "{(trip u.alias)}.{(trip face)}"))
6726+ %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
57486727 %face [%face name.t $(t body.t)]
57496728 %fn [%fn $(t sample.t) $(t product.t)]
57506729 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5790,15 +6769,27 @@
57906769 ?~ rest ~
57916770 `[[i.names i.args] u.rest]
57926771::
5793−++ template-apply
5794− |= [template=ischeme args=(list itype)]
5795− ^- (unit itype)
6772+++ template-apply-sub
6773+ |= [template=ischeme args=(list itype) sub=isub]
6774+ ^- (unit [typ=itype sub=isub])
57966775 =/ vars=(list @ud) vars.template
57976776 =/ ren=isub ~
57986777 |-
5799− ?~ vars ?~(args `(itype-rename typ.template ren) ~)
6778+ ?~ vars ?~(args `[(itype-rename typ.template ren) sub] ~)
58006779 ?~ args ~
5801− $(vars t.vars, args t.args, ren [[i.vars i.args] ren])
6780+ =/ replacement=(unit igf-form)
6781+ ?: (itype-var-is-gate-free i.vars typ.template)
6782+ (itype-gate-free-form i.args sub 256)
6783+ `[i.args sub 256]
6784+ ?~ replacement ~
6785+ $(vars t.vars, args t.args, ren [[i.vars typ.u.replacement] ren], sub sub.u.replacement)
6786+::
6787+++ template-apply
6788+ |= [template=ischeme args=(list itype)]
6789+ ^- (unit itype)
6790+ =/ applied=(unit [typ=itype sub=isub]) (template-apply-sub template args ~)
6791+ ?~ applied ~
6792+ `typ.u.applied
58026793::
58036794++ infer-shape-args
58046795 |= [args=(list shape) state=istate]
@@ -5817,9 +6808,66 @@
58176808 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
58186809 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
58196810::
6811+:: Recognize a unique top-level source mold with exactly a null case and a
6812+:: faced atom-headed cell whose faced tail names that same mold. Its Jibb
6813+:: path and name provide nominal identity. Other recursive shapes fail closed;
6814+:: construction and matching expose the proven shape one layer at a time.
6815+++ simple-source-recursive
6816+ |= [name=term sh=shape state=istate]
6817+ ^- (unit itype)
6818+ ?. (lien top-molds.state |=(n=term =(n name))) ~
6819+ =/ original=(unit shape) (find-simple-mold name molds.state)
6820+ ?~ original ~
6821+ ?. =(u.original sh) ~
6822+ ?. ?=(%union -.sh) ~
6823+ =/ cs=(list shape) cases.sh
6824+ ?~ cs ~
6825+ ?~ t.cs ~
6826+ ?^ t.t.cs ~
6827+ ?. ?=(%const -.i.cs) ~
6828+ ?. =(%null form.lit.i.cs) ~
6829+ ?. ?=(%cell -.i.t.cs) ~
6830+ =/ fs=(list field) fields.i.t.cs
6831+ ?~ fs ~
6832+ ?~ t.fs ~
6833+ ?^ t.t.fs ~
6834+ ?. ?=(%face -.i.fs) ~
6835+ ?. ?=(%aura -.shape.i.fs) ~
6836+ ?. !=(0 aura.shape.i.fs) ~
6837+ ?. ?=(%face -.i.t.fs) ~
6838+ ?. !=(name.i.fs name.i.t.fs) ~
6839+ =/ tail=shape shape.i.t.fs
6840+ ?. ?=(%ref -.tail) ~
6841+ ?. =(names.tail ~[name]) ~
6842+ `[%jrec at.state name `name name.i.fs aura.shape.i.fs name.i.t.fs]
6843+::
6844+++ simple-source-generic-recursive
6845+ |= [name=term sh=shape args=(list itype) state=istate]
6846+ ^- (unit itype)
6847+ ?. ?=(%generic -.sh) ~
6848+ ?. ?=([@ ~] vars.sh) ~
6849+ ?. ?=([* ~] args) ~
6850+ ?~ grec-index.state ~
6851+ ?. =(at.u.grec-index.state at.state) ~
6852+ ?~ prelude.state ~
6853+ ?. =(prelude.u.grec-index.state u.prelude.state) ~
6854+ =/ proof=(unit shape) (~(get by shapes.u.grec-index.state) name)
6855+ ?~ proof ~
6856+ ?. =(u.proof sh) ~
6857+ `[%grec at.state name `name sh args]
6858+::
6859+
58206860++ infer-mold-template
58216861 |= [sh=shape state=istate]
58226862 ^- (unit [template=ischeme state=istate])
6863+ =/ generic=(unit itype)
6864+ ?. ?=([@ ~] active.state) ~
6865+ (simple-source-generic-recursive i.active.state sh ~[[%var next.state]] state)
6866+ ?^ generic `[[u.generic ~[next.state]] state(next +(next.state))]
6867+ =/ direct=(unit itype)
6868+ ?. ?=([@ ~] active.state) ~
6869+ (simple-source-recursive i.active.state sh state)
6870+ ?^ direct `[[u.direct ~] state]
58236871 ?: ?=(%generic -.sh)
58246872 ?~ vars.sh ~
58256873 ?. (distinct-params vars.sh) ~
@@ -5827,17 +6875,19 @@
58276875 =/ out=(unit [typ=itype state=istate])
58286876 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
58296877 ?~ out ~
6878+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58306879 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
58316880 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
58326881 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
58336882 =/ used=(list @ud) (itype-vars typ.u.out)
58346883 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
5835− `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state)]
6884+ `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
58366885 =/ out=(unit [typ=itype state=istate])
58376886 (infer-simple-shape sh state(params ~, in-mold &))
58386887 ?~ out ~
6888+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58396889 ?: ?=(^ (itype-vars typ.u.out)) ~
5840− `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state)]
6890+ `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
58416891::
58426892:: A direct imported reference may carry definite reader evidence. Only
58436893:: uniquely supplied, declared inputs are used; unsupported data stay generic.
@@ -5871,33 +6921,93 @@
58716921 ?~ found ~
58726922 ?^ t.found ~
58736923 result.i.found
5874− ?. ?=([%invalid ?(%aura %core) @] raw) ~
6924+ ?. ?=([%invalid ?(%aura %core %overlap) @] raw) ~
58756925 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
58766926::
5877−++ direct-sample-invalid
5878− |= [s=sample state=istate]
6927+:: Replay only the shape branches whose evaluation order we can prove.
6928+:: Successful prefixes must be checked before descending to a failure.
6929+++ nested-import-invalid
6930+ |= [sh=shape state=istate]
6931+ ^- (unit idiag)
6932+ ?: ?=(^ (infer-simple-shape sh state)) ~
6933+ ?- -.sh
6934+ %ref
6935+ =/ direct=(unit idiag) (direct-import-invalid sh state)
6936+ ?^ direct direct
6937+ ?~ names.sh ~
6938+ ?^ t.names.sh ~
6939+ =/ n=term i.names.sh
6940+ ?: (lien marks.state |=(x=term =(x n))) ~
6941+ ?: (lien active.state |=(x=term =(x n))) ~
6942+ =/ found=(unit shape) (find-simple-mold n molds.state)
6943+ ?~ found ~
6944+ $(sh u.found, state state(active [n active.state], in-mold &, params ~))
6945+ %fn
6946+ =/ first=(unit [typ=itype state=istate]) (infer-simple-shape sample.sh state)
6947+ ?~ first $(sh sample.sh)
6948+ $(sh product.sh, state state.u.first)
6949+ %cell (nested-field-invalid fields.sh state)
6950+ * ~
6951+ ==
6952+::
6953+++ nested-field-invalid
6954+ |= [fields=(list field) state=istate]
6955+ ^- (unit idiag)
6956+ ?~ fields ~
6957+ =/ sh=shape
6958+ ?- -.i.fields
6959+ %bare shape.i.fields
6960+ %face shape.i.fields
6961+ %pun [%ref at.i.fields ~[name.i.fields]]
6962+ ==
6963+ =/ out=(unit [typ=itype state=istate]) (infer-simple-shape sh state)
6964+ ?~ out (nested-import-invalid sh state)
6965+ $(fields t.fields, state state.u.out)
6966+::
6967+++ sample-import-invalid
6968+ |= [s=sample env=ienv state=istate]
58796969 ^- (unit idiag)
6970+ =/ result=isample-result (infer-sample s env state)
6971+ ?: ?=(%& -.result) ~
6972+ ?. =(p.result "sample mold is not supported by partial inference") ~
58806973 ?- s
5881− [%face *] (direct-import-invalid shape.s state)
5882− [%bare *] (direct-import-invalid shape.s state)
5883− [%pun *] (direct-import-invalid [%ref at.s ~[name.s]] state)
6974+ [%face *] (nested-import-invalid shape.s state)
6975+ [%bare *] (nested-import-invalid shape.s state)
6976+ [%pun *] (nested-import-invalid [%ref at.s ~[name.s]] state)
6977+ [%cell *] (nested-samples-invalid items.s env state)
58846978 * ~
58856979 ==
58866980::
6981+++ nested-samples-invalid
6982+ |= [items=(list sample) env=ienv state=istate]
6983+ ^- (unit idiag)
6984+ ?~ items ~
6985+ =/ head=isample-result (infer-sample i.items env state)
6986+ ?: ?=(%| -.head) (sample-import-invalid i.items env state)
6987+ $(items t.items, env env.p.head, state state.p.head)
6988+::
58876989++ infer-simple-shape
58886990 |= [sh=shape state=istate]
58896991 ^- (unit [typ=itype state=istate])
58906992 ?- -.sh
6993+ %hole `[[%var next.state] state(next +(next.state), holes [[next.state at.sh] holes.state])]
58916994 %aura
58926995 ?: =(0 aura.sh) `[[%any-atom ~] state]
58936996 `[[%atom aura.sh] state]
58946997 %flag `[[%flag ~] state]
6998+ %noun `[[%noun ~] state]
6999+ %void `[[%empty ~] state]
58957000 %const
5896− ?. |(=(%term form.lit.sh) =(%null form.lit.sh)) ~
7001+ ?. |(=(%term form.lit.sh) =(%null form.lit.sh) =(%loobean form.lit.sh)) ~
7002+ ?: &(=(%loobean form.lit.sh) !|(=(0 val.lit.sh) =(1 val.lit.sh))) ~
58977003 `[[%const lit.sh] state]
58987004 %union
58997005 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
5900− ?. (levy pairs |=(p=upair =(%disjoint relation.p))) ~
7006+ ?: (lien pairs |=(p=upair =(%overlap relation.p))) ~
7007+ =/ source-proof=?
7008+ ?: (levy pairs |=(p=upair =(%disjoint relation.p))) &
7009+ &((union-source-state-safe state 256) (union-source-distinct-tags cases.sh molds.state 256))
7010+ ?. source-proof ~
59017011 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
59027012 ?~ cs ~
59037013 `[[%union types.u.cs ~ ~ ~] state.u.cs]
@@ -5918,7 +7028,7 @@
59187028 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
59197029 ?~ found ~
59207030 ?^ vars.u.found ~
5921− `[(itype-in-import typ.u.found u.iface i.t.names.sh) state]
7031+ `[(itype-in-import typ.u.found u.iface i.t.names.sh prelude.state) state]
59227032 =/ found=(unit itype)
59237033 (find-imported-mold i.t.names.sh n externals.state surs.state)
59247034 ?~ found ~
@@ -5937,15 +7047,29 @@
59377047 ?~ prelude-entry ~
59387048 ?^ vars.u.prelude-entry ~
59397049 `[typ.u.prelude-entry state]
7050+ =/ direct=(unit itype) (simple-source-recursive n u.found state)
7051+ ?^ direct `[u.direct state]
59407052 =/ out=(unit [typ=itype state=istate])
59417053 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
59427054 ?~ out ~
5943− `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state)]
7055+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
7056+ `[(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)]
59447057 %apply
59457058 ?~ ref.sh ~
59467059 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
59477060 ?~ args ~
59487061 =/ n=term i.ref.sh
7062+ =/ keyed=(unit [types=(list itype) sub=isub])
7063+ ?: ?=(^ (find-simple-mold n molds.state.u.args))
7064+ `[types.u.args sub.state.u.args]
7065+ ?~ prelude.state.u.args
7066+ (itype-collection-keys n types.u.args sub.state.u.args)
7067+ ?: ?=(^ (find-jibb-mold n u.prelude.state.u.args))
7068+ `[types.u.args sub.state.u.args]
7069+ (itype-collection-keys n types.u.args sub.state.u.args)
7070+ ?~ keyed ~
7071+ =. types.u.args types.u.keyed
7072+ =. sub.state.u.args sub.u.keyed
59497073 ?^ t.ref.sh
59507074 ?^ t.t.ref.sh ~
59517075 =/ iface=(unit ifile) (find-jibb-interface i.t.ref.sh jimports.state.u.args)
@@ -5953,9 +7077,10 @@
59537077 =/ template=(unit ischeme) (find-jibb-mold n u.iface)
59547078 ?~ template ~
59557079 ?~ vars.u.template ~
5956− =/ applied=(unit itype) (template-apply u.template types.u.args)
7080+ =/ applied=(unit [typ=itype sub=isub]) (template-apply-sub u.template types.u.args sub.state.u.args)
59577081 ?~ applied ~
5958− `[(itype-in-import u.applied u.iface i.t.ref.sh) state.u.args]
7082+ =. sub.state.u.args sub.u.applied
7083+ `[(itype-in-import typ.u.applied u.iface i.t.ref.sh prelude.state.u.args) state.u.args]
59597084 ?: (lien active.state.u.args |=(x=term =(x n))) ~
59607085 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
59617086 ?~ found
@@ -5964,21 +7089,25 @@
59647089 =/ prelude-entry=(unit ischeme) (find-jibb-mold n u.prelude.state.u.args)
59657090 ?~ prelude-entry ~
59667091 ?~ vars.u.prelude-entry ~
5967− =/ applied=(unit itype) (template-apply u.prelude-entry types.u.args)
7092+ =/ applied=(unit [typ=itype sub=isub]) (template-apply-sub u.prelude-entry types.u.args sub.state.u.args)
59687093 ?~ applied ~
5969− `[u.applied state.u.args]
7094+ =. sub.state.u.args sub.u.applied
7095+ `[typ.u.applied state.u.args]
59707096 ?. ?=(%generic -.u.found) ~
7097+ =/ grec=(unit itype) (simple-source-generic-recursive n u.found types.u.args state.u.args)
7098+ ?^ grec `[u.grec state.u.args]
59717099 ?. (distinct-params vars.u.found) ~
59727100 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
59737101 ?~ params ~
59747102 =/ out=(unit [typ=itype state=istate])
59757103 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
59767104 ?~ out ~
7105+ ?^ (unresolved-hole holes.state.u.out holes.state.u.args state.u.out) ~
59777106 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
59787107 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
59797108 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
59807109 (label-direct-union typ.u.out(args types.u.args) u.found n state.u.args)
5981− `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args)]
7110+ `[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)]
59827111 %tvar
59837112 =/ param=(unit itype) (iparam-lookup name.sh params.state)
59847113 ?^ param `[u.param state]
@@ -6018,12 +7147,12 @@
60187147 ^- isample-result
60197148 ?- -.s
60207149 %bind
6021− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
7150+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
60227151 [%| "sample shadows a name"]
60237152 =/ t=itype [%var next.state]
60247153 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
60257154 %face
6026− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
7155+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
60277156 [%| "sample shadows a name"]
60287157 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
60297158 ?~ t [%| "sample mold is not supported by partial inference"]
@@ -6061,8 +7190,8 @@
60617190 [%& [%cell ht typ.p.tail] env.p.tail state.p.tail]
60627191::
60637192:: Local definitions generalize only variables outside their enclosing
6064−:: environment and explicit-capital scope. Single self-recursive gates
6065−:: use a monomorphic placeholder; mutually recursive groups stay unsupported.
7193+:: environment and explicit-capital scope. Recursive gate groups use
7194+:: monomorphic placeholders while their bodies are checked.
60667195::
60677196+$ ilocal-result (each [env=ienv state=istate] idiag)
60687197++ free-env-vars
@@ -6091,6 +7220,7 @@
60917220 |-
60927221 ?~ ds &
60937222 ?: ?=(%mold -.i.ds) $(ds t.ds)
7223+ ?: =(name.i.ds %proj) |
60947224 ?. (unique-value-name name.i.ds names) |
60957225 ?: ?=(^ (ienv-lookup name.i.ds env)) |
60967226 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
@@ -6114,6 +7244,7 @@
61147244 |-
61157245 ?~ locals &
61167246 =/ n=term name.i.locals
7247+ ?: =(n %proj) |
61177248 ?. (unique-value-name n names) |
61187249 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
61197250 ?: (lien marks.state |=(m=term =(n m))) |
@@ -6278,7 +7409,13 @@
62787409 |-
62797410 ?~ ds
62807411 ?~ remaining [%& env state]
6281− ?. progressed [%| ["local definitions need unsupported inference" ~]]
7412+ ?. progressed
7413+ =/ pending=(list def) (flop remaining)
7414+ =/ groups=icomponents (graph-components pending (global-value-names pending))
7415+ =/ grouped=(unit [rest=(list def) env=ienv state=istate])
7416+ (try-local-group pending groups env state)
7417+ ?~ grouped [%| ["local definitions need unsupported inference" ~]]
7418+ $(ds rest.u.grouped, remaining ~, env env.u.grouped, state state.u.grouped, progressed |)
62827419 $(ds (flop remaining), remaining ~, progressed |)
62837420 =/ d=def i.ds
62847421 ?> ?=(%value -.d)
@@ -6287,6 +7424,11 @@
62877424 =/ retried=? ?=(%| -.inferred)
62887425 =? inferred retried (infer-recursive-gate d env local-state)
62897426 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
7427+ ?: !=(obligations.state.p.inferred obligations.state) [%| ["deferred local definition needs unsupported inference" ~]]
7428+ =. state.p.inferred (promote-restricted-numbers state.p.inferred env)
7429+ =. 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)))
7430+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.inferred holes.state state.p.inferred)
7431+ ?^ hole [%| u.hole]
62907432 =/ merged=(unit [first=icap second=icap])
62917433 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
62927434 ?^ merged
@@ -6302,7 +7444,28 @@
63027444 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
63037445 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
63047446 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
6305− $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state), progressed &)
7447+ $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state, holes holes.state), progressed &)
7448+::
7449+:: Try complete cyclic local groups after individual definitions stall.
7450+:: Components with non-gates or unresolved constraints stay unavailable.
7451+::
7452+++ try-local-group
7453+ |= [ds=(list def) groups=icomponents env=ienv state=istate]
7454+ ^- (unit [rest=(list def) env=ienv state=istate])
7455+ ?~ groups ~
7456+ =/ names=(list term) i.groups
7457+ ?. (gth (lent names) 1) $(groups t.groups)
7458+ =/ members=(list def)
7459+ (skim ds |=(d=def &(?=(%value -.d) (lien names |=(n=term =(n name.d))))))
7460+ ?. =((lent members) (lent names)) $(groups t.groups)
7461+ =/ result=ilocal-result (infer-gate-group members env state)
7462+ ?: ?=(%| -.result) $(groups t.groups)
7463+ =/ rest=(list def)
7464+ (skim ds |=(d=def !(lien names |=(n=term =(n name.d)))))
7465+ =/ more=(unit [rest=(list def) env=ienv state=istate])
7466+ $(ds rest, groups t.groups, env env.p.result, state state.p.result)
7467+ ?^ more more
7468+ `[rest env.p.result state.p.result]
63067469::
63077470:: Read only fields of a known record. Unresolved field constraints and
63087471:: ambiguous repeated faces are outside this fragment. Imported record
@@ -6325,17 +7488,29 @@
63257488 ^- iresult
63267489 =/ reverse=(list term) (flop names)
63277490 ?~ reverse [%| ["empty wing" ~]]
6328− =/ scheme=(unit ischeme) (ienv-lookup i.reverse env)
6329− ?~ scheme [%| ["field access is not supported by partial inference" ~]]
6330− =/ inst=[typ=itype state=istate] (instantiate-scheme u.scheme state)
7491+ =/ iface=(unit ifile) (find-jibb-interface i.reverse jimports.state)
63317492 =/ fields=(list term) t.reverse
7493+ ?~ fields [%| ["field access is not supported by partial inference" ~]]
7494+ =/ scheme=(unit ischeme)
7495+ ?~ iface
7496+ (ienv-lookup i.reverse env)
7497+ (ienv-lookup i.fields values.u.iface)
7498+ ?~ scheme
7499+ ?^ iface [%| ["module member is not available to partial inference" ~]]
7500+ [%| ["field access is not supported by partial inference" ~]]
7501+ =/ inst=[typ=itype state=istate]
7502+ ?~ iface (instantiate-scheme u.scheme state)
7503+ =/ imported=ischeme u.scheme
7504+ =. typ.imported (itype-in-import typ.imported u.iface i.reverse prelude.state)
7505+ (instantiate-scheme imported state)
7506+ =/ remaining=(list term) ?~(iface fields t.fields)
63327507 =/ typ=itype typ.inst
63337508 |-
6334− ?~ fields [%& typ state.inst]
6335− =/ found=(list itype) (record-fields-named i.fields typ sub.state.inst)
7509+ ?~ remaining [%& typ state.inst]
7510+ =/ found=(list itype) (record-fields-named i.remaining typ sub.state.inst)
63367511 ?~ found [%| ["field is not available to partial inference" ~]]
63377512 ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
6338− $(fields t.fields, typ i.found)
7513+ $(remaining t.remaining, typ i.found)
63397514::
63407515:: Propagate a known union or list through supported loobean, unit and list
63417516:: branches. Empty bodies and groups are transparent; bodies with definitions
@@ -6359,6 +7534,8 @@
63597534 ?: &(?=(%collection -.expected) =(%list name.expected) (context-list-expression e))
63607535 (infer-list-context e expected env state context)
63617536 ?: ?=(%branch -.e)
7537+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[expected context])
7538+ ?^ empty-list u.empty-list
63627539 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
63637540 ?~ t.arms.e [%| ["branch pattern is not supported by partial inference" ~]]
63647541 ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -6374,6 +7551,9 @@
63747551 [%| ["branch does not cover both loobeans" ~]]
63757552 =/ subject=iresult (infer-fragment subject.e env state)
63767553 ?: ?=(%| -.subject) subject
7554+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
7555+ ?: ?=(%union -.subject-type)
7556+ [%| ["contextual union-pattern branch is not supported by partial inference" ~]]
63777557 =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
63787558 ?~ su [%| ["loobean branch subject does not unify with ?" ~]]
63797559 =/ left=iresult $(e val.x, state state.p.subject(sub u.su))
@@ -6387,10 +7567,17 @@
63877567 ?: ?=(%unknown -.fit)
63887568 ?: &(?=(%collection -.expected) =(%list name.expected))
63897569 [%| ["branch list constraint is not supported by partial inference" ~]]
7570+ ?: ?=(%flag -.expected) [%| ["branch loobean constraint is not supported by partial inference" ~]]
63907571 [%| ["branch union constraint is not supported by partial inference" ~]]
63917572 ?: ?=(%bad -.fit)
7573+ =/ missing=(unit idiag) (missing-union-tag e expected sub.state.p.value context)
7574+ ?^ missing [%| u.missing]
7575+ =/ nested=(unit idiag) (nested-missing-tag e typ.p.value expected sub.state.p.value next.state.p.value context)
7576+ ?^ nested [%| u.nested]
63927577 ?: &(?=(%collection -.expected) =(%list name.expected))
63937578 [%| ["branch arm does not fit its expected list" ~[[context "expected list"] [(span-of e) "branch arm"]]]]
7579+ ?: ?=(%flag -.expected)
7580+ [%| ["branch arm does not fit its expected loobean" ~[[context "expected loobean"] [(span-of e) "branch arm"]]]]
63947581 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
63957582 [%& expected state.p.value(sub sub.fit, next next.fit)]
63967583::
@@ -6455,23 +7642,47 @@
64557642 [%| ["list tail does not fit its expected type" ~[[context (site-type-note "expected list" target sub.state.p.tail)] [(span-of val.i.t.items.e) (site-type-note "list tail" typ.p.tail sub.state.p.tail)]]]]
64567643 [%& target state.p.tail(sub sub.fit, next next.fit)]
64577644::
7645+++ infer-open-list-items
7646+ |= [items=(list expr) expected=itype env=ienv state=istate context=span]
7647+ ^- iresult
7648+ ?~ items [%& expected state]
7649+ =/ target=itype (itype-walk expected sub.state)
7650+ =/ value=iresult (infer-call-context-arg i.items target env state context)
7651+ ?: ?=(%| -.value) value
7652+ =/ ordinary-fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7653+ =/ fit=ifit
7654+ ?: ?=(%ok -.ordinary-fit) ordinary-fit
7655+ ?: ?&(?=(%union -.target) ?=(^ prelude.state) =(origin.target `[at.u.prelude.state %element]))
7656+ (program-single-generic-fit typ.p.value target sub.state.p.value next.state.p.value)
7657+ ordinary-fit
7658+ ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
7659+ ?: ?=(%bad -.fit)
7660+ ?: |((itype-family-related typ.p.value target sub.state.p.value) (itype-has-any-atom typ.p.value sub.state.p.value) (itype-has-any-atom target sub.state.p.value))
7661+ [%| ["list item widening is not supported by partial inference" ~]]
7662+ [%| ["list items do not have compatible types" ~[[context (site-type-note "expected item" target sub.state.p.value)] [(span-of i.items) (site-type-note "list item" typ.p.value sub.state.p.value)]]]]
7663+ ?: (itype-has-tag (itype-normalize expected sub.fit))
7664+ [%| ["list item needs context in partial inference" ~]]
7665+ $(items t.items, state state.p.value(sub sub.fit, next next.fit))
7666+::
64587667++ infer-list-items
64597668 |= [items=(list expr) expected=itype env=ienv state=istate context=span]
64607669 ^- iresult
64617670 ?~ items [%& expected state]
64627671 =/ target=itype (itype-walk expected sub.state)
6463− =/ value=iresult
6464− ?: &(?=(%union -.target) (context-union-branch i.items))
6465− (infer-union-context i.items target env state context)
6466− ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch i.items))
6467− (infer-union-context i.items target env state context)
6468− ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression i.items))
6469− (infer-list-context i.items target env state context)
6470− (infer-fragment i.items env state)
7672+ =/ value=iresult (infer-call-context-arg i.items target env state context)
64717673 ?: ?=(%| -.value) value
6472− =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7674+ =/ ordinary-fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7675+ =/ fit=ifit
7676+ ?: ?=(%ok -.ordinary-fit) ordinary-fit
7677+ ?: ?&(?=(%union -.target) ?=(^ prelude.state) =(origin.target `[at.u.prelude.state %element]))
7678+ (program-single-generic-fit typ.p.value target sub.state.p.value next.state.p.value)
7679+ ordinary-fit
64737680 ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
64747681 ?: ?=(%bad -.fit)
7682+ =/ missing=(unit idiag) (missing-union-tag i.items target sub.state.p.value context)
7683+ ?^ missing [%| u.missing]
7684+ =/ nested=(unit idiag) (nested-missing-tag i.items typ.p.value target sub.state.p.value next.state.p.value context)
7685+ ?^ nested [%| u.nested]
64757686 [%| ["list item does not fit its expected type" ~[[context (site-type-note "expected item" target sub.state.p.value)] [(span-of i.items) (site-type-note "list item" typ.p.value sub.state.p.value)]]]]
64767687 $(items t.items, state state.p.value(sub sub.fit, next next.fit))
64777688::
@@ -6552,6 +7763,11 @@
65527763 [%| ["list pattern needs the standard prelude in partial inference" ~]]
65537764 ?~ args.typ [%| ["list pattern is not supported by partial inference" ~]]
65547765 ?^ t.args.typ [%| ["list pattern is not supported by partial inference" ~]]
7766+ =/ item-live=(unit [result=?(%yes %no %unknown) left=@ud])
7767+ (itype-inhabited-proof i.args.typ sub.state caps.state 256)
7768+ ?~ item-live [%| ["list element reachability needs unsupported inference" ~]]
7769+ ?: =(%unknown result.u.item-live) [%| ["list element reachability needs unsupported inference" ~]]
7770+ ?: =(%no result.u.item-live) [%| ["list nonempty pattern is unreachable" ~]]
65557771 ?~ arms.e [%| ["list branch is not supported by partial inference" ~]]
65567772 ?~ t.arms.e [%| ["list branch is not supported by partial inference" ~]]
65577773 ?^ t.t.arms.e [%| ["list branch is not supported by partial inference" ~]]
@@ -6564,7 +7780,7 @@
65647780 [%| ["list branch pattern is not supported by partial inference" ~]]
65657781 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
65667782 ?~ binder [%| ["list branch pattern is not supported by partial inference" ~]]
6567− ?: |(=(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)))))
7783+ ?: |(=(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)))))
65687784 [%| ["pattern binder shadows a name" ~]]
65697785 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
65707786 =/ left=iresult
@@ -6601,10 +7817,15 @@
66017817 [%| ["unit branch pattern is not supported by partial inference" ~]]
66027818 =/ binder=(unit term) ?:(first-empty second-name first-name)
66037819 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
6604− ?: |(?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
7820+ ?: |(=(u.binder %proj) ?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
66057821 [%| ["pattern binder shadows a name" ~]]
66067822 =/ payload=(unit itype) (unit-union-payload typ)
66077823 ?~ payload [%| ["unit branch subject is not supported by partial inference" ~]]
7824+ =/ payload-live=(unit [result=?(%yes %no %unknown) left=@ud])
7825+ (itype-inhabited-proof u.payload sub.state.p.subject caps.state.p.subject 256)
7826+ ?~ payload-live [%| ["unit payload reachability needs unsupported inference" ~]]
7827+ ?: =(%unknown result.u.payload-live) [%| ["unit payload reachability needs unsupported inference" ~]]
7828+ ?: =(%no result.u.payload-live) [%| ["unit present pattern is unreachable" ~]]
66087829 =/ extended=ienv [[u.binder [u.payload ~]] env]
66097830 =/ left=iresult
66107831 ?~ expected (infer-fragment val.x ?:(first-empty env extended) state.p.subject)
@@ -6619,27 +7840,752 @@
66197840 ?~ joined [%| ["unit branch results need unsupported inference" ~]]
66207841 [%& typ.p.left state.p.right(sub u.joined)]
66217842::
6622−++ infer-fragment
6623− |= [e=expr env=ienv state=istate]
7843+:: Infer pieces in order, retaining their substitutions and pending tags.
7844+:: A bare decimal literal has no outside type constraint, so it takes its
7845+:: normal @ud default here. Other open numeric and aura variables wait for
7846+:: deferred constraints, which this fragment does not implement yet.
7847+++ infer-string-pieces
7848+ |= [ps=(list piece) env=ienv state=istate]
66247849 ^- iresult
6625− ?- -.e
7850+ ?~ ps [%& [%atom %t] state]
7851+ ?: ?=(%text -.i.ps) $(ps t.ps)
7852+ =/ item=iresult (infer-fragment p.i.ps env state)
7853+ ?: ?=(%| -.item) item
7854+ =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
7855+ ?: |(?=(%atom -.t) ?=(%any-atom -.t))
7856+ $(ps t.ps, state state.p.item)
7857+ ?: &(|(?=(%nvar -.t) ?=(%rnvar -.t)) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
7858+ $(ps t.ps, state state.p.item)
7859+ ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
7860+ $(ps t.ps, state state.p.item)
7861+ ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7862+ [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7863+ ?: &(?=(%rvar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7864+ [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7865+ ?: ?=(%cell -.t)
7866+ [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
7867+ [%| ["interpolation type needs unsupported inference" ~]]
7868+::
7869+:: Whole-case coverage for a known union. When a pattern may cover only
7870+:: part of a case, finite loobean refinements are tried below; other
7871+:: partial coverage stays unsupported until the general pattern matrix.
7872++$ imatch ?(%full %none %unknown)
7873+++ union-pattern-items
7874+ |= [ps=(list pattern) t=itype]
7875+ ^- imatch
7876+ ?~ ps %unknown
7877+ ?~ t.ps (union-pattern i.ps t)
7878+ =. t ?:(?=(%face -.t) body.t t)
7879+ ?. ?=(%cell -.t)
7880+ ?: |(?=(%atom -.t) ?=(%any-atom -.t) ?=(%flag -.t) ?=(%const -.t)) %none
7881+ %unknown
7882+ =/ a=imatch (union-pattern i.ps hed.t)
7883+ =/ b=imatch $(ps t.ps, t tal.t)
7884+ ?: |(=(%none a) =(%none b)) %none
7885+ ?:(&(=(%full a) =(%full b)) %full %unknown)
7886+::
7887+++ union-pattern
7888+ |= [p=pattern t=itype]
7889+ ^- imatch
7890+ =. t ?:(?=(%face -.t) body.t t)
7891+ ?- -.p
7892+ %any %full
7893+ %bind %full
66267894 %lit
6627− ?- form.lit.e
6628− %number ?: =(%ud aura.lit.e)
6629− [%& [%nvar next.state] state(next +(next.state))]
6630− [%& [%atom aura.lit.e] state]
6631− %ship [%& [%atom %p] state]
6632− %date [%& [%atom %da] state]
6633− %duration [%& [%atom %dr] state]
6634− %knot [%& [%atom %ta] state]
7895+ ?: ?=(%const -.t) ?:(=(val.literal.t val.lit.p) %full %none)
7896+ ?: ?=(%cell -.t) %none
7897+ ?: ?=(%flag -.t)
7898+ ?:(|(=(0 val.lit.p) =(1 val.lit.p)) %unknown %none)
7899+ %unknown
7900+ %str ?:(?=(%cell -.t) %none %unknown)
7901+ %cell (union-pattern-items items.p t)
7902+ ==
7903+::
7904+++ union-pattern-has-bind
7905+ |= p=pattern
7906+ ^- ?
7907+ ?: ?=(%bind -.p) &
7908+ ?. ?=(%cell -.p) |
7909+ (lien items.p union-pattern-has-bind)
7910+::
7911+++ union-pattern-bind-items
7912+ |= [ps=(list pattern) t=itype env=ienv globals=(list term)]
7913+ ^- (unit ienv)
7914+ ?~ ps ~
7915+ ?~ t.ps (union-pattern-bind i.ps t env globals)
7916+ =. t ?:(?=(%face -.t) body.t t)
7917+ ?. ?=(%cell -.t) ~
7918+ =/ first=(unit ienv) (union-pattern-bind i.ps hed.t env globals)
7919+ ?~ first ~
7920+ $(ps t.ps, t tal.t, env u.first)
7921+::
7922+++ union-pattern-bind
7923+ |= [p=pattern t=itype env=ienv globals=(list term)]
7924+ ^- (unit ienv)
7925+ =. t ?:(?=(%face -.t) body.t t)
7926+ ?: ?=(%bind -.p)
7927+ ?: |(=(name.p %proj) ?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
7928+ `[[name.p [t ~]] env]
7929+ ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
7930+ `env
7931+::
7932+:: Split loobean fields into finite refinements for partial patterns.
7933+:: Keep original cases for binder types and preserve whole-case matching
7934+:: before trying refinements. Cap products at 64; unknown, empty or opaque
7935+:: shapes stay unsupported rather than implying complete pattern checking.
7936++$ ifinite [origin=@ud base=itype part=itype]
7937+++ finite-product
7938+ |= [hs=(list itype) ts=(list itype) out=(list itype)]
7939+ ^- (list itype)
7940+ ?~ hs out
7941+ =/ rows=(list itype) (turn ts |=(t=itype [%cell i.hs t]))
7942+ $(hs t.hs, out (weld rows out))
7943+::
7944+++ finite-type
7945+ |= t=itype
7946+ ^- (unit (list itype))
7947+ ?- -.t
7948+ %flag
7949+ `~[[%const [%loobean %f 0 '%.y']] [%const [%loobean %f 1 '%.n']]]
7950+ %face
7951+ =/ body=(unit (list itype)) $(t body.t)
7952+ ?~ body ~
7953+ `(turn u.body |=(x=itype [%face name.t x]))
7954+ %cell
7955+ =/ hed=(unit (list itype)) $(t hed.t)
7956+ ?~ hed ~
7957+ =/ tal=(unit (list itype)) $(t tal.t)
7958+ ?~ tal ~
7959+ ?: (gth (mul (lent u.hed) (lent u.tal)) 64) ~
7960+ `(finite-product u.hed u.tal ~)
7961+ * `~[t]
7962+ ==
7963+::
7964+++ finite-cases
7965+ |= [xs=(list itype) out=(list ifinite) origin=@ud]
7966+ ^- (unit (list ifinite))
7967+ ?~ xs `out
7968+ =/ parts=(unit (list itype)) (finite-type i.xs)
7969+ ?~ parts ~
7970+ ?: (gth (add (lent out) (lent u.parts)) 64) ~
7971+ =/ rows=(list ifinite) (turn u.parts |=(t=itype [origin i.xs t]))
7972+ $(xs t.xs, out (weld out rows), origin +(origin))
7973+::
7974+++ infer-known-union-whole
7975+ |= [e=expr env=ienv subject=iresult]
7976+ ^- (unit iresult)
7977+ ?> ?=(%branch -.e)
7978+ ?: ?=(%| -.subject) `subject
7979+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7980+ ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
7981+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7982+ ?~ live ~
7983+ =/ cases=(list itype) u.live
7984+ =/ remaining=(list itype) cases
7985+ =/ arms=(list arm) arms.e
7986+ =/ st=istate state.p.subject
7987+ =/ answer=(unit itype) ~
7988+ |-
7989+ ?~ arms
7990+ ?^ remaining
7991+ `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
7992+ ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
7993+ `[%& u.answer st]
7994+ =/ a=arm i.arms
7995+ ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
7996+ ~
7997+ =/ matching=(list itype) (skim remaining |=(c=itype =(%full (union-pattern pat.a c))))
7998+ ?~ matching
7999+ ?: (lien cases |=(c=itype =(%full (union-pattern pat.a c))))
8000+ `[%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
8001+ `[%| ["union pattern is not supported by partial inference" ~]]
8002+ ?: &(?=(^ t.matching) (union-pattern-has-bind pat.a))
8003+ `[%| ["a union pattern binding several cases is not supported by partial inference" ~]]
8004+ =/ bound=(unit ienv) (union-pattern-bind pat.a i.matching env globals.st)
8005+ ?~ bound `[%| ["pattern binder shadows a name" ~]]
8006+ =/ body=iresult (infer-fragment val.a u.bound st)
8007+ ?: ?=(%| -.body) `body
8008+ =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8009+ =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
8010+ ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
8011+ $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
8012+::
8013+++ infer-known-union-context-whole
8014+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
8015+ ^- (unit iresult)
8016+ ?> ?=(%branch -.e)
8017+ ?: ?=(%| -.subject) `subject
8018+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8019+ ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
8020+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
8021+ ?~ live ~
8022+ =/ cases=(list itype) u.live
8023+ =/ remaining=(list itype) cases
8024+ =/ arms=(list arm) arms.e
8025+ =/ st=istate state.p.subject
8026+ =/ answer=(unit itype) ~
8027+ |-
8028+ ?~ arms
8029+ ?^ remaining
8030+ `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
8031+ ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
8032+ `[%& expected st]
8033+ =/ a=arm i.arms
8034+ ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
8035+ ~
8036+ =/ matching=(list itype) (skim remaining |=(c=itype =(%full (union-pattern pat.a c))))
8037+ ?~ matching
8038+ ?: (lien cases |=(c=itype =(%full (union-pattern pat.a c))))
8039+ `[%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
8040+ `[%| ["union pattern is not supported by partial inference" ~]]
8041+ ?: &(?=(^ t.matching) (union-pattern-has-bind pat.a))
8042+ `[%| ["a union pattern binding several cases is not supported by partial inference" ~]]
8043+ =/ bound=(unit ienv) (union-pattern-bind pat.a i.matching env globals.st)
8044+ ?~ bound `[%| ["pattern binder shadows a name" ~]]
8045+ =/ body=iresult (infer-call-context-arg val.a expected u.bound st context)
8046+ ?: ?=(%| -.body) `body
8047+ =/ fit=ifit (itype-fit typ.p.body expected sub.state.p.body next.state.p.body)
8048+ ?: ?=(%unknown -.fit) `[%| ["union branch result constraint is not supported by partial inference" ~]]
8049+ ?: ?=(%bad -.fit)
8050+ =/ missing=(unit idiag) (missing-union-tag val.a expected sub.state.p.body context)
8051+ ?^ missing `[%| u.missing]
8052+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body expected sub.state.p.body next.state.p.body context)
8053+ ?^ nested `[%| u.nested]
8054+ `[%| ["union branch arm does not fit its expected type" ~[[context "expected type"] [(span-of val.a) "branch arm"]]]]
8055+ ?: (itype-has-tag (itype-normalize expected sub.fit))
8056+ `[%| ["union branch result needs context in partial inference" ~]]
8057+ $(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)
8058+::
8059+++ infer-known-union-finite
8060+ |= [e=expr env=ienv subject=iresult expected=(unit [typ=itype context=span])]
8061+ ^- iresult
8062+ ?> ?=(%branch -.e)
8063+ ?: ?=(%| -.subject) subject
8064+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8065+ ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
8066+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
8067+ ?~ live [%| ["union emptiness needs unsupported inference" ~]]
8068+ =/ expanded=(unit (list ifinite)) (finite-cases u.live ~ 0)
8069+ ?~ expanded [%| ["union pattern expansion needs unsupported inference" ~]]
8070+ =/ cases=(list ifinite) u.expanded
8071+ =/ remaining=(list ifinite) cases
8072+ =/ arms=(list arm) arms.e
8073+ =/ st=istate state.p.subject
8074+ =/ answer=(unit itype) ~
8075+ |-
8076+ ?~ arms
8077+ ?^ remaining
8078+ [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
8079+ ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
8080+ ?~ expected [%& u.answer st]
8081+ [%& typ.u.expected st]
8082+ =/ a=arm i.arms
8083+ ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
8084+ [%| ["partial union pattern is not supported by partial inference" ~]]
8085+ =/ matching=(list ifinite) (skim remaining |=(c=ifinite =(%full (union-pattern pat.a part.c))))
8086+ ?~ matching
8087+ ?: (lien cases |=(c=ifinite =(%full (union-pattern pat.a part.c))))
8088+ [%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
8089+ [%| ["union pattern is not supported by partial inference" ~]]
8090+ ?: &((union-pattern-has-bind pat.a) (lien t.matching |=(c=ifinite !=(origin.c origin.i.matching))))
8091+ [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
8092+ =/ bound=(unit ienv) (union-pattern-bind pat.a base.i.matching env globals.st)
8093+ ?~ bound [%| ["pattern binder shadows a name" ~]]
8094+ =/ body=iresult
8095+ ?~ expected (infer-fragment val.a u.bound st)
8096+ (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
8097+ ?: ?=(%| -.body) body
8098+ ?^ expected
8099+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
8100+ ?: ?=(%unknown -.fit) [%| ["union branch result constraint is not supported by partial inference" ~]]
8101+ ?: ?=(%bad -.fit)
8102+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
8103+ ?^ missing [%| u.missing]
8104+ =/ 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)
8105+ ?^ nested [%| u.nested]
8106+ [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
8107+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8108+ [%| ["union branch result needs context in partial inference" ~]]
8109+ $(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)
8110+ =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
8111+ =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
8112+ ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
8113+ $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
8114+::
8115+:: Prove a one-arm record pattern covers a known, non-union subject.
8116+:: Variable or partial matches stay unsupported; binding uses the same
8117+:: scope and original payload types as the existing union matcher.
8118+++ single-structured-pattern
8119+ |= e=expr
8120+ ^- ?
8121+ ?. ?=(%branch -.e) |
8122+ ?~ arms.e |
8123+ ?^ t.arms.e |
8124+ =/ p=pattern pat.i.arms.e
8125+ ?. ?=(%cell -.p) |
8126+ !(levy items.p |=(x=pattern ?=(%bind -.x)))
8127+::
8128+++ infer-single-case-branch
8129+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
8130+ ^- iresult
8131+ ?> (single-structured-pattern e)
8132+ ?> ?=(%branch -.e)
8133+ ?> ?=(^ arms.e)
8134+ =/ a=arm i.arms.e
8135+ =/ subject=iresult (infer-fragment subject.e env state)
8136+ ?: ?=(%| -.subject) subject
8137+ =/ st=istate state.p.subject
8138+ =/ typ=itype (itype-normalize typ.p.subject sub.st)
8139+ ?: ?=(%union -.typ) [%| ["single-case pattern needs unsupported inference" ~]]
8140+ ?. =(%full (union-pattern pat.a typ))
8141+ [%| ["single-case pattern needs unsupported inference" ~]]
8142+ =/ bound=(unit ienv) (union-pattern-bind pat.a typ env globals.st)
8143+ ?~ bound [%| ["pattern binder shadows a name" ~]]
8144+ ?~ expected (infer-fragment val.a u.bound st)
8145+ =/ body=iresult (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
8146+ ?: ?=(%| -.body) body
8147+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
8148+ ?: ?=(%unknown -.fit) [%| ["single-case branch result constraint is not supported by partial inference" ~]]
8149+ ?: ?=(%bad -.fit)
8150+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
8151+ ?^ missing [%| u.missing]
8152+ =/ 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)
8153+ ?^ nested [%| u.nested]
8154+ [%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
8155+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8156+ [%| ["single-case branch result needs context in partial inference" ~]]
8157+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
8158+::
8159+:: This view is used only by pattern analysis, never exported or bound as
8160+:: the subject. Only null plus a two-binder/wildcard cell is supported; its
8161+:: tail keeps the original recursive type. Other patterns fail closed.
8162+++ jrec-match-view
8163+ |= [e=expr subject=iresult]
8164+ ^- iresult
8165+ ?: ?=(%| -.subject) subject
8166+ ?. ?=(%branch -.e) subject
8167+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8168+ ?. ?=(%jrec -.typ) subject
8169+ ?~ arms.e subject
8170+ ?~ t.arms.e subject
8171+ ?^ t.t.arms.e subject
8172+ =/ x=pattern pat.i.arms.e
8173+ =/ y=pattern pat.i.t.arms.e
8174+ =/ empty=? &(?=(%lit -.x) =(%null form.lit.x))
8175+ =/ full=pattern ?:(empty y x)
8176+ ?. |(empty &(?=(%lit -.y) =(%null form.lit.y))) subject
8177+ ?. ?=(%cell -.full) subject
8178+ ?~ items.full subject
8179+ ?~ t.items.full subject
8180+ ?^ t.t.items.full subject
8181+ ?. |(?=(%bind -.i.items.full) ?=(%any -.i.items.full)) subject
8182+ ?. |(?=(%bind -.i.t.items.full) ?=(%any -.i.t.items.full)) subject
8183+ ?: =(0 jrec-fuel.state.p.subject)
8184+ [%| ["recursive mold unfolding needs unsupported inference" ~]]
8185+ =/ nil=itype [%const [%null %n 0 '~']]
8186+ =/ cell=itype [%cell [%face head.typ [%atom aura.typ]] [%face tail.typ typ]]
8187+ [%& [%union ~[nil cell] ~ ~ ~] state.p.subject(jrec-fuel (dec jrec-fuel.state.p.subject))]
8188+::
8189+:: A bounded source-proven tree match permits flat tag patterns and
8190+:: nonbinding catch-alls. Whole-case binders cannot consume the temporary
8191+:: structural view. Pattern count and field arity are checked first.
8192+++ grec-simple-pattern
8193+ |= [pat=pattern view=itype]
8194+ ^- ?
8195+ ?. ?=(%cell -.pat) |
8196+ ?~ items.pat |
8197+ =/ first=pattern i.items.pat
8198+ ?. ?=(%lit -.first) |
8199+ ?. =(%term form.lit.first) |
8200+ =/ chosen=(unit itype) (contextual-tagged-case view val.lit.first ~)
8201+ ?~ chosen |
8202+ ?> ?=(%cell -.u.chosen)
8203+ =/ rest=(list pattern) t.items.pat
8204+ =/ arity=? ?:(?=(%cell -.tal.u.chosen) ?=([* [* ~]] rest) ?=([* ~] rest))
8205+ ?. arity |
8206+ (levy rest |=(p=pattern |(?=(%bind -.p) ?=(%any -.p))))
8207+::
8208+:: A catch-all with no binder is safe even when it covers both cases.
8209+:: A bound whole case still declines to avoid exporting the analysis view.
8210+++ grec-patterns-eligible
8211+ |= [arms=(list arm) view=itype left=@ud]
8212+ ^- ?
8213+ ?~ arms &
8214+ ?: =(0 left) |
8215+ =/ pat=pattern pat.i.arms
8216+ ?. |(?=(%any -.pat) (grec-simple-pattern pat view)) |
8217+ $(arms t.arms, left (dec left))
8218+++ grec-match-view
8219+ |= [e=expr subject=iresult]
8220+ ^- iresult
8221+ ?: ?=(%| -.subject) subject
8222+ ?. ?=(%branch -.e) subject
8223+ ?. (grec-direct-context typ.p.subject sub.state.p.subject) subject
8224+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8225+ ?. ?=(%grec -.typ) subject
8226+ ?~ arms.e subject
8227+ =/ view=(unit [view=itype left=@ud]) (grec-unfold-view typ jrec-fuel.state.p.subject)
8228+ ?~ view [%| ["recursive mold unfolding needs unsupported inference" ~]]
8229+ ?. (grec-patterns-eligible arms.e view.u.view 128) subject
8230+ [%& view.u.view state.p.subject(jrec-fuel left.u.view)]
8231+::
8232+:: A single-arm diagnostic only probes a direct, source-typed in-scope wing;
8233+:: other subjects retain the prior single-pattern inference path.
8234+++ grec-single-wing-subject
8235+ |= [e=expr env=ienv state=istate]
8236+ ^- (unit iresult)
8237+ ?. ?=(%wing -.e) ~
8238+ ?. ?=([@ ~] names.e) ~
8239+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8240+ ?~ scheme ~
8241+ ?. (grec-direct-context typ.u.scheme sub.state) ~
8242+ `(infer-fragment e env state)
8243+::
8244+++ infer-known-union-branch-subject
8245+ |= [e=expr env=ienv subject=iresult]
8246+ ^- iresult
8247+ =. subject (grec-match-view e subject)
8248+ =. subject (jrec-match-view e subject)
8249+ =/ whole=(unit iresult) (infer-known-union-whole e env subject)
8250+ ?~ whole (infer-known-union-finite e env subject ~)
8251+ u.whole
8252+::
8253+++ infer-known-union-branch
8254+ |= [e=expr env=ienv state=istate]
8255+ ^- iresult
8256+ ?> ?=(%branch -.e)
8257+ (infer-known-union-branch-subject e env (infer-fragment subject.e env state))
8258+::
8259+++ infer-known-union-context-subject
8260+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
8261+ ^- iresult
8262+ =. subject (grec-match-view e subject)
8263+ =. subject (jrec-match-view e subject)
8264+ =/ whole=(unit iresult) (infer-known-union-context-whole e expected env subject context)
8265+ ?~ whole (infer-known-union-finite e env subject `[expected context])
8266+ u.whole
8267+::
8268+:: Limit speculative subject inference to wings and shallow calls;
8269+:: grouping is peeled linearly and cannot introduce a nested branch.
8270+++ simple-union-subject-arg
8271+ |= e=expr
8272+ ^- ?
8273+ ?- -.e
8274+ %wing &
8275+ %lit &
8276+ %str !(lien pieces.e |=(p=piece ?=(%expr -.p)))
8277+ * |
8278+ ==
8279+::
8280+++ safe-union-subject
8281+ |= e=expr
8282+ ^- ?
8283+ ?: ?=(%group -.e) $(e inner.e)
8284+ ?: ?=(%wing -.e) &
8285+ ?. ?=(%call -.e) |
8286+ ?. ?=(%wing -.head.e) |
8287+ (levy args.e simple-union-subject-arg)
8288+::
8289+++ duplicate-loobean-arms
8290+ |= e=expr
8291+ ^- ?
8292+ ?. ?=(%branch -.e) |
8293+ ?~ arms.e |
8294+ ?~ t.arms.e |
8295+ ?^ t.t.arms.e |
8296+ =/ x=pattern pat.i.arms.e
8297+ =/ y=pattern pat.i.t.arms.e
8298+ ?. &(?=(%lit -.x) ?=(%lit -.y)) |
8299+ ?. &(=(%loobean form.lit.x) =(%loobean form.lit.y)) |
8300+ =(val.lit.x val.lit.y)
8301+::
8302+++ union-subject-call
8303+ |= e=expr
8304+ ^- ?
8305+ ?: ?=(%group -.e) $(e inner.e)
8306+ ?=(%call -.e)
8307+::
8308+++ known-union-subject
8309+ |= [e=expr env=ienv state=istate]
8310+ ^- (unit iresult)
8311+ ?. (safe-union-subject e) ~
8312+ =/ subject=iresult (infer-fragment e env state)
8313+ ?: ?=(%| -.subject) ?:((union-subject-call e) `subject ~)
8314+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8315+ ?. |(?=(%union -.typ) ?=(%jrec -.typ) &(?=(%grec -.typ) (grec-direct-context typ.p.subject sub.state.p.subject))) ~
8316+ `subject
8317+::
8318+:: A direct wing with an already-known union may skip genuinely empty cases
8319+:: when checking a one-arm match. Other subjects keep their existing path.
8320+:: A directly known canonical list of an empty element contains only null.
8321+:: This helper never refines an opaque or variable-bound subject.
8322+++ empty-list-null-branch
8323+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
8324+ ^- (unit iresult)
8325+ ?. ?=(%branch -.e) ~
8326+ ?~ arms.e ~
8327+ ?^ t.arms.e ~
8328+ ?. (unit-empty-pattern pat.i.arms.e) ~
8329+ ?. ?=(%wing -.subject.e) ~
8330+ ?. ?=([@ ~] names.subject.e) ~
8331+ =/ scheme=(unit ischeme) (ienv-lookup i.names.subject.e env)
8332+ ?~ scheme ~
8333+ ?. ?=(%collection -.typ.u.scheme) ~
8334+ ?. =(%list name.typ.u.scheme) ~
8335+ ?~ prelude.state ~
8336+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb) ~
8337+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8338+ ?~ standard ~
8339+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
8340+ =/ subject=iresult (infer-fragment subject.e env state)
8341+ ?: ?=(%| -.subject) ~
8342+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8343+ ?. ?=(%collection -.typ) ~
8344+ ?. =(%list name.typ) ~
8345+ ?~ args.typ ~
8346+ ?^ t.args.typ ~
8347+ =/ proof=(unit [empty=? left=@ud]) (itype-empty-proof i.args.typ sub.state.p.subject 256)
8348+ ?~ proof ~
8349+ ?. empty.u.proof ~
8350+ ?~ expected `(infer-fragment val.i.arms.e env state.p.subject)
8351+ =/ body=iresult (infer-call-context-arg val.i.arms.e typ.u.expected env state.p.subject context.u.expected)
8352+ ?: ?=(%| -.body) `body
8353+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
8354+ ?: ?=(%unknown -.fit) `[%| ["single-case branch result constraint is not supported by partial inference" ~]]
8355+ ?: ?=(%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"]]]]
8356+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8357+ `[%| ["single-case branch result needs context in partial inference" ~]]
8358+ `[%& typ.p.body state.p.body(sub sub.fit, next next.fit)]
8359+::
8360+++ known-empty-union-wing
8361+ |= [e=expr env=ienv state=istate]
8362+ ^- (unit iresult)
8363+ ?. ?=(%wing -.e) ~
8364+ ?. ?=([@ ~] names.e) ~
8365+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8366+ ?~ scheme ~
8367+ ?. (contextual-direct-union typ.u.scheme) ~
8368+ =/ subject=iresult (infer-fragment e env state)
8369+ ?: ?=(%| -.subject) ~
8370+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8371+ ?. ?=(%union -.typ) ~
8372+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
8373+ ?~ live ~
8374+ ?: =(u.live cases.typ) ~
8375+ `subject
8376+::
8377+:: Infer changes only against a fully known record spine. Retain the
8378+:: target type; unknown spines and repeated edits remain unsupported.
8379+++ change-spine-known
8380+ |= [t=itype sub=isub]
8381+ ^- ?
8382+ =. t (itype-walk t sub)
8383+ ?: ?=(%face -.t) &
8384+ ?. ?=(%cell -.t) |
8385+ =/ first=itype (itype-walk hed.t sub)
8386+ ?. ?=(%face -.first) |
8387+ $(t tal.t)
8388+::
8389+++ infer-change-edits
8390+ |= [edits=(list edit) target=itype env=ienv state=istate seen=(list term)]
8391+ ^- iresult
8392+ ?~ edits [%& target state]
8393+ =/ entry=edit i.edits
8394+ ?: (lien seen |=(name=term =(name name.entry)))
8395+ [%| ["repeated change fields are not supported by partial inference" ~]]
8396+ ?. (change-spine-known target sub.state)
8397+ [%| ["change target needs a known record in partial inference" ~]]
8398+ =/ found=(list itype) (record-fields-named name.entry target sub.state)
8399+ ?~ found
8400+ [%| ["record has no field `{(trip name.entry)}`" ~[[at.entry "unknown field"]]]]
8401+ ?^ t.found [%| ["change field is ambiguous in partial inference" ~]]
8402+ =/ expected=itype i.found
8403+ =/ value=iresult (infer-call-context-arg val.entry expected env state at.entry)
8404+ ?: ?=(%| -.value) value
8405+ =/ fit=ifit (itype-fit typ.p.value expected sub.state.p.value next.state.p.value)
8406+ ?: ?=(%unknown -.fit) [%| ["change field constraint is not supported by partial inference" ~]]
8407+ ?: ?=(%bad -.fit)
8408+ [%| ["change field and replacement do not unify" ~[[at.entry (site-type-note "expected replacement" expected sub.state.p.value)] [(span-of val.entry) (site-type-note "replacement" typ.p.value sub.state.p.value)]]]]
8409+ $(edits t.edits, state state.p.value(sub sub.fit, next next.fit), seen [name.entry seen])
8410+::
8411+:: Backtick constructs the canonical prelude unit, after checking its
8412+:: prepared template has the standard null and [~ u=A] cases.
8413+++ standard-unit-template
8414+ |= [template=ischeme at=path]
8415+ ^- ?
8416+ ?. =(at /lib/jibb/prelude/jibb) |
8417+ ?~ vars.template |
8418+ ?^ t.vars.template |
8419+ =/ v=@ud i.vars.template
8420+ =/ nil=itype [%const [%null %n 0 '~']]
8421+ =/ expected=itype
8422+ [%union ~[nil [%cell nil [%face %u [%var v]]]] `[at %unit] `%unit ~[[%var v]]]
8423+ =(typ.template expected)
8424+::
8425+:: A named missing-case diagnostic needs more than a failed fit: a case
8426+:: with that tag but the wrong payload is not a missing case. Unknown
8427+:: shapes and atom types that accept terms keep the proof conservative.
8428++$ itag-presence ?(%yes %no %maybe)
8429+++ tag-presence-cases
8430+ |= [cases=(list itype) value=@ sub=isub]
8431+ ^- itag-presence
8432+ ?~ cases %no
8433+ =/ first=itag-presence (tag-presence i.cases value sub)
8434+ ?: =(%yes first) %yes
8435+ =/ rest=itag-presence $(cases t.cases)
8436+ ?: =(%yes rest) %yes
8437+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8438+ %no
8439+::
8440+++ tag-presence
8441+ |= [t=itype value=@ sub=isub]
8442+ ^- itag-presence
8443+ =. t (itype-walk t sub)
8444+ ?- -.t
8445+ %const ?:(=(value val.literal.t) %yes %no)
8446+ %flag ?:(|(=(value 0) =(value 1)) %yes %no)
8447+ %atom ?:(|(=(%tas aura.t) =(%ta aura.t)) %maybe %no)
8448+ %face $(t body.t)
8449+ %cell
8450+ =/ first=itag-presence $(t hed.t)
8451+ ?: =(%yes first) %yes
8452+ =/ rest=itag-presence $(t tal.t)
8453+ ?: =(%yes rest) %yes
8454+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8455+ %no
8456+ %union (tag-presence-cases cases.t value sub)
8457+ * %maybe
8458+ ==
8459+::
8460+++ missing-union-tag
8461+ |= [e=expr expected=itype sub=isub context=span]
8462+ ^- (unit idiag)
8463+ ?. ?=(%lit -.e) ~
8464+ ?. =(%term form.lit.e) ~
8465+ =. expected (itype-walk expected sub)
8466+ |-
8467+ ?: ?=(%face -.expected) $(expected (itype-walk body.expected sub))
8468+ ?. ?=(%union -.expected) ~
8469+ ?. =(%no (tag-presence-cases cases.expected val.lit.e sub)) ~
8470+ =/ label=tape
8471+ ?~ label.expected "union {(show-itype expected sub)}"
8472+ (show-itype expected sub)
8473+ `["{label} has no case `{(trip txt.lit.e)}`" ~[[context "expected union"] [(span-of e) "tag"]]]
8474+::
8475+:: Locate a missing tag inside a syntactic tuple only by replaying the
8476+:: directional fit in source order. Uncertain or earlier failures stop
8477+:: the walk, preserving the generic diagnostic rather than guessing.
8478+++ nested-missing-tag
8479+ |= [e=expr actual=itype expected=itype sub=isub next=@ud context=span]
8480+ ^- (unit idiag)
8481+ =/ original=[left=itype right=itype] [actual expected]
8482+ ?: |(?=(%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))) ~
8483+ =/ fit=ifit (itype-fit actual expected sub next)
8484+ ?. ?=(%bad -.fit) ~
8485+ =. actual (itype-walk actual sub)
8486+ =. expected (itype-walk expected sub)
8487+ ?: &(?=(%face -.actual) ?=(%face -.expected))
8488+ ?. =(name.actual name.expected) ~
8489+ $(actual body.actual, expected body.expected)
8490+ ?: ?=(%face -.actual) $(actual body.actual)
8491+ ?: ?=(%face -.expected) $(expected body.expected)
8492+ =/ direct=(unit idiag) (missing-union-tag e expected sub context)
8493+ ?^ direct direct
8494+ ?. ?=(%tuple -.e) ~
8495+ (nested-missing-items items.e actual expected sub next context)
8496+::
8497+++ nested-missing-items
8498+ |= [items=(list item) actual=itype expected=itype sub=isub next=@ud context=span]
8499+ ^- (unit idiag)
8500+ ?~ items ~
8501+ ?~ t.items (nested-missing-tag val.i.items actual expected sub next context)
8502+ =/ original=[left=itype right=itype] [actual expected]
8503+ ?: |(?=(%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))) ~
8504+ =. actual (itype-walk actual sub)
8505+ =. expected (itype-walk expected sub)
8506+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8507+ =/ first=ifit (itype-fit hed.actual hed.expected sub next)
8508+ ?: ?=(%bad -.first)
8509+ (nested-missing-tag val.i.items hed.actual hed.expected sub next context)
8510+ ?. ?=(%ok -.first) ~
8511+ $(items t.items, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
8512+::
8513+:: A term-headed pair is the same noun as a two-item cell. Preserve the
8514+:: whole pair span for the synthetic head and the value's own span for
8515+:: the payload; unresolved term constraints follow ordinary cell inference.
8516+++ pair-as-cell
8517+ |= e=expr
8518+ ^- expr
8519+ ?> ?=(%pair -.e)
8520+ =/ head=expr [%lit at.e [%term %tas tag.e (crip ['%' (trip tag.e)])]]
8521+ [%tuple at.e ~[[at.e ~ head] [(span-of val.e) ~ val.e]]]
8522+::
8523+:: A segment costs one shared step; dynamic segments are not handled yet.
8524+++ qath-static-fuel
8525+ |= [segs=(list qseg) fuel=@ud]
8526+ ^- (unit @ud)
8527+ ?~ segs `fuel
8528+ ?: =(0 fuel) ~
8529+ ?. ?=(%knot -.i.segs) ~
8530+ $(segs t.segs, fuel (dec fuel))
8531+::
8532+++ infer-fragment
8533+ |= [e=expr env=ienv state=istate]
8534+ ^- iresult
8535+ ?- -.e
8536+ %pair $(e (pair-as-cell e))
8537+ %lit
8538+ ?- form.lit.e
8539+ %number ?: =(%ud aura.lit.e)
8540+ [%& [%nvar next.state] state(next +(next.state))]
8541+ [%& [%atom aura.lit.e] state]
8542+ %ship [%& [%atom %p] state]
8543+ %date [%& [%atom %da] state]
8544+ %duration [%& [%atom %dr] state]
8545+ %knot [%& [%atom %ta] state]
66358546 %loobean [%& [%flag ~] state]
6636− %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
6637− %null [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
8547+ %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e at.e] tags.state])]
8548+ %null [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e at.e] tags.state])]
66388549 ==
6639− %str
6640− =/ interpolated=? (lien pieces.e |=(p=piece ?=(%expr -.p)))
6641− ?: interpolated [%| ["interpolation is not supported by partial inference" ~]]
6642− [%& [%atom %t] state]
8550+ %unit
8551+ ?~ prelude.state [%| ["unit construction needs the standard prelude in partial inference" ~]]
8552+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
8553+ ?~ standard [%| ["unit construction needs the standard prelude in partial inference" ~]]
8554+ ?. (standard-unit-template u.standard at.u.prelude.state)
8555+ [%| ["unit construction needs the standard prelude in partial inference" ~]]
8556+ =/ value=iresult $(e val.e)
8557+ ?: ?=(%| -.value) value
8558+ =/ result=(unit itype) (template-apply u.standard ~[typ.p.value])
8559+ ?~ result [%| ["unit construction is not supported by partial inference" ~]]
8560+ [%& u.result state.p.value]
8561+ %list
8562+ ?~ prelude.state [%| ["list literal needs the standard prelude in partial inference" ~]]
8563+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8564+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8565+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8566+ ?~ standard [%| ["list literal needs the standard prelude in partial inference" ~]]
8567+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]])
8568+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8569+ =/ element=itype [%var next.state]
8570+ =/ result=iresult (infer-open-list-items items.e element env state(next +(next.state)) at.e)
8571+ ?: ?=(%| -.result) result
8572+ [%& [%collection %list ~[element]] state.p.result]
8573+ %str (infer-string-pieces pieces.e env state)
8574+ %qath
8575+ ?~ prelude.state [%| ["application path needs the standard prelude in partial inference" ~]]
8576+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8577+ [%| ["application path needs the standard prelude in partial inference" ~]]
8578+ =/ standard=(unit ischeme) (find-jibb-mold %qath u.prelude.state)
8579+ ?~ standard [%| ["application path needs the standard prelude in partial inference" ~]]
8580+ ?. ?=(~ vars.u.standard) [%| ["application path mold needs unsupported inference" ~]]
8581+ =/ typ=itype typ.u.standard
8582+ ?. ?=(%jrec -.typ) [%| ["application path mold needs unsupported inference" ~]]
8583+ ?. &(=(at.typ /lib/jibb/internal/jibb) =(%qath name.typ) =(%i head.typ) =(%ta aura.typ) =(%t tail.typ))
8584+ [%| ["application path mold needs unsupported inference" ~]]
8585+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8586+ =/ remain=(unit @ud) (qath-static-fuel segs.e (dec jrec-fuel.state))
8587+ ?~ remain [%| ["application path segments need unsupported inference" ~]]
8588+ [%& typ state(jrec-fuel u.remain)]
66438589 %wing
66448590 ?~ names.e [%| ["empty wing" ~]]
66458591 ?^ t.names.e
@@ -6648,7 +8594,7 @@
66488594 ?~ iface (infer-field-wing names.e env state)
66498595 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
66508596 ?~ member [%| ["module member is not available to partial inference" ~]]
6651− =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e)
8597+ =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e prelude.state)
66528598 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
66538599 [%& typ.instance state.instance]
66548600 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
@@ -6661,12 +8607,20 @@
66618607 =/ instance=[typ=itype state=istate] (instantiate-scheme u.scheme state)
66628608 [%& typ.instance state.instance]
66638609 %group $(e inner.e)
6664− %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [[next.state tag.e] tags.state])]
8610+ %change
8611+ ?~ edits.e [%| ["a change takes at least one field" ~[[at.e "empty change"]]]]
8612+ =/ target=iresult $(e [%wing at.e target.e])
8613+ ?: ?=(%| -.target) target
8614+ (infer-change-edits edits.e typ.p.target env state.p.target ~)
8615+ %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [[next.state tag.e at.e] tags.state])]
66658616 %trace
66668617 =/ traced=iresult $(e val.e)
66678618 ?: ?=(%| -.traced) traced
66688619 $(e then.e, state state.p.traced)
6669− %tuple (infer-simple-items items.e env state)
8620+ %tuple
8621+ ?: &(?=(^ defer.state) ?=(^ prelude.state))
8622+ (dg-infer-tuple-items items.e env state)
8623+ (infer-simple-items items.e env state)
66708624 %body
66718625 ?~ defs.e $(e final.e)
66728626 =/ local-names=(list term) (global-value-names defs.e)
@@ -6677,6 +8631,9 @@
66778631 [%| ["local molds shadow a name" ~]]
66788632 =/ local-state=istate
66798633 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8634+ =/ mold-hole=(unit span) (simple-local-mold-hole defs.e)
8635+ ?^ mold-hole
8636+ [%| ["type hole needs a determined type" ~[[u.mold-hole "unresolved type hole"]]]]
66808637 ?. (local-molds-supported local-molds local-state)
66818638 [%| ["local molds need unsupported inference" ~]]
66828639 =/ values=(list def) (local-value-defs defs.e)
@@ -6686,21 +8643,38 @@
66868643 ?: ?=(%| -.result) result
66878644 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
66888645 %branch
8646+ ?^ defer.state (dg-boolean-branch e env state)
66898647 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
6690− ?~ t.arms.e (infer-cell-branch e env state)
6691− ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
8648+ ?~ t.arms.e
8649+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state ~)
8650+ ?^ empty-list u.empty-list
8651+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
8652+ ?^ empty-union (infer-known-union-branch-subject e env u.empty-union)
8653+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8654+ ?^ single (infer-known-union-branch-subject e env u.single)
8655+ ?: (single-structured-pattern e) (infer-single-case-branch e env state ~)
8656+ (infer-cell-branch e env state ~)
8657+ ?^ t.t.arms.e (infer-known-union-branch e env state)
8658+ =/ known=(unit iresult) (known-union-subject subject.e env state)
8659+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
8660+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
8661+ (infer-known-union-branch-subject e env u.known)
66928662 =/ x=arm i.arms.e
66938663 =/ y=arm i.t.arms.e
66948664 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
66958665 (infer-unit-branch e env state ~)
6696− ?. ?=(%lit -.pat.x) [%| ["branch pattern is not supported by partial inference" ~]]
6697− ?. ?=(%lit -.pat.y) [%| ["branch pattern is not supported by partial inference" ~]]
8666+ ?. ?=(%lit -.pat.x) (infer-known-union-branch e env state)
8667+ ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
66988668 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
6699− [%| ["branch pattern is not supported by partial inference" ~]]
8669+ (infer-known-union-branch e env state)
8670+ ?: &(?=(^ known) ?=(%& -.u.known)) (infer-known-union-branch-subject e env u.known)
67008671 ?: =(val.lit.pat.x val.lit.pat.y)
67018672 [%| ["branch does not cover both loobeans" ~]]
67028673 =/ subject=iresult $(e subject.e)
67038674 ?: ?=(%| -.subject) subject
8675+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
8676+ ?: ?=(%union -.subject-type)
8677+ [%| ["union-pattern branch subject is not supported by partial inference" ~]]
67048678 =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
67058679 ?~ su [%| ["loobean branch subject does not unify with ?" ~]]
67068680 =/ left=iresult $(e val.x, state state.p.subject(sub u.su))
@@ -6728,29 +8702,32 @@
67288702 %cast
67298703 =/ target=(unit [typ=itype state=istate]) (infer-simple-shape shape.e state)
67308704 ?~ target
6731− =/ diag=(unit idiag) (direct-import-invalid shape.e state)
8705+ =/ diag=(unit idiag) (nested-import-invalid shape.e state)
67328706 ?^ diag [%| u.diag]
67338707 [%| ["cast mold is not supported by partial inference" ~]]
67348708 =/ value=iresult
6735− ?: &(?=(%union -.typ.u.target) (context-union-branch val.e))
6736− (infer-union-context val.e typ.u.target env state.u.target at.shape.e)
6737− ?: &(?=(%collection -.typ.u.target) =(%list name.typ.u.target) (context-union-branch val.e))
6738− (infer-union-context val.e typ.u.target env state.u.target at.shape.e)
6739− ?: &(?=(%collection -.typ.u.target) =(%list name.typ.u.target) (context-list-expression val.e))
6740− (infer-list-context val.e typ.u.target env state.u.target at.shape.e)
6741− $(e val.e, state state.u.target)
8709+ (infer-call-context-arg val.e typ.u.target env state.u.target at.shape.e)
67428710 ?: ?=(%| -.value) value
8711+ =/ shape=(unit [source=iwfields target=iwfields])
8712+ (width-shape typ.p.value typ.u.target sub.state.p.value)
8713+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
67438714 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
67448715 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
67458716 ?: ?=(%bad -.fit)
8717+ =/ missing=(unit idiag) (missing-union-tag val.e typ.u.target sub.state.p.value at.shape.e)
8718+ ?^ missing [%| u.missing]
8719+ =/ 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)
8720+ ?^ nested [%| u.nested]
67468721 [%| ["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)]]]]
8722+ ?: &(?=(^ defer.state.p.value) !(dg-stable-fit typ.p.value typ.u.target sub.fit))
8723+ [%| ["deferred cast fit needs stable inference" ~]]
67478724 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
67488725 [%& merged state.p.value(sub sub.fit, next next.fit)]
67498726 %crash [%& [%var next.state] state(next +(next.state))]
67508727 %gate
67518728 =/ sam=isample-result (infer-sample sample.e env state)
67528729 ?: ?=(%| -.sam)
6753− =/ diag=(unit idiag) (direct-sample-invalid sample.e state)
8730+ =/ diag=(unit idiag) (sample-import-invalid sample.e env state)
67548731 ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
67558732 [%| [p.sam ~]]
67568733 =/ body=iresult $(e body.e, env env.p.sam, state state.p.sam)
@@ -6759,7 +8736,7 @@
67598736 %gate-wide
67608737 =/ sam=isample-result (infer-sample sample.e env state)
67618738 ?: ?=(%| -.sam)
6762− =/ diag=(unit idiag) (direct-sample-invalid sample.e state)
8739+ =/ diag=(unit idiag) (sample-import-invalid sample.e env state)
67638740 ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
67648741 [%| [p.sam ~]]
67658742 =/ body=iresult $(e body.e, env env.p.sam, state state.p.sam)
@@ -6767,43 +8744,9 @@
67678744 [%& [%fn typ.p.sam typ.p.body] state.p.body]
67688745 %call
67698746 ?~ args.e [%| ["call has no argument" ~]]
6770− =/ head=iresult $(e head.e)
6771− ?: ?=(%| -.head) head
6772− =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
6773− =/ arg=iresult
6774− ?^ t.args.e
6775− ?: ?=(%fn -.head-type)
6776− (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
6777− (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
6778− ?: &(?=(%fn -.head-type) ?=(%union -.sample.head-type) (context-union-branch i.args.e))
6779− (infer-union-context i.args.e sample.head-type env state.p.head (span-of head.e))
6780− ?: &(?=(%fn -.head-type) ?=(%collection -.sample.head-type) =(%list name.sample.head-type) (context-union-branch i.args.e))
6781− (infer-union-context i.args.e sample.head-type env state.p.head (span-of head.e))
6782− ?: &(?=(%fn -.head-type) ?=(%collection -.sample.head-type) =(%list name.sample.head-type) (context-list-expression i.args.e))
6783− (infer-list-context i.args.e sample.head-type env state.p.head (span-of head.e))
6784− $(e i.args.e, state state.p.head)
6785− ?: ?=(%| -.arg) arg
6786− =/ st=istate state.p.arg
6787− =/ ht=itype (itype-walk typ.p.head sub.st)
6788− ?: ?=(%fn -.ht)
6789− =/ fit=ifit (itype-fit typ.p.arg sample.ht sub.st next.st)
6790− ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
6791− ?: ?=(%bad -.fit)
6792− =/ bad=(unit [at=span typ=itype])
6793− ?~(t.args.e ~ (call-error-site args.e typ.p.arg sample.ht sub.st next.st))
6794− =/ whole-args=span
6795− ?~(t.args.e (span-of i.args.e) [beg:(span-of i.args.e) end:(span-of (rear args.e))])
6796− =/ arg-at=span ?~(bad whole-args at.u.bad)
6797− =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
6798− [%| ["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)]]]]
6799− ?: &((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))
6800− [%| ["call result face propagation is not supported by partial inference" ~]]
6801− [%& product.ht st(sub sub.fit, next next.fit)]
6802− =/ result=itype [%var next.st]
6803− =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
6804− ?~ uni
6805− [%| ["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)]]]]
6806− [%& result st(next +(next.st), sub u.uni)]
8747+ ?: (explicit-proj-call e env state)
8748+ [%| ["proj needs an expected record type" ~]]
8749+ (infer-call-with-head e env state (infer-fragment head.e env state))
68078750 * [%| ["expression is not supported by partial inference" ~]]
68088751 ==
68098752::
@@ -6811,12 +8754,322 @@
68118754:: failed. If an intermediate fit is uncertain, retain the whole argument
68128755:: span rather than assigning blame to a particular argument.
68138756::
8757+:: Check a call using the head already inferred in this state. Keeping
8758+:: this shared avoids evaluating or instantiating a contextual head twice.
8759+++ width-has-projections
8760+ |= ps=(list iwprojection)
8761+ ^- ?
8762+ ?~ ps |
8763+ &
8764+::
8765++$ iwidth-elaboration [original=expr typ=itype sub=isub projections=(list iwprojection)]
8766+++ infer-width-elaboration
8767+ |= [e=expr env=ienv state=istate]
8768+ ^- (each iwidth-elaboration idiag)
8769+ =/ out=iresult (infer-fragment e env state)
8770+ ?: ?=(%| -.out) [%| p.out]
8771+ [%& [e typ.p.out sub.state.p.out (flop projections.state.p.out)]]
8772+::
8773+:: Source-bound gate-layout evidence, confined to checked root gate
8774+:: definitions and direct unshadowed prelude calls. The prepared prelude
8775+:: interface and its retained source are trusted as a matching artifact.
8776+:: Layouts identify sample binder faces; they do not change call arity or
8777+:: authorize stripping nested value faces. Unknown origins use ordinary fit.
8778+++ direct-written-gates
8779+ |= [ds=(list def) out=ivisited]
8780+ ^- ivisited
8781+ ?~ ds out
8782+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8783+ ?. |(?=(%gate -.val.i.ds) ?=(%gate-wide -.val.i.ds)) $(ds t.ds)
8784+ $(ds t.ds, out (~(put by out) name.i.ds &))
8785+++ direct-may-use-prelude
8786+ |= [ds=(list def) root=ivisited heads=ivisited]
8787+ ^- ?
8788+ ?~ ds |
8789+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8790+ =/ refs=(list term) (dependency-expr val.i.ds)
8791+ =/ has-root=? (lien refs |=(n=term ?=(^ (~(get by root) n))))
8792+ =/ has-head=? (lien refs |=(n=term ?=(^ (~(get by heads) n))))
8793+ ?: &(has-root has-head) &
8794+ $(ds t.ds)
8795+++ direct-unique-names
8796+ |= [names=(list term) seen=ivisited]
8797+ ^- ?
8798+ ?~ names &
8799+ ?: ?=(^ (~(get by seen) i.names)) |
8800+ $(names t.names, seen (~(put by seen) i.names &))
8801+++ direct-prelude-evidence
8802+ |= [ds=(list def) prelude=(unit ifile)]
8803+ ^- (unit igate-prelude-evidence)
8804+ ?~ prelude ~
8805+ ?~ source.u.prelude ~
8806+ =/ root=ivisited (direct-written-gates ds ~)
8807+ =/ names=(list term) (turn values.u.prelude |=(e=[name=term scheme=ischeme] name.e))
8808+ =/ heads=ivisited (graph-nameset names ~)
8809+ ?. (direct-may-use-prelude ds root heads) ~
8810+ =/ parsed (parse at.u.prelude u.source.u.prelude)
8811+ ?: ?=(%| -.parsed) ~
8812+ ?^ (duplicate-defs defs.p.parsed) ~
8813+ ?. (direct-unique-names (global-value-names defs.p.parsed) ~) ~
8814+ =/ gates=(map term def) (direct-checked-gates defs.p.parsed values.u.prelude)
8815+ `[u.prelude gates]
8816+++ direct-checked-gates
8817+ |= [ds=(list def) env=ienv]
8818+ ^- (map term def)
8819+ =/ names=(list term) (turn env |=(e=[name=term scheme=ischeme] name.e))
8820+ =/ known=ivisited (graph-nameset names ~)
8821+ =/ out=(map term def) ~
8822+ |-
8823+ ?~ ds out
8824+ =/ d=def i.ds
8825+ ?: ?=(%mold -.d) $(ds t.ds)
8826+ ?. ?=(^ (~(get by known) name.d)) $(ds t.ds)
8827+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) $(ds t.ds)
8828+ $(ds t.ds, out (~(put by out) name.d d))
8829+++ direct-find-gate
8830+ |= [n=term ds=(list def)]
8831+ ^- (unit def)
8832+ ?~ ds ~
8833+ ?: &(?=(%value -.i.ds) =(n name.i.ds)) `i.ds
8834+ $(ds t.ds)
8835+++ direct-gate-sample
8836+ |= d=def
8837+ ^- (unit sample)
8838+ ?. ?=(%value -.d) ~
8839+ ?- -.val.d
8840+ %gate `sample.val.d
8841+ %gate-wide `sample.val.d
8842+ * ~
8843+ ==
8844+++ direct-sample-name
8845+ |= sam=sample
8846+ ^- (unit term)
8847+ ?- -.sam
8848+ %bind `name.sam
8849+ %face `name.sam
8850+ %pun `name.sam
8851+ * ~
8852+ ==
8853+++ direct-field-name
8854+ |= f=field
8855+ ^- (unit term)
8856+ ?- -.f
8857+ %face `name.f
8858+ %pun `name.f
8859+ * ~
8860+ ==
8861+++ direct-slot-body
8862+ |= [typ=itype name=(unit term)]
8863+ ^- (unit itype)
8864+ ?~ name `typ
8865+ ?. ?=(%face -.typ) ~
8866+ ?. =(name.typ u.name) ~
8867+ `body.typ
8868+++ direct-invariant
8869+ |= [a=itype b=itype sub=isub next=@ud]
8870+ ^- ifit
8871+ ?: (itype-face-asym a b sub) [%unknown ~]
8872+ =/ forward=ifit (itype-fit a b sub next)
8873+ ?. ?=(%ok -.forward) [%unknown ~]
8874+ ?: (itype-face-asym a b sub.forward) [%unknown ~]
8875+ =/ reverse=ifit (itype-fit b a sub.forward next.forward)
8876+ ?. ?=(%ok -.reverse) [%unknown ~]
8877+ reverse
8878+++ direct-function-fit
8879+ |= [a=itype b=itype sam=sample sh=shape sub=isub next=@ud]
8880+ ^- ifit
8881+ ?. &(?=(%fn -.a) ?=(%fn -.b) ?=(%cell -.sam) ?=(%fn -.sh)) [%unknown ~]
8882+ ?. ?=(%cell -.sample.sh) [%unknown ~]
8883+ =/ as=(list sample) items.sam
8884+ =/ bs=(list field) fields.sample.sh
8885+ ?~ as [%unknown ~]
8886+ ?~ t.as [%unknown ~]
8887+ ?^ t.t.as [%unknown ~]
8888+ ?~ bs [%unknown ~]
8889+ ?~ t.bs [%unknown ~]
8890+ ?^ t.t.bs [%unknown ~]
8891+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) [%unknown ~]
8892+ =/ an=(unit term) (direct-sample-name i.as)
8893+ =/ bn=(unit term) (direct-field-name i.bs)
8894+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8895+ =/ x=(unit itype) (direct-slot-body hed.sample.a an)
8896+ =/ y=(unit itype) (direct-slot-body hed.sample.b bn)
8897+ ?~ x [%unknown ~]
8898+ ?~ y [%unknown ~]
8899+ =/ first=ifit (direct-invariant u.x u.y sub next)
8900+ ?. ?=(%ok -.first) [%unknown ~]
8901+ =. an (direct-sample-name i.t.as)
8902+ =. bn (direct-field-name i.t.bs)
8903+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8904+ =/ x2=(unit itype) (direct-slot-body tal.sample.a an)
8905+ =/ y2=(unit itype) (direct-slot-body tal.sample.b bn)
8906+ ?~ x2 [%unknown ~]
8907+ ?~ y2 [%unknown ~]
8908+ =/ second=ifit (direct-invariant u.x2 u.y2 sub.first next.first)
8909+ ?. ?=(%ok -.second) [%unknown ~]
8910+ (direct-invariant product.a product.b sub.second next.second)
8911+:: This is a tentative proof: its caller must require closed call samples
8912+:: and repeat every positional check under the stable final substitution.
8913+++ direct-positional-fit
8914+ |= [args=(list expr) slots=(list sample) actual=itype expected=itype env=ienv state=istate sub=isub next=@ud]
8915+ ^- ifit
8916+ ?~ args [%unknown ~]
8917+ ?~ slots [%unknown ~]
8918+ =/ last=? ?=(~ t.args)
8919+ ?: !=(last ?=(~ t.slots)) [%unknown ~]
8920+ =/ split=(unit [left=itype right=itype])
8921+ ?: last `[actual expected]
8922+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8923+ `[hed.actual hed.expected]
8924+ ?~ split [%unknown ~]
8925+ =/ x=itype left.u.split
8926+ =/ y=itype right.u.split
8927+ =/ expected-name=(unit term) (direct-sample-name i.slots)
8928+ =/ expected-body=(unit itype) (direct-slot-body y expected-name)
8929+ ?~ expected-body [%unknown ~]
8930+ =. y u.expected-body
8931+ =/ fit=ifit (itype-fit x y sub next)
8932+ =/ accepted=? &(?=(%ok -.fit) !(itype-positional-slot-face-asym x y sub.fit))
8933+ =/ result=(unit ifit)
8934+ ?: accepted `fit
8935+ ?. &(?=(%face -.i.slots) ?=(%fn -.shape.i.slots)) ~
8936+ ?. ?=(%wing -.i.args) ~
8937+ ?. ?=([@ ~] names.i.args) ~
8938+ ?. (unique-value-name i.names.i.args globals.state) ~
8939+ =/ source=(unit def) (~(get by gate-defs.state) i.names.i.args)
8940+ ?~ source ~
8941+ =/ sample=(unit sample) (direct-gate-sample u.source)
8942+ ?~ sample ~
8943+ =/ trial=ifit (direct-function-fit x y u.sample shape.i.slots sub next)
8944+ ?. ?=(%ok -.trial) ~
8945+ `trial
8946+ ?~ result [%unknown ~]
8947+ =. fit u.result
8948+ ?: last fit
8949+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
8950+ ?. ?=(%ok -.fit) [%unknown ~]
8951+ $(args t.args, slots t.slots, actual tal.actual, expected tal.expected, sub sub.fit, next next.fit)
8952+++ direct-any-gate-arg
8953+ |= [args=(list expr) defs=(map term def)]
8954+ ^- ?
8955+ ?~ args |
8956+ =/ found=?
8957+ ?. ?=(%wing -.i.args) |
8958+ ?. ?=([@ ~] names.i.args) |
8959+ ?=(^ (~(get by defs) i.names.i.args))
8960+ ?: found &
8961+ $(args t.args)
8962+++ direct-gate-call-fit
8963+ |= [e=expr actual=itype expected=itype env=ienv state=istate]
8964+ ^- (unit ifit)
8965+ ?. ?=(%call -.e) ~
8966+ ?~ args.e ~
8967+ ?~ t.args.e ~
8968+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8969+ ?. ?=(%wing -.head.e) ~
8970+ ?. ?=([@ ~] names.head.e) ~
8971+ ?. ?=(~ (ienv-lookup i.names.head.e env)) ~
8972+ ?. (unique-value-name i.names.head.e globals.state) ~
8973+ ?. (direct-any-gate-arg args.e gate-defs.state) ~
8974+ ?~ prelude.state ~
8975+ ?~ source.u.prelude.state ~
8976+ ?~ head-evidence.state ~
8977+ ?. =(u.prelude.state iface.u.head-evidence.state) ~
8978+ ?. ?=(^ (ienv-lookup i.names.head.e values.u.prelude.state)) ~
8979+ =/ head=(unit def) (~(get by gates.u.head-evidence.state) i.names.head.e)
8980+ ?~ head ~
8981+ =/ sam=(unit sample) (direct-gate-sample u.head)
8982+ ?~ sam ~
8983+ ?. ?=(%cell -.u.sam) ~
8984+ =/ fit=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.state next.state)
8985+ ?. ?=(%ok -.fit) ~
8986+ :: Enclosing inference may add constraints after this call. Only a
8987+ :: closed call-sample proof can remain stable under those later bindings.
8988+ =/ actual-final=itype (itype-normalize actual sub.fit)
8989+ =/ expected-final=itype (itype-normalize expected sub.fit)
8990+ ?^ (itype-vars actual-final) ~
8991+ ?^ (itype-vars expected-final) ~
8992+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
8993+ :: A later argument may resolve a variable used by an earlier slot.
8994+ :: Recheck every fit and face against the completed substitution; no
8995+ :: additional binding or fresh variable is permitted in the second pass.
8996+ =/ verified=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.fit next.fit)
8997+ ?. ?=(%ok -.verified) ~
8998+ ?. &(=(sub.fit sub.verified) =(next.fit next.verified)) ~
8999+ `fit
9000+::
9001+++ infer-call-with-head
9002+ |= [e=expr env=ienv state=istate head=iresult]
9003+ ^- iresult
9004+ ?> ?=(%call -.e)
9005+ ?~ args.e [%| ["call has no argument" ~]]
9006+ ?: ?=(%| -.head) head
9007+ =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
9008+ =/ arg=iresult
9009+ ?^ t.args.e
9010+ ?: ?=(%fn -.head-type)
9011+ (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
9012+ (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
9013+ ?: ?=(%fn -.head-type)
9014+ (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
9015+ (infer-fragment i.args.e env state.p.head)
9016+ ?: ?=(%| -.arg) arg
9017+ =/ st=istate state.p.arg
9018+ =/ ht=itype (itype-walk typ.p.head sub.st)
9019+ ?: ?=(%fn -.ht)
9020+ =/ shape=(unit [source=iwfields target=iwfields])
9021+ ?^ t.args.e ~
9022+ (width-shape typ.p.arg sample.ht sub.st)
9023+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
9024+ =/ fit=ifit
9025+ ?^ t.args.e (itype-fit-inner typ.p.arg sample.ht sub.st next.st & |)
9026+ (itype-fit typ.p.arg sample.ht sub.st next.st)
9027+ =/ direct=(unit ifit)
9028+ ?: ?=(%ok -.fit) ~
9029+ (direct-gate-call-fit e typ.p.arg sample.ht env st)
9030+ =. fit ?~(direct fit u.direct)
9031+ ?: ?=(%unknown -.fit)
9032+ ?~ defer.st [%| ["call constraint is not supported by partial inference" ~]]
9033+ =/ edge=(unit dgo) (dg-eligible-ctor e typ.p.head typ.p.arg sample.ht st)
9034+ ?~ edge [%| ["call constraint is not supported by partial inference" ~]]
9035+ ?: (gth (lent obligations.st) 63) [%| ["call constraint is not supported by partial inference" ~]]
9036+ [%& product.ht st(obligations [u.edge obligations.st])]
9037+
9038+ ?: ?=(%bad -.fit)
9039+ ?~ t.args.e
9040+ =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
9041+ ?^ missing [%| u.missing]
9042+ =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
9043+ ?^ nested [%| u.nested]
9044+ [%| ["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)]]]]
9045+ =/ bad=(unit [at=span typ=itype])
9046+ (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
9047+ =/ whole-args=span
9048+ [beg:(span-of i.args.e) end:(span-of (rear args.e))]
9049+ =/ arg-at=span ?~(bad whole-args at.u.bad)
9050+ =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
9051+ [%| ["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)]]]]
9052+ ?: &(?=(^ defer.st) !(dg-stable-call-fit typ.p.arg sample.ht product.ht sub.fit ?=(^ t.args.e)))
9053+ [%| ["deferred call fit needs stable inference" ~]]
9054+ =/ face-asym=?
9055+ ?^ direct |
9056+ ?^ t.args.e (itype-positional-face-asym args.e typ.p.arg sample.ht sub.fit)
9057+ (itype-face-asym typ.p.arg sample.ht sub.fit)
9058+ ?: &((itype-has-face typ.p.arg sub.fit) face-asym (itype-output-may-be-cell product.ht sub.fit))
9059+ [%| ["call result face propagation is not supported by partial inference" ~]]
9060+ [%& product.ht st(sub sub.fit, next next.fit)]
9061+ =/ result=itype [%var next.st]
9062+ =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
9063+ ?~ uni
9064+ [%| ["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)]]]]
9065+ [%& result st(next +(next.st), sub u.uni)]
9066+::
68149067++ call-error-site
68159068 |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
68169069 ^- (unit [at=span typ=itype])
68179070 ?~ args ~
68189071 =/ original=[left=itype right=itype] [actual expected]
6819− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
9072+ ?: |(?=(%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))) ~
68209073 =. actual (itype-walk actual sub)
68219074 =. expected (itype-walk expected sub)
68229075 ?: &(?=(%face -.expected) !?=(%face -.actual))
@@ -6831,36 +9084,519 @@
68319084 ?: ?=(%unknown -.first) ~
68329085 $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
68339086::
6834−:: Context can help each argument while the final fit still checks the
6835−:: complete right-nested sample, including any faces on its positions.
9087+:: Context can help a call argument or cast value while the final fit
9088+:: checks the complete right-nested type, including any written faces.
9089+::
9090+:: Context can resolve the payload of a canonical prelude unit, but an
9091+:: unrelated union with a similar noun shape is not the same mold.
9092+++ infer-unit-context
9093+ |= [e=expr expected=itype env=ienv state=istate context=span]
9094+ ^- iresult
9095+ ?> ?=(%unit -.e)
9096+ ?> ?=(%union -.expected)
9097+ ?~ prelude.state (infer-fragment e env state)
9098+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
9099+ ?~ standard (infer-fragment e env state)
9100+ ?. (standard-unit-template u.standard at.u.prelude.state) (infer-fragment e env state)
9101+ ?. =(origin.expected `[at.u.prelude.state %unit]) (infer-fragment e env state)
9102+ ?~ args.expected (infer-fragment e env state)
9103+ ?^ t.args.expected (infer-fragment e env state)
9104+ =/ payload=itype i.args.expected
9105+ =/ canonical=(unit itype) (template-apply u.standard ~[payload])
9106+ ?~ canonical (infer-fragment e env state)
9107+ ?> ?=(%union -.u.canonical)
9108+ ?. =((itype-normalize expected(label ~) sub.state) (itype-normalize u.canonical(label ~) sub.state))
9109+ (infer-fragment e env state)
9110+ =/ value=iresult (infer-call-context-arg val.e payload env state context)
9111+ ?: ?=(%| -.value) value
9112+ =/ fit=ifit (itype-fit typ.p.value payload sub.state.p.value next.state.p.value)
9113+ ?: ?=(%unknown -.fit) [%| ["unit payload constraint is not supported by partial inference" ~]]
9114+ ?: ?=(%bad -.fit)
9115+ =/ missing=(unit idiag) (missing-union-tag val.e payload sub.state.p.value context)
9116+ ?^ missing [%| u.missing]
9117+ =/ nested=(unit idiag) (nested-missing-tag val.e typ.p.value payload sub.state.p.value next.state.p.value context)
9118+ ?^ nested [%| u.nested]
9119+ [%| ["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)]]]]
9120+ [%& expected state.p.value(sub sub.fit, next next.fit)]
9121+::
9122+:: A known gate may receive an enclosing target before its argument is
9123+:: inferred when its result is open or a direct, matching named generic
9124+:: union. Opaque, recursive, tag-constrained and variable-bound union
9125+:: results keep the existing directional path.
9126+++ infer-contextual-call
9127+ |= [e=expr expected=itype env=ienv state=istate]
9128+ ^- iresult
9129+ ?> ?=(%call -.e)
9130+ ?~ args.e [%| ["call has no argument" ~]]
9131+ =/ head=iresult (infer-fragment head.e env state)
9132+ ?: ?=(%| -.head) head
9133+ =/ ht=itype (itype-walk typ.p.head sub.state.p.head)
9134+ ?. ?=(%fn -.ht) (infer-call-with-head e env state head)
9135+ =/ result=itype (itype-walk product.ht sub.state.p.head)
9136+ =/ eligible=?
9137+ ?: ?=(%var -.result) &
9138+ :: A direct known generic union may receive the same nominal result
9139+ :: context before its arguments are checked. Variable-bound origins,
9140+ :: pending tags, recursive identities and unknown atoms stay open.
9141+ ?. &(?=(%union -.product.ht) ?=(%union -.result) ?=(%union -.expected)) |
9142+ ?~ origin.result |
9143+ ?. =(origin.result origin.expected) |
9144+ ?~ args.result |
9145+ ?. =((lent args.result) (lent args.expected)) |
9146+ ?: |((itype-has-tag (itype-normalize result sub.state.p.head)) (itype-has-tag (itype-normalize expected sub.state.p.head))) |
9147+ =/ result-recursive=? (itype-has-recursive (itype-normalize result sub.state.p.head))
9148+ =/ expected-recursive=? (itype-has-recursive (itype-normalize expected sub.state.p.head))
9149+ =/ result-ok=?
9150+ ?. result-recursive &
9151+ ?~ prelude.state |
9152+ &(=(at.u.prelude.state /lib/jibb/prelude/jibb) =(origin.result `[at.u.prelude.state %element]))
9153+ =/ expected-ok=?
9154+ ?. expected-recursive &
9155+ ?~ prelude.state |
9156+ &(=(at.u.prelude.state /lib/jibb/prelude/jibb) =(origin.expected `[at.u.prelude.state %element]))
9157+ ?. &(result-ok expected-ok) |
9158+ ?: |((itype-has-any-atom result sub.state.p.head) (itype-has-any-atom expected sub.state.p.head)) |
9159+ &
9160+ ?. eligible (infer-call-with-head e env state head)
9161+ ?: |(?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)) (itype-has-tag (itype-normalize expected sub.state.p.head)))
9162+ (infer-call-with-head e env state head)
9163+ =/ sub=(unit isub) (itype-unify result expected sub.state.p.head)
9164+ ?~ sub (infer-call-with-head e env state head)
9165+ (infer-call-with-head e env state [%& typ.p.head state.p.head(sub u.sub)])
9166+::
9167+:: An eligible fully faced literal receives context by name, in source order.
9168+++ width-literal-fields
9169+ |= [items=(list item) axis=@ud fuel=@ud]
9170+ ^- (unit iwfields)
9171+ =/ order=(list iwfield) ~
9172+ =/ index=(map term iwfield) *(map term iwfield)
9173+ |-
9174+ ?~ items ~
9175+ ?: =(0 fuel) ~
9176+ ?~ face.i.items ~
9177+ =/ at-axis=@ud ?~(t.items axis (mul 2 axis))
9178+ =/ entry=iwfield [u.face.i.items at-axis [%noun ~]]
9179+ ?: ?=(^ (~(get by index) name.entry)) ~
9180+ =. index (~(put by index) name.entry entry)
9181+ =. order [entry order]
9182+ ?~ t.items `[(flop order) index]
9183+ $(items t.items, axis +((mul 2 axis)), fuel (dec fuel))
9184+++ width-infer-items
9185+ |= [items=(list item) expected=(map term iwfield) env=ienv state=istate context=span]
9186+ ^- iresult
9187+ ?~ items [%| ["empty record is not supported" ~]]
9188+ ?~ face.i.items [%| ["record face needs unsupported inference" ~]]
9189+ =/ field=(unit iwfield) (~(get by expected) u.face.i.items)
9190+ =/ head=iresult
9191+ ?~ field (infer-fragment val.i.items env state)
9192+ (infer-call-context-arg val.i.items typ.u.field env state context)
9193+ ?: ?=(%| -.head) head
9194+ =/ typ=itype [%face u.face.i.items typ.p.head]
9195+ ?~ t.items [%& typ state.p.head]
9196+ =/ tail=iresult $(items t.items, state state.p.head)
9197+ ?: ?=(%| -.tail) tail
9198+ [%& [%cell typ typ.p.tail] state.p.tail]
9199+++ width-infer-literal
9200+ |= [e=expr expected=itype env=ienv state=istate context=span]
9201+ ^- (unit iresult)
9202+ ?. ?=(%tuple -.e) ~
9203+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) ~
9204+ =/ source=(unit iwfields) (width-literal-fields items.e 1 4.096)
9205+ =/ target=(unit iwfields) (width-scan expected sub.state 1 4.096)
9206+ ?~ source ~
9207+ ?~ target ~
9208+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
9209+ ?. (width-in-order order.u.source order.u.target)
9210+ `(infer-simple-items items.e env state)
9211+ `(width-infer-items items.e index.u.target env state context)
9212+::
9213+:: Experimental intrinsic recognition; real bindings retain normal calls.
9214+++ explicit-proj-call
9215+ |= [e=expr env=ienv state=istate]
9216+ ^- ?
9217+ ?. ?=(%call -.e) |
9218+ ?. ?=([* ~] args.e) |
9219+ ?. ?=(%wing -.head.e) |
9220+ ?. =(names.head.e ~[%proj]) |
9221+ ?: ?=(^ (ienv-lookup %proj env)) |
9222+ ?: (lien globals.state |=(n=term =(n %proj))) |
9223+ ?~ prelude.state &
9224+ ?:(?=(^ (ienv-lookup %proj values.u.prelude.state)) | &)
9225+++ infer-proj-source
9226+ |= [e=expr expected=itype env=ienv state=istate context=span]
9227+ ^- iresult
9228+ ?: ?=(%group -.e) $(e inner.e)
9229+ =/ literal=(unit iresult) (width-infer-literal e expected env state context)
9230+ ?^ literal u.literal
9231+ (infer-fragment e env state)
9232+++ infer-proj-context
9233+ |= [e=expr expected=itype env=ienv state=istate context=span]
9234+ ^- iresult
9235+ ?> ?=(%call -.e)
9236+ ?~ args.e [%| ["proj needs one record" ~]]
9237+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) [%| ["proj needs an expected record type" ~]]
9238+ =/ value=iresult (infer-proj-source i.args.e expected env state context)
9239+ ?: ?=(%| -.value) value
9240+ =/ shape=(unit [source=iwfields target=iwfields])
9241+ (width-proj-shape typ.p.value expected sub.state.p.value)
9242+ ?~ shape [%| ["proj needs a known record containing its expected fields" ~]]
9243+ =/ project=(unit iwidth-result) (width-project u.shape sub.state.p.value next.state.p.value)
9244+ ?~ project [%| ["proj constraint needs unsupported inference" ~]]
9245+ =/ st=istate state.p.value(sub sub.u.project, next next.u.project)
9246+ [%& expected st(projections [[at.e e typ.p.value expected steps.u.project] projections.st])]
9247+::
9248+:: A known literal singleton in a direct union can contextualize a
9249+:: loobean literal of the same noun. Only explicit singleton and cell
9250+:: competitors are considered; opaque or variable cases stay unknown.
9251+++ explicit-singleton-in-union
9252+ |= [t=itype noun=@]
9253+ ^- ?
9254+ ?. ?=(%union -.t) |
9255+ =/ cases=(list itype) cases.t
9256+ =/ found=? |
9257+ |-
9258+ ?~ cases found
9259+ =/ c=itype i.cases
9260+ ?: ?=(%cell -.c) $(cases t.cases)
9261+ ?. ?=(%const -.c) |
9262+ ?: =(noun val.literal.c)
9263+ ?: found |
9264+ $(cases t.cases, found &)
9265+ $(cases t.cases)
9266+::
9267+:: Select a written literal-headed case only when every competing case is
9268+:: also an explicit singleton-headed cell and exactly one matches. Opaque,
9269+:: variable-bound and differently shaped cases keep inference unchanged.
9270+:: This first slice supplies context to a directly called payload. Plain
9271+:: literal data and other expressions retain their existing inference path.
9272+++ contextual-atomic-arguments
9273+ |= args=(list expr)
9274+ ^- ?
9275+ ?~ args &
9276+ ?. ?=(?(%lit %wing %ctor) -.i.args) |
9277+ $(args t.args)
9278+++ contextual-direct-payload-call
9279+ |= e=expr
9280+ ^- ?
9281+ ?: ?=(%group -.e) $(e inner.e)
9282+ ?. ?=(%call -.e) |
9283+ ?. ?=(%wing -.head.e) |
9284+ ?~ args.e |
9285+ (contextual-atomic-arguments args.e)
9286+::
9287+:: A walked variable may have concealed a union inside a substituted
9288+:: structure before this arm was called. Decline in that case rather than
9289+:: deriving provenance from the already-walked type.
9290+++ contextual-simple-sub
9291+ |= sub=isub
9292+ ^- ?
9293+ ?~ sub &
9294+ ?: ?=(?(%cell %face %fn %union %collection) -.val.i.sub) |
9295+ $(sub t.sub)
9296+::
9297+:: Check the syntactic root before scanning; scan substitutions once.
9298+++ grec-direct-context
9299+ |= [expected=itype sub=isub]
9300+ ^- ?
9301+ =/ left=@ud 4.096
9302+ |-
9303+ ?: ?=(%face -.expected)
9304+ ?: =(0 left) |
9305+ $(expected body.expected, left (dec left))
9306+ ?. ?=(%grec -.expected) |
9307+ ?~ sub &
9308+ ?: =(0 left) |
9309+ ?: ?=(?(%cell %face %fn %union %collection %grec) -.val.i.sub) |
9310+ $(sub t.sub, left (dec left))
9311+++ contextual-direct-union
9312+ |= target=itype
9313+ ^- ?
9314+ ?: ?=(%face -.target) $(target body.target)
9315+ ?=(%union -.target)
9316+++ contextual-tagged-case
9317+ |= [target=itype tag=@ sub=isub]
9318+ ^- (unit itype)
9319+ ?. ?=(%union -.target) ~
9320+ =/ remaining=(list itype) cases.target
9321+ =/ found=(unit itype) ~
9322+ =/ seen=(set @) *(set @)
9323+ |-
9324+ ?~ remaining found
9325+ =/ c=itype i.remaining
9326+ ?. ?=(%cell -.c) ~
9327+ =/ head=itype hed.c
9328+ ?. ?=(%const -.head) ~
9329+ ?: (~(has in:..zuse seen) val.literal.head) ~
9330+ =. seen (~(put in:..zuse seen) val.literal.head)
9331+ ?: =(tag val.literal.head)
9332+ $(remaining t.remaining, found `c)
9333+ $(remaining t.remaining)
9334+::
9335+:: A bounded syntactic screen: no nested branch, cast, gate or local body
9336+:: can re-enter cell-branch retry during either inference attempt.
9337+++ closed-cell-retry-safe
9338+ |= [todo=(list expr) fuel=@ud]
9339+ ^- ?
9340+ ?~ todo &
9341+ ?: =(0 fuel) |
9342+ =/ e=expr i.todo
9343+ =. fuel (dec fuel)
9344+ ?+ -.e |
9345+ %lit $(todo t.todo)
9346+ %wing $(todo t.todo)
9347+ %ctor $(todo t.todo)
9348+ %path $(todo t.todo)
9349+ %crash $(todo t.todo)
9350+ %str
9351+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) |
9352+ $(todo t.todo)
9353+ %group $(todo [inner.e t.todo])
9354+ %pair $(todo [val.e t.todo])
9355+ %unit $(todo [val.e t.todo])
9356+ %list $(todo (weld items.e t.todo))
9357+ %tuple $(todo (weld (turn items.e |=(i=item val.i)) t.todo))
9358+ %change $(todo (weld (turn edits.e |=(ed=edit val.ed)) t.todo))
9359+ %call $(todo [head.e (weld args.e t.todo)])
9360+ %trace $(todo [val.e then.e t.todo])
9361+ ==
9362+::
9363+++ closed-cell-sub-safe
9364+ |= [sub=isub fuel=@ud]
9365+ ^- ?
9366+ ?~ sub &
9367+ ?: =(0 fuel) |
9368+ ?: ?=(?(%cell %face %fn %union %collection %grec %jrec %recursive) -.val.i.sub) |
9369+ $(sub t.sub, fuel (dec fuel))
9370+::
9371+++ closed-cell-branch-eligible
9372+ |= [e=expr expected=itype sub=isub]
9373+ ^- ?
9374+ ?. &(?=(%branch -.e) ?=(%cell -.expected) (closed-cell-sub-safe sub 512)) |
9375+ ?~ arms.e |
9376+ ?~ t.arms.e |
9377+ ?^ t.t.arms.e |
9378+ =/ x=arm i.arms.e
9379+ =/ y=arm i.t.arms.e
9380+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
9381+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
9382+ ?: =(val.lit.pat.x val.lit.pat.y) |
9383+ (closed-cell-retry-safe ~[subject.e val.x val.y] 512)
9384+::
9385+:: Attempt ordinary inference first; retry from the same state only for
9386+:: the bounded non-reentrant syntax above. Preserve original value faces.
9387+++ infer-closed-cell-branch
9388+ |= [e=expr expected=itype env=ienv state=istate context=span]
9389+ ^- iresult
9390+ ?> (closed-cell-branch-eligible e expected sub.state)
9391+ ?> ?=(%branch -.e)
9392+ ?> ?=(^ arms.e)
9393+ ?> ?=(^ t.arms.e)
9394+ =/ ordinary=iresult (infer-fragment e env state)
9395+ =/ ordinary-good=?
9396+ ?: ?=(%| -.ordinary) |
9397+ =/ fit=ifit (itype-fit typ.p.ordinary expected sub.state.p.ordinary next.state.p.ordinary)
9398+ ?=(%ok -.fit)
9399+ ?: ordinary-good ordinary
9400+ =/ attempt=(unit iresult)
9401+ =/ x=arm i.arms.e
9402+ =/ y=arm i.t.arms.e
9403+ =/ subject=iresult (infer-fragment subject.e env state)
9404+ ?: ?=(%| -.subject) ~
9405+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
9406+ ?: ?=(%union -.subject-type) ~
9407+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
9408+ ?~ su ~
9409+ =/ left=iresult (infer-call-context-arg val.x expected env state.p.subject(sub u.su) context)
9410+ ?: ?=(%| -.left) ~
9411+ =/ lf=ifit (itype-fit typ.p.left expected sub.state.p.left next.state.p.left)
9412+ ?. ?=(%ok -.lf) ~
9413+ =/ right=iresult (infer-call-context-arg val.y expected env state.p.left(sub sub.lf, next next.lf) context)
9414+ ?: ?=(%| -.right) ~
9415+ =/ rf=ifit (itype-fit typ.p.right expected sub.state.p.right next.state.p.right)
9416+ ?. ?=(%ok -.rf) ~
9417+ =/ sub=isub sub.rf
9418+ =/ next=@ud next.rf
9419+ =/ lt=itype (itype-normalize typ.p.left sub)
9420+ =/ rt=itype (itype-normalize typ.p.right sub)
9421+ =/ et=itype (itype-normalize expected sub)
9422+ ?. =(lt rt) ~
9423+ ?: |(?=(^ (itype-vars lt)) ?=(^ (itype-vars rt)) ?=(^ (itype-vars et))) ~
9424+ ?: |((itype-has-tag lt) (itype-has-tag rt) (itype-has-tag et)) ~
9425+ =/ lcheck=ifit (itype-fit typ.p.left expected sub next)
9426+ ?. ?=(%ok -.lcheck) ~
9427+ ?. &(=(sub.lcheck sub) =(next.lcheck next)) ~
9428+ =/ rcheck=ifit (itype-fit typ.p.right expected sub next)
9429+ ?. ?=(%ok -.rcheck) ~
9430+ ?. &(=(sub.rcheck sub) =(next.rcheck next)) ~
9431+ `[%& typ.p.left state.p.right(sub sub, next next)]
9432+ ?~ attempt ordinary
9433+ u.attempt
68369434::
68379435++ infer-call-context-arg
68389436 |= [e=expr expected=itype env=ienv state=istate context=span]
68399437 ^- iresult
9438+ ?: &(?=(^ defer.state) ?=(%branch -.e)) (infer-fragment e env state)
9439+ ?: &(?=(^ defer.state) ?=(^ prelude.state) ?=(%tuple -.e))
9440+ (infer-fragment e env state)
9441+ ?: ?=(%pair -.e) $(e (pair-as-cell e))
9442+ ?: ?=(%group -.e) $(e inner.e)
9443+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
9444+ ?: ?=(%trace -.e)
9445+ =/ traced=iresult (infer-fragment val.e env state)
9446+ ?: ?=(%| -.traced) traced
9447+ $(e then.e, state state.p.traced)
68409448 =/ target=itype (itype-walk expected sub.state)
68419449 |-
68429450 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9451+ ?: (explicit-proj-call e env state)
9452+ (infer-proj-context e expected env state context)
9453+ :: Experimental construction only for a source-proven direct target.
9454+ :: Decline any walked structural binding to retain raw-variable provenance.
9455+ ?: &(?=(%grec -.target) ?=(%tuple -.e) (grec-direct-context expected sub.state))
9456+ =/ unfolded=(unit [view=itype left=@ud]) (grec-unfold-view target jrec-fuel.state)
9457+ ?~ unfolded [%| ["recursive mold unfolding needs unsupported inference" ~]]
9458+ ?~ items.e [%| ["recursive mold constructor needs unsupported inference" ~]]
9459+ =/ first=item i.items.e
9460+ ?. &(?=(~ face.first) ?=(%lit -.val.first) =(%term form.lit.val.first))
9461+ [%| ["recursive mold constructor needs unsupported inference" ~]]
9462+ =/ chosen=(unit itype) (contextual-tagged-case view.u.unfolded val.lit.val.first sub.state)
9463+ ?~ chosen [%| ["recursive mold constructor has no matching case" ~]]
9464+ =/ value=iresult (infer-call-context-items items.e u.chosen env state(jrec-fuel left.u.unfolded) context)
9465+ ?: ?=(%| -.value) value
9466+ =/ fit=ifit (itype-fit typ.p.value u.chosen sub.state.p.value next.state.p.value)
9467+ ?: ?=(%unknown -.fit) [%| ["recursive mold case needs unsupported inference" ~]]
9468+ ?: ?=(%bad -.fit) [%| ["recursive mold case does not fit its source shape" ~]]
9469+ [%& target state.p.value(sub sub.fit, next next.fit)]
9470+ :: Only the source-proven one-layer cell is exposed. Each recursive
9471+ :: descent consumes one written tuple; named values use ordinary fit.
9472+ ?: &(?=(%jrec -.target) ?=(%lit -.e) =(%null form.lit.e))
9473+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9474+ [%& target state(jrec-fuel (dec jrec-fuel.state))]
9475+ ?: &(?=(%jrec -.target) ?=(%tuple -.e))
9476+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9477+ =. state state(jrec-fuel (dec jrec-fuel.state))
9478+ =/ shape=itype
9479+ [%cell [%face head.target [%atom aura.target]] [%face tail.target target]]
9480+ =/ value=iresult (infer-call-context-items items.e shape env state context)
9481+ ?: ?=(%| -.value) value
9482+ =/ fit=ifit (itype-fit typ.p.value shape sub.state.p.value next.state.p.value)
9483+ ?: ?=(%unknown -.fit) [%| ["recursive mold cell constraint needs unsupported inference" ~]]
9484+ ?: ?=(%bad -.fit) [%| ["recursive mold cell does not fit its source shape" ~]]
9485+ [%& target state.p.value(sub sub.fit, next next.fit)]
9486+ ?: ?=(%call -.e) (infer-contextual-call e target env state)
9487+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[target context])
9488+ ?^ empty-list u.empty-list
9489+ ?: (single-structured-pattern e)
9490+ ?> ?=(%branch -.e)
9491+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
9492+ ?^ empty-union (infer-known-union-context-subject e target env u.empty-union context)
9493+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
9494+ ?^ single (infer-known-union-context-subject e target env u.single context)
9495+ (infer-single-case-branch e env state `[target context])
9496+ ?: (cell-binder-pattern e)
9497+ (infer-cell-branch e env state `[target context])
9498+ :: In an explicit singleton context retain the written loobean noun;
9499+ :: the ordinary singleton fit compares its noun, not its spelling.
9500+ =/ singleton=(unit itype)
9501+ ?. ?=(%lit -.e) ~
9502+ ?. =(%loobean form.lit.e) ~
9503+ ?. |(?=(%const -.target) &(?=(%union -.expected) (explicit-singleton-in-union expected val.lit.e))) ~
9504+ `[%const lit.e]
9505+ ?^ singleton [%& u.singleton state]
9506+ =/ known=(unit iresult)
9507+ ?: ?=(%branch -.e) (known-union-subject subject.e env state)
9508+ ~
9509+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
9510+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
9511+ (infer-known-union-context-subject e target env u.known context)
9512+ ?: &(?=(%union -.target) ?=(%unit -.e))
9513+ (infer-unit-context e target env state context)
9514+ ?: (closed-cell-branch-eligible e expected sub.state)
9515+ (infer-closed-cell-branch e expected env state context)
9516+ ?: &(?=(%flag -.target) (context-union-branch e))
9517+ (infer-union-context e target env state context)
68439518 ?: &(?=(%union -.target) (context-union-branch e))
68449519 (infer-union-context e target env state context)
68459520 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
68469521 (infer-union-context e target env state context)
68479522 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
68489523 (infer-list-context e target env state context)
9524+ :: A literal-headed tuple can receive the unique case's payload
9525+ :: context. The ordinary final fit still checks the complete union.
9526+ =/ selected=(unit itype)
9527+ ?. &((contextual-simple-sub sub.state) (contextual-direct-union expected) ?=(%union -.target) ?=(%tuple -.e) ?=(^ items.e)) ~
9528+ ?~ t.items.e ~
9529+ ?^ t.t.items.e ~
9530+ ?. (contextual-direct-payload-call val.i.t.items.e) ~
9531+ =/ first=item i.items.e
9532+ ?. &(?=(~ face.first) ?=(%lit -.val.first) |(=(%term form.lit.val.first) =(%null form.lit.val.first) =(%loobean form.lit.val.first))) ~
9533+ (contextual-tagged-case target val.lit.val.first sub.state)
9534+ ?^ selected
9535+ ?> ?=(%tuple -.e)
9536+ :: On this bounded shallow-call shape, preserve any inference that
9537+ :: already fits before trying the new contextual path. Neither pass
9538+ :: can recursively select a nested tuple from the atomic arguments.
9539+ =/ ordinary=(unit iresult)
9540+ =/ initial=iresult (infer-fragment e env state)
9541+ ?: ?=(%| -.initial) ~
9542+ =/ fit=ifit (itype-fit typ.p.initial target sub.state.p.initial next.state.p.initial)
9543+ ?. ?=(%ok -.fit) ~
9544+ `initial
9545+ ?^ ordinary u.ordinary
9546+ =/ value=iresult (infer-call-context-items items.e u.selected env state context)
9547+ ?: ?=(%| -.value) value
9548+ =/ fit=ifit (itype-fit typ.p.value u.selected sub.state.p.value next.state.p.value)
9549+ ?: ?=(%unknown -.fit) [%| ["tagged case needs unsupported inference" ~]]
9550+ ?: ?=(%bad -.fit) [%| ["tagged case does not fit its expected type" ~[[context "expected union case"] [(span-of e) "value"]]]]
9551+ [%& typ.p.value state.p.value(sub sub.fit, next next.fit)]
9552+ ?: &(?=(%cell -.target) ?=(%tuple -.e))
9553+ (infer-call-context-items items.e target env state context)
68499554 (infer-fragment e env state)
68509555::
6851−++ infer-call-context-args
6852− |= [args=(list expr) expected=itype env=ienv state=istate context=span]
9556+:: Preserve each written face; the final complete sample fit checks faces.
9557+:: A tuple or positional field face belongs to the enclosing sample,
9558+:: not to the expression at that position. A second face, if present,
9559+:: is part of the value's own expected type.
9560+++ projection-field-target
9561+ |= expected=itype
9562+ ^- itype
9563+ ?:(?=(%face -.expected) body.expected expected)
9564+::
9565+++ infer-call-context-items
9566+ |= [items=(list item) expected=itype env=ienv state=istate context=span]
68539567 ^- iresult
6854− ?~ args [%| ["call has no argument" ~]]
6855− ?~ t.args (infer-call-context-arg i.args expected env state context)
9568+ ?~ items [%| ["empty cell is not supported by partial inference" ~]]
9569+ ?~ t.items
9570+ =/ last=iresult (infer-call-context-arg val.i.items (projection-field-target expected) env state context)
9571+ ?: ?=(%| -.last) last
9572+ =/ typ=itype typ.p.last
9573+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9574+ [%& typ state.p.last]
68569575 =/ target=itype (itype-walk expected sub.state)
68579576 |-
68589577 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
6859− ?. ?=(%cell -.target)
6860− (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
6861− =/ head=iresult (infer-call-context-arg i.args hed.target env state context)
9578+ ?. ?=(%cell -.target) (infer-simple-items items env state)
9579+ =/ head=iresult (infer-call-context-arg val.i.items (projection-field-target hed.target) env state context)
68629580 ?: ?=(%| -.head) head
6863− =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
9581+ =/ typ=itype typ.p.head
9582+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9583+ =/ tail=iresult (infer-call-context-items t.items tal.target env state.p.head context)
9584+ ?: ?=(%| -.tail) tail
9585+ [%& [%cell typ typ.p.tail] state.p.tail]
9586+::
9587+++ infer-call-context-args
9588+ |= [args=(list expr) expected=itype env=ienv state=istate context=span]
9589+ ^- iresult
9590+ ?~ args [%| ["call has no argument" ~]]
9591+ ?~ t.args (infer-call-context-arg i.args (projection-field-target expected) env state context)
9592+ =/ target=itype (itype-walk expected sub.state)
9593+ |-
9594+ ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9595+ ?. ?=(%cell -.target)
9596+ (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
9597+ =/ head=iresult (infer-call-context-arg i.args (projection-field-target hed.target) env state context)
9598+ ?: ?=(%| -.head) head
9599+ =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
68649600 ?: ?=(%| -.tail) tail
68659601 [%& [%cell typ.p.head typ.p.tail] state.p.tail]
68669602::
@@ -6879,11 +9615,55 @@
68799615 ?: ?=(%| -.tail) tail
68809616 [%& [%cell ht typ.p.tail] state.p.tail]
68819617::
6882−:: A single two-binder cell pattern covers every value of a cell type.
6883−:: No other pattern matrix is implemented here.
9618+:: A single all-binder cell pattern covers a known cell spine; the final
9619+:: binder captures the remaining noun. Other pattern matrices stay partial.
9620+::
9621+:: Validate binders before reading the subject, preserving shadow-error
9622+:: precedence. The last binder receives the entire remaining tail.
9623+++ cell-pattern-names
9624+ |= [pats=(list pattern) env=ienv globals=(list term) seen=(list term)]
9625+ ^- (each (list term) @t)
9626+ ?~ pats [%& ~]
9627+ ?. ?=(%bind -.i.pats) [%| 'branch pattern is not supported by partial inference']
9628+ =/ name=term name.i.pats
9629+ ?: |(=(name %proj) ?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
9630+ [%| 'pattern shadows a name']
9631+ =/ rest=(each (list term) @t) $(pats t.pats, seen [name seen])
9632+ ?: ?=(%| -.rest) rest
9633+ [%& [name p.rest]]
9634+::
9635+++ cell-pattern-types
9636+ |= [names=(list term) env=ienv next=@ud]
9637+ ^- [typ=itype env=ienv next=@ud]
9638+ ?~ names !!
9639+ =/ head=itype [%var next]
9640+ =/ scope=ienv [[i.names [head ~]] env]
9641+ ?~ t.names [head scope +(next)]
9642+ =/ tail=[typ=itype env=ienv next=@ud] $(names t.names, env scope, next +(next))
9643+ [[%cell head typ.tail] env.tail next.tail]
9644+::
9645+:: At every position that must be a cell, opaque or sum types may still
9646+:: contain cells. Do not report a definite mismatch without unfolding them.
9647+++ cell-pattern-spine-unknown
9648+ |= [typ=itype names=(list term) sub=isub]
9649+ ^- ?
9650+ ?~ names |
9651+ ?~ t.names |
9652+ =. typ (itype-walk typ sub)
9653+ ?: ?=(%cell -.typ) $(typ tal.typ, names t.names)
9654+ |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%jrec -.typ) ?=(%grec -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9655+::
9656+++ cell-binder-pattern
9657+ |= e=expr
9658+ ^- ?
9659+ ?. ?=(%branch -.e) |
9660+ ?~ arms.e |
9661+ ?^ t.arms.e |
9662+ ?. ?=(%cell -.pat.i.arms.e) |
9663+ !(single-structured-pattern e)
68849664::
68859665++ infer-cell-branch
6886− |= [e=expr env=ienv state=istate]
9666+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
68879667 ^- iresult
68889668 ?> ?=(%branch -.e)
68899669 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -6892,25 +9672,31 @@
68929672 =/ pats=(list pattern) items.pat.arm
68939673 ?~ pats [%| ["branch pattern is not supported by partial inference" ~]]
68949674 ?~ t.pats [%| ["branch pattern is not supported by partial inference" ~]]
6895− ?^ t.t.pats [%| ["branch pattern is not supported by partial inference" ~]]
6896− ?. ?=(%bind -.i.pats) [%| ["branch pattern is not supported by partial inference" ~]]
6897− ?. ?=(%bind -.i.t.pats) [%| ["branch pattern is not supported by partial inference" ~]]
6898− =/ one=term name.i.pats
6899− =/ two=term name.i.t.pats
6900− ?: |(=(one two) ?=(^ (ienv-lookup one env)) ?=(^ (ienv-lookup two env)) (lien globals.state |=(x=term |(=(x one) =(x two)))))
6901− [%| ["pattern shadows a name" ~]]
9675+ =/ names=(each (list term) @t) (cell-pattern-names pats env globals.state ~)
9676+ ?: ?=(%| -.names) [%| [(trip p.names) ~]]
69029677 =/ subject=iresult (infer-fragment subject.e env state)
69039678 ?: ?=(%| -.subject) subject
69049679 =/ st=istate state.p.subject
6905− ?: (itype-has-recursive (itype-normalize typ.p.subject sub.st))
9680+ =/ subject-type=itype (itype-normalize typ.p.subject sub.st)
9681+ ?: (itype-has-recursive subject-type)
69069682 [%| ["recursive pattern is not supported by partial inference" ~]]
69079683 ?: (itype-has-face typ.p.subject sub.st)
69089684 [%| ["record patterns are not supported by partial inference" ~]]
6909− =/ head=itype [%var next.st]
6910− =/ tail=itype [%var +(next.st)]
6911− =/ sub=(unit isub) (itype-unify typ.p.subject [%cell head tail] sub.st)
9685+ ?: (cell-pattern-spine-unknown subject-type p.names sub.st)
9686+ [%| ["cell pattern subject is not supported by partial inference" ~]]
9687+ =/ binders=[typ=itype env=ienv next=@ud] (cell-pattern-types p.names env next.st)
9688+ =/ sub=(unit isub) (itype-unify typ.p.subject typ.binders sub.st)
69129689 ?~ sub [%| ["cell pattern does not match the subject type" ~]]
6913− (infer-fragment val.arm [[one [head ~]] [two [tail ~]] env] st(next (add 2 next.st), sub u.sub))
9690+ =. st st(next next.binders, sub u.sub)
9691+ ?~ expected (infer-fragment val.arm env.binders st)
9692+ =/ body=iresult (infer-call-context-arg val.arm typ.u.expected env.binders st context.u.expected)
9693+ ?: ?=(%| -.body) body
9694+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
9695+ ?: ?=(%unknown -.fit) [%| ["cell branch result constraint is not supported by partial inference" ~]]
9696+ ?: ?=(%bad -.fit) [%| ["cell branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.arm) "branch arm"]]]]
9697+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
9698+ [%| ["cell branch result needs context in partial inference" ~]]
9699+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
69149700::
69159701++ show-itype
69169702 |= [t=itype sub=isub]
@@ -6920,15 +9706,26 @@
69209706 %var
69219707 ?: (lth id.t 26) [(add 65 id.t) ~]
69229708 "T{<id.t>}"
9709+ %fvar
9710+ ?: (lth id.t 26) [(add 65 id.t) ~]
9711+ "T{<id.t>}"
69239712 %avar
69249713 ?: (lth id.t 26) [(add 65 id.t) ~]
69259714 "T{<id.t>}"
9715+ %rvar
9716+ ?: (lth id.t 26) [(add 65 id.t) ~]
9717+ "T{<id.t>}"
69269718 %nvar
69279719 ?: (lth id.t 26) [(add 65 id.t) ~]
69289720 "T{<id.t>}"
9721+ %rnvar
9722+ ?: (lth id.t 26) [(add 65 id.t) ~]
9723+ "T{<id.t>}"
69299724 %atom "@{(trip aura.t)}"
69309725 %any-atom "@"
69319726 %flag "?"
9727+ %noun "*"
9728+ %empty "!!"
69329729 %tag (trip txt.literal.t)
69339730 %const (trip txt.literal.t)
69349731 %union
@@ -6936,6 +9733,8 @@
69369733 ?~ args.t (trip u.label.t)
69379734 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
69389735 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9736+ %jrec ?~(label.t "recursive mold" (trip u.label.t))
9737+ %grec ?~(label.t "recursive mold" "({(trip u.label.t)} {(show-itype-cases args.t sub)})")
69399738 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
69409739 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
69419740 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
@@ -6971,15 +9770,22 @@
69719770 ^- ?
69729771 ?- -.typ
69739772 %nvar &
9773+ %rnvar &
69749774 %var |
9775+ %fvar |
69759776 %avar |
9777+ %rvar |
69769778 %atom |
69779779 %any-atom |
69789780 %flag |
9781+ %noun |
9782+ %empty |
69799783 %tag |
69809784 %const |
69819785 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
69829786 %recursive |
9787+ %jrec |
9788+ %grec (lien args.typ |=(c=itype (itype-has-nvar c)))
69839789 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
69849790 %face $(typ body.typ)
69859791 %fn |($(typ sample.typ) $(typ product.typ))
@@ -6990,7 +9796,7 @@
69909796 |= [label=tape typ=itype sub=isub]
69919797 ^- tape
69929798 =/ normalized=itype (itype-normalize typ sub)
6993− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
9799+ ?: |(?=(%var -.normalized) ?=(%fvar -.normalized) ?=(%avar -.normalized) ?=(%rvar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
69949800 ?: (itype-has-hidden-recursive normalized) label
69959801 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
69969802 ?: (gth (lent vars) 26) label
@@ -7011,7 +9817,9 @@
70119817 =/ ident=(unit @ud)
70129818 ?+ -.resolved ~
70139819 %var `id.resolved
9820+ %fvar `id.resolved
70149821 %avar `id.resolved
9822+ %rvar `id.resolved
70159823 ==
70169824 ?~ ident $(caps t.caps)
70179825 ?: =(n u.ident) &
@@ -7025,7 +9833,9 @@
70259833 =/ ident=(unit @ud)
70269834 ?+ -.resolved ~
70279835 %var `id.resolved
9836+ %fvar `id.resolved
70289837 %avar `id.resolved
9838+ %rvar `id.resolved
70299839 ==
70309840 ?~ ident $(caps t.caps)
70319841 ?: =(n u.ident) `i.caps
@@ -7039,7 +9849,9 @@
70399849 =/ ident=(unit @ud)
70409850 ?+ -.resolved ~
70419851 %var `id.resolved
9852+ %fvar `id.resolved
70429853 %avar `id.resolved
9854+ %rvar `id.resolved
70439855 ==
70449856 ?~ ident $(caps t.caps)
70459857 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
@@ -7054,7 +9866,9 @@
70549866 =/ ident=(unit @ud)
70559867 ?+ -.resolved ~
70569868 %var `id.resolved
9869+ %fvar `id.resolved
70579870 %avar `id.resolved
9871+ %rvar `id.resolved
70589872 ==
70599873 ?~ ident &
70609874 ?: (cap-id-in u.ident t.caps sub) &
@@ -7069,8 +9883,8 @@
70699883 ^- ?
70709884 ?~ caps |
70719885 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
7072− ?: ?=(%avar -.resolved)
7073− ?: =(n id.resolved) &
9886+ ?: |(?=(%avar -.resolved) ?=(%rvar -.resolved))
9887+ ?: =(n +.resolved) &
70749888 $(caps t.caps)
70759889 $(caps t.caps)
70769890::
@@ -7079,15 +9893,22 @@
70799893 ^- ?
70809894 ?- -.t
70819895 %var |
9896+ %fvar |
70829897 %avar =(n id.t)
9898+ %rvar =(n id.t)
70839899 %nvar |
9900+ %rnvar |
70849901 %atom |
70859902 %any-atom |
70869903 %flag |
9904+ %noun |
9905+ %empty |
70879906 %tag |
70889907 %const |
70899908 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
70909909 %recursive |
9910+ %jrec |
9911+ %grec (lien args.t |=(c=itype (has-atom-var n c)))
70919912 %collection (lien args.t |=(c=itype (has-atom-var n c)))
70929913 %face $(t body.t)
70939914 %fn |($(t sample.t) $(t product.t))
@@ -7127,17 +9948,25 @@
71279948 =/ out=tape ""
71289949 |-
71299950 ?~ vars out
9951+ ?: (itype-var-is-restricted i.vars t)
9952+ =/ sep=tape ?:(printed ", " " where ")
9953+ =/ clause=tape "{sep}{(show-itype [%rvar i.vars] ~)} is an atom other than ?"
9954+ $(vars t.vars, printed &, out (weld out clause))
71309955 ?: (itype-var-is-atom i.vars t)
71319956 =/ sep=tape ?:(printed ", " " where ")
71329957 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
71339958 $(vars t.vars, printed &, out (weld out clause))
9959+ ?: (itype-var-is-gate-free i.vars t)
9960+ =/ sep=tape ?:(printed ", " " where ")
9961+ =/ clause=tape "{sep}{(show-itype [%fvar i.vars] ~)} contains no gates"
9962+ $(vars t.vars, printed &, out (weld out clause))
71349963 $(vars t.vars)
71359964::
71369965:: Build the supported part of the value environment in dependency order.
71379966:: Each pass adds successful definitions. Forward references become
7138−:: available on a later pass; mutually recursive groups and unsupported
7139−:: syntax do not enter the environment. Generalized definitions are closed, so a
7140−:: use instantiates its variables afresh.
9967+:: available on a later pass; unsupported syntax does not enter the
9968+:: environment. Generalized definitions are closed, so a use instantiates
9969+:: its variables afresh.
71419970::
71429971++ global-value-names
71439972 |= ds=(list def)
@@ -7227,6 +10056,8 @@
722710056++ infer-recursive-gate
722810057 |= [d=def env=ienv state=istate]
722910058 ^- iresult
10059+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
10060+ =. gate-defs.state ~
723010061 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
723110062 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
723210063 [%| ["recursive definition is not a gate" ~]]
@@ -7241,8 +10072,8 @@
724110072 ?: ?=(%| -.sam)
724210073 =/ diag=(unit idiag)
724310074 ?- -.gate
7244− %gate (direct-sample-invalid sample.gate state)
7245− %gate-wide (direct-sample-invalid sample.gate state)
10075+ %gate (sample-import-invalid sample.gate env state)
10076+ %gate-wide (sample-import-invalid sample.gate env state)
724610077 * ~
724710078 ==
724810079 ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
@@ -7264,36 +10095,565 @@
726410095 ?~ uni [%| ["recursive gate constraint is not supported by partial inference" ~]]
726510096 [%& [%fn typ.p.sam typ.p.out] state.p.out(sub u.uni)]
726610097::
7267−++ add-supported-defs
7268− |= [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)]
10098+++ dependency-root
10099+ |= names=(list term)
10100+ ^- (list term)
10101+ ?~ names ~
10102+ ~[(rear names)]
10103+::
10104+++ dependency-exprs
10105+ |= xs=(list expr)
10106+ ^- (list term)
10107+ ?~ xs ~
10108+ =/ first=(list term) (dependency-expr i.xs)
10109+ (weld first $(xs t.xs))
10110+::
10111+++ dependency-pieces
10112+ |= xs=(list piece)
10113+ ^- (list term)
10114+ ?~ xs ~
10115+ =/ first=(list term)
10116+ ?- -.i.xs
10117+ %expr (dependency-expr p.i.xs)
10118+ %text ~
10119+ ==
10120+ (weld first $(xs t.xs))
10121+::
10122+++ dependency-qsegs
10123+ |= xs=(list qseg)
10124+ ^- (list term)
10125+ ?~ xs ~
10126+ =/ first=(list term)
10127+ ?- -.i.xs
10128+ %expr (dependency-expr p.i.xs)
10129+ %knot ~
10130+ ==
10131+ (weld first $(xs t.xs))
10132+::
10133+++ dependency-items
10134+ |= xs=(list item)
10135+ ^- (list term)
10136+ ?~ xs ~
10137+ =/ first=(list term) (dependency-expr val.i.xs)
10138+ (weld first $(xs t.xs))
10139+::
10140+++ dependency-edits
10141+ |= xs=(list edit)
10142+ ^- (list term)
10143+ ?~ xs ~
10144+ =/ first=(list term) (dependency-expr val.i.xs)
10145+ (weld first $(xs t.xs))
10146+::
10147+++ dependency-arms
10148+ |= xs=(list arm)
10149+ ^- (list term)
10150+ ?~ xs ~
10151+ =/ first=(list term) (dependency-expr val.i.xs)
10152+ (weld first $(xs t.xs))
10153+::
10154+++ dependency-defs
10155+ |= xs=(list def)
10156+ ^- (list term)
10157+ ?~ xs ~
10158+ =/ first=(list term)
10159+ ?: ?=(%value -.i.xs) (dependency-expr val.i.xs)
10160+ ~
10161+ (weld first $(xs t.xs))
10162+::
10163+++ dependency-expr
10164+ |= e=expr
10165+ ^- (list term)
10166+ ?- -.e
10167+ %str (dependency-pieces pieces.e)
10168+ %qath (dependency-qsegs segs.e)
10169+ %wing (dependency-root names.e)
10170+ %change
10171+ =/ first=(list term) (dependency-root target.e)
10172+ =/ last=(list term) (dependency-edits edits.e)
10173+ (weld first last)
10174+ %pair (dependency-expr val.e)
10175+ %unit (dependency-expr val.e)
10176+ %group (dependency-expr inner.e)
10177+ %list (dependency-exprs items.e)
10178+ %tuple (dependency-items items.e)
10179+ %gate (dependency-expr body.e)
10180+ %gate-wide (dependency-expr body.e)
10181+ %call
10182+ =/ first=(list term) (dependency-expr head.e)
10183+ =/ last=(list term) (dependency-exprs args.e)
10184+ (weld first last)
10185+ %cast (dependency-expr val.e)
10186+ %trace
10187+ =/ first=(list term) (dependency-expr val.e)
10188+ =/ last=(list term) (dependency-expr then.e)
10189+ (weld first last)
10190+ %branch
10191+ =/ first=(list term) (dependency-expr subject.e)
10192+ =/ last=(list term) (dependency-arms arms.e)
10193+ (weld first last)
10194+ %body
10195+ =/ first=(list term) (dependency-defs defs.e)
10196+ =/ last=(list term) (dependency-expr final.e)
10197+ (weld first last)
10198+ * ~
10199+ ==
10200+::
10201+:: Infer a cyclic component with one monomorphic seed per gate. All members
10202+:: must succeed before any scheme is available; pending constraints and
10203+:: unresolved branch joins remain partial.
10204++$ igate-entry [name=term typ=itype body=expr env=ienv caps=icaps]
10205++$ igate-seeds (each [entries=(list igate-entry) state=istate] idiag)
10206+++ seed-gate-group
10207+ |= [ds=(list def) env=ienv state=istate]
10208+ ^- igate-seeds
10209+ ?~ ds [%& [~ state]]
10210+ =/ d=def i.ds
10211+ ?. ?=(%value -.d) [%| ["recursive group contains a non-gate" ~]]
10212+ =/ gate=expr val.d
10213+ ?. |(?=(%gate -.gate) ?=(%gate-wide -.gate))
10214+ [%| ["recursive group contains a non-gate" ~]]
10215+ =/ initial=istate (reserve-def-caps gate state)
10216+ =/ sam=isample-result
10217+ ?- -.gate
10218+ %gate (infer-sample sample.gate env initial)
10219+ %gate-wide (infer-sample sample.gate env initial)
10220+ * !!
10221+ ==
10222+ ?: ?=(%| -.sam) [%| [p.sam ~]]
10223+ =/ body=expr
10224+ ?- -.gate
10225+ %gate body.gate
10226+ %gate-wide body.gate
10227+ * !!
10228+ ==
10229+ =/ seed=itype [%fn typ.p.sam [%var next.state.p.sam]]
10230+ =/ entry=igate-entry [name.d seed body env.p.sam caps.state.p.sam]
10231+ =/ after=istate state.p.sam(next +(next.state.p.sam), caps caps.state)
10232+ =/ rest=igate-seeds $(ds t.ds, state after)
10233+ ?: ?=(%| -.rest) rest
10234+ [%& [[entry entries.p.rest] state.p.rest]]
10235+::
10236+++ group-seed-env
10237+ |= [entries=(list igate-entry) env=ienv]
726910238 ^- ienv
7270− ?~ ds env
10239+ ?~ entries env
10240+ [[name.i.entries [typ.i.entries ~]] $(entries t.entries)]
10241+::
10242+++ infer-gate-group-bodies
10243+ |= [entries=(list igate-entry) seeds=ienv state=istate]
10244+ ^- igate-seeds
10245+ ?~ entries [%& [~ state]]
10246+ =/ entry=igate-entry i.entries
10247+ ?> ?=(%fn -.typ.entry)
10248+ =/ scope=ienv (weld seeds env.entry)
10249+ =/ out=iresult (infer-fragment body.entry scope state(caps caps.entry))
10250+ ?: ?=(%| -.out) out
10251+ =/ uni=(unit isub) (itype-unify product.typ.entry typ.p.out sub.state.p.out)
10252+ ?~ uni [%| ["recursive group constraint is not supported by partial inference" ~]]
10253+ =. caps.entry caps.state.p.out
10254+ =/ after=istate state.p.out(sub u.uni, caps caps.state)
10255+ =/ rest=igate-seeds $(entries t.entries, state after)
10256+ ?: ?=(%| -.rest) rest
10257+ [%& [[entry entries.p.rest] state.p.rest]]
10258+::
10259+++ group-schemes
10260+ |= [entries=(list igate-entry) env=ienv outer=istate state=istate]
10261+ ^- (each ienv idiag)
10262+ ?~ entries [%& ~]
10263+ =/ entry=igate-entry i.entries
10264+ =/ merged=(unit [first=icap second=icap]) (merged-capitals caps.entry sub.state)
10265+ ?^ merged
10266+ [%| ["distinct type variables must not be forced equal" ~[[at.first.u.merged "first type variable"] [at.second.u.merged "second type variable"]]]]
10267+ ?: (constrained-capitals caps.entry sub.state)
10268+ [%| ["explicit capital constraints are not supported by partial inference" ~]]
10269+ =/ typ=itype (itype-normalize typ.entry sub.state)
10270+ ?: (itype-has-nvar typ) [%| ["recursive group needs unsupported inference" ~]]
10271+ ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
10272+ [%| ["recursive group needs unsupported inference" ~]]
10273+ =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
10274+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
10275+ =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
10276+ ?: (gth (lent vars) 26) [%| ["recursive group needs too many type variables" ~]]
10277+ =/ rest=(each ienv idiag) $(entries t.entries)
10278+ ?: ?=(%| -.rest) rest
10279+ [%& [[name.entry [typ vars]] p.rest]]
10280+::
10281+++ infer-gate-group
10282+ |= [ds=(list def) env=ienv state=istate]
10283+ ^- ilocal-result
10284+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
10285+ =/ names=(list term) (global-value-names ds)
10286+ ?. (levy names |=(n=term (unique-value-name n names)))
10287+ [%| ["recursive group contains duplicate names" ~]]
10288+ ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
10289+ [%| ["recursive group shadows a name" ~]]
10290+ =/ scoped=istate state(globals (weld names globals.state), gate-defs ~)
10291+ =/ seeded=igate-seeds (seed-gate-group ds env scoped)
10292+ ?: ?=(%| -.seeded) seeded
10293+ =/ seeds=ienv (group-seed-env entries.p.seeded ~)
10294+ =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
10295+ ?: ?=(%| -.body) body
10296+ :: Per-member ownership through mutual recursion is not implemented.
10297+ ?: !=(projections.state.p.body projections.state)
10298+ [%| ["record projection in recursive groups needs unsupported inference" ~]]
10299+ ?: !=(holes.state.p.body holes.state)
10300+ [%| ["holes in recursive groups need unsupported inference" ~]]
10301+ ?: (pending-tags tags.state.p.body sub.state.p.body)
10302+ [%| ["recursive group has unresolved literal constraints" ~]]
10303+ =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
10304+ ?: ?=(%| -.schemes) schemes
10305+ [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
10306+::
10307+++ width-finalize
10308+ |= [ps=(list iwprojection) sub=isub visible=(list @ud)]
10309+ ^- (unit (list iwprojection))
10310+ ?~ ps `~
10311+ ?: (lien t.ps |=(p=iwprojection =(at.p at.i.ps))) ~
10312+ =/ src=itype (default-decimals (itype-normalize source.i.ps sub))
10313+ =/ dst=itype (default-decimals (itype-normalize target.i.ps sub))
10314+ ?: |((itype-has-nvar src) (itype-has-nvar dst) (itype-has-tag src) (itype-has-tag dst)) ~
10315+ =/ vars=(list @ud) (weld (itype-vars src) (itype-vars dst))
10316+ ?. (levy vars |=(n=@ud (lien visible |=(v=@ud =(n v))))) ~
10317+ =/ rest=(unit (list iwprojection)) $(ps t.ps)
10318+ ?~ rest ~
10319+ =/ entry=iwprojection i.ps
10320+ =. entry entry(source src, target dst)
10321+ `[entry u.rest]
10322+::
10323+++ add-supported-defs
10324+ |= [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)]
10325+ ^- [env=ienv artifacts=(list iwidth-definition)]
10326+ (add-supported-defs-core ds all-defs checked heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts ~)
10327+::
10328+
10329++$ iresolved [env=ienv grouped=(list term) artifacts=(list iwidth-definition)]
10330++$ iadj (map term (list term))
10331++$ ivisited (map term ?)
10332++$ iwork (list [name=term done=?])
10333++$ iwresult [seen=ivisited order=(list term)]
10334++$ icresult [seen=ivisited component=(list term)]
10335++$ icomponents (list (list term))
10336+++ graph-nameset
10337+ |= [names=(list term) seen=ivisited]
10338+ ^- ivisited
10339+ ?~ names seen
10340+ $(names t.names, seen (~(put by seen) i.names &))
10341+::
10342+++ graph-edges
10343+ |= [name=term graph=iadj]
10344+ ^- (list term)
10345+ =/ found=(unit (list term)) (~(get by graph) name)
10346+ ?~ found ~
10347+ u.found
10348+::
10349+++ graph-make-forward
10350+ |= [ds=(list def) names=ivisited graph=iadj]
10351+ ^- iadj
10352+ ?~ ds graph
10353+ ?. ?=(%value -.i.ds) $(ds t.ds)
10354+ =/ deps=(list term) (dependency-expr val.i.ds)
10355+ =. deps (skim deps |=(n=term ?=(^ (~(get by names) n))))
10356+ $(ds t.ds, graph (~(put by graph) name.i.ds deps))
10357+::
10358+++ graph-add-reverse
10359+ |= [name=term edges=(list term) reverse=iadj]
10360+ ^- iadj
10361+ ?~ edges reverse
10362+ =/ prior=(list term) (graph-edges i.edges reverse)
10363+ $(edges t.edges, reverse (~(put by reverse) i.edges [name prior]))
10364+::
10365+++ graph-reverse
10366+ |= [names=(list term) graph=iadj reverse=iadj]
10367+ ^- iadj
10368+ ?~ names reverse
10369+ =. reverse (graph-add-reverse i.names (graph-edges i.names graph) reverse)
10370+ $(names t.names)
10371+::
10372+++ graph-order
10373+ |= [todo=iwork seen=ivisited order=(list term) graph=iadj]
10374+ ^- iwresult
10375+ ?~ todo [seen order]
10376+ =/ event=[name=term done=?] i.todo
10377+ ?: done.event $(todo t.todo, order [name.event order])
10378+ ?: ?=(^ (~(get by seen) name.event)) $(todo t.todo)
10379+ =. seen (~(put by seen) name.event &)
10380+ =/ children=iwork (turn (graph-edges name.event graph) |=(n=term [n |]))
10381+ $(todo (weld children [[name.event &] t.todo]))
10382+::
10383+++ graph-collect
10384+ |= [todo=(list term) seen=ivisited component=(list term) graph=iadj]
10385+ ^- icresult
10386+ ?~ todo [seen component]
10387+ ?: ?=(^ (~(get by seen) i.todo)) $(todo t.todo)
10388+ =. seen (~(put by seen) i.todo &)
10389+ $(todo (weld (graph-edges i.todo graph) t.todo), component [i.todo component])
10390+::
10391+++ graph-collect-all
10392+ |= [order=(list term) seen=ivisited graph=iadj comps=icomponents]
10393+ ^- icomponents
10394+ ?~ order comps
10395+ ?: ?=(^ (~(get by seen) i.order)) $(order t.order)
10396+ =/ found=icresult (graph-collect ~[i.order] seen ~ graph)
10397+ $(order t.order, seen seen.found, comps [component.found comps])
10398+::
10399+:: Two depth-first passes find components before group inference. Maps
10400+:: preserve the graph identity; duplicate global names fail closed.
10401+++ graph-components
10402+ |= [ds=(list def) names=(list term)]
10403+ ^- icomponents
10404+ =/ nameset=ivisited ~
10405+ =/ pending=(list term) names
10406+ |-
10407+ ?^ pending
10408+ ?: ?=(^ (~(get by nameset) i.pending)) ~
10409+ $(pending t.pending, nameset (~(put by nameset) i.pending &))
10410+ =/ graph=iadj (graph-make-forward ds nameset ~)
10411+ =/ reverse=iadj (graph-reverse names graph ~)
10412+ =/ order=iwresult (graph-order (turn names |=(n=term [n |])) ~ ~ graph)
10413+ (graph-collect-all order.order ~ reverse ~)
10414+::
10415+++ graph-cycle
10416+ |= [component=(list term) graph=iadj]
10417+ ^- ?
10418+ ?~ component |
10419+ ?^ t.component &
10420+ (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
10421+::
10422+++ add-groups
10423+ |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) artifacts=(list iwidth-definition) state=istate]
10424+ ^- iresolved
10425+ ?~ components [env grouped artifacts]
10426+ =/ component=(list term) i.components
10427+ ?. (graph-cycle component graph) $(components t.components)
10428+ ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
10429+ =/ members=(list def)
10430+ %+ skim ds
10431+ |= d=def
10432+ &(?=(%value -.d) (lien component |=(n=term =(n name.d))))
10433+ ?. =((lent members) (lent component)) $(components t.components)
10434+ ?. (levy component |=(n=term (unique-value-name n globals.state))) $(components t.components)
10435+ =/ result=ilocal-result (infer-gate-group members env state)
10436+ ?: ?=(%| -.result) $(components t.components)
10437+ $(components t.components, env env.p.result, grouped (weld component grouped))
10438+::
10439+++ resolve-groups
10440+ |= [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)]
10441+ ^- iresolved
10442+ (resolve-groups-core ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude ~)
10443+::
10444+
10445++$ iadded-definition
10446+ [env=ienv checked=(map term def) artifacts=(list iwidth-definition)]
10447+++ add-supported-result
10448+ |= [d=def result=iresult initial=istate env=ienv checked=(map term def) artifacts=(list iwidth-definition)]
10449+ ^- (unit iadded-definition)
10450+ ?> ?=(%value -.d)
10451+ ?: ?=(%| -.result) ~
10452+ =. state.p.result (promote-restricted-numbers state.p.result env)
10453+ =. 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)))
10454+ ?^ (unresolved-hole holes.state.p.result holes.initial state.p.result) ~
10455+ ?: (constrained-capitals caps.state.p.result sub.state.p.result) ~
10456+ =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
10457+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) ~
10458+ ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) ~
10459+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
10460+ ?: (gth (lent vars) 26) ~
10461+ =/ finalized=(unit (list iwprojection))
10462+ (width-finalize projections.state.p.result sub.state.p.result vars)
10463+ ?~ finalized ~
10464+ =? artifacts ?=(^ u.finalized)
10465+ [[name.d val.d typ sub.state.p.result (flop u.finalized)] artifacts]
10466+ =? checked |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) (~(put by checked) name.d d)
10467+ `[[[name.d [typ vars]] env] checked artifacts]
10468+++ add-supported-defs-core
10469+ |= [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)])]
10470+ ^- [env=ienv artifacts=(list iwidth-definition)]
10471+ ?~ ds [env artifacts]
727110472 =/ d=def i.ds
727210473 ?: ?=(%mold -.d) $(ds t.ds)
10474+ ?: (lien (program-recovery-names all-defs) |=(n=term =(n name.d))) $(ds t.ds)
727310475 ?. (unique-value-name name.d globals) $(ds t.ds)
727410476 ?^ (ienv-lookup name.d env) $(ds t.ds)
727510477 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7276− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
10478+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10479+ =. grec-index.initial index
10480+ =. gate-defs.initial checked
10481+ =. head-evidence.initial heads
727710482 =. initial (reserve-def-caps val.d initial)
727810483 =/ result=iresult (infer-fragment val.d env initial)
727910484 =? result ?=(%| -.result) (infer-recursive-gate d env initial)
7280− ?: ?=(%| -.result) $(ds t.ds)
7281− ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
7282− =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
7283− ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
7284− ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
7285− =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
7286− ?: (gth (lent vars) 26) $(ds t.ds)
7287− $(ds t.ds, env [[name.d [typ vars]] env])
10485+ =/ added=(unit iadded-definition)
10486+ (add-supported-result d result initial env checked artifacts)
10487+ ?~ added $(ds t.ds)
10488+ $(ds t.ds, env env.u.added, checked checked.u.added, artifacts artifacts.u.added)
10489+::
10490+:: Full checking discards unsupported definitions. On that failure path only,
10491+:: retry a bounded number of missing definitions to explain a pending tag
10492+:: from the same ordinary inference state instead of hiding it behind the
10493+:: generic completeness error. No successful definition takes this path.
10494+++ module-pending-tag
10495+ |= [ds=(list def) env=ienv base=istate fuel=@ud]
10496+ ^- (unit [at=span msg=tape])
10497+ =/ checked=(map term def) (direct-checked-gates ds env)
10498+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.base)
10499+ |-
10500+ ?~ ds ~
10501+ ?: =(0 fuel) ~
10502+ =/ d=def i.ds
10503+ ?: ?=(%mold -.d) $(ds t.ds, fuel (dec fuel))
10504+ ?^ (ienv-lookup name.d env) $(ds t.ds, fuel (dec fuel))
10505+ =/ initial=istate base(gate-defs checked, head-evidence heads)
10506+ =. initial (reserve-def-caps val.d initial)
10507+ =/ result=iresult (infer-fragment val.d env initial)
10508+ =? result ?=(%| -.result) (infer-recursive-gate d env initial)
10509+ ?: ?=(%| -.result) $(ds t.ds, fuel (dec fuel))
10510+ =/ pending=(unit [at=span msg=tape])
10511+ (pending-tag-diagnostic tags.state.p.result sub.state.p.result)
10512+ ?^ pending pending
10513+ $(ds t.ds, fuel (dec fuel))
10514+::
10515+++ resolve-groups-core
10516+ |= [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)])]
10517+ ^- iresolved
10518+ =/ env=ienv ~
10519+ =/ grouped=(list term) ~
10520+ =/ artifacts=(list iwidth-definition) ~
10521+ =/ names=(list term) (global-value-names ds)
10522+ =/ nameset=ivisited (graph-nameset names ~)
10523+ =/ graph=iadj (graph-make-forward ds nameset ~)
10524+ =/ components=icomponents (graph-components ds names)
10525+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10526+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
10527+ |-
10528+ =/ next=[env=ienv artifacts=(list iwidth-definition)]
10529+ (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)
10530+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10531+ =. grec-index.initial index
10532+ =/ out=iresolved (add-groups ds components graph env.next grouped artifacts.next initial)
10533+ ?: =(env env.out) out
10534+ $(env env.out, grouped grouped.out, artifacts artifacts.out)
728810535::
728910536++ resolve-supported-defs
729010537 |= [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)]
729110538 ^- ienv
7292− =/ env=ienv ~
10539+ env:(resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
10540+::
10541+:: A diagnostic-only proof for a narrow syntactic value cycle. Every
10542+:: edge is an unqualified wing in a supported expression, and samples
10543+:: may not shadow global bindings. Unknown forms yield no conclusion.
10544++$ icyclesite [name=term at=span]
10545++$ icycle [name=term first=span next=span]
10546+++ cycle-sites-list
10547+ |= [xs=(list expr) globals=(list term) locals=(list term)]
10548+ ^- (unit (list icyclesite))
10549+ ?~ xs `~
10550+ =/ first=(unit (list icyclesite)) (cycle-sites i.xs globals locals)
10551+ ?~ first ~
10552+ =/ tail=(unit (list icyclesite)) $(xs t.xs)
10553+ ?~ tail ~
10554+ `(weld u.first u.tail)
10555+::
10556+++ cycle-sample-name
10557+ |= [sam=sample globals=(list term) locals=(list term)]
10558+ ^- (unit (unit term))
10559+ ?- -.sam
10560+ %bind
10561+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10562+ ``name.sam
10563+ %face
10564+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10565+ ``name.sam
10566+ %bare `~
10567+ * ~
10568+ ==
10569+::
10570+++ cycle-sites
10571+ |= [e=expr globals=(list term) locals=(list term)]
10572+ ^- (unit (list icyclesite))
10573+ ?- -.e
10574+ %wing
10575+ ?. ?=([@ ~] names.e) ~
10576+ `~[[i.names.e at.e]]
10577+ %lit `~
10578+ %str
10579+ ?: (lien pieces.e |=(p=piece ?=(%expr -.p))) ~
10580+ `~
10581+ %group $(e inner.e)
10582+ %body ?~(defs.e $(e final.e) ~)
10583+ %cast $(e val.e)
10584+ %gate
10585+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10586+ ?~ binder ~
10587+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10588+ $(e body.e, locals nested)
10589+ %gate-wide
10590+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10591+ ?~ binder ~
10592+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10593+ $(e body.e, locals nested)
10594+ %call
10595+ =/ first=(unit (list icyclesite)) $(e head.e)
10596+ ?~ first ~
10597+ =/ tail=(unit (list icyclesite)) (cycle-sites-list args.e globals locals)
10598+ ?~ tail ~
10599+ `(weld u.first u.tail)
10600+ * ~
10601+ ==
10602+::
10603+++ cycle-definitely-atom
10604+ |= e=expr
10605+ ^- ?
10606+ ?: ?=(%group -.e) $(e inner.e)
10607+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
10608+ ?. ?=(%cast -.e) |
10609+ |(?=(%aura -.shape.e) ?=(%flag -.shape.e))
10610+::
10611+++ cycle-proof-group
10612+ |= [members=(list def) globals=(list term)]
10613+ ^- ?
10614+ ?~ members &
10615+ ?. ?=(%value -.i.members) |
10616+ ?. (unique-value-name name.i.members globals) |
10617+ ?. ?=(^ (cycle-sites val.i.members globals ~)) |
10618+ $(members t.members)
10619+::
10620+++ cycle-find-site
10621+ |= [sites=(list icyclesite) component=(list term)]
10622+ ^- (unit span)
10623+ ?~ sites ~
10624+ ?: (lien component |=(n=term =(n name.i.sites))) `at.i.sites
10625+ $(sites t.sites)
10626+::
10627+++ cycle-group-errors
10628+ |= [members=(list def) component=(list term) globals=(list term)]
10629+ ^- (list icycle)
10630+ ?~ members ~
10631+ =/ d=def i.members
10632+ ?> ?=(%value -.d)
10633+ =/ tail=(list icycle) $(members t.members)
10634+ ?. (cycle-definitely-atom val.d) tail
10635+ =/ sites=(unit (list icyclesite)) (cycle-sites val.d globals ~)
10636+ ?~ sites tail
10637+ =/ found=(unit span) (cycle-find-site u.sites component)
10638+ ?~ found tail
10639+ [[name.d at.d u.found] tail]
10640+::
10641+++ definite-value-cycles
10642+ |= [ds=(list def) globals=(list term)]
10643+ ^- (list icycle)
10644+ =/ names=(list term) (global-value-names ds)
10645+ =/ graph=iadj (graph-make-forward ds (graph-nameset names ~) ~)
10646+ =/ components=icomponents (graph-components ds names)
10647+ =/ out=(list icycle) ~
729310648 |-
7294− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
7295− ?: =(next env) env
7296− $(env next)
10649+ ?~ components out
10650+ =/ component=(list term) i.components
10651+ ?. (graph-cycle component graph) $(components t.components)
10652+ =/ members=(list def)
10653+ (skim ds |=(d=def &(?=(%value -.d) (lien component |=(n=term =(n name.d))))))
10654+ ?. =((lent members) (lent component)) $(components t.components)
10655+ ?. (cycle-proof-group members globals) $(components t.components)
10656+ $(components t.components, out (weld (cycle-group-errors members component globals) out))
729710657::
729810658+| %union-analysis
729910659::
@@ -7417,6 +10777,257 @@
741710777 %overlap
741810778 %unknown
741910779::
10780+:: A source-only fallback for literal-tagged cells and one-hop local
10781+:: generic applications. It screens all work before ordinary inference.
10782+++ union-simple-shape-budget
10783+ |= [s=shape fuel=@ud vars=(unit (list @t))]
10784+ ^- (unit @ud)
10785+ ?: =(0 fuel) ~
10786+ =. fuel (dec fuel)
10787+ ?- -.s
10788+ ?(%aura %noun %void %flag) `fuel
10789+ %tvar
10790+ ?~ vars `fuel
10791+ ?:((lien u.vars |=(n=@t =(n name.s))) `fuel ~)
10792+ %const
10793+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10794+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10795+ `fuel
10796+ %cell (union-simple-fields-budget fields.s fuel vars)
10797+ %fn
10798+ =/ left=(unit @ud) $(s sample.s, fuel fuel)
10799+ ?~ left ~
10800+ $(s product.s, fuel u.left)
10801+ * ~
10802+ ==
10803+++ union-simple-fields-budget
10804+ |= [fields=(list field) fuel=@ud vars=(unit (list @t))]
10805+ ^- (unit @ud)
10806+ ?~ fields `fuel
10807+ ?: =(0 fuel) ~
10808+ =/ field-shape=shape
10809+ ?- -.i.fields
10810+ %bare shape.i.fields
10811+ %face shape.i.fields
10812+ %pun [%ref at.i.fields ~[name.i.fields]]
10813+ ==
10814+ =/ head=(unit @ud) (union-simple-shape-budget field-shape (dec fuel) vars)
10815+ ?~ head ~
10816+ $(fields t.fields, fuel u.head)
10817+++ union-source-find
10818+ |= [n=term molds=imolds fuel=@ud]
10819+ ^- (unit [body=shape left=@ud])
10820+ =/ found=(unit shape) ~
10821+ |-
10822+ ?~ molds
10823+ ?~ found ~
10824+ `[u.found fuel]
10825+ ?: =(0 fuel) ~
10826+ ?: =(n name.i.molds)
10827+ ?^ found ~
10828+ $(molds t.molds, fuel (dec fuel), found `body.i.molds)
10829+ $(molds t.molds, fuel (dec fuel))
10830+++ union-source-args-budget
10831+ |= [vars=(list @t) args=(list shape) fuel=@ud]
10832+ ^- (unit @ud)
10833+ =/ seen=(set @t) *(set @t)
10834+ |-
10835+ ?~ vars ?~(args `fuel ~)
10836+ ?~ args ~
10837+ ?: =(0 fuel) ~
10838+ ?: (~(has in:..zuse seen) i.vars) ~
10839+ =/ arg=(unit @ud) (union-simple-shape-budget i.args (dec fuel) ~)
10840+ ?~ arg ~
10841+ $(vars t.vars, args t.args, fuel u.arg, seen (~(put in:..zuse seen) i.vars))
10842+++ union-source-cell-tag
10843+ |= s=shape
10844+ ^- (unit @)
10845+ ?. ?=(%cell -.s) ~
10846+ ?~ fields.s ~
10847+ ?~ t.fields.s ~
10848+ ?. ?=(%bare -.i.fields.s) ~
10849+ =/ head=shape shape.i.fields.s
10850+ ?. ?=(%const -.head) ~
10851+ ?. |(=(%term form.lit.head) =(%null form.lit.head) =(%loobean form.lit.head)) ~
10852+ ?: &(=(%loobean form.lit.head) !|(=(0 val.lit.head) =(1 val.lit.head))) ~
10853+ `val.lit.head
10854+++ union-source-case-tag
10855+ |= [s=shape molds=imolds fuel=@ud]
10856+ ^- (unit [tag=@ left=@ud])
10857+ ?: ?=(%cell -.s)
10858+ =/ tag=(unit @) (union-source-cell-tag s)
10859+ ?~ tag ~
10860+ =/ left=(unit @ud) (union-simple-shape-budget s fuel ~)
10861+ ?~ left ~
10862+ `[u.tag u.left]
10863+ ?. ?=(%apply -.s) ~
10864+ ?. ?=([@ ~] ref.s) ~
10865+ ?: =(0 fuel) ~
10866+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10867+ ?~ found ~
10868+ ?. ?=(%generic -.body.u.found) ~
10869+ ?~ vars.body.u.found ~
10870+ =/ tag=(unit @) (union-source-cell-tag body.body.u.found)
10871+ ?~ tag ~
10872+ =/ args=(unit @ud) (union-source-args-budget vars.body.u.found args.s left.u.found)
10873+ ?~ args ~
10874+ =/ left=(unit @ud) (union-simple-shape-budget body.body.u.found u.args `vars.body.u.found)
10875+ ?~ left ~
10876+ `[u.tag u.left]
10877+++ union-source-distinct-tags
10878+ |= [cases=(list shape) molds=imolds fuel=@ud]
10879+ ^- ?
10880+ =/ seen=(set @) *(set @)
10881+ =/ has-application=? |
10882+ |-
10883+ ?~ cases has-application
10884+ ?: =(0 fuel) |
10885+ =/ item=(unit [tag=@ left=@ud]) (union-source-case-tag i.cases molds (dec fuel))
10886+ ?~ item |
10887+ ?: (~(has in:..zuse seen) tag.u.item) |
10888+ $(cases t.cases, fuel left.u.item, seen (~(put in:..zuse seen) tag.u.item), has-application |(has-application ?=(%apply -.i.cases)))
10889+::
10890+:: This inference-only screen bounds inherited work that the small source
10891+:: slice may consult. It does not authenticate a caller-created state.
10892+++ union-state-leaf
10893+ |= t=itype
10894+ ^- ?
10895+ ?=(?(%var %fvar %avar %rvar %nvar %rnvar %atom %any-atom %flag %noun %empty %const) -.t)
10896+++ union-state-params-budget
10897+ |= [params=iparams fuel=@ud]
10898+ ^- (unit @ud)
10899+ ?~ params `fuel
10900+ ?: =(0 fuel) ~
10901+ ?. (union-state-leaf typ.i.params) ~
10902+ $(params t.params, fuel (dec fuel))
10903+++ union-state-sub-budget
10904+ |= [sub=isub fuel=@ud]
10905+ ^- (unit @ud)
10906+ ?~ sub `fuel
10907+ ?: =(0 fuel) ~
10908+ ?. (union-state-leaf val.i.sub) ~
10909+ $(sub t.sub, fuel (dec fuel))
10910+++ union-state-caps-budget
10911+ |= [caps=icaps fuel=@ud]
10912+ ^- (unit @ud)
10913+ ?~ caps `fuel
10914+ ?: =(0 fuel) ~
10915+ $(caps t.caps, fuel (dec fuel))
10916+++ union-state-active-budget
10917+ |= [active=(list term) fuel=@ud]
10918+ ^- (unit @ud)
10919+ ?~ active `fuel
10920+ ?: =(0 fuel) ~
10921+ $(active t.active, fuel (dec fuel))
10922+++ union-state-tags-budget
10923+ |= [tags=(list ipending) fuel=@ud]
10924+ ^- (unit @ud)
10925+ ?~ tags `fuel
10926+ ?: =(0 fuel) ~
10927+ $(tags t.tags, fuel (dec fuel))
10928+++ union-source-state-safe
10929+ |= [state=istate fuel=@ud]
10930+ ^- ?
10931+ ?^ grec-index.state |
10932+ ?^ holes.state |
10933+ ?^ defer.state |
10934+ ?^ obligations.state |
10935+ =/ params=(unit @ud) (union-state-params-budget params.state fuel)
10936+ ?~ params |
10937+ =/ sub=(unit @ud) (union-state-sub-budget sub.state u.params)
10938+ ?~ sub |
10939+ =/ caps=(unit @ud) (union-state-caps-budget caps.state u.sub)
10940+ ?~ caps |
10941+ =/ active=(unit @ud) (union-state-active-budget active.state u.caps)
10942+ ?~ active |
10943+ ?=(^ (union-state-tags-budget tags.state u.active))
10944+::
10945+:: Positive overlap witnesses from parsed, one-hop local source only.
10946+:: Unknown or exhausted work returns no witness, never disjointness.
10947++$ uow-case [at=span head=@ payload=upat]
10948+++ union-overlap-primitive
10949+ |= s=shape
10950+ ^- (unit upat)
10951+ ?- -.s
10952+ %aura `[%atom ~]
10953+ %noun `[%all ~]
10954+ %void `[%empty ~]
10955+ %flag `[%flag ~]
10956+ %const
10957+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10958+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10959+ `[%atom `val.lit.s]
10960+ * ~
10961+ ==
10962+++ union-overlap-case
10963+ |= [s=shape molds=imolds fuel=@ud]
10964+ ^- (unit [item=uow-case left=@ud])
10965+ ?: =(0 fuel) ~
10966+ =. fuel (dec fuel)
10967+ :: Each body has exactly two fields; an application has exactly one
10968+ :: parameter and one concrete primitive argument. The full mold table
10969+ :: is scanned to establish unique ownership.
10970+ =/ expanded=(unit [body=shape param=(unit [name=@t pat=upat]) left=@ud])
10971+ ?: ?=(%cell -.s) `[s ~ fuel]
10972+ ?. ?=(%apply -.s) ~
10973+ ?. ?=([@ ~] ref.s) ~
10974+ ?. ?=([* ~] args.s) ~
10975+ ?: =(0 fuel) ~
10976+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10977+ ?~ found ~
10978+ ?. ?=(%generic -.body.u.found) ~
10979+ ?. ?=([@ ~] vars.body.u.found) ~
10980+ ?: =(0 left.u.found) ~
10981+ =/ argument=(unit upat) (union-overlap-primitive i.args.s)
10982+ ?~ argument ~
10983+ `[body.body.u.found `[i.vars.body.u.found u.argument] (dec left.u.found)]
10984+ ?~ expanded ~
10985+ =/ body=shape body.u.expanded
10986+ ?. ?=(%cell -.body) ~
10987+ ?. ?=([* * ~] fields.body) ~
10988+ :: Charge the cell, two fields, and the head and payload nodes.
10989+ ?: (lth left.u.expanded 5) ~
10990+ =/ head=(unit @) (union-source-cell-tag body)
10991+ ?~ head ~
10992+ =/ field=field i.t.fields.body
10993+ =/ payload=shape
10994+ ?- -.field
10995+ %bare shape.field
10996+ %face shape.field
10997+ %pun [%ref at.field ~[name.field]]
10998+ ==
10999+ =/ pattern=(unit upat)
11000+ ?: ?=(%tvar -.payload)
11001+ ?~ param.u.expanded ~
11002+ ?. =(name.payload name.u.param.u.expanded) ~
11003+ `pat.u.param.u.expanded
11004+ (union-overlap-primitive payload)
11005+ ?~ pattern ~
11006+ `[[at.s u.head u.pattern] (sub left.u.expanded 5)]
11007+++ union-overlap-against
11008+ |= [first=uow-case rest=(list shape) molds=imolds fuel=@ud]
11009+ ^- (unit [witness=(unit upair) left=@ud])
11010+ ?~ rest `[~ fuel]
11011+ ?: =(0 fuel) ~
11012+ =/ other=(unit [item=uow-case left=@ud]) (union-overlap-case i.rest molds (dec fuel))
11013+ ?~ other ~
11014+ ?: &(=(head.first head.item.u.other) =(%overlap (union-relate payload.first payload.item.u.other)))
11015+ `[`[at.first at.item.u.other %overlap] left.u.other]
11016+ $(rest t.rest, fuel left.u.other)
11017+++ union-source-overlap
11018+ |= [cases=(list shape) molds=imolds fuel=@ud]
11019+ ^- (unit upair)
11020+ ?~ cases ~
11021+ ?~ t.cases ~
11022+ ?: =(0 fuel) ~
11023+ =/ first=(unit [item=uow-case left=@ud]) (union-overlap-case i.cases molds (dec fuel))
11024+ ?~ first ~
11025+ =/ found=(unit [witness=(unit upair) left=@ud])
11026+ (union-overlap-against item.u.first t.cases molds left.u.first)
11027+ ?~ found ~
11028+ ?^ witness.u.found witness.u.found
11029+ $(cases t.cases, fuel left.u.found)
11030+::
742011031++ union-pairs
742111032 |= [cases=(list shape) molds=imolds]
742211033 ^- (list upair)
@@ -7430,15 +11041,151 @@
743011041 [at.first at.second (union-relate a (project-union-mold second molds ~))]
743111042 (weld pairs $(cases t.cases))
743211043::
11044+:: A closed structural mold supplies no equation to determine a hole.
11045+:: Applications, references, unbound capitals and unions are unproved.
11046+++ simple-mold-hole
11047+ |= sh=shape
11048+ ^- (unit (unit span))
11049+ ?: ?=(%generic -.sh)
11050+ ?~ vars.sh ~
11051+ ?. (distinct-params vars.sh) ~
11052+ (simple-mold-hole-in body.sh vars.sh)
11053+ (simple-mold-hole-in sh ~)
11054+++ simple-mold-hole-in
11055+ |= [sh=shape vars=(list @t)]
11056+ ^- (unit (unit span))
11057+ ?- -.sh
11058+ %hole ``at.sh
11059+ ?(%aura %noun %void %flag %const) `~
11060+ %tvar ?:((lien vars |=(v=@t =(v name.sh))) `~ ~)
11061+ %cell (simple-mold-field-holes fields.sh vars)
11062+ %fn
11063+ =/ a=(unit (unit span)) $(sh sample.sh)
11064+ ?~ a ~
11065+ =/ b=(unit (unit span)) $(sh product.sh)
11066+ ?~ b ~
11067+ `?~(u.a u.b u.a)
11068+ %generic ~
11069+ * ~
11070+ ==
11071+++ simple-mold-field-holes
11072+ |= [fields=(list field) vars=(list @t)]
11073+ ^- (unit (unit span))
11074+ ?~ fields `~
11075+ =/ f=field i.fields
11076+ =/ first=(unit (unit span))
11077+ ?- -.f
11078+ %face (simple-mold-hole-in shape.f vars)
11079+ %bare (simple-mold-hole-in shape.f vars)
11080+ %pun ~
11081+ ==
11082+ ?~ first ~
11083+ =/ rest=(unit (unit span)) $(fields t.fields)
11084+ ?~ rest ~
11085+ `?~(u.first u.rest u.first)
11086+++ simple-local-mold-hole
11087+ |= defs=(list def)
11088+ ^- (unit span)
11089+ ?~ defs ~
11090+ ?. ?=(%mold -.i.defs) $(defs t.defs)
11091+ =/ found=(unit (unit span)) (simple-mold-hole shape.i.defs)
11092+ ?~ found $(defs t.defs)
11093+ ?^ u.found u.found
11094+ $(defs t.defs)
11095+::
11096+:: A partial prelude may omit unsupported declarations, but may not
11097+:: publish an interface while a named mold's hole remains unchecked.
11098+++ shape-has-hole
11099+ |= sh=shape
11100+ ^- ?
11101+ ?- -.sh
11102+ %hole &
11103+ %path (lien segs.sh |=(s=pseg ?=(%inferred -.s)))
11104+ %apply (lien args.sh shape-has-hole)
11105+ %union (lien cases.sh shape-has-hole)
11106+ %cell (lien fields.sh field-has-hole)
11107+ %fn |($(sh sample.sh) $(sh product.sh))
11108+ %generic $(sh body.sh)
11109+ * |
11110+ ==
11111+++ field-has-hole
11112+ |= f=field
11113+ ^- ?
11114+ ?- -.f
11115+ %face (shape-has-hole shape.f)
11116+ %bare (shape-has-hole shape.f)
11117+ %pun |
11118+ ==
11119+++ named-mold-has-hole
11120+ |= ds=(list def)
11121+ ^- ?
11122+ ?~ ds |
11123+ ?: &(?=(%mold -.i.ds) (shape-has-hole shape.i.ds)) &
11124+ $(ds t.ds)
11125+::
11126+++ sample-has-hole
11127+ |= sam=sample
11128+ ^- ?
11129+ ?- -.sam
11130+ %face (shape-has-hole shape.sam)
11131+ %bare (shape-has-hole shape.sam)
11132+ %cell (lien items.sam sample-has-hole)
11133+ * |
11134+ ==
11135+++ def-has-hole
11136+ |= d=def
11137+ ^- ?
11138+ ?- -.d
11139+ %mold (shape-has-hole shape.d)
11140+ %value (expr-has-hole val.d)
11141+ ==
11142+++ expr-has-hole
11143+ |= e=expr
11144+ ^- ?
11145+ ?- -.e
11146+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
11147+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
11148+ %change (lien edits.e |=(p=edit (expr-has-hole val.p)))
11149+ %pair $(e val.e)
11150+ %unit $(e val.e)
11151+ %group $(e inner.e)
11152+ %list (lien items.e expr-has-hole)
11153+ %tuple (lien items.e |=(i=item (expr-has-hole val.i)))
11154+ ?(%gate %gate-wide) |((sample-has-hole sample.e) $(e body.e))
11155+ %cast |((shape-has-hole shape.e) $(e val.e))
11156+ %call |($(e head.e) (lien args.e expr-has-hole))
11157+ %trace |($(e val.e) $(e then.e))
11158+ %branch |($(e subject.e) (lien arms.e |=(a=arm (expr-has-hole val.a))))
11159+ %body |((lien defs.e def-has-hole) $(e final.e))
11160+ * |
11161+ ==
11162+++ hole-values-present
11163+ |= [ds=(list def) env=ienv]
11164+ ^- ?
11165+ ?~ ds &
11166+ ?. ?=(%value -.i.ds) $(ds t.ds)
11167+ ?: (expr-has-hole val.i.ds)
11168+ ?. ?=(^ (ienv-lookup name.i.ds env)) |
11169+ $(ds t.ds)
11170+ $(ds t.ds)
743311171++ show-partial-mold
743411172 |= [file=path src=@t d=def molds=imolds]
743511173 ^- @t
743611174 ?> ?=(%mold -.d)
743711175 =/ sh=shape shape.d
11176+ =/ hole=(unit (unit span)) (simple-mold-hole sh)
11177+ ?: &(?=(^ hole) ?=(^ u.hole))
11178+ =/ text=@t (show-error src [file line.beg.u.u.hole col.beg.u.u.hole "unresolved type hole"])
11179+ (of-wain:format ~[(crip "+$ {(trip name.d)}: type hole needs a determined type") text])
743811180 =? sh ?=(%generic -.sh) body.sh
743911181 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
744011182 =/ pairs=(list upair) (union-pairs cases.sh molds)
744111183 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
11184+ =. overlapping
11185+ ?^ overlapping overlapping
11186+ ?. (lien pairs |=(p=upair =(%unknown relation.p))) ~
11187+ =/ witness=(unit upair) (union-source-overlap cases.sh molds 256)
11188+ ?~(witness ~ ~[u.witness])
744211189 ?^ overlapping
744311190 =/ p=upair i.overlapping
744411191 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
@@ -7446,7 +11193,9 @@
744611193 =/ second=@t (show-error src [file line.beg.second.p col.beg.second.p "overlapping case"])
744711194 (of-wain:format ~[summary first second])
744811195 ?: (lien pairs |=(p=upair =(%unknown relation.p)))
7449− (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
11196+ ?. (union-source-distinct-tags cases.sh molds 256)
11197+ (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
11198+ (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
745011199 (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
745111200::
745211201:: +show-inference-diagnostic: a partial report with both source sites
@@ -7461,8 +11210,23 @@
746111210 (show-error src [file line.beg.at.site col.beg.at.site note.site])
746211211 (of-wain:format [summary excerpts])
746311212::
7464−:: +golden-types: a partial report; it does not claim the module checks
7465−::
11213+:: Both written field sites are shown in the source that declares them.
11214+++ show-duplicate-fields
11215+ |= [file=path src=@t diagnostic=idiag]
11216+ ^- @t
11217+ =/ excerpts=(list @t)
11218+ %+ turn sites.diagnostic
11219+ |= site=[at=span note=tape]
11220+ (show-error src [file line.beg.at.site col.beg.at.site note.site])
11221+ (of-wain:format [(crip msg.diagnostic) excerpts])
11222+::
11223+++ duplicate-fields-report
11224+ |= [file=path src=@t diagnostic=idiag]
11225+ ^- @t
11226+ (of-wain:format ~['partial inference; module not checked' (show-duplicate-fields file src diagnostic)])
11227+::
11228+:: +golden-types: a partial report; it does not claim the module checks
11229+::
746611230++ golden-types
746711231 |= [file=path src=@t]
746811232 ^- @t
@@ -7488,8 +11252,189 @@
748811252+$ jbundle (list jsource)
748911253+$ jcache (list [at=path iface=ifile])
749011254+$ jfile-result (each [iface=ifile cache=jcache] @t)
11255+:: Overlap evidence retains the exact source that supplied its spans.
11256+:: Ordinary Jibb imports preserve this evidence through the resolver.
11257++$ jfile-overlap [file=path source=@t name=term cases=upair]
11258++$ jfile-failure [message=@t overlap=(unit jfile-overlap)]
11259++$ jfile-detailed-result (each [iface=ifile cache=jcache] jfile-failure)
749111260+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
11261+:: Preserve an imported overlap's original file and source across the graph.
11262++$ jimports-detailed-result (each [resolved=ijimports cache=jcache] jfile-failure)
749211263::
11264+:: Written record fields each have their own lexical record scope.
11265++$ written-fields (map term span)
11266+++ duplicate-written-field
11267+ |= [name=term at=span seen=written-fields]
11268+ ^- (unit idiag)
11269+ =/ prior=(unit span) (~(get by seen) name)
11270+ ?~ prior ~
11271+ `["record field `{(trip name)}` is repeated" ~[[u.prior "first field"] [at "repeated field"]]]
11272+++ duplicate-shapes
11273+ |= xs=(list shape)
11274+ ^- (unit idiag)
11275+ ?~ xs ~
11276+ =/ first (duplicate-shape i.xs)
11277+ ?^ first first
11278+ $(xs t.xs)
11279+++ duplicate-fields
11280+ |= [fields=(list field) seen=written-fields]
11281+ ^- (unit idiag)
11282+ ?~ fields ~
11283+ =/ f=field i.fields
11284+ =/ n=(unit term)
11285+ ?- -.f
11286+ %face `name.f
11287+ %pun `name.f
11288+ %bare ~
11289+ ==
11290+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.f seen))
11291+ ?^ dup dup
11292+ =/ inner=(unit idiag)
11293+ ?- -.f
11294+ %face (duplicate-shape shape.f)
11295+ %pun ~
11296+ %bare (duplicate-shape shape.f)
11297+ ==
11298+ ?^ inner inner
11299+ $(fields t.fields, seen ?~(n seen (~(put by seen) u.n at.f)))
11300+++ duplicate-shape
11301+ |= s=shape
11302+ ^- (unit idiag)
11303+ ?- -.s
11304+ %cell (duplicate-fields fields.s ~)
11305+ %apply (duplicate-shapes args.s)
11306+ %union (duplicate-shapes cases.s)
11307+ %fn
11308+ =/ left (duplicate-shape sample.s)
11309+ ?^ left left
11310+ (duplicate-shape product.s)
11311+ %generic (duplicate-shape body.s)
11312+ * ~
11313+ ==
11314+++ duplicate-samples
11315+ |= [items=(list sample) seen=written-fields]
11316+ ^- (unit idiag)
11317+ ?~ items ~
11318+ =/ a=sample i.items
11319+ =/ n=(unit term)
11320+ ?- -.a
11321+ %bind `name.a
11322+ %face `name.a
11323+ %pun `name.a
11324+ * ~
11325+ ==
11326+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.a seen))
11327+ ?^ dup dup
11328+ =/ inner (duplicate-sample a)
11329+ ?^ inner inner
11330+ $(items t.items, seen ?~(n seen (~(put by seen) u.n at.a)))
11331+++ duplicate-sample
11332+ |= s=sample
11333+ ^- (unit idiag)
11334+ ?- -.s
11335+ %cell (duplicate-samples items.s ~)
11336+ %face (duplicate-shape shape.s)
11337+ %bare (duplicate-shape shape.s)
11338+ * ~
11339+ ==
11340+++ duplicate-exprs
11341+ |= xs=(list expr)
11342+ ^- (unit idiag)
11343+ ?~ xs ~
11344+ =/ first (duplicate-expr i.xs)
11345+ ?^ first first
11346+ $(xs t.xs)
11347+++ duplicate-items
11348+ |= [items=(list item) seen=written-fields]
11349+ ^- (unit idiag)
11350+ ?~ items ~
11351+ =/ a=item i.items
11352+ =/ dup=(unit idiag) ?~(face.a ~ (duplicate-written-field u.face.a at.a seen))
11353+ ?^ dup dup
11354+ =/ inner (duplicate-expr val.a)
11355+ ?^ inner inner
11356+ $(items t.items, seen ?~(face.a seen (~(put by seen) u.face.a at.a)))
11357+++ duplicate-pieces
11358+ |= pieces=(list piece)
11359+ ^- (unit idiag)
11360+ ?~ pieces ~
11361+ =/ first=(unit idiag) ?:(?=(%expr -.i.pieces) (duplicate-expr p.i.pieces) ~)
11362+ ?^ first first
11363+ $(pieces t.pieces)
11364+++ duplicate-qsegs
11365+ |= segs=(list qseg)
11366+ ^- (unit idiag)
11367+ ?~ segs ~
11368+ =/ first=(unit idiag) ?:(?=(%expr -.i.segs) (duplicate-expr p.i.segs) ~)
11369+ ?^ first first
11370+ $(segs t.segs)
11371+++ duplicate-edits
11372+ |= edits=(list edit)
11373+ ^- (unit idiag)
11374+ ?~ edits ~
11375+ =/ first (duplicate-expr val.i.edits)
11376+ ?^ first first
11377+ $(edits t.edits)
11378+++ duplicate-arms
11379+ |= arms=(list arm)
11380+ ^- (unit idiag)
11381+ ?~ arms ~
11382+ =/ first (duplicate-expr val.i.arms)
11383+ ?^ first first
11384+ $(arms t.arms)
11385+++ duplicate-defs
11386+ |= defs=(list def)
11387+ ^- (unit idiag)
11388+ ?~ defs ~
11389+ =/ first=(unit idiag)
11390+ ?- -.i.defs
11391+ %mold (duplicate-shape shape.i.defs)
11392+ %value (duplicate-expr val.i.defs)
11393+ ==
11394+ ?^ first first
11395+ $(defs t.defs)
11396+++ duplicate-expr
11397+ |= e=expr
11398+ ^- (unit idiag)
11399+ ?- -.e
11400+ %str (duplicate-pieces pieces.e)
11401+ %qath (duplicate-qsegs segs.e)
11402+ %change (duplicate-edits edits.e)
11403+ %pair (duplicate-expr val.e)
11404+ %unit (duplicate-expr val.e)
11405+ %group (duplicate-expr inner.e)
11406+ %list (duplicate-exprs items.e)
11407+ %tuple (duplicate-items items.e ~)
11408+ %gate-wide
11409+ =/ first (duplicate-sample sample.e)
11410+ ?^ first first
11411+ (duplicate-expr body.e)
11412+ %gate
11413+ =/ first (duplicate-sample sample.e)
11414+ ?^ first first
11415+ (duplicate-expr body.e)
11416+ %cast
11417+ =/ first (duplicate-shape shape.e)
11418+ ?^ first first
11419+ (duplicate-expr val.e)
11420+ %call
11421+ =/ first (duplicate-expr head.e)
11422+ ?^ first first
11423+ (duplicate-exprs args.e)
11424+ %trace
11425+ =/ first (duplicate-expr val.e)
11426+ ?^ first first
11427+ (duplicate-expr then.e)
11428+ %branch
11429+ =/ first (duplicate-expr subject.e)
11430+ ?^ first first
11431+ (duplicate-arms arms.e)
11432+ %body
11433+ =/ first (duplicate-defs defs.e)
11434+ ?^ first first
11435+ (duplicate-expr final.e)
11436+ * ~
11437+ ==
749311438++ import-binding-names
749411439 |= imports=(list import)
749511440 ^- (list term)
@@ -7502,6 +11447,60 @@
750211447 ==
750311448 [n $(imports t.imports)]
750411449::
11450+++ reserved-proj-sample
11451+ |= sam=sample
11452+ ^- ?
11453+ ?- -.sam
11454+ %bind =(name.sam %proj)
11455+ %face =(name.sam %proj)
11456+ %pun =(name.sam %proj)
11457+ %cell (lien items.sam reserved-proj-sample)
11458+ * |
11459+ ==
11460+++ reserved-proj-pattern
11461+ |= p=pattern
11462+ ^- ?
11463+ ?- -.p
11464+ %bind =(name.p %proj)
11465+ %cell (lien items.p reserved-proj-pattern)
11466+ * |
11467+ ==
11468+++ reserved-proj-def
11469+ |= d=def
11470+ ^- ?
11471+ ?: =(name.d %proj) &
11472+ ?: ?=(%value -.d) (reserved-proj-expr val.d)
11473+ |
11474+++ reserved-proj-expr
11475+ |= e=expr
11476+ ^- ?
11477+ ?- -.e
11478+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11479+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11480+ %change (lien edits.e |=(p=edit (reserved-proj-expr val.p)))
11481+ %pair $(e val.e)
11482+ %unit $(e val.e)
11483+ %group $(e inner.e)
11484+ %list (lien items.e reserved-proj-expr)
11485+ %tuple (lien items.e |=(i=item (reserved-proj-expr val.i)))
11486+ ?(%gate %gate-wide) |((reserved-proj-sample sample.e) $(e body.e))
11487+ %cast $(e val.e)
11488+ %call |($(e head.e) (lien args.e reserved-proj-expr))
11489+ %trace |($(e val.e) $(e then.e))
11490+ %branch |($(e subject.e) (lien arms.e |=(a=arm |((reserved-proj-pattern pat.a) (reserved-proj-expr val.a)))))
11491+ %body |((lien defs.e reserved-proj-def) $(e final.e))
11492+ * |
11493+ ==
11494+::
11495+++ module-has-reserved-proj
11496+ |= mod=module
11497+ ^- ?
11498+ =/ imported=(list term) (import-binding-names imports.mod)
11499+ =/ vals=(list term) (global-value-names defs.mod)
11500+ =/ molds=imolds (collect-simple-molds defs.mod)
11501+ =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11502+ |((lien (weld imported (weld vals mold-names)) |=(n=term =(n %proj))) (lien defs.mod reserved-proj-def))
11503+::
750511504++ module-scope-valid
750611505 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
750711506 ^- ?
@@ -7509,6 +11508,7 @@
750911508 =/ vals=(list term) (global-value-names defs.mod)
751011509 =/ molds=imolds (collect-simple-molds defs.mod)
751111510 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11511+ ?: (module-has-reserved-proj mod) |
751211512 ?. %+ levy imported
751311513 |= n=term
751411514 &((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))))
@@ -7516,6 +11516,43 @@
751611516 ?. (levy vals |=(n=term &((unique-value-name n vals) !(lien prelude-values |=(v=term =(n v)))))) |
751711517 (levy mold-names |=(n=term &((unique-value-name n mold-names) !(lien prelude-molds |=(m=term =(n m))))))
751811518::
11519+:: A detailed failure is attached only to the first mold that actually
11520+:: failed in this check, using that module's checked source mold table.
11521++$ imold-failure [message=@t overlap=(unit [name=term cases=upair])]
11522+:: Validate a generic wrapper without an unbounded duplicate-name pass.
11523+++ module-mold-params-valid
11524+ |= [vars=(list @t) seen=(set @t) fuel=@ud]
11525+ ^- ?
11526+ ?~ vars &
11527+ ?: =(0 fuel) |
11528+ ?: (~(has in:..zuse seen) i.vars) |
11529+ $(vars t.vars, seen (~(put in:..zuse seen) i.vars), fuel (dec fuel))
11530+++ module-mold-overlap
11531+ |= [m=[name=term body=shape] molds=imolds]
11532+ ^- (unit upair)
11533+ =/ sh=shape body.m
11534+ =/ valid=?
11535+ ?. ?=(%generic -.sh) &
11536+ ?~ vars.sh |
11537+ (module-mold-params-valid vars.sh *(set @t) 256)
11538+ ?. valid ~
11539+ =? sh ?=(%generic -.sh) body.sh
11540+ ?. ?=(%union -.sh) ~
11541+ (union-source-overlap cases.sh molds 256)
11542+++ module-mold-types-detail
11543+ |= [molds=imolds state=istate]
11544+ ^- (each imold-types imold-failure)
11545+ ?~ molds [%& ~]
11546+ =/ m=[name=term body=shape] i.molds
11547+ =/ t=(unit [template=ischeme state=istate])
11548+ (infer-mold-template body.m state(active [name.m active.state], in-mold &))
11549+ ?~ t
11550+ =/ overlap=(unit upair) (module-mold-overlap m molds.state)
11551+ [%| ['module mold needs unsupported inference' ?~(overlap ~ `[name.m u.overlap])]]
11552+ =. typ.template.u.t (label-direct-union typ.template.u.t body.m name.m state)
11553+ =/ rest=(each imold-types imold-failure) $(molds t.molds)
11554+ ?: ?=(%| -.rest) rest
11555+ [%& [[name.m template.u.t] p.rest]]
751911556++ module-mold-types
752011557 |= [molds=imolds state=istate]
752111558 ^- (each imold-types @t)
@@ -7531,9 +11568,9 @@
753111568::
753211569:: Prepare a provisional interface from the trusted vendored source.
753311570:: Every declared name remains reserved, but only molds and values this
7534−:: fragment can infer are usable. Unsupported bodies are not validated,
7535−:: and imports into the prelude are not supported yet. The fixed origin
7536−:: gives its named unions the same identity in every importing module.
11571+:: fragment can infer are usable. Unsupported bodies are not validated.
11572+:: An optional internal source supplies the prelude's one supported import;
11573+:: clients cannot import that path directly. Named unions retain their origin.
753711574::
753811575:: Recognize only the complete standard prelude list shape. Its recursive
753911576:: tail uses the same parameter and the unqualified list name. The reader
@@ -7573,6 +11610,20 @@
757311610 ?. ?=(%tvar -.i.args.tail) |
757411611 =(var name.i.args.tail)
757511612::
11613+++ prelude-label
11614+ |= [typ=itype name=term vars=(list @ud)]
11615+ ^- itype
11616+ ?: ?=(%jrec -.typ) typ(label `name)
11617+ ?: ?=(%grec -.typ)
11618+ ?. (identity-union-parameters vars args.typ) typ(label ~)
11619+ typ(label `name)
11620+ ?. ?=(%union -.typ) typ
11621+ ?. (identity-union-parameters vars args.typ)
11622+ ?~ origin.typ typ
11623+ ?: =(at.u.origin.typ /lib/jibb/internal/jibb) typ(label ~)
11624+ typ
11625+ typ(label `name)
11626+::
757611627++ partial-prelude-molds
757711628 |= [molds=imolds state=istate]
757811629 ^- imold-types
@@ -7585,22 +11636,131 @@
758511636 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
758611637 ?~ out $(molds t.molds)
758711638 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
11639+ =. typ.template.u.out (prelude-label typ.template.u.out name.m vars.template.u.out)
758811640 [[name.m template.u.out] $(molds t.molds)]
758911641::
7590−++ partial-prelude-interface
7591− |= src=@t
11642+:: A compiler-owned interface available only to the dedicated
11643+:: internal-prelude preparation path, never the ordinary module resolver.
11644+++ private-primitive-interface
11645+ ^- ifile
11646+ =/ a=itype [%avar 0]
11647+ =/ pair=itype [%cell a a]
11648+ =/ b=itype [%rvar 0]
11649+ =/ plus=ischeme [[%fn [%cell b b] b] ~[0]]
11650+ =/ minus=ischeme [[%fn b b] ~[0]]
11651+ =/ greater=ischeme [[%fn pair [%flag ~]] ~[0]]
11652+ =/ free=itype [%fvar 0]
11653+ =/ equal=ischeme [[%fn [%cell free free] [%flag ~]] ~[0]]
11654+ =/ utf8=itype [%atom 'tD']
11655+ =/ tape=itype [%collection %list ~[utf8]]
11656+ =/ codepoints=itype [%collection %list ~[[%atom %c]]]
11657+ =/ text-trip=ischeme [[%fn [%atom %t] tape] ~]
11658+ =/ text-tuba=ischeme [[%fn tape codepoints] ~]
11659+ [~[[%raw-add plus] [%raw-dec minus] [%raw-gth greater] [%raw-eq equal] [%raw-trip text-trip] [%raw-tuba text-tuba]] ~ /lib/jibb/primitives/jibb ~ ~ ~ ~ ~]
11660+::
11661+++ infer-private-internal
11662+ |= [src=@t public-source=@t]
11663+ ^- (unit ifile)
11664+ =/ at=path /lib/jibb/internal/jibb
11665+ =/ parsed (parse at src)
11666+ ?: ?=(%| -.parsed) ~
11667+ =/ mod=module p.parsed
11668+ ?^ (duplicate-defs defs.mod) ~
11669+ ?~ imports.mod
11670+ =/ built=jfile-result (infer-jibb-file at src ~ ~ ~ ~[at] ~ ~ ~ ~)
11671+ ?: ?=(%| -.built) ~
11672+ `iface.p.built
11673+ ?. ?=([[%jibb *] ~] imports.mod) ~
11674+ ?. =(path.i.imports.mod /lib/jibb/primitives) ~
11675+ ?. (module-scope-valid mod ~ ~) ~
11676+ =/ vals=(list term) (global-value-names defs.mod)
11677+ ?: (lien vals |=(n=term =(n %main))) ~
11678+ =/ molds=imolds (collect-simple-molds defs.mod)
11679+ =/ globals=(list term) (weld (import-binding-names imports.mod) vals)
11680+ :: The private source can use the public list and unit molds before the
11681+ :: prelude is otherwise prepared. Re-read the trusted public source here
11682+ :: and admit only its validated canonical templates; do not accept schemes
11683+ :: supplied independently by the caller.
11684+ =/ public=(each module error) (parse /lib/jibb/prelude/jibb public-source)
11685+ ?: ?=(%| -.public) ~
11686+ ?^ (duplicate-defs defs.p.public) ~
11687+ ?. (module-scope-valid p.public ~ ~) ~
11688+ =/ source-molds=imolds (collect-simple-molds defs.p.public)
11689+ =/ written-list=(unit shape) (find-simple-mold %list source-molds)
11690+ =/ source-list=(unit ischeme)
11691+ ?~ written-list ~
11692+ ?. (standard-prelude-list u.written-list) ~
11693+ `[[%collection %list ~[[%var 0]]] ~[0]]
11694+ :: Derive the public unit template from its actual source, then compare
11695+ :: the complete nominal template before making it available privately.
11696+ =/ unit-decl=(unit shape) (find-simple-mold %unit source-molds)
11697+ =/ source-unit=(unit ischeme)
11698+ ?~ unit-decl ~
11699+ =/ unit-molds=imolds ~[[%unit u.unit-decl]]
11700+ =/ unit-state=istate [0 ~ ~ ~ unit-molds ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | /lib/jibb/prelude/jibb ~[%unit] ~ ~ 256 ~ ~ ~ ~ ~ ~]
11701+ =/ unit-types=imold-types (partial-prelude-molds unit-molds unit-state)
11702+ =/ unit-iface=ifile [~ unit-types /lib/jibb/prelude/jibb ~ ~ ~ ~ ~]
11703+ =/ found=(unit ischeme) (find-jibb-mold %unit unit-iface)
11704+ ?~ found ~
11705+ ?. (standard-unit-template u.found /lib/jibb/prelude/jibb) ~
11706+ found
11707+ =/ primitive=ifile private-primitive-interface
11708+ =? primitive ?=(^ source-list)
11709+ primitive(molds [[%list u.source-list] molds.primitive])
11710+ =? primitive ?=(^ source-unit)
11711+ primitive(molds [[%unit u.source-unit] molds.primitive])
11712+ =/ js=ijimports ~[[face.i.imports.mod primitive]]
11713+ =/ reserved=(list term) ~[face.i.imports.mod]
11714+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11715+ =/ state=istate [0 ~ ~ ~ molds globals ~ ~ ~ ~ js reserved ~ ~ ~ | at top ~ ~ 256 ~ ~ ~ ~ ~ ~]
11716+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11717+ =/ usable=(unit imold-types)
11718+ ?: ?=(%& -.mts) `p.mts
11719+ :: Missing public templates may make an unrelated internal mold
11720+ :: unavailable. Validate all molds once with isolated canonical
11721+ :: templates before admitting only those inferred using the actual
11722+ :: source-backed templates. The proof interface is never exported.
11723+ ?. |(?=(~ source-list) ?=(~ source-unit)) ~
11724+ =/ nil=itype [%const [%null %n 0 '~']]
11725+ =/ canonical-unit=ischeme
11726+ [[%union ~[nil [%cell nil [%face %u [%var 0]]]] `[/lib/jibb/prelude/jibb %unit] `%unit ~[[%var 0]]] ~[0]]
11727+ =/ canonical-list=ischeme [[%collection %list ~[[%var 0]]] ~[0]]
11728+ =/ proof-primitive=ifile private-primitive-interface
11729+ =. molds.proof-primitive ~[[%list canonical-list] [%unit canonical-unit]]
11730+ =/ proof-imports=ijimports ~[[face.i.imports.mod proof-primitive]]
11731+ =/ proof=(each imold-types @t) (module-mold-types molds state(jimports proof-imports))
11732+ ?: ?=(%| -.proof) ~
11733+ `(partial-prelude-molds molds state)
11734+ ?~ usable ~
11735+ =/ resolution=iresolved (resolve-groups defs.mod molds globals ~ ~ ~ ~ js reserved at ~)
11736+ =/ env=ienv env.resolution
11737+ ?. (module-values-complete defs.mod env) ~
11738+ `[env u.usable at ~ artifacts.resolution ~ `src ~]
11739+::
11740+++ partial-prelude-interface-with-internal
11741+ |= [src=@t internal-source=(unit @t)]
759211742 ^- (unit ifile)
759311743 ?: =(0 src) ~
759411744 =/ at=path /lib/jibb/prelude/jibb
759511745 =/ parsed (parse at src)
759611746 ?: ?=(%| -.parsed) ~
7597− ?^ imports.p.parsed ~
11747+ ?: (named-mold-has-hole defs.p.parsed) ~
11748+ ?^ (duplicate-defs defs.p.parsed) ~
11749+ =/ private=(unit ijimports)
11750+ ?~ imports.p.parsed `~
11751+ ?. ?=([[%jibb *] ~] imports.p.parsed) ~
11752+ ?. =(path.i.imports.p.parsed /lib/jibb/internal) ~
11753+ ?~ internal-source ~
11754+ =/ built=(unit ifile) (infer-private-internal u.internal-source src)
11755+ ?~ built ~
11756+ `~[[face.i.imports.p.parsed u.built]]
11757+ ?~ private ~
759811758 ?~ defs.p.parsed ~
759911759 ?. (module-scope-valid p.parsed ~ ~) ~
760011760 =/ ds=(list def) defs.p.parsed
760111761 =/ molds=imolds (collect-simple-molds ds)
760211762 =/ names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7603− =/ globals=(list term) (global-value-names ds)
11763+ =/ globals=(list term) (weld (import-binding-names imports.p.parsed) (global-value-names ds))
760411764 :: Remove raw list before inferring any template, so an altered list
760511765 :: cannot leak through an alias. Its name remains reserved either way.
760611766 =/ declared=? (lien names |=(name=term =(%list name)))
@@ -7608,11 +11768,38 @@
760811768 =? env-molds declared
760911769 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
761011770 =/ reserved=(list term) ?:(declared ~[%list] ~)
7611− =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ ~ reserved ~ ~ ~ | at names ~]
7612− =/ mt=imold-types (partial-prelude-molds molds state)
7613− =/ partial=ifile [~ mt at]
7614− =/ env=ienv (resolve-supported-defs ds env-molds globals ~ ~ ~ ~ ~ reserved at `partial)
7615− `[env mt at]
11771+ =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~ ~ 256 ~ ~ ~ ~ ~ ~]
11772+ :: Other prelude molds may use list only after its source has passed
11773+ :: the standard-list check. The raw declaration remains removed.
11774+ =/ declared-list=(unit shape) (find-simple-mold %list molds)
11775+ =/ mold-prelude=(unit ifile)
11776+ ?~ declared-list ~
11777+ ?. (standard-prelude-list u.declared-list) ~
11778+ `[~ ~[[%list [[%collection %list ~[[%var 0]]] ~[0]]]] at ~ ~ ~ ~ ~]
11779+ =/ mt=imold-types (partial-prelude-molds molds state(prelude mold-prelude))
11780+ =/ partial=ifile [~ mt at ~ ~ ~ ~ ~]
11781+ :: An explicitly qualified re-export must resolve. Other unsupported
11782+ :: prelude declarations remain reserved but absent from the interface.
11783+ =/ required=imolds
11784+ %+ skim molds
11785+ |= m=[name=term body=shape]
11786+ =/ sh=shape body.m
11787+ ?. ?=(%ref -.sh) |
11788+ ?~ names.sh |
11789+ ?=(^ t.names.sh)
11790+ ?. (levy required |=(m=[name=term body=shape] ?=(^ (find-jibb-mold name.m partial)))) ~
11791+ =/ resolution=iresolved (resolve-groups ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
11792+ =/ env=ienv env.resolution
11793+ ?. (hole-values-present ds env) ~
11794+ =/ deps=(list iwidth-dependency)
11795+ ?~ u.private ~
11796+ ~[[at.interface.i.u.private source.interface.i.u.private elaborations.interface.i.u.private]]
11797+ `[env mt at ~ artifacts.resolution deps `src ~]
11798+::
11799+++ partial-prelude-interface
11800+ |= src=@t
11801+ ^- (unit ifile)
11802+ (partial-prelude-interface-with-internal src ~)
761611803::
761711804+$ iprelude [iface=ifile values=(list term) molds=(list term)]
761811805::
@@ -7627,6 +11814,17 @@
762711814 =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
762811815 `[u.iface vals ms]
762911816::
11817+++ prepare-prelude-with-internal
11818+ |= [src=@t internal-source=@t]
11819+ ^- (unit iprelude)
11820+ =/ iface=(unit ifile) (partial-prelude-interface-with-internal src `internal-source)
11821+ ?~ iface ~
11822+ =/ parsed (parse /lib/jibb/prelude/jibb src)
11823+ ?: ?=(%| -.parsed) ~
11824+ =/ vals=(list term) (global-value-names defs.p.parsed)
11825+ =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
11826+ `[u.iface vals ms]
11827+::
763011828++ module-values-complete
763111829 |= [ds=(list def) env=ienv]
763211830 ^- ?
@@ -7647,52 +11845,2675 @@
764711845 ?: =(at at.i.cache) `iface.i.cache
764811846 $(cache t.cache)
764911847::
11848+:: These certificates retain the complete checked source closure. The
11849+:: trusted host must supply the identical prepared prelude and reader nouns.
11850+:: Exact bundle equality binds all source paths and versions; the set
11851+:: retains transitive paths for active-cycle checks. Request-bearing graphs
11852+:: alone have a size limit; incompatible diamond evidence fails closed.
11853+++ request-graph-requests-add
11854+ |= [pending=(list irequest-evidence) acc=(list irequest-evidence) fuel=@ud]
11855+ ^- (unit (list irequest-evidence))
11856+ ?~ pending `acc
11857+ ?: =(0 fuel) ~
11858+ =/ hit=(list irequest-evidence)
11859+ (skim acc |=(x=irequest-evidence &(=(api-at.x api-at.i.pending) =(name.x name.i.pending))))
11860+ ?^ hit
11861+ ?. ?=([* ~] hit) ~
11862+ ?. =(i.hit i.pending) ~
11863+ $(pending t.pending, fuel (dec fuel))
11864+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11865+++ request-graph-inputs-match
11866+ |= [g=irequest-graph externals=iexternals marks=imark-externals modules=jbundle values=(list term) molds=(list term) prelude=(unit ifile)]
11867+ ^- ?
11868+ ?& =(bundle-input.g modules)
11869+ =(prelude-input.g prelude)
11870+ =(prelude-values.g values)
11871+ =(prelude-molds.g molds)
11872+ =(externals.g externals)
11873+ =(marks.g marks)
11874+ ==
11875+++ request-graph-bounded
11876+ |= g=irequest-graph
11877+ ^- ?
11878+ =/ total=@ud (add (lent requests.g) (lent stores.g))
11879+ &((lte (lent ~(tap in:..zuse paths.g)) 256) (lte total 256))
11880+::
11881+++ store-graph-requests-add
11882+ |= [pending=(list istore-request-evidence) acc=(list istore-request-evidence) fuel=@ud]
11883+ ^- (unit (list istore-request-evidence))
11884+ ?~ pending `acc
11885+ ?: =(0 fuel) ~
11886+ =/ hit=(list istore-request-evidence)
11887+ (skim acc |=(x=istore-request-evidence =(store-at.x store-at.i.pending)))
11888+ ?^ hit
11889+ ?. ?=([* ~] hit) ~
11890+ ?. =(i.hit i.pending) ~
11891+ $(pending t.pending, fuel (dec fuel))
11892+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11893+::
11894+++ request-graph-merge
11895+ |= [imports=ijimports g=irequest-graph fuel=@ud]
11896+ ^- (unit irequest-graph)
11897+ ?~ imports `g
11898+ ?: =(0 fuel) ~
11899+ =/ child=ifile interface.i.imports
11900+ ?~ graph.child ~
11901+ =/ cg=irequest-graph u.graph.child
11902+ ?. ?& =(bundle-input.g bundle-input.cg)
11903+ =(prelude-input.g prelude-input.cg)
11904+ =(prelude-values.g prelude-values.cg)
11905+ =(prelude-molds.g prelude-molds.cg)
11906+ =(externals.g externals.cg)
11907+ =(marks.g marks.cg)
11908+ ==
11909+ ~
11910+ =/ merged=(set path) (~(uni in:..zuse paths.g) paths.cg)
11911+ =/ rs=(unit (list irequest-evidence))
11912+ (request-graph-requests-add requests.cg requests.g (add 1 (lent requests.cg)))
11913+ ?~ rs ~
11914+ =/ ss=(unit (list istore-request-evidence))
11915+ (store-graph-requests-add stores.cg stores.g (add 1 (lent stores.cg)))
11916+ ?~ ss ~
11917+ =/ total=@ud (add (lent u.rs) (lent u.ss))
11918+ ?: &(?=(^ u.rs) |((gth (lent ~(tap in:..zuse merged)) 256) (gth total 256))) ~
11919+ ?: &(?=(^ u.ss) |((gth (lent ~(tap in:..zuse merged)) 256) (gth total 256))) ~
11920+ $(imports t.imports, g g(paths merged, requests u.rs, stores u.ss), fuel (dec fuel))
11921+++ request-graph-reusable
11922+ |= [f=ifile src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) values=(list term) molds=(list term) prelude=(unit ifile)]
11923+ ^- ?
11924+ ?~ source.f |
11925+ ?. =(u.source.f src) |
11926+ ?~ graph.f |
11927+ =/ g=irequest-graph u.graph.f
11928+ ?. (request-graph-inputs-match g externals marks modules values molds prelude) |
11929+ ?. (~(has in:..zuse paths.g) at.f) |
11930+ !(lien active |=(p=path (~(has in:..zuse paths.g) p)))
11931+::
765011932++ resolve-jibb-imports
765111933 |= [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)]
765211934 ^- jimports-result
11935+ =/ result=jimports-detailed-result
11936+ (resolve-jibb-imports-detailed imports externals mark-externals modules active prelude-values prelude-molds cache prelude)
11937+ ?: ?=(%| -.result) [%| message.p.result]
11938+ [%& p.result]
11939+++ resolve-jibb-imports-detailed
11940+ |= [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)]
11941+ ^- jimports-detailed-result
765311942 ?~ imports [%& [~ cache]]
765411943 ?. ?=(%jibb -.i.imports) $(imports t.imports)
765511944 =/ at=path (weld path.i.imports `path`~[%jibb])
11945+ ?: =(at /lib/jibb/internal/jibb)
11946+ [%| ['the prelude internal module is private' ~]]
11947+ ?: =(at /lib/jibb/primitives/jibb)
11948+ [%| ['the prelude primitive interface is private' ~]]
765611949 ?: (lien active |=(p=path =(p at)))
7657− [%| (crip "import cycle at {(spud at)}")]
11950+ [%| [(crip "import cycle at {(spud at)}") ~]]
765811951 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
7659− ?~ found [%| (crip "module source missing: {(spud at)}")]
7660− ?^ t.found [%| (crip "duplicate module sources: {(spud at)}")]
11952+ ?~ found [%| [(crip "module source missing: {(spud at)}") ~]]
11953+ ?^ t.found [%| [(crip "duplicate module sources: {(spud at)}") ~]]
766111954 =/ cached=(unit ifile) (find-jibb-cache at cache)
7662− =/ iface=jfile-result
7663− ?^ cached [%& [u.cached cache]]
7664− (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
11955+ =/ iface=jfile-detailed-result
11956+ ?^ cached
11957+ ?. =(at.u.cached at) [%| ['cached module identity needs unsupported inference' ~]]
11958+ ?~ graph.u.cached
11959+ :: A detached legacy interface has unknown evidence. Rebuild it
11960+ :: against the current graph, without retaining any stale entry.
11961+ =/ clean=jcache (skim cache |=(x=[at=path iface=ifile] !=(at.x at)))
11962+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds clean prelude)
11963+ ?. (request-graph-reusable u.cached source.i.found externals mark-externals modules active prelude-values prelude-molds prelude)
11964+ [%| ['cached module evidence needs unsupported inference' ~]]
11965+ [%& [u.cached cache]]
11966+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
766511967 ?: ?=(%| -.iface) [%| p.iface]
7666− =/ rest=jimports-result $(imports t.imports, cache cache.p.iface)
11968+ =/ rest=jimports-detailed-result $(imports t.imports, cache cache.p.iface)
766711969 ?: ?=(%| -.rest) rest
766811970 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
766911971::
11972+:: Provisional declaration extraction only; this does not derive asks,
11973+:: validate imported types, or claim that an API module has checked.
11974++$ iapi-path [at=span name=term segments=(list pseg) full=term diffs=(list term) scry=(unit (list pseg))]
11975+++ api-path-mark
11976+ |= [sh=shape marks=(list term)]
11977+ ^- (unit term)
11978+ ?. ?=(%ref -.sh) ~
11979+ ?. ?=([@ ~] names.sh) ~
11980+ ?. (unique-value-name i.names.sh marks) ~
11981+ `i.names.sh
11982+::
11983+++ api-path-diffs
11984+ |= [shapes=(list shape) marks=(list term) used=(list term)]
11985+ ^- (unit (list term))
11986+ ?~ shapes `~
11987+ =/ n=(unit term) (api-path-mark i.shapes marks)
11988+ ?~ n ~
11989+ ?: (lien used |=(x=term =(x u.n))) ~
11990+ =/ rest=(unit (list term)) $(shapes t.shapes, used [u.n used])
11991+ ?~ rest ~
11992+ `[u.n u.rest]
11993+::
11994+++ api-path-payload
11995+ |= [sh=shape marks=(list term)]
11996+ ^- (unit [full=term diffs=(list term)])
11997+ =/ direct=(unit term) (api-path-mark sh marks)
11998+ ?^ direct `[u.direct ~]
11999+ ?. ?=(%apply -.sh) ~
12000+ ?. =(~[%facts] ref.sh) ~
12001+ ?~ args.sh ~
12002+ ?~ t.args.sh ~
12003+ =/ full=(unit term) (api-path-mark i.args.sh marks)
12004+ ?~ full ~
12005+ =/ diffs=(unit (list term)) (api-path-diffs t.args.sh marks ~[u.full])
12006+ ?~ diffs ~
12007+ `[u.full u.diffs]
12008+::
12009++$ iapi-parameter [name=term aura=@ta at=span]
12010+++ api-path-parameters
12011+ |= [segments=(list pseg) seen=(list term)]
12012+ ^- (unit (list iapi-parameter))
12013+ ?~ segments `~
12014+ ?: ?=(%knot -.i.segments) $(segments t.segments)
12015+ =/ seg=pseg i.segments
12016+ ?. ?=(%typed -.seg) ~
12017+ ?: =(0 aura.seg) ~
12018+ ?: (lien seen |=(n=term =(n name.seg))) ~
12019+ =/ rest=(unit (list iapi-parameter)) $(segments t.segments, seen [name.seg seen])
12020+ ?~ rest ~
12021+ `[[name.seg aura.seg at.seg] u.rest]
12022+::
12023+++ api-scry-parameters-compatible
12024+ |= [scry=(list iapi-parameter) watch=(list iapi-parameter)]
12025+ ^- ?
12026+ ?~ scry &
12027+ ?. (lien watch |=(p=iapi-parameter &(=(name.p name.i.scry) =(aura.p aura.i.scry)))) |
12028+ $(scry t.scry)
12029+::
12030+++ api-path-one
12031+ |= [sh=shape marks=(list term)]
12032+ ^- (unit iapi-path)
12033+ ?. ?=(%cell -.sh) ~
12034+ =/ fs=(list field) fields.sh
12035+ ?~ fs ~
12036+ ?~ t.fs ~
12037+ ?~ t.t.fs ~
12038+ ?: (gth (lent fs) 4) ~
12039+ ?. ?=(%bare -.i.fs) ~
12040+ =/ tag=shape shape.i.fs
12041+ ?. ?=(%const -.tag) ~
12042+ ?. =(%term form.lit.tag) ~
12043+ =/ name=term val.lit.tag
12044+ ?. (jibb-face-name name) ~
12045+ ?. ?=(%bare -.i.t.fs) ~
12046+ =/ path-shape=shape shape.i.t.fs
12047+ ?. ?=(%path -.path-shape) ~
12048+ ?. ?=(%bare -.i.t.t.fs) ~
12049+ =/ payload=(unit [full=term diffs=(list term)]) (api-path-payload shape.i.t.t.fs marks)
12050+ ?~ payload ~
12051+ =/ scry=(unit (unit (list pseg)))
12052+ ?~ t.t.t.fs `~
12053+ =/ entry=field i.t.t.t.fs
12054+ ?. ?=(%face -.entry) ~
12055+ ?. =(%scry name.entry) ~
12056+ ?. ?=(%path -.shape.entry) ~
12057+ ``segs.shape.entry
12058+ ?~ scry ~
12059+ =/ params=(unit (list iapi-parameter)) (api-path-parameters segs.path-shape ~)
12060+ ?~ params ~
12061+ ?^ u.scry
12062+ =/ scry-params=(unit (list iapi-parameter)) (api-path-parameters u.u.scry ~)
12063+ ?~ scry-params ~
12064+ ?. (api-scry-parameters-compatible u.scry-params u.params) ~
12065+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
12066+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
12067+::
12068+++ api-path-many
12069+ |= [shapes=(list shape) marks=(list term) seen=(list term)]
12070+ ^- (unit (list iapi-path))
12071+ ?~ shapes `~
12072+ =/ one=(unit iapi-path) (api-path-one i.shapes marks)
12073+ ?~ one ~
12074+ ?: (lien seen |=(n=term =(n name.u.one))) ~
12075+ =/ rest=(unit (list iapi-path)) $(shapes t.shapes, seen [name.u.one seen])
12076+ ?~ rest ~
12077+ `[u.one u.rest]
12078+::
12079+++ api-path-declaration
12080+ |= [sh=shape marks=(list term)]
12081+ ^- (unit (list iapi-path))
12082+ ?: ?=(%union -.sh) (api-path-many cases.sh marks ~)
12083+ (api-path-many ~[sh] marks ~)
12084+::
12085+:: Derived gates share the value namespace. /% marks name molds; /- and
12086+:: /= also introduce faces that cannot be shadowed by a derived value.
12087+++ api-import-faces
12088+ |= imports=(list import)
12089+ ^- (list term)
12090+ ?~ imports ~
12091+ ?- -.i.imports
12092+ %mark $(imports t.imports)
12093+ %sur [name.i.imports $(imports t.imports)]
12094+ %jibb [face.i.imports $(imports t.imports)]
12095+ ==
12096+::
12097+++ api-derived-names-valid
12098+ |= [paths=(list iapi-path) poke-names=(list term) mod=module prelude-values=(list term)]
12099+ ^- ?
12100+ =/ path-names=(list term) (turn paths |=(p=iapi-path name.p))
12101+ =/ derived=(list term) (weld path-names poke-names)
12102+ ?: (lien derived |=(n=term =(n %proj))) |
12103+ =/ outer=(list term) (weld prelude-values (weld (global-value-names defs.mod) (api-import-faces imports.mod)))
12104+ (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x))))))
12105+::
12106+:: Analysis only. Successful external entries must be unchanged results
12107+:: produced for the declared marks; no request interface is produced.
12108++$ iapi-mark-type [name=term typ=itype]
12109++$ iapi-path-typed [path=iapi-path full=itype diffs=(list iapi-mark-type)]
12110+++ api-diff-types
12111+ |= [names=(list term) externals=imark-externals declared=(list term)]
12112+ ^- (unit (list iapi-mark-type))
12113+ ?~ names `~
12114+ =/ typ=(unit itype) (find-imported-mark i.names externals declared)
12115+ ?~ typ ~
12116+ =/ tail=(unit (list iapi-mark-type)) $(names t.names)
12117+ ?~ tail ~
12118+ `[[i.names u.typ] u.tail]
12119+::
12120+++ api-path-types
12121+ |= [paths=(list iapi-path) externals=imark-externals declared=(list term)]
12122+ ^- (unit (list iapi-path-typed))
12123+ ?~ paths `~
12124+ =/ full=(unit itype) (find-imported-mark full.i.paths externals declared)
12125+ ?~ full ~
12126+ =/ diffs=(unit (list iapi-mark-type)) (api-diff-types diffs.i.paths externals declared)
12127+ ?~ diffs ~
12128+ =/ tail=(unit (list iapi-path-typed)) $(paths t.paths)
12129+ ?~ tail ~
12130+ `[[i.paths u.full u.diffs] u.tail]
12131+::
12132+++ api-poke-mark-names
12133+ |= [pokes=(list def) declared=(list term)]
12134+ ^- (unit (list term))
12135+ ?~ pokes `~
12136+ ?^ t.pokes ~
12137+ =/ d=def i.pokes
12138+ ?. ?=(%mold -.d) ~
12139+ =/ sh=shape shape.d
12140+ ?: ?=(%union -.sh) (api-path-diffs cases.sh declared ~)
12141+ =/ name=(unit term) (api-path-mark sh declared)
12142+ ?~ name ~
12143+ `~[u.name]
12144+::
12145+++ api-path-analysis
12146+ |= [mod=module externals=imark-externals prelude-values=(list term) prelude-molds=(list term)]
12147+ ^- (unit (list iapi-path-typed))
12148+ ?: (lien defs.mod def-has-hole) ~
12149+ ?^ (duplicate-defs defs.mod) ~
12150+ =/ ds=(list def) defs.mod
12151+ =/ declarations=(list def)
12152+ (skim ds |=(d=def &(?=(%mold -.d) =(%paths name.d))))
12153+ ?. ?=([* ~] declarations) ~
12154+ =/ pokes=(list def)
12155+ (skim ds |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12156+ ?: (gth (lent pokes) 1) ~
12157+ =/ ordinary=(list def)
12158+ (skim ds |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12159+ ?. (module-scope-valid mod(defs ordinary) prelude-values prelude-molds) ~
12160+ =/ declared=(list term) (collect-mark-imports imports.mod)
12161+ =/ poke-names=(unit (list term)) (api-poke-mark-names pokes declared)
12162+ ?~ poke-names ~
12163+ =/ decl=def i.declarations
12164+ ?> ?=(%mold -.decl)
12165+ =/ paths=(unit (list iapi-path)) (api-path-declaration shape.decl declared)
12166+ ?~ paths ~
12167+ =/ derived-pokes=(list term) ?~(pokes ~ ~[%poke])
12168+ ?. (api-derived-names-valid u.paths derived-pokes mod prelude-values) ~
12169+ (api-path-types u.paths externals declared)
12170+::
12171+:: Source/graph entry for path analysis only. The returned paths retain
12172+:: reader-derived mark types and import resolution has checked reachable
12173+:: Jibb dependencies. This is not an API interface or a module check.
12174+++ api-path-analysis-source
12175+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12176+ ^- (each (list iapi-path-typed) @t)
12177+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path analysis requires /ui/api/<agent>.jibb']
12178+ =/ parsed (parse file src)
12179+ ?: ?=(%| -.parsed) [%| 'API path source does not parse']
12180+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12181+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12182+ ?~ prepared [%| 'API path analysis needs the prepared prelude']
12183+ =/ prelude=(unit ifile) `iface.u.prepared
12184+ =/ deps=jimports-result
12185+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ prelude)
12186+ ?: ?=(%| -.deps) [%| p.deps]
12187+ =/ paths=(unit (list iapi-path-typed))
12188+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
12189+ ?~ paths [%| 'API path declaration needs unsupported analysis']
12190+ [%& u.paths]
12191+::
12192+:: Analysis evidence retains the API source, the prepared interface, the
12193+:: caller's reader results and the resolved Jibb dependency cache alongside
12194+:: the typed path declarations. Reader results and prepared interfaces are
12195+:: trusted inputs: this does not verify their underlying Hoon source/version,
12196+:: create requests or check the provenance of arbitrary values.
12197++$ iapi-path-evidence
12198+ [at=path source=@t prepared=iprelude externals=iexternals marks=imark-externals dependencies=jcache paths=(list iapi-path-typed)]
12199+++ api-path-evidence-source
12200+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12201+ ^- (each iapi-path-evidence @t)
12202+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
12203+ =/ parsed (parse file src)
12204+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
12205+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12206+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12207+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
12208+ =/ public=ifile iface.u.prepared
12209+ =/ deps=jimports-result
12210+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
12211+ ?: ?=(%| -.deps) [%| p.deps]
12212+ =/ paths=(unit (list iapi-path-typed))
12213+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
12214+ ?~ paths [%| 'API path declaration needs unsupported analysis']
12215+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
12216+:: Graph-aware variant preserves the caller active stack and cache.
12217+++ api-path-evidence-graph
12218+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12219+ ^- (each iapi-path-evidence @t)
12220+ ?~ active [%| 'API analysis needs an active graph']
12221+ ?. =(i.active file) [%| 'API analysis active graph does not start at the source']
12222+ ?: (lien t.active |=(p=path =(p file))) [%| 'API analysis active graph contains a cycle']
12223+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
12224+ =/ parsed (parse file src)
12225+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
12226+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12227+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12228+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
12229+ =/ public=ifile iface.u.prepared
12230+ =/ deps=jimports-result
12231+ (resolve-jibb-imports imports.p.parsed externals marks modules active values.u.prepared molds.u.prepared cache `public)
12232+ ?: ?=(%| -.deps) [%| p.deps]
12233+ =/ paths=(unit (list iapi-path-typed))
12234+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
12235+ ?~ paths [%| 'API path declaration needs unsupported analysis']
12236+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
12237+::
12238+:: This query classifies a unique path declaration only. Missing evidence
12239+:: or a nonunique name is unknown; it proves nothing about an ask value.
12240+:: Like prepared interfaces, the supplied evidence is a trusted host input.
12241+++ api-path-watchability
12242+ |= [evidence=(unit iapi-path-evidence) case-name=term]
12243+ ^- ?(%watchable %not-watchable %unknown)
12244+ ?~ evidence %unknown
12245+ =/ found=(list iapi-path-typed)
12246+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
12247+ ?. ?=([* ~] found) %unknown
12248+ ?~ scry.path.i.found %watchable
12249+ %not-watchable
12250+::
12251+:: These are declaration-derived request components, not a callable gate,
12252+:: an ask value, or proof of a value's provenance. Keep the exact trusted
12253+:: source/reader evidence until a later checked interface and lowerer can
12254+:: attach it to a generated request. No argument ordering is claimed here.
12255++$ iapi-request-parameter [name=term typ=itype at=span]
12256++$ iapi-request-parts
12257+ [evidence=iapi-path-evidence path=iapi-path-typed parameters=(list iapi-request-parameter) reply-sample=itype fold=(unit itype) watchability=?(%watchable %not-watchable)]
12258+++ api-request-parameter-types
12259+ |= params=(list iapi-parameter)
12260+ ^- (unit (list iapi-request-parameter))
12261+ ?~ params `~
12262+ =/ aura=@ta aura.i.params
12263+ ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
12264+ =/ rest=(unit (list iapi-request-parameter)) $(params t.params)
12265+ ?~ rest ~
12266+ `[[name.i.params [%atom aura] at.i.params] u.rest]
12267+::
12268+:: A single diff's fold consumes the tagged diff and the previous full value.
12269+:: Multiple-diff unions need a checked union representation and remain open.
12270+++ api-request-fold-type
12271+ |= p=iapi-path-typed
12272+ ^- (unit (unit itype))
12273+ ?~ diffs.p `~
12274+ ?^ t.diffs.p ~
12275+ =/ d=iapi-mark-type i.diffs.p
12276+ =/ literal=lit [%term %tas name.d (crip ['%' (trip name.d)])]
12277+ =/ sample=itype [%cell [%cell [%const literal] typ.d] full.p]
12278+ ``[%fn sample full.p]
12279+::
12280+++ api-request-parts
12281+ |= [evidence=(unit iapi-path-evidence) case-name=term]
12282+ ^- (unit iapi-request-parts)
12283+ ?~ evidence ~
12284+ =/ found=(list iapi-path-typed)
12285+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
12286+ ?. ?=([* ~] found) ~
12287+ =/ p=iapi-path-typed i.found
12288+ =/ raw=(unit (list iapi-parameter)) (api-path-parameters segments.path.p ~)
12289+ ?~ raw ~
12290+ =/ params=(unit (list iapi-request-parameter)) (api-request-parameter-types u.raw)
12291+ ?~ params ~
12292+ =/ fold=(unit (unit itype)) (api-request-fold-type p)
12293+ ?~ fold ~
12294+ =/ watch=?(%watchable %not-watchable) ?~(scry.path.p %watchable %not-watchable)
12295+ `[u.evidence p u.params full.p u.fold watch]
12296+::
12297+:: Check ordinary API molds and values plus every declared mark type using
12298+:: the same trusted source, prepared prelude and reader inputs as path
12299+:: evidence. Keep elaborations with those inputs for a later interface.
12300+:: This is partial analysis: an unused /- core is not independently checked,
12301+:: definitions needing derived values remain unsupported, and no complete
12302+:: API, request or constructor is exported or given runtime behavior.
12303++$ iapi-support-evidence
12304+ [paths=iapi-path-evidence values=ienv molds=imold-types marks=(list iapi-mark-type) elaborations=(list iwidth-definition)]
12305+++ api-support-analysis-source
12306+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12307+ ^- (each iapi-support-evidence @t)
12308+ =/ path-result (api-path-evidence-source file src externals marks modules prepared)
12309+ ?: ?=(%| -.path-result) [%| p.path-result]
12310+ =/ evidence=iapi-path-evidence p.path-result
12311+ =/ parsed (parse file src)
12312+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12313+ =/ mod=module p.parsed
12314+ =/ ordinary=(list def)
12315+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12316+ =/ prep=iprelude prepared.evidence
12317+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12318+ =/ vals=(list term) (global-value-names ordinary)
12319+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12320+ =/ declared=(list term) (collect-mark-imports imports.mod)
12321+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12322+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12323+ =/ prelude=(unit ifile) `iface.prep
12324+ =/ deps=jimports-result
12325+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.prep molds.prep dependencies.evidence prelude)
12326+ ?: ?=(%| -.deps) [%| p.deps]
12327+ =/ molds=imolds (collect-simple-molds ordinary)
12328+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12329+ =/ surs=(list term) (collect-sur-imports imports.mod)
12330+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12331+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12332+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12333+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12334+ ?: ?=(%| -.mts) [%| p.mts]
12335+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12336+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12337+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12338+:: Preserve the same graph context through supporting definitions.
12339+++ api-support-analysis-graph
12340+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12341+ ^- (each iapi-support-evidence @t)
12342+ =/ path-result (api-path-evidence-graph file src externals marks modules active cache prepared)
12343+ ?: ?=(%| -.path-result) [%| p.path-result]
12344+ =/ evidence=iapi-path-evidence p.path-result
12345+ =/ parsed (parse file src)
12346+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12347+ =/ mod=module p.parsed
12348+ =/ ordinary=(list def)
12349+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12350+ =/ prep=iprelude prepared.evidence
12351+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12352+ =/ vals=(list term) (global-value-names ordinary)
12353+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12354+ =/ declared=(list term) (collect-mark-imports imports.mod)
12355+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12356+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12357+ =/ prelude=(unit ifile) `iface.prep
12358+ =/ deps=jimports-result
12359+ (resolve-jibb-imports imports.mod externals marks modules active values.prep molds.prep dependencies.evidence prelude)
12360+ ?: ?=(%| -.deps) [%| p.deps]
12361+ =/ molds=imolds (collect-simple-molds ordinary)
12362+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12363+ =/ surs=(list term) (collect-sur-imports imports.mod)
12364+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12365+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12366+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12367+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12368+ ?: ?=(%| -.mts) [%| p.mts]
12369+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12370+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12371+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12372+::
12373+:: Type-analysis artifact for one plain request. The resolver may publish
12374+:: its interface only together with trusted source and reader evidence.
12375+:: No lowering or runtime validator exists.
12376+:: Value watchability remains unproved even for a watchable declaration.
12377++$ ione-request-interface
12378+ [support=iapi-support-evidence parts=iapi-request-parts iface=ifile]
12379+++ compatible-raw-poke
12380+ |= prelude=iprelude
12381+ ^- (unit ischeme)
12382+ =/ public=ifile iface.prelude
12383+ ?. =(at.public /lib/jibb/prelude/jibb) ~
12384+ =/ poke=(unit ischeme) (find-jibb-mold %raw-poke public)
12385+ ?~ poke ~
12386+ ?^ vars.u.poke ~
12387+ ?. ?=(%union -.typ.u.poke) ~
12388+ ?^ args.typ.u.poke ~
12389+ ?. =(origin.typ.u.poke `[/lib/jibb/internal/jibb %raw-poke]) ~
12390+ ?: (itype-has-tag typ.u.poke) ~
12391+ =/ private=(list iwidth-dependency)
12392+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12393+ ?. ?=([* ~] private) ~
12394+ ?~ source.i.private ~
12395+ =/ agent-case=itype
12396+ [%cell [%const [%term %tas %agent '%agent']] [%cell [%face %agent [%atom %tas]] [%cell [%face %mark [%atom %tas]] [%face %payload [%noun ~]]]]]
12397+ =/ store-case=itype
12398+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %action [%atom %tas]] [%face %payload [%noun ~]]]]]
12399+ ?. =(cases.typ.u.poke ~[agent-case store-case]) ~
12400+ poke
12401+::
12402+++ request-compatible-ask
12403+ |= prelude=iprelude
12404+ ^- (unit ischeme)
12405+ =/ public=ifile iface.prelude
12406+ ?. =(at.public /lib/jibb/prelude/jibb) ~
12407+ =/ ask=(unit ischeme) (find-jibb-mold %ask public)
12408+ ?~ ask ~
12409+ ?. ?=([@ ~] vars.u.ask) ~
12410+ ?. ?=(%union -.typ.u.ask) ~
12411+ ?. =(origin.typ.u.ask `[/lib/jibb/internal/jibb %ask]) ~
12412+ ?. (identity-union-parameters vars.u.ask args.typ.u.ask) ~
12413+ =/ m=@ud i.vars.u.ask
12414+ ?: (itype-var-is-atom m typ.u.ask) ~
12415+ ?. (levy (itype-vars typ.u.ask) |=(n=@ud =(n m))) ~
12416+ ?: (itype-has-tag typ.u.ask) ~
12417+ =/ private=(list iwidth-dependency)
12418+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12419+ ?. ?=([* ~] private) ~
12420+ ?~ source.i.private ~
12421+ =/ path=(unit ischeme) (find-jibb-mold %path public)
12422+ ?~ path ~
12423+ ?^ vars.u.path ~
12424+ =/ path-type=itype [%collection %list ~[[%atom %ta]]]
12425+ ?. =(typ.u.path path-type) ~
12426+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit public)
12427+ ?~ unit-template ~
12428+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
12429+ =/ state-unit=(unit itype) (template-apply u.unit-template ~[[%noun ~]])
12430+ ?~ state-unit ~
12431+ =/ path-unit=(unit itype) (template-apply u.unit-template ~[path-type])
12432+ ?~ path-unit ~
12433+ =/ output=itype [%cell [%face %state [%noun ~]] [%face %message [%var m]]]
12434+ =/ agent-input=itype [%cell [%face %mark [%atom %tas]] [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]]
12435+ =/ store-input=itype [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]
12436+ =/ pure-case=itype [%cell [%const [%term %tas %pure '%pure']] [%face %value [%var m]]]
12437+ =/ agent-case=itype
12438+ [%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]]]]]]]]
12439+ =/ store-case=itype
12440+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %name [%atom %tas]] [%face %receive [%fn store-input output]]]]]
12441+ ?. =(cases.typ.u.ask ~[pure-case agent-case store-case]) ~
12442+ ask
12443+::
12444+:: The first supported standalone API has exactly one mark import and one
12445+:: plain path declaration, with no other definitions or imports. No partial
12446+:: success is published when source, schema, or a required mold is unknown.
12447+++ one-request-interface-source
12448+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12449+ ^- (each ione-request-interface @t)
12450+ =/ out (api-support-analysis-source file src externals marks modules prepared)
12451+ ?: ?=(%| -.out) [%| p.out]
12452+ =/ support=iapi-support-evidence p.out
12453+ =/ ev=iapi-path-evidence paths.support
12454+ =/ parsed (parse file src)
12455+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12456+ =/ mod=module p.parsed
12457+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12458+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12459+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12460+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12461+ =/ p=iapi-path-typed i.paths.ev
12462+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12463+ ?~ parts [%| 'request components need unsupported inference']
12464+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12465+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12466+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12467+ =/ valid-marks=?
12468+ ?~ fold.u.parts ?=([* ~] marks.support)
12469+ ?=([* [* ~]] marks.support)
12470+ ?. valid-marks [%| 'request marks need unsupported inference']
12471+ =/ fold-open=?
12472+ ?~ fold.u.parts |
12473+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12474+ ?: fold-open [%| 'request fold needs unsupported inference']
12475+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12476+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12477+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12478+ ?~ ask [%| 'request ask needs unsupported inference']
12479+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12480+ ?~ result [%| 'request ask needs unsupported inference']
12481+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12482+ =/ sample=itype
12483+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12484+ ?~ parameters.u.parts callback
12485+ [%cell typ.i.parameters.u.parts callback]
12486+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12487+ =/ exports=imold-types
12488+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12489+ =/ prelude=iprelude prepared.ev
12490+ =/ public=ifile iface.prelude
12491+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12492+ =/ private=(list iwidth-dependency)
12493+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12494+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12495+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12496+ =/ req=irequest-evidence
12497+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12498+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] ~ modules `public values.prelude molds.prelude externals marks]]
12499+ [%& [support u.parts interface]]
12500+:: Graph-aware request artifact; resolver use remains type-only.
12501+++ one-request-interface-graph
12502+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12503+ ^- (each ione-request-interface @t)
12504+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12505+ ?: ?=(%| -.out) [%| p.out]
12506+ =/ support=iapi-support-evidence p.out
12507+ =/ ev=iapi-path-evidence paths.support
12508+ =/ parsed (parse file src)
12509+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12510+ =/ mod=module p.parsed
12511+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12512+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12513+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12514+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12515+ =/ p=iapi-path-typed i.paths.ev
12516+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12517+ ?~ parts [%| 'request components need unsupported inference']
12518+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12519+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12520+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12521+ =/ valid-marks=?
12522+ ?~ fold.u.parts ?=([* ~] marks.support)
12523+ ?=([* [* ~]] marks.support)
12524+ ?. valid-marks [%| 'request marks need unsupported inference']
12525+ =/ fold-open=?
12526+ ?~ fold.u.parts |
12527+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12528+ ?: fold-open [%| 'request fold needs unsupported inference']
12529+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12530+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12531+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12532+ ?~ ask [%| 'request ask needs unsupported inference']
12533+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12534+ ?~ result [%| 'request ask needs unsupported inference']
12535+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12536+ =/ sample=itype
12537+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12538+ ?~ parameters.u.parts callback
12539+ [%cell typ.i.parameters.u.parts callback]
12540+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12541+ =/ exports=imold-types
12542+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12543+ =/ prelude=iprelude prepared.ev
12544+ =/ public=ifile iface.prelude
12545+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12546+ =/ private=(list iwidth-dependency)
12547+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12548+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12549+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12550+ =/ req=irequest-evidence
12551+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12552+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] ~ modules `public values.prelude molds.prelude externals marks]]
12553+ [%& [support u.parts interface]]
12554+::
12555+++ api-mark-exports
12556+ |= [marks=(list term) all=(list term) externals=imark-externals]
12557+ ^- imold-types
12558+ ?~ marks ~
12559+ =/ t=(unit itype) (find-imported-mark i.marks externals all)
12560+ ?~ t $(marks t.marks)
12561+ [[i.marks [u.t ~]] $(marks t.marks)]
12562+::
12563+:: Experimental direct poke-only API. Unsupported API declarations fail
12564+:: as a whole; supplied mark reader results retain their existing boundary.
12565+++ api-poke-interface
12566+ |= [at=path mod=module mark-externals=imark-externals prelude-values=(list term) prelude-molds=(list term) prelude=(unit ifile)]
12567+ ^- (unit ifile)
12568+ ?: (lien defs.mod def-has-hole) ~
12569+ ?. ?=([%ui %api @ %jibb ~] at) ~
12570+ ?^ (duplicate-defs defs.mod) ~
12571+ ?~ prelude ~
12572+ ?. =(at.u.prelude /lib/jibb/prelude/jibb) ~
12573+ =/ poke=(unit ischeme) (find-jibb-mold %raw-poke u.prelude)
12574+ ?~ poke ~
12575+ ?. ?=(%union -.typ.u.poke) ~
12576+ ?^ vars.u.poke ~
12577+ =/ compatible=?
12578+ %+ lien cases.typ.u.poke
12579+ |= c=itype
12580+ ?=([%cell [%const [%term %tas %agent *]] [%cell [%face %agent [%atom %tas]] [%cell [%face %mark [%atom %tas]] [%face %payload [%noun ~]]]]] c)
12581+ ?. compatible ~
12582+ ?. (module-scope-valid mod(defs ~) prelude-values prelude-molds) ~
12583+ ?. (levy imports.mod |=(i=import ?=(%mark -.i))) ~
12584+ =/ marks=(list term) (collect-mark-imports imports.mod)
12585+ ?. ?=([@ ~] marks) ~
12586+ =/ ds=(list def) defs.mod
12587+ ?. ?=([[%mold *] ~] ds) ~
12588+ ?. =(%poke name.i.ds) ~
12589+ =/ sh=shape shape.i.ds
12590+ ?. ?=([%ref *] sh) ~
12591+ ?. ?=([@ ~] names.sh) ~
12592+ =/ n=term i.names.sh
12593+ ?. (unique-value-name n marks) ~
12594+ ?: |((lien prelude-values |=(x=term =(n x))) (lien prelude-molds |=(x=term =(n x)))) ~
12595+ =/ mark=(unit itype) (find-imported-mark n mark-externals marks)
12596+ ?~ mark ~
12597+ =/ sc=(unit ischeme) (derived-poke-command-scheme u.prelude u.mark)
12598+ ?~ sc ~
12599+ `[~[[%poke u.sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]] ~ ~ ~ ~]
12600+::
12601+:: Source-proven ordinary helpers validate each selected /sur dependency.
12602+:: Unused or less direct cores remain unsupported by this first interface.
12603+++ api-sur-covered
12604+ |= [surs=(list term) defs=(list def) externals=iexternals all=(list term)]
12605+ ^- ?
12606+ ?~ surs &
12607+ =/ found=(list def)
12608+ %+ skim defs
12609+ |= d=def
12610+ ?. ?=(%mold -.d) |
12611+ ?. ?=(%ref -.shape.d) |
12612+ ?. ?=([@ [@ ~]] names.shape.d) |
12613+ =(i.t.names.shape.d i.surs)
12614+ ?~ found |
12615+ =/ selected=def i.found
12616+ ?. ?=(%mold -.selected) |
12617+ =/ sh=shape shape.selected
12618+ ?. ?=(%ref -.sh) |
12619+ ?. ?=([@ [@ ~]] names.sh) |
12620+ =/ checked=(unit itype) (find-imported-mold i.surs i.names.sh externals all)
12621+ ?~ checked |
12622+ $(surs t.surs)
12623+::
12624++$ imulti-request-gates [values=ienv requests=(list irequest-evidence)]
12625+++ api-request-gates
12626+ |= [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]
12627+ ^- (unit imulti-request-gates)
12628+ ?~ paths `[~ ~]
12629+ ?: =(0 fuel) ~
12630+ =/ p=iapi-path-typed i.paths
12631+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12632+ ?~ parts ~
12633+ ?. ?=(?(~ [* ~]) parameters.u.parts) ~
12634+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) ~
12635+ ?^ scry.path.p ~
12636+ ?^ (itype-vars reply-sample.u.parts) ~
12637+ ?: (itype-has-tag reply-sample.u.parts) ~
12638+ =/ open-fold=?
12639+ ?~ fold.u.parts |
12640+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12641+ ?: open-fold ~
12642+ =/ result=(unit itype) (template-apply ask ~[[%var 0]])
12643+ ?~ result ~
12644+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12645+ =/ sample=itype
12646+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12647+ ?~ parameters.u.parts callback
12648+ [%cell typ.i.parameters.u.parts callback]
12649+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12650+ =/ prep=iprelude prepared.ev
12651+ =/ req=irequest-evidence
12652+ [file name.path.p p src public internal values.prep molds.prep externals marks]
12653+ =/ rest=(unit imulti-request-gates)
12654+ $(paths t.paths, fuel (dec fuel))
12655+ ?~ rest ~
12656+ `[[[name.path.p scheme] values.u.rest] [req requests.u.rest]]
12657+::
12658+++ api-poke-from-checked
12659+ |= [file=path mod=module marks=imark-externals values=(list term) molds=(list term) prelude=(unit ifile)]
12660+ ^- (unit [values=ienv derived=(list iderived)])
12661+ =/ pokes=(list def)
12662+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12663+ ?~ pokes `[~ ~]
12664+ ?. ?=([* ~] pokes) ~
12665+ =/ declared=(list term) (collect-mark-imports imports.mod)
12666+ =/ ns=(unit (list term)) (api-poke-mark-names pokes declared)
12667+ ?~ ns ~
12668+ ?. ?=([@ ~] u.ns) ~
12669+ =/ matching=(list import)
12670+ %+ skim imports.mod
12671+ |= i=import
12672+ ?. ?=(%mark -.i) |
12673+ =(mark.i i.u.ns)
12674+ ?. ?=([* ~] matching) ~
12675+ =/ checked=(unit ifile)
12676+ (api-poke-interface file mod(defs pokes, imports matching) marks values molds prelude)
12677+ ?~ checked ~
12678+ `[values.u.checked derived.u.checked]
12679+::
12680+:: The partial interface is published atomically: all paths, ordinary
12681+:: source definitions, declared marks and the poke must check. Unselected
12682+:: /sur bindings, runtime validation and value watchability remain unproved.
12683+++ multi-request-interface-graph
12684+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12685+ ^- (each [iface=ifile cache=jcache] @t)
12686+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12687+ ?: ?=(%| -.out) [%| p.out]
12688+ =/ support=iapi-support-evidence p.out
12689+ =/ ev=iapi-path-evidence paths.support
12690+ =/ parsed (parse file src)
12691+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12692+ =/ mod=module p.parsed
12693+ ?. (levy imports.mod |=(i=import ?=(?(%mark %sur) -.i)))
12694+ [%| 'request imports need unsupported inference']
12695+ =/ surs=(list term) (collect-sur-imports imports.mod)
12696+ ?. (api-sur-covered surs defs.mod externals surs)
12697+ [%| 'API source dependency needs unsupported inference']
12698+ ?~ paths.ev [%| 'request count needs unsupported inference']
12699+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12700+ ?~ ask [%| 'request ask needs unsupported inference']
12701+ =/ prep=iprelude prepared.ev
12702+ =/ public=ifile iface.prep
12703+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12704+ =/ private=(list iwidth-dependency)
12705+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12706+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12707+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12708+ =/ gates=(unit imulti-request-gates)
12709+ (api-request-gates paths.ev ev u.ask file src u.source.public u.source.i.private externals marks 256)
12710+ ?~ gates [%| 'request paths need unsupported inference']
12711+ =/ poke=(unit [values=ienv derived=(list iderived)])
12712+ (api-poke-from-checked file mod marks values.prep molds.prep `public)
12713+ ?~ poke [%| 'API poke needs unsupported inference']
12714+ =/ mark-molds=imold-types
12715+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12716+ =/ exports=imold-types (weld mark-molds molds.support)
12717+ =/ names=(list term) (turn exports |=(m=[name=term template=ischeme] name.m))
12718+ ?. (levy names |=(n=term (unique-value-name n names)))
12719+ [%| 'API exported molds need unsupported inference']
12720+ =/ env=ienv (weld values.u.gates (weld values.u.poke values.support))
12721+ =/ graph=irequest-graph
12722+ [(silt `(list path)`~[file]) requests.u.gates ~ modules `public values.prep molds.prep externals marks]
12723+ =/ iface=ifile
12724+ [env exports file derived.u.poke elaborations.support ~ `src `graph]
12725+ [%& [iface dependencies.ev]]
12726+::
12727+:: A checked program main is only the direct four-component source call.
12728+:: Grouping is transparent, but aliases, qualified wings and other module
12729+:: kinds remain outside this slice.
12730+++ program-main-def
12731+ |= ds=(list def)
12732+ ^- (unit def)
12733+ ?~ ds ~
12734+ ?: &(?=(%value -.i.ds) =(%main name.i.ds)) `i.ds
12735+ $(ds t.ds)
12736+::
12737+++ program-main-wing
12738+ |= e=expr
12739+ ^- (unit term)
12740+ ?: ?=(%group -.e) $(e inner.e)
12741+ ?. ?=(%wing -.e) ~
12742+ ?. ?=([@ ~] names.e) ~
12743+ `i.names.e
12744+::
12745+++ program-main-args
12746+ |= d=def
12747+ ^- (unit (list expr))
12748+ ?. ?=(%value -.d) ~
12749+ |-
12750+ ?: ?=(%group -.val.d) $(val.d inner.val.d)
12751+ ?. ?=(%call -.val.d) ~
12752+ =/ head=(unit term) (program-main-wing head.val.d)
12753+ ?~ head ~
12754+ ?. =(%program u.head) ~
12755+ ?. ?=([* * * * ~] args.val.d) ~
12756+ `args.val.d
12757+::
12758+++ program-main-parts
12759+ |= d=def
12760+ ^- (unit [init=term update=term view=term subs=term])
12761+ ?. ?=(%value -.d) ~
12762+ |-
12763+ ?: ?=(%group -.val.d) $(val.d inner.val.d)
12764+ ?. ?=(%call -.val.d) ~
12765+ =/ head=(unit term) (program-main-wing head.val.d)
12766+ ?~ head ~
12767+ ?. =(%program u.head) ~
12768+ ?. ?=([* * * * ~] args.val.d) ~
12769+ =/ args=(list expr) args.val.d
12770+ ?> ?=([* * * * ~] args)
12771+ =/ init=(unit term) (program-main-wing i.args)
12772+ =/ update=(unit term) (program-main-wing i.t.args)
12773+ =/ view=(unit term) (program-main-wing i.t.t.args)
12774+ =/ subs=(unit term) (program-main-wing i.t.t.t.args)
12775+ ?~ init ~
12776+ ?~ update ~
12777+ ?~ view ~
12778+ ?~ subs ~
12779+ `[u.init u.update u.view u.subs]
12780+::
12781+:: A data page is only the direct two-component source call. Grouping is
12782+:: transparent, but page aliases, qualified wings and other kinds are not.
12783+++ page-main-parts
12784+ |= d=def
12785+ ^- (unit [load=term view=term])
12786+ ?. ?=(%value -.d) ~
12787+ |-
12788+ ?: ?=(%group -.val.d) $(val.d inner.val.d)
12789+ ?. ?=(%call -.val.d) ~
12790+ =/ head=(unit term) (program-main-wing head.val.d)
12791+ ?~ head ~
12792+ ?. =(%page u.head) ~
12793+ ?. ?=([* * ~] args.val.d) ~
12794+ =/ args=(list expr) args.val.d
12795+ ?> ?=([* * ~] args)
12796+ =/ load=(unit term) (program-main-wing i.args)
12797+ =/ view=(unit term) (program-main-wing i.t.args)
12798+ ?~ load ~
12799+ ?~ view ~
12800+ `[u.load u.view]
12801+::
12802+:: A store main is only the direct two-wing source call. Its local poke mold
12803+:: is checked here and remains in ordinary mold/value inference.
12804+++ store-main-parts
12805+ |= d=def
12806+ ^- (unit [init=term update=term])
12807+ ?. ?=(%value -.d) ~
12808+ |-
12809+ ?: ?=(%group -.val.d) $(val.d inner.val.d)
12810+ ?. ?=(%call -.val.d) ~
12811+ =/ head=(unit term) (program-main-wing head.val.d)
12812+ ?~ head ~
12813+ ?. =(%store u.head) ~
12814+ ?. ?=([* * ~] args.val.d) ~
12815+ =/ args=(list expr) args.val.d
12816+ ?> ?=([* * ~] args)
12817+ =/ init=(unit term) (program-main-wing i.args)
12818+ =/ update=(unit term) (program-main-wing i.t.args)
12819+ ?~ init ~
12820+ ?~ update ~
12821+ `[u.init u.update]
12822+::
12823++$ istore-declaration [action=term defs=(list def)]
12824+++ store-declaration
12825+ |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
12826+ ^- (unit istore-declaration)
12827+ =/ ds=(list def) defs.mod
12828+ =/ pokes=(list def)
12829+ (skim ds |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12830+ ?. ?=([* ~] pokes) ~
12831+ =/ states=(list def)
12832+ (skim ds |=(d=def &(?=(%mold -.d) =(%state name.d))))
12833+ ?. ?=([* ~] states) ~
12834+ =/ poke=def i.pokes
12835+ =/ state=def i.states
12836+ ?> &(?=(%mold -.poke) ?=(%mold -.state))
12837+ ?: ?=(%generic -.shape.state) ~
12838+ ?: ?=(%generic -.shape.poke) ~
12839+ =/ action=term %poke
12840+ =/ ordinary=(list def) ds
12841+ ?. (module-scope-valid mod prelude-values prelude-molds) ~
12842+ =/ derived=(list term) ~[%state action]
12843+ ?: (lien derived |=(n=term =(n %proj))) ~
12844+ =/ outer=(list term)
12845+ (weld prelude-values (weld (global-value-names ordinary) (api-import-faces imports.mod)))
12846+ ?. (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x)))))) ~
12847+ `[action ordinary]
12848+::
12849+++ program-empty-null
12850+ |= e=expr
12851+ ^- ?
12852+ ?- -.e
12853+ %lit =(%null form.lit.e)
12854+ %cast $(e val.e)
12855+ %group $(e inner.e)
12856+ %body ?~(defs.e $(e final.e) |)
12857+ * |
12858+ ==
12859+::
12860+++ program-subs-empty
12861+ |= d=def
12862+ ^- ?
12863+ ?. ?=(%value -.d) |
12864+ ?- -.val.d
12865+ %gate (program-empty-null body.val.d)
12866+ %gate-wide (program-empty-null body.val.d)
12867+ * |
12868+ ==
12869+::
12870+++ program-transparent
12871+ |= e=expr
12872+ ^- expr
12873+ ?- -.e
12874+ %group $(e inner.e)
12875+ %cast $(e val.e)
12876+ %body ?~(defs.e $(e final.e) e)
12877+ * e
12878+ ==
12879+++ program-init-tuple-null
12880+ |= d=def
12881+ ^- ?
12882+ ?. ?=(%value -.d) |
12883+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) |
12884+ =/ body=expr
12885+ ?- -.val.d
12886+ %gate body.val.d
12887+ %gate-wide body.val.d
12888+ * !!
12889+ ==
12890+ =. body (program-transparent body)
12891+ ?. ?=(%tuple -.body) |
12892+ ?~ items.body |
12893+ (program-empty-null val:(rear items.body))
12894+::
12895+:: Recover only the update of an already recognized direct program main.
12896+:: Its written sample determines the message/model relationship; the canonical
12897+:: cmd, unit and update slot determine the result context. Publication is
12898+:: component-local so later subscription/view/initializer retries can accumulate.
12899+++ program-update-context
12900+ |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
12901+ ^- (unit iresolved)
12902+ =/ env=ienv env.resolution
12903+ ?^ (ienv-lookup %main env) ~
12904+ ?^ (ienv-lookup update.parts env) ~
12905+ =/ updates=(list def)
12906+ (skim ds |=(d=def &(?=(%value -.d) =(update.parts name.d))))
12907+ ?. ?=([* ~] updates) ~
12908+ =/ update-def=def i.updates
12909+ ?> ?=(%value -.update-def)
12910+ =/ written-update=(unit sample) (direct-gate-sample update-def)
12911+ ?~ written-update ~
12912+ ?. ?=(%cell -.u.written-update) ~
12913+ ?. ?=([* * ~] items.u.written-update) ~
12914+ ?~ prelude.initial ~
12915+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
12916+ ?~ program ~
12917+ =/ command=(unit ischeme) (find-jibb-mold %cmd u.prelude.initial)
12918+ =/ list-template=(unit ischeme) (find-jibb-mold %list u.prelude.initial)
12919+ ?~ command ~
12920+ ?~ list-template ~
12921+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
12922+ ?~ heads ~
12923+ =/ written=(unit def) (~(get by gates.u.heads) %program)
12924+ ?~ written ~
12925+ =/ written-sample=(unit sample) (direct-gate-sample u.written)
12926+ ?~ written-sample ~
12927+ ?. ?=(%cell -.u.written-sample) ~
12928+ ?. ?=([* * * * ~] items.u.written-sample) ~
12929+ =/ checked=(map term def)
12930+ (~(put by (direct-checked-gates ds env)) update.parts update-def)
12931+ =/ templates=ienv
12932+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
12933+ =/ scanned=(unit dgscan)
12934+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
12935+ ?~ scanned ~
12936+ =. next.initial (dg-next-id ids.u.scanned 0)
12937+ =/ update-state=istate (reserve-def-caps val.update-def initial)
12938+ =/ sam=isample-result (infer-sample u.written-update env update-state)
12939+ ?: ?=(%| -.sam) ~
12940+ =/ actual-sample=itype (itype-normalize typ.p.sam sub.state.p.sam)
12941+ ?. ?=(%cell -.actual-sample) ~
12942+ =/ message=(unit itype)
12943+ (direct-slot-body hed.actual-sample (direct-sample-name i.items.u.written-update))
12944+ =/ model=(unit itype)
12945+ (direct-slot-body tal.actual-sample (direct-sample-name i.t.items.u.written-update))
12946+ ?~ message ~
12947+ ?~ model ~
12948+ =/ cmd=(unit itype) (template-apply u.command ~[u.message])
12949+ ?~ cmd ~
12950+ =/ command-result=(unit itype) (template-apply u.list-template ~[u.cmd])
12951+ ?~ command-result ~
12952+ =/ product=itype [%cell u.model u.command-result]
12953+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.program state.p.sam)
12954+ ?. ?=(%fn -.typ.instance) ~
12955+ ?. ?=(%cell -.sample.typ.instance) ~
12956+ ?. ?=(%cell -.tal.sample.typ.instance) ~
12957+ =/ expected-update=(unit itype)
12958+ (direct-slot-body hed.tal.sample.typ.instance (direct-sample-name i.t.items.u.written-sample))
12959+ ?~ expected-update ~
12960+ ?. ?=(%fn -.u.expected-update) ~
12961+ :: Sample binders are not value faces. Strip only those two slot faces
12962+ :: for the invariant canonical-gate proof; the source-faced gate is still
12963+ :: used by the complete positional call and final ordinary result cast.
12964+ =/ canonical-candidate=itype [%fn [%cell u.message u.model] product]
12965+ =/ gate-fit=ifit
12966+ (direct-invariant canonical-candidate u.expected-update sub.state.instance next.state.instance)
12967+ ?. ?=(%ok -.gate-fit) ~
12968+ =/ closed=itype
12969+ (itype-normalize [%fn typ.p.sam product] sub.gate-fit)
12970+ ?. ?=(%fn -.closed) ~
12971+ :: The closed product no longer needs the canonical slot substitutions.
12972+ :: Start the body at its ordinary sample state so existing branch retries
12973+ :: keep their substitution guards, but retain the shared fresh-ID high water.
12974+ =/ st=istate state.p.sam(next next.gate-fit, gate-defs checked, head-evidence heads)
12975+ =/ body=expr
12976+ ?- -.val.update-def
12977+ %gate body.val.update-def
12978+ %gate-wide body.val.update-def
12979+ * !!
12980+ ==
12981+ =/ inferred=iresult
12982+ (infer-call-context-arg body product.closed env.p.sam st (span-of body))
12983+ ?: ?=(%| -.inferred) ~
12984+ =/ product-fit=ifit
12985+ (itype-fit typ.p.inferred product.closed sub.state.p.inferred next.state.p.inferred)
12986+ ?. ?=(%ok -.product-fit) ~
12987+ =/ merged-product=itype
12988+ (itype-merge-faces typ.p.inferred product.closed sub.product-fit)
12989+ =/ actual-cast=itype [%fn typ.p.sam merged-product]
12990+ =/ cast=ifit
12991+ (itype-fit actual-cast closed sub.product-fit next.product-fit)
12992+ ?. ?=(%ok -.cast) ~
12993+ =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
12994+ =/ adjusted=iresult
12995+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
12996+ =/ added=(unit iadded-definition)
12997+ (add-supported-result update-def adjusted update-state env checked artifacts.resolution)
12998+ ?~ added ~
12999+ =/ recovered=(unit ischeme) (ienv-lookup update.parts env.u.added)
13000+ ?~ recovered ~
13001+ ?. ?=(~ vars.u.recovered) ~
13002+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13003+ `[env.u.added grouped.resolution artifacts.u.added]
13004+::
13005+++ program-inferred-slot
13006+ |= [typ=itype name=(unit term)]
13007+ ^- itype
13008+ ?~ name typ
13009+ ?: &(?=(%face -.typ) =(name.typ u.name)) body.typ
13010+ typ
13011+::
13012+++ program-inferred-sample
13013+ |= [typ=itype sam=sample]
13014+ ^- itype
13015+ (program-inferred-slot typ (direct-sample-name sam))
13016+::
13017+++ program-two-slot-names
13018+ |= sam=sample
13019+ ^- (unit [first=(unit term) second=(unit term)])
13020+ ?- -.sam
13021+ %cell
13022+ ?. ?=([* * ~] items.sam) ~
13023+ `[(direct-sample-name i.items.sam) (direct-sample-name i.t.items.sam)]
13024+ %face
13025+ ?. ?=(%cell -.shape.sam) ~
13026+ ?. ?=([* * ~] fields.shape.sam) ~
13027+ `[(direct-field-name i.fields.shape.sam) (direct-field-name i.t.fields.shape.sam)]
13028+ * ~
13029+ ==
13030+::
13031+:: Read message/model from the checked update and its written source layout.
13032+:: The source names strip only top-level sample binder faces; nested value
13033+:: faces remain part of the canonical message and model.
13034+++ program-update-relation
13035+ |= [name=term ds=(list def) env=ienv]
13036+ ^- (unit [message=itype model=itype])
13037+ =/ update=(unit ischeme) (ienv-lookup name env)
13038+ ?~ update ~
13039+ ?. ?=(~ vars.u.update) ~
13040+ ?. ?=(~ (itype-vars typ.u.update)) ~
13041+ ?. ?=(%fn -.typ.u.update) ~
13042+ ?. ?=(%cell -.sample.typ.u.update) ~
13043+ =/ defs=(list def)
13044+ (skim ds |=(d=def &(?=(%value -.d) =(name name.d))))
13045+ ?. ?=([* ~] defs) ~
13046+ =/ written=(unit sample) (direct-gate-sample i.defs)
13047+ ?~ written ~
13048+ ?. ?=(%cell -.u.written) ~
13049+ ?. ?=([* * ~] items.u.written) ~
13050+ =/ message=(unit itype)
13051+ (direct-slot-body hed.sample.typ.u.update (direct-sample-name i.items.u.written))
13052+ =/ model=(unit itype)
13053+ (direct-slot-body tal.sample.typ.u.update (direct-sample-name i.t.items.u.written))
13054+ ?~ message ~
13055+ ?~ model ~
13056+ `[u.message u.model]
13057+::
13058+:: Recover an unannotated direct subscription component from the checked
13059+:: update relation and canonical fourth program slot. This establishes only
13060+:: the value type; the final program watch proof remains separate.
13061+++ program-subs-context
13062+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
13063+ ^- (unit iresolved)
13064+ =/ env=ienv env.resolution
13065+ ?^ (ienv-lookup %main env) ~
13066+ ?^ (ienv-lookup subs.parts env) ~
13067+ =/ relation=(unit [message=itype model=itype])
13068+ (program-update-relation update.parts ds env)
13069+ ?~ relation ~
13070+ =/ subs=(list def)
13071+ (skim ds |=(d=def &(?=(%value -.d) =(subs.parts name.d))))
13072+ ?. ?=([* ~] subs) ~
13073+ =/ subs-def=def i.subs
13074+ ?> ?=(%value -.subs-def)
13075+ =/ written-subs=(unit sample) (direct-gate-sample subs-def)
13076+ ?~ written-subs ~
13077+ ?~ prelude.initial ~
13078+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
13079+ =/ sub=(unit ischeme) (find-jibb-mold %sub u.prelude.initial)
13080+ =/ list-template=(unit ischeme) (find-jibb-mold %list u.prelude.initial)
13081+ ?~ program ~
13082+ ?~ sub ~
13083+ ?~ list-template ~
13084+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
13085+ ?~ heads ~
13086+ =/ written=(unit def) (~(get by gates.u.heads) %program)
13087+ ?~ written ~
13088+ =/ written-sample=(unit sample) (direct-gate-sample u.written)
13089+ ?~ written-sample ~
13090+ ?. ?=(%cell -.u.written-sample) ~
13091+ ?. ?=([* * * * ~] items.u.written-sample) ~
13092+ =/ checked=(map term def) (direct-checked-gates ds env)
13093+ =/ templates=ienv
13094+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13095+ =/ scanned=(unit dgscan)
13096+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13097+ ?~ scanned ~
13098+ =. next.initial (dg-next-id ids.u.scanned 0)
13099+ =/ subs-state=istate (reserve-def-caps val.subs-def initial)
13100+ =/ sam=isample-result (infer-sample u.written-subs env subs-state)
13101+ ?: ?=(%| -.sam) ~
13102+ =/ actual-model=itype (program-inferred-sample typ.p.sam u.written-subs)
13103+ ?. ?=(~ (itype-vars actual-model)) ~
13104+ ?: (itype-has-tag actual-model) ~
13105+ =/ model-fit=ifit
13106+ (direct-invariant actual-model model.u.relation sub.state.p.sam next.state.p.sam)
13107+ ?. ?=(%ok -.model-fit) ~
13108+ =/ message-sub=(unit itype) (template-apply u.sub ~[message.u.relation])
13109+ ?~ message-sub ~
13110+ =/ product=(unit itype) (template-apply u.list-template ~[u.message-sub])
13111+ ?~ product ~
13112+ =/ instance=[typ=itype state=istate]
13113+ (instantiate-scheme u.program state.p.sam(sub sub.model-fit, next next.model-fit))
13114+ ?. ?=(%fn -.typ.instance) ~
13115+ ?. ?=(%cell -.sample.typ.instance) ~
13116+ ?. ?=(%cell -.tal.sample.typ.instance) ~
13117+ ?. ?=(%cell -.tal.tal.sample.typ.instance) ~
13118+ =/ expected-subs=(unit itype)
13119+ (direct-slot-body tal.tal.tal.sample.typ.instance (direct-sample-name i.t.t.t.items.u.written-sample))
13120+ ?~ expected-subs ~
13121+ ?. ?=(%fn -.u.expected-subs) ~
13122+ =/ canonical=itype [%fn model.u.relation u.product]
13123+ =/ gate-fit=ifit
13124+ (direct-invariant canonical u.expected-subs sub.state.instance next.state.instance)
13125+ ?. ?=(%ok -.gate-fit) ~
13126+ =/ closed=itype
13127+ (itype-normalize [%fn typ.p.sam u.product] sub.gate-fit)
13128+ ?. ?=(%fn -.closed) ~
13129+ =/ body=expr
13130+ ?- -.val.subs-def
13131+ %gate body.val.subs-def
13132+ %gate-wide body.val.subs-def
13133+ * !!
13134+ ==
13135+ =/ st=istate
13136+ state.p.sam(next next.gate-fit, gate-defs checked, head-evidence heads)
13137+ =/ inferred=iresult
13138+ (infer-call-context-arg body product.closed env.p.sam st (span-of body))
13139+ ?: ?=(%| -.inferred) ~
13140+ =/ product-fit=ifit
13141+ (itype-fit typ.p.inferred product.closed sub.state.p.inferred next.state.p.inferred)
13142+ ?. ?=(%ok -.product-fit) ~
13143+ =/ merged-product=itype
13144+ (itype-merge-faces typ.p.inferred product.closed sub.product-fit)
13145+ =/ actual-cast=itype [%fn typ.p.sam merged-product]
13146+ =/ cast=ifit
13147+ (itype-fit actual-cast closed sub.product-fit next.product-fit)
13148+ ?. ?=(%ok -.cast) ~
13149+ =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
13150+ =/ adjusted=iresult
13151+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
13152+ =/ added=(unit iadded-definition)
13153+ (add-supported-result subs-def adjusted subs-state env checked artifacts.resolution)
13154+ ?~ added ~
13155+ =/ recovered=(unit ischeme) (ienv-lookup subs.parts env.u.added)
13156+ ?~ recovered ~
13157+ ?. ?=(~ vars.u.recovered) ~
13158+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13159+ `[env.u.added grouped.resolution artifacts.u.added]
13160+::
13161++$ iview-site [xs=expr mapper=term]
13162+++ program-view-site
13163+ |= e=expr
13164+ ^- (unit iview-site)
13165+ =. e (program-transparent e)
13166+ ?. ?=(%call -.e) ~
13167+ ?. ?=([* ~] args.e) ~
13168+ =/ each=expr (program-transparent head.e)
13169+ ?. ?=(%wing -.each) ~
13170+ ?. ?=([%each ~] names.each) ~
13171+ =/ turned=expr (program-transparent i.args.e)
13172+ ?. ?=(%call -.turned) ~
13173+ ?. ?=([* * ~] args.turned) ~
13174+ =/ turn=expr (program-transparent head.turned)
13175+ ?. ?=(%wing -.turn) ~
13176+ ?. ?=([%turn ~] names.turn) ~
13177+ =/ xs=expr (program-transparent i.args.turned)
13178+ ?. ?=(%wing -.xs) ~
13179+ ?~ names.xs ~
13180+ =/ mapper=(unit term) (program-main-wing i.t.args.turned)
13181+ ?~ mapper ~
13182+ `[xs u.mapper]
13183+::
13184+++ program-recovery-names
13185+ |= ds=(list def)
13186+ ^- (list term)
13187+ =/ main=(unit def) (program-main-def ds)
13188+ ?~ main ~
13189+ =/ parts=(unit [init=term update=term view=term subs=term])
13190+ (program-main-parts u.main)
13191+ ?~ parts ~
13192+ =/ views=(list def)
13193+ (skim ds |=(d=def &(?=(%value -.d) =(view.u.parts name.d))))
13194+ ?. ?=([* ~] views) ~
13195+ =/ view-def=def i.views
13196+ ?> ?=(%value -.view-def)
13197+ =/ written=(unit sample) (direct-gate-sample view-def)
13198+ ?~ written ~
13199+ =/ body=expr
13200+ ?- -.val.view-def
13201+ %gate body.val.view-def
13202+ %gate-wide body.val.view-def
13203+ * !!
13204+ ==
13205+ =/ sites=(unit (list iview-site)) (program-view-sites body ~)
13206+ ?~ sites ~
13207+ ?. ?=([* ~] u.sites) ~
13208+ =/ mapper=term mapper.i.u.sites
13209+ =/ components=(list term)
13210+ :~ init.u.parts
13211+ update.u.parts
13212+ view.u.parts
13213+ subs.u.parts
13214+ ==
13215+ ?: (lien components |=(n=term =(n mapper))) ~
13216+ =/ mappers=(list def)
13217+ (skim ds |=(d=def &(?=(%value -.d) =(mapper name.d))))
13218+ ?. ?=([* ~] mappers) ~
13219+ :~ init.u.parts
13220+ update.u.parts
13221+ view.u.parts
13222+ subs.u.parts
13223+ mapper
13224+ ==
13225+::
13226+++ program-sample-binders
13227+ |= sam=sample
13228+ ^- (list term)
13229+ ?- -.sam
13230+ %bind ~[name.sam]
13231+ %face ~[name.sam]
13232+ %pun ~[name.sam]
13233+ %cell (zing (turn items.sam |=(s=sample (program-sample-binders s))))
13234+ * ~
13235+ ==
13236+::
13237+++ program-pattern-binders
13238+ |= pat=pattern
13239+ ^- (list term)
13240+ ?- -.pat
13241+ %bind ~[name.pat]
13242+ %cell (zing (turn items.pat |=(p=pattern (program-pattern-binders p))))
13243+ * ~
13244+ ==
13245+::
13246+++ program-view-sites-merge
13247+ |= [a=(unit (list iview-site)) b=(unit (list iview-site))]
13248+ ^- (unit (list iview-site))
13249+ ?~ a ~
13250+ ?~ b ~
13251+ `(weld u.a u.b)
13252+::
13253+++ program-view-sites-exprs
13254+ |= [xs=(list expr) locals=(list term)]
13255+ ^- (unit (list iview-site))
13256+ ?~ xs `~
13257+ (program-view-sites-merge (program-view-sites i.xs locals) $(xs t.xs))
13258+::
13259+++ program-view-sites-items
13260+ |= [xs=(list item) locals=(list term)]
13261+ ^- (unit (list iview-site))
13262+ ?~ xs `~
13263+ (program-view-sites-merge (program-view-sites val.i.xs locals) $(xs t.xs))
13264+::
13265+++ program-view-sites-pieces
13266+ |= [xs=(list piece) locals=(list term)]
13267+ ^- (unit (list iview-site))
13268+ ?~ xs `~
13269+ =/ here=(unit (list iview-site))
13270+ ?- -.i.xs
13271+ %expr (program-view-sites p.i.xs locals)
13272+ %text `~
13273+ ==
13274+ (program-view-sites-merge here $(xs t.xs))
13275+::
13276+++ program-view-sites-qsegs
13277+ |= [xs=(list qseg) locals=(list term)]
13278+ ^- (unit (list iview-site))
13279+ ?~ xs `~
13280+ =/ here=(unit (list iview-site))
13281+ ?- -.i.xs
13282+ %expr (program-view-sites p.i.xs locals)
13283+ %knot `~
13284+ ==
13285+ (program-view-sites-merge here $(xs t.xs))
13286+::
13287+++ program-view-sites-edits
13288+ |= [xs=(list edit) locals=(list term)]
13289+ ^- (unit (list iview-site))
13290+ ?~ xs `~
13291+ (program-view-sites-merge (program-view-sites val.i.xs locals) $(xs t.xs))
13292+::
13293+++ program-view-sites-defs
13294+ |= [xs=(list def) locals=(list term)]
13295+ ^- (unit (list iview-site))
13296+ ?~ xs `~
13297+ =/ here=(unit (list iview-site))
13298+ ?: ?=(%mold -.i.xs) `~
13299+ (program-view-sites val.i.xs locals)
13300+ (program-view-sites-merge here $(xs t.xs))
13301+::
13302+++ program-view-sites-arms
13303+ |= [xs=(list arm) locals=(list term)]
13304+ ^- (unit (list iview-site))
13305+ ?~ xs `~
13306+ =/ nested=(list term) (weld (program-pattern-binders pat.i.xs) locals)
13307+ (program-view-sites-merge (program-view-sites val.i.xs nested) $(xs t.xs))
13308+::
13309+++ program-view-sites
13310+ |= [e=expr locals=(list term)]
13311+ ^- (unit (list iview-site))
13312+ =/ site=(unit iview-site) (program-view-site e)
13313+ ?^ site
13314+ =/ names=(list term) ~[%each %turn mapper.u.site]
13315+ ?> ?=(%wing -.xs.u.site)
13316+ =/ root=term (rear names.xs.u.site)
13317+ ?: |((lien names |=(n=term (lien locals |=(x=term =(n x))))) (lien locals |=(x=term =(root x))))
13318+ ~
13319+ `~[u.site]
13320+ ?- -.e
13321+ %str (program-view-sites-pieces pieces.e locals)
13322+ %qath (program-view-sites-qsegs segs.e locals)
13323+ %change (program-view-sites-edits edits.e locals)
13324+ %pair (program-view-sites val.e locals)
13325+ %unit (program-view-sites val.e locals)
13326+ %group (program-view-sites inner.e locals)
13327+ %list (program-view-sites-exprs items.e locals)
13328+ %tuple (program-view-sites-items items.e locals)
13329+ %gate
13330+ (program-view-sites body.e (weld (program-sample-binders sample.e) locals))
13331+ %gate-wide
13332+ (program-view-sites body.e (weld (program-sample-binders sample.e) locals))
13333+ %call
13334+ (program-view-sites-merge (program-view-sites head.e locals) (program-view-sites-exprs args.e locals))
13335+ %cast (program-view-sites val.e locals)
13336+ %trace
13337+ (program-view-sites-merge (program-view-sites val.e locals) (program-view-sites then.e locals))
13338+ %branch
13339+ (program-view-sites-merge (program-view-sites subject.e locals) (program-view-sites-arms arms.e locals))
13340+ %body
13341+ =/ nested=(list term) (weld (global-value-names defs.e) locals)
13342+ (program-view-sites-merge (program-view-sites-defs defs.e nested) (program-view-sites final.e nested))
13343+ * `~
13344+ ==
13345+::
13346+++ program-union-tag-case
13347+ |= [expected=itype tag=@]
13348+ ^- (unit itype)
13349+ ?. ?=(%union -.expected) ~
13350+ =/ remaining=(list itype) cases.expected
13351+ =/ found=(unit itype) ~
13352+ =/ seen=(set @) *(set @)
13353+ |-
13354+ ?~ remaining found
13355+ =/ case=itype i.remaining
13356+ =/ head=(unit @)
13357+ ?: ?=(%const -.case) `val.literal.case
13358+ ?. ?=(%cell -.case) ~
13359+ ?. ?=(%const -.hed.case) ~
13360+ `val.literal.hed.case
13361+ ?~ head ~
13362+ ?: (~(has in:..zuse seen) u.head) ~
13363+ =. seen (~(put in:..zuse seen) u.head)
13364+ =? found =(tag u.head)
13365+ ?^(found ~ `case)
13366+ $(remaining t.remaining)
13367+::
13368+++ program-single-case-fit
13369+ |= [actual=itype expected=itype sub=isub next=@ud]
13370+ ^- ifit
13371+ =. actual (itype-normalize actual sub)
13372+ =. expected (itype-normalize expected sub)
13373+ ?. ?=(%union -.expected) [%unknown ~]
13374+ =/ found=(unit itype)
13375+ ?: ?=(%const -.actual) `actual
13376+ ?: ?=(%tag -.actual) `actual
13377+ ?: ?=(%cell -.actual) `actual
13378+ ?. ?=(%union -.actual) ~
13379+ ?. ?=([* ~] cases.actual) ~
13380+ `i.cases.actual
13381+ ?~ found [%unknown ~]
13382+ =/ case=itype u.found
13383+ =/ tag=(unit lit)
13384+ ?: ?=(%const -.case) `literal.case
13385+ ?: ?=(%tag -.case) `literal.case
13386+ ?. ?=(%cell -.case) ~
13387+ =/ head=itype (projection-field-target hed.case)
13388+ ?: ?=(%const -.head) `literal.head
13389+ ?: ?=(%tag -.head) `literal.head
13390+ ~
13391+ ?~ tag [%unknown ~]
13392+ =/ chosen=(unit itype) (program-union-tag-case expected val.u.tag)
13393+ ?~ chosen [%unknown ~]
13394+ ?: |(?=(%const -.case) ?=(%tag -.case))
13395+ ?. ?=(%const -.u.chosen) [%unknown ~]
13396+ (itype-fit case u.chosen sub next)
13397+ ?. ?=(%cell -.case) [%unknown ~]
13398+ ?. ?=(%cell -.u.chosen) [%unknown ~]
13399+ =/ head-fit=ifit (itype-fit hed.case hed.u.chosen sub next)
13400+ ?. ?=(%ok -.head-fit) head-fit
13401+ (itype-fit tal.case tal.u.chosen sub.head-fit next.head-fit)
13402+::
13403+++ program-single-generic-fit
13404+ |= [actual=itype expected=itype sub=isub next=@ud]
13405+ ^- ifit
13406+ =. actual (itype-normalize actual sub)
13407+ =. expected (itype-normalize expected sub)
13408+ ?. &(?=(%union -.actual) ?=(%union -.expected)) [%unknown ~]
13409+ ?~ origin.actual [%unknown ~]
13410+ ?. =(origin.actual origin.expected) [%unknown ~]
13411+ ?. ?=([* ~] args.actual) [%unknown ~]
13412+ ?. ?=([* ~] args.expected) [%unknown ~]
13413+ =/ argument-fit=ifit (direct-invariant i.args.actual i.args.expected sub next)
13414+ ?: ?=(%ok -.argument-fit) argument-fit
13415+ (program-single-case-fit i.args.actual i.args.expected sub next)
13416+::
13417+++ program-keyed-product-fit
13418+ |= [actual=itype expected=itype element=ischeme sub=isub next=@ud]
13419+ ^- ifit
13420+ =. actual (itype-normalize actual sub)
13421+ =. expected (itype-normalize expected sub)
13422+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
13423+ =/ key-fit=ifit
13424+ (itype-fit (projection-field-target hed.actual) (projection-field-target hed.expected) sub next)
13425+ ?. ?=(%ok -.key-fit) key-fit
13426+ =/ actual-el=itype
13427+ (itype-normalize (projection-field-target tal.actual) sub.key-fit)
13428+ =/ expected-el=itype
13429+ (itype-normalize (projection-field-target tal.expected) sub.key-fit)
13430+ ?. &(?=(%union -.actual-el) ?=(%union -.expected-el)) [%unknown ~]
13431+ ?. =(origin.actual-el origin.expected-el) [%unknown ~]
13432+ ?. ?=([* ~] args.actual-el) [%unknown ~]
13433+ ?. ?=([* ~] args.expected-el) [%unknown ~]
13434+ =/ canonical-actual=(unit itype)
13435+ (template-apply element ~[i.args.actual-el])
13436+ =/ canonical-expected=(unit itype)
13437+ (template-apply element ~[i.args.expected-el])
13438+ ?~ canonical-actual [%unknown ~]
13439+ ?~ canonical-expected [%unknown ~]
13440+ =/ actual-check=ifit
13441+ (direct-invariant actual-el u.canonical-actual sub.key-fit next.key-fit)
13442+ ?. ?=(%ok -.actual-check) actual-check
13443+ =/ expected-check=ifit
13444+ (direct-invariant expected-el u.canonical-expected sub.actual-check next.actual-check)
13445+ ?. ?=(%ok -.expected-check) expected-check
13446+ =/ case-fit=ifit
13447+ (program-single-case-fit i.args.actual-el i.args.expected-el sub.expected-check next.expected-check)
13448+ case-fit
13449+::
13450+:: A direct view without a keyed each/turn site still needs the message type
13451+:: from the checked update. Recover only that closed component; final main
13452+:: checking remains the canonical program-kind boundary.
13453+++ program-plain-view-context
13454+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
13455+ ^- (unit iresolved)
13456+ =/ env=ienv env.resolution
13457+ ?^ (ienv-lookup %main env) ~
13458+ ?^ (ienv-lookup view.parts env) ~
13459+ =/ relation=(unit [message=itype model=itype])
13460+ (program-update-relation update.parts ds env)
13461+ ?~ relation ~
13462+ =/ views=(list def)
13463+ (skim ds |=(d=def &(?=(%value -.d) =(view.parts name.d))))
13464+ ?. ?=([* ~] views) ~
13465+ =/ view-def=def i.views
13466+ ?> ?=(%value -.view-def)
13467+ =/ written-view=(unit sample) (direct-gate-sample view-def)
13468+ ?~ written-view ~
13469+ =/ body=expr
13470+ ?- -.val.view-def
13471+ %gate body.val.view-def
13472+ %gate-wide body.val.view-def
13473+ * !!
13474+ ==
13475+ =/ sites=(unit (list iview-site)) (program-view-sites body ~)
13476+ ?~ sites ~
13477+ ?^ u.sites ~
13478+ ?~ prelude.initial ~
13479+ ?~ (ienv-lookup %program values.u.prelude.initial) ~
13480+ =/ element=(unit ischeme) (find-jibb-mold %element u.prelude.initial)
13481+ ?~ element ~
13482+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
13483+ ?~ heads ~
13484+ ?~ (~(get by gates.u.heads) %program) ~
13485+ =/ checked=(map term def) (direct-checked-gates ds env)
13486+ =/ templates=ienv
13487+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13488+ =/ scanned=(unit dgscan)
13489+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13490+ ?~ scanned ~
13491+ =. next.initial (dg-next-id ids.u.scanned 0)
13492+ =/ view-state=istate (reserve-def-caps val.view-def initial)
13493+ =/ sam=isample-result (infer-sample u.written-view env view-state)
13494+ ?: ?=(%| -.sam) ~
13495+ =/ actual-model=itype (program-inferred-sample typ.p.sam u.written-view)
13496+ ?. ?=(~ (itype-vars actual-model)) ~
13497+ ?: (itype-has-tag actual-model) ~
13498+ =/ model-fit=ifit
13499+ (direct-invariant actual-model model.u.relation sub.state.p.sam next.state.p.sam)
13500+ ?. ?=(%ok -.model-fit) ~
13501+ =/ product=(unit itype) (template-apply u.element ~[message.u.relation])
13502+ ?~ product ~
13503+ =/ st=istate
13504+ state.p.sam(sub sub.model-fit, next next.model-fit, gate-defs checked, head-evidence heads)
13505+ =/ inferred=iresult
13506+ (infer-call-context-arg body u.product env.p.sam st (span-of body))
13507+ ?: ?=(%| -.inferred) ~
13508+ =/ product-fit=ifit
13509+ (itype-fit typ.p.inferred u.product sub.state.p.inferred next.state.p.inferred)
13510+ ?. ?=(%ok -.product-fit) ~
13511+ =/ merged-product=itype
13512+ (itype-merge-faces typ.p.inferred u.product sub.product-fit)
13513+ =/ actual-cast=itype [%fn typ.p.sam merged-product]
13514+ =/ closed=itype [%fn typ.p.sam u.product]
13515+ =/ cast=ifit
13516+ (itype-fit actual-cast closed sub.product-fit next.product-fit)
13517+ ?. ?=(%ok -.cast) ~
13518+ =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
13519+ =/ adjusted=iresult
13520+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
13521+ =/ added=(unit iadded-definition)
13522+ (add-supported-result view-def adjusted view-state env checked artifacts.resolution)
13523+ ?~ added ~
13524+ =/ recovered=(unit ischeme) (ienv-lookup view.parts env.u.added)
13525+ ?~ recovered ~
13526+ ?. ?=(~ vars.u.recovered) ~
13527+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13528+ `[env.u.added grouped.resolution artifacts.u.added]
13529+::
13530+:: Recover exactly one direct keyed each/turn row mapper, then its view.
13531+:: The prelude's own each and turn schemes determine the mapper gate: the
13532+:: key is inferred from the mapper body, never selected by this recovery.
13533+++ program-view-context
13534+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
13535+ ^- (unit iresolved)
13536+ =/ env=ienv env.resolution
13537+ ?^ (ienv-lookup %main env) ~
13538+ ?^ (ienv-lookup view.parts env) ~
13539+ =/ relation=(unit [message=itype model=itype])
13540+ (program-update-relation update.parts ds env)
13541+ ?~ relation ~
13542+ =/ views=(list def)
13543+ (skim ds |=(d=def &(?=(%value -.d) =(view.parts name.d))))
13544+ ?. ?=([* ~] views) ~
13545+ =/ view-def=def i.views
13546+ ?> ?=(%value -.view-def)
13547+ =/ written-view=(unit sample) (direct-gate-sample view-def)
13548+ ?~ written-view ~
13549+ =/ view-body=expr
13550+ ?- -.val.view-def
13551+ %gate body.val.view-def
13552+ %gate-wide body.val.view-def
13553+ * !!
13554+ ==
13555+ =/ sites=(unit (list iview-site)) (program-view-sites view-body ~)
13556+ ?~ sites ~
13557+ ?. ?=([* ~] u.sites) ~
13558+ =/ site=iview-site i.u.sites
13559+ =/ component-names=(list term) ~[init.parts update.parts view.parts subs.parts]
13560+ ?: (lien component-names |=(n=term =(n mapper.site))) ~
13561+ ?^ (ienv-lookup mapper.site env) ~
13562+ =/ mappers=(list def)
13563+ (skim ds |=(d=def &(?=(%value -.d) =(mapper.site name.d))))
13564+ ?. ?=([* ~] mappers) ~
13565+ =/ mapper-def=def i.mappers
13566+ ?> ?=(%value -.mapper-def)
13567+ =/ written-mapper=(unit sample) (direct-gate-sample mapper-def)
13568+ ?~ written-mapper ~
13569+ ?~ prelude.initial ~
13570+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
13571+ =/ each-scheme=(unit ischeme) (ienv-lookup %each values.u.prelude.initial)
13572+ =/ turn-scheme=(unit ischeme) (ienv-lookup %turn values.u.prelude.initial)
13573+ =/ element=(unit ischeme) (find-jibb-mold %element u.prelude.initial)
13574+ =/ list-template=(unit ischeme) (find-jibb-mold %list u.prelude.initial)
13575+ ?~ program ~
13576+ ?~ each-scheme ~
13577+ ?~ turn-scheme ~
13578+ ?~ element ~
13579+ ?~ list-template ~
13580+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
13581+ ?~ heads ~
13582+ =/ written-program=(unit def) (~(get by gates.u.heads) %program)
13583+ =/ written-each=(unit def) (~(get by gates.u.heads) %each)
13584+ =/ written-turn=(unit def) (~(get by gates.u.heads) %turn)
13585+ ?~ written-program ~
13586+ ?~ written-each ~
13587+ ?~ written-turn ~
13588+ =/ program-sample=(unit sample) (direct-gate-sample u.written-program)
13589+ =/ each-sample=(unit sample) (direct-gate-sample u.written-each)
13590+ =/ turn-sample=(unit sample) (direct-gate-sample u.written-turn)
13591+ ?~ program-sample ~
13592+ ?~ each-sample ~
13593+ ?~ turn-sample ~
13594+ ?. ?=(%cell -.u.program-sample) ~
13595+ ?. ?=([* * * * ~] items.u.program-sample) ~
13596+ =/ turn-names=(unit [first=(unit term) second=(unit term)])
13597+ (program-two-slot-names u.turn-sample)
13598+ ?~ turn-names ~
13599+ =/ checked=(map term def) (direct-checked-gates ds env)
13600+ =/ templates=ienv
13601+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13602+ =/ scanned=(unit dgscan)
13603+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13604+ ?~ scanned ~
13605+ =. next.initial (dg-next-id ids.u.scanned 0)
13606+ =/ view-state=istate (reserve-def-caps val.view-def initial)
13607+ =/ sam=isample-result (infer-sample u.written-view env view-state)
13608+ ?: ?=(%| -.sam) ~
13609+ =/ actual-model=itype (program-inferred-sample typ.p.sam u.written-view)
13610+ =/ model-fit=ifit
13611+ (direct-invariant actual-model model.u.relation sub.state.p.sam next.state.p.sam)
13612+ ?. ?=(%ok -.model-fit) ~
13613+ =/ xs-result=iresult
13614+ (infer-fragment xs.site env.p.sam state.p.sam(sub sub.model-fit, next next.model-fit))
13615+ ?: ?=(%| -.xs-result) ~
13616+ =/ element-var=itype [%var next.state.p.xs-result]
13617+ =/ list-a=(unit itype) (template-apply u.list-template ~[element-var])
13618+ ?~ list-a ~
13619+ =/ xs-fit=ifit
13620+ (itype-fit typ.p.xs-result u.list-a sub.state.p.xs-result +(next.state.p.xs-result))
13621+ ?. ?=(%ok -.xs-fit) ~
13622+ =/ closed-xs=itype (itype-normalize u.list-a sub.xs-fit)
13623+ ?^ (itype-vars closed-xs) ~
13624+ ?: (itype-has-tag closed-xs) ~
13625+ =/ each-instance=[typ=itype state=istate]
13626+ (instantiate-scheme u.each-scheme state.p.xs-result(sub sub.xs-fit, next next.xs-fit))
13627+ ?. ?=(%fn -.typ.each-instance) ~
13628+ =/ turn-instance=[typ=itype state=istate]
13629+ (instantiate-scheme u.turn-scheme state.each-instance)
13630+ ?. ?=(%fn -.typ.turn-instance) ~
13631+ ?. ?=(%cell -.sample.typ.turn-instance) ~
13632+ =/ element-message=(unit itype)
13633+ (template-apply u.element ~[message.u.relation])
13634+ ?~ element-message ~
13635+ =/ each-fit=ifit
13636+ (itype-fit product.typ.each-instance u.element-message sub.state.turn-instance next.state.turn-instance)
13637+ ?. ?=(%ok -.each-fit) ~
13638+ =/ each-input=itype
13639+ (program-inferred-sample sample.typ.each-instance u.each-sample)
13640+ =/ turn-fit=ifit
13641+ (itype-fit product.typ.turn-instance each-input sub.each-fit next.each-fit)
13642+ ?. ?=(%ok -.turn-fit) ~
13643+ =/ turn-list=itype
13644+ (program-inferred-slot hed.sample.typ.turn-instance first.u.turn-names)
13645+ =/ list-fit=ifit
13646+ (itype-fit closed-xs turn-list sub.turn-fit next.turn-fit)
13647+ ?. ?=(%ok -.list-fit) ~
13648+ =/ mapper-type=itype
13649+ (program-inferred-slot tal.sample.typ.turn-instance second.u.turn-names)
13650+ =/ expected-mapper=itype (itype-normalize mapper-type sub.list-fit)
13651+ ?. ?=(%fn -.expected-mapper) ~
13652+ ?^ (itype-vars sample.expected-mapper) ~
13653+ ?: (itype-has-tag sample.expected-mapper) ~
13654+ :: These faces come from the source-backed each sample. Keeping them in
13655+ :: the expected mapper product lets ordinary tuple inference supply key/el.
13656+ ?. ?=(%cell -.product.expected-mapper) ~
13657+ ?. ?=(%face -.hed.product.expected-mapper) ~
13658+ ?. =(%key name.hed.product.expected-mapper) ~
13659+ ?. ?=(%face -.tal.product.expected-mapper) ~
13660+ ?. =(%el name.tal.product.expected-mapper) ~
13661+ =/ mapper-state=istate
13662+ (reserve-def-caps val.mapper-def initial(next next.list-fit))
13663+ =/ mapper-sam=isample-result (infer-sample u.written-mapper env mapper-state)
13664+ ?: ?=(%| -.mapper-sam) ~
13665+ =/ mapper-input=itype (program-inferred-sample typ.p.mapper-sam u.written-mapper)
13666+ =/ mapper-sample-fit=ifit
13667+ (direct-invariant mapper-input sample.expected-mapper sub.state.p.mapper-sam next.state.p.mapper-sam)
13668+ ?. ?=(%ok -.mapper-sample-fit) ~
13669+ =/ mapper-product=itype
13670+ (itype-normalize product.expected-mapper sub.mapper-sample-fit)
13671+ =/ mapper-body=expr
13672+ ?- -.val.mapper-def
13673+ %gate body.val.mapper-def
13674+ %gate-wide body.val.mapper-def
13675+ * !!
13676+ ==
13677+ =/ mapper-inferred=iresult
13678+ (infer-call-context-arg mapper-body mapper-product env.p.mapper-sam state.p.mapper-sam(sub sub.mapper-sample-fit, next next.mapper-sample-fit) (span-of mapper-body))
13679+ ?: ?=(%| -.mapper-inferred) ~
13680+ =/ ordinary-product-fit=ifit
13681+ (itype-fit typ.p.mapper-inferred mapper-product sub.state.p.mapper-inferred next.state.p.mapper-inferred)
13682+ =/ mapper-product-fit=ifit
13683+ ?: ?=(%ok -.ordinary-product-fit) ordinary-product-fit
13684+ (program-keyed-product-fit typ.p.mapper-inferred mapper-product u.element sub.state.p.mapper-inferred next.state.p.mapper-inferred)
13685+ ?. ?=(%ok -.mapper-product-fit) ~
13686+ =/ closed-mapper-product=itype
13687+ (itype-normalize mapper-product sub.mapper-product-fit)
13688+ ?^ (itype-vars closed-mapper-product) ~
13689+ ?: (itype-has-tag closed-mapper-product) ~
13690+ =/ merged-mapper-product=itype
13691+ (itype-merge-faces typ.p.mapper-inferred closed-mapper-product sub.mapper-product-fit)
13692+ =/ mapper-cast=itype [%fn typ.p.mapper-sam merged-mapper-product]
13693+ =/ closed-mapper=itype [%fn typ.p.mapper-sam closed-mapper-product]
13694+ =/ mapper-cast-fit=ifit
13695+ (itype-fit mapper-cast closed-mapper sub.mapper-product-fit next.mapper-product-fit)
13696+ ?. ?=(%ok -.mapper-cast-fit) ~
13697+ =/ merged-mapper=itype
13698+ (itype-merge-faces mapper-cast closed-mapper sub.mapper-cast-fit)
13699+ =/ mapper-adjusted=iresult
13700+ [%& merged-mapper state.p.mapper-inferred(sub sub.mapper-cast-fit, next next.mapper-cast-fit)]
13701+ =/ mapper-added=(unit iadded-definition)
13702+ (add-supported-result mapper-def mapper-adjusted mapper-state env checked artifacts.resolution)
13703+ ?~ mapper-added ~
13704+ =/ mapper-scheme=(unit ischeme) (ienv-lookup mapper.site env.u.mapper-added)
13705+ ?~ mapper-scheme ~
13706+ ?. ?=(~ vars.u.mapper-scheme) ~
13707+ ?. ?=(~ (itype-vars typ.u.mapper-scheme)) ~
13708+ =/ program-instance=[typ=itype state=istate]
13709+ (instantiate-scheme u.program state.p.sam(next next.mapper-cast-fit))
13710+ ?. ?=(%fn -.typ.program-instance) ~
13711+ ?. ?=(%cell -.sample.typ.program-instance) ~
13712+ ?. ?=(%cell -.tal.sample.typ.program-instance) ~
13713+ ?. ?=(%cell -.tal.tal.sample.typ.program-instance) ~
13714+ =/ expected-view=(unit itype)
13715+ (direct-slot-body hed.tal.tal.sample.typ.program-instance (direct-sample-name i.t.t.items.u.program-sample))
13716+ ?~ expected-view ~
13717+ ?. ?=(%fn -.u.expected-view) ~
13718+ =/ canonical-view=itype [%fn model.u.relation u.element-message]
13719+ =/ view-fit=ifit
13720+ (direct-invariant canonical-view u.expected-view sub.state.program-instance next.state.program-instance)
13721+ ?. ?=(%ok -.view-fit) ~
13722+ =/ closed-view=itype
13723+ (itype-normalize [%fn typ.p.sam u.element-message] sub.view-fit)
13724+ ?. ?=(%fn -.closed-view) ~
13725+ =/ view-env=ienv [[mapper.site u.mapper-scheme] env.p.sam]
13726+ =/ final-view-state=istate
13727+ (reserve-def-caps val.view-def state.p.sam(next next.view-fit, gate-defs checked.u.mapper-added, head-evidence heads))
13728+ =/ inferred=iresult
13729+ (infer-call-context-arg view-body product.closed-view view-env final-view-state (span-of view-body))
13730+ ?: ?=(%| -.inferred) ~
13731+ =/ product-fit=ifit
13732+ (itype-fit typ.p.inferred product.closed-view sub.state.p.inferred next.state.p.inferred)
13733+ ?. ?=(%ok -.product-fit) ~
13734+ =/ merged-product=itype
13735+ (itype-merge-faces typ.p.inferred product.closed-view sub.product-fit)
13736+ =/ actual-cast=itype [%fn typ.p.sam merged-product]
13737+ =/ cast=ifit
13738+ (itype-fit actual-cast closed-view sub.product-fit next.product-fit)
13739+ ?. ?=(%ok -.cast) ~
13740+ =/ merged=itype (itype-merge-faces actual-cast closed-view sub.cast)
13741+ =/ adjusted=iresult
13742+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
13743+ =/ added=(unit iadded-definition)
13744+ (add-supported-result view-def adjusted final-view-state env.u.mapper-added checked.u.mapper-added artifacts.u.mapper-added)
13745+ ?~ added ~
13746+ =/ recovered=(unit ischeme) (ienv-lookup view.parts env.u.added)
13747+ ?~ recovered ~
13748+ ?. ?=(~ vars.u.recovered) ~
13749+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13750+ `[env.u.added grouped.resolution artifacts.u.added]
13751+::
13752+++ program-init-null-sample
13753+ |= d=def
13754+ ^- ?
13755+ =/ written=(unit sample) (direct-gate-sample d)
13756+ ?~ written |
13757+ ?. ?=(%bare -.u.written) |
13758+ =/ sh=shape shape.u.written
13759+ ?. ?=(%const -.sh) |
13760+ =(%null form.lit.sh)
13761+::
13762+:: The tuple-ending-null initializer retry above intentionally keeps its own
13763+:: boundary. A direct null-sample initializer can instead receive the closed
13764+:: model already established by update, view and subscriptions.
13765+++ program-plain-init-context
13766+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
13767+ ^- (unit iresolved)
13768+ =/ env=ienv env.resolution
13769+ ?^ (ienv-lookup %main env) ~
13770+ ?^ (ienv-lookup init.parts env) ~
13771+ ?~ (ienv-lookup update.parts env) ~
13772+ ?~ (ienv-lookup view.parts env) ~
13773+ ?~ (ienv-lookup subs.parts env) ~
13774+ =/ relation=(unit [message=itype model=itype])
13775+ (program-update-relation update.parts ds env)
13776+ ?~ relation ~
13777+ =/ inits=(list def)
13778+ (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
13779+ ?. ?=([* ~] inits) ~
13780+ =/ init-def=def i.inits
13781+ ?> ?=(%value -.init-def)
13782+ ?. (program-init-null-sample init-def) ~
13783+ =/ written=(unit sample) (direct-gate-sample init-def)
13784+ ?~ written ~
13785+ =/ body=expr
13786+ ?- -.val.init-def
13787+ %gate body.val.init-def
13788+ %gate-wide body.val.init-def
13789+ * !!
13790+ ==
13791+ ?~ prelude.initial ~
13792+ ?~ (ienv-lookup %program values.u.prelude.initial) ~
13793+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
13794+ ?~ heads ~
13795+ ?~ (~(get by gates.u.heads) %program) ~
13796+ =/ checked=(map term def) (direct-checked-gates ds env)
13797+ =/ templates=ienv
13798+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13799+ =/ scanned=(unit dgscan)
13800+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13801+ ?~ scanned ~
13802+ =. next.initial (dg-next-id ids.u.scanned 0)
13803+ =/ init-state=istate (reserve-def-caps val.init-def initial)
13804+ =/ sam=isample-result (infer-sample u.written env init-state)
13805+ ?: ?=(%| -.sam) ~
13806+ ?. ?=(~ (itype-vars typ.p.sam)) ~
13807+ ?: (itype-has-tag typ.p.sam) ~
13808+ =/ st=istate state.p.sam(gate-defs checked, head-evidence heads)
13809+ =/ inferred=iresult
13810+ (infer-call-context-arg body model.u.relation env.p.sam st (span-of body))
13811+ ?: ?=(%| -.inferred) ~
13812+ =/ product-fit=ifit
13813+ (itype-fit typ.p.inferred model.u.relation sub.state.p.inferred next.state.p.inferred)
13814+ ?. ?=(%ok -.product-fit) ~
13815+ =/ merged-product=itype
13816+ (itype-merge-faces typ.p.inferred model.u.relation sub.product-fit)
13817+ =/ actual-cast=itype [%fn typ.p.sam merged-product]
13818+ =/ closed=itype [%fn typ.p.sam model.u.relation]
13819+ =/ cast=ifit
13820+ (itype-fit actual-cast closed sub.product-fit next.product-fit)
13821+ ?. ?=(%ok -.cast) ~
13822+ =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
13823+ =/ adjusted=iresult
13824+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
13825+ =/ added=(unit iadded-definition)
13826+ (add-supported-result init-def adjusted init-state env checked artifacts.resolution)
13827+ ?~ added ~
13828+ =/ recovered=(unit ischeme) (ienv-lookup init.parts env.u.added)
13829+ ?~ recovered ~
13830+ ?. ?=(~ vars.u.recovered) ~
13831+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13832+ `[env.u.added grouped.resolution artifacts.u.added]
13833+::
13834+:: Recover only the initializer of an already recognized direct program main.
13835+:: The derived call is evidence for an ordinary init/main retry, never an
13836+:: interface to publish on its own. Any failure returns the original resolution.
13837+++ program-init-context
13838+ |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
13839+ ^- (unit iresolved)
13840+ =/ env=ienv env.resolution
13841+ ?^ (ienv-lookup %main env) ~
13842+ ?^ (ienv-lookup init.parts env) ~
13843+ =/ update=(unit ischeme) (ienv-lookup update.parts env)
13844+ =/ view=(unit ischeme) (ienv-lookup view.parts env)
13845+ =/ subs=(unit ischeme) (ienv-lookup subs.parts env)
13846+ ?~ update ~
13847+ ?~ view ~
13848+ ?~ subs ~
13849+ =/ inits=(list def)
13850+ (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
13851+ ?. ?=([* ~] inits) ~
13852+ =/ init-def=def i.inits
13853+ ?> ?=(%value -.init-def)
13854+ ?. (program-init-tuple-null init-def) ~
13855+ =/ args=(unit (list expr)) (program-main-args main)
13856+ ?~ args ~
13857+ ?~ prelude.initial ~
13858+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
13859+ ?~ program ~
13860+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
13861+ ?~ heads ~
13862+ =/ written=(unit def) (~(get by gates.u.heads) %program)
13863+ ?~ written ~
13864+ =/ written-sample=(unit sample) (direct-gate-sample u.written)
13865+ ?~ written-sample ~
13866+ ?. ?=(%cell -.u.written-sample) ~
13867+ ?~ items.u.written-sample ~
13868+ =/ checked=(map term def) (direct-checked-gates ds env)
13869+ =/ templates=ienv
13870+ (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
13871+ =/ scanned=(unit dgscan)
13872+ (dg-all-env-ids (weld env (weld values.u.prelude.initial templates)) 32.768 ~)
13873+ ?~ scanned ~
13874+ =. next.initial (dg-next-id ids.u.scanned 0)
13875+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.program initial)
13876+ ?. ?=(%fn -.typ.instance) ~
13877+ ?. ?=(%cell -.sample.typ.instance) ~
13878+ =/ expected-init=(unit itype)
13879+ (direct-slot-body hed.sample.typ.instance (direct-sample-name i.items.u.written-sample))
13880+ ?~ expected-init ~
13881+ ?. ?=(%fn -.u.expected-init) ~
13882+ ?. ?=(%var -.sample.u.expected-init) ~
13883+ =/ data=@ud id.sample.u.expected-init
13884+ =/ init-var=itype [%var next.state.instance]
13885+ =/ st=istate state.instance(next +(next.state.instance))
13886+ =/ up=[typ=itype state=istate] (instantiate-scheme u.update st)
13887+ =/ vw=[typ=itype state=istate] (instantiate-scheme u.view state.up)
13888+ =/ sb=[typ=itype state=istate] (instantiate-scheme u.subs state.vw)
13889+ =. st state.sb(gate-defs checked, head-evidence heads)
13890+ =/ actual=itype [%cell init-var [%cell typ.up [%cell typ.vw typ.sb]]]
13891+ =/ fit=ifit
13892+ (direct-positional-fit u.args items.u.written-sample actual sample.typ.instance env st sub.st next.st)
13893+ ?. ?=(%ok -.fit) ~
13894+ =/ actual-final=itype (itype-normalize actual sub.fit)
13895+ =/ expected-final=itype (itype-normalize sample.typ.instance sub.fit)
13896+ =/ open=(list @ud)
13897+ (unique-type-vars (weld (itype-vars actual-final) (itype-vars expected-final)))
13898+ ?. (levy open |=(n=@ud =(data n))) ~
13899+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
13900+ =/ replay=ifit
13901+ (direct-positional-fit u.args items.u.written-sample actual sample.typ.instance env st sub.fit next.fit)
13902+ ?. ?=(%ok -.replay) ~
13903+ ?. &(=(sub.fit sub.replay) =(next.fit next.replay)) ~
13904+ =/ expected=itype (itype-normalize u.expected-init sub.fit)
13905+ ?. ?=(%fn -.expected) ~
13906+ =. st st(sub sub.fit, next next.fit)
13907+ =/ init-state=istate (reserve-def-caps val.init-def st)
13908+ =/ inferred=iresult (infer-fragment val.init-def env init-state)
13909+ =? inferred ?=(%| -.inferred) (infer-recursive-gate init-def env init-state)
13910+ ?: ?=(%| -.inferred) ~
13911+ ?. ?=(%fn -.typ.p.inferred) ~
13912+ ?^ (itype-vars sample.typ.p.inferred) ~
13913+ =/ data-fit=ifit
13914+ (itype-fit sample.typ.p.inferred sample.expected sub.state.p.inferred next.state.p.inferred)
13915+ ?. ?=(%ok -.data-fit) ~
13916+ =/ closed=itype (itype-normalize expected sub.data-fit)
13917+ ?. ?=(%fn -.closed) ~
13918+ :: Resolve the ordinary tuple cast first, then check the complete gate.
13919+ :: General function fit remains unchanged; only this recovered candidate
13920+ :: receives the derived result context before its whole-type cast fit.
13921+ =/ product-fit=ifit
13922+ (itype-fit product.typ.p.inferred product.closed sub.data-fit next.data-fit)
13923+ ?. ?=(%ok -.product-fit) ~
13924+ =/ product=itype
13925+ (itype-merge-faces product.typ.p.inferred product.closed sub.product-fit)
13926+ =/ actual-cast=itype [%fn sample.typ.p.inferred product]
13927+ =/ cast=ifit
13928+ (itype-fit actual-cast closed sub.product-fit next.product-fit)
13929+ ?. ?=(%ok -.cast) ~
13930+ =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
13931+ =/ adjusted=iresult
13932+ [%& merged state.p.inferred(sub sub.cast, next next.cast)]
13933+ =/ added=(unit iadded-definition)
13934+ (add-supported-result init-def adjusted init-state env checked artifacts.resolution)
13935+ ?~ added ~
13936+ =/ recovered=(unit ischeme) (ienv-lookup init.parts env.u.added)
13937+ ?~ recovered ~
13938+ ?. ?=(~ vars.u.recovered) ~
13939+ ?. ?=(~ (itype-vars typ.u.recovered)) ~
13940+ `[env.u.added grouped.resolution artifacts.u.added]
13941+::
13942+++ derived-poke-command-scheme
13943+ |= [prelude=ifile action=itype]
13944+ ^- (unit ischeme)
13945+ =/ prep=iprelude [prelude ~ ~]
13946+ =/ raw=(unit ischeme) (compatible-raw-poke prep)
13947+ ?~ raw ~
13948+ =/ command=(unit ischeme) (find-jibb-mold %cmd prelude)
13949+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit prelude)
13950+ ?~ command ~
13951+ ?~ unit-template ~
13952+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
13953+ ?. ?=([@ ~] vars.u.command) ~
13954+ ?. ?=(%union -.typ.u.command) ~
13955+ ?. =(origin.typ.u.command `[/lib/jibb/prelude/jibb %cmd]) ~
13956+ ?. (identity-union-parameters vars.u.command args.typ.u.command) ~
13957+ =/ m=@ud i.vars.u.command
13958+ ?: (itype-var-is-atom m typ.u.command) ~
13959+ ?. (levy (itype-vars typ.u.command) |=(n=@ud =(n m))) ~
13960+ ?: (itype-has-tag typ.u.command) ~
13961+ =/ error=(unit itype) (template-apply u.unit-template ~[[%atom %t]])
13962+ ?~ error ~
13963+ ?. ?=(%union -.typ.u.raw) ~
13964+ =/ poke-case=itype
13965+ [%cell [%const [%term %tas %poke '%poke']] [%cell [%face %p typ.u.raw(label `'raw-poke.internal')] [%face %reply [%fn u.error [%var m]]]]]
13966+ =/ go-case=itype
13967+ [%cell [%const [%term %tas %go '%go']] [%face %url [%atom %t]]]
13968+ =/ wait-case=itype
13969+ [%cell [%const [%term %tas %wait '%wait']] [%cell [%face %gap [%atom %dr]] [%face %msg [%var m]]]]
13970+ =/ now-case=itype
13971+ [%cell [%const [%term %tas %now '%now']] [%face %reply [%fn [%atom %da] [%var m]]]]
13972+ =/ who-case=itype
13973+ [%cell [%const [%term %tas %who '%who']] [%face %reply [%fn [%atom %p] [%var m]]]]
13974+ ?. =(cases.typ.u.command ~[poke-case go-case wait-case now-case who-case]) ~
13975+ =/ command-result=(unit itype) (template-apply u.command ~[[%var 0]])
13976+ ?~ command-result ~
13977+ `[[%fn [%cell action [%fn u.error [%var 0]]] u.command-result] ~[0]]
13978+::
13979+++ store-derived-schemes
13980+ |= [prelude=ifile values=(list term) molds=(list term) state=itype action=itype]
13981+ ^- (unit [state=ischeme action=ischeme])
13982+ =/ prep=iprelude [prelude values molds]
13983+ =/ ask=(unit ischeme) (request-compatible-ask prep)
13984+ ?~ ask ~
13985+ ?^ (itype-vars state) ~
13986+ ?^ (itype-vars action) ~
13987+ ?: |((itype-has-tag state) (itype-has-tag action)) ~
13988+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
13989+ ?~ result ~
13990+ =/ request=ischeme [[%fn [%fn state [%var 0]] u.result] ~[0]]
13991+ =/ constructor=(unit ischeme) (derived-poke-command-scheme prelude action)
13992+ ?~ constructor ~
13993+ `[request u.constructor]
13994+::
13995+++ program-subs-watch
13996+ |= [d=def imports=ijimports graph=irequest-graph prelude=ifile]
13997+ ^- ?
13998+ ?. ?=(%value -.d) |
13999+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) |
14000+ =/ body=expr
14001+ ?- -.val.d
14002+ %gate body.val.d
14003+ %gate-wide body.val.d
14004+ * val.d
14005+ ==
14006+ =. body (program-transparent body)
14007+ ?. ?=(%list -.body) |
14008+ ?. ?=([* ~] items.body) |
14009+ =/ watch=expr (program-transparent i.items.body)
14010+ ?. ?=(%tuple -.watch) |
14011+ ?. ?=([* * ~] items.watch) |
14012+ =/ tag=item i.items.watch
14013+ =/ payload=item i.t.items.watch
14014+ ?. &(?=(~ face.tag) ?=(~ face.payload)) |
14015+ =/ tag-expr=expr (program-transparent val.tag)
14016+ ?. ?=(%lit -.tag-expr) |
14017+ ?. &(?=(%term form.lit.tag-expr) =(%watch val.lit.tag-expr)) |
14018+ =/ request=expr (program-transparent val.payload)
14019+ ?. ?=(%call -.request) |
14020+ ?. ?=([* ~] args.request) |
14021+ =/ head=expr (program-transparent head.request)
14022+ ?. ?=(%wing -.head) |
14023+ ?. ?=([@ @ ~] names.head) |
14024+ =/ case=term i.names.head
14025+ =/ face=term i.t.names.head
14026+ =/ callback=expr (program-transparent i.args.request)
14027+ ?. ?=(%ctor -.callback) |
14028+ ?. ?=(%term form.tag.callback) |
14029+ ?| ?=(^ (derived-request-member case face imports graph prelude))
14030+ ?=(^ (derived-store-request-member case face imports graph prelude))
14031+ ==
14032+::
14033+:: Exact derived-member and request-evidence identity, shared by direct
14034+:: program watches and direct data-page loads. Only a plain request in the
14035+:: selected interface's own source-backed graph can establish this shape.
14036+++ derived-request-member
14037+ |= [case=term face=term imports=ijimports graph=irequest-graph prelude=ifile]
14038+ ^- (unit ischeme)
14039+ =/ selected=(list [face=term interface=ifile])
14040+ (skim imports |=(j=[face=term interface=ifile] =(face face.j)))
14041+ ?. ?=([* ~] selected) ~
14042+ =/ iface=ifile interface.i.selected
14043+ =/ member=(unit ischeme) (ienv-lookup case values.iface)
14044+ ?~ member ~
14045+ ?~ source.iface ~
14046+ =/ evidence=(list irequest-evidence)
14047+ (skim requests.graph |=(r=irequest-evidence &(=(api-at.r at.iface) =(name.r case))))
14048+ ?. ?=([* ~] evidence) ~
14049+ =/ request-evidence=irequest-evidence i.evidence
14050+ ?. =(u.source.iface api-source.request-evidence) ~
14051+ ?. =(name.path.path.request-evidence case) ~
14052+ ?~ graph.iface ~
14053+ ?. (lien requests.u.graph.iface |=(r=irequest-evidence =(r request-evidence))) ~
14054+ ?. ?=(~ scry.path.path.request-evidence) ~
14055+ ?. &(?=(~ diffs.path.request-evidence) ?=(~ diffs.path.path.request-evidence)) ~
14056+ ?: (lien segments.path.path.request-evidence |=(p=pseg !?=(%knot -.p))) ~
14057+ ?. ?=([@ ~] vars.u.member) ~
14058+ =/ message=@ud i.vars.u.member
14059+ ?. ?=(%fn -.typ.u.member) ~
14060+ ?. ?=(%fn -.sample.typ.u.member) ~
14061+ ?. =(sample.sample.typ.u.member full.path.request-evidence) ~
14062+ ?. =(product.sample.typ.u.member [%var message]) ~
14063+ =/ prep=iprelude [prelude prelude-values.graph prelude-molds.graph]
14064+ =/ ask=(unit ischeme) (request-compatible-ask prep)
14065+ ?~ ask ~
14066+ =/ result=(unit itype) (template-apply u.ask ~[[%var message]])
14067+ ?~ result ~
14068+ ?. =(product.typ.u.member u.result) ~
14069+ member
14070+::
14071+:: Store state is watchable by definition, but only the actual derived member
14072+:: of the uniquely selected source-bound store interface proves that fact.
14073+++ derived-store-request-member
14074+ |= [case=term face=term imports=ijimports graph=irequest-graph prelude=ifile]
14075+ ^- (unit ischeme)
14076+ ?. =(%state case) ~
14077+ =/ selected=(list [face=term interface=ifile])
14078+ (skim imports |=(j=[face=term interface=ifile] =(face face.j)))
14079+ ?. ?=([* ~] selected) ~
14080+ =/ iface=ifile interface.i.selected
14081+ =/ member=(unit ischeme) (ienv-lookup %state values.iface)
14082+ ?~ member ~
14083+ ?~ source.iface ~
14084+ =/ evidence=(list istore-request-evidence)
14085+ (skim stores.graph |=(r=istore-request-evidence =(store-at.r at.iface)))
14086+ ?. ?=([* ~] evidence) ~
14087+ =/ request=istore-request-evidence i.evidence
14088+ ?. =(u.source.iface source.request) ~
14089+ ?~ graph.iface ~
14090+ ?. (lien stores.u.graph.iface |=(r=istore-request-evidence =(r request))) ~
14091+ =/ derived=(unit [state=ischeme action=ischeme])
14092+ (store-derived-schemes prelude prelude-values.graph prelude-molds.graph state.request action.request)
14093+ ?~ derived ~
14094+ ?. =(u.member state.u.derived) ~
14095+ =/ constructor=(unit ischeme) (ienv-lookup action-name.request values.iface)
14096+ ?~ constructor ~
14097+ ?. =(u.constructor action.u.derived) ~
14098+ member
14099+::
14100+++ program-main-context
14101+ |= [main=def ds=(list def) resolution=iresolved initial=istate]
14102+ ^- iresolved
14103+ ?^ (ienv-lookup %main env.resolution) resolution
14104+ =/ heads=(unit igate-prelude-evidence)
14105+ (direct-prelude-evidence ds prelude.initial)
14106+ ?~ heads resolution
14107+ =/ checked=(map term def) (direct-checked-gates ds env.resolution)
14108+ =/ completed=[env=ienv artifacts=(list iwidth-definition)]
14109+ (add-supported-defs-core ~[main] ds checked heads env.resolution molds.initial globals.initial externals.initial surs.initial mark-externals.initial marks.initial jimports.initial reserved-molds.initial at.initial prelude.initial artifacts.resolution grec-index.initial)
14110+ [env.completed grouped.resolution artifacts.completed]
14111+::
14112+:: A static main may retain a generic element message in its ordinary
14113+:: scheme. Instantiate that scheme, specialize it to canonical element !!,
14114+:: and publish only the resulting closed scheme.
14115+++ static-main-specialized
14116+ |= [env=ienv prelude=(unit ifile)]
14117+ ^- (unit ischeme)
14118+ ?~ prelude ~
14119+ =/ element=(unit ischeme) (find-jibb-mold %element u.prelude)
14120+ ?~ element ~
14121+ =/ main=(unit ischeme) (ienv-lookup %main env)
14122+ ?~ main ~
14123+ =/ canonical=(unit itype) (template-apply u.element ~[[%empty ~]])
14124+ ?~ canonical ~
14125+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.main *istate)
14126+ =/ fit=ifit (itype-fit typ.instance u.canonical ~ next.state.instance)
14127+ ?. ?=(%ok -.fit) ~
14128+ =/ closed=itype (itype-normalize typ.instance sub.fit)
14129+ ?^ (itype-vars closed) ~
14130+ ?: (itype-has-tag closed) ~
14131+ ?. ?=(%union -.closed) ~
14132+ ?. ?=(%union -.u.canonical) ~
14133+ ?. &(=(origin.closed origin.u.canonical) =(args.closed args.u.canonical)) ~
14134+ =/ exact=ifit (direct-invariant closed u.canonical ~ next.fit)
14135+ ?. ?=(%ok -.exact) ~
14136+ `[u.canonical ~]
14137+::
14138+:: The load of a direct data page must itself be a direct gate whose
14139+:: transparent body is one plain derived request with a wing or ctor reply.
14140+++ page-load-derived
14141+ |= [name=term ds=(list def) imports=ijimports graph=irequest-graph prelude=ifile]
14142+ ^- ?
14143+ =/ loads=(list def)
14144+ (skim ds |=(d=def &(?=(%value -.d) =(name name.d))))
14145+ ?. ?=([* ~] loads) |
14146+ =/ load=def i.loads
14147+ ?> ?=(%value -.load)
14148+ ?. |(?=(%gate -.val.load) ?=(%gate-wide -.val.load)) |
14149+ =/ body=expr
14150+ ?- -.val.load
14151+ %gate body.val.load
14152+ %gate-wide body.val.load
14153+ * !!
14154+ ==
14155+ =. body (program-transparent body)
14156+ ?. ?=(%call -.body) |
14157+ ?. ?=([* ~] args.body) |
14158+ =/ head=expr (program-transparent head.body)
14159+ ?. ?=(%wing -.head) |
14160+ ?. ?=([@ @ ~] names.head) |
14161+ =/ reply=expr (program-transparent i.args.body)
14162+ ?. ?| &(?=(%wing -.reply) ?=([@ ~] names.reply))
14163+ &(?=(%ctor -.reply) ?=(%term form.tag.reply))
14164+ ==
14165+ |
14166+ ?=(^ (derived-request-member i.names.head i.t.names.head imports graph prelude))
14167+::
14168+++ page-main-closed
14169+ |= [parts=[load=term view=term] ds=(list def) env=ienv prelude=(unit ifile) imports=ijimports graph=irequest-graph]
14170+ ^- ?
14171+ ?~ prelude |
14172+ =/ page=(unit ischeme) (find-jibb-mold %page u.prelude)
14173+ ?~ page |
14174+ =/ main=(unit ischeme) (ienv-lookup %main env)
14175+ ?~ main |
14176+ ?. ?=(~ vars.u.main) |
14177+ ?. ?=(~ (itype-vars typ.u.main)) |
14178+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.page *istate)
14179+ =/ main-fit=ifit (direct-invariant typ.u.main typ.instance ~ next.state.instance)
14180+ ?. ?=(%ok -.main-fit) |
14181+ (page-load-derived load.parts ds imports graph u.prelude)
14182+::
14183+++ program-main-closed
14184+ |= [parts=[init=term update=term view=term subs=term] ds=(list def) env=ienv prelude=(unit ifile) imports=ijimports graph=irequest-graph]
14185+ ^- ?
14186+ ?~ prelude |
14187+ ?~ (ienv-lookup %program values.u.prelude) |
14188+ =/ program=(unit ischeme) (find-jibb-mold %program u.prelude)
14189+ ?~ program |
14190+ =/ main=(unit ischeme) (ienv-lookup %main env)
14191+ ?~ main |
14192+ ?. ?=(~ vars.u.main) |
14193+ ?. ?=(~ (itype-vars typ.u.main)) |
14194+ =/ instance=[typ=itype state=istate] (instantiate-scheme u.program *istate)
14195+ =/ main-fit=ifit (direct-invariant typ.u.main typ.instance ~ next.state.instance)
14196+ ?. ?=(%ok -.main-fit) |
14197+ =/ init=(unit ischeme) (ienv-lookup init.parts env)
14198+ ?~ init |
14199+ ?. ?=(~ vars.u.init) |
14200+ ?. ?=(%fn -.typ.u.init) |
14201+ ?. ?=(~ (itype-vars sample.typ.u.init)) |
14202+ ?. ?=(~ (itype-vars product.typ.u.init)) |
14203+ =/ data=igate-free (gate-free-type sample.typ.u.init 256 ~)
14204+ ?. =(%yes verdict.data) |
14205+ =/ model=igate-free (gate-free-type product.typ.u.init left.data ~)
14206+ ?. =(%yes verdict.model) |
14207+ =/ subs=(list def)
14208+ (skim ds |=(d=def &(?=(%value -.d) =(subs.parts name.d))))
14209+ ?. ?=([* ~] subs) |
14210+ |((program-subs-empty i.subs) (program-subs-watch i.subs imports graph u.prelude))
14211+::
14212+:: The two outer sample faces are binder names, not part of the action/state
14213+:: relation. Leave every face inside either component untouched.
14214+++ store-update-unfaced
14215+ |= typ=itype
14216+ ^- itype
14217+ ?. ?=(%fn -.typ) typ
14218+ ?. ?=(%cell -.sample.typ) typ
14219+ =/ head=itype hed.sample.typ
14220+ =/ tail=itype tal.sample.typ
14221+ =? head ?=(%face -.head) body.head
14222+ =? tail ?=(%face -.tail) body.tail
14223+ typ(sample [%cell head tail])
14224+::
14225+:: The builder erases the action from main. Recover it only from the local
14226+:: poke mold and check both ordinary components invariantly.
14227+++ store-main-closed
14228+ |= [parts=[init=term update=term] action=term env=ienv molds=imold-types prelude=(unit ifile)]
14229+ ^- (unit ischeme)
14230+ ?~ prelude ~
14231+ =/ builder=(unit ischeme) (ienv-lookup %store values.u.prelude)
14232+ ?~ builder ~
14233+ ?. ?=([@ @ ~] vars.u.builder) ~
14234+ =/ state-var=@ud i.vars.u.builder
14235+ =/ action-var=@ud i.t.vars.u.builder
14236+ ?: =(state-var action-var) ~
14237+ =/ builder-sample=itype
14238+ [%cell [%face %init [%var state-var]] [%face %update [%fn [%cell [%var action-var] [%var state-var]] [%var state-var]]]]
14239+ =/ builder-product=itype [%cell [%face %init [%var state-var]] [%face %update [%noun ~]]]
14240+ ?. =(typ.u.builder [%fn builder-sample builder-product]) ~
14241+ =/ store=(unit ischeme) (find-jibb-mold %store u.prelude)
14242+ ?~ store ~
14243+ ?. ?=([@ ~] vars.u.store) ~
14244+ ?. =(typ.u.store [%cell [%face %init [%var i.vars.u.store]] [%face %update [%noun ~]]]) ~
14245+ =/ state=(unit ischeme) (find-jibb-mold %state [~ molds /tmp ~ ~ ~ ~ ~])
14246+ ?~ state ~
14247+ =/ action-mold=(unit ischeme) (find-jibb-mold action [~ molds /tmp ~ ~ ~ ~ ~])
14248+ ?~ action-mold ~
14249+ ?. &(?=(~ vars.u.state) ?=(~ (itype-vars typ.u.state))) ~
14250+ ?. &(?=(~ vars.u.action-mold) ?=(~ (itype-vars typ.u.action-mold))) ~
14251+ =/ canonical=(unit itype) (template-apply u.store ~[typ.u.state])
14252+ ?~ canonical ~
14253+ =/ main=(unit ischeme) (ienv-lookup %main env)
14254+ =/ main-fit=(unit ifit)
14255+ ?~(main ~ `(direct-invariant typ.u.main u.canonical ~ 0))
14256+ =/ main-ok=?
14257+ ?~ main &
14258+ ?. ?=(~ vars.u.main) |
14259+ ?. ?=(~ (itype-vars typ.u.main)) |
14260+ ?~ main-fit |
14261+ ?=(%ok -.u.main-fit)
14262+ ?. main-ok ~
14263+ =/ init=(unit ischeme) (ienv-lookup init.parts env)
14264+ ?~ init ~
14265+ ?. ?=(~ vars.u.init) ~
14266+ ?. ?=(~ (itype-vars typ.u.init)) ~
14267+ =/ init-fit=ifit (direct-invariant typ.u.init typ.u.state ~ 0)
14268+ ?. ?=(%ok -.init-fit) ~
14269+ =/ update=(unit ischeme) (ienv-lookup update.parts env)
14270+ ?~ update ~
14271+ ?. ?=(~ vars.u.update) ~
14272+ ?. ?=(~ (itype-vars typ.u.update)) ~
14273+ =/ expected=itype [%fn [%cell typ.u.action-mold typ.u.state] typ.u.state]
14274+ =/ update-fit=ifit (direct-invariant (store-update-unfaced typ.u.update) expected ~ 0)
14275+ ?. ?=(%ok -.update-fit) ~
14276+ `[u.canonical ~]
14277+::
767014278++ infer-jibb-file
767114279 |= [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)]
767214280 ^- jfile-result
7673− ?: ?=([%ui %api *] at) [%| (crip "API module needs unsupported inference: {(spud at)}")]
14281+ =/ out=jfile-detailed-result
14282+ (infer-jibb-file-detailed at src externals mark-externals modules active prelude-values prelude-molds cache prelude)
14283+ ?: ?=(%| -.out) [%| message.p.out]
14284+ [%& p.out]
14285+:: Returns structured root-source overlap evidence after the same full check.
14286+++ infer-jibb-file-detailed
14287+ |= [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)]
14288+ ^- jfile-detailed-result
767414289 =/ parsed (parse at src)
7675− ?: ?=(%| -.parsed) [%| (crip "module source does not parse: {(spud at)}")]
14290+ ?: ?=(%| -.parsed) [%| [(crip "module source does not parse: {(spud at)}") ~]]
767614291 =/ mod=module p.parsed
7677− ?. (module-scope-valid mod prelude-values prelude-molds) [%| (crip "module has conflicting names: {(spud at)}")]
7678− =/ vals=(list term) (global-value-names defs.mod)
7679− ?: (lien vals |=(n=term =(n %main)))
7680− [%| (crip "module kind needs unsupported inference: {(spud at)}")]
7681− =/ js=jimports-result (resolve-jibb-imports imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
14292+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
14293+ ?^ duplicate [%| [(show-duplicate-fields at src u.duplicate) ~]]
14294+ ?: &(?=([%ui %api *] at) ?=(^ (program-main-def defs.mod)))
14295+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
14296+ ?: ?=([%ui %api *] at)
14297+ =/ iface=(unit ifile) (api-poke-interface at mod mark-externals prelude-values prelude-molds prelude)
14298+ ?^ iface
14299+ =/ checked=ifile u.iface(source `src, graph `[(silt `(list path)`~[at]) ~ ~ modules prelude prelude-values prelude-molds externals mark-externals])
14300+ [%& [checked [[at checked] cache]]]
14301+ ?~ prelude [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
14302+ =/ prepared=iprelude [u.prelude prelude-values prelude-molds]
14303+ =/ narrow=?
14304+ ?. ?=([[%mark *] ~] imports.mod) |
14305+ ?. ?=([[%mold *] ~] defs.mod) |
14306+ ?. =(%paths name.i.defs.mod) |
14307+ !?=(%union -.shape.i.defs.mod)
14308+ ?: narrow
14309+ =/ request=(each ione-request-interface @t)
14310+ (one-request-interface-graph at src externals mark-externals modules active cache `prepared)
14311+ ?: ?=(%| -.request) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
14312+ =/ checked=ifile iface.p.request
14313+ [%& [checked [[at checked] dependencies.paths.support.p.request]]]
14314+ =/ multi=(each [iface=ifile cache=jcache] @t)
14315+ (multi-request-interface-graph at src externals mark-externals modules active cache `prepared)
14316+ ?: ?=(%| -.multi) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
14317+ [%& [iface.p.multi [[at iface.p.multi] cache.p.multi]]]
14318+ =/ main=(unit def) (program-main-def defs.mod)
14319+ =/ main-parts=(unit [init=term update=term view=term subs=term])
14320+ ?~(main ~ (program-main-parts u.main))
14321+ =/ page-parts=(unit [load=term view=term])
14322+ ?~(main ~ (page-main-parts u.main))
14323+ =/ store-parts=(unit [init=term update=term])
14324+ ?~(main ~ (store-main-parts u.main))
14325+ =/ declared=(unit istore-declaration)
14326+ ?~(store-parts ~ (store-declaration mod prelude-values prelude-molds))
14327+ ?: &(?=(^ store-parts) ?=(~ declared))
14328+ [%| [(crip "module kind or scope needs unsupported inference: {(spud at)}") ~]]
14329+ ?: &(?=([%ui %stores *] at) ?=(^ main) ?=(~ store-parts))
14330+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
14331+ =/ ds=(list def) ?~(declared defs.mod defs.u.declared)
14332+ =/ checking=module mod(defs ds)
14333+ ?. (module-scope-valid checking prelude-values prelude-molds)
14334+ [%| [(crip "module has conflicting names: {(spud at)}") ~]]
14335+ =/ vals=(list term) (global-value-names ds)
14336+ =/ js=jimports-detailed-result (resolve-jibb-imports-detailed imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
768214337 ?: ?=(%| -.js) [%| p.js]
7683− =/ molds=imolds (collect-simple-molds defs.mod)
14338+ =/ collected=grec-collected
14339+ ?^ imports.mod [(collect-simple-molds ds) *(map term shape)]
14340+ (grec-collect-molds ds)
14341+ =/ molds=imolds molds.collected
768414342 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
768514343 =/ surs=(list term) (collect-sur-imports imports.mod)
768614344 =/ marks=(list term) (collect-mark-imports imports.mod)
768714345 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
768814346 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7689− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude]
7690− =/ mts=(each imold-types @t) (module-mold-types molds state)
7691− ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
7692− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
7693− ?. (module-values-complete defs.mod env)
7694− [%| (crip "module definitions need unsupported inference: {(spud at)}")]
7695− [%& [[env p.mts at] [[at [env p.mts at]] cache.p.js]]]
14347+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
14348+ :: Source and scope were checked above; preserve that exact root and prelude.
14349+ :: This first integration only indexes import-free library sources.
14350+ =/ index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])
14351+ ?^ imports.mod ~
14352+ ?~ prelude ~
14353+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude)
14354+ ?~ standard ~
14355+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
14356+ =/ index=(map term shape) proofs.collected
14357+ ?. !=(index *(map term shape)) ~
14358+ ?: (lien molds |=(m=[name=term body=shape] =(%list name.m))) ~
14359+ `[at src u.prelude index]
14360+ =. grec-index.state index
14361+ =/ mts=(each imold-types imold-failure) (module-mold-types-detail molds state)
14362+ ?: ?=(%| -.mts)
14363+ ?~ overlap.p.mts [%| [(crip "{(trip message.p.mts)}: {(spud at)}") ~]]
14364+ =/ witness=[name=term cases=upair] u.overlap.p.mts
14365+ =/ first=@t (show-error src [at line.beg.first.cases.witness col.beg.first.cases.witness "first union case"])
14366+ =/ second=@t (show-error src [at line.beg.second.cases.witness col.beg.second.cases.witness "overlapping case"])
14367+ =/ msg=@t (of-wain:format ~[(crip "module mold {(trip name.witness)} has overlapping cases") first second])
14368+ [%| [msg `[at src name.witness cases.witness]]]
14369+ =/ resolution=iresolved
14370+ ?~ index
14371+ (resolve-groups ds molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
14372+ (resolve-groups-core ds molds globals externals surs mark-externals marks resolved.p.js reserved at prelude index)
14373+ =/ env=ienv env.resolution
14374+ =/ recovered=iresolved
14375+ ?~ main resolution
14376+ ?~ main-parts resolution
14377+ =/ updated=(unit iresolved)
14378+ (program-update-context u.main u.main-parts ds resolution state)
14379+ =/ with-update=iresolved ?~(updated resolution u.updated)
14380+ =/ subscribed=(unit iresolved)
14381+ (program-subs-context u.main-parts ds with-update state)
14382+ =/ with-subs=iresolved ?~(subscribed with-update u.subscribed)
14383+ =/ viewed=(unit iresolved)
14384+ (program-view-context u.main-parts ds with-subs state)
14385+ =/ with-keyed-view=iresolved ?~(viewed with-subs u.viewed)
14386+ =/ plain-view=(unit iresolved)
14387+ ?^(viewed ~ (program-plain-view-context u.main-parts ds with-keyed-view state))
14388+ =/ with-view=iresolved ?~(plain-view with-keyed-view u.plain-view)
14389+ =/ initialized=(unit iresolved)
14390+ (program-init-context u.main u.main-parts ds with-view state)
14391+ =/ with-initialized=iresolved ?~(initialized with-view u.initialized)
14392+ =/ plain-init=(unit iresolved)
14393+ ?^(initialized ~ (program-plain-init-context u.main-parts ds with-initialized state))
14394+ =/ components=iresolved ?~(plain-init with-initialized u.plain-init)
14395+ (program-main-context u.main ds components state)
14396+ =. env env.recovered
14397+ =. artifacts.resolution artifacts.recovered
14398+ =. env
14399+ ?: (module-values-complete ds env) env
14400+ ?: |(?=([%ui %stores *] at) ?=(^ imports.mod) ?=(^ prelude) ?=(^ prelude-values) ?=(^ prelude-molds)) env
14401+ ?: (gth (met 3 src) 65.536) env
14402+ ?: (gth (lent ds) 64) env
14403+ ?. (dg-source-candidate ds 64) env
14404+ =/ transaction=(unit dgcommit) (dg-root-source at src)
14405+ ?~ transaction env
14406+ ?: (dg-interface-safe env.u.transaction) env.u.transaction
14407+ env
14408+ =/ required=(list def)
14409+ ?~ store-parts ds
14410+ (skim ds |=(d=def !&(?=(%value -.d) =(%main name.d))))
14411+ ?. (module-values-complete required env)
14412+ =/ pending=(unit [at=span msg=tape]) (module-pending-tag required env state 64)
14413+ ?^ pending
14414+ [%| [(show-error src [at line.beg.at.u.pending col.beg.at.u.pending msg.u.pending]) ~]]
14415+ [%| [(crip "module definitions need unsupported inference: {(spud at)}") ~]]
14416+ =/ initial=irequest-graph [(silt `(list path)`~[at]) ~ ~ modules prelude prelude-values prelude-molds externals mark-externals]
14417+ =/ graph=(unit irequest-graph) (request-graph-merge resolved.p.js initial (add 1 (lent resolved.p.js)))
14418+ ?~ graph [%| ['module request evidence needs unsupported inference' ~]]
14419+ =/ static-main=(unit ischeme)
14420+ ?~ main ~
14421+ ?^ main-parts ~
14422+ ?^ page-parts ~
14423+ ?^ store-parts ~
14424+ (static-main-specialized env prelude)
14425+ =? env ?=(^ static-main)
14426+ [[%main u.static-main] (skim env |=(entry=[name=term scheme=ischeme] !=(%main name.entry)))]
14427+ =/ store-main=(unit ischeme)
14428+ ?~ store-parts ~
14429+ ?~ declared ~
14430+ (store-main-closed u.store-parts action.u.declared env p.mts prelude)
14431+ =? env ?=(^ store-main)
14432+ [[%main u.store-main] (skim env |=(entry=[name=term scheme=ischeme] !=(%main name.entry)))]
14433+ =/ kind-ok=?
14434+ ?~ main &
14435+ ?^ main-parts (program-main-closed u.main-parts ds env prelude resolved.p.js u.graph)
14436+ ?^ page-parts (page-main-closed u.page-parts ds env prelude resolved.p.js u.graph)
14437+ ?^ store-parts ?=(^ store-main)
14438+ ?=(^ static-main)
14439+ ?. kind-ok
14440+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
14441+ =/ store-derived=(unit [values=ienv evidence=istore-request-evidence])
14442+ ?~ declared ~
14443+ ?~ prelude ~
14444+ =/ state=(unit ischeme) (find-jibb-mold %state [~ p.mts at ~ ~ ~ ~ ~])
14445+ ?~ state ~
14446+ =/ action-mold=(unit ischeme) (find-jibb-mold action.u.declared [~ p.mts at ~ ~ ~ ~ ~])
14447+ ?~ action-mold ~
14448+ =/ schemes=(unit [state=ischeme action=ischeme])
14449+ (store-derived-schemes u.prelude prelude-values prelude-molds typ.u.state typ.u.action-mold)
14450+ ?~ schemes ~
14451+ =/ evidence=istore-request-evidence
14452+ [at src typ.u.state action.u.declared typ.u.action-mold]
14453+ `[~[[%state state.u.schemes] [action.u.declared action.u.schemes]] evidence]
14454+ ?: &(?=(^ declared) ?=(~ store-derived))
14455+ [%| [(crip "store derived gates need unsupported inference: {(spud at)}") ~]]
14456+ =? env ?=(^ store-derived) (weld values.u.store-derived env)
14457+ =? graph ?=(^ store-derived)
14458+ `u.graph(stores [evidence.u.store-derived stores.u.graph])
14459+ ?. (request-graph-bounded u.graph)
14460+ [%| ['module request evidence needs unsupported inference' ~]]
14461+ =/ iface=ifile [env p.mts at ~ artifacts.resolution ~ `src graph]
14462+ [%& [iface [[at iface] cache.p.js]]]
14463+::
14464+:: A source-bound analysis of one named mold, not a module, island,
14465+:: request, watchability or runtime check. The host owns the trusted
14466+:: prepared prelude, canonical paths and reader/source version identities.
14467+:: The 256-node cap covers only classification, not source/graph work.
14468++$ igate-free-mold
14469+ [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]
14470+++ gate-free-mold-source
14471+ |= [file=path src=@t name=term externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude) fuel=@ud]
14472+ ^- (each igate-free-mold @t)
14473+ ?~ file [%| 'mold analysis needs a path ending in jibb']
14474+ ?. =(%jibb (rear file)) [%| 'mold analysis needs a path ending in jibb']
14475+ ?: |(=(file /lib/jibb/internal/jibb) =(file /lib/jibb/primitives/jibb))
14476+ [%| 'the prelude internal modules are private']
14477+ ?: ?=([%ui %api *] file) [%| 'API declarations need unsupported mold analysis']
14478+ ?: ?=([%ui %stores *] file) [%| 'store declarations need unsupported mold analysis']
14479+ =/ entries=jbundle (skim modules |=(m=jsource =(file at.m)))
14480+ ?: (gth (lent entries) 1) [%| 'duplicate root module sources']
14481+ =/ wrong-root=? ?~(entries | !=(source.i.entries src))
14482+ ?: wrong-root [%| 'root module source does not match bundle']
14483+ =/ parsed (parse file src)
14484+ ?: ?=(%| -.parsed) [%| 'mold source does not parse']
14485+ =/ mod=module p.parsed
14486+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
14487+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
14488+ ?~ prepared [%| 'mold analysis needs the prepared prelude']
14489+ ?. (module-scope-valid mod values.u.prepared molds.u.prepared)
14490+ [%| 'mold source has conflicting or unsupported scope']
14491+ =/ selected=(list def)
14492+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(name.d name))))
14493+ ?~ selected [%| 'selected mold is not declared']
14494+ ?^ t.selected [%| 'selected mold is not unique']
14495+ ?> ?=(%mold -.i.selected)
14496+ =/ public=ifile iface.u.prepared
14497+ =/ js=jimports-result
14498+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
14499+ ?: ?=(%| -.js) [%| p.js]
14500+ =/ ms=imolds (collect-simple-molds defs.mod)
14501+ =/ vals=(list term) (global-value-names defs.mod)
14502+ =/ globals=(list term) (weld values.u.prepared (weld (import-binding-names imports.mod) vals))
14503+ =/ surs=(list term) (collect-sur-imports imports.mod)
14504+ =/ declared=(list term) (collect-mark-imports imports.mod)
14505+ =/ reserved=(list term) (weld molds.u.prepared (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
14506+ =/ top=(list term) (turn ms |=(m=[name=term body=shape] name.m))
14507+ =/ state=istate [0 ~ ~ ~ ms globals externals surs marks declared resolved.p.js reserved ~ ~ ~ | file top `public ~ 256 ~ ~ ~ ~ ~ ~]
14508+ =/ inferred=(unit [template=ischeme state=istate])
14509+ (infer-mold-template shape.i.selected state(active ~[name], in-mold &))
14510+ ?~ inferred [%| 'selected mold needs unsupported inference']
14511+ =/ template=ischeme template.u.inferred
14512+ =. typ.template (label-direct-union typ.template shape.i.selected name state)
14513+ =. typ.template (itype-normalize typ.template sub.state.u.inferred)
14514+ =/ cap=@ud (min fuel 256)
14515+ =/ analysis=igate-free (gate-free-type typ.template cap ~)
14516+ [%& [file src name u.prepared externals marks modules cache.p.js template fuel cap analysis]]
769614517::
769714518:: +golden-types-with-modules fails closed for imports without prelude
769814519:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -7703,6 +14524,8 @@
770314524 ^- @t
770414525 =/ parsed (parse file src)
770514526 ?: ?=(%| -.parsed) (show-error src p.parsed)
14527+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
14528+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
770614529 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
770714530 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
770814531 (golden-types-with-marks file src externals mark-externals)
@@ -7717,6 +14540,8 @@
771714540 ^- @t
771814541 =/ parsed (parse file src)
771914542 ?: ?=(%| -.parsed) (show-error src p.parsed)
14543+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
14544+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
772014545 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
772114546 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
772214547 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
@@ -7724,11 +14549,19 @@
772414549 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
772514550 (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
772614551::
14552+++ golden-types-with-prelude-and-internal
14553+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prelude-source=@t internal-source=@t]
14554+ ^- @t
14555+ =/ prepared=(unit iprelude) (prepare-prelude-with-internal prelude-source internal-source)
14556+ (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
14557+::
772714558++ golden-types-with-prepared-prelude
772814559 |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prepared=(unit iprelude)]
772914560 ^- @t
773014561 =/ parsed (parse file src)
773114562 ?: ?=(%| -.parsed) (show-error src p.parsed)
14563+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
14564+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
773214565 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
773314566 =/ prelude-values=(list term) values.u.prepared
773414567 =/ prelude-molds=(list term) molds.u.prepared
@@ -7740,7 +14573,7 @@
774014573 ?: ?=(%| -.js) (of-wain:format ~['partial inference; module not checked' p.js])
774114574 =/ scope-values=(list term)
774214575 (weld prelude-values (weld (collect-sur-imports imports.p.parsed) (collect-mark-imports imports.p.parsed)))
7743− (golden-types-in-context file src externals mark-externals resolved.p.js scope-values prelude-molds iface)
14576+ (golden-types-in-context-core file src externals mark-externals resolved.p.js scope-values prelude-molds iface prepared)
774414577::
774514578:: +golden-types-with-marks: supply declared mark types separately from /sur
774614579:: entries, as [mark result] with the result from +read-mark:jibb-import.
@@ -7771,15 +14604,60 @@
777114604++ golden-types-in-context
777214605 |= [file=path src=@t externals=iexternals mark-externals=imark-externals jimports=ijimports prelude-values=(list term) reserved-molds=(list term) prelude=(unit ifile)]
777314606 ^- @t
14607+ (golden-types-in-context-core file src externals mark-externals jimports prelude-values reserved-molds prelude ~)
14608+++ golden-types-in-context-core
14609+ |= [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)]
14610+ ^- @t
777414611 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
777514612 =/ parsed (parse file src)
777614613 ?: ?=(%| -.parsed) (show-error src p.parsed)
14614+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
14615+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
14616+ ?: (module-has-reserved-proj p.parsed)
14617+ 'module has reserved proj name'
777714618 =/ ds=(list def) defs.p.parsed
777814619 =/ molds=imolds (collect-simple-molds ds)
777914620 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
778014621 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
778114622 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
7782− =/ env=ienv (resolve-supported-defs ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
14623+ =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
14624+ =/ cycles=(list icycle) (definite-value-cycles ds globals)
14625+ =/ env=ienv env.resolution
14626+ =/ recovered=(list term) ~
14627+ =/ eligible=?
14628+ ?& ?=(~ imports.p.parsed)
14629+ ?=(~ jimports)
14630+ !?=([%ui %api *] file)
14631+ !?=([%ui %stores *] file)
14632+ !(lien (global-value-names ds) |=(n=term =(n %main)))
14633+ !(module-values-complete ds env)
14634+ (lte (met 3 src) 65.536)
14635+ (lte (lent ds) 64)
14636+ ?| &(?=(~ prepared) ?=(~ prelude) ?=(~ prelude-values) ?=(~ reserved-molds) (module-scope-valid p.parsed ~ ~) (dg-source-candidate ds 64))
14637+ ?& ?=(^ prepared)
14638+ ?=(^ prelude)
14639+ =(u.prelude iface.u.prepared)
14640+ =(prelude-values values.u.prepared)
14641+ =(reserved-molds molds.u.prepared)
14642+ (module-scope-valid p.parsed values.u.prepared molds.u.prepared)
14643+ (dg-prepared-candidate ds 64)
14644+ ==
14645+ ==
14646+ ==
14647+ =/ transaction=(unit dgcommit)
14648+ ?. eligible ~
14649+ ?~ prepared (dg-root-source file src)
14650+ (dg-root-prepared file src u.prepared)
14651+ =. recovered
14652+ ?~ transaction ~
14653+ ?. &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) ~
14654+ (turn (skim env.u.transaction |=(entry=[name=term scheme=ischeme] ?=(~ (ienv-lookup name.entry env)))) |=(entry=[name=term scheme=ischeme] name.entry))
14655+ =. env
14656+ ?~ transaction env
14657+ ?: &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) env.u.transaction
14658+ env
14659+ =/ source-defs=(map term def) (direct-checked-gates ds env)
14660+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
778314661 =/ lines=(list @t) ~
778414662 |-
778514663 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -7788,8 +14666,30 @@
778814666 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
778914667 ?. (unique-value-name name.d globals)
779014668 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
14669+ =/ cycle=(list icycle) (skim cycles |=(c=icycle =(name.c name.d)))
14670+ ?^ cycle
14671+ =/ diag=idiag ["non-gate value depends on itself through a cycle" ~[[first.i.cycle "value in cycle"] [next.i.cycle "dependency in cycle"]]]
14672+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d diag) lines])
14673+ ?: (lien recovered |=(n=term =(n name.d)))
14674+ =/ found=(unit ischeme) (ienv-lookup name.d env)
14675+ ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: committed definition unavailable") lines])
14676+ ?: (itype-has-hidden-recursive typ.u.found)
14677+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive mold name is not available in this scope") lines])
14678+ ?: (itype-has-hidden-generic typ.u.found)
14679+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: generic union name is not available in this scope") lines])
14680+ =/ typ=itype (canonical-itype typ.u.found vars.u.found)
14681+ =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
14682+ $(ds t.ds, lines [line lines])
14683+ ?: (lien grouped.resolution |=(n=term =(n name.d)))
14684+ =/ found=(unit ischeme) (ienv-lookup name.d env)
14685+ ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
14686+ =/ typ=itype (canonical-itype typ.u.found vars.u.found)
14687+ =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
14688+ $(ds t.ds, lines [line lines])
779114689 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7792− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude]
14690+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
14691+ =. gate-defs.initial source-defs
14692+ =. head-evidence.initial heads
779314693 =. initial (reserve-def-caps val.d initial)
779414694 =/ result=iresult
779514695 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
@@ -7797,6 +14697,11 @@
779714697 (infer-fragment val.d env initial)
779814698 ?: ?=(%| -.result)
779914699 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
14700+ =. state.p.result (promote-restricted-numbers state.p.result env)
14701+ =. 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)))
14702+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.result holes.initial state.p.result)
14703+ ?^ hole
14704+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d u.hole) lines])
780014705 =/ merged=(unit [first=icap second=icap])
780114706 (merged-capitals caps.state.p.result sub.state.p.result)
780214707 ?^ merged
@@ -7819,7 +14724,672 @@
781914724 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
782014725 ?: (gth (lent vars) 26)
782114726 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
14727+ ?~ (width-finalize projections.state.p.result sub.state.p.result vars)
14728+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: record projection elaboration needs unsupported inference") lines])
782214729 =/ printable=itype (canonical-itype typ vars)
782314730 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
782414731 $(ds t.ds, lines [line lines])
14732+:: Experimental module-owned pending-constraint generalization only.
14733+:: Inputs, IDs and substitution come from one checker-owned transaction.
14734++$ dgscan [ids=(list @ud) fuel=@ud]
14735+++ dg-scan
14736+ |= [todo=(list itype) sub=isub fuel=@ud ids=(list @ud)]
14737+ ^- (unit dgscan)
14738+ ?~ todo `[ids fuel]
14739+ ?: =(0 fuel) ~
14740+ =. fuel (dec fuel)
14741+ =/ t=itype i.todo
14742+ ?: ?=(?(%var %fvar %avar %rvar %nvar %rnvar %tag) -.t)
14743+ =/ node-id=@ud ?:(?=(%tag -.t) id.t +.t)
14744+ =/ found=(unit itype) (itype-lookup node-id sub)
14745+ ?~ found $(todo t.todo, ids [node-id ids])
14746+ ?: &(?=(?(%rvar %rnvar) -.u.found) =(node-id +.u.found))
14747+ $(todo t.todo, ids [node-id ids])
14748+ $(todo [u.found t.todo])
14749+ ?: ?=(%jrec -.t) $(todo t.todo)
14750+ ?+ -.t ~
14751+ %collection $(todo (weld args.t t.todo))
14752+ %union $(todo (weld args.t (weld cases.t t.todo)))
14753+ %face $(todo [body.t t.todo])
14754+ %fn $(todo [sample.t product.t t.todo])
14755+ %cell $(todo [hed.t tal.t t.todo])
14756+ %atom $(todo t.todo)
14757+ %any-atom $(todo t.todo)
14758+ %flag $(todo t.todo)
14759+ %noun $(todo t.todo)
14760+ %empty $(todo t.todo)
14761+ %const $(todo t.todo)
14762+ ==
14763+::
14764+++ dg-scan-ids
14765+ |= [ids=(list @ud) sub=isub fuel=@ud blocked=(list @ud)]
14766+ ^- (unit dgscan)
14767+ ?~ ids `[blocked fuel]
14768+ =/ one=(unit dgscan) (dg-scan ~[[%var i.ids]] sub fuel blocked)
14769+ ?~ one ~
14770+ $(ids t.ids, fuel fuel.u.one, blocked ids.u.one)
14771+::
14772+++ dg-env
14773+ |= [env=ienv sub=isub fuel=@ud blocked=(list @ud)]
14774+ ^- (unit dgscan)
14775+ ?~ env `[blocked fuel]
14776+ =/ sc=ischeme scheme.i.env
14777+ :: Quantifiers are local to the scheme: first find raw free IDs, then
14778+ :: follow those IDs in the module substitution without capturing them.
14779+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ fuel ~)
14780+ ?~ raw ~
14781+ =/ free=(list @ud) (skim ids.u.raw |=(n=@ud !(lien vars.sc |=(q=@ud =(q n)))))
14782+ =/ resolved=(unit dgscan) (dg-scan-ids free sub fuel.u.raw blocked)
14783+ ?~ resolved ~
14784+ $(env t.env, fuel fuel.u.resolved, blocked ids.u.resolved)
14785+::
14786+++ dg-obligations
14787+ |= [pending=(list dgo) sub=isub fuel=@ud blocked=(list @ud)]
14788+ ^- (unit dgscan)
14789+ ?~ pending `[blocked fuel]
14790+ =/ found=(unit dgscan) (dg-scan ~[left.i.pending right.i.pending] sub fuel blocked)
14791+ ?~ found ~
14792+ $(pending t.pending, fuel fuel.u.found, blocked ids.u.found)
14793+::
14794+++ dg-tags
14795+ |= [tags=(list ipending) sub=isub fuel=@ud blocked=(list @ud)]
14796+ ^- (unit dgscan)
14797+ ?~ tags `[blocked fuel]
14798+ ?: =(0 fuel) ~
14799+ =/ found=(unit itype) (itype-lookup id.i.tags sub)
14800+ ?~ found $(tags t.tags, fuel (dec fuel), blocked [id.i.tags blocked])
14801+ :: Until this entry is explicitly discharged, retain variables reachable
14802+ :: through its binding; mere existence of a substitution is not proof.
14803+ =/ reached=(unit dgscan) (dg-scan ~[u.found] sub (dec fuel) blocked)
14804+ ?~ reached ~
14805+ $(tags t.tags, fuel fuel.u.reached, blocked ids.u.reached)
14806+::
14807+++ dg-generalize
14808+ |= [typ=itype env=ienv pending=(list dgo) tags=(list ipending) captured=(list @ud) state=istate fuel=@ud]
14809+ ^- (unit ischeme)
14810+ :: Bound the obligation list and all graph/substitution walks. The
14811+ :: substitution is assumed checker-owned and occurs-checked.
14812+ ?: (gth (lent pending) 64) ~
14813+ =/ capt=(unit dgscan) (dg-scan-ids captured sub.state fuel ~)
14814+ ?~ capt ~
14815+ =/ env-free=(unit dgscan) (dg-env env sub.state fuel.u.capt ids.u.capt)
14816+ ?~ env-free ~
14817+ =/ obligations=(unit dgscan) (dg-obligations pending sub.state fuel.u.env-free ids.u.env-free)
14818+ ?~ obligations ~
14819+ =/ tagged=(unit dgscan) (dg-tags tags sub.state fuel.u.obligations ids.u.obligations)
14820+ ?~ tagged ~
14821+ =/ bounded=(unit dgscan) (dg-scan ~[typ] sub.state fuel.u.tagged ~)
14822+ ?~ bounded ~
14823+ =/ normalized=itype (itype-normalize typ sub.state)
14824+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
14825+ =/ quantified=(list @ud) (skim vars |=(n=@ud !(lien ids.u.tagged |=(b=@ud =(b n)))))
14826+ `[[normalized quantified]]
14827+::
14828++$ dgcommit [env=ienv state=istate]
14829+:: A branch literal must not acquire a value face through replay.
14830+++ dg-literal-target-safe
14831+ |= target=itype
14832+ ^- ?
14833+ ?: ?=(%union -.target)
14834+ (levy cases.target |=(c=itype ?=(?(%const %cell) -.c)))
14835+ ?=(?(%const %atom %any-atom %flag %noun) -.target)
14836+::
14837+++ dg-replay-edges
14838+ |= [edges=(list dgo) state=istate fuel=@ud]
14839+ ^- (unit istate)
14840+ ?~ edges `state
14841+ ?: =(0 fuel) ~
14842+ =/ trial=ifit (itype-fit left.i.edges right.i.edges sub.state next.state)
14843+ ?. ?=(%ok -.trial) ~
14844+ =/ valid=?
14845+ ?: ?=(%tag -.left.i.edges)
14846+ ?. constructor.left.i.edges
14847+ =/ closed=(unit dgscan) (dg-scan ~[right.i.edges] sub.trial 512 ~)
14848+ ?~ closed |
14849+ ?^ ids.u.closed |
14850+ (dg-literal-target-safe (itype-normalize right.i.edges sub.trial))
14851+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
14852+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
14853+ ?. valid ~
14854+ $(edges t.edges, state state(sub sub.trial, next next.trial), fuel (dec fuel))
14855+::
14856+++ dg-close-env
14857+ |= [env=ienv sub=isub fuel=@ud]
14858+ ^- (unit ienv)
14859+ ?~ env `~
14860+ ?: =(0 fuel) ~
14861+ =/ s=ischeme scheme.i.env
14862+ :: Quantified IDs are scheme-local and cannot be rewritten on publication.
14863+ ?. (levy vars.s |=(n=@ud ?=(~ (itype-lookup n sub)))) ~
14864+ =/ bounded=(unit dgscan) (dg-scan ~[typ.s] sub (dec fuel) ~)
14865+ ?~ bounded ~
14866+ =/ normalized=itype (itype-normalize typ.s sub)
14867+ ?: (itype-has-tag normalized) ~
14868+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
14869+ ?. (levy vars |=(n=@ud (lien vars.s |=(v=@ud =(v n))))) ~
14870+ =/ rest=(unit ienv) (dg-close-env t.env sub fuel.u.bounded)
14871+ ?~ rest ~
14872+ `[[name.i.env [normalized vars.s]] u.rest]
14873+::
14874+:: A deferred boolean branch has exactly the two literal flag patterns.
14875+:: Arms are inferred in order. Equal types are retained; two direct pending
14876+:: literals may instead retain source-owned obligations for later context.
14877+++ dg-boolean-patterns
14878+ |= e=expr
14879+ ^- ?
14880+ ?. ?=(%branch -.e) |
14881+ ?~ arms.e |
14882+ ?~ t.arms.e |
14883+ ?^ t.t.arms.e |
14884+ =/ x=arm i.arms.e
14885+ =/ y=arm i.t.arms.e
14886+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
14887+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
14888+ !=(val.lit.pat.x val.lit.pat.y)
14889+:: Only a direct source literal which created its own unbound pending tag
14890+:: may create a branch edge. The caller must retain the exact source and state.
14891+++ dg-owned-arm-literal
14892+ |= [e=expr t=itype tags=(list ipending) sub=isub initial=@ud]
14893+ ^- ?
14894+ ?. ?=(%lit -.e) |
14895+ ?. ?=(%tag -.t) |
14896+ ?: constructor.t |
14897+ ?. =(lit.e literal.t) |
14898+ ?: (lth id.t initial) |
14899+ ?^ (itype-lookup id.t sub) |
14900+ (lien tags |=(x=ipending &(=(id.x id.t) =(literal.x literal.t))))
14901+++ dg-boolean-branch
14902+ |= [e=expr env=ienv state=istate]
14903+ ^- iresult
14904+ ?. (dg-boolean-patterns e) [%| ["deferred branch patterns need unsupported inference" ~]]
14905+ ?> ?=(%branch -.e)
14906+ ?> ?=(^ arms.e)
14907+ ?> ?=(^ t.arms.e)
14908+ =/ x=arm i.arms.e
14909+ =/ y=arm i.t.arms.e
14910+ =/ subject=iresult (infer-fragment subject.e env state)
14911+ ?: ?=(%| -.subject) subject
14912+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
14913+ ?~ su [%| ["deferred branch subject does not unify with ?" ~]]
14914+ =/ left=iresult (infer-fragment val.x env state.p.subject(sub u.su))
14915+ ?: ?=(%| -.left) left
14916+ =/ right=iresult (infer-fragment val.y env state.p.left)
14917+ ?: ?=(%| -.right) right
14918+ ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
14919+ =/ st=istate state.p.right
14920+ ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
14921+ [%| ["deferred branch arm context needs unsupported inference" ~]]
14922+ ?. (dg-owned-arm-literal val.y typ.p.right tags.st sub.st next.state)
14923+ [%| ["deferred branch arm context needs unsupported inference" ~]]
14924+ ?> ?=(%tag -.typ.p.left)
14925+ ?> ?=(%tag -.typ.p.right)
14926+ ?: =(id.typ.p.left id.typ.p.right)
14927+ [%| ["deferred branch arm context needs unsupported inference" ~]]
14928+ ?: (gth (lent obligations.st) 62)
14929+ [%| ["deferred branch arm context needs unsupported inference" ~]]
14930+ =/ result=itype [%var next.st]
14931+ =/ ex=dgo [typ.p.left result (span-of val.x) (span-of e)]
14932+ =/ ey=dgo [typ.p.right result (span-of val.y) (span-of e)]
14933+ [%& result st(next +(next.st), obligations [ex ey obligations.st])]
14934+ [%& typ.p.left state.p.right]
14935+::
14936+:: A direct tuple literal may wait for a later exact result context.
14937+:: Each pending literal retains its source tag and its own fit obligation.
14938+++ dg-infer-tuple-items
14939+ |= [items=(list item) env=ienv state=istate]
14940+ ^- iresult
14941+ ?~ items [%| ["empty cell is not supported by partial inference" ~]]
14942+ =/ head=iresult (infer-fragment val.i.items env state)
14943+ ?: ?=(%| -.head) head
14944+ =/ typ=itype typ.p.head
14945+ =/ st=istate state.p.head
14946+ =/ adjusted=(unit [typ=itype state=istate])
14947+ ?. (dg-owned-arm-literal val.i.items typ tags.st sub.st next.state) `[typ st]
14948+ ?: (gth (lent obligations.st) 63) ~
14949+ =/ pending=itype [%var next.st]
14950+ =/ edge=dgo [typ pending (span-of val.i.items) at.i.items]
14951+ `[pending st(next +(next.st), obligations [edge obligations.st])]
14952+ ?~ adjusted [%| ["deferred tuple context needs unsupported inference" ~]]
14953+ =. typ typ.u.adjusted
14954+ =. st state.u.adjusted
14955+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
14956+ ?~ t.items [%& typ st]
14957+ =/ tail=iresult $(items t.items, state st)
14958+ ?: ?=(%| -.tail) tail
14959+ [%& [%cell typ typ.p.tail] state.p.tail]
14960+::
14961+:: Deferred inference uses only source forms whose successful fit sites are
14962+:: guarded below; a shared source-node budget bounds this screen.
14963+++ dg-safe-expressions
14964+ |= [todo=(list expr) fuel=@ud]
14965+ ^- (unit @ud)
14966+ ?~ todo `fuel
14967+ =/ first=(unit @ud) (dg-safe-expression i.todo fuel)
14968+ ?~ first ~
14969+ $(todo t.todo, fuel u.first)
14970+++ dg-safe-items
14971+ |= [items=(list item) fuel=@ud]
14972+ ^- (unit @ud)
14973+ ?~ items `fuel
14974+ =/ first=(unit @ud) (dg-safe-expression val.i.items fuel)
14975+ ?~ first ~
14976+ $(items t.items, fuel u.first)
14977+++ dg-safe-expression
14978+ |= [e=expr fuel=@ud]
14979+ ^- (unit @ud)
14980+ ?: =(0 fuel) ~
14981+ =. fuel (dec fuel)
14982+ ?+ -.e ~
14983+ ?(%lit %ctor) `fuel
14984+ %wing ?:(?=([@ ~] names.e) `fuel ~)
14985+ %str
14986+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) ~
14987+ `fuel
14988+ %group $(e inner.e, fuel fuel)
14989+ %body
14990+ ?^ defs.e ~
14991+ $(e final.e, fuel fuel)
14992+ %gate $(e body.e, fuel fuel)
14993+ %gate-wide $(e body.e, fuel fuel)
14994+ %tuple (dg-safe-items items.e fuel)
14995+ %branch
14996+ ?. (dg-boolean-patterns e) ~
14997+ ?> ?=(^ arms.e)
14998+ ?> ?=(^ t.arms.e)
14999+ =/ subject=(unit @ud) $(e subject.e, fuel fuel)
15000+ ?~ subject ~
15001+ (dg-safe-expressions ~[val.i.arms.e val.i.t.arms.e] u.subject)
15002+ %cast $(e val.e, fuel fuel)
15003+ %call
15004+ =/ head=(unit @ud) $(e head.e, fuel fuel)
15005+ ?~ head ~
15006+ (dg-safe-expressions args.e u.head)
15007+ ==
15008+:: Exact normalized equality is preserved by all later substitutions.
15009+:: The bounded scan declines opaque types and oversized inputs.
15010+++ dg-stable-fit
15011+ |= [actual=itype expected=itype sub=isub]
15012+ ^- ?
15013+ ?~ (dg-scan ~[actual expected] sub 512 ~) |
15014+ =((itype-normalize actual sub) (itype-normalize expected sub))
15015+::
15016+:: A positional call peels sample-slot faces during its separate face check.
15017+:: Require its argument, sample and result closed so that check stays valid.
15018+++ dg-stable-call-fit
15019+ |= [actual=itype expected=itype product=itype sub=isub positional=?]
15020+ ^- ?
15021+ =/ checked=(unit dgscan) (dg-scan ~[actual expected product] sub 512 ~)
15022+ ?~ checked |
15023+ ?: &(positional ?=(^ ids.u.checked)) |
15024+ =((itype-normalize actual sub) (itype-normalize expected sub))
15025+::
15026+:: One definition attempt retains state only when inference succeeds.
15027++$ dg-step [env=ienv state=istate pending=(list dgo)]
15028+++ dg-stage-one
15029+ |= [d=def env=ienv state=istate]
15030+ ^- (unit dg-step)
15031+ ?> ?=(%value -.d)
15032+ ?~ (dg-safe-expression val.d 512) ~
15033+ =/ local=istate (reserve-def-caps val.d state)
15034+ :: This first slice declines all written capitals and holes/projections.
15035+ ?^ caps.local ~
15036+ =/ ordinary=iresult (infer-fragment val.d env local)
15037+ ?: ?=(%| -.ordinary) ~
15038+ =/ typ=itype typ.p.ordinary
15039+ =/ after=istate state.p.ordinary
15040+ =/ edges=(list dgo) obligations.after
15041+ ?. =(binders.after binders.state) ~
15042+ ?. =(molds.after molds.state) ~
15043+ ?. =(globals.after globals.state) ~
15044+ ?. =(externals.after externals.state) ~
15045+ ?. =(surs.after surs.state) ~
15046+ ?. =(mark-externals.after mark-externals.state) ~
15047+ ?. =(marks.after marks.state) ~
15048+ ?. =(jimports.after jimports.state) ~
15049+ ?. =(reserved-molds.after reserved-molds.state) ~
15050+ ?. =(params.after params.state) ~
15051+ ?. =(active.after active.state) ~
15052+ ?. =(in-mold.after in-mold.state) ~
15053+ ?. =(at.after at.state) ~
15054+ ?. =(top-molds.after top-molds.state) ~
15055+ ?. =(prelude.after prelude.state) ~
15056+ ?. =(gate-defs.after gate-defs.state) ~
15057+ ?. =(head-evidence.after head-evidence.state) ~
15058+ ?. =(grec-index.after grec-index.state) ~
15059+ ?. =(defer.after defer.state) ~
15060+ ?. =(holes.after holes.state) ~
15061+ ?. =(caps.after caps.state) ~
15062+ ?. =(projections.after projections.state) ~
15063+ ?: (unsupported-atom-vars (itype-normalize typ sub.after) caps.after binders.after sub.after) ~
15064+ ?: (itype-has-nvar (itype-normalize typ sub.after)) ~
15065+ =/ scheme=(unit ischeme) (dg-generalize typ env edges tags.after ~ after 32.768)
15066+ ?~ scheme ~
15067+ `[[[name.d u.scheme] env] after edges]
15068+:: Retry only definitions that did not infer. Successful definitions are
15069+:: committed into the local transaction, never published until all close.
15070+++ dg-stage
15071+ |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
15072+ ^- (unit dgcommit)
15073+ ?: (gth fuel 64) ~
15074+ ?: (gth (lent ds) fuel) ~
15075+ =/ remaining=(list def) ds
15076+ =/ waiting=(list def) ~
15077+ =/ progress=? |
15078+ =/ attempts=@ud (mul fuel fuel)
15079+ |-
15080+ ?~ remaining
15081+ ?^ waiting
15082+ ?. progress ~
15083+ $(remaining (flop waiting), waiting ~, progress |)
15084+ =/ replayed=(unit istate) (dg-replay-edges pending state 64)
15085+ ?~ replayed ~
15086+ ?: (pending-tags tags.u.replayed sub.u.replayed) ~
15087+ =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
15088+ ?~ closed-edges ~
15089+ ?^ ids.u.closed-edges ~
15090+ =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
15091+ ?~ rechecked ~
15092+ ?. =(sub.u.rechecked sub.u.replayed) ~
15093+ ?. =(next.u.rechecked next.u.replayed) ~
15094+ =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
15095+ ?~ closed ~
15096+ `[[u.closed u.replayed(defer ~, obligations ~)]]
15097+ ?: =(0 attempts) ~
15098+ =. attempts (dec attempts)
15099+ =/ d=def i.remaining
15100+ ?: ?=(%mold -.d) $(remaining t.remaining)
15101+ ?^ (ienv-lookup name.d base) $(remaining t.remaining)
15102+ ?^ (ienv-lookup name.d env) ~
15103+ =/ done=(unit dg-step) (dg-stage-one d env state)
15104+ ?~ done $(remaining t.remaining, waiting [d waiting])
15105+ $(remaining t.remaining, env env.u.done, state state.u.done, pending pending.u.done, progress &)
15106+::
15107+:: Cheap bounded eligibility check on the already parsed source. This
15108+:: deliberately covers only direct constructor calls beneath transparent
15109+:: groups, gates, casts and definition-free bodies. Other shapes decline
15110+:: this fallback without a second parse or resolution pass.
15111+++ dg-direct-source
15112+ |= [e=expr fuel=@ud]
15113+ ^- ?
15114+ ?: =(0 fuel) |
15115+ ?+ -.e |
15116+ %group $(e inner.e, fuel (dec fuel))
15117+ %gate $(e body.e, fuel (dec fuel))
15118+ %gate-wide $(e body.e, fuel (dec fuel))
15119+ %cast $(e val.e, fuel (dec fuel))
15120+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
15121+ %call
15122+ ?. ?=([* ~] args.e) |
15123+ ?=(%ctor -.i.args.e)
15124+ ==
15125+++ dg-source-candidate
15126+ |= [ds=(list def) fuel=@ud]
15127+ ^- ?
15128+ ?~ ds |
15129+ ?: =(0 fuel) |
15130+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
15131+ ?: (dg-direct-source val.i.ds 64) &
15132+ $(ds t.ds, fuel (dec fuel))
15133+::
15134+++ dg-prepared-source
15135+ |= [e=expr fuel=@ud]
15136+ ^- ?
15137+ ?: (dg-direct-source e fuel) &
15138+ ?: =(0 fuel) |
15139+ ?+ -.e |
15140+ %group $(e inner.e, fuel (dec fuel))
15141+ %gate $(e body.e, fuel (dec fuel))
15142+ %gate-wide $(e body.e, fuel (dec fuel))
15143+ %cast $(e val.e, fuel (dec fuel))
15144+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
15145+ %tuple &
15146+ ==
15147+++ dg-prepared-candidate
15148+ |= [ds=(list def) fuel=@ud]
15149+ ^- ?
15150+ ?~ ds |
15151+ ?: =(0 fuel) |
15152+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
15153+ ?: (dg-prepared-source val.i.ds 64) &
15154+ $(ds t.ds, fuel (dec fuel))
15155+::
15156+++ dg-interface-safe
15157+ |= [env=ienv]
15158+ ^- ?
15159+ ?~ env &
15160+ =/ sc=ischeme scheme.i.env
15161+ ?: |((itype-has-hidden-recursive typ.sc) (itype-has-hidden-generic typ.sc)) |
15162+ ?: (gth (lent vars.sc) 26) |
15163+ $(env t.env)
15164+:: Parse status and the transaction result come from the same source parse.
15165++$ dgparse [parsed=? result=(unit dgcommit)]
15166+++ dg-root-source
15167+ |= [at=path src=@t]
15168+ ^- (unit dgcommit)
15169+ result:(dg-root-detail at src)
15170+++ dg-root-detail
15171+ |= [at=path src=@t]
15172+ ^- dgparse
15173+ =/ parsed (parse at src)
15174+ ?: ?=(%| -.parsed) [| ~]
15175+ =/ transact
15176+ |.
15177+ ?^ imports.p.parsed ~
15178+ ?. (module-scope-valid p.parsed ~ ~) ~
15179+ ?^ (duplicate-defs defs.p.parsed) ~
15180+ =/ defs=(list def) defs.p.parsed
15181+ ?: (gth (lent defs) 64) ~
15182+ =/ molds=imolds (collect-simple-molds defs)
15183+ =/ globals=(list term) (global-value-names defs)
15184+ =/ resolution=iresolved (resolve-groups defs molds globals ~ ~ ~ ~ ~ ~ at ~)
15185+ ?^ grouped.resolution ~
15186+ ?^ artifacts.resolution ~
15187+ =/ base=ienv env.resolution
15188+ =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
15189+ ?~ free ~
15190+ ?^ ids.u.free ~
15191+ =/ all=(unit dgscan) (dg-all-env-ids base 32.768 ~)
15192+ ?~ all ~
15193+ =/ fresh=@ud (dg-next-id ids.u.all 0)
15194+ =/ st=istate *istate
15195+ =. 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)
15196+ =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
15197+ ?: ?=(%| -.checked-molds) ~
15198+ (dg-stage defs base base st ~ 64)
15199+ ::
15200+ [& (transact)]
15201+:: The caller supplies the trusted prepared prelude. This transaction is
15202+:: only report evidence; the ordinary module resolver does not publish it.
15203+++ dg-root-prepared
15204+ |= [at=path src=@t prepared=iprelude]
15205+ ^- (unit dgcommit)
15206+ ?: ?=([%ui %api *] at) ~
15207+ ?: ?=([%ui %stores *] at) ~
15208+ ?: (gth (met 3 src) 65.536) ~
15209+ =/ parsed (parse at src)
15210+ ?: ?=(%| -.parsed) ~
15211+ ?^ imports.p.parsed ~
15212+ ?. (module-scope-valid p.parsed values.prepared molds.prepared) ~
15213+ ?^ (duplicate-defs defs.p.parsed) ~
15214+ =/ defs=(list def) defs.p.parsed
15215+ ?: (gth (lent defs) 64) ~
15216+ ?: (lien (global-value-names defs) |=(n=term =(n %main))) ~
15217+ ?. (dg-prepared-candidate defs 64) ~
15218+ =/ local-molds=imolds (collect-simple-molds defs)
15219+ =/ globals=(list term) (weld values.prepared (global-value-names defs))
15220+ =/ iface=ifile iface.prepared
15221+ =/ prelude=(unit ifile) `iface
15222+ =/ resolution=iresolved
15223+ (resolve-groups defs local-molds globals ~ ~ ~ ~ ~ molds.prepared at prelude)
15224+ ?^ grouped.resolution ~
15225+ ?^ artifacts.resolution ~
15226+ =/ base=ienv env.resolution
15227+ =/ templates=ienv
15228+ (turn molds.iface |=(x=[name=term template=ischeme] [name.x template.x]))
15229+ =/ all-env=ienv (weld base (weld values.iface templates))
15230+ =/ free=(unit dgscan) (dg-env all-env ~ 32.768 ~)
15231+ ?~ free ~
15232+ ?^ ids.u.free ~
15233+ =/ all=(unit dgscan) (dg-all-env-ids all-env 32.768 ~)
15234+ ?~ all ~
15235+ =/ fresh=@ud (dg-next-id ids.u.all 0)
15236+ =/ st=istate *istate
15237+ =. 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)
15238+ =/ checked-molds=(each imold-types @t) (module-mold-types local-molds st)
15239+ ?: ?=(%| -.checked-molds) ~
15240+ (dg-stage defs base base st ~ 64)
15241+::
15242+++ dg-all-env-ids
15243+ |= [env=ienv fuel=@ud ids=(list @ud)]
15244+ ^- (unit dgscan)
15245+ ?~ env `[ids fuel]
15246+ ?: =(0 fuel) ~
15247+ =/ sc=ischeme scheme.i.env
15248+ ?: (itype-has-tag typ.sc) ~
15249+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ (dec fuel) ids)
15250+ ?~ raw ~
15251+ =/ quant=(unit dgscan) (dg-scan-ids vars.sc ~ fuel.u.raw ids.u.raw)
15252+ ?~ quant ~
15253+ $(env t.env, fuel fuel.u.quant, ids ids.u.quant)
15254+::
15255+++ dg-next-id
15256+ |= [ids=(list @ud) largest=@ud]
15257+ ^- @ud
15258+ ?~ ids +(largest)
15259+ $(ids t.ids, largest (max largest i.ids))
15260+::
15261+++ dg-eligible-ctor
15262+ |= [e=expr head=itype actual=itype expected=itype state=istate]
15263+ ^- (unit dgo)
15264+ ?. ?=(%call -.e) ~
15265+ ?. ?=([* ~] args.e) ~
15266+ ?. ?=(%ctor -.i.args.e) ~
15267+ ?. ?=(%fn -.head) ~
15268+ ?. ?=(%fn -.expected) ~
15269+ ?. ?=(%tag -.actual) ~
15270+ ?. constructor.actual ~
15271+ ?. ?=(%var -.product.expected) ~
15272+ ?^ (itype-lookup id.product.expected sub.state) ~
15273+ =/ bounded=(unit dgscan) (dg-scan ~[sample.expected] sub.state 256 ~)
15274+ ?~ bounded ~
15275+ ?^ ids.u.bounded ~
15276+ `[[actual expected (span-of i.args.e) (span-of head.e)]]
15277+::
15278+:: Experimental per-module, source-derived recursive tree index.
15279+:: The two tags and the exact children/list/self layout are fixed-shape
15280+:: checks, so ordinary definitions incur no type-tree or source scans.
15281+++ grec-tagged-fields
15282+ |= sh=shape
15283+ ^- (unit [tag=@ fields=(list field)])
15284+ ?. ?=(%cell -.sh) ~
15285+ ?~ fields.sh ~
15286+ =/ head=field i.fields.sh
15287+ ?. ?=(%bare -.head) ~
15288+ ?. ?=(%const -.shape.head) ~
15289+ ?. &(?=(%term form.lit.shape.head) =(%tas aura.lit.shape.head)) ~
15290+ `[val.lit.shape.head t.fields.sh]
15291+++ grec-tree-children
15292+ |= [fs=(list field) param=@t]
15293+ ^- (unit field)
15294+ ?~ fs ~
15295+ ?~ t.fs `i.fs
15296+ ?^ t.t.fs ~
15297+ =/ event=field i.fs
15298+ =/ kids=field i.t.fs
15299+ ?. &(?=(%face -.event) ?=(%face -.kids)) ~
15300+ ?. !=(name.event name.kids) ~
15301+ ?. ?=(%fn -.shape.event) ~
15302+ ?. ?=(%aura -.sample.shape.event) ~
15303+ ?. =(%t aura.sample.shape.event) ~
15304+ ?. ?=(%tvar -.product.shape.event) ~
15305+ ?. =(param name.product.shape.event) ~
15306+ `kids
15307+::
15308+++ grec-tree-proof
15309+ |= [name=term sh=shape]
15310+ ^- ?
15311+ ?. ?=(%generic -.sh) |
15312+ ?. ?=([@ ~] vars.sh) |
15313+ =/ param=@t i.vars.sh
15314+ ?. ?=(%union -.body.sh) |
15315+ ?. ?=([* [* ~]] cases.body.sh) |
15316+ =/ a=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.cases.body.sh)
15317+ =/ b=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.t.cases.body.sh)
15318+ ?~ a |
15319+ ?~ b |
15320+ ?. !=(tag.u.a tag.u.b) |
15321+ ?. ?=([* ~] fields.u.a) |
15322+ =/ value=field i.fields.u.a
15323+ ?. ?=(%face -.value) |
15324+ ?. ?=(%aura -.shape.value) |
15325+ ?. =(%t aura.shape.value) |
15326+ =/ selected=(unit field) (grec-tree-children fields.u.b param)
15327+ ?~ selected |
15328+ =/ kids=field u.selected
15329+ ?. ?=(%face -.kids) |
15330+ ?. ?=(%apply -.shape.kids) |
15331+ ?. =(ref.shape.kids ~[%list]) |
15332+ ?. ?=([* ~] args.shape.kids) |
15333+ =/ self=shape i.args.shape.kids
15334+ ?. ?=(%apply -.self) |
15335+ ?. =(ref.self ~[name]) |
15336+ ?. ?=([* ~] args.self) |
15337+ ?. ?=(%tvar -.i.args.self) |
15338+ =(name.i.args.self param)
15339++$ grec-collected [molds=imolds proofs=(map term shape)]
15340+:: Experimental one-layer analysis view, never an exported mold identity.
15341+++ grec-unfold-view
15342+ |= [typ=itype fuel=@ud]
15343+ ^- (unit [view=itype left=@ud])
15344+ ?. ?=(%grec -.typ) ~
15345+ ?: =(fuel 0) ~
15346+ ?. ?=([* ~] args.typ) ~
15347+ =/ sh=shape proof.typ
15348+ ?. (grec-tree-proof name.typ sh) ~
15349+ ?> ?=(%generic -.sh)
15350+ ?> ?=([@ ~] vars.sh)
15351+ ?> ?=(%union -.body.sh)
15352+ ?> ?=([* [* ~]] cases.body.sh)
15353+ =/ ca=shape i.cases.body.sh
15354+ =/ cb=shape i.t.cases.body.sh
15355+ ?> ?=(%cell -.ca)
15356+ ?> ?=(%cell -.cb)
15357+ ?> ?=([* [* ~]] fields.ca)
15358+ ?> ?=([* *] fields.cb)
15359+ =/ tag-a=field i.fields.ca
15360+ =/ tag-b=field i.fields.cb
15361+ ?> ?=(%bare -.tag-a)
15362+ ?> ?=(%bare -.tag-b)
15363+ ?> ?=(%const -.shape.tag-a)
15364+ ?> ?=(%const -.shape.tag-b)
15365+ =/ text-field=field i.t.fields.ca
15366+ ?> ?=(%face -.text-field)
15367+ =/ branch=(list field) t.fields.cb
15368+ =/ kids=(unit field) (grec-tree-children branch i.vars.sh)
15369+ ?~ kids ~
15370+ ?> ?=(%face -.u.kids)
15371+ =/ children=itype [%face name.u.kids [%collection %list ~[typ]]]
15372+ ?> ?=(^ branch)
15373+ =/ payload=itype
15374+ ?~ t.branch children
15375+ =/ event=field i.branch
15376+ ?> ?=(%face -.event)
15377+ [%cell [%face name.event [%fn [%atom %t] i.args.typ]] children]
15378+ =/ leaf=itype [%cell [%const lit.shape.tag-a] [%face name.text-field [%atom %t]]]
15379+ =/ node=itype [%cell [%const lit.shape.tag-b] payload]
15380+ `[[%union ~[leaf node] ~ ~ ~] (dec fuel)]
15381+::
15382+++ grec-collect-molds
15383+ |= ds=(list def)
15384+ ^- grec-collected
15385+ ?~ ds [~ *(map term shape)]
15386+ =/ rest=grec-collected $(ds t.ds)
15387+ ?. ?=(%mold -.i.ds) rest
15388+ =/ name=term name.i.ds
15389+ =/ body=shape shape.i.ds
15390+ =/ proofs=(map term shape) proofs.rest
15391+ =? proofs (grec-tree-proof name body) (~(put by proofs) name body)
15392+ [[[name body] molds.rest] proofs]
15393+::
15394+
782515395--