@@ -874,7 +874,7 @@
874874 %'~[' %'|=(' %'$-(' :: openers
875875 %'%/' %'/' :: paths
876876 %'+' %'`' %'=' :: pair, unit, face
877− %'*' %'?' :: noun, loobean mold
877+ %'*' %'?' %'_' :: noun, loobean, type hole
878878 %'++' %'+$' %'|=' %'|$' :: runes
879879 %'^-' %'~&' %'?-' %'!!' :: runes
880880 %'/-' %'/%' %'/=' :: imports
@@ -1016,6 +1016,7 @@
10161016 [%const at=span =lit] :: ~ %add %.y
10171017 [%ref at=span names=(list term)] :: state item.todo
10181018 [%tvar at=span name=@t] :: M
1019+ [%hole at=span ~] :: _
10191020 [%path at=span segs=(list pseg)] :: / /todos /todo/[id=@ud]
10201021 [%apply at=span ref=(list term) args=(list shape)] :: (list @t)
10211022 [%cell at=span fields=(list field)] :: [text=@t done=?]
@@ -1024,9 +1025,9 @@
10241025 [%generic at=span vars=(list @t) body=shape] :: +$ name |$ [M] …
10251026 ==
10261027::
1027−:: +pseg: a path mold's segment, a knot or [name=aura]
1028+:: +pseg: a path mold's segment, a knot, [name=aura], or [name=_]
10281029::
1029−+$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta])
1030++$ pseg $%([%knot p=@ta] [%typed at=span name=term aura=@ta] [%inferred at=span name=term hole-at=span])
10301031::
10311032+| %api
10321033::
@@ -1295,6 +1296,7 @@
12951296 (emit 1 %'=')
12961297 ?: =('`' a) (emit 1 %'`')
12971298 ?: =('*' a) (emit 1 %'*')
1299+ ?: =('_' a) (emit 1 %'_')
12981300 ?: =('~' a)
12991301 ?: =('[' b) (emit 2 %'~[')
13001302 ?: =('&' b) (emit 2 %'~&')
@@ -1670,14 +1672,14 @@
16701672:: What may begin each place the parser reads (section 3, Errors):
16711673:: an expression a-z 0-9 " ( [ ~ % / ` | ^ ? !
16721674:: an operand a-z 0-9 " ( [ ~ % / ` | !
1673−:: a mold a-z A-Z @ * ! ? ~ % / ( [ $
1675+:: a mold a-z A-Z @ * ! ? ~ % / ( [ $ _
16741676:: a pattern a-z 0-9 " ~ % * [
16751677:: and what may go tight after an operand: . ( + = after a name, a
16761678:: closer ) ] }, or the : of a comment
16771679::
16781680++ expr-mask 0x57ff.ffff.4800.0000.83ff.8126.0000.0000
16791681++ operand-mask 0x57ff.ffff.0800.0000.03ff.8126.0000.0000
1680−++ mold-mask 0x47ff.fffe.0fff.ffff.8000.8532.0000.0000
1682+++ mold-mask 0x47ff.fffe.8fff.ffff.8000.8532.0000.0000
16811683++ bar-mask 0x1000.0000.0000.0000.0000.0000.0000.0000
16821684++ pattern-mask 0x47ff.fffe.0800.0000.03ff.0424.0000.0000
16831685++ after-mask 0x2000.0000.2000.0000.2400.4b00.0000.0000
@@ -2107,6 +2109,7 @@
21072109 ?- -.s
21082110 %knot (weld "/" (trip p.s))
21092111 %typed "/[{(trip name.s)}=@{(trip aura.s)}]"
2112+ %inferred "/[{(trip name.s)}=_]"
21102113 ==
21112114::
21122115++ show-tvars
@@ -2318,6 +2321,7 @@
23182321 %const (nod "const" at.s (show-lit lit.s) ~)
23192322 %ref (nod "ref" at.s (show-names names.s) ~)
23202323 %tvar (nod "tvar" at.s (trip name.s) ~)
2324+ %hole (nod "hole" at.s "" ~)
23212325 %path (nod "path" at.s (show-psegs segs.s) ~)
23222326 %apply (nod "apply" at.s (show-names ref.s) (turn args.s sexp-shape))
23232327 %cell (nod "cell" at.s "" (turn fields.s sexp-field))
@@ -3842,6 +3846,7 @@
38423846 %'*' [%& [%noun at.t ~] t.ts]
38433847 %'!!' [%& [%void at.t ~] t.ts]
38443848 %'?' [%& [%flag at.t ~] t.ts]
3849+ %'_' [%& [%hole at.t ~] t.ts]
38453850 [%name *] [%& [%ref at.t ~[p.lex.t]] t.ts]
38463851 [%wing *] [%& [%ref at.t p.lex.t] t.ts]
38473852 [%tvar *] [%& [%tvar at.t p.lex.t] t.ts]
@@ -4058,7 +4063,7 @@
40584063 ?: &(?=(^ nex) tight.i.nex) (bad nex "a path segment")
40594064 (bad-space i.after nex "a path segment")
40604065 ::
4061− :: +read-pseg: a path mold's segment, a knot or [name=aura] with no
4066+ :: +read-pseg: a path mold's knot, [name=aura], or [name=_] with no
40624067 :: spaces, and where it ends
40634068 ::
40644069 ++ read-pseg
@@ -4075,13 +4080,16 @@
40754080 ?: |(?=(~ r2) !tight.i.r2) (bad-space i.r1 r2 "`=`")
40764081 ?. ?=([[* * %'='] *] r2) (bad-in r2 "`=`" tis-mask)
40774082 =/ r3=(list token) t.r2
4078− ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura")
4079− ?. ?=([[* * [%aura *]] *] r3) (bad-in r3 "an aura" pat-mask)
4083+ ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura or type hole")
4084+ ?. ?=([[* * ?([%aura *] %'_')] *] r3) (bad-in r3 "an aura or type hole" (con pat-mask (bex 95)))
40804085 =/ r4=(list token) t.r3
40814086 ?: |(?=(~ r4) !tight.i.r4) (bad-space i.r3 r4 "`]`")
40824087 ?. ?=([[* * %']'] *] r4) (bad-in r4 "`]`" ser-mask)
40834088 =/ at=span [beg.at.op end.at.i.r4]
4084− [%& [[%typed at p.lex.i.r1 p.lex.i.r3] end.at.i.r4] t.r4]
4089+ =/ seg=pseg
4090+ ?: ?=(%'_' lex.i.r3) [%inferred at p.lex.i.r1 at.i.r3]
4091+ [%typed at p.lex.i.r1 p.lex.i.r3]
4092+ [%& [seg end.at.i.r4] t.r4]
40854093 --
40864094::
40874095+| %span-check
@@ -4465,6 +4473,7 @@
44654473 %const [%const at.s ~[%lit] %one ~]
44664474 %ref [%ref at.s ~[%name %wing] %one ~]
44674475 %tvar [%tvar at.s ~[%tvar] %one ~]
4476+ %hole [%hole at.s ~[%'_'] %one ~]
44684477 %apply [%apply at.s ~[%'('] %shut (turn args.s outline-shape)]
44694478 %cell [%cell at.s ~[%'['] %shut (turn fields.s outline-sample)]
44704479 ::
@@ -4473,8 +4482,11 @@
44734482 %+ murn segs.s
44744483 |= g=pseg
44754484 ^- (unit outline)
4476− ?. ?=(%typed -.g) ~
4477− `[%typed at.g ~[%'['] %shut ~]
4485+ ?- -.g
4486+ %knot ~
4487+ %typed `[%typed at.g ~[%'['] %shut ~]
4488+ %inferred `[%typed at.g ~[%'['] %shut ~[[%hole hole-at.g ~[%'_'] %one ~]]]
4489+ ==
44784490 [%path at.s ~[%'/'] %run ks]
44794491 ::
44804492 %union
@@ -4534,6 +4546,8 @@
45344546 [%path [1 9] [1 9] [1 21]]
45354547 [%face [1 7] [1 7] [1 21]]
45364548 ==
4549+ :: an inferred path aura's hole spanning its = as well
4550+ ['+$ x /a/[id=_]' ~[[%hole [1 13] [1 12] [1 14]]]]
45374551 :: an import's path cut short
45384552 ['/= c /ui/c' ~[[%jibb [1 1] [1 1] [1 11]]]]
45394553 :: brackets that close with the deeper lines, cut at their line's
@@ -4593,6 +4607,8 @@
45934607:: Atom constraints tied to an explicit capital or an inferred sample
45944608:: are generalized and printed. Other aura variables remain unsupported until
45954609:: their defaulting and inferred generalization are implemented.
4610+:: Restricted-number promotion considers written capitals only; if there
4611+:: are none, it skips the otherwise unnecessary environment traversal.
45964612:: Bare @ is a separate unrestricted atom type. A directional fit check
45974613:: permits concrete atoms to widen to it, never the reverse. A fit that
45984614:: needs a not-yet-implemented constraint remains unsupported. Named unions
@@ -4600,18 +4616,63 @@
46004616:: from their display name. Generic cases must be disjoint for all arguments.
46014617:: Unnamed union printing is informational; it is not Jibb syntax.
46024618::
4619+:: `proj` is a reserved, type-directed operation, not an ordinary gate.
4620+:: The supported fragment selects uniquely faced fields from a known record
4621+:: in source order (reordering is a doc question). It records the original
4622+:: call, source and target types, and source axes with its definition;
4623+:: A single selected field keeps its face and uses one source axis.
4624+:: Checked module interfaces retain that evidence and their source, including
4625+:: the private prelude dependency. A later lowerer must replace the call by
4626+:: an inline gate applied to the operand once; no lowering is implemented yet.
4627+:: Ordinary fits never insert a projection. Unknown or variable-origin record
4628+:: spines, nested projected fields and projections in
4629+:: recursive groups remain unsupported. Directional fits bound faced-spine
4630+:: proofs to fewer than 1,024 cells; the projection planner has a separate
4631+:: 4,096-step bound. These are inference limits, not language limits.
4632+::
4633+:: Supported API imports derive request-gate types atomically for multiple
4634+:: paths, including one typed segment or one diff fold per case. Their checked
4635+:: ordinary definitions, mark molds and supported poke constructor are also
4636+:: exported. A selected /sur mold is checked through its trusted reader result;
4637+:: unused cores and other bindings are not independently validated. APIs
4638+:: with /= imports, separate scry paths, multiple parameters or diffs, or a
4639+:: parameter together with a fold remain unsupported. The unchanged todo API
4640+:: fits this fragment, including named closed fold gates.
4641+::
4642+:: Each case's source-derived schema and canonical API identity travel in a
4643+:: dependency closure bound to the exact supplied bundle, prelude, scope and
4644+:: trusted reader results. Unknown cached entries are rebuilt. Request-bearing
4645+:: closures are limited to 256 source paths and requests. This is type
4646+:: inference only: no request lowering, runtime schema validator or proof that
4647+:: an arbitrary ask value is watchable is supplied.
4648+::
4649+:: A closed gate sample may omit one outer face from a known input slot when
4650+:: its product is identical. Distinct written names, nested value faces,
4651+:: ambiguous cell tails and raw-variable-origin fits retain their prior rules.
4652+::
4653+:: In one synthetic eval of a 48-module deep and 48-module wide request-free
4654+:: graph, baseline versus certificate inference took 21.53 s versus 23.10 s
4655+:: elapsed (21.10 s versus 22.34 s CPU), including startup. The deep cache's
4656+:: jam grew from 2,402 to 4,209 bytes (+1,807 bytes). These single-run figures
4657+:: are not production memory or performance benchmarks.
4658+::
46034659+$ itype
46044660 $~ [%var 0]
46054661 $% [%var id=@ud]
46064662 [%avar id=@ud]
4663+ [%rvar id=@ud]
46074664 [%nvar id=@ud]
4665+ [%rnvar id=@ud]
46084666 [%atom aura=@ta]
46094667 [%any-atom ~]
46104668 [%flag ~]
4669+ [%noun ~]
46114670 [%tag id=@ud literal=lit constructor=?]
46124671 [%const literal=lit]
46134672 [%collection name=term args=(list itype)]
46144673 [%recursive module=term name=term label=(unit @t)]
4674+ [%jrec at=path name=term label=(unit @t) head=term aura=@ta tail=term]
4675+ [%grec at=path name=term label=(unit @t) proof=shape args=(list itype)]
46154676 [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t) args=(list itype)]
46164677 [%face name=term body=itype]
46174678 [%fn sample=itype product=itype]
@@ -4635,18 +4696,32 @@
46354696 %var
46364697 =/ found=(unit itype) (itype-lookup id.t sub)
46374698 ?~ found t
4699+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46384700 $(t u.found)
46394701 %avar
46404702 =/ found=(unit itype) (itype-lookup id.t sub)
46414703 ?~ found t
4704+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4705+ $(t u.found)
4706+ %rvar
4707+ =/ found=(unit itype) (itype-lookup id.t sub)
4708+ ?~ found t
4709+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46424710 $(t u.found)
46434711 %nvar
46444712 =/ found=(unit itype) (itype-lookup id.t sub)
46454713 ?~ found t
4714+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4715+ $(t u.found)
4716+ %rnvar
4717+ =/ found=(unit itype) (itype-lookup id.t sub)
4718+ ?~ found t
4719+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46464720 $(t u.found)
46474721 %tag
46484722 =/ found=(unit itype) (itype-lookup id.t sub)
46494723 ?~ found t
4724+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
46504725 $(t u.found)
46514726 ==
46524727::
@@ -4657,14 +4732,19 @@
46574732 ?- -.t
46584733 %var =(n id.t)
46594734 %avar =(n id.t)
4735+ %rvar =(n id.t)
46604736 %nvar =(n id.t)
4737+ %rnvar =(n id.t)
46614738 %atom |
46624739 %any-atom |
46634740 %flag |
4741+ %noun |
46644742 %tag =(n id.t)
46654743 %const |
46664744 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
46674745 %recursive |
4746+ %jrec |
4747+ %grec (lien args.t |=(c=itype (itype-occurs n c sub)))
46684748 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
46694749 %face $(t body.t)
46704750 %fn |($(t sample.t) $(t product.t))
@@ -4683,6 +4763,11 @@
46834763 =. a (itype-walk a sub)
46844764 =. b (itype-walk b sub)
46854765 ?: =(a b) `sub
4766+ ?: &(?=(%grec -.a) ?=(%grec -.b))
4767+ ?. &(=(at.a at.b) =(name.a name.b)) ~
4768+ (itype-unify-args args.a args.b sub)
4769+ ?: &(?=(%jrec -.a) ?=(%jrec -.b))
4770+ ?:(&(=(at.a at.b) =(name.a name.b) =(head.a head.b) =(aura.a aura.b) =(tail.a tail.b)) `sub ~)
46864771 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
46874772 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
46884773 ?: &(?=(%union -.a) ?=(%union -.b))
@@ -4699,6 +4784,32 @@
46994784 ?: ?=(%var -.b)
47004785 ?: (itype-occurs id.b a sub) ~
47014786 `[[id.b a] sub]
4787+ :: Arithmetic's aura variable excludes loobeans; decimal literals
4788+ :: remain defaultable until a later constraint makes them concrete.
4789+ ?: &(?=(%nvar -.a) ?=(%rvar -.b))
4790+ `[[id.b [%rnvar id.a]] [id.a [%rnvar id.a]] sub]
4791+ ?: &(?=(%rvar -.a) ?=(%nvar -.b))
4792+ `[[id.a [%rnvar id.b]] [id.b [%rnvar id.b]] sub]
4793+ ?: &(?=(%rnvar -.a) ?=(%rvar -.b)) `[[id.b a] sub]
4794+ ?: &(?=(%rvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4795+ ?: &(?=(%rnvar -.a) ?=(%nvar -.b)) `[[id.b a] sub]
4796+ ?: &(?=(%nvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4797+ ?: &(?=(%rnvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4798+ ?: &(?=(%avar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4799+ ?: ?=(%rnvar -.a)
4800+ ?. |(?=(%rnvar -.b) ?=(%atom -.b)) ~
4801+ `[[id.a b] sub]
4802+ ?: ?=(%rnvar -.b)
4803+ ?. ?=(%atom -.a) ~
4804+ `[[id.b a] sub]
4805+ ?: &(?=(%avar -.a) ?=(%rvar -.b)) `[[id.a b] sub]
4806+ ?: &(?=(%rvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4807+ ?: ?=(%rvar -.a)
4808+ ?. |(?=(%rvar -.b) ?=(%atom -.b)) ~
4809+ `[[id.a b] sub]
4810+ ?: ?=(%rvar -.b)
4811+ ?. ?=(%atom -.a) ~
4812+ `[[id.b a] sub]
47024813 :: The narrower decimal constraint survives a match with an atom
47034814 :: variable; decimal syntax alone does not make it a loobean.
47044815 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
@@ -4753,14 +4864,19 @@
47534864 ?- -.t
47544865 %var |
47554866 %avar |
4867+ %rvar |
47564868 %nvar |
4869+ %rnvar |
47574870 %atom |
47584871 %any-atom &
47594872 %flag |
4873+ %noun |
47604874 %tag |
47614875 %const |
47624876 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
47634877 %recursive |
4878+ %jrec |
4879+ %grec (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47644880 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
47654881 %face $(t body.t)
47664882 %fn |($(t sample.t) $(t product.t))
@@ -4823,14 +4939,19 @@
48234939 ?- -.typ
48244940 %var |
48254941 %avar |
4942+ %rvar |
48264943 %nvar |
4944+ %rnvar |
48274945 %atom &
48284946 %any-atom &
48294947 %flag &
4948+ %noun |
48304949 %tag &
48314950 %const &
48324951 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
48334952 %recursive |
4953+ %jrec |
4954+ %grec (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48344955 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
48354956 %face $(typ body.typ)
48364957 %fn |($(typ sample.typ) $(typ product.typ))
@@ -4859,6 +4980,7 @@
48594980 ^- ?
48604981 =. t (itype-walk t sub)
48614982 ?- -.t
4983+ %grec (lien args.t |=(c=itype (itype-has-face c sub)))
48624984 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
48634985 %face &
48644986 %cell |($(t hed.t) $(t tal.t))
@@ -4866,6 +4988,42 @@
48664988 * |
48674989 ==
48684990::
4991+:: Closed function samples may omit a slot face, but a known name must
4992+:: match another known name. Keep nested value faces and require exact
4993+:: invariant compatibility; a faced tail against a cell is ambiguous.
4994+++ itype-closed-slot-match
4995+ |= [a=itype b=itype]
4996+ ^- ?
4997+ ?: &(?=(%face -.a) ?=(%face -.b))
4998+ ?. =(name.a name.b) |
4999+ ?=(^ (itype-unify body.a body.b ~))
5000+ ?: ?=(%face -.a) ?=(^ (itype-unify body.a b ~))
5001+ ?: ?=(%face -.b) ?=(^ (itype-unify a body.b ~))
5002+ ?=(^ (itype-unify a b ~))
5003+++ itype-closed-sample-match
5004+ |= [a=itype b=itype fuel=@ud]
5005+ ^- ?
5006+ ?: =(0 fuel) |
5007+ ?. &(?=(%cell -.a) ?=(%cell -.b)) |
5008+ ?. (itype-closed-slot-match hed.a hed.b) |
5009+ =/ x=itype tal.a
5010+ =/ y=itype tal.b
5011+ ?: &(?=(%cell -.x) ?=(%cell -.y))
5012+ ?=(^ (itype-unify x y ~))
5013+ ?: |(&(?=(%face -.x) ?=(%cell -.y)) &(?=(%cell -.x) ?=(%face -.y))) |
5014+ (itype-closed-slot-match x y)
5015+++ itype-closed-gates-match
5016+ |= [a=itype b=itype]
5017+ ^- ?
5018+ ?. &(?=(%fn -.a) ?=(%fn -.b)) |
5019+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) |
5020+ ?. =(product.a product.b) |
5021+ ?^ (itype-vars a) |
5022+ ?^ (itype-vars b) |
5023+ ?: |((itype-has-tag a) (itype-has-tag b)) |
5024+ ?. (itype-closed-sample-match sample.a sample.b 1.024) |
5025+ ?=(^ (itype-unify product.a product.b ~))
5026+::
48695027++ itype-face-asym-collection-args
48705028 |= [as=(list itype) bs=(list itype) sub=isub]
48715029 ^- ?
@@ -4879,12 +5037,15 @@
48795037 ^- ?
48805038 =. a (itype-walk a sub)
48815039 =. b (itype-walk b sub)
5040+ ?: &(?=(%grec -.a) ?=(%grec -.b))
5041+ ?. &(=(at.a at.b) =(name.a name.b)) |
5042+ (itype-face-asym-collection-args args.a args.b sub)
48825043 ?: &(?=(%collection -.a) ?=(%collection -.b))
48835044 ?. =(name.a name.b) |
48845045 (itype-face-asym-collection-args args.a args.b sub)
48855046 ?: &(?=(%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))
5047+ ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%rvar -.b) |(?=(%nvar -.b) ?=(%rnvar -.b)))
5048+ ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%rvar -.a) |(?=(%nvar -.a) ?=(%rnvar -.a)))
48885049 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
48895050 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
48905051 |
@@ -4907,6 +5068,30 @@
49075068 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
49085069 expected
49095070::
5071+:: Positional call arguments do not write the sample's enclosing field
5072+:: labels. Ignore one raw sample-slot face per written argument while
5073+:: checking value faces as usual. An unknown or variable-bound cell spine
5074+:: cannot justify this distinction, so keep the existing conservative guard.
5075+++ itype-positional-slot-face-asym
5076+ |= [actual=itype expected=itype sub=isub]
5077+ ^- ?
5078+ ?: &(?=(%fn -.actual) ?=(%fn -.expected) (itype-closed-gates-match actual expected)) |
5079+ (itype-face-asym actual expected sub)
5080+::
5081+++ itype-positional-face-asym
5082+ |= [args=(list expr) actual=itype expected=itype sub=isub]
5083+ ^- ?
5084+ ?~ args &
5085+ ?~ t.args
5086+ =/ slot=itype expected
5087+ =? slot ?=(%face -.slot) body.slot
5088+ (itype-positional-slot-face-asym actual slot sub)
5089+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) &
5090+ =/ slot=itype hed.expected
5091+ =? slot ?=(%face -.slot) body.slot
5092+ ?: (itype-positional-slot-face-asym hed.actual slot sub) &
5093+ $(args t.args, actual tal.actual, expected tal.expected)
5094+::
49105095++ itype-output-may-be-cell
49115096 |= [t=itype sub=isub]
49125097 ^- ?
@@ -4916,6 +5101,9 @@
49165101 %cell &
49175102 %union &
49185103 %recursive &
5104+ %jrec &
5105+ %grec &
5106+ %noun &
49195107 %collection &
49205108 %face $(t body.t)
49215109 %fn |($(t sample.t) $(t product.t))
@@ -4944,6 +5132,7 @@
49445132 ^- ?
49455133 ?- -.t
49465134 %tag &
5135+ %grec (lien args.t |=(c=itype (itype-has-tag c)))
49475136 %collection (lien args.t |=(c=itype (itype-has-tag c)))
49485137 %face $(t body.t)
49495138 %fn |($(t sample.t) $(t product.t))
@@ -4957,6 +5146,7 @@
49575146 ^- ?
49585147 ?- -.t
49595148 %union &
5149+ %grec (lien args.t |=(c=itype (itype-has-union c)))
49605150 %collection (lien args.t |=(c=itype (itype-has-union c)))
49615151 %face $(t body.t)
49625152 %fn |($(t sample.t) $(t product.t))
@@ -4975,6 +5165,7 @@
49755165 %union
49765166 ?: &(?=(~ label.t) ?=(^ args.t)) &
49775167 (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-generic c)))
5168+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-generic c))))
49785169 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
49795170 %face $(t body.t)
49805171 %fn |($(t sample.t) $(t product.t))
@@ -4987,6 +5178,8 @@
49875178 ^- ?
49885179 ?- -.t
49895180 %recursive &
5181+ %jrec &
5182+ %grec &
49905183 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
49915184 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
49925185 %face $(t body.t)
@@ -5000,6 +5193,8 @@
50005193 ^- ?
50015194 ?- -.t
50025195 %recursive ?=(~ label.t)
5196+ %jrec ?=(~ label.t)
5197+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-recursive c))))
50035198 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
50045199 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
50055200 %face $(t body.t)
@@ -5027,34 +5222,99 @@
50275222 $(cases t.cases, good `trial)
50285223 ==
50295224::
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.
5225+:: A constructor needs a case whose head has the same literal noun as its
5226+:: tag. An unresolved or opaque case may reveal one later, so it cannot
5227+:: prove a mismatch or a unique match. A broad atom mold is not a case.
50335228::
50345229++ itype-fit-ctor-cases
50355230 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
50365231 ^- ifit
50375232 =/ found=(unit ifit) ~
5233+ =/ pending=? |
50385234 |-
5039− ?~ cases ?~(found [%bad ~] u.found)
5040− =/ c=itype (itype-walk i.cases sub)
5235+ ?~ cases
5236+ ?: pending [%unknown ~]
5237+ ?~ found [%bad ~]
5238+ u.found
5239+ =/ raw=itype i.cases
5240+ ?: ?=(%var -.raw)
5241+ $(cases t.cases, pending &)
5242+ =/ c=itype (itype-walk raw sub)
5243+ ?: ?=(?(%var %tag %recursive %jrec %grec %union %face) -.c)
5244+ $(cases t.cases, pending &)
50415245 ?. ?=(%cell -.c) $(cases t.cases)
5042− =/ head=itype (itype-walk hed.c sub)
5246+ =/ raw-head=itype hed.c
5247+ ?: ?=(%var -.raw-head)
5248+ $(cases t.cases, pending &)
5249+ =/ head=itype (itype-walk raw-head sub)
5250+ :: A single faced, explicitly atom-only head cannot be the tag case.
5251+ :: Do not follow variables or peel nested faces for this negative proof.
5252+ ?: ?=(%face -.head)
5253+ ?: ?=(?(%atom %any-atom %flag %avar %rvar %nvar %rnvar) -.body.head)
5254+ $(cases t.cases)
5255+ $(cases t.cases, pending &)
5256+ ?: ?=(?(%var %tag %recursive %jrec %grec %union) -.head)
5257+ $(cases t.cases, pending &)
50435258 ?. ?=(%const -.head) $(cases t.cases)
5044− ?. =(%term form.literal.head) $(cases t.cases)
50455259 ?. =(val.literal.head val.tag) $(cases t.cases)
5046− ?^ found [%unknown ~]
5260+ :: Equal heads can have disjoint payloads. Test each from the original
5261+ :: substitution; a unique success is usable only with no unknown rival.
50475262 =/ trial=ifit (itype-fit sample tal.c sub next)
5048− $(cases t.cases, found `trial)
5263+ ?- -.trial
5264+ %bad $(cases t.cases)
5265+ %unknown $(cases t.cases, pending &)
5266+ %ok
5267+ ?^ found [%unknown ~]
5268+ $(cases t.cases, found `trial)
5269+ ==
50495270::
50505271++ itype-fit
50515272 |= [actual=itype expected=itype sub=isub next=@ud]
50525273 ^- ifit
5274+ (itype-fit-inner actual expected sub next | |)
5275+++ itype-fit-inner
5276+ |= [actual=itype expected=itype sub=isub next=@ud skip-width=? spine-proof=?]
5277+ ^- ifit
5278+ ?: &(!skip-width ?=(%cell -.actual) ?=(%cell -.expected) |((width-spine-exhausted actual 1.024) (width-spine-exhausted expected 1.024)))
5279+ [%unknown ~]
5280+ =/ known=(unit [source=iwfields target=iwfields])
5281+ ?: skip-width ~
5282+ (width-known-shape actual expected sub)
5283+ =/ too-wide=? ?~(known | (gth (lent order.source.u.known) (lent order.target.u.known)))
5284+ ?: too-wide [%unknown ~]
5285+ =/ spine-checked=? |(spine-proof ?=(^ known))
50535286 =/ uncertain=?
5054− |(?=(%var -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%var -.expected) ?=(%avar -.expected) ?=(%nvar -.expected))
5287+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)))
5288+ =/ actual-open=?
5289+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))
50555290 =. actual (itype-walk actual sub)
50565291 =. expected (itype-walk expected sub)
50575292 ?: =(actual expected) [%ok sub next]
5293+ :: The relation of the source loobean mold to explicit @f is not yet
5294+ :: established. Keep it unsupported rather than asserting a mismatch.
5295+ ?: &(?=(%flag -.actual) ?=(%atom -.expected) =(%f aura.expected)) [%unknown ~]
5296+ :: Any value can be used where a noun is expected. An unresolved
5297+ :: bare tag is fixed as a constant; a constructor still needs a gate.
5298+ ?: ?=(%noun -.expected)
5299+ ?: ?=(%tag -.actual)
5300+ ?: constructor.actual [%unknown ~]
5301+ [%ok [[id.actual expected] sub] next]
5302+ [%ok sub next]
5303+ :: An arbitrary noun is not known to fit a narrower type.
5304+ ?: &(?=(%noun -.actual) !?=(%var -.expected)) [%unknown ~]
5305+ ?: &(!uncertain ?=(%grec -.actual) ?=(%face -.expected)) $(expected body.expected)
5306+ ?: &(!uncertain ?=(%face -.actual) ?=(%grec -.expected)) $(actual body.actual)
5307+ ?: &(?=(%grec -.actual) ?=(%grec -.expected))
5308+ ?. &(=(at.actual at.expected) =(name.actual name.expected)) [%unknown ~]
5309+ =/ matched=(unit isub) (itype-unify-args args.actual args.expected sub)
5310+ ?~ matched [%unknown ~]
5311+ [%ok u.matched next]
5312+ ?: &(|(?=(%grec -.actual) ?=(%grec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5313+ ?: &(!uncertain ?=(%jrec -.actual) ?=(%face -.expected)) $(expected body.expected)
5314+ ?: &(!uncertain ?=(%face -.actual) ?=(%jrec -.expected)) $(actual body.actual)
5315+ ?: &(?=(%jrec -.actual) ?=(%jrec -.expected))
5316+ ?:(&(=(at.actual at.expected) =(name.actual name.expected) =(head.actual head.expected) =(aura.actual aura.expected) =(tail.actual tail.expected)) [%ok sub next] [%bad ~])
5317+ ?: &(|(?=(%jrec -.actual) ?=(%jrec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
50585318 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
50595319 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
50605320 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
@@ -5066,8 +5326,21 @@
50665326 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
50675327 ?^ unified [%ok u.unified next]
50685328 [%unknown ~]
5329+ :: A known union can instantiate an unconstrained sample directly;
5330+ :: preserve unknown results for variable-bound union origins.
5331+ ?: &(!actual-open ?=(%union -.actual) ?=(%var -.expected))
5332+ ?~ origin.actual [%unknown ~]
5333+ =/ normalized=itype (itype-normalize actual sub)
5334+ ?: |((itype-has-tag normalized) (itype-has-recursive normalized) (itype-has-any-atom actual sub)) [%unknown ~]
5335+ =/ unified=(unit isub) (itype-unify actual expected sub)
5336+ ?~ unified [%unknown ~]
5337+ [%ok u.unified next]
5338+ :: A concrete union value in a tuple may acquire the expected field's
5339+ :: face. A variable-bound union still needs face propagation support.
5340+ ?: &(!uncertain ?=(%union -.actual) ?=(%face -.expected))
5341+ $(expected body.expected)
50695342 ?: ?=(%union -.actual) [%unknown ~]
5070− ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
5343+ ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))) [%unknown ~]
50715344 ?: &(?=(%union -.expected) !?=(%var -.actual))
50725345 (itype-fit-cases actual cases.expected sub next)
50735346 ?: ?=(%tag -.actual)
@@ -5075,7 +5348,7 @@
50755348 =/ u=(unit isub) (itype-unify actual expected sub)
50765349 ?~ u [%bad ~]
50775350 [%ok u.u next]
5078− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5351+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
50795352 ?: ?=(%face -.expected) $(expected body.expected)
50805353 ?: constructor.actual
50815354 ?. ?=(%fn -.expected) [%bad ~]
@@ -5103,13 +5376,17 @@
51035376 =/ u=(unit isub) (itype-unify actual expected sub)
51045377 ?~ u [%bad ~]
51055378 [%ok u.u next]
5106− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5379+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51075380 ?: ?=(%face -.expected) $(expected body.expected)
51085381 ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
51095382 [%unknown ~]
51105383 ?: ?=(%const -.expected)
51115384 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
51125385 ?: ?=(%atom -.expected)
5386+ :: A loobean singleton must not silently widen into another aura.
5387+ ?: =(%loobean form.literal.actual)
5388+ ?: =(%f aura.expected) [%unknown ~]
5389+ [%bad ~]
51135390 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
51145391 [%bad ~]
51155392 ?: ?=(%flag -.expected)
@@ -5117,8 +5394,14 @@
51175394 ?: ?=(%any-atom -.expected) [%ok sub next]
51185395 [%bad ~]
51195396 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
5397+ :: A known face labels the same noun. Peel it before applying the
5398+ :: directional unrestricted-atom rule, preserving raw-variable guards.
5399+ ?: &(!uncertain ?=(%any-atom -.actual) ?=(%face -.expected))
5400+ $(expected body.expected, skip-width |, spine-proof |)
5401+ ?: &(!uncertain ?=(%any-atom -.expected) ?=(%face -.actual))
5402+ $(actual body.actual, skip-width |, spine-proof |)
51205403 ?: ?=(%any-atom -.expected)
5121− ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
5404+ ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%flag -.actual)) [%ok sub next]
51225405 ?: ?=(%var -.actual)
51235406 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
51245407 ?~ unified [%bad ~]
@@ -5129,16 +5412,16 @@
51295412 =/ unified=(unit isub) (itype-unify actual expected sub)
51305413 ?~ unified [%bad ~]
51315414 [%ok u.unified next]
5132− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5415+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
51335416 [%bad ~]
51345417 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
51355418 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
51365419 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
51375420 [%bad ~]
51385421 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5139− =/ first=ifit $(actual hed.actual, expected hed.expected)
5422+ =/ first=ifit $(actual hed.actual, expected hed.expected, skip-width |, spine-proof |)
51405423 ?. ?=(%ok -.first) first
5141− $(actual tal.actual, expected tal.expected, sub sub.first, next next.first)
5424+ $(actual tal.actual, expected tal.expected, sub sub.first, next next.first, skip-width spine-checked, spine-proof spine-checked)
51425425 :: A field may add a face to an occurrence of the very same type
51435426 :: variable. Binding that variable to a face around itself would fail
51445427 :: the occurs check, but its underlying type has already matched.
@@ -5160,9 +5443,10 @@
51605443 [%ok u.unified next]
51615444 ?: &(?=(%face -.actual) ?=(%face -.expected))
51625445 ?. =(name.actual name.expected) [%bad ~]
5163− $(actual body.actual, expected body.expected)
5164− ?: ?=(%face -.actual) $(actual body.actual)
5165− ?: ?=(%face -.expected) $(expected body.expected)
5446+ $(actual body.actual, expected body.expected, skip-width |, spine-proof |)
5447+ ?: ?=(%face -.actual) $(actual body.actual, skip-width |, spine-proof |)
5448+ ?: ?=(%face -.expected) $(expected body.expected, skip-width |, spine-proof |)
5449+ ?: &(!uncertain (itype-closed-gates-match actual expected)) [%ok sub next]
51665450 ?: (itype-face-asym actual expected sub) [%unknown ~]
51675451 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
51685452 [%unknown ~]
@@ -5238,7 +5522,18 @@
52385522+$ ischeme [typ=itype vars=(list @ud)]
52395523+$ ienv (list [name=term scheme=ischeme])
52405524+$ imold-types (list [name=term template=ischeme])
5241−+$ ifile [values=ienv molds=imold-types at=path]
5525++$ iderived [name=term agent=term mark=term]
5526++$ iwidth-definition [name=term original=expr typ=itype sub=isub projections=(list iwprojection)]
5527++$ iwidth-dependency [at=path source=(unit @t) definitions=(list iwidth-definition)]
5528+:: Nonrecursive request evidence is compiler-owned metadata, not a property
5529+:: of an arbitrary ask value. Reader graphs and source inputs are trusted.
5530++$ irequest-evidence
5531+ [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]
5532+:: A unit distinguishes a verified empty closure from a detached legacy file.
5533+:: The opaque prelude is an exact trusted input, not a recursive interface mold.
5534++$ irequest-graph
5535+ [paths=(set path) requests=(list irequest-evidence) bundle-input=* prelude-input=* prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5536++$ 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)]
52425537+$ ijimports (list [face=term interface=ifile])
52435538+$ icap [name=@t id=@ud at=span]
52445539+$ icaps (list icap)
@@ -5248,7 +5543,167 @@
52485543:: This core has no Ford dependencies; unrecognized payloads fail closed.
52495544+$ iexternals (list [module=term name=term result=*])
52505545+$ imark-externals (list [mark=term result=*])
5251−+$ 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)]
5546+:: Hole obligations survive discarded expressions until their owning
5547+:: definition has inferred; their source spans support unresolved reports.
5548++$ ihole [id=@ud at=span]
5549+:: Recursive-mold unfolding spends fuel in the threaded inference state.
5550+:: Retries can restart from an earlier state, so this bounds an attempt,
5551+:: not all parsing or module-checking work.
5552+:: Experimental: only closed, uniquely faced records have known axes.
5553++$ iwfield [name=term axis=@ud typ=itype]
5554++$ iwfields [order=(list iwfield) index=(map term iwfield)]
5555++$ iwstep [name=term axis=@ud]
5556++$ iwidth-result [steps=(list iwstep) sub=isub next=@ud]
5557++$ iwprojection [at=span original=expr source=itype target=itype steps=(list iwstep)]
5558+++ width-scan
5559+ |= [typ=itype sub=isub axis=@ud fuel=@ud]
5560+ ^- (unit iwfields)
5561+ =/ order=(list iwfield) ~
5562+ =/ index=(map term iwfield) *(map term iwfield)
5563+ |-
5564+ ?: =(0 fuel) ~
5565+ ?: |(?=(%var -.typ) ?=(%avar -.typ) ?=(%rvar -.typ) ?=(%nvar -.typ) ?=(%rnvar -.typ)) ~
5566+ ?: ?=(%face -.typ)
5567+ =/ entry=iwfield [name.typ axis body.typ]
5568+ ?: ?=(^ (~(get by index) name.entry)) ~
5569+ `[(flop [entry order]) (~(put by index) name.entry entry)]
5570+ ?. ?=(%cell -.typ) ~
5571+ =/ head=itype hed.typ
5572+ ?: |(?=(%var -.head) ?=(%avar -.head) ?=(%rvar -.head) ?=(%nvar -.head) ?=(%rnvar -.head)) ~
5573+ ?. ?=(%face -.head) ~
5574+ =/ entry=iwfield [name.head (mul 2 axis) body.head]
5575+ ?: ?=(^ (~(get by index) name.entry)) ~
5576+ $(typ tal.typ, axis +((mul 2 axis)), fuel (dec fuel), order [entry order], index (~(put by index) name.entry entry))
5577+++ width-in-order
5578+ |= [source=(list iwfield) target=(list iwfield)]
5579+ ^- ?
5580+ ?~ target &
5581+ ?~ source |
5582+ ?: =(name.i.source name.i.target) $(source t.source, target t.target)
5583+ $(source t.source)
5584+++ width-fit-fields
5585+ |= [source=(map term iwfield) target=(list iwfield) sub=isub next=@ud]
5586+ ^- (unit iwidth-result)
5587+ ?~ target `[~ sub next]
5588+ =/ found=(unit iwfield) (~(get by source) name.i.target)
5589+ ?~ found ~
5590+ =/ fit=ifit (itype-fit typ.u.found typ.i.target sub next)
5591+ ?. ?=(%ok -.fit) ~
5592+ =/ rest=(unit iwidth-result) $(target t.target, sub sub.fit, next next.fit)
5593+ ?~ rest ~
5594+ `[[[name.i.target axis.u.found] steps.u.rest] sub.u.rest next.u.rest]
5595+++ width-spine-exhausted
5596+ |= [t=itype fuel=@ud]
5597+ ^- ?
5598+ ?: =(0 fuel) &
5599+ ?. ?=(%cell -.t) |
5600+ ?. ?=(%face -.hed.t) |
5601+ $(t tal.t, fuel (dec fuel))
5602+++ width-known-shape
5603+ |= [actual=itype expected=itype sub=isub]
5604+ ^- (unit [source=iwfields target=iwfields])
5605+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5606+ =/ source=(unit iwfields) (width-scan actual sub 1 1.024)
5607+ =/ target=(unit iwfields) (width-scan expected sub 1 1.024)
5608+ ?~ source ~
5609+ ?~ target ~
5610+ `[u.source u.target]
5611+::
5612+++ width-shape
5613+ |= [actual=itype expected=itype sub=isub]
5614+ ^- (unit [source=iwfields target=iwfields])
5615+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5616+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5617+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5618+ ?~ source ~
5619+ ?~ target ~
5620+ ?. (gth (lent order.u.source) (lent order.u.target)) ~
5621+ `[u.source u.target]
5622+++ width-proj-shape
5623+ |= [actual=itype expected=itype sub=isub]
5624+ ^- (unit [source=iwfields target=iwfields])
5625+ ?. &(|(?=(%cell -.actual) ?=(%face -.actual)) |(?=(%cell -.expected) ?=(%face -.expected))) ~
5626+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5627+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5628+ ?~ source ~
5629+ ?~ target ~
5630+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
5631+ `[u.source u.target]
5632+::
5633+++ width-project
5634+ |= [shape=[source=iwfields target=iwfields] sub=isub next=@ud]
5635+ ^- (unit iwidth-result)
5636+ ?. (width-in-order order.source.shape order.target.shape) ~
5637+ (width-fit-fields index.source.shape order.target.shape sub next)
5638+::
5639+:: Provisional, globally budgeted gate-free proof. %no includes a
5640+:: gate-bearing witness; an uninhabited sibling could invalidate it.
5641+:: Input types must be resolved and normalized under valid substitutions,
5642+:: from trusted source-backed interfaces and reader results. Collection
5643+:: list/unit names rely on their existing identity invariant; this arm
5644+:: does not validate fabricated internal types.
5645++$ igf-segment
5646+ $% [%field name=term]
5647+ [%head ~]
5648+ [%tail ~]
5649+ [%item ~]
5650+ [%case index=@ud]
5651+ ==
5652++$ igate-free [verdict=?(%yes %no %unknown) inhabited=? left=@ud path=(unit (list igf-segment))]
5653+++ gate-free-types
5654+ |= [types=(list itype) fuel=@ud path=(list igf-segment) index=@ud]
5655+ ^- igate-free
5656+ ?~ types [%yes | fuel ~]
5657+ ?: =(0 fuel) [%unknown | 0 ~]
5658+ =/ first=igate-free (gate-free-type i.types fuel [[%case index] path])
5659+ ?: =(%no verdict.first) first
5660+ =/ rest=igate-free $(types t.types, fuel left.first, index +(index))
5661+ ?: =(%no verdict.rest) rest
5662+ =/ inhabited=? |(inhabited.first inhabited.rest)
5663+ ?: |(=(%unknown verdict.first) =(%unknown verdict.rest)) [%unknown inhabited left.rest ~]
5664+ [%yes inhabited left.rest ~]
5665+++ gate-free-type
5666+ |= [typ=itype fuel=@ud path=(list igf-segment)]
5667+ ^- igate-free
5668+ ?: =(0 fuel) [%unknown | 0 ~]
5669+ =. fuel (dec fuel)
5670+ ?- -.typ
5671+ %fn [%no & fuel `(flop path)]
5672+ %atom [%yes & fuel ~]
5673+ %any-atom [%yes & fuel ~]
5674+ %flag [%yes & fuel ~]
5675+ %const [%yes & fuel ~]
5676+ %face $(typ body.typ, path [[%field name.typ] path])
5677+ %cell
5678+ =/ head=igate-free $(typ hed.typ, path [[%head ~] path])
5679+ =/ tail=igate-free $(typ tal.typ, fuel left.head, path [[%tail ~] path])
5680+ =/ inhabited=? &(inhabited.head inhabited.tail)
5681+ ?: &(=(%no verdict.head) inhabited.tail) head(left left.tail)
5682+ ?: &(=(%no verdict.tail) inhabited.head) tail
5683+ ?: |(!=(%yes verdict.head) !=(%yes verdict.tail)) [%unknown inhabited left.tail ~]
5684+ [%yes inhabited left.tail ~]
5685+ %collection
5686+ ?. |(=(%list name.typ) =(%unit name.typ)) [%unknown | fuel ~]
5687+ ?. ?=([* ~] args.typ) [%unknown | fuel ~]
5688+ =/ item=igate-free $(typ i.args.typ, path [[%item ~] path])
5689+ item(inhabited &)
5690+ %union
5691+ ?~ cases.typ [%unknown | fuel ~]
5692+ (gate-free-types cases.typ fuel path 0)
5693+ %noun [%unknown & fuel ~]
5694+ %var [%unknown | fuel ~]
5695+ %avar [%yes & fuel ~]
5696+ %rvar [%yes & fuel ~]
5697+ %nvar [%yes & fuel ~]
5698+ %rnvar [%yes & fuel ~]
5699+ %tag [%unknown | fuel ~]
5700+ %recursive [%unknown | fuel ~]
5701+ %jrec [%yes & fuel ~]
5702+ %grec [%unknown | fuel ~]
5703+ ==
5704+::
5705++$ igate-prelude-evidence [iface=ifile gates=(map term def)]
5706++$ 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)])]
52525707+$ idiag [msg=tape sites=(list [at=span note=tape])]
52535708+$ iresult (each [typ=itype state=istate] idiag)
52545709+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5268,6 +5723,7 @@
52685723 |= [t=itype sub=isub]
52695724 ^- itype
52705725 =. t (itype-walk t sub)
5726+ ?: ?=(%grec -.t) t(args (turn args.t |=(c=itype (itype-normalize c sub))))
52715727 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
52725728 ?: ?=(%union -.t)
52735729 [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t (turn args.t |=(c=itype (itype-normalize c sub)))]
@@ -5284,6 +5740,8 @@
52845740:: generalize an aura from its sample, which requires constraint analysis
52855741:: beyond this fragment; leave those cases unresolved.
52865742::
5743+:: This helper only controls decimal defaulting in visible types. A noun
5744+:: may contain gates and is not proof of a gate-free value.
52875745++ itype-has-gate
52885746 |= t=itype
52895747 ^- ?
@@ -5291,6 +5749,8 @@
52915749 %fn &
52925750 %cell |($(t hed.t) $(t tal.t))
52935751 %recursive |
5752+ %jrec |
5753+ %grec &
52945754 %collection (lien args.t |=(c=itype (itype-has-gate c)))
52955755 %face $(t body.t)
52965756 %union (lien cases.t |=(c=itype (itype-has-gate c)))
@@ -5298,10 +5758,13 @@
52985758 %const |
52995759 %var |
53005760 %avar |
5761+ %rvar |
53015762 %nvar |
5763+ %rnvar |
53025764 %atom |
53035765 %any-atom |
53045766 %flag |
5767+ %noun |
53055768 ==
53065769::
53075770++ default-decimals
@@ -5310,26 +5773,135 @@
53105773 ?: (itype-has-gate t) t
53115774 ?- -.t
53125775 %nvar [%atom %ud]
5776+ %rnvar [%atom %ud]
5777+ %grec t(args (turn args.t |=(c=itype (default-decimals c))))
53135778 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
53145779 %face [%face name.t $(t body.t)]
53155780 %cell [%cell $(t hed.t) $(t tal.t)]
53165781 * t
53175782 ==
53185783::
5784+:: A hole is solved only by a fully determined type or a written
5785+:: in-scope type variable. Ordinary fresh variables are not evidence.
5786+:: Compare representatives after substitution, since unification can
5787+:: orient a written capital toward the hole rather than the reverse.
5788+++ hole-variable-id
5789+ |= t=itype
5790+ ^- (unit @ud)
5791+ ?- -.t
5792+ %var `id.t
5793+ %avar `id.t
5794+ %rvar `id.t
5795+ %nvar `id.t
5796+ %rnvar `id.t
5797+ %tag `id.t
5798+ * ~
5799+ ==
5800+++ hole-same-variable
5801+ |= [a=itype b=itype]
5802+ ^- ?
5803+ =/ x=(unit @ud) (hole-variable-id a)
5804+ ?~ x |
5805+ =/ y=(unit @ud) (hole-variable-id b)
5806+ ?~ y |
5807+ =(u.x u.y)
5808+++ hole-known
5809+ |= [t=itype state=istate]
5810+ ^- ?
5811+ =. t (itype-walk t sub.state)
5812+ ?- -.t
5813+ ?(%var %avar %rvar %nvar %rnvar)
5814+ ?: (lien caps.state |=(c=icap (hole-same-variable t (itype-walk [%var id.c] sub.state)))) &
5815+ (lien params.state |=(p=[name=@t typ=itype] (hole-same-variable t (itype-walk typ.p sub.state))))
5816+ %tag |
5817+ %any-atom &
5818+ %union &((levy cases.t |=(c=itype (hole-known c state))) (levy args.t |=(c=itype (hole-known c state))))
5819+ %grec (levy args.t |=(c=itype (hole-known c state)))
5820+ %collection (levy args.t |=(c=itype (hole-known c state)))
5821+ %face $(t body.t)
5822+ %fn &($(t sample.t) $(t product.t))
5823+ %cell &($(t hed.t) $(t tal.t))
5824+ * &
5825+ ==
5826+++ promote-restricted-numbers
5827+ |= [state=istate env=ienv]
5828+ ^- istate
5829+ :: With no written capitals, there is nothing to promote.
5830+ ?~ caps.state state
5831+ =/ ids=(list @ud) (turn caps.state |=(c=icap id.c))
5832+ =/ free=(list @ud) (free-env-vars env sub.state)
5833+ |-
5834+ ?~ ids state
5835+ =/ t=itype (itype-walk [%var i.ids] sub.state)
5836+ ?: &(?=(%rnvar -.t) !(lien free |=(n=@ud =(n +.t))))
5837+ $(ids t.ids, state state(sub [[+.t [%rvar +.t]] sub.state]))
5838+ $(ids t.ids)
5839+::
5840+++ default-hole-numbers
5841+ |= [all=(list ihole) prior=(list ihole) state=istate env=ienv permit=?]
5842+ ^- istate
5843+ :: Do not default a named capital or a variable captured from env.
5844+ ?. permit state
5845+ ?: =(all prior) state
5846+ ?~ all state
5847+ =/ t=itype (itype-walk [%var id.i.all] sub.state)
5848+ =/ free=(list @ud) (free-env-vars env sub.state)
5849+ =? state &(?=(?(%nvar %rnvar) -.t) !(hole-known t state) !(lien free |=(id=@ud =(id id.t))))
5850+ state(sub [[id.t [%atom %ud]] sub.state])
5851+ $(all t.all)
5852+::
5853+:: Only obligations created inside this definition belong to it.
5854+++ holes-created
5855+ |= [all=(list ihole) prior=(list ihole)]
5856+ ^- (list ihole)
5857+ ?: =(all prior) ~
5858+ ?~ all ~
5859+ [i.all $(all t.all)]
5860+++ hole-uncertain
5861+ |= [t=itype state=istate]
5862+ ^- ?
5863+ =. t (itype-walk t sub.state)
5864+ ?- -.t
5865+ ?(%tag %nvar %rnvar %avar %rvar) !(hole-known t state)
5866+ %union |((lien cases.t |=(c=itype (hole-uncertain c state))) (lien args.t |=(c=itype (hole-uncertain c state))))
5867+ %grec (lien args.t |=(c=itype (hole-uncertain c state)))
5868+ %collection (lien args.t |=(c=itype (hole-uncertain c state)))
5869+ %face $(t body.t)
5870+ %fn |($(t sample.t) $(t product.t))
5871+ %cell |($(t hed.t) $(t tal.t))
5872+ * |
5873+ ==
5874+::
5875+++ unresolved-hole
5876+ |= [all=(list ihole) prior=(list ihole) state=istate]
5877+ ^- (unit idiag)
5878+ =/ work=(list ihole) (flop (holes-created all prior))
5879+ |-
5880+ ?~ work ~
5881+ ?: (hole-known [%var id.i.work] state) $(work t.work)
5882+ ?: (hole-uncertain [%var id.i.work] state)
5883+ `["type hole needs unsupported inference" ~[[at.i.work "type hole"]]]
5884+ `["type hole needs a determined type" ~[[at.i.work "unresolved type hole"]]]
5885+::
53195886++ itype-vars
53205887 |= t=itype
53215888 ^- (list @ud)
53225889 ?- -.t
53235890 %var ~[id.t]
53245891 %avar ~[id.t]
5892+ %rvar ~[id.t]
53255893 %nvar ~[id.t]
5894+ %rnvar ~[id.t]
53265895 %atom ~
53275896 %any-atom ~
53285897 %flag ~
5898+ %noun ~
53295899 %tag ~
53305900 %const ~
53315901 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
53325902 %recursive ~
5903+ %jrec ~
5904+ %grec (zing (turn args.t |=(c=itype (itype-vars c))))
53335905 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
53345906 %face $(t body.t)
53355907 %fn (weld $(t sample.t) $(t product.t))
@@ -5357,17 +5929,28 @@
53575929 =/ found=(unit itype) (itype-lookup id.t ren)
53585930 ?~ found t
53595931 u.found
5932+ %rvar
5933+ =/ found=(unit itype) (itype-lookup id.t ren)
5934+ ?~ found t
5935+ u.found
53605936 %nvar
53615937 =/ found=(unit itype) (itype-lookup id.t ren)
53625938 ?~ found t
53635939 u.found
5940+ %rnvar
5941+ =/ found=(unit itype) (itype-lookup id.t ren)
5942+ ?~ found t
5943+ u.found
53645944 %atom t
53655945 %any-atom t
53665946 %flag t
5947+ %noun t
53675948 %tag t
53685949 %const t
53695950 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
53705951 %recursive t
5952+ %jrec t
5953+ %grec t(args (turn args.t |=(c=itype (itype-rename c ren))))
53715954 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
53725955 %face [%face name.t $(t body.t)]
53735956 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5383,19 +5966,48 @@
53835966 ?- -.t
53845967 %var |
53855968 %avar =(n id.t)
5969+ %rvar =(n id.t)
53865970 %nvar =(n id.t)
5971+ %rnvar =(n id.t)
53875972 %atom |
53885973 %any-atom |
53895974 %flag |
5975+ %noun |
53905976 %tag |
53915977 %const |
53925978 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
53935979 %recursive |
5980+ %jrec |
5981+ %grec (lien args.t |=(c=itype (itype-var-is-atom n c)))
53945982 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
53955983 %face $(t body.t)
53965984 %fn |($(t sample.t) $(t product.t))
53975985 %cell |($(t hed.t) $(t tal.t))
53985986 ==
5987+++ itype-var-is-restricted
5988+ |= [n=@ud t=itype]
5989+ ^- ?
5990+ ?- -.t
5991+ %var |
5992+ %avar |
5993+ %rvar =(n id.t)
5994+ %nvar |
5995+ %rnvar |
5996+ %atom |
5997+ %any-atom |
5998+ %flag |
5999+ %noun |
6000+ %tag |
6001+ %const |
6002+ %union |((lien cases.t |=(c=itype (itype-var-is-restricted n c))) (lien args.t |=(c=itype (itype-var-is-restricted n c))))
6003+ %recursive |
6004+ %jrec |
6005+ %grec (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6006+ %collection (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6007+ %face $(t body.t)
6008+ %fn |($(t sample.t) $(t product.t))
6009+ %cell |($(t hed.t) $(t tal.t))
6010+ ==
53996011::
54006012:: Canonical numbering makes printed variables independent of the order
54016013:: the unifier happened to allocate intermediates.
@@ -5407,7 +6019,7 @@
54076019 =/ n=@ud 0
54086020 |-
54096021 ?~ vars (itype-rename t ren)
5410− =/ replacement=itype ?:((itype-var-is-atom i.vars t) [%avar n] [%var n])
6022+ =/ replacement=itype ?:((itype-var-is-restricted i.vars t) [%rvar n] ?:((itype-var-is-atom i.vars t) [%avar n] [%var n]))
54116023 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
54126024::
54136025++ instantiate-scheme
@@ -5418,11 +6030,11 @@
54186030 |-
54196031 ?~ vars [(itype-rename typ.scheme ren) state]
54206032 =/ replacement=itype
5421− ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state])
6033+ ?:((itype-var-is-restricted i.vars typ.scheme) [%rvar next.state] ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state]))
54226034 :: A generalized atom variable is a valid origin for re-generalizing
54236035 :: an alias, just as a sample binder is.
54246036 =/ st=istate state(next +(next.state))
5425− =? binders.st ?=(%avar -.replacement) [next.state binders.state]
6037+ =? binders.st |(?=(%avar -.replacement) ?=(%rvar -.replacement)) [next.state binders.state]
54266038 $(vars t.vars, ren [[i.vars replacement] ren], state st)
54276039::
54286040++ icap-lookup
@@ -5493,6 +6105,11 @@
54936105 ?. ?=([%ref @ @] node) ~
54946106 ?. &(=(module +<.node) =(name +>.node)) ~
54956107 `[[%unknown ~] &]
6108+ %apply
6109+ ?. ?=([%apply %list [* ~]] node) ~
6110+ =/ item $(node -.+>.node)
6111+ ?~ item ~
6112+ `[[%or ~[[%atom `0] [%cell pat.u.item [%unknown ~]]]] has.u.item]
54966113 %face
54976114 ?. ?=([%face @ *] node) ~
54986115 ?. (jibb-face-name +<.node) ~
@@ -5547,6 +6164,10 @@
55476164 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
55486165 %fork (imported-faces-valid-list +.node)
55496166 %apply ?:(?=([%apply @ *] node) (imported-faces-valid-list +>.node) |)
6167+ %named
6168+ ?. ?=([%named @ @ *] node) |
6169+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6170+ (imported-faces-valid body.n)
55506171 ==
55516172::
55526173++ imported-faces-valid-list
@@ -5578,7 +6199,19 @@
55786199 ^- (unit itype)
55796200 ?@ node ~
55806201 ?+ -.node ~
6202+ %noun ?:(=(node [%noun ~]) `[%noun ~] ~)
55816203 %atom
6204+ :: A Hoon loobean singleton is one of the two Jibb loobeans.
6205+ ?: ?=([%atom %f [~ @]] node)
6206+ =/ value=@ +>+.node
6207+ ?. |(=(value 0) =(value 1)) ~
6208+ =/ printed=@t ?:(=(value 0) '%.y' '%.n')
6209+ `[%const [%loobean %f value printed]]
6210+ :: Hoon's null singleton is the same noun as Jibb's `~` mold.
6211+ :: Other non-term singleton atoms remain unsupported here.
6212+ ?: ?=([%atom %n [~ @]] node)
6213+ ?. =(0 +>+.node) ~
6214+ `[%const [%null %n 0 '~']]
55826215 ?: ?=([%atom %tas [~ @]] node)
55836216 =/ value=@ +>+.node
55846217 ?. |(=(value 0) (jibb-face-name value)) ~
@@ -5588,6 +6221,15 @@
55886221 =/ aura=@ta (@ta +<.node)
55896222 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
55906223 `[%atom aura]
6224+ %named
6225+ ?. ?=([%named @ @ *] node) ~
6226+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6227+ ?. &((jibb-face-name module.n) (jibb-face-name name.n)) ~
6228+ ?. ?=([%fork *] body.n) ~
6229+ =/ proof=(unit irec-pattern) (rec-pattern body.n (@tas module.n) (@tas name.n))
6230+ ?~ proof ~
6231+ ?. has.u.proof ~
6232+ `[%recursive (@tas module.n) (@tas name.n) `(crip "{(trip name.n)}.{(trip module.n)}")]
55916233 %apply
55926234 ?. ?=([%apply @ *] node) ~
55936235 =/ name=term (@tas +<.node)
@@ -5601,10 +6243,15 @@
56016243 ?. =(arity (lent u.args)) ~
56026244 `[%collection name u.args]
56036245 %fork
5604− =/ cases=(unit (list itype)) (import-to-itypes +.node)
6246+ :: Hoon's ordinary ? mold is the fork of its two %f singletons.
6247+ =/ raw=* +.node
6248+ ?: |(=(raw ~[[%atom %f `0] [%atom %f `1]]) =(raw ~[[%atom %f `1] [%atom %f `0]]))
6249+ `[%flag ~]
6250+ =/ cases=(unit (list itype)) (import-to-itypes raw)
56056251 ?~ cases ~
56066252 ?~ u.cases ~
56076253 ?~ t.u.cases ~
6254+ ?: (import-has-loobean-singleton u.cases) ~
56086255 ?. (import-cases-disjoint u.cases) ~
56096256 `[%union u.cases ~ ~ ~]
56106257 %face
@@ -5623,6 +6270,20 @@
56236270 `[%cell u.left u.right]
56246271 ==
56256272::
6273+++ import-direct-loobean
6274+ |= t=itype
6275+ ^- ?
6276+ ?: ?=(%face -.t) $(t body.t)
6277+ ?: ?=(%union -.t) (import-has-loobean-singleton cases.t)
6278+ ?=([%const [%loobean *]] t)
6279+::
6280+++ import-has-loobean-singleton
6281+ |= cases=(list itype)
6282+ ^- ?
6283+ ?~ cases |
6284+ ?: (import-direct-loobean i.cases) &
6285+ $(cases t.cases)
6286+::
56266287++ import-to-itypes
56276288 |= nodes=*
56286289 ^- (unit (list itype))
@@ -5637,7 +6298,9 @@
56376298 |= typ=itype
56386299 ^- upat
56396300 ?- -.typ
6301+ %noun [%all ~]
56406302 %atom [%atom ~]
6303+ %flag [%or ~[[%atom `0] [%atom `1]]]
56416304 %const [%atom `val.literal.typ]
56426305 %face $(typ body.typ)
56436306 %cell [%cell $(typ hed.typ) $(typ tal.typ)]
@@ -5732,25 +6395,85 @@
57326395 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
57336396 $(molds t.molds)
57346397::
5735−:: Only names exported by this directly imported module are visible through
5736−:: its face. Other origins retain identity but print as unnamed unions.
6398+:: A prelude union alias is a display name, not a new union identity. An
6399+:: identity-generic alias can carry the origin's arguments only when the
6400+:: origin, arity and ordered parameters match. Swapped, repeated, fixed
6401+:: or phantom parameters cannot be printed that way and remain unsupported
6402+:: when their only available name is private. A nongeneric alias of a
6403+:: generic instantiation cannot be printed with the origin's arguments.
6404+++ identity-union-parameters
6405+ |= [vars=(list @ud) args=(list itype)]
6406+ ^- ?
6407+ ?~ vars ?=(~ args)
6408+ ?~ args |
6409+ ?. =([%var i.vars] i.args) |
6410+ $(vars t.vars, args t.args)
6411+++ prelude-union-alias
6412+ |= [origin=[at=path name=term] args=(list itype) molds=imold-types]
6413+ ^- (unit term)
6414+ ?~ molds ~
6415+ =/ template=ischeme template.i.molds
6416+ ?. ?=(%union -.typ.template) $(molds t.molds)
6417+ ?. =(`origin origin.typ.template) $(molds t.molds)
6418+ ?~ vars.template
6419+ ?^ args $(molds t.molds)
6420+ ?:(=(args args.typ.template) `name.i.molds $(molds t.molds))
6421+ ?: &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args)))
6422+ `name.i.molds
6423+ $(molds t.molds)
6424+::
6425+:: Names exported by the directly imported module are visible through its
6426+:: face; a matching prelude alias is also visible without a qualifier.
6427+::
6428+++ jrec-alias
6429+ |= [origin=path name=term molds=imold-types]
6430+ ^- (unit term)
6431+ ?~ molds ~
6432+ =/ template=ischeme template.i.molds
6433+ ?: &(?=(~ vars.template) ?=(%jrec -.typ.template) =(at.typ.template origin) =(name.typ.template name)) `name.i.molds
6434+ $(molds t.molds)
6435+::
6436+++ grec-visible-alias
6437+ |= [origin=path name=term proof=shape args=(list itype) molds=imold-types]
6438+ ^- (unit term)
6439+ ?~ molds ~
6440+ =/ template=ischeme template.i.molds
6441+ ?. ?=(%grec -.typ.template) $(molds t.molds)
6442+ ?. &(=(at.typ.template origin) =(name.typ.template name) =(proof.typ.template proof)) $(molds t.molds)
6443+ ?. &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args))) $(molds t.molds)
6444+ `name.i.molds
57376445::
57386446++ itype-in-import
5739− |= [t=itype iface=ifile face=term]
6447+ |= [t=itype iface=ifile face=term prelude=(unit ifile)]
57406448 ^- itype
57416449 ?- -.t
57426450 %union
57436451 =/ label=(unit @t)
57446452 ?~ origin.t ~
57456453 ?: =(at.u.origin.t /lib/jibb/prelude/jibb) `name.u.origin.t
6454+ =/ public=(unit term)
6455+ ?~ prelude ~
6456+ (prelude-union-alias u.origin.t args.t molds.u.prelude)
6457+ ?^ public `u.public
57466458 =/ alias=(unit term) ~
57476459 =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
57486460 =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
57496461 ?~ alias ~
57506462 `(crip "{(trip u.alias)}.{(trip face)}")
5751− [%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)))]
6463+ [%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)))]
57526464 %recursive [%recursive module.t name.t ~]
5753− %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face)))]
6465+ %grec
6466+ =/ public=(unit term) ?~(prelude ~ (grec-visible-alias at.t name.t proof.t args.t molds.u.prelude))
6467+ =/ alias=(unit term) ?~(public (grec-visible-alias at.t name.t proof.t args.t molds.iface) public)
6468+ =/ label=(unit @t) ?~(alias ~ ?~(public `(crip "{(trip u.alias)}.{(trip face)}") `u.alias))
6469+ t(label label, args (turn args.t |=(c=itype (itype-in-import c iface face prelude))))
6470+ %jrec
6471+ =/ public=(unit term) ?~(prelude ~ (jrec-alias at.t name.t molds.u.prelude))
6472+ ?^ public t(label `u.public)
6473+ =/ alias=(unit term) (jrec-alias at.t name.t molds.iface)
6474+ ?~ alias t(label ~)
6475+ t(label `(crip "{(trip u.alias)}.{(trip face)}"))
6476+ %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
57546477 %face [%face name.t $(t body.t)]
57556478 %fn [%fn $(t sample.t) $(t product.t)]
57566479 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5823,9 +6546,66 @@
58236546 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
58246547 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
58256548::
6549+:: Recognize a unique top-level source mold with exactly a null case and a
6550+:: faced atom-headed cell whose faced tail names that same mold. Its Jibb
6551+:: path and name provide nominal identity. Other recursive shapes fail closed;
6552+:: construction and matching expose the proven shape one layer at a time.
6553+++ simple-source-recursive
6554+ |= [name=term sh=shape state=istate]
6555+ ^- (unit itype)
6556+ ?. (lien top-molds.state |=(n=term =(n name))) ~
6557+ =/ original=(unit shape) (find-simple-mold name molds.state)
6558+ ?~ original ~
6559+ ?. =(u.original sh) ~
6560+ ?. ?=(%union -.sh) ~
6561+ =/ cs=(list shape) cases.sh
6562+ ?~ cs ~
6563+ ?~ t.cs ~
6564+ ?^ t.t.cs ~
6565+ ?. ?=(%const -.i.cs) ~
6566+ ?. =(%null form.lit.i.cs) ~
6567+ ?. ?=(%cell -.i.t.cs) ~
6568+ =/ fs=(list field) fields.i.t.cs
6569+ ?~ fs ~
6570+ ?~ t.fs ~
6571+ ?^ t.t.fs ~
6572+ ?. ?=(%face -.i.fs) ~
6573+ ?. ?=(%aura -.shape.i.fs) ~
6574+ ?. !=(0 aura.shape.i.fs) ~
6575+ ?. ?=(%face -.i.t.fs) ~
6576+ ?. !=(name.i.fs name.i.t.fs) ~
6577+ =/ tail=shape shape.i.t.fs
6578+ ?. ?=(%ref -.tail) ~
6579+ ?. =(names.tail ~[name]) ~
6580+ `[%jrec at.state name `name name.i.fs aura.shape.i.fs name.i.t.fs]
6581+::
6582+++ simple-source-generic-recursive
6583+ |= [name=term sh=shape args=(list itype) state=istate]
6584+ ^- (unit itype)
6585+ ?. ?=(%generic -.sh) ~
6586+ ?. ?=([@ ~] vars.sh) ~
6587+ ?. ?=([* ~] args) ~
6588+ ?~ grec-index.state ~
6589+ ?. =(at.u.grec-index.state at.state) ~
6590+ ?~ prelude.state ~
6591+ ?. =(prelude.u.grec-index.state u.prelude.state) ~
6592+ =/ proof=(unit shape) (~(get by shapes.u.grec-index.state) name)
6593+ ?~ proof ~
6594+ ?. =(u.proof sh) ~
6595+ `[%grec at.state name `name sh args]
6596+::
6597+
58266598++ infer-mold-template
58276599 |= [sh=shape state=istate]
58286600 ^- (unit [template=ischeme state=istate])
6601+ =/ generic=(unit itype)
6602+ ?. ?=([@ ~] active.state) ~
6603+ (simple-source-generic-recursive i.active.state sh ~[[%var next.state]] state)
6604+ ?^ generic `[[u.generic ~[next.state]] state(next +(next.state))]
6605+ =/ direct=(unit itype)
6606+ ?. ?=([@ ~] active.state) ~
6607+ (simple-source-recursive i.active.state sh state)
6608+ ?^ direct `[[u.direct ~] state]
58296609 ?: ?=(%generic -.sh)
58306610 ?~ vars.sh ~
58316611 ?. (distinct-params vars.sh) ~
@@ -5833,17 +6613,19 @@
58336613 =/ out=(unit [typ=itype state=istate])
58346614 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
58356615 ?~ out ~
6616+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58366617 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
58376618 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
58386619 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
58396620 =/ used=(list @ud) (itype-vars typ.u.out)
58406621 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
5841− `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state)]
6622+ `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
58426623 =/ out=(unit [typ=itype state=istate])
58436624 (infer-simple-shape sh state(params ~, in-mold &))
58446625 ?~ out ~
6626+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
58456627 ?: ?=(^ (itype-vars typ.u.out)) ~
5846− `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state)]
6628+ `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
58476629::
58486630:: A direct imported reference may carry definite reader evidence. Only
58496631:: uniquely supplied, declared inputs are used; unsupported data stay generic.
@@ -5877,7 +6659,7 @@
58776659 ?~ found ~
58786660 ?^ t.found ~
58796661 result.i.found
5880− ?. ?=([%invalid ?(%aura %core) @] raw) ~
6662+ ?. ?=([%invalid ?(%aura %core %overlap) @] raw) ~
58816663 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
58826664::
58836665:: Replay only the shape branches whose evaluation order we can prove.
@@ -5946,12 +6728,15 @@
59466728 |= [sh=shape state=istate]
59476729 ^- (unit [typ=itype state=istate])
59486730 ?- -.sh
6731+ %hole `[[%var next.state] state(next +(next.state), holes [[next.state at.sh] holes.state])]
59496732 %aura
59506733 ?: =(0 aura.sh) `[[%any-atom ~] state]
59516734 `[[%atom aura.sh] state]
59526735 %flag `[[%flag ~] state]
6736+ %noun `[[%noun ~] state]
59536737 %const
5954− ?. |(=(%term form.lit.sh) =(%null form.lit.sh)) ~
6738+ ?. |(=(%term form.lit.sh) =(%null form.lit.sh) =(%loobean form.lit.sh)) ~
6739+ ?: &(=(%loobean form.lit.sh) !|(=(0 val.lit.sh) =(1 val.lit.sh))) ~
59556740 `[[%const lit.sh] state]
59566741 %union
59576742 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
@@ -5976,7 +6761,7 @@
59766761 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
59776762 ?~ found ~
59786763 ?^ vars.u.found ~
5979− `[(itype-in-import typ.u.found u.iface i.t.names.sh) state]
6764+ `[(itype-in-import typ.u.found u.iface i.t.names.sh prelude.state) state]
59806765 =/ found=(unit itype)
59816766 (find-imported-mold i.t.names.sh n externals.state surs.state)
59826767 ?~ found ~
@@ -5995,10 +6780,13 @@
59956780 ?~ prelude-entry ~
59966781 ?^ vars.u.prelude-entry ~
59976782 `[typ.u.prelude-entry state]
6783+ =/ direct=(unit itype) (simple-source-recursive n u.found state)
6784+ ?^ direct `[u.direct state]
59986785 =/ out=(unit [typ=itype state=istate])
59996786 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
60006787 ?~ out ~
6001− `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state)]
6788+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
6789+ `[(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)]
60026790 %apply
60036791 ?~ ref.sh ~
60046792 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
@@ -6013,7 +6801,7 @@
60136801 ?~ vars.u.template ~
60146802 =/ applied=(unit itype) (template-apply u.template types.u.args)
60156803 ?~ applied ~
6016− `[(itype-in-import u.applied u.iface i.t.ref.sh) state.u.args]
6804+ `[(itype-in-import u.applied u.iface i.t.ref.sh prelude.state.u.args) state.u.args]
60176805 ?: (lien active.state.u.args |=(x=term =(x n))) ~
60186806 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
60196807 ?~ found
@@ -6026,17 +6814,20 @@
60266814 ?~ applied ~
60276815 `[u.applied state.u.args]
60286816 ?. ?=(%generic -.u.found) ~
6817+ =/ grec=(unit itype) (simple-source-generic-recursive n u.found types.u.args state.u.args)
6818+ ?^ grec `[u.grec state.u.args]
60296819 ?. (distinct-params vars.u.found) ~
60306820 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
60316821 ?~ params ~
60326822 =/ out=(unit [typ=itype state=istate])
60336823 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
60346824 ?~ out ~
6825+ ?^ (unresolved-hole holes.state.u.out holes.state.u.args state.u.out) ~
60356826 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
60366827 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
60376828 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
60386829 (label-direct-union typ.u.out(args types.u.args) u.found n state.u.args)
6039− `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args)]
6830+ `[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)]
60406831 %tvar
60416832 =/ param=(unit itype) (iparam-lookup name.sh params.state)
60426833 ?^ param `[u.param state]
@@ -6076,12 +6867,12 @@
60766867 ^- isample-result
60776868 ?- -.s
60786869 %bind
6079− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6870+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
60806871 [%| "sample shadows a name"]
60816872 =/ t=itype [%var next.state]
60826873 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
60836874 %face
6084− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6875+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
60856876 [%| "sample shadows a name"]
60866877 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
60876878 ?~ t [%| "sample mold is not supported by partial inference"]
@@ -6119,8 +6910,8 @@
61196910 [%& [%cell ht typ.p.tail] env.p.tail state.p.tail]
61206911::
61216912:: Local definitions generalize only variables outside their enclosing
6122−:: environment and explicit-capital scope. Single self-recursive gates
6123−:: use a monomorphic placeholder; mutually recursive groups stay unsupported.
6913+:: environment and explicit-capital scope. Recursive gate groups use
6914+:: monomorphic placeholders while their bodies are checked.
61246915::
61256916+$ ilocal-result (each [env=ienv state=istate] idiag)
61266917++ free-env-vars
@@ -6149,6 +6940,7 @@
61496940 |-
61506941 ?~ ds &
61516942 ?: ?=(%mold -.i.ds) $(ds t.ds)
6943+ ?: =(name.i.ds %proj) |
61526944 ?. (unique-value-name name.i.ds names) |
61536945 ?: ?=(^ (ienv-lookup name.i.ds env)) |
61546946 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
@@ -6172,6 +6964,7 @@
61726964 |-
61736965 ?~ locals &
61746966 =/ n=term name.i.locals
6967+ ?: =(n %proj) |
61756968 ?. (unique-value-name n names) |
61766969 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
61776970 ?: (lien marks.state |=(m=term =(n m))) |
@@ -6336,7 +7129,13 @@
63367129 |-
63377130 ?~ ds
63387131 ?~ remaining [%& env state]
6339− ?. progressed [%| ["local definitions need unsupported inference" ~]]
7132+ ?. progressed
7133+ =/ pending=(list def) (flop remaining)
7134+ =/ groups=icomponents (graph-components pending (global-value-names pending))
7135+ =/ grouped=(unit [rest=(list def) env=ienv state=istate])
7136+ (try-local-group pending groups env state)
7137+ ?~ grouped [%| ["local definitions need unsupported inference" ~]]
7138+ $(ds rest.u.grouped, remaining ~, env env.u.grouped, state state.u.grouped, progressed |)
63407139 $(ds (flop remaining), remaining ~, progressed |)
63417140 =/ d=def i.ds
63427141 ?> ?=(%value -.d)
@@ -6345,6 +7144,10 @@
63457144 =/ retried=? ?=(%| -.inferred)
63467145 =? inferred retried (infer-recursive-gate d env local-state)
63477146 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
7147+ =. state.p.inferred (promote-restricted-numbers state.p.inferred env)
7148+ =. 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)))
7149+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.inferred holes.state state.p.inferred)
7150+ ?^ hole [%| u.hole]
63487151 =/ merged=(unit [first=icap second=icap])
63497152 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
63507153 ?^ merged
@@ -6360,7 +7163,28 @@
63607163 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
63617164 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
63627165 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
6363− $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state), progressed &)
7166+ $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state, holes holes.state), progressed &)
7167+::
7168+:: Try complete cyclic local groups after individual definitions stall.
7169+:: Components with non-gates or unresolved constraints stay unavailable.
7170+::
7171+++ try-local-group
7172+ |= [ds=(list def) groups=icomponents env=ienv state=istate]
7173+ ^- (unit [rest=(list def) env=ienv state=istate])
7174+ ?~ groups ~
7175+ =/ names=(list term) i.groups
7176+ ?. (gth (lent names) 1) $(groups t.groups)
7177+ =/ members=(list def)
7178+ (skim ds |=(d=def &(?=(%value -.d) (lien names |=(n=term =(n name.d))))))
7179+ ?. =((lent members) (lent names)) $(groups t.groups)
7180+ =/ result=ilocal-result (infer-gate-group members env state)
7181+ ?: ?=(%| -.result) $(groups t.groups)
7182+ =/ rest=(list def)
7183+ (skim ds |=(d=def !(lien names |=(n=term =(n name.d)))))
7184+ =/ more=(unit [rest=(list def) env=ienv state=istate])
7185+ $(ds rest, groups t.groups, env env.p.result, state state.p.result)
7186+ ?^ more more
7187+ `[rest env.p.result state.p.result]
63647188::
63657189:: Read only fields of a known record. Unresolved field constraints and
63667190:: ambiguous repeated faces are outside this fragment. Imported record
@@ -6383,17 +7207,29 @@
63837207 ^- iresult
63847208 =/ reverse=(list term) (flop names)
63857209 ?~ reverse [%| ["empty wing" ~]]
6386− =/ scheme=(unit ischeme) (ienv-lookup i.reverse env)
6387− ?~ scheme [%| ["field access is not supported by partial inference" ~]]
6388− =/ inst=[typ=itype state=istate] (instantiate-scheme u.scheme state)
7210+ =/ iface=(unit ifile) (find-jibb-interface i.reverse jimports.state)
63897211 =/ fields=(list term) t.reverse
7212+ ?~ fields [%| ["field access is not supported by partial inference" ~]]
7213+ =/ scheme=(unit ischeme)
7214+ ?~ iface
7215+ (ienv-lookup i.reverse env)
7216+ (ienv-lookup i.fields values.u.iface)
7217+ ?~ scheme
7218+ ?^ iface [%| ["module member is not available to partial inference" ~]]
7219+ [%| ["field access is not supported by partial inference" ~]]
7220+ =/ inst=[typ=itype state=istate]
7221+ ?~ iface (instantiate-scheme u.scheme state)
7222+ =/ imported=ischeme u.scheme
7223+ =. typ.imported (itype-in-import typ.imported u.iface i.reverse prelude.state)
7224+ (instantiate-scheme imported state)
7225+ =/ remaining=(list term) ?~(iface fields t.fields)
63907226 =/ typ=itype typ.inst
63917227 |-
6392− ?~ fields [%& typ state.inst]
6393− =/ found=(list itype) (record-fields-named i.fields typ sub.state.inst)
7228+ ?~ remaining [%& typ state.inst]
7229+ =/ found=(list itype) (record-fields-named i.remaining typ sub.state.inst)
63947230 ?~ found [%| ["field is not available to partial inference" ~]]
63957231 ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
6396− $(fields t.fields, typ i.found)
7232+ $(remaining t.remaining, typ i.found)
63977233::
63987234:: Propagate a known union or list through supported loobean, unit and list
63997235:: branches. Empty bodies and groups are transparent; bodies with definitions
@@ -6448,10 +7284,17 @@
64487284 ?: ?=(%unknown -.fit)
64497285 ?: &(?=(%collection -.expected) =(%list name.expected))
64507286 [%| ["branch list constraint is not supported by partial inference" ~]]
7287+ ?: ?=(%flag -.expected) [%| ["branch loobean constraint is not supported by partial inference" ~]]
64517288 [%| ["branch union constraint is not supported by partial inference" ~]]
64527289 ?: ?=(%bad -.fit)
7290+ =/ missing=(unit idiag) (missing-union-tag e expected sub.state.p.value context)
7291+ ?^ missing [%| u.missing]
7292+ =/ nested=(unit idiag) (nested-missing-tag e typ.p.value expected sub.state.p.value next.state.p.value context)
7293+ ?^ nested [%| u.nested]
64537294 ?: &(?=(%collection -.expected) =(%list name.expected))
64547295 [%| ["branch arm does not fit its expected list" ~[[context "expected list"] [(span-of e) "branch arm"]]]]
7296+ ?: ?=(%flag -.expected)
7297+ [%| ["branch arm does not fit its expected loobean" ~[[context "expected loobean"] [(span-of e) "branch arm"]]]]
64557298 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
64567299 [%& expected state.p.value(sub sub.fit, next next.fit)]
64577300::
@@ -6516,23 +7359,37 @@
65167359 [%| ["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)]]]]
65177360 [%& target state.p.tail(sub sub.fit, next next.fit)]
65187361::
7362+++ infer-open-list-items
7363+ |= [items=(list expr) expected=itype env=ienv state=istate context=span]
7364+ ^- iresult
7365+ ?~ items [%& expected state]
7366+ =/ target=itype (itype-walk expected sub.state)
7367+ =/ value=iresult (infer-call-context-arg i.items target env state context)
7368+ ?: ?=(%| -.value) value
7369+ =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7370+ ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
7371+ ?: ?=(%bad -.fit)
7372+ ?: |((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))
7373+ [%| ["list item widening is not supported by partial inference" ~]]
7374+ [%| ["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)]]]]
7375+ ?: (itype-has-tag (itype-normalize expected sub.fit))
7376+ [%| ["list item needs context in partial inference" ~]]
7377+ $(items t.items, state state.p.value(sub sub.fit, next next.fit))
7378+::
65197379++ infer-list-items
65207380 |= [items=(list expr) expected=itype env=ienv state=istate context=span]
65217381 ^- iresult
65227382 ?~ items [%& expected state]
65237383 =/ target=itype (itype-walk expected sub.state)
6524− =/ value=iresult
6525− ?: &(?=(%union -.target) (context-union-branch i.items))
6526− (infer-union-context i.items target env state context)
6527− ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch i.items))
6528− (infer-union-context i.items target env state context)
6529− ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression i.items))
6530− (infer-list-context i.items target env state context)
6531− (infer-fragment i.items env state)
7384+ =/ value=iresult (infer-call-context-arg i.items target env state context)
65327385 ?: ?=(%| -.value) value
65337386 =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
65347387 ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
65357388 ?: ?=(%bad -.fit)
7389+ =/ missing=(unit idiag) (missing-union-tag i.items target sub.state.p.value context)
7390+ ?^ missing [%| u.missing]
7391+ =/ nested=(unit idiag) (nested-missing-tag i.items typ.p.value target sub.state.p.value next.state.p.value context)
7392+ ?^ nested [%| u.nested]
65367393 [%| ["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)]]]]
65377394 $(items t.items, state state.p.value(sub sub.fit, next next.fit))
65387395::
@@ -6625,7 +7482,7 @@
66257482 [%| ["list branch pattern is not supported by partial inference" ~]]
66267483 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
66277484 ?~ binder [%| ["list branch pattern is not supported by partial inference" ~]]
6628− ?: |(=(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)))))
7485+ ?: |(=(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)))))
66297486 [%| ["pattern binder shadows a name" ~]]
66307487 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
66317488 =/ left=iresult
@@ -6662,7 +7519,7 @@
66627519 [%| ["unit branch pattern is not supported by partial inference" ~]]
66637520 =/ binder=(unit term) ?:(first-empty second-name first-name)
66647521 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
6665− ?: |(?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
7522+ ?: |(=(u.binder %proj) ?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
66667523 [%| ["pattern binder shadows a name" ~]]
66677524 =/ payload=(unit itype) (unit-union-payload typ)
66687525 ?~ payload [%| ["unit branch subject is not supported by partial inference" ~]]
@@ -6694,12 +7551,14 @@
66947551 =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
66957552 ?: |(?=(%atom -.t) ?=(%any-atom -.t))
66967553 $(ps t.ps, state state.p.item)
6697− ?: &(?=(%nvar -.t) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
7554+ ?: &(|(?=(%nvar -.t) ?=(%rnvar -.t)) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
66987555 $(ps t.ps, state state.p.item)
66997556 ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
67007557 $(ps t.ps, state state.p.item)
67017558 ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
67027559 [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7560+ ?: &(?=(%rvar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7561+ [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
67037562 ?: ?=(%cell -.t)
67047563 [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
67057564 [%| ["interpolation type needs unsupported inference" ~]]
@@ -6762,7 +7621,7 @@
67627621 ^- (unit ienv)
67637622 =. t ?:(?=(%face -.t) body.t t)
67647623 ?: ?=(%bind -.p)
6765− ?: |(?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
7624+ ?: |(=(name.p %proj) ?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
67667625 `[[name.p [t ~]] env]
67677626 ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
67687627 `env
@@ -6810,10 +7669,9 @@
68107669 $(xs t.xs, out (weld out rows), origin +(origin))
68117670::
68127671++ infer-known-union-whole
6813− |= [e=expr env=ienv state=istate]
7672+ |= [e=expr env=ienv subject=iresult]
68147673 ^- (unit iresult)
68157674 ?> ?=(%branch -.e)
6816− =/ subject=iresult (infer-fragment subject.e env state)
68177675 ?: ?=(%| -.subject) `subject
68187676 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
68197677 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
@@ -6847,11 +7705,54 @@
68477705 ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
68487706 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
68497707::
7708+++ infer-known-union-context-whole
7709+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
7710+ ^- (unit iresult)
7711+ ?> ?=(%branch -.e)
7712+ ?: ?=(%| -.subject) `subject
7713+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7714+ ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
7715+ =/ cases=(list itype) cases.typ
7716+ =/ remaining=(list itype) cases
7717+ =/ arms=(list arm) arms.e
7718+ =/ st=istate state.p.subject
7719+ =/ answer=(unit itype) ~
7720+ |-
7721+ ?~ arms
7722+ ?^ remaining
7723+ `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
7724+ ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
7725+ `[%& expected st]
7726+ =/ a=arm i.arms
7727+ ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
7728+ ~
7729+ =/ matching=(list itype) (skim remaining |=(c=itype =(%full (union-pattern pat.a c))))
7730+ ?~ matching
7731+ ?: (lien cases |=(c=itype =(%full (union-pattern pat.a c))))
7732+ `[%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
7733+ `[%| ["union pattern is not supported by partial inference" ~]]
7734+ ?: &(?=(^ t.matching) (union-pattern-has-bind pat.a))
7735+ `[%| ["a union pattern binding several cases is not supported by partial inference" ~]]
7736+ =/ bound=(unit ienv) (union-pattern-bind pat.a i.matching env globals.st)
7737+ ?~ bound `[%| ["pattern binder shadows a name" ~]]
7738+ =/ body=iresult (infer-call-context-arg val.a expected u.bound st context)
7739+ ?: ?=(%| -.body) `body
7740+ =/ fit=ifit (itype-fit typ.p.body expected sub.state.p.body next.state.p.body)
7741+ ?: ?=(%unknown -.fit) `[%| ["union branch result constraint is not supported by partial inference" ~]]
7742+ ?: ?=(%bad -.fit)
7743+ =/ missing=(unit idiag) (missing-union-tag val.a expected sub.state.p.body context)
7744+ ?^ missing `[%| u.missing]
7745+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body expected sub.state.p.body next.state.p.body context)
7746+ ?^ nested `[%| u.nested]
7747+ `[%| ["union branch arm does not fit its expected type" ~[[context "expected type"] [(span-of val.a) "branch arm"]]]]
7748+ ?: (itype-has-tag (itype-normalize expected sub.fit))
7749+ `[%| ["union branch result needs context in partial inference" ~]]
7750+ $(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)
7751+::
68507752++ infer-known-union-finite
6851− |= [e=expr env=ienv state=istate]
7753+ |= [e=expr env=ienv subject=iresult expected=(unit [typ=itype context=span])]
68527754 ^- iresult
68537755 ?> ?=(%branch -.e)
6854− =/ subject=iresult (infer-fragment subject.e env state)
68557756 ?: ?=(%| -.subject) subject
68567757 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
68577758 ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
@@ -6867,7 +7768,8 @@
68677768 ?^ remaining
68687769 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
68697770 ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
6870− [%& u.answer st]
7771+ ?~ expected [%& u.answer st]
7772+ [%& typ.u.expected st]
68717773 =/ a=arm i.arms
68727774 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
68737775 [%| ["partial union pattern is not supported by partial inference" ~]]
@@ -6880,38 +7782,387 @@
68807782 [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
68817783 =/ bound=(unit ienv) (union-pattern-bind pat.a base.i.matching env globals.st)
68827784 ?~ bound [%| ["pattern binder shadows a name" ~]]
6883− =/ body=iresult (infer-fragment val.a u.bound st)
7785+ =/ body=iresult
7786+ ?~ expected (infer-fragment val.a u.bound st)
7787+ (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
68847788 ?: ?=(%| -.body) body
7789+ ?^ expected
7790+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7791+ ?: ?=(%unknown -.fit) [%| ["union branch result constraint is not supported by partial inference" ~]]
7792+ ?: ?=(%bad -.fit)
7793+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7794+ ?^ missing [%| u.missing]
7795+ =/ 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)
7796+ ?^ nested [%| u.nested]
7797+ [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7798+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7799+ [%| ["union branch result needs context in partial inference" ~]]
7800+ $(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)
68857801 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
68867802 =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
68877803 ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
68887804 $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
68897805::
7806+:: Prove a one-arm record pattern covers a known, non-union subject.
7807+:: Variable or partial matches stay unsupported; binding uses the same
7808+:: scope and original payload types as the existing union matcher.
7809+++ single-structured-pattern
7810+ |= e=expr
7811+ ^- ?
7812+ ?. ?=(%branch -.e) |
7813+ ?~ arms.e |
7814+ ?^ t.arms.e |
7815+ =/ p=pattern pat.i.arms.e
7816+ ?. ?=(%cell -.p) |
7817+ !(levy items.p |=(x=pattern ?=(%bind -.x)))
7818+::
7819+++ infer-single-case-branch
7820+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
7821+ ^- iresult
7822+ ?> (single-structured-pattern e)
7823+ ?> ?=(%branch -.e)
7824+ ?> ?=(^ arms.e)
7825+ =/ a=arm i.arms.e
7826+ =/ subject=iresult (infer-fragment subject.e env state)
7827+ ?: ?=(%| -.subject) subject
7828+ =/ st=istate state.p.subject
7829+ =/ typ=itype (itype-normalize typ.p.subject sub.st)
7830+ ?: ?=(%union -.typ) [%| ["single-case pattern needs unsupported inference" ~]]
7831+ ?. =(%full (union-pattern pat.a typ))
7832+ [%| ["single-case pattern needs unsupported inference" ~]]
7833+ =/ bound=(unit ienv) (union-pattern-bind pat.a typ env globals.st)
7834+ ?~ bound [%| ["pattern binder shadows a name" ~]]
7835+ ?~ expected (infer-fragment val.a u.bound st)
7836+ =/ body=iresult (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
7837+ ?: ?=(%| -.body) body
7838+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7839+ ?: ?=(%unknown -.fit) [%| ["single-case branch result constraint is not supported by partial inference" ~]]
7840+ ?: ?=(%bad -.fit)
7841+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7842+ ?^ missing [%| u.missing]
7843+ =/ 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)
7844+ ?^ nested [%| u.nested]
7845+ [%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7846+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7847+ [%| ["single-case branch result needs context in partial inference" ~]]
7848+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
7849+::
7850+:: This view is used only by pattern analysis, never exported or bound as
7851+:: the subject. Only null plus a two-binder/wildcard cell is supported; its
7852+:: tail keeps the original recursive type. Other patterns fail closed.
7853+++ jrec-match-view
7854+ |= [e=expr subject=iresult]
7855+ ^- iresult
7856+ ?: ?=(%| -.subject) subject
7857+ ?. ?=(%branch -.e) subject
7858+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7859+ ?. ?=(%jrec -.typ) subject
7860+ ?~ arms.e subject
7861+ ?~ t.arms.e subject
7862+ ?^ t.t.arms.e subject
7863+ =/ x=pattern pat.i.arms.e
7864+ =/ y=pattern pat.i.t.arms.e
7865+ =/ empty=? &(?=(%lit -.x) =(%null form.lit.x))
7866+ =/ full=pattern ?:(empty y x)
7867+ ?. |(empty &(?=(%lit -.y) =(%null form.lit.y))) subject
7868+ ?. ?=(%cell -.full) subject
7869+ ?~ items.full subject
7870+ ?~ t.items.full subject
7871+ ?^ t.t.items.full subject
7872+ ?. |(?=(%bind -.i.items.full) ?=(%any -.i.items.full)) subject
7873+ ?. |(?=(%bind -.i.t.items.full) ?=(%any -.i.t.items.full)) subject
7874+ ?: =(0 jrec-fuel.state.p.subject)
7875+ [%| ["recursive mold unfolding needs unsupported inference" ~]]
7876+ =/ nil=itype [%const [%null %n 0 '~']]
7877+ =/ cell=itype [%cell [%face head.typ [%atom aura.typ]] [%face tail.typ typ]]
7878+ [%& [%union ~[nil cell] ~ ~ ~] state.p.subject(jrec-fuel (dec jrec-fuel.state.p.subject))]
7879+::
7880+:: Experimental bounded, source-proven tree match. Only two explicit
7881+:: flat tag/binder patterns may consume the view: a whole-case binder
7882+:: must not leak the temporary structural representation.
7883+++ grec-simple-pattern
7884+ |= [pat=pattern view=itype]
7885+ ^- ?
7886+ ?. ?=(%cell -.pat) |
7887+ ?~ items.pat |
7888+ =/ first=pattern i.items.pat
7889+ ?. ?=(%lit -.first) |
7890+ ?. =(%term form.lit.first) |
7891+ =/ chosen=(unit itype) (contextual-tagged-case view val.lit.first ~)
7892+ ?~ chosen |
7893+ ?> ?=(%cell -.u.chosen)
7894+ =/ rest=(list pattern) t.items.pat
7895+ ?. (levy rest |=(p=pattern |(?=(%bind -.p) ?=(%any -.p)))) |
7896+ ?: ?=(%cell -.tal.u.chosen) ?=([* [* ~]] rest)
7897+ ?=([* ~] rest)
7898+++ grec-match-view
7899+ |= [e=expr subject=iresult]
7900+ ^- iresult
7901+ ?: ?=(%| -.subject) subject
7902+ ?. ?=(%branch -.e) subject
7903+ ?. (grec-direct-context typ.p.subject sub.state.p.subject) subject
7904+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7905+ ?. ?=(%grec -.typ) subject
7906+ ?~ arms.e subject
7907+ ?. |(?=(~ t.arms.e) ?=([* ~] t.arms.e)) subject
7908+ =/ view=(unit [view=itype left=@ud]) (grec-unfold-view typ jrec-fuel.state.p.subject)
7909+ ?~ view [%| ["recursive mold unfolding needs unsupported inference" ~]]
7910+ ?. (grec-simple-pattern pat.i.arms.e view.u.view) subject
7911+ =/ rest-ok=? ?~(t.arms.e & (grec-simple-pattern pat.i.t.arms.e view.u.view))
7912+ ?. rest-ok subject
7913+ [%& view.u.view state.p.subject(jrec-fuel left.u.view)]
7914+::
7915+:: A single-arm diagnostic only probes a direct, source-typed in-scope wing;
7916+:: other subjects retain the prior single-pattern inference path.
7917+++ grec-single-wing-subject
7918+ |= [e=expr env=ienv state=istate]
7919+ ^- (unit iresult)
7920+ ?. ?=(%wing -.e) ~
7921+ ?. ?=([@ ~] names.e) ~
7922+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
7923+ ?~ scheme ~
7924+ ?. (grec-direct-context typ.u.scheme sub.state) ~
7925+ `(infer-fragment e env state)
7926+::
7927+++ infer-known-union-branch-subject
7928+ |= [e=expr env=ienv subject=iresult]
7929+ ^- iresult
7930+ =. subject (grec-match-view e subject)
7931+ =. subject (jrec-match-view e subject)
7932+ =/ whole=(unit iresult) (infer-known-union-whole e env subject)
7933+ ?~ whole (infer-known-union-finite e env subject ~)
7934+ u.whole
7935+::
68907936++ infer-known-union-branch
68917937 |= [e=expr env=ienv state=istate]
68927938 ^- iresult
6893− =/ whole=(unit iresult) (infer-known-union-whole e env state)
6894− ?~ whole (infer-known-union-finite e env state)
7939+ ?> ?=(%branch -.e)
7940+ (infer-known-union-branch-subject e env (infer-fragment subject.e env state))
7941+::
7942+++ infer-known-union-context-subject
7943+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
7944+ ^- iresult
7945+ =. subject (grec-match-view e subject)
7946+ =. subject (jrec-match-view e subject)
7947+ =/ whole=(unit iresult) (infer-known-union-context-whole e expected env subject context)
7948+ ?~ whole (infer-known-union-finite e env subject `[expected context])
68957949 u.whole
68967950::
7951+:: Limit speculative subject inference to wings and shallow calls;
7952+:: grouping is peeled linearly and cannot introduce a nested branch.
7953+++ simple-union-subject-arg
7954+ |= e=expr
7955+ ^- ?
7956+ ?- -.e
7957+ %wing &
7958+ %lit &
7959+ %str !(lien pieces.e |=(p=piece ?=(%expr -.p)))
7960+ * |
7961+ ==
7962+::
7963+++ safe-union-subject
7964+ |= e=expr
7965+ ^- ?
7966+ ?: ?=(%group -.e) $(e inner.e)
7967+ ?: ?=(%wing -.e) &
7968+ ?. ?=(%call -.e) |
7969+ ?. ?=(%wing -.head.e) |
7970+ (levy args.e simple-union-subject-arg)
7971+::
7972+++ duplicate-loobean-arms
7973+ |= e=expr
7974+ ^- ?
7975+ ?. ?=(%branch -.e) |
7976+ ?~ arms.e |
7977+ ?~ t.arms.e |
7978+ ?^ t.t.arms.e |
7979+ =/ x=pattern pat.i.arms.e
7980+ =/ y=pattern pat.i.t.arms.e
7981+ ?. &(?=(%lit -.x) ?=(%lit -.y)) |
7982+ ?. &(=(%loobean form.lit.x) =(%loobean form.lit.y)) |
7983+ =(val.lit.x val.lit.y)
7984+::
7985+++ union-subject-call
7986+ |= e=expr
7987+ ^- ?
7988+ ?: ?=(%group -.e) $(e inner.e)
7989+ ?=(%call -.e)
7990+::
68977991++ known-union-subject
68987992 |= [e=expr env=ienv state=istate]
6899− ^- (unit itype)
6900− ?. ?=(%wing -.e) ~
7993+ ^- (unit iresult)
7994+ ?. (safe-union-subject e) ~
69017995 =/ subject=iresult (infer-fragment e env state)
6902− ?: ?=(%| -.subject) ~
7996+ ?: ?=(%| -.subject) ?:((union-subject-call e) `subject ~)
69037997 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
6904− ?. ?=(%union -.typ) ~
6905− `typ
7998+ ?. |(?=(%union -.typ) ?=(%jrec -.typ) &(?=(%grec -.typ) (grec-direct-context typ.p.subject sub.state.p.subject))) ~
7999+ `subject
69068000::
6907−++ infer-fragment
6908− |= [e=expr env=ienv state=istate]
8001+::
8002+:: Infer changes only against a fully known record spine. Retain the
8003+:: target type; unknown spines and repeated edits remain unsupported.
8004+++ change-spine-known
8005+ |= [t=itype sub=isub]
8006+ ^- ?
8007+ =. t (itype-walk t sub)
8008+ ?: ?=(%face -.t) &
8009+ ?. ?=(%cell -.t) |
8010+ =/ first=itype (itype-walk hed.t sub)
8011+ ?. ?=(%face -.first) |
8012+ $(t tal.t)
8013+::
8014+++ infer-change-edits
8015+ |= [edits=(list edit) target=itype env=ienv state=istate seen=(list term)]
69098016 ^- iresult
6910− ?- -.e
6911− %lit
6912− ?- form.lit.e
6913− %number ?: =(%ud aura.lit.e)
6914− [%& [%nvar next.state] state(next +(next.state))]
8017+ ?~ edits [%& target state]
8018+ =/ entry=edit i.edits
8019+ ?: (lien seen |=(name=term =(name name.entry)))
8020+ [%| ["repeated change fields are not supported by partial inference" ~]]
8021+ ?. (change-spine-known target sub.state)
8022+ [%| ["change target needs a known record in partial inference" ~]]
8023+ =/ found=(list itype) (record-fields-named name.entry target sub.state)
8024+ ?~ found
8025+ [%| ["record has no field `{(trip name.entry)}`" ~[[at.entry "unknown field"]]]]
8026+ ?^ t.found [%| ["change field is ambiguous in partial inference" ~]]
8027+ =/ expected=itype i.found
8028+ =/ value=iresult (infer-call-context-arg val.entry expected env state at.entry)
8029+ ?: ?=(%| -.value) value
8030+ =/ fit=ifit (itype-fit typ.p.value expected sub.state.p.value next.state.p.value)
8031+ ?: ?=(%unknown -.fit) [%| ["change field constraint is not supported by partial inference" ~]]
8032+ ?: ?=(%bad -.fit)
8033+ [%| ["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)]]]]
8034+ $(edits t.edits, state state.p.value(sub sub.fit, next next.fit), seen [name.entry seen])
8035+::
8036+:: Backtick constructs the canonical prelude unit, after checking its
8037+:: prepared template has the standard null and [~ u=A] cases.
8038+++ standard-unit-template
8039+ |= [template=ischeme at=path]
8040+ ^- ?
8041+ ?. =(at /lib/jibb/prelude/jibb) |
8042+ ?~ vars.template |
8043+ ?^ t.vars.template |
8044+ =/ v=@ud i.vars.template
8045+ =/ nil=itype [%const [%null %n 0 '~']]
8046+ =/ expected=itype
8047+ [%union ~[nil [%cell nil [%face %u [%var v]]]] `[at %unit] `%unit ~[[%var v]]]
8048+ =(typ.template expected)
8049+::
8050+:: A named missing-case diagnostic needs more than a failed fit: a case
8051+:: with that tag but the wrong payload is not a missing case. Unknown
8052+:: shapes and atom types that accept terms keep the proof conservative.
8053++$ itag-presence ?(%yes %no %maybe)
8054+++ tag-presence-cases
8055+ |= [cases=(list itype) value=@ sub=isub]
8056+ ^- itag-presence
8057+ ?~ cases %no
8058+ =/ first=itag-presence (tag-presence i.cases value sub)
8059+ ?: =(%yes first) %yes
8060+ =/ rest=itag-presence $(cases t.cases)
8061+ ?: =(%yes rest) %yes
8062+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8063+ %no
8064+::
8065+++ tag-presence
8066+ |= [t=itype value=@ sub=isub]
8067+ ^- itag-presence
8068+ =. t (itype-walk t sub)
8069+ ?- -.t
8070+ %const ?:(=(value val.literal.t) %yes %no)
8071+ %flag ?:(|(=(value 0) =(value 1)) %yes %no)
8072+ %atom ?:(|(=(%tas aura.t) =(%ta aura.t)) %maybe %no)
8073+ %face $(t body.t)
8074+ %cell
8075+ =/ first=itag-presence $(t hed.t)
8076+ ?: =(%yes first) %yes
8077+ =/ rest=itag-presence $(t tal.t)
8078+ ?: =(%yes rest) %yes
8079+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8080+ %no
8081+ %union (tag-presence-cases cases.t value sub)
8082+ * %maybe
8083+ ==
8084+::
8085+++ missing-union-tag
8086+ |= [e=expr expected=itype sub=isub context=span]
8087+ ^- (unit idiag)
8088+ ?. ?=(%lit -.e) ~
8089+ ?. =(%term form.lit.e) ~
8090+ =. expected (itype-walk expected sub)
8091+ |-
8092+ ?: ?=(%face -.expected) $(expected (itype-walk body.expected sub))
8093+ ?. ?=(%union -.expected) ~
8094+ ?. =(%no (tag-presence-cases cases.expected val.lit.e sub)) ~
8095+ =/ label=tape
8096+ ?~ label.expected "union {(show-itype expected sub)}"
8097+ (show-itype expected sub)
8098+ `["{label} has no case `{(trip txt.lit.e)}`" ~[[context "expected union"] [(span-of e) "tag"]]]
8099+::
8100+:: Locate a missing tag inside a syntactic tuple only by replaying the
8101+:: directional fit in source order. Uncertain or earlier failures stop
8102+:: the walk, preserving the generic diagnostic rather than guessing.
8103+++ nested-missing-tag
8104+ |= [e=expr actual=itype expected=itype sub=isub next=@ud context=span]
8105+ ^- (unit idiag)
8106+ =/ original=[left=itype right=itype] [actual expected]
8107+ ?: |(?=(%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))) ~
8108+ =/ fit=ifit (itype-fit actual expected sub next)
8109+ ?. ?=(%bad -.fit) ~
8110+ =. actual (itype-walk actual sub)
8111+ =. expected (itype-walk expected sub)
8112+ ?: &(?=(%face -.actual) ?=(%face -.expected))
8113+ ?. =(name.actual name.expected) ~
8114+ $(actual body.actual, expected body.expected)
8115+ ?: ?=(%face -.actual) $(actual body.actual)
8116+ ?: ?=(%face -.expected) $(expected body.expected)
8117+ =/ direct=(unit idiag) (missing-union-tag e expected sub context)
8118+ ?^ direct direct
8119+ ?. ?=(%tuple -.e) ~
8120+ (nested-missing-items items.e actual expected sub next context)
8121+::
8122+++ nested-missing-items
8123+ |= [items=(list item) actual=itype expected=itype sub=isub next=@ud context=span]
8124+ ^- (unit idiag)
8125+ ?~ items ~
8126+ ?~ t.items (nested-missing-tag val.i.items actual expected sub next context)
8127+ =/ original=[left=itype right=itype] [actual expected]
8128+ ?: |(?=(%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))) ~
8129+ =. actual (itype-walk actual sub)
8130+ =. expected (itype-walk expected sub)
8131+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8132+ =/ first=ifit (itype-fit hed.actual hed.expected sub next)
8133+ ?: ?=(%bad -.first)
8134+ (nested-missing-tag val.i.items hed.actual hed.expected sub next context)
8135+ ?. ?=(%ok -.first) ~
8136+ $(items t.items, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
8137+::
8138+:: A term-headed pair is the same noun as a two-item cell. Preserve the
8139+:: whole pair span for the synthetic head and the value's own span for
8140+:: the payload; unresolved term constraints follow ordinary cell inference.
8141+++ pair-as-cell
8142+ |= e=expr
8143+ ^- expr
8144+ ?> ?=(%pair -.e)
8145+ =/ head=expr [%lit at.e [%term %tas tag.e (crip ['%' (trip tag.e)])]]
8146+ [%tuple at.e ~[[at.e ~ head] [(span-of val.e) ~ val.e]]]
8147+::
8148+:: A segment costs one shared step; dynamic segments are not handled yet.
8149+++ qath-static-fuel
8150+ |= [segs=(list qseg) fuel=@ud]
8151+ ^- (unit @ud)
8152+ ?~ segs `fuel
8153+ ?: =(0 fuel) ~
8154+ ?. ?=(%knot -.i.segs) ~
8155+ $(segs t.segs, fuel (dec fuel))
8156+::
8157+++ infer-fragment
8158+ |= [e=expr env=ienv state=istate]
8159+ ^- iresult
8160+ ?- -.e
8161+ %pair $(e (pair-as-cell e))
8162+ %lit
8163+ ?- form.lit.e
8164+ %number ?: =(%ud aura.lit.e)
8165+ [%& [%nvar next.state] state(next +(next.state))]
69158166 [%& [%atom aura.lit.e] state]
69168167 %ship [%& [%atom %p] state]
69178168 %date [%& [%atom %da] state]
@@ -6921,7 +8172,45 @@
69218172 %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
69228173 %null [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
69238174 ==
8175+ %unit
8176+ ?~ prelude.state [%| ["unit construction needs the standard prelude in partial inference" ~]]
8177+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
8178+ ?~ standard [%| ["unit construction needs the standard prelude in partial inference" ~]]
8179+ ?. (standard-unit-template u.standard at.u.prelude.state)
8180+ [%| ["unit construction needs the standard prelude in partial inference" ~]]
8181+ =/ value=iresult $(e val.e)
8182+ ?: ?=(%| -.value) value
8183+ =/ result=(unit itype) (template-apply u.standard ~[typ.p.value])
8184+ ?~ result [%| ["unit construction is not supported by partial inference" ~]]
8185+ [%& u.result state.p.value]
8186+ %list
8187+ ?~ prelude.state [%| ["list literal needs the standard prelude in partial inference" ~]]
8188+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8189+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8190+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8191+ ?~ standard [%| ["list literal needs the standard prelude in partial inference" ~]]
8192+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]])
8193+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8194+ =/ element=itype [%var next.state]
8195+ =/ result=iresult (infer-open-list-items items.e element env state(next +(next.state)) at.e)
8196+ ?: ?=(%| -.result) result
8197+ [%& [%collection %list ~[element]] state.p.result]
69248198 %str (infer-string-pieces pieces.e env state)
8199+ %qath
8200+ ?~ prelude.state [%| ["application path needs the standard prelude in partial inference" ~]]
8201+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8202+ [%| ["application path needs the standard prelude in partial inference" ~]]
8203+ =/ standard=(unit ischeme) (find-jibb-mold %qath u.prelude.state)
8204+ ?~ standard [%| ["application path needs the standard prelude in partial inference" ~]]
8205+ ?. ?=(~ vars.u.standard) [%| ["application path mold needs unsupported inference" ~]]
8206+ =/ typ=itype typ.u.standard
8207+ ?. ?=(%jrec -.typ) [%| ["application path mold needs unsupported inference" ~]]
8208+ ?. &(=(at.typ /lib/jibb/internal/jibb) =(%qath name.typ) =(%i head.typ) =(%ta aura.typ) =(%t tail.typ))
8209+ [%| ["application path mold needs unsupported inference" ~]]
8210+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8211+ =/ remain=(unit @ud) (qath-static-fuel segs.e (dec jrec-fuel.state))
8212+ ?~ remain [%| ["application path segments need unsupported inference" ~]]
8213+ [%& typ state(jrec-fuel u.remain)]
69258214 %wing
69268215 ?~ names.e [%| ["empty wing" ~]]
69278216 ?^ t.names.e
@@ -6930,7 +8219,7 @@
69308219 ?~ iface (infer-field-wing names.e env state)
69318220 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
69328221 ?~ member [%| ["module member is not available to partial inference" ~]]
6933− =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e)
8222+ =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e prelude.state)
69348223 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
69358224 [%& typ.instance state.instance]
69368225 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
@@ -6943,6 +8232,11 @@
69438232 =/ instance=[typ=itype state=istate] (instantiate-scheme u.scheme state)
69448233 [%& typ.instance state.instance]
69458234 %group $(e inner.e)
8235+ %change
8236+ ?~ edits.e [%| ["a change takes at least one field" ~[[at.e "empty change"]]]]
8237+ =/ target=iresult $(e [%wing at.e target.e])
8238+ ?: ?=(%| -.target) target
8239+ (infer-change-edits edits.e typ.p.target env state.p.target ~)
69468240 %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [[next.state tag.e] tags.state])]
69478241 %trace
69488242 =/ traced=iresult $(e val.e)
@@ -6959,6 +8253,9 @@
69598253 [%| ["local molds shadow a name" ~]]
69608254 =/ local-state=istate
69618255 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8256+ =/ mold-hole=(unit span) (simple-local-mold-hole defs.e)
8257+ ?^ mold-hole
8258+ [%| ["type hole needs a determined type" ~[[u.mold-hole "unresolved type hole"]]]]
69628259 ?. (local-molds-supported local-molds local-state)
69638260 [%| ["local molds need unsupported inference" ~]]
69648261 =/ values=(list def) (local-value-defs defs.e)
@@ -6969,11 +8266,16 @@
69698266 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
69708267 %branch
69718268 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
6972− ?~ t.arms.e (infer-cell-branch e env state)
8269+ ?~ t.arms.e
8270+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8271+ ?^ single (infer-known-union-branch-subject e env u.single)
8272+ ?: (single-structured-pattern e) (infer-single-case-branch e env state ~)
8273+ (infer-cell-branch e env state ~)
69738274 ?^ t.t.arms.e (infer-known-union-branch e env state)
6974− =/ known=(unit itype) (known-union-subject subject.e env state)
6975− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
6976− (infer-known-union-branch e env state)
8275+ =/ known=(unit iresult) (known-union-subject subject.e env state)
8276+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
8277+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
8278+ (infer-known-union-branch-subject e env u.known)
69778279 =/ x=arm i.arms.e
69788280 =/ y=arm i.t.arms.e
69798281 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
@@ -6982,7 +8284,7 @@
69828284 ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
69838285 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
69848286 (infer-known-union-branch e env state)
6985− ?^ known (infer-known-union-branch e env state)
8287+ ?: &(?=(^ known) ?=(%& -.u.known)) (infer-known-union-branch-subject e env u.known)
69868288 ?: =(val.lit.pat.x val.lit.pat.y)
69878289 [%| ["branch does not cover both loobeans" ~]]
69888290 =/ subject=iresult $(e subject.e)
@@ -7021,17 +8323,18 @@
70218323 ?^ diag [%| u.diag]
70228324 [%| ["cast mold is not supported by partial inference" ~]]
70238325 =/ value=iresult
7024− ?: &(?=(%union -.typ.u.target) (context-union-branch val.e))
7025− (infer-union-context val.e typ.u.target env state.u.target at.shape.e)
7026− ?: &(?=(%collection -.typ.u.target) =(%list name.typ.u.target) (context-union-branch val.e))
7027− (infer-union-context val.e typ.u.target env state.u.target at.shape.e)
7028− ?: &(?=(%collection -.typ.u.target) =(%list name.typ.u.target) (context-list-expression val.e))
7029− (infer-list-context val.e typ.u.target env state.u.target at.shape.e)
7030− $(e val.e, state state.u.target)
8326+ (infer-call-context-arg val.e typ.u.target env state.u.target at.shape.e)
70318327 ?: ?=(%| -.value) value
8328+ =/ shape=(unit [source=iwfields target=iwfields])
8329+ (width-shape typ.p.value typ.u.target sub.state.p.value)
8330+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
70328331 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
70338332 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
70348333 ?: ?=(%bad -.fit)
8334+ =/ missing=(unit idiag) (missing-union-tag val.e typ.u.target sub.state.p.value at.shape.e)
8335+ ?^ missing [%| u.missing]
8336+ =/ 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)
8337+ ?^ nested [%| u.nested]
70358338 [%| ["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)]]]]
70368339 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
70378340 [%& merged state.p.value(sub sub.fit, next next.fit)]
@@ -7056,43 +8359,9 @@
70568359 [%& [%fn typ.p.sam typ.p.body] state.p.body]
70578360 %call
70588361 ?~ args.e [%| ["call has no argument" ~]]
7059− =/ head=iresult $(e head.e)
7060− ?: ?=(%| -.head) head
7061− =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
7062− =/ arg=iresult
7063− ?^ t.args.e
7064− ?: ?=(%fn -.head-type)
7065− (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
7066− (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
7067− ?: &(?=(%fn -.head-type) ?=(%union -.sample.head-type) (context-union-branch i.args.e))
7068− (infer-union-context i.args.e sample.head-type env state.p.head (span-of head.e))
7069− ?: &(?=(%fn -.head-type) ?=(%collection -.sample.head-type) =(%list name.sample.head-type) (context-union-branch i.args.e))
7070− (infer-union-context i.args.e sample.head-type env state.p.head (span-of head.e))
7071− ?: &(?=(%fn -.head-type) ?=(%collection -.sample.head-type) =(%list name.sample.head-type) (context-list-expression i.args.e))
7072− (infer-list-context i.args.e sample.head-type env state.p.head (span-of head.e))
7073− $(e i.args.e, state state.p.head)
7074− ?: ?=(%| -.arg) arg
7075− =/ st=istate state.p.arg
7076− =/ ht=itype (itype-walk typ.p.head sub.st)
7077− ?: ?=(%fn -.ht)
7078− =/ fit=ifit (itype-fit typ.p.arg sample.ht sub.st next.st)
7079− ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
7080− ?: ?=(%bad -.fit)
7081− =/ bad=(unit [at=span typ=itype])
7082− ?~(t.args.e ~ (call-error-site args.e typ.p.arg sample.ht sub.st next.st))
7083− =/ whole-args=span
7084− ?~(t.args.e (span-of i.args.e) [beg:(span-of i.args.e) end:(span-of (rear args.e))])
7085− =/ arg-at=span ?~(bad whole-args at.u.bad)
7086− =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
7087− [%| ["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)]]]]
7088− ?: &((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))
7089− [%| ["call result face propagation is not supported by partial inference" ~]]
7090− [%& product.ht st(sub sub.fit, next next.fit)]
7091− =/ result=itype [%var next.st]
7092− =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
7093− ?~ uni
7094− [%| ["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)]]]]
7095− [%& result st(next +(next.st), sub u.uni)]
8362+ ?: (explicit-proj-call e env state)
8363+ [%| ["proj needs an expected record type" ~]]
8364+ (infer-call-with-head e env state (infer-fragment head.e env state))
70968365 * [%| ["expression is not supported by partial inference" ~]]
70978366 ==
70988367::
@@ -7100,12 +8369,314 @@
71008369:: failed. If an intermediate fit is uncertain, retain the whole argument
71018370:: span rather than assigning blame to a particular argument.
71028371::
8372+:: Check a call using the head already inferred in this state. Keeping
8373+:: this shared avoids evaluating or instantiating a contextual head twice.
8374+++ width-has-projections
8375+ |= ps=(list iwprojection)
8376+ ^- ?
8377+ ?~ ps |
8378+ &
8379+::
8380++$ iwidth-elaboration [original=expr typ=itype sub=isub projections=(list iwprojection)]
8381+++ infer-width-elaboration
8382+ |= [e=expr env=ienv state=istate]
8383+ ^- (each iwidth-elaboration idiag)
8384+ =/ out=iresult (infer-fragment e env state)
8385+ ?: ?=(%| -.out) [%| p.out]
8386+ [%& [e typ.p.out sub.state.p.out (flop projections.state.p.out)]]
8387+::
8388+:: Source-bound gate-layout evidence, confined to checked root gate
8389+:: definitions and direct unshadowed prelude calls. The prepared prelude
8390+:: interface and its retained source are trusted as a matching artifact.
8391+:: Layouts identify sample binder faces; they do not change call arity or
8392+:: authorize stripping nested value faces. Unknown origins use ordinary fit.
8393+++ direct-written-gates
8394+ |= [ds=(list def) out=ivisited]
8395+ ^- ivisited
8396+ ?~ ds out
8397+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8398+ ?. |(?=(%gate -.val.i.ds) ?=(%gate-wide -.val.i.ds)) $(ds t.ds)
8399+ $(ds t.ds, out (~(put by out) name.i.ds &))
8400+++ direct-may-use-prelude
8401+ |= [ds=(list def) root=ivisited heads=ivisited]
8402+ ^- ?
8403+ ?~ ds |
8404+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8405+ =/ refs=(list term) (dependency-expr val.i.ds)
8406+ =/ has-root=? (lien refs |=(n=term ?=(^ (~(get by root) n))))
8407+ =/ has-head=? (lien refs |=(n=term ?=(^ (~(get by heads) n))))
8408+ ?: &(has-root has-head) &
8409+ $(ds t.ds)
8410+++ direct-unique-names
8411+ |= [names=(list term) seen=ivisited]
8412+ ^- ?
8413+ ?~ names &
8414+ ?: ?=(^ (~(get by seen) i.names)) |
8415+ $(names t.names, seen (~(put by seen) i.names &))
8416+++ direct-prelude-evidence
8417+ |= [ds=(list def) prelude=(unit ifile)]
8418+ ^- (unit igate-prelude-evidence)
8419+ ?~ prelude ~
8420+ ?~ source.u.prelude ~
8421+ =/ root=ivisited (direct-written-gates ds ~)
8422+ =/ names=(list term) (turn values.u.prelude |=(e=[name=term scheme=ischeme] name.e))
8423+ =/ heads=ivisited (graph-nameset names ~)
8424+ ?. (direct-may-use-prelude ds root heads) ~
8425+ =/ parsed (parse at.u.prelude u.source.u.prelude)
8426+ ?: ?=(%| -.parsed) ~
8427+ ?^ (duplicate-defs defs.p.parsed) ~
8428+ ?. (direct-unique-names (global-value-names defs.p.parsed) ~) ~
8429+ =/ gates=(map term def) (direct-checked-gates defs.p.parsed values.u.prelude)
8430+ `[u.prelude gates]
8431+++ direct-checked-gates
8432+ |= [ds=(list def) env=ienv]
8433+ ^- (map term def)
8434+ =/ names=(list term) (turn env |=(e=[name=term scheme=ischeme] name.e))
8435+ =/ known=ivisited (graph-nameset names ~)
8436+ =/ out=(map term def) ~
8437+ |-
8438+ ?~ ds out
8439+ =/ d=def i.ds
8440+ ?: ?=(%mold -.d) $(ds t.ds)
8441+ ?. ?=(^ (~(get by known) name.d)) $(ds t.ds)
8442+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) $(ds t.ds)
8443+ $(ds t.ds, out (~(put by out) name.d d))
8444+++ direct-find-gate
8445+ |= [n=term ds=(list def)]
8446+ ^- (unit def)
8447+ ?~ ds ~
8448+ ?: &(?=(%value -.i.ds) =(n name.i.ds)) `i.ds
8449+ $(ds t.ds)
8450+++ direct-gate-sample
8451+ |= d=def
8452+ ^- (unit sample)
8453+ ?. ?=(%value -.d) ~
8454+ ?- -.val.d
8455+ %gate `sample.val.d
8456+ %gate-wide `sample.val.d
8457+ * ~
8458+ ==
8459+++ direct-sample-name
8460+ |= sam=sample
8461+ ^- (unit term)
8462+ ?- -.sam
8463+ %bind `name.sam
8464+ %face `name.sam
8465+ %pun `name.sam
8466+ * ~
8467+ ==
8468+++ direct-field-name
8469+ |= f=field
8470+ ^- (unit term)
8471+ ?- -.f
8472+ %face `name.f
8473+ %pun `name.f
8474+ * ~
8475+ ==
8476+++ direct-slot-body
8477+ |= [typ=itype name=(unit term)]
8478+ ^- (unit itype)
8479+ ?~ name `typ
8480+ ?. ?=(%face -.typ) ~
8481+ ?. =(name.typ u.name) ~
8482+ `body.typ
8483+++ direct-invariant
8484+ |= [a=itype b=itype sub=isub next=@ud]
8485+ ^- ifit
8486+ ?: (itype-face-asym a b sub) [%unknown ~]
8487+ =/ forward=ifit (itype-fit a b sub next)
8488+ ?. ?=(%ok -.forward) [%unknown ~]
8489+ ?: (itype-face-asym a b sub.forward) [%unknown ~]
8490+ =/ reverse=ifit (itype-fit b a sub.forward next.forward)
8491+ ?. ?=(%ok -.reverse) [%unknown ~]
8492+ reverse
8493+++ direct-function-fit
8494+ |= [a=itype b=itype sam=sample sh=shape sub=isub next=@ud]
8495+ ^- ifit
8496+ ?. &(?=(%fn -.a) ?=(%fn -.b) ?=(%cell -.sam) ?=(%fn -.sh)) [%unknown ~]
8497+ ?. ?=(%cell -.sample.sh) [%unknown ~]
8498+ =/ as=(list sample) items.sam
8499+ =/ bs=(list field) fields.sample.sh
8500+ ?~ as [%unknown ~]
8501+ ?~ t.as [%unknown ~]
8502+ ?^ t.t.as [%unknown ~]
8503+ ?~ bs [%unknown ~]
8504+ ?~ t.bs [%unknown ~]
8505+ ?^ t.t.bs [%unknown ~]
8506+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) [%unknown ~]
8507+ =/ an=(unit term) (direct-sample-name i.as)
8508+ =/ bn=(unit term) (direct-field-name i.bs)
8509+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8510+ =/ x=(unit itype) (direct-slot-body hed.sample.a an)
8511+ =/ y=(unit itype) (direct-slot-body hed.sample.b bn)
8512+ ?~ x [%unknown ~]
8513+ ?~ y [%unknown ~]
8514+ =/ first=ifit (direct-invariant u.x u.y sub next)
8515+ ?. ?=(%ok -.first) [%unknown ~]
8516+ =. an (direct-sample-name i.t.as)
8517+ =. bn (direct-field-name i.t.bs)
8518+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8519+ =/ x2=(unit itype) (direct-slot-body tal.sample.a an)
8520+ =/ y2=(unit itype) (direct-slot-body tal.sample.b bn)
8521+ ?~ x2 [%unknown ~]
8522+ ?~ y2 [%unknown ~]
8523+ =/ second=ifit (direct-invariant u.x2 u.y2 sub.first next.first)
8524+ ?. ?=(%ok -.second) [%unknown ~]
8525+ (direct-invariant product.a product.b sub.second next.second)
8526+:: This is a tentative proof: its caller must require closed call samples
8527+:: and repeat every positional check under the stable final substitution.
8528+++ direct-positional-fit
8529+ |= [args=(list expr) slots=(list sample) actual=itype expected=itype env=ienv state=istate sub=isub next=@ud]
8530+ ^- ifit
8531+ ?~ args [%unknown ~]
8532+ ?~ slots [%unknown ~]
8533+ =/ last=? ?=(~ t.args)
8534+ ?: !=(last ?=(~ t.slots)) [%unknown ~]
8535+ =/ split=(unit [left=itype right=itype])
8536+ ?: last `[actual expected]
8537+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8538+ `[hed.actual hed.expected]
8539+ ?~ split [%unknown ~]
8540+ =/ x=itype left.u.split
8541+ =/ y=itype right.u.split
8542+ =/ expected-name=(unit term) (direct-sample-name i.slots)
8543+ =/ expected-body=(unit itype) (direct-slot-body y expected-name)
8544+ ?~ expected-body [%unknown ~]
8545+ =. y u.expected-body
8546+ =/ fit=ifit (itype-fit x y sub next)
8547+ =/ accepted=? &(?=(%ok -.fit) !(itype-positional-slot-face-asym x y sub.fit))
8548+ =/ result=(unit ifit)
8549+ ?: accepted `fit
8550+ ?. &(?=(%face -.i.slots) ?=(%fn -.shape.i.slots)) ~
8551+ ?. ?=(%wing -.i.args) ~
8552+ ?. ?=([@ ~] names.i.args) ~
8553+ ?. (unique-value-name i.names.i.args globals.state) ~
8554+ =/ source=(unit def) (~(get by gate-defs.state) i.names.i.args)
8555+ ?~ source ~
8556+ =/ sample=(unit sample) (direct-gate-sample u.source)
8557+ ?~ sample ~
8558+ =/ trial=ifit (direct-function-fit x y u.sample shape.i.slots sub next)
8559+ ?. ?=(%ok -.trial) ~
8560+ `trial
8561+ ?~ result [%unknown ~]
8562+ =. fit u.result
8563+ ?: last fit
8564+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
8565+ ?. ?=(%ok -.fit) [%unknown ~]
8566+ $(args t.args, slots t.slots, actual tal.actual, expected tal.expected, sub sub.fit, next next.fit)
8567+++ direct-any-gate-arg
8568+ |= [args=(list expr) defs=(map term def)]
8569+ ^- ?
8570+ ?~ args |
8571+ =/ found=?
8572+ ?. ?=(%wing -.i.args) |
8573+ ?. ?=([@ ~] names.i.args) |
8574+ ?=(^ (~(get by defs) i.names.i.args))
8575+ ?: found &
8576+ $(args t.args)
8577+++ direct-gate-call-fit
8578+ |= [e=expr actual=itype expected=itype env=ienv state=istate]
8579+ ^- (unit ifit)
8580+ ?. ?=(%call -.e) ~
8581+ ?~ args.e ~
8582+ ?~ t.args.e ~
8583+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8584+ ?. ?=(%wing -.head.e) ~
8585+ ?. ?=([@ ~] names.head.e) ~
8586+ ?. ?=(~ (ienv-lookup i.names.head.e env)) ~
8587+ ?. (unique-value-name i.names.head.e globals.state) ~
8588+ ?. (direct-any-gate-arg args.e gate-defs.state) ~
8589+ ?~ prelude.state ~
8590+ ?~ source.u.prelude.state ~
8591+ ?~ head-evidence.state ~
8592+ ?. =(u.prelude.state iface.u.head-evidence.state) ~
8593+ ?. ?=(^ (ienv-lookup i.names.head.e values.u.prelude.state)) ~
8594+ =/ head=(unit def) (~(get by gates.u.head-evidence.state) i.names.head.e)
8595+ ?~ head ~
8596+ =/ sam=(unit sample) (direct-gate-sample u.head)
8597+ ?~ sam ~
8598+ ?. ?=(%cell -.u.sam) ~
8599+ =/ fit=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.state next.state)
8600+ ?. ?=(%ok -.fit) ~
8601+ :: Enclosing inference may add constraints after this call. Only a
8602+ :: closed call-sample proof can remain stable under those later bindings.
8603+ =/ actual-final=itype (itype-normalize actual sub.fit)
8604+ =/ expected-final=itype (itype-normalize expected sub.fit)
8605+ ?^ (itype-vars actual-final) ~
8606+ ?^ (itype-vars expected-final) ~
8607+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
8608+ :: A later argument may resolve a variable used by an earlier slot.
8609+ :: Recheck every fit and face against the completed substitution; no
8610+ :: additional binding or fresh variable is permitted in the second pass.
8611+ =/ verified=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.fit next.fit)
8612+ ?. ?=(%ok -.verified) ~
8613+ ?. &(=(sub.fit sub.verified) =(next.fit next.verified)) ~
8614+ `fit
8615+::
8616+++ infer-call-with-head
8617+ |= [e=expr env=ienv state=istate head=iresult]
8618+ ^- iresult
8619+ ?> ?=(%call -.e)
8620+ ?~ args.e [%| ["call has no argument" ~]]
8621+ ?: ?=(%| -.head) head
8622+ =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
8623+ =/ arg=iresult
8624+ ?^ t.args.e
8625+ ?: ?=(%fn -.head-type)
8626+ (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
8627+ (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
8628+ ?: ?=(%fn -.head-type)
8629+ (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
8630+ (infer-fragment i.args.e env state.p.head)
8631+ ?: ?=(%| -.arg) arg
8632+ =/ st=istate state.p.arg
8633+ =/ ht=itype (itype-walk typ.p.head sub.st)
8634+ ?: ?=(%fn -.ht)
8635+ =/ shape=(unit [source=iwfields target=iwfields])
8636+ ?^ t.args.e ~
8637+ (width-shape typ.p.arg sample.ht sub.st)
8638+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
8639+ =/ fit=ifit
8640+ ?^ t.args.e (itype-fit-inner typ.p.arg sample.ht sub.st next.st & |)
8641+ (itype-fit typ.p.arg sample.ht sub.st next.st)
8642+ =/ direct=(unit ifit)
8643+ ?: ?=(%ok -.fit) ~
8644+ (direct-gate-call-fit e typ.p.arg sample.ht env st)
8645+ =. fit ?~(direct fit u.direct)
8646+ ?: ?=(%unknown -.fit) [%| ["call constraint is not supported by partial inference" ~]]
8647+ ?: ?=(%bad -.fit)
8648+ ?~ t.args.e
8649+ =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
8650+ ?^ missing [%| u.missing]
8651+ =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
8652+ ?^ nested [%| u.nested]
8653+ [%| ["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)]]]]
8654+ =/ bad=(unit [at=span typ=itype])
8655+ (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
8656+ =/ whole-args=span
8657+ [beg:(span-of i.args.e) end:(span-of (rear args.e))]
8658+ =/ arg-at=span ?~(bad whole-args at.u.bad)
8659+ =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
8660+ [%| ["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)]]]]
8661+ =/ face-asym=?
8662+ ?^ direct |
8663+ ?^ t.args.e (itype-positional-face-asym args.e typ.p.arg sample.ht sub.fit)
8664+ (itype-face-asym typ.p.arg sample.ht sub.fit)
8665+ ?: &((itype-has-face typ.p.arg sub.fit) face-asym (itype-output-may-be-cell product.ht sub.fit))
8666+ [%| ["call result face propagation is not supported by partial inference" ~]]
8667+ [%& product.ht st(sub sub.fit, next next.fit)]
8668+ =/ result=itype [%var next.st]
8669+ =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
8670+ ?~ uni
8671+ [%| ["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)]]]]
8672+ [%& result st(next +(next.st), sub u.uni)]
8673+::
71038674++ call-error-site
71048675 |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
71058676 ^- (unit [at=span typ=itype])
71068677 ?~ args ~
71078678 =/ original=[left=itype right=itype] [actual expected]
7108− ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%nvar -.left.original) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%nvar -.right.original)) ~
8679+ ?: |(?=(%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))) ~
71098680 =. actual (itype-walk actual sub)
71108681 =. expected (itype-walk expected sub)
71118682 ?: &(?=(%face -.expected) !?=(%face -.actual))
@@ -7120,34 +8691,398 @@
71208691 ?: ?=(%unknown -.first) ~
71218692 $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
71228693::
7123−:: Context can help each argument while the final fit still checks the
7124−:: complete right-nested sample, including any faces on its positions.
8694+:: Context can help a call argument or cast value while the final fit
8695+:: checks the complete right-nested type, including any written faces.
8696+::
8697+:: Context can resolve the payload of a canonical prelude unit, but an
8698+:: unrelated union with a similar noun shape is not the same mold.
8699+++ infer-unit-context
8700+ |= [e=expr expected=itype env=ienv state=istate context=span]
8701+ ^- iresult
8702+ ?> ?=(%unit -.e)
8703+ ?> ?=(%union -.expected)
8704+ ?~ prelude.state (infer-fragment e env state)
8705+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
8706+ ?~ standard (infer-fragment e env state)
8707+ ?. (standard-unit-template u.standard at.u.prelude.state) (infer-fragment e env state)
8708+ ?. =(origin.expected `[at.u.prelude.state %unit]) (infer-fragment e env state)
8709+ ?~ args.expected (infer-fragment e env state)
8710+ ?^ t.args.expected (infer-fragment e env state)
8711+ =/ payload=itype i.args.expected
8712+ =/ canonical=(unit itype) (template-apply u.standard ~[payload])
8713+ ?~ canonical (infer-fragment e env state)
8714+ ?> ?=(%union -.u.canonical)
8715+ ?. =((itype-normalize expected(label ~) sub.state) (itype-normalize u.canonical(label ~) sub.state))
8716+ (infer-fragment e env state)
8717+ =/ value=iresult (infer-call-context-arg val.e payload env state context)
8718+ ?: ?=(%| -.value) value
8719+ =/ fit=ifit (itype-fit typ.p.value payload sub.state.p.value next.state.p.value)
8720+ ?: ?=(%unknown -.fit) [%| ["unit payload constraint is not supported by partial inference" ~]]
8721+ ?: ?=(%bad -.fit)
8722+ =/ missing=(unit idiag) (missing-union-tag val.e payload sub.state.p.value context)
8723+ ?^ missing [%| u.missing]
8724+ =/ nested=(unit idiag) (nested-missing-tag val.e typ.p.value payload sub.state.p.value next.state.p.value context)
8725+ ?^ nested [%| u.nested]
8726+ [%| ["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)]]]]
8727+ [%& expected state.p.value(sub sub.fit, next next.fit)]
8728+::
8729+:: A known gate may receive an enclosing target before its argument is
8730+:: inferred when its result is open or a direct, matching named generic
8731+:: union. Opaque, recursive, tag-constrained and variable-bound union
8732+:: results keep the existing directional path.
8733+++ infer-contextual-call
8734+ |= [e=expr expected=itype env=ienv state=istate]
8735+ ^- iresult
8736+ ?> ?=(%call -.e)
8737+ ?~ args.e [%| ["call has no argument" ~]]
8738+ =/ head=iresult (infer-fragment head.e env state)
8739+ ?: ?=(%| -.head) head
8740+ =/ ht=itype (itype-walk typ.p.head sub.state.p.head)
8741+ ?. ?=(%fn -.ht) (infer-call-with-head e env state head)
8742+ =/ result=itype (itype-walk product.ht sub.state.p.head)
8743+ =/ eligible=?
8744+ ?: ?=(%var -.result) &
8745+ :: A direct known generic union may receive the same nominal result
8746+ :: context before its arguments are checked. Variable-bound origins,
8747+ :: pending tags, recursive identities and unknown atoms stay open.
8748+ ?. &(?=(%union -.product.ht) ?=(%union -.result) ?=(%union -.expected)) |
8749+ ?~ origin.result |
8750+ ?. =(origin.result origin.expected) |
8751+ ?~ args.result |
8752+ ?. =((lent args.result) (lent args.expected)) |
8753+ ?: |((itype-has-tag (itype-normalize result sub.state.p.head)) (itype-has-tag (itype-normalize expected sub.state.p.head))) |
8754+ ?: |((itype-has-recursive (itype-normalize result sub.state.p.head)) (itype-has-recursive (itype-normalize expected sub.state.p.head))) |
8755+ ?: |((itype-has-any-atom result sub.state.p.head) (itype-has-any-atom expected sub.state.p.head)) |
8756+ &
8757+ ?. eligible (infer-call-with-head e env state head)
8758+ ?: |(?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)) (itype-has-tag (itype-normalize expected sub.state.p.head)))
8759+ (infer-call-with-head e env state head)
8760+ =/ sub=(unit isub) (itype-unify result expected sub.state.p.head)
8761+ ?~ sub (infer-call-with-head e env state head)
8762+ (infer-call-with-head e env state [%& typ.p.head state.p.head(sub u.sub)])
8763+::
8764+:: An eligible fully faced literal receives context by name, in source order.
8765+++ width-literal-fields
8766+ |= [items=(list item) axis=@ud fuel=@ud]
8767+ ^- (unit iwfields)
8768+ =/ order=(list iwfield) ~
8769+ =/ index=(map term iwfield) *(map term iwfield)
8770+ |-
8771+ ?~ items ~
8772+ ?: =(0 fuel) ~
8773+ ?~ face.i.items ~
8774+ =/ at-axis=@ud ?~(t.items axis (mul 2 axis))
8775+ =/ entry=iwfield [u.face.i.items at-axis [%noun ~]]
8776+ ?: ?=(^ (~(get by index) name.entry)) ~
8777+ =. index (~(put by index) name.entry entry)
8778+ =. order [entry order]
8779+ ?~ t.items `[(flop order) index]
8780+ $(items t.items, axis +((mul 2 axis)), fuel (dec fuel))
8781+++ width-infer-items
8782+ |= [items=(list item) expected=(map term iwfield) env=ienv state=istate context=span]
8783+ ^- iresult
8784+ ?~ items [%| ["empty record is not supported" ~]]
8785+ ?~ face.i.items [%| ["record face needs unsupported inference" ~]]
8786+ =/ field=(unit iwfield) (~(get by expected) u.face.i.items)
8787+ =/ head=iresult
8788+ ?~ field (infer-fragment val.i.items env state)
8789+ (infer-call-context-arg val.i.items typ.u.field env state context)
8790+ ?: ?=(%| -.head) head
8791+ =/ typ=itype [%face u.face.i.items typ.p.head]
8792+ ?~ t.items [%& typ state.p.head]
8793+ =/ tail=iresult $(items t.items, state state.p.head)
8794+ ?: ?=(%| -.tail) tail
8795+ [%& [%cell typ typ.p.tail] state.p.tail]
8796+++ width-infer-literal
8797+ |= [e=expr expected=itype env=ienv state=istate context=span]
8798+ ^- (unit iresult)
8799+ ?. ?=(%tuple -.e) ~
8800+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) ~
8801+ =/ source=(unit iwfields) (width-literal-fields items.e 1 4.096)
8802+ =/ target=(unit iwfields) (width-scan expected sub.state 1 4.096)
8803+ ?~ source ~
8804+ ?~ target ~
8805+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
8806+ ?. (width-in-order order.u.source order.u.target)
8807+ `(infer-simple-items items.e env state)
8808+ `(width-infer-items items.e index.u.target env state context)
8809+::
8810+:: Experimental intrinsic recognition; real bindings retain normal calls.
8811+++ explicit-proj-call
8812+ |= [e=expr env=ienv state=istate]
8813+ ^- ?
8814+ ?. ?=(%call -.e) |
8815+ ?. ?=([* ~] args.e) |
8816+ ?. ?=(%wing -.head.e) |
8817+ ?. =(names.head.e ~[%proj]) |
8818+ ?: ?=(^ (ienv-lookup %proj env)) |
8819+ ?: (lien globals.state |=(n=term =(n %proj))) |
8820+ ?~ prelude.state &
8821+ ?:(?=(^ (ienv-lookup %proj values.u.prelude.state)) | &)
8822+++ infer-proj-source
8823+ |= [e=expr expected=itype env=ienv state=istate context=span]
8824+ ^- iresult
8825+ ?: ?=(%group -.e) $(e inner.e)
8826+ =/ literal=(unit iresult) (width-infer-literal e expected env state context)
8827+ ?^ literal u.literal
8828+ (infer-fragment e env state)
8829+++ infer-proj-context
8830+ |= [e=expr expected=itype env=ienv state=istate context=span]
8831+ ^- iresult
8832+ ?> ?=(%call -.e)
8833+ ?~ args.e [%| ["proj needs one record" ~]]
8834+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) [%| ["proj needs an expected record type" ~]]
8835+ =/ value=iresult (infer-proj-source i.args.e expected env state context)
8836+ ?: ?=(%| -.value) value
8837+ =/ shape=(unit [source=iwfields target=iwfields])
8838+ (width-proj-shape typ.p.value expected sub.state.p.value)
8839+ ?~ shape [%| ["proj needs a known record containing its expected fields" ~]]
8840+ =/ project=(unit iwidth-result) (width-project u.shape sub.state.p.value next.state.p.value)
8841+ ?~ project [%| ["proj constraint needs unsupported inference" ~]]
8842+ =/ st=istate state.p.value(sub sub.u.project, next next.u.project)
8843+ [%& expected st(projections [[at.e e typ.p.value expected steps.u.project] projections.st])]
8844+::
8845+:: A known literal singleton in a direct union can contextualize a
8846+:: loobean literal of the same noun. Only explicit singleton and cell
8847+:: competitors are considered; opaque or variable cases stay unknown.
8848+++ explicit-singleton-in-union
8849+ |= [t=itype noun=@]
8850+ ^- ?
8851+ ?. ?=(%union -.t) |
8852+ =/ cases=(list itype) cases.t
8853+ =/ found=? |
8854+ |-
8855+ ?~ cases found
8856+ =/ c=itype i.cases
8857+ ?: ?=(%cell -.c) $(cases t.cases)
8858+ ?. ?=(%const -.c) |
8859+ ?: =(noun val.literal.c)
8860+ ?: found |
8861+ $(cases t.cases, found &)
8862+ $(cases t.cases)
8863+::
8864+:: Select a written literal-headed case only when every competing case is
8865+:: also an explicit singleton-headed cell and exactly one matches. Opaque,
8866+:: variable-bound and differently shaped cases keep inference unchanged.
8867+:: This first slice supplies context to a directly called payload. Plain
8868+:: literal data and other expressions retain their existing inference path.
8869+++ contextual-atomic-arguments
8870+ |= args=(list expr)
8871+ ^- ?
8872+ ?~ args &
8873+ ?. ?=(?(%lit %wing %ctor) -.i.args) |
8874+ $(args t.args)
8875+++ contextual-direct-payload-call
8876+ |= e=expr
8877+ ^- ?
8878+ ?: ?=(%group -.e) $(e inner.e)
8879+ ?. ?=(%call -.e) |
8880+ ?. ?=(%wing -.head.e) |
8881+ ?~ args.e |
8882+ (contextual-atomic-arguments args.e)
8883+::
8884+:: A walked variable may have concealed a union inside a substituted
8885+:: structure before this arm was called. Decline in that case rather than
8886+:: deriving provenance from the already-walked type.
8887+++ contextual-simple-sub
8888+ |= sub=isub
8889+ ^- ?
8890+ ?~ sub &
8891+ ?: ?=(?(%cell %face %fn %union %collection) -.val.i.sub) |
8892+ $(sub t.sub)
8893+::
8894+:: Check the syntactic root before scanning; scan substitutions once.
8895+++ grec-direct-context
8896+ |= [expected=itype sub=isub]
8897+ ^- ?
8898+ =/ left=@ud 4.096
8899+ |-
8900+ ?: ?=(%face -.expected)
8901+ ?: =(0 left) |
8902+ $(expected body.expected, left (dec left))
8903+ ?. ?=(%grec -.expected) |
8904+ ?~ sub &
8905+ ?: =(0 left) |
8906+ ?: ?=(?(%cell %face %fn %union %collection %grec) -.val.i.sub) |
8907+ $(sub t.sub, left (dec left))
8908+++ contextual-direct-union
8909+ |= target=itype
8910+ ^- ?
8911+ ?: ?=(%face -.target) $(target body.target)
8912+ ?=(%union -.target)
8913+++ contextual-tagged-case
8914+ |= [target=itype tag=@ sub=isub]
8915+ ^- (unit itype)
8916+ ?. ?=(%union -.target) ~
8917+ =/ remaining=(list itype) cases.target
8918+ =/ found=(unit itype) ~
8919+ =/ seen=(set @) *(set @)
8920+ |-
8921+ ?~ remaining found
8922+ =/ c=itype i.remaining
8923+ ?. ?=(%cell -.c) ~
8924+ =/ head=itype hed.c
8925+ ?. ?=(%const -.head) ~
8926+ ?: (~(has in:..zuse seen) val.literal.head) ~
8927+ =. seen (~(put in:..zuse seen) val.literal.head)
8928+ ?: =(tag val.literal.head)
8929+ $(remaining t.remaining, found `c)
8930+ $(remaining t.remaining)
71258931::
71268932++ infer-call-context-arg
71278933 |= [e=expr expected=itype env=ienv state=istate context=span]
71288934 ^- iresult
8935+ ?: ?=(%pair -.e) $(e (pair-as-cell e))
8936+ ?: ?=(%group -.e) $(e inner.e)
8937+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
8938+ ?: ?=(%trace -.e)
8939+ =/ traced=iresult (infer-fragment val.e env state)
8940+ ?: ?=(%| -.traced) traced
8941+ $(e then.e, state state.p.traced)
71298942 =/ target=itype (itype-walk expected sub.state)
71308943 |-
71318944 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
8945+ ?: (explicit-proj-call e env state)
8946+ (infer-proj-context e expected env state context)
8947+ :: Experimental construction only for a source-proven direct target.
8948+ :: Decline any walked structural binding to retain raw-variable provenance.
8949+ ?: &(?=(%grec -.target) ?=(%tuple -.e) (grec-direct-context expected sub.state))
8950+ =/ unfolded=(unit [view=itype left=@ud]) (grec-unfold-view target jrec-fuel.state)
8951+ ?~ unfolded [%| ["recursive mold unfolding needs unsupported inference" ~]]
8952+ ?~ items.e [%| ["recursive mold constructor needs unsupported inference" ~]]
8953+ =/ first=item i.items.e
8954+ ?. &(?=(~ face.first) ?=(%lit -.val.first) =(%term form.lit.val.first))
8955+ [%| ["recursive mold constructor needs unsupported inference" ~]]
8956+ =/ chosen=(unit itype) (contextual-tagged-case view.u.unfolded val.lit.val.first sub.state)
8957+ ?~ chosen [%| ["recursive mold constructor has no matching case" ~]]
8958+ =/ value=iresult (infer-call-context-items items.e u.chosen env state(jrec-fuel left.u.unfolded) context)
8959+ ?: ?=(%| -.value) value
8960+ =/ fit=ifit (itype-fit typ.p.value u.chosen sub.state.p.value next.state.p.value)
8961+ ?: ?=(%unknown -.fit) [%| ["recursive mold case needs unsupported inference" ~]]
8962+ ?: ?=(%bad -.fit) [%| ["recursive mold case does not fit its source shape" ~]]
8963+ [%& target state.p.value(sub sub.fit, next next.fit)]
8964+ :: Only the source-proven one-layer cell is exposed. Each recursive
8965+ :: descent consumes one written tuple; named values use ordinary fit.
8966+ ?: &(?=(%jrec -.target) ?=(%lit -.e) =(%null form.lit.e))
8967+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8968+ [%& target state(jrec-fuel (dec jrec-fuel.state))]
8969+ ?: &(?=(%jrec -.target) ?=(%tuple -.e))
8970+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8971+ =. state state(jrec-fuel (dec jrec-fuel.state))
8972+ =/ shape=itype
8973+ [%cell [%face head.target [%atom aura.target]] [%face tail.target target]]
8974+ =/ value=iresult (infer-call-context-items items.e shape env state context)
8975+ ?: ?=(%| -.value) value
8976+ =/ fit=ifit (itype-fit typ.p.value shape sub.state.p.value next.state.p.value)
8977+ ?: ?=(%unknown -.fit) [%| ["recursive mold cell constraint needs unsupported inference" ~]]
8978+ ?: ?=(%bad -.fit) [%| ["recursive mold cell does not fit its source shape" ~]]
8979+ [%& target state.p.value(sub sub.fit, next next.fit)]
8980+ ?: ?=(%call -.e) (infer-contextual-call e target env state)
8981+ ?: (single-structured-pattern e)
8982+ ?> ?=(%branch -.e)
8983+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8984+ ?^ single (infer-known-union-context-subject e target env u.single context)
8985+ (infer-single-case-branch e env state `[target context])
8986+ ?: (cell-binder-pattern e)
8987+ (infer-cell-branch e env state `[target context])
8988+ :: In an explicit singleton context retain the written loobean noun;
8989+ :: the ordinary singleton fit compares its noun, not its spelling.
8990+ =/ singleton=(unit itype)
8991+ ?. ?=(%lit -.e) ~
8992+ ?. =(%loobean form.lit.e) ~
8993+ ?. |(?=(%const -.target) &(?=(%union -.expected) (explicit-singleton-in-union expected val.lit.e))) ~
8994+ `[%const lit.e]
8995+ ?^ singleton [%& u.singleton state]
8996+ =/ known=(unit iresult)
8997+ ?: ?=(%branch -.e) (known-union-subject subject.e env state)
8998+ ~
8999+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
9000+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
9001+ (infer-known-union-context-subject e target env u.known context)
9002+ ?: &(?=(%union -.target) ?=(%unit -.e))
9003+ (infer-unit-context e target env state context)
9004+ ?: &(?=(%flag -.target) (context-union-branch e))
9005+ (infer-union-context e target env state context)
71329006 ?: &(?=(%union -.target) (context-union-branch e))
71339007 (infer-union-context e target env state context)
71349008 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
71359009 (infer-union-context e target env state context)
71369010 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
71379011 (infer-list-context e target env state context)
9012+ :: A literal-headed tuple can receive the unique case's payload
9013+ :: context. The ordinary final fit still checks the complete union.
9014+ =/ selected=(unit itype)
9015+ ?. &((contextual-simple-sub sub.state) (contextual-direct-union expected) ?=(%union -.target) ?=(%tuple -.e) ?=(^ items.e)) ~
9016+ ?~ t.items.e ~
9017+ ?^ t.t.items.e ~
9018+ ?. (contextual-direct-payload-call val.i.t.items.e) ~
9019+ =/ first=item i.items.e
9020+ ?. &(?=(~ face.first) ?=(%lit -.val.first) |(=(%term form.lit.val.first) =(%null form.lit.val.first) =(%loobean form.lit.val.first))) ~
9021+ (contextual-tagged-case target val.lit.val.first sub.state)
9022+ ?^ selected
9023+ ?> ?=(%tuple -.e)
9024+ :: On this bounded shallow-call shape, preserve any inference that
9025+ :: already fits before trying the new contextual path. Neither pass
9026+ :: can recursively select a nested tuple from the atomic arguments.
9027+ =/ ordinary=(unit iresult)
9028+ =/ initial=iresult (infer-fragment e env state)
9029+ ?: ?=(%| -.initial) ~
9030+ =/ fit=ifit (itype-fit typ.p.initial target sub.state.p.initial next.state.p.initial)
9031+ ?. ?=(%ok -.fit) ~
9032+ `initial
9033+ ?^ ordinary u.ordinary
9034+ =/ value=iresult (infer-call-context-items items.e u.selected env state context)
9035+ ?: ?=(%| -.value) value
9036+ =/ fit=ifit (itype-fit typ.p.value u.selected sub.state.p.value next.state.p.value)
9037+ ?: ?=(%unknown -.fit) [%| ["tagged case needs unsupported inference" ~]]
9038+ ?: ?=(%bad -.fit) [%| ["tagged case does not fit its expected type" ~[[context "expected union case"] [(span-of e) "value"]]]]
9039+ [%& typ.p.value state.p.value(sub sub.fit, next next.fit)]
9040+ ?: &(?=(%cell -.target) ?=(%tuple -.e))
9041+ (infer-call-context-items items.e target env state context)
71389042 (infer-fragment e env state)
71399043::
9044+:: Preserve each written face; the final complete sample fit checks faces.
9045+:: A tuple or positional field face belongs to the enclosing sample,
9046+:: not to the expression at that position. A second face, if present,
9047+:: is part of the value's own expected type.
9048+++ projection-field-target
9049+ |= expected=itype
9050+ ^- itype
9051+ ?:(?=(%face -.expected) body.expected expected)
9052+::
9053+++ infer-call-context-items
9054+ |= [items=(list item) expected=itype env=ienv state=istate context=span]
9055+ ^- iresult
9056+ ?~ items [%| ["empty cell is not supported by partial inference" ~]]
9057+ ?~ t.items
9058+ =/ last=iresult (infer-call-context-arg val.i.items (projection-field-target expected) env state context)
9059+ ?: ?=(%| -.last) last
9060+ =/ typ=itype typ.p.last
9061+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9062+ [%& typ state.p.last]
9063+ =/ target=itype (itype-walk expected sub.state)
9064+ |-
9065+ ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9066+ ?. ?=(%cell -.target) (infer-simple-items items env state)
9067+ =/ head=iresult (infer-call-context-arg val.i.items (projection-field-target hed.target) env state context)
9068+ ?: ?=(%| -.head) head
9069+ =/ typ=itype typ.p.head
9070+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9071+ =/ tail=iresult (infer-call-context-items t.items tal.target env state.p.head context)
9072+ ?: ?=(%| -.tail) tail
9073+ [%& [%cell typ typ.p.tail] state.p.tail]
9074+::
71409075++ infer-call-context-args
71419076 |= [args=(list expr) expected=itype env=ienv state=istate context=span]
71429077 ^- iresult
71439078 ?~ args [%| ["call has no argument" ~]]
7144− ?~ t.args (infer-call-context-arg i.args expected env state context)
9079+ ?~ t.args (infer-call-context-arg i.args (projection-field-target expected) env state context)
71459080 =/ target=itype (itype-walk expected sub.state)
71469081 |-
71479082 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
71489083 ?. ?=(%cell -.target)
71499084 (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
7150− =/ head=iresult (infer-call-context-arg i.args hed.target env state context)
9085+ =/ head=iresult (infer-call-context-arg i.args (projection-field-target hed.target) env state context)
71519086 ?: ?=(%| -.head) head
71529087 =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
71539088 ?: ?=(%| -.tail) tail
@@ -7168,11 +9103,55 @@
71689103 ?: ?=(%| -.tail) tail
71699104 [%& [%cell ht typ.p.tail] state.p.tail]
71709105::
7171−:: A single two-binder cell pattern covers every value of a cell type.
7172−:: No other pattern matrix is implemented here.
9106+:: A single all-binder cell pattern covers a known cell spine; the final
9107+:: binder captures the remaining noun. Other pattern matrices stay partial.
9108+::
9109+:: Validate binders before reading the subject, preserving shadow-error
9110+:: precedence. The last binder receives the entire remaining tail.
9111+++ cell-pattern-names
9112+ |= [pats=(list pattern) env=ienv globals=(list term) seen=(list term)]
9113+ ^- (each (list term) @t)
9114+ ?~ pats [%& ~]
9115+ ?. ?=(%bind -.i.pats) [%| 'branch pattern is not supported by partial inference']
9116+ =/ name=term name.i.pats
9117+ ?: |(=(name %proj) ?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
9118+ [%| 'pattern shadows a name']
9119+ =/ rest=(each (list term) @t) $(pats t.pats, seen [name seen])
9120+ ?: ?=(%| -.rest) rest
9121+ [%& [name p.rest]]
9122+::
9123+++ cell-pattern-types
9124+ |= [names=(list term) env=ienv next=@ud]
9125+ ^- [typ=itype env=ienv next=@ud]
9126+ ?~ names !!
9127+ =/ head=itype [%var next]
9128+ =/ scope=ienv [[i.names [head ~]] env]
9129+ ?~ t.names [head scope +(next)]
9130+ =/ tail=[typ=itype env=ienv next=@ud] $(names t.names, env scope, next +(next))
9131+ [[%cell head typ.tail] env.tail next.tail]
9132+::
9133+:: At every position that must be a cell, opaque or sum types may still
9134+:: contain cells. Do not report a definite mismatch without unfolding them.
9135+++ cell-pattern-spine-unknown
9136+ |= [typ=itype names=(list term) sub=isub]
9137+ ^- ?
9138+ ?~ names |
9139+ ?~ t.names |
9140+ =. typ (itype-walk typ sub)
9141+ ?: ?=(%cell -.typ) $(typ tal.typ, names t.names)
9142+ |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%jrec -.typ) ?=(%grec -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9143+::
9144+++ cell-binder-pattern
9145+ |= e=expr
9146+ ^- ?
9147+ ?. ?=(%branch -.e) |
9148+ ?~ arms.e |
9149+ ?^ t.arms.e |
9150+ ?. ?=(%cell -.pat.i.arms.e) |
9151+ !(single-structured-pattern e)
71739152::
71749153++ infer-cell-branch
7175− |= [e=expr env=ienv state=istate]
9154+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
71769155 ^- iresult
71779156 ?> ?=(%branch -.e)
71789157 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -7181,25 +9160,31 @@
71819160 =/ pats=(list pattern) items.pat.arm
71829161 ?~ pats [%| ["branch pattern is not supported by partial inference" ~]]
71839162 ?~ t.pats [%| ["branch pattern is not supported by partial inference" ~]]
7184− ?^ t.t.pats [%| ["branch pattern is not supported by partial inference" ~]]
7185− ?. ?=(%bind -.i.pats) [%| ["branch pattern is not supported by partial inference" ~]]
7186− ?. ?=(%bind -.i.t.pats) [%| ["branch pattern is not supported by partial inference" ~]]
7187− =/ one=term name.i.pats
7188− =/ two=term name.i.t.pats
7189− ?: |(=(one two) ?=(^ (ienv-lookup one env)) ?=(^ (ienv-lookup two env)) (lien globals.state |=(x=term |(=(x one) =(x two)))))
7190− [%| ["pattern shadows a name" ~]]
9163+ =/ names=(each (list term) @t) (cell-pattern-names pats env globals.state ~)
9164+ ?: ?=(%| -.names) [%| [(trip p.names) ~]]
71919165 =/ subject=iresult (infer-fragment subject.e env state)
71929166 ?: ?=(%| -.subject) subject
71939167 =/ st=istate state.p.subject
7194− ?: (itype-has-recursive (itype-normalize typ.p.subject sub.st))
9168+ =/ subject-type=itype (itype-normalize typ.p.subject sub.st)
9169+ ?: (itype-has-recursive subject-type)
71959170 [%| ["recursive pattern is not supported by partial inference" ~]]
71969171 ?: (itype-has-face typ.p.subject sub.st)
71979172 [%| ["record patterns are not supported by partial inference" ~]]
7198− =/ head=itype [%var next.st]
7199− =/ tail=itype [%var +(next.st)]
7200− =/ sub=(unit isub) (itype-unify typ.p.subject [%cell head tail] sub.st)
9173+ ?: (cell-pattern-spine-unknown subject-type p.names sub.st)
9174+ [%| ["cell pattern subject is not supported by partial inference" ~]]
9175+ =/ binders=[typ=itype env=ienv next=@ud] (cell-pattern-types p.names env next.st)
9176+ =/ sub=(unit isub) (itype-unify typ.p.subject typ.binders sub.st)
72019177 ?~ sub [%| ["cell pattern does not match the subject type" ~]]
7202− (infer-fragment val.arm [[one [head ~]] [two [tail ~]] env] st(next (add 2 next.st), sub u.sub))
9178+ =. st st(next next.binders, sub u.sub)
9179+ ?~ expected (infer-fragment val.arm env.binders st)
9180+ =/ body=iresult (infer-call-context-arg val.arm typ.u.expected env.binders st context.u.expected)
9181+ ?: ?=(%| -.body) body
9182+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
9183+ ?: ?=(%unknown -.fit) [%| ["cell branch result constraint is not supported by partial inference" ~]]
9184+ ?: ?=(%bad -.fit) [%| ["cell branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.arm) "branch arm"]]]]
9185+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
9186+ [%| ["cell branch result needs context in partial inference" ~]]
9187+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
72039188::
72049189++ show-itype
72059190 |= [t=itype sub=isub]
@@ -7212,12 +9197,19 @@
72129197 %avar
72139198 ?: (lth id.t 26) [(add 65 id.t) ~]
72149199 "T{<id.t>}"
9200+ %rvar
9201+ ?: (lth id.t 26) [(add 65 id.t) ~]
9202+ "T{<id.t>}"
72159203 %nvar
72169204 ?: (lth id.t 26) [(add 65 id.t) ~]
72179205 "T{<id.t>}"
9206+ %rnvar
9207+ ?: (lth id.t 26) [(add 65 id.t) ~]
9208+ "T{<id.t>}"
72189209 %atom "@{(trip aura.t)}"
72199210 %any-atom "@"
72209211 %flag "?"
9212+ %noun "*"
72219213 %tag (trip txt.literal.t)
72229214 %const (trip txt.literal.t)
72239215 %union
@@ -7225,6 +9217,8 @@
72259217 ?~ args.t (trip u.label.t)
72269218 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
72279219 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9220+ %jrec ?~(label.t "recursive mold" (trip u.label.t))
9221+ %grec ?~(label.t "recursive mold" "({(trip u.label.t)} {(show-itype-cases args.t sub)})")
72289222 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
72299223 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
72309224 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
@@ -7260,15 +9254,20 @@
72609254 ^- ?
72619255 ?- -.typ
72629256 %nvar &
9257+ %rnvar &
72639258 %var |
72649259 %avar |
9260+ %rvar |
72659261 %atom |
72669262 %any-atom |
72679263 %flag |
9264+ %noun |
72689265 %tag |
72699266 %const |
72709267 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
72719268 %recursive |
9269+ %jrec |
9270+ %grec (lien args.typ |=(c=itype (itype-has-nvar c)))
72729271 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
72739272 %face $(typ body.typ)
72749273 %fn |($(typ sample.typ) $(typ product.typ))
@@ -7279,7 +9278,7 @@
72799278 |= [label=tape typ=itype sub=isub]
72809279 ^- tape
72819280 =/ normalized=itype (itype-normalize typ sub)
7282− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
9281+ ?: |(?=(%var -.normalized) ?=(%avar -.normalized) ?=(%rvar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
72839282 ?: (itype-has-hidden-recursive normalized) label
72849283 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
72859284 ?: (gth (lent vars) 26) label
@@ -7301,6 +9300,7 @@
73019300 ?+ -.resolved ~
73029301 %var `id.resolved
73039302 %avar `id.resolved
9303+ %rvar `id.resolved
73049304 ==
73059305 ?~ ident $(caps t.caps)
73069306 ?: =(n u.ident) &
@@ -7315,6 +9315,7 @@
73159315 ?+ -.resolved ~
73169316 %var `id.resolved
73179317 %avar `id.resolved
9318+ %rvar `id.resolved
73189319 ==
73199320 ?~ ident $(caps t.caps)
73209321 ?: =(n u.ident) `i.caps
@@ -7329,6 +9330,7 @@
73299330 ?+ -.resolved ~
73309331 %var `id.resolved
73319332 %avar `id.resolved
9333+ %rvar `id.resolved
73329334 ==
73339335 ?~ ident $(caps t.caps)
73349336 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
@@ -7344,6 +9346,7 @@
73449346 ?+ -.resolved ~
73459347 %var `id.resolved
73469348 %avar `id.resolved
9349+ %rvar `id.resolved
73479350 ==
73489351 ?~ ident &
73499352 ?: (cap-id-in u.ident t.caps sub) &
@@ -7358,8 +9361,8 @@
73589361 ^- ?
73599362 ?~ caps |
73609363 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
7361− ?: ?=(%avar -.resolved)
7362− ?: =(n id.resolved) &
9364+ ?: |(?=(%avar -.resolved) ?=(%rvar -.resolved))
9365+ ?: =(n +.resolved) &
73639366 $(caps t.caps)
73649367 $(caps t.caps)
73659368::
@@ -7369,14 +9372,19 @@
73699372 ?- -.t
73709373 %var |
73719374 %avar =(n id.t)
9375+ %rvar =(n id.t)
73729376 %nvar |
9377+ %rnvar |
73739378 %atom |
73749379 %any-atom |
73759380 %flag |
9381+ %noun |
73769382 %tag |
73779383 %const |
73789384 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
73799385 %recursive |
9386+ %jrec |
9387+ %grec (lien args.t |=(c=itype (has-atom-var n c)))
73809388 %collection (lien args.t |=(c=itype (has-atom-var n c)))
73819389 %face $(t body.t)
73829390 %fn |($(t sample.t) $(t product.t))
@@ -7416,6 +9424,10 @@
74169424 =/ out=tape ""
74179425 |-
74189426 ?~ vars out
9427+ ?: (itype-var-is-restricted i.vars t)
9428+ =/ sep=tape ?:(printed ", " " where ")
9429+ =/ clause=tape "{sep}{(show-itype [%rvar i.vars] ~)} is an atom other than ?"
9430+ $(vars t.vars, printed &, out (weld out clause))
74199431 ?: (itype-var-is-atom i.vars t)
74209432 =/ sep=tape ?:(printed ", " " where ")
74219433 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
@@ -7424,9 +9436,9 @@
74249436::
74259437:: Build the supported part of the value environment in dependency order.
74269438:: Each pass adds successful definitions. Forward references become
7427−:: available on a later pass; mutually recursive groups and unsupported
7428−:: syntax do not enter the environment. Generalized definitions are closed, so a
7429−:: use instantiates its variables afresh.
9439+:: available on a later pass; unsupported syntax does not enter the
9440+:: environment. Generalized definitions are closed, so a use instantiates
9441+:: its variables afresh.
74309442::
74319443++ global-value-names
74329444 |= ds=(list def)
@@ -7516,6 +9528,7 @@
75169528++ infer-recursive-gate
75179529 |= [d=def env=ienv state=istate]
75189530 ^- iresult
9531+ =. gate-defs.state ~
75199532 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
75209533 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
75219534 [%| ["recursive definition is not a gate" ~]]
@@ -7656,9 +9669,9 @@
76569669 * ~
76579670 ==
76589671::
7659−:: Infer a cyclic top-level component with one monomorphic seed per gate.
7660−:: All members must succeed before any scheme is available; local cyclic
7661−:: groups, pending constraints and unresolved branch joins remain partial.
9672+:: Infer a cyclic component with one monomorphic seed per gate. All members
9673+:: must succeed before any scheme is available; pending constraints and
9674+:: unresolved branch joins remain partial.
76629675+$ igate-entry [name=term typ=itype body=expr env=ienv caps=icaps]
76639676+$ igate-seeds (each [entries=(list igate-entry) state=istate] idiag)
76649677++ seed-gate-group
@@ -7725,6 +9738,7 @@
77259738 ?: (constrained-capitals caps.entry sub.state)
77269739 [%| ["explicit capital constraints are not supported by partial inference" ~]]
77279740 =/ typ=itype (itype-normalize typ.entry sub.state)
9741+ ?: (itype-has-nvar typ) [%| ["recursive group needs unsupported inference" ~]]
77289742 ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
77299743 [%| ["recursive group needs unsupported inference" ~]]
77309744 =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
@@ -7743,41 +9757,46 @@
77439757 [%| ["recursive group contains duplicate names" ~]]
77449758 ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
77459759 [%| ["recursive group shadows a name" ~]]
7746− =/ scoped=istate state(globals (weld names globals.state))
9760+ =/ scoped=istate state(globals (weld names globals.state), gate-defs ~)
77479761 =/ seeded=igate-seeds (seed-gate-group ds env scoped)
77489762 ?: ?=(%| -.seeded) seeded
77499763 =/ seeds=ienv (group-seed-env entries.p.seeded ~)
77509764 =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
77519765 ?: ?=(%| -.body) body
9766+ :: Per-member ownership through mutual recursion is not implemented.
9767+ ?: !=(projections.state.p.body projections.state)
9768+ [%| ["record projection in recursive groups needs unsupported inference" ~]]
9769+ ?: !=(holes.state.p.body holes.state)
9770+ [%| ["holes in recursive groups need unsupported inference" ~]]
77529771 ?: (pending-tags tags.state.p.body sub.state.p.body)
77539772 [%| ["recursive group has unresolved literal constraints" ~]]
77549773 =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
77559774 ?: ?=(%| -.schemes) schemes
77569775 [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
77579776::
9777+++ width-finalize
9778+ |= [ps=(list iwprojection) sub=isub visible=(list @ud)]
9779+ ^- (unit (list iwprojection))
9780+ ?~ ps `~
9781+ ?: (lien t.ps |=(p=iwprojection =(at.p at.i.ps))) ~
9782+ =/ src=itype (default-decimals (itype-normalize source.i.ps sub))
9783+ =/ dst=itype (default-decimals (itype-normalize target.i.ps sub))
9784+ ?: |((itype-has-nvar src) (itype-has-nvar dst) (itype-has-tag src) (itype-has-tag dst)) ~
9785+ =/ vars=(list @ud) (weld (itype-vars src) (itype-vars dst))
9786+ ?. (levy vars |=(n=@ud (lien visible |=(v=@ud =(n v))))) ~
9787+ =/ rest=(unit (list iwprojection)) $(ps t.ps)
9788+ ?~ rest ~
9789+ =/ entry=iwprojection i.ps
9790+ =. entry entry(source src, target dst)
9791+ `[entry u.rest]
9792+::
77589793++ add-supported-defs
7759− |= [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)]
7760− ^- ienv
7761− ?~ ds env
7762− =/ d=def i.ds
7763− ?: ?=(%mold -.d) $(ds t.ds)
7764− ?. (unique-value-name name.d globals) $(ds t.ds)
7765− ?^ (ienv-lookup name.d env) $(ds t.ds)
7766− =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7767− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
7768− =. initial (reserve-def-caps val.d initial)
7769− =/ result=iresult (infer-fragment val.d env initial)
7770− =? result ?=(%| -.result) (infer-recursive-gate d env initial)
7771− ?: ?=(%| -.result) $(ds t.ds)
7772− ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
7773− =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
7774− ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
7775− ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
7776− =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
7777− ?: (gth (lent vars) 26) $(ds t.ds)
7778− $(ds t.ds, env [[name.d [typ vars]] env])
9794+ |= [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)]
9795+ ^- [env=ienv artifacts=(list iwidth-definition)]
9796+ (add-supported-defs-core ds all-defs checked heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts ~)
77799797::
7780−+$ iresolved [env=ienv grouped=(list term)]
9798+
9799++$ iresolved [env=ienv grouped=(list term) artifacts=(list iwidth-definition)]
77819800+$ iadj (map term (list term))
77829801+$ ivisited (map term ?)
77839802+$ iwork (list [name=term done=?])
@@ -7871,9 +9890,9 @@
78719890 (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
78729891::
78739892++ add-groups
7874− |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) state=istate]
9893+ |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) artifacts=(list iwidth-definition) state=istate]
78759894 ^- iresolved
7876− ?~ components [env grouped]
9895+ ?~ components [env grouped artifacts]
78779896 =/ component=(list term) i.components
78789897 ?. (graph-cycle component graph) $(components t.components)
78799898 ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
@@ -7890,25 +9909,186 @@
78909909++ resolve-groups
78919910 |= [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)]
78929911 ^- iresolved
9912+ (resolve-groups-core ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude ~)
9913+::
9914+
9915+++ add-supported-defs-core
9916+ |= [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)])]
9917+ ^- [env=ienv artifacts=(list iwidth-definition)]
9918+ ?~ ds [env artifacts]
9919+ =/ d=def i.ds
9920+ ?: ?=(%mold -.d) $(ds t.ds)
9921+ ?. (unique-value-name name.d globals) $(ds t.ds)
9922+ ?^ (ienv-lookup name.d env) $(ds t.ds)
9923+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
9924+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~]
9925+ =. grec-index.initial index
9926+ =. gate-defs.initial checked
9927+ =. head-evidence.initial heads
9928+ =. initial (reserve-def-caps val.d initial)
9929+ =/ result=iresult (infer-fragment val.d env initial)
9930+ =? result ?=(%| -.result) (infer-recursive-gate d env initial)
9931+ ?: ?=(%| -.result) $(ds t.ds)
9932+ =. state.p.result (promote-restricted-numbers state.p.result env)
9933+ =. 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)))
9934+ ?^ (unresolved-hole holes.state.p.result holes.initial state.p.result) $(ds t.ds)
9935+ ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
9936+ =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
9937+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
9938+ ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
9939+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
9940+ ?: (gth (lent vars) 26) $(ds t.ds)
9941+ =/ finalized=(unit (list iwprojection))
9942+ (width-finalize projections.state.p.result sub.state.p.result vars)
9943+ ?~ finalized $(ds t.ds)
9944+ =? artifacts ?=(^ u.finalized)
9945+ [[name.d val.d typ sub.state.p.result (flop u.finalized)] artifacts]
9946+ =? checked |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) (~(put by checked) name.d d)
9947+ $(ds t.ds, env [[name.d [typ vars]] env], checked checked)
9948+::
9949+++ resolve-groups-core
9950+ |= [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)])]
9951+ ^- iresolved
78939952 =/ env=ienv ~
78949953 =/ grouped=(list term) ~
9954+ =/ artifacts=(list iwidth-definition) ~
78959955 =/ names=(list term) (global-value-names ds)
78969956 =/ nameset=ivisited (graph-nameset names ~)
78979957 =/ graph=iadj (graph-make-forward ds nameset ~)
78989958 =/ components=icomponents (graph-components ds names)
78999959 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
9960+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
79009961 |-
7901− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
7902− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
7903− =/ out=iresolved (add-groups ds components graph next grouped initial)
9962+ =/ next=[env=ienv artifacts=(list iwidth-definition)]
9963+ (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)
9964+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~]
9965+ =. grec-index.initial index
9966+ =/ out=iresolved (add-groups ds components graph env.next grouped artifacts.next initial)
79049967 ?: =(env env.out) out
7905− $(env env.out, grouped grouped.out)
9968+ $(env env.out, grouped grouped.out, artifacts artifacts.out)
79069969::
79079970++ resolve-supported-defs
79089971 |= [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)]
79099972 ^- ienv
79109973 env:(resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
79119974::
9975+:: A diagnostic-only proof for a narrow syntactic value cycle. Every
9976+:: edge is an unqualified wing in a supported expression, and samples
9977+:: may not shadow global bindings. Unknown forms yield no conclusion.
9978++$ icyclesite [name=term at=span]
9979++$ icycle [name=term first=span next=span]
9980+++ cycle-sites-list
9981+ |= [xs=(list expr) globals=(list term) locals=(list term)]
9982+ ^- (unit (list icyclesite))
9983+ ?~ xs `~
9984+ =/ first=(unit (list icyclesite)) (cycle-sites i.xs globals locals)
9985+ ?~ first ~
9986+ =/ tail=(unit (list icyclesite)) $(xs t.xs)
9987+ ?~ tail ~
9988+ `(weld u.first u.tail)
9989+::
9990+++ cycle-sample-name
9991+ |= [sam=sample globals=(list term) locals=(list term)]
9992+ ^- (unit (unit term))
9993+ ?- -.sam
9994+ %bind
9995+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
9996+ ``name.sam
9997+ %face
9998+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
9999+ ``name.sam
10000+ %bare `~
10001+ * ~
10002+ ==
10003+::
10004+++ cycle-sites
10005+ |= [e=expr globals=(list term) locals=(list term)]
10006+ ^- (unit (list icyclesite))
10007+ ?- -.e
10008+ %wing
10009+ ?. ?=([@ ~] names.e) ~
10010+ `~[[i.names.e at.e]]
10011+ %lit `~
10012+ %str
10013+ ?: (lien pieces.e |=(p=piece ?=(%expr -.p))) ~
10014+ `~
10015+ %group $(e inner.e)
10016+ %body ?~(defs.e $(e final.e) ~)
10017+ %cast $(e val.e)
10018+ %gate
10019+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10020+ ?~ binder ~
10021+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10022+ $(e body.e, locals nested)
10023+ %gate-wide
10024+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10025+ ?~ binder ~
10026+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10027+ $(e body.e, locals nested)
10028+ %call
10029+ =/ first=(unit (list icyclesite)) $(e head.e)
10030+ ?~ first ~
10031+ =/ tail=(unit (list icyclesite)) (cycle-sites-list args.e globals locals)
10032+ ?~ tail ~
10033+ `(weld u.first u.tail)
10034+ * ~
10035+ ==
10036+::
10037+++ cycle-definitely-atom
10038+ |= e=expr
10039+ ^- ?
10040+ ?: ?=(%group -.e) $(e inner.e)
10041+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
10042+ ?. ?=(%cast -.e) |
10043+ |(?=(%aura -.shape.e) ?=(%flag -.shape.e))
10044+::
10045+++ cycle-proof-group
10046+ |= [members=(list def) globals=(list term)]
10047+ ^- ?
10048+ ?~ members &
10049+ ?. ?=(%value -.i.members) |
10050+ ?. (unique-value-name name.i.members globals) |
10051+ ?. ?=(^ (cycle-sites val.i.members globals ~)) |
10052+ $(members t.members)
10053+::
10054+++ cycle-find-site
10055+ |= [sites=(list icyclesite) component=(list term)]
10056+ ^- (unit span)
10057+ ?~ sites ~
10058+ ?: (lien component |=(n=term =(n name.i.sites))) `at.i.sites
10059+ $(sites t.sites)
10060+::
10061+++ cycle-group-errors
10062+ |= [members=(list def) component=(list term) globals=(list term)]
10063+ ^- (list icycle)
10064+ ?~ members ~
10065+ =/ d=def i.members
10066+ ?> ?=(%value -.d)
10067+ =/ tail=(list icycle) $(members t.members)
10068+ ?. (cycle-definitely-atom val.d) tail
10069+ =/ sites=(unit (list icyclesite)) (cycle-sites val.d globals ~)
10070+ ?~ sites tail
10071+ =/ found=(unit span) (cycle-find-site u.sites component)
10072+ ?~ found tail
10073+ [[name.d at.d u.found] tail]
10074+::
10075+++ definite-value-cycles
10076+ |= [ds=(list def) globals=(list term)]
10077+ ^- (list icycle)
10078+ =/ names=(list term) (global-value-names ds)
10079+ =/ graph=iadj (graph-make-forward ds (graph-nameset names ~) ~)
10080+ =/ components=icomponents (graph-components ds names)
10081+ =/ out=(list icycle) ~
10082+ |-
10083+ ?~ components out
10084+ =/ component=(list term) i.components
10085+ ?. (graph-cycle component graph) $(components t.components)
10086+ =/ members=(list def)
10087+ (skim ds |=(d=def &(?=(%value -.d) (lien component |=(n=term =(n name.d))))))
10088+ ?. =((lent members) (lent component)) $(components t.components)
10089+ ?. (cycle-proof-group members globals) $(components t.components)
10090+ $(components t.components, out (weld (cycle-group-errors members component globals) out))
10091+::
791210092+| %union-analysis
791310093::
791410094:: A conservative projection of written molds onto noun shapes. The
@@ -8044,11 +10224,142 @@
804410224 [at.first at.second (union-relate a (project-union-mold second molds ~))]
804510225 (weld pairs $(cases t.cases))
804610226::
10227+:: A closed structural mold supplies no equation to determine a hole.
10228+:: Applications, references, unbound capitals and unions are unproved.
10229+++ simple-mold-hole
10230+ |= sh=shape
10231+ ^- (unit (unit span))
10232+ ?: ?=(%generic -.sh)
10233+ ?~ vars.sh ~
10234+ ?. (distinct-params vars.sh) ~
10235+ (simple-mold-hole-in body.sh vars.sh)
10236+ (simple-mold-hole-in sh ~)
10237+++ simple-mold-hole-in
10238+ |= [sh=shape vars=(list @t)]
10239+ ^- (unit (unit span))
10240+ ?- -.sh
10241+ %hole ``at.sh
10242+ ?(%aura %noun %void %flag %const) `~
10243+ %tvar ?:((lien vars |=(v=@t =(v name.sh))) `~ ~)
10244+ %cell (simple-mold-field-holes fields.sh vars)
10245+ %fn
10246+ =/ a=(unit (unit span)) $(sh sample.sh)
10247+ ?~ a ~
10248+ =/ b=(unit (unit span)) $(sh product.sh)
10249+ ?~ b ~
10250+ `?~(u.a u.b u.a)
10251+ %generic ~
10252+ * ~
10253+ ==
10254+++ simple-mold-field-holes
10255+ |= [fields=(list field) vars=(list @t)]
10256+ ^- (unit (unit span))
10257+ ?~ fields `~
10258+ =/ f=field i.fields
10259+ =/ first=(unit (unit span))
10260+ ?- -.f
10261+ %face (simple-mold-hole-in shape.f vars)
10262+ %bare (simple-mold-hole-in shape.f vars)
10263+ %pun ~
10264+ ==
10265+ ?~ first ~
10266+ =/ rest=(unit (unit span)) $(fields t.fields)
10267+ ?~ rest ~
10268+ `?~(u.first u.rest u.first)
10269+++ simple-local-mold-hole
10270+ |= defs=(list def)
10271+ ^- (unit span)
10272+ ?~ defs ~
10273+ ?. ?=(%mold -.i.defs) $(defs t.defs)
10274+ =/ found=(unit (unit span)) (simple-mold-hole shape.i.defs)
10275+ ?~ found $(defs t.defs)
10276+ ?^ u.found u.found
10277+ $(defs t.defs)
10278+::
10279+:: A partial prelude may omit unsupported declarations, but may not
10280+:: publish an interface while a named mold's hole remains unchecked.
10281+++ shape-has-hole
10282+ |= sh=shape
10283+ ^- ?
10284+ ?- -.sh
10285+ %hole &
10286+ %path (lien segs.sh |=(s=pseg ?=(%inferred -.s)))
10287+ %apply (lien args.sh shape-has-hole)
10288+ %union (lien cases.sh shape-has-hole)
10289+ %cell (lien fields.sh field-has-hole)
10290+ %fn |($(sh sample.sh) $(sh product.sh))
10291+ %generic $(sh body.sh)
10292+ * |
10293+ ==
10294+++ field-has-hole
10295+ |= f=field
10296+ ^- ?
10297+ ?- -.f
10298+ %face (shape-has-hole shape.f)
10299+ %bare (shape-has-hole shape.f)
10300+ %pun |
10301+ ==
10302+++ named-mold-has-hole
10303+ |= ds=(list def)
10304+ ^- ?
10305+ ?~ ds |
10306+ ?: &(?=(%mold -.i.ds) (shape-has-hole shape.i.ds)) &
10307+ $(ds t.ds)
10308+::
10309+++ sample-has-hole
10310+ |= sam=sample
10311+ ^- ?
10312+ ?- -.sam
10313+ %face (shape-has-hole shape.sam)
10314+ %bare (shape-has-hole shape.sam)
10315+ %cell (lien items.sam sample-has-hole)
10316+ * |
10317+ ==
10318+++ def-has-hole
10319+ |= d=def
10320+ ^- ?
10321+ ?- -.d
10322+ %mold (shape-has-hole shape.d)
10323+ %value (expr-has-hole val.d)
10324+ ==
10325+++ expr-has-hole
10326+ |= e=expr
10327+ ^- ?
10328+ ?- -.e
10329+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10330+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10331+ %change (lien edits.e |=(p=edit (expr-has-hole val.p)))
10332+ %pair $(e val.e)
10333+ %unit $(e val.e)
10334+ %group $(e inner.e)
10335+ %list (lien items.e expr-has-hole)
10336+ %tuple (lien items.e |=(i=item (expr-has-hole val.i)))
10337+ ?(%gate %gate-wide) |((sample-has-hole sample.e) $(e body.e))
10338+ %cast |((shape-has-hole shape.e) $(e val.e))
10339+ %call |($(e head.e) (lien args.e expr-has-hole))
10340+ %trace |($(e val.e) $(e then.e))
10341+ %branch |($(e subject.e) (lien arms.e |=(a=arm (expr-has-hole val.a))))
10342+ %body |((lien defs.e def-has-hole) $(e final.e))
10343+ * |
10344+ ==
10345+++ hole-values-present
10346+ |= [ds=(list def) env=ienv]
10347+ ^- ?
10348+ ?~ ds &
10349+ ?. ?=(%value -.i.ds) $(ds t.ds)
10350+ ?: (expr-has-hole val.i.ds)
10351+ ?. ?=(^ (ienv-lookup name.i.ds env)) |
10352+ $(ds t.ds)
10353+ $(ds t.ds)
804710354++ show-partial-mold
804810355 |= [file=path src=@t d=def molds=imolds]
804910356 ^- @t
805010357 ?> ?=(%mold -.d)
805110358 =/ sh=shape shape.d
10359+ =/ hole=(unit (unit span)) (simple-mold-hole sh)
10360+ ?: &(?=(^ hole) ?=(^ u.hole))
10361+ =/ text=@t (show-error src [file line.beg.u.u.hole col.beg.u.u.hole "unresolved type hole"])
10362+ (of-wain:format ~[(crip "+$ {(trip name.d)}: type hole needs a determined type") text])
805210363 =? sh ?=(%generic -.sh) body.sh
805310364 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
805410365 =/ pairs=(list upair) (union-pairs cases.sh molds)
@@ -8075,6 +10386,21 @@
807510386 (show-error src [file line.beg.at.site col.beg.at.site note.site])
807610387 (of-wain:format [summary excerpts])
807710388::
10389+:: Both written field sites are shown in the source that declares them.
10390+++ show-duplicate-fields
10391+ |= [file=path src=@t diagnostic=idiag]
10392+ ^- @t
10393+ =/ excerpts=(list @t)
10394+ %+ turn sites.diagnostic
10395+ |= site=[at=span note=tape]
10396+ (show-error src [file line.beg.at.site col.beg.at.site note.site])
10397+ (of-wain:format [(crip msg.diagnostic) excerpts])
10398+::
10399+++ duplicate-fields-report
10400+ |= [file=path src=@t diagnostic=idiag]
10401+ ^- @t
10402+ (of-wain:format ~['partial inference; module not checked' (show-duplicate-fields file src diagnostic)])
10403+::
807810404:: +golden-types: a partial report; it does not claim the module checks
807910405::
808010406++ golden-types
@@ -8104,6 +10430,180 @@
810410430+$ jfile-result (each [iface=ifile cache=jcache] @t)
810510431+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
810610432::
10433+:: Written record fields each have their own lexical record scope.
10434++$ written-fields (map term span)
10435+++ duplicate-written-field
10436+ |= [name=term at=span seen=written-fields]
10437+ ^- (unit idiag)
10438+ =/ prior=(unit span) (~(get by seen) name)
10439+ ?~ prior ~
10440+ `["record field `{(trip name)}` is repeated" ~[[u.prior "first field"] [at "repeated field"]]]
10441+++ duplicate-shapes
10442+ |= xs=(list shape)
10443+ ^- (unit idiag)
10444+ ?~ xs ~
10445+ =/ first (duplicate-shape i.xs)
10446+ ?^ first first
10447+ $(xs t.xs)
10448+++ duplicate-fields
10449+ |= [fields=(list field) seen=written-fields]
10450+ ^- (unit idiag)
10451+ ?~ fields ~
10452+ =/ f=field i.fields
10453+ =/ n=(unit term)
10454+ ?- -.f
10455+ %face `name.f
10456+ %pun `name.f
10457+ %bare ~
10458+ ==
10459+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.f seen))
10460+ ?^ dup dup
10461+ =/ inner=(unit idiag)
10462+ ?- -.f
10463+ %face (duplicate-shape shape.f)
10464+ %pun ~
10465+ %bare (duplicate-shape shape.f)
10466+ ==
10467+ ?^ inner inner
10468+ $(fields t.fields, seen ?~(n seen (~(put by seen) u.n at.f)))
10469+++ duplicate-shape
10470+ |= s=shape
10471+ ^- (unit idiag)
10472+ ?- -.s
10473+ %cell (duplicate-fields fields.s ~)
10474+ %apply (duplicate-shapes args.s)
10475+ %union (duplicate-shapes cases.s)
10476+ %fn
10477+ =/ left (duplicate-shape sample.s)
10478+ ?^ left left
10479+ (duplicate-shape product.s)
10480+ %generic (duplicate-shape body.s)
10481+ * ~
10482+ ==
10483+++ duplicate-samples
10484+ |= [items=(list sample) seen=written-fields]
10485+ ^- (unit idiag)
10486+ ?~ items ~
10487+ =/ a=sample i.items
10488+ =/ n=(unit term)
10489+ ?- -.a
10490+ %bind `name.a
10491+ %face `name.a
10492+ %pun `name.a
10493+ * ~
10494+ ==
10495+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.a seen))
10496+ ?^ dup dup
10497+ =/ inner (duplicate-sample a)
10498+ ?^ inner inner
10499+ $(items t.items, seen ?~(n seen (~(put by seen) u.n at.a)))
10500+++ duplicate-sample
10501+ |= s=sample
10502+ ^- (unit idiag)
10503+ ?- -.s
10504+ %cell (duplicate-samples items.s ~)
10505+ %face (duplicate-shape shape.s)
10506+ %bare (duplicate-shape shape.s)
10507+ * ~
10508+ ==
10509+++ duplicate-exprs
10510+ |= xs=(list expr)
10511+ ^- (unit idiag)
10512+ ?~ xs ~
10513+ =/ first (duplicate-expr i.xs)
10514+ ?^ first first
10515+ $(xs t.xs)
10516+++ duplicate-items
10517+ |= [items=(list item) seen=written-fields]
10518+ ^- (unit idiag)
10519+ ?~ items ~
10520+ =/ a=item i.items
10521+ =/ dup=(unit idiag) ?~(face.a ~ (duplicate-written-field u.face.a at.a seen))
10522+ ?^ dup dup
10523+ =/ inner (duplicate-expr val.a)
10524+ ?^ inner inner
10525+ $(items t.items, seen ?~(face.a seen (~(put by seen) u.face.a at.a)))
10526+++ duplicate-pieces
10527+ |= pieces=(list piece)
10528+ ^- (unit idiag)
10529+ ?~ pieces ~
10530+ =/ first=(unit idiag) ?:(?=(%expr -.i.pieces) (duplicate-expr p.i.pieces) ~)
10531+ ?^ first first
10532+ $(pieces t.pieces)
10533+++ duplicate-qsegs
10534+ |= segs=(list qseg)
10535+ ^- (unit idiag)
10536+ ?~ segs ~
10537+ =/ first=(unit idiag) ?:(?=(%expr -.i.segs) (duplicate-expr p.i.segs) ~)
10538+ ?^ first first
10539+ $(segs t.segs)
10540+++ duplicate-edits
10541+ |= edits=(list edit)
10542+ ^- (unit idiag)
10543+ ?~ edits ~
10544+ =/ first (duplicate-expr val.i.edits)
10545+ ?^ first first
10546+ $(edits t.edits)
10547+++ duplicate-arms
10548+ |= arms=(list arm)
10549+ ^- (unit idiag)
10550+ ?~ arms ~
10551+ =/ first (duplicate-expr val.i.arms)
10552+ ?^ first first
10553+ $(arms t.arms)
10554+++ duplicate-defs
10555+ |= defs=(list def)
10556+ ^- (unit idiag)
10557+ ?~ defs ~
10558+ =/ first=(unit idiag)
10559+ ?- -.i.defs
10560+ %mold (duplicate-shape shape.i.defs)
10561+ %value (duplicate-expr val.i.defs)
10562+ ==
10563+ ?^ first first
10564+ $(defs t.defs)
10565+++ duplicate-expr
10566+ |= e=expr
10567+ ^- (unit idiag)
10568+ ?- -.e
10569+ %str (duplicate-pieces pieces.e)
10570+ %qath (duplicate-qsegs segs.e)
10571+ %change (duplicate-edits edits.e)
10572+ %pair (duplicate-expr val.e)
10573+ %unit (duplicate-expr val.e)
10574+ %group (duplicate-expr inner.e)
10575+ %list (duplicate-exprs items.e)
10576+ %tuple (duplicate-items items.e ~)
10577+ %gate-wide
10578+ =/ first (duplicate-sample sample.e)
10579+ ?^ first first
10580+ (duplicate-expr body.e)
10581+ %gate
10582+ =/ first (duplicate-sample sample.e)
10583+ ?^ first first
10584+ (duplicate-expr body.e)
10585+ %cast
10586+ =/ first (duplicate-shape shape.e)
10587+ ?^ first first
10588+ (duplicate-expr val.e)
10589+ %call
10590+ =/ first (duplicate-expr head.e)
10591+ ?^ first first
10592+ (duplicate-exprs args.e)
10593+ %trace
10594+ =/ first (duplicate-expr val.e)
10595+ ?^ first first
10596+ (duplicate-expr then.e)
10597+ %branch
10598+ =/ first (duplicate-expr subject.e)
10599+ ?^ first first
10600+ (duplicate-arms arms.e)
10601+ %body
10602+ =/ first (duplicate-defs defs.e)
10603+ ?^ first first
10604+ (duplicate-expr final.e)
10605+ * ~
10606+ ==
810710607++ import-binding-names
810810608 |= imports=(list import)
810910609 ^- (list term)
@@ -8116,6 +10616,60 @@
811610616 ==
811710617 [n $(imports t.imports)]
811810618::
10619+++ reserved-proj-sample
10620+ |= sam=sample
10621+ ^- ?
10622+ ?- -.sam
10623+ %bind =(name.sam %proj)
10624+ %face =(name.sam %proj)
10625+ %pun =(name.sam %proj)
10626+ %cell (lien items.sam reserved-proj-sample)
10627+ * |
10628+ ==
10629+++ reserved-proj-pattern
10630+ |= p=pattern
10631+ ^- ?
10632+ ?- -.p
10633+ %bind =(name.p %proj)
10634+ %cell (lien items.p reserved-proj-pattern)
10635+ * |
10636+ ==
10637+++ reserved-proj-def
10638+ |= d=def
10639+ ^- ?
10640+ ?: =(name.d %proj) &
10641+ ?: ?=(%value -.d) (reserved-proj-expr val.d)
10642+ |
10643+++ reserved-proj-expr
10644+ |= e=expr
10645+ ^- ?
10646+ ?- -.e
10647+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
10648+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
10649+ %change (lien edits.e |=(p=edit (reserved-proj-expr val.p)))
10650+ %pair $(e val.e)
10651+ %unit $(e val.e)
10652+ %group $(e inner.e)
10653+ %list (lien items.e reserved-proj-expr)
10654+ %tuple (lien items.e |=(i=item (reserved-proj-expr val.i)))
10655+ ?(%gate %gate-wide) |((reserved-proj-sample sample.e) $(e body.e))
10656+ %cast $(e val.e)
10657+ %call |($(e head.e) (lien args.e reserved-proj-expr))
10658+ %trace |($(e val.e) $(e then.e))
10659+ %branch |($(e subject.e) (lien arms.e |=(a=arm |((reserved-proj-pattern pat.a) (reserved-proj-expr val.a)))))
10660+ %body |((lien defs.e reserved-proj-def) $(e final.e))
10661+ * |
10662+ ==
10663+::
10664+++ module-has-reserved-proj
10665+ |= mod=module
10666+ ^- ?
10667+ =/ imported=(list term) (import-binding-names imports.mod)
10668+ =/ vals=(list term) (global-value-names defs.mod)
10669+ =/ molds=imolds (collect-simple-molds defs.mod)
10670+ =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10671+ |((lien (weld imported (weld vals mold-names)) |=(n=term =(n %proj))) (lien defs.mod reserved-proj-def))
10672+::
811910673++ module-scope-valid
812010674 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
812110675 ^- ?
@@ -8123,6 +10677,7 @@
812310677 =/ vals=(list term) (global-value-names defs.mod)
812410678 =/ molds=imolds (collect-simple-molds defs.mod)
812510679 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10680+ ?: (module-has-reserved-proj mod) |
812610681 ?. %+ levy imported
812710682 |= n=term
812810683 &((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))))
@@ -8130,6 +10685,22 @@
813010685 ?. (levy vals |=(n=term &((unique-value-name n vals) !(lien prelude-values |=(v=term =(n v)))))) |
813110686 (levy mold-names |=(n=term &((unique-value-name n mold-names) !(lien prelude-molds |=(m=term =(n m))))))
813210687::
10688+:: In an API file or before main's kind is known, a lone `+$ poke`
10689+:: may be a declaration rather than a mold that shadows the prelude. Do not call
10690+:: that one collision definite, and do not hide unrelated scope errors.
10691+++ pending-declared-poke
10692+ |= [at=path mod=module prelude-values=(list term) prelude-molds=(list term)]
10693+ ^- ?
10694+ ?. (lien prelude-molds |=(n=term =(%poke n))) |
10695+ ?. |(?=([%ui %api @ %jibb ~] at) (lien defs.mod |=(d=def &(?=(%value -.d) =(%main name.d))))) |
10696+ =/ pokes=(list def)
10697+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
10698+ ?~ pokes |
10699+ ?^ t.pokes |
10700+ =/ remaining=(list def)
10701+ (skim defs.mod |=(d=def !&(?=(%mold -.d) =(%poke name.d))))
10702+ (module-scope-valid mod(defs remaining) prelude-values prelude-molds)
10703+::
813310704++ module-mold-types
813410705 |= [molds=imolds state=istate]
813510706 ^- (each imold-types @t)
@@ -8145,9 +10716,9 @@
814510716::
814610717:: Prepare a provisional interface from the trusted vendored source.
814710718:: Every declared name remains reserved, but only molds and values this
8148−:: fragment can infer are usable. Unsupported bodies are not validated,
8149−:: and imports into the prelude are not supported yet. The fixed origin
8150−:: gives its named unions the same identity in every importing module.
10719+:: fragment can infer are usable. Unsupported bodies are not validated.
10720+:: An optional internal source supplies the prelude's one supported import;
10721+:: clients cannot import that path directly. Named unions retain their origin.
815110722::
815210723:: Recognize only the complete standard prelude list shape. Its recursive
815310724:: tail uses the same parameter and the unqualified list name. The reader
@@ -8187,6 +10758,20 @@
818710758 ?. ?=(%tvar -.i.args.tail) |
818810759 =(var name.i.args.tail)
818910760::
10761+++ prelude-label
10762+ |= [typ=itype name=term vars=(list @ud)]
10763+ ^- itype
10764+ ?: ?=(%jrec -.typ) typ(label `name)
10765+ ?: ?=(%grec -.typ)
10766+ ?. (identity-union-parameters vars args.typ) typ(label ~)
10767+ typ(label `name)
10768+ ?. ?=(%union -.typ) typ
10769+ ?. (identity-union-parameters vars args.typ)
10770+ ?~ origin.typ typ
10771+ ?: =(at.u.origin.typ /lib/jibb/internal/jibb) typ(label ~)
10772+ typ
10773+ typ(label `name)
10774+::
819010775++ partial-prelude-molds
819110776 |= [molds=imolds state=istate]
819210777 ^- imold-types
@@ -8199,22 +10784,124 @@
819910784 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
820010785 ?~ out $(molds t.molds)
820110786 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
10787+ =. typ.template.u.out (prelude-label typ.template.u.out name.m vars.template.u.out)
820210788 [[name.m template.u.out] $(molds t.molds)]
820310789::
8204−++ partial-prelude-interface
8205− |= src=@t
10790+:: A compiler-owned interface available only to the dedicated
10791+:: internal-prelude preparation path, never the ordinary module resolver.
10792+++ private-primitive-interface
10793+ ^- ifile
10794+ =/ a=itype [%avar 0]
10795+ =/ pair=itype [%cell a a]
10796+ =/ b=itype [%rvar 0]
10797+ =/ plus=ischeme [[%fn [%cell b b] b] ~[0]]
10798+ =/ minus=ischeme [[%fn b b] ~[0]]
10799+ =/ greater=ischeme [[%fn pair [%flag ~]] ~[0]]
10800+ [~[[%raw-add plus] [%raw-dec minus] [%raw-gth greater]] ~ /lib/jibb/primitives/jibb ~ ~ ~ ~ ~]
10801+::
10802+++ infer-private-internal
10803+ |= [src=@t public-source=@t]
10804+ ^- (unit ifile)
10805+ =/ at=path /lib/jibb/internal/jibb
10806+ =/ parsed (parse at src)
10807+ ?: ?=(%| -.parsed) ~
10808+ =/ mod=module p.parsed
10809+ ?^ (duplicate-defs defs.mod) ~
10810+ ?~ imports.mod
10811+ =/ built=jfile-result (infer-jibb-file at src ~ ~ ~ ~[at] ~ ~ ~ ~)
10812+ ?: ?=(%| -.built) ~
10813+ `iface.p.built
10814+ ?. ?=([[%jibb *] ~] imports.mod) ~
10815+ ?. =(path.i.imports.mod /lib/jibb/primitives) ~
10816+ ?. (module-scope-valid mod ~ ~) ~
10817+ =/ vals=(list term) (global-value-names defs.mod)
10818+ ?: (lien vals |=(n=term =(n %main))) ~
10819+ =/ molds=imolds (collect-simple-molds defs.mod)
10820+ =/ globals=(list term) (weld (import-binding-names imports.mod) vals)
10821+ :: The private source can use the public list and unit molds before the
10822+ :: prelude is otherwise prepared. Re-read the trusted public source here
10823+ :: and admit only its validated canonical templates; do not accept schemes
10824+ :: supplied independently by the caller.
10825+ =/ public=(each module error) (parse /lib/jibb/prelude/jibb public-source)
10826+ ?: ?=(%| -.public) ~
10827+ ?^ (duplicate-defs defs.p.public) ~
10828+ ?. (module-scope-valid p.public ~ ~) ~
10829+ =/ source-molds=imolds (collect-simple-molds defs.p.public)
10830+ =/ written-list=(unit shape) (find-simple-mold %list source-molds)
10831+ =/ source-list=(unit ischeme)
10832+ ?~ written-list ~
10833+ ?. (standard-prelude-list u.written-list) ~
10834+ `[[%collection %list ~[[%var 0]]] ~[0]]
10835+ :: Derive the public unit template from its actual source, then compare
10836+ :: the complete nominal template before making it available privately.
10837+ =/ unit-decl=(unit shape) (find-simple-mold %unit source-molds)
10838+ =/ source-unit=(unit ischeme)
10839+ ?~ unit-decl ~
10840+ =/ unit-molds=imolds ~[[%unit u.unit-decl]]
10841+ =/ unit-state=istate [0 ~ ~ ~ unit-molds ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | /lib/jibb/prelude/jibb ~[%unit] ~ ~ 256 ~ ~ ~ ~]
10842+ =/ unit-types=imold-types (partial-prelude-molds unit-molds unit-state)
10843+ =/ unit-iface=ifile [~ unit-types /lib/jibb/prelude/jibb ~ ~ ~ ~ ~]
10844+ =/ found=(unit ischeme) (find-jibb-mold %unit unit-iface)
10845+ ?~ found ~
10846+ ?. (standard-unit-template u.found /lib/jibb/prelude/jibb) ~
10847+ found
10848+ =/ primitive=ifile private-primitive-interface
10849+ =? primitive ?=(^ source-list)
10850+ primitive(molds [[%list u.source-list] molds.primitive])
10851+ =? primitive ?=(^ source-unit)
10852+ primitive(molds [[%unit u.source-unit] molds.primitive])
10853+ =/ js=ijimports ~[[face.i.imports.mod primitive]]
10854+ =/ reserved=(list term) ~[face.i.imports.mod]
10855+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10856+ =/ state=istate [0 ~ ~ ~ molds globals ~ ~ ~ ~ js reserved ~ ~ ~ | at top ~ ~ 256 ~ ~ ~ ~]
10857+ =/ mts=(each imold-types @t) (module-mold-types molds state)
10858+ =/ usable=(unit imold-types)
10859+ ?: ?=(%& -.mts) `p.mts
10860+ :: Missing public templates may make an unrelated internal mold
10861+ :: unavailable. Validate all molds once with isolated canonical
10862+ :: templates before admitting only those inferred using the actual
10863+ :: source-backed templates. The proof interface is never exported.
10864+ ?. |(?=(~ source-list) ?=(~ source-unit)) ~
10865+ =/ nil=itype [%const [%null %n 0 '~']]
10866+ =/ canonical-unit=ischeme
10867+ [[%union ~[nil [%cell nil [%face %u [%var 0]]]] `[/lib/jibb/prelude/jibb %unit] `%unit ~[[%var 0]]] ~[0]]
10868+ =/ canonical-list=ischeme [[%collection %list ~[[%var 0]]] ~[0]]
10869+ =/ proof-primitive=ifile private-primitive-interface
10870+ =. molds.proof-primitive ~[[%list canonical-list] [%unit canonical-unit]]
10871+ =/ proof-imports=ijimports ~[[face.i.imports.mod proof-primitive]]
10872+ =/ proof=(each imold-types @t) (module-mold-types molds state(jimports proof-imports))
10873+ ?: ?=(%| -.proof) ~
10874+ `(partial-prelude-molds molds state)
10875+ ?~ usable ~
10876+ =/ resolution=iresolved (resolve-groups defs.mod molds globals ~ ~ ~ ~ js reserved at ~)
10877+ =/ env=ienv env.resolution
10878+ ?. (module-values-complete defs.mod env) ~
10879+ `[env u.usable at ~ artifacts.resolution ~ `src ~]
10880+::
10881+++ partial-prelude-interface-with-internal
10882+ |= [src=@t internal-source=(unit @t)]
820610883 ^- (unit ifile)
820710884 ?: =(0 src) ~
820810885 =/ at=path /lib/jibb/prelude/jibb
820910886 =/ parsed (parse at src)
821010887 ?: ?=(%| -.parsed) ~
8211− ?^ imports.p.parsed ~
10888+ ?: (named-mold-has-hole defs.p.parsed) ~
10889+ ?^ (duplicate-defs defs.p.parsed) ~
10890+ =/ private=(unit ijimports)
10891+ ?~ imports.p.parsed `~
10892+ ?. ?=([[%jibb *] ~] imports.p.parsed) ~
10893+ ?. =(path.i.imports.p.parsed /lib/jibb/internal) ~
10894+ ?~ internal-source ~
10895+ =/ built=(unit ifile) (infer-private-internal u.internal-source src)
10896+ ?~ built ~
10897+ `~[[face.i.imports.p.parsed u.built]]
10898+ ?~ private ~
821210899 ?~ defs.p.parsed ~
821310900 ?. (module-scope-valid p.parsed ~ ~) ~
821410901 =/ ds=(list def) defs.p.parsed
821510902 =/ molds=imolds (collect-simple-molds ds)
821610903 =/ names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8217− =/ globals=(list term) (global-value-names ds)
10904+ =/ globals=(list term) (weld (import-binding-names imports.p.parsed) (global-value-names ds))
821810905 :: Remove raw list before inferring any template, so an altered list
821910906 :: cannot leak through an alias. Its name remains reserved either way.
822010907 =/ declared=? (lien names |=(name=term =(%list name)))
@@ -8222,11 +10909,38 @@
822210909 =? env-molds declared
822310910 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
822410911 =/ reserved=(list term) ?:(declared ~[%list] ~)
8225− =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ ~ reserved ~ ~ ~ | at names ~]
8226− =/ mt=imold-types (partial-prelude-molds molds state)
8227− =/ partial=ifile [~ mt at]
8228− =/ env=ienv (resolve-supported-defs ds env-molds globals ~ ~ ~ ~ ~ reserved at `partial)
8229− `[env mt at]
10912+ =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~ ~ 256 ~ ~ ~ ~]
10913+ :: Other prelude molds may use list only after its source has passed
10914+ :: the standard-list check. The raw declaration remains removed.
10915+ =/ declared-list=(unit shape) (find-simple-mold %list molds)
10916+ =/ mold-prelude=(unit ifile)
10917+ ?~ declared-list ~
10918+ ?. (standard-prelude-list u.declared-list) ~
10919+ `[~ ~[[%list [[%collection %list ~[[%var 0]]] ~[0]]]] at ~ ~ ~ ~ ~]
10920+ =/ mt=imold-types (partial-prelude-molds molds state(prelude mold-prelude))
10921+ =/ partial=ifile [~ mt at ~ ~ ~ ~ ~]
10922+ :: An explicitly qualified re-export must resolve. Other unsupported
10923+ :: prelude declarations remain reserved but absent from the interface.
10924+ =/ required=imolds
10925+ %+ skim molds
10926+ |= m=[name=term body=shape]
10927+ =/ sh=shape body.m
10928+ ?. ?=(%ref -.sh) |
10929+ ?~ names.sh |
10930+ ?=(^ t.names.sh)
10931+ ?. (levy required |=(m=[name=term body=shape] ?=(^ (find-jibb-mold name.m partial)))) ~
10932+ =/ resolution=iresolved (resolve-groups ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
10933+ =/ env=ienv env.resolution
10934+ ?. (hole-values-present ds env) ~
10935+ =/ deps=(list iwidth-dependency)
10936+ ?~ u.private ~
10937+ ~[[at.interface.i.u.private source.interface.i.u.private elaborations.interface.i.u.private]]
10938+ `[env mt at ~ artifacts.resolution deps `src ~]
10939+::
10940+++ partial-prelude-interface
10941+ |= src=@t
10942+ ^- (unit ifile)
10943+ (partial-prelude-interface-with-internal src ~)
823010944::
823110945+$ iprelude [iface=ifile values=(list term) molds=(list term)]
823210946::
@@ -8241,6 +10955,17 @@
824110955 =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
824210956 `[u.iface vals ms]
824310957::
10958+++ prepare-prelude-with-internal
10959+ |= [src=@t internal-source=@t]
10960+ ^- (unit iprelude)
10961+ =/ iface=(unit ifile) (partial-prelude-interface-with-internal src `internal-source)
10962+ ?~ iface ~
10963+ =/ parsed (parse /lib/jibb/prelude/jibb src)
10964+ ?: ?=(%| -.parsed) ~
10965+ =/ vals=(list term) (global-value-names defs.p.parsed)
10966+ =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
10967+ `[u.iface vals ms]
10968+::
824410969++ module-values-complete
824510970 |= [ds=(list def) env=ienv]
824610971 ^- ?
@@ -8261,12 +10986,76 @@
826110986 ?: =(at at.i.cache) `iface.i.cache
826210987 $(cache t.cache)
826310988::
10989+:: These certificates retain the complete checked source closure. The
10990+:: trusted host must supply the identical prepared prelude and reader nouns.
10991+:: Exact bundle equality binds all source paths and versions; the set
10992+:: retains transitive paths for active-cycle checks. Request-bearing graphs
10993+:: alone have a size limit; incompatible diamond evidence fails closed.
10994+++ request-graph-requests-add
10995+ |= [pending=(list irequest-evidence) acc=(list irequest-evidence) fuel=@ud]
10996+ ^- (unit (list irequest-evidence))
10997+ ?~ pending `acc
10998+ ?: =(0 fuel) ~
10999+ =/ hit=(list irequest-evidence)
11000+ (skim acc |=(x=irequest-evidence &(=(api-at.x api-at.i.pending) =(name.x name.i.pending))))
11001+ ?^ hit
11002+ ?. ?=([* ~] hit) ~
11003+ ?. =(i.hit i.pending) ~
11004+ $(pending t.pending, fuel (dec fuel))
11005+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11006+++ request-graph-inputs-match
11007+ |= [g=irequest-graph externals=iexternals marks=imark-externals modules=jbundle values=(list term) molds=(list term) prelude=(unit ifile)]
11008+ ^- ?
11009+ ?& =(bundle-input.g modules)
11010+ =(prelude-input.g prelude)
11011+ =(prelude-values.g values)
11012+ =(prelude-molds.g molds)
11013+ =(externals.g externals)
11014+ =(marks.g marks)
11015+ ==
11016+++ request-graph-merge
11017+ |= [imports=ijimports g=irequest-graph fuel=@ud]
11018+ ^- (unit irequest-graph)
11019+ ?~ imports `g
11020+ ?: =(0 fuel) ~
11021+ =/ child=ifile interface.i.imports
11022+ ?~ graph.child ~
11023+ =/ cg=irequest-graph u.graph.child
11024+ ?. ?& =(bundle-input.g bundle-input.cg)
11025+ =(prelude-input.g prelude-input.cg)
11026+ =(prelude-values.g prelude-values.cg)
11027+ =(prelude-molds.g prelude-molds.cg)
11028+ =(externals.g externals.cg)
11029+ =(marks.g marks.cg)
11030+ ==
11031+ ~
11032+ =/ merged=(set path) (~(uni in:..zuse paths.g) paths.cg)
11033+ =/ rs=(unit (list irequest-evidence))
11034+ (request-graph-requests-add requests.cg requests.g (add 1 (lent requests.cg)))
11035+ ?~ rs ~
11036+ ?: &(?=(^ u.rs) |((gth (lent ~(tap in:..zuse merged)) 256) (gth (lent u.rs) 256))) ~
11037+ $(imports t.imports, g g(paths merged, requests u.rs), fuel (dec fuel))
11038+++ request-graph-reusable
11039+ |= [f=ifile src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) values=(list term) molds=(list term) prelude=(unit ifile)]
11040+ ^- ?
11041+ ?~ source.f |
11042+ ?. =(u.source.f src) |
11043+ ?~ graph.f |
11044+ =/ g=irequest-graph u.graph.f
11045+ ?. (request-graph-inputs-match g externals marks modules values molds prelude) |
11046+ ?. (~(has in:..zuse paths.g) at.f) |
11047+ !(lien active |=(p=path (~(has in:..zuse paths.g) p)))
11048+::
826411049++ resolve-jibb-imports
826511050 |= [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)]
826611051 ^- jimports-result
826711052 ?~ imports [%& [~ cache]]
826811053 ?. ?=(%jibb -.i.imports) $(imports t.imports)
826911054 =/ at=path (weld path.i.imports `path`~[%jibb])
11055+ ?: =(at /lib/jibb/internal/jibb)
11056+ [%| 'the prelude internal module is private']
11057+ ?: =(at /lib/jibb/primitives/jibb)
11058+ [%| 'the prelude primitive interface is private']
827011059 ?: (lien active |=(p=path =(p at)))
827111060 [%| (crip "import cycle at {(spud at)}")]
827211061 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
@@ -8274,39 +11063,882 @@
827411063 ?^ t.found [%| (crip "duplicate module sources: {(spud at)}")]
827511064 =/ cached=(unit ifile) (find-jibb-cache at cache)
827611065 =/ iface=jfile-result
8277− ?^ cached [%& [u.cached cache]]
11066+ ?^ cached
11067+ ?. =(at.u.cached at) [%| 'cached module identity needs unsupported inference']
11068+ ?~ graph.u.cached
11069+ :: A detached legacy interface has unknown evidence. Rebuild it
11070+ :: against the current graph, without retaining any stale entry.
11071+ =/ clean=jcache (skim cache |=(x=[at=path iface=ifile] !=(at.x at)))
11072+ (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds clean prelude)
11073+ ?. (request-graph-reusable u.cached source.i.found externals mark-externals modules active prelude-values prelude-molds prelude)
11074+ [%| 'cached module evidence needs unsupported inference']
11075+ [%& [u.cached cache]]
827811076 (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
827911077 ?: ?=(%| -.iface) [%| p.iface]
828011078 =/ rest=jimports-result $(imports t.imports, cache cache.p.iface)
828111079 ?: ?=(%| -.rest) rest
828211080 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
828311081::
11082+:: Provisional declaration extraction only; this does not derive asks,
11083+:: validate imported types, or claim that an API module has checked.
11084++$ iapi-path [at=span name=term segments=(list pseg) full=term diffs=(list term) scry=(unit (list pseg))]
11085+++ api-path-mark
11086+ |= [sh=shape marks=(list term)]
11087+ ^- (unit term)
11088+ ?. ?=(%ref -.sh) ~
11089+ ?. ?=([@ ~] names.sh) ~
11090+ ?. (unique-value-name i.names.sh marks) ~
11091+ `i.names.sh
11092+::
11093+++ api-path-diffs
11094+ |= [shapes=(list shape) marks=(list term) used=(list term)]
11095+ ^- (unit (list term))
11096+ ?~ shapes `~
11097+ =/ n=(unit term) (api-path-mark i.shapes marks)
11098+ ?~ n ~
11099+ ?: (lien used |=(x=term =(x u.n))) ~
11100+ =/ rest=(unit (list term)) $(shapes t.shapes, used [u.n used])
11101+ ?~ rest ~
11102+ `[u.n u.rest]
11103+::
11104+++ api-path-payload
11105+ |= [sh=shape marks=(list term)]
11106+ ^- (unit [full=term diffs=(list term)])
11107+ =/ direct=(unit term) (api-path-mark sh marks)
11108+ ?^ direct `[u.direct ~]
11109+ ?. ?=(%apply -.sh) ~
11110+ ?. =(~[%facts] ref.sh) ~
11111+ ?~ args.sh ~
11112+ ?~ t.args.sh ~
11113+ =/ full=(unit term) (api-path-mark i.args.sh marks)
11114+ ?~ full ~
11115+ =/ diffs=(unit (list term)) (api-path-diffs t.args.sh marks ~[u.full])
11116+ ?~ diffs ~
11117+ `[u.full u.diffs]
11118+::
11119++$ iapi-parameter [name=term aura=@ta at=span]
11120+++ api-path-parameters
11121+ |= [segments=(list pseg) seen=(list term)]
11122+ ^- (unit (list iapi-parameter))
11123+ ?~ segments `~
11124+ ?: ?=(%knot -.i.segments) $(segments t.segments)
11125+ =/ seg=pseg i.segments
11126+ ?. ?=(%typed -.seg) ~
11127+ ?: =(0 aura.seg) ~
11128+ ?: (lien seen |=(n=term =(n name.seg))) ~
11129+ =/ rest=(unit (list iapi-parameter)) $(segments t.segments, seen [name.seg seen])
11130+ ?~ rest ~
11131+ `[[name.seg aura.seg at.seg] u.rest]
11132+::
11133+++ api-scry-parameters-compatible
11134+ |= [scry=(list iapi-parameter) watch=(list iapi-parameter)]
11135+ ^- ?
11136+ ?~ scry &
11137+ ?. (lien watch |=(p=iapi-parameter &(=(name.p name.i.scry) =(aura.p aura.i.scry)))) |
11138+ $(scry t.scry)
11139+::
11140+++ api-path-one
11141+ |= [sh=shape marks=(list term)]
11142+ ^- (unit iapi-path)
11143+ ?. ?=(%cell -.sh) ~
11144+ =/ fs=(list field) fields.sh
11145+ ?~ fs ~
11146+ ?~ t.fs ~
11147+ ?~ t.t.fs ~
11148+ ?: (gth (lent fs) 4) ~
11149+ ?. ?=(%bare -.i.fs) ~
11150+ =/ tag=shape shape.i.fs
11151+ ?. ?=(%const -.tag) ~
11152+ ?. =(%term form.lit.tag) ~
11153+ =/ name=term val.lit.tag
11154+ ?. (jibb-face-name name) ~
11155+ ?. ?=(%bare -.i.t.fs) ~
11156+ =/ path-shape=shape shape.i.t.fs
11157+ ?. ?=(%path -.path-shape) ~
11158+ ?. ?=(%bare -.i.t.t.fs) ~
11159+ =/ payload=(unit [full=term diffs=(list term)]) (api-path-payload shape.i.t.t.fs marks)
11160+ ?~ payload ~
11161+ =/ scry=(unit (unit (list pseg)))
11162+ ?~ t.t.t.fs `~
11163+ =/ entry=field i.t.t.t.fs
11164+ ?. ?=(%face -.entry) ~
11165+ ?. =(%scry name.entry) ~
11166+ ?. ?=(%path -.shape.entry) ~
11167+ ``segs.shape.entry
11168+ ?~ scry ~
11169+ =/ params=(unit (list iapi-parameter)) (api-path-parameters segs.path-shape ~)
11170+ ?~ params ~
11171+ ?^ u.scry
11172+ =/ scry-params=(unit (list iapi-parameter)) (api-path-parameters u.u.scry ~)
11173+ ?~ scry-params ~
11174+ ?. (api-scry-parameters-compatible u.scry-params u.params) ~
11175+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11176+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11177+::
11178+++ api-path-many
11179+ |= [shapes=(list shape) marks=(list term) seen=(list term)]
11180+ ^- (unit (list iapi-path))
11181+ ?~ shapes `~
11182+ =/ one=(unit iapi-path) (api-path-one i.shapes marks)
11183+ ?~ one ~
11184+ ?: (lien seen |=(n=term =(n name.u.one))) ~
11185+ =/ rest=(unit (list iapi-path)) $(shapes t.shapes, seen [name.u.one seen])
11186+ ?~ rest ~
11187+ `[u.one u.rest]
11188+::
11189+++ api-path-declaration
11190+ |= [sh=shape marks=(list term)]
11191+ ^- (unit (list iapi-path))
11192+ ?: ?=(%union -.sh) (api-path-many cases.sh marks ~)
11193+ (api-path-many ~[sh] marks ~)
11194+::
11195+:: Derived gates share the value namespace. /% marks name molds; /- and
11196+:: /= also introduce faces that cannot be shadowed by a derived value.
11197+++ api-import-faces
11198+ |= imports=(list import)
11199+ ^- (list term)
11200+ ?~ imports ~
11201+ ?- -.i.imports
11202+ %mark $(imports t.imports)
11203+ %sur [name.i.imports $(imports t.imports)]
11204+ %jibb [face.i.imports $(imports t.imports)]
11205+ ==
11206+::
11207+++ api-derived-names-valid
11208+ |= [paths=(list iapi-path) poke-names=(list term) mod=module prelude-values=(list term)]
11209+ ^- ?
11210+ =/ path-names=(list term) (turn paths |=(p=iapi-path name.p))
11211+ =/ derived=(list term) (weld path-names poke-names)
11212+ ?: (lien derived |=(n=term =(n %proj))) |
11213+ =/ outer=(list term) (weld prelude-values (weld (global-value-names defs.mod) (api-import-faces imports.mod)))
11214+ (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x))))))
11215+::
11216+:: Analysis only. Successful external entries must be unchanged results
11217+:: produced for the declared marks; no request interface is produced.
11218++$ iapi-mark-type [name=term typ=itype]
11219++$ iapi-path-typed [path=iapi-path full=itype diffs=(list iapi-mark-type)]
11220+++ api-diff-types
11221+ |= [names=(list term) externals=imark-externals declared=(list term)]
11222+ ^- (unit (list iapi-mark-type))
11223+ ?~ names `~
11224+ =/ typ=(unit itype) (find-imported-mark i.names externals declared)
11225+ ?~ typ ~
11226+ =/ tail=(unit (list iapi-mark-type)) $(names t.names)
11227+ ?~ tail ~
11228+ `[[i.names u.typ] u.tail]
11229+::
11230+++ api-path-types
11231+ |= [paths=(list iapi-path) externals=imark-externals declared=(list term)]
11232+ ^- (unit (list iapi-path-typed))
11233+ ?~ paths `~
11234+ =/ full=(unit itype) (find-imported-mark full.i.paths externals declared)
11235+ ?~ full ~
11236+ =/ diffs=(unit (list iapi-mark-type)) (api-diff-types diffs.i.paths externals declared)
11237+ ?~ diffs ~
11238+ =/ tail=(unit (list iapi-path-typed)) $(paths t.paths)
11239+ ?~ tail ~
11240+ `[[i.paths u.full u.diffs] u.tail]
11241+::
11242+++ api-poke-mark-names
11243+ |= [pokes=(list def) declared=(list term)]
11244+ ^- (unit (list term))
11245+ ?~ pokes `~
11246+ ?^ t.pokes ~
11247+ =/ d=def i.pokes
11248+ ?. ?=(%mold -.d) ~
11249+ =/ sh=shape shape.d
11250+ ?: ?=(%union -.sh) (api-path-diffs cases.sh declared ~)
11251+ =/ name=(unit term) (api-path-mark sh declared)
11252+ ?~ name ~
11253+ `~[u.name]
11254+::
11255+++ api-path-analysis
11256+ |= [mod=module externals=imark-externals prelude-values=(list term) prelude-molds=(list term)]
11257+ ^- (unit (list iapi-path-typed))
11258+ ?: (lien defs.mod def-has-hole) ~
11259+ ?^ (duplicate-defs defs.mod) ~
11260+ =/ ds=(list def) defs.mod
11261+ =/ declarations=(list def)
11262+ (skim ds |=(d=def &(?=(%mold -.d) =(%paths name.d))))
11263+ ?. ?=([* ~] declarations) ~
11264+ =/ pokes=(list def)
11265+ (skim ds |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11266+ ?: (gth (lent pokes) 1) ~
11267+ =/ ordinary=(list def)
11268+ (skim ds |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
11269+ ?. (module-scope-valid mod(defs ordinary) prelude-values prelude-molds) ~
11270+ =/ declared=(list term) (collect-mark-imports imports.mod)
11271+ =/ poke-names=(unit (list term)) (api-poke-mark-names pokes declared)
11272+ ?~ poke-names ~
11273+ =/ decl=def i.declarations
11274+ ?> ?=(%mold -.decl)
11275+ =/ paths=(unit (list iapi-path)) (api-path-declaration shape.decl declared)
11276+ ?~ paths ~
11277+ ?. (api-derived-names-valid u.paths u.poke-names mod prelude-values) ~
11278+ (api-path-types u.paths externals declared)
11279+::
11280+:: Source/graph entry for path analysis only. The returned paths retain
11281+:: reader-derived mark types and import resolution has checked reachable
11282+:: Jibb dependencies. This is not an API interface or a module check.
11283+++ api-path-analysis-source
11284+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11285+ ^- (each (list iapi-path-typed) @t)
11286+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path analysis requires /ui/api/<agent>.jibb']
11287+ =/ parsed (parse file src)
11288+ ?: ?=(%| -.parsed) [%| 'API path source does not parse']
11289+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11290+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11291+ ?~ prepared [%| 'API path analysis needs the prepared prelude']
11292+ =/ prelude=(unit ifile) `iface.u.prepared
11293+ =/ deps=jimports-result
11294+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ prelude)
11295+ ?: ?=(%| -.deps) [%| p.deps]
11296+ =/ paths=(unit (list iapi-path-typed))
11297+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11298+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11299+ [%& u.paths]
11300+::
11301+:: Analysis evidence retains the API source, the prepared interface, the
11302+:: caller's reader results and the resolved Jibb dependency cache alongside
11303+:: the typed path declarations. Reader results and prepared interfaces are
11304+:: trusted inputs: this does not verify their underlying Hoon source/version,
11305+:: create requests or check the provenance of arbitrary values.
11306++$ iapi-path-evidence
11307+ [at=path source=@t prepared=iprelude externals=iexternals marks=imark-externals dependencies=jcache paths=(list iapi-path-typed)]
11308+++ api-path-evidence-source
11309+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11310+ ^- (each iapi-path-evidence @t)
11311+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11312+ =/ parsed (parse file src)
11313+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11314+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11315+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11316+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11317+ =/ public=ifile iface.u.prepared
11318+ =/ deps=jimports-result
11319+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
11320+ ?: ?=(%| -.deps) [%| p.deps]
11321+ =/ paths=(unit (list iapi-path-typed))
11322+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11323+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11324+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11325+:: Graph-aware variant preserves the caller active stack and cache.
11326+++ api-path-evidence-graph
11327+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11328+ ^- (each iapi-path-evidence @t)
11329+ ?~ active [%| 'API analysis needs an active graph']
11330+ ?. =(i.active file) [%| 'API analysis active graph does not start at the source']
11331+ ?: (lien t.active |=(p=path =(p file))) [%| 'API analysis active graph contains a cycle']
11332+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11333+ =/ parsed (parse file src)
11334+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11335+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11336+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11337+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11338+ =/ public=ifile iface.u.prepared
11339+ =/ deps=jimports-result
11340+ (resolve-jibb-imports imports.p.parsed externals marks modules active values.u.prepared molds.u.prepared cache `public)
11341+ ?: ?=(%| -.deps) [%| p.deps]
11342+ =/ paths=(unit (list iapi-path-typed))
11343+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11344+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11345+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11346+::
11347+:: This query classifies a unique path declaration only. Missing evidence
11348+:: or a nonunique name is unknown; it proves nothing about an ask value.
11349+:: Like prepared interfaces, the supplied evidence is a trusted host input.
11350+++ api-path-watchability
11351+ |= [evidence=(unit iapi-path-evidence) case-name=term]
11352+ ^- ?(%watchable %not-watchable %unknown)
11353+ ?~ evidence %unknown
11354+ =/ found=(list iapi-path-typed)
11355+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
11356+ ?. ?=([* ~] found) %unknown
11357+ ?~ scry.path.i.found %watchable
11358+ %not-watchable
11359+::
11360+:: These are declaration-derived request components, not a callable gate,
11361+:: an ask value, or proof of a value's provenance. Keep the exact trusted
11362+:: source/reader evidence until a later checked interface and lowerer can
11363+:: attach it to a generated request. No argument ordering is claimed here.
11364++$ iapi-request-parameter [name=term typ=itype at=span]
11365++$ iapi-request-parts
11366+ [evidence=iapi-path-evidence path=iapi-path-typed parameters=(list iapi-request-parameter) reply-sample=itype fold=(unit itype) watchability=?(%watchable %not-watchable)]
11367+++ api-request-parameter-types
11368+ |= params=(list iapi-parameter)
11369+ ^- (unit (list iapi-request-parameter))
11370+ ?~ params `~
11371+ =/ aura=@ta aura.i.params
11372+ ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
11373+ =/ rest=(unit (list iapi-request-parameter)) $(params t.params)
11374+ ?~ rest ~
11375+ `[[name.i.params [%atom aura] at.i.params] u.rest]
11376+::
11377+:: A single diff's fold consumes the tagged diff and the previous full value.
11378+:: Multiple-diff unions need a checked union representation and remain open.
11379+++ api-request-fold-type
11380+ |= p=iapi-path-typed
11381+ ^- (unit (unit itype))
11382+ ?~ diffs.p `~
11383+ ?^ t.diffs.p ~
11384+ =/ d=iapi-mark-type i.diffs.p
11385+ =/ literal=lit [%term %tas name.d (crip ['%' (trip name.d)])]
11386+ =/ sample=itype [%cell [%cell [%const literal] typ.d] full.p]
11387+ ``[%fn sample full.p]
11388+::
11389+++ api-request-parts
11390+ |= [evidence=(unit iapi-path-evidence) case-name=term]
11391+ ^- (unit iapi-request-parts)
11392+ ?~ evidence ~
11393+ =/ found=(list iapi-path-typed)
11394+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
11395+ ?. ?=([* ~] found) ~
11396+ =/ p=iapi-path-typed i.found
11397+ =/ raw=(unit (list iapi-parameter)) (api-path-parameters segments.path.p ~)
11398+ ?~ raw ~
11399+ =/ params=(unit (list iapi-request-parameter)) (api-request-parameter-types u.raw)
11400+ ?~ params ~
11401+ =/ fold=(unit (unit itype)) (api-request-fold-type p)
11402+ ?~ fold ~
11403+ =/ watch=?(%watchable %not-watchable) ?~(scry.path.p %watchable %not-watchable)
11404+ `[u.evidence p u.params full.p u.fold watch]
11405+::
11406+:: Check ordinary API molds and values plus every declared mark type using
11407+:: the same trusted source, prepared prelude and reader inputs as path
11408+:: evidence. Keep elaborations with those inputs for a later interface.
11409+:: This is partial analysis: an unused /- core is not independently checked,
11410+:: definitions needing derived values remain unsupported, and no complete
11411+:: API, request or constructor is exported or given runtime behavior.
11412++$ iapi-support-evidence
11413+ [paths=iapi-path-evidence values=ienv molds=imold-types marks=(list iapi-mark-type) elaborations=(list iwidth-definition)]
11414+++ api-support-analysis-source
11415+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11416+ ^- (each iapi-support-evidence @t)
11417+ =/ path-result (api-path-evidence-source file src externals marks modules prepared)
11418+ ?: ?=(%| -.path-result) [%| p.path-result]
11419+ =/ evidence=iapi-path-evidence p.path-result
11420+ =/ parsed (parse file src)
11421+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
11422+ =/ mod=module p.parsed
11423+ =/ ordinary=(list def)
11424+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
11425+ =/ prep=iprelude prepared.evidence
11426+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
11427+ =/ vals=(list term) (global-value-names ordinary)
11428+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
11429+ =/ declared=(list term) (collect-mark-imports imports.mod)
11430+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
11431+ ?~ mark-types [%| 'API declared marks need unsupported inference']
11432+ =/ prelude=(unit ifile) `iface.prep
11433+ =/ deps=jimports-result
11434+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.prep molds.prep dependencies.evidence prelude)
11435+ ?: ?=(%| -.deps) [%| p.deps]
11436+ =/ molds=imolds (collect-simple-molds ordinary)
11437+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
11438+ =/ surs=(list term) (collect-sur-imports imports.mod)
11439+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
11440+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11441+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~]
11442+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11443+ ?: ?=(%| -.mts) [%| p.mts]
11444+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
11445+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
11446+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
11447+:: Preserve the same graph context through supporting definitions.
11448+++ api-support-analysis-graph
11449+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11450+ ^- (each iapi-support-evidence @t)
11451+ =/ path-result (api-path-evidence-graph file src externals marks modules active cache prepared)
11452+ ?: ?=(%| -.path-result) [%| p.path-result]
11453+ =/ evidence=iapi-path-evidence p.path-result
11454+ =/ parsed (parse file src)
11455+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
11456+ =/ mod=module p.parsed
11457+ =/ ordinary=(list def)
11458+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
11459+ =/ prep=iprelude prepared.evidence
11460+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
11461+ =/ vals=(list term) (global-value-names ordinary)
11462+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
11463+ =/ declared=(list term) (collect-mark-imports imports.mod)
11464+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
11465+ ?~ mark-types [%| 'API declared marks need unsupported inference']
11466+ =/ prelude=(unit ifile) `iface.prep
11467+ =/ deps=jimports-result
11468+ (resolve-jibb-imports imports.mod externals marks modules active values.prep molds.prep dependencies.evidence prelude)
11469+ ?: ?=(%| -.deps) [%| p.deps]
11470+ =/ molds=imolds (collect-simple-molds ordinary)
11471+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
11472+ =/ surs=(list term) (collect-sur-imports imports.mod)
11473+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
11474+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11475+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~]
11476+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11477+ ?: ?=(%| -.mts) [%| p.mts]
11478+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
11479+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
11480+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
11481+::
11482+:: Type-analysis artifact for one plain request. The resolver may publish
11483+:: its interface only together with trusted source and reader evidence.
11484+:: No lowering or runtime validator exists.
11485+:: Value watchability remains unproved even for a watchable declaration.
11486++$ ione-request-interface
11487+ [support=iapi-support-evidence parts=iapi-request-parts iface=ifile]
11488+++ request-compatible-ask
11489+ |= prelude=iprelude
11490+ ^- (unit ischeme)
11491+ =/ public=ifile iface.prelude
11492+ ?. =(at.public /lib/jibb/prelude/jibb) ~
11493+ =/ ask=(unit ischeme) (find-jibb-mold %ask public)
11494+ ?~ ask ~
11495+ ?. ?=([@ ~] vars.u.ask) ~
11496+ ?. ?=(%union -.typ.u.ask) ~
11497+ ?. =(origin.typ.u.ask `[/lib/jibb/internal/jibb %ask]) ~
11498+ ?. (identity-union-parameters vars.u.ask args.typ.u.ask) ~
11499+ =/ m=@ud i.vars.u.ask
11500+ ?: (itype-var-is-atom m typ.u.ask) ~
11501+ ?. (levy (itype-vars typ.u.ask) |=(n=@ud =(n m))) ~
11502+ ?: (itype-has-tag typ.u.ask) ~
11503+ =/ private=(list iwidth-dependency)
11504+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
11505+ ?. ?=([* ~] private) ~
11506+ ?~ source.i.private ~
11507+ =/ path=(unit ischeme) (find-jibb-mold %path public)
11508+ ?~ path ~
11509+ ?^ vars.u.path ~
11510+ =/ path-type=itype [%collection %list ~[[%atom %ta]]]
11511+ ?. =(typ.u.path path-type) ~
11512+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit public)
11513+ ?~ unit-template ~
11514+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
11515+ =/ state-unit=(unit itype) (template-apply u.unit-template ~[[%noun ~]])
11516+ ?~ state-unit ~
11517+ =/ path-unit=(unit itype) (template-apply u.unit-template ~[path-type])
11518+ ?~ path-unit ~
11519+ =/ output=itype [%cell [%face %state [%noun ~]] [%face %message [%var m]]]
11520+ =/ agent-input=itype [%cell [%face %mark [%atom %tas]] [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]]
11521+ =/ store-input=itype [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]
11522+ =/ pure-case=itype [%cell [%const [%term %tas %pure '%pure']] [%face %value [%var m]]]
11523+ =/ agent-case=itype
11524+ [%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]]]]]]]]
11525+ =/ store-case=itype
11526+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %name [%atom %tas]] [%face %receive [%fn store-input output]]]]]
11527+ ?. =(cases.typ.u.ask ~[pure-case agent-case store-case]) ~
11528+ ask
11529+::
11530+:: The first supported standalone API has exactly one mark import and one
11531+:: plain path declaration, with no other definitions or imports. No partial
11532+:: success is published when source, schema, or a required mold is unknown.
11533+++ one-request-interface-source
11534+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11535+ ^- (each ione-request-interface @t)
11536+ =/ out (api-support-analysis-source file src externals marks modules prepared)
11537+ ?: ?=(%| -.out) [%| p.out]
11538+ =/ support=iapi-support-evidence p.out
11539+ =/ ev=iapi-path-evidence paths.support
11540+ =/ parsed (parse file src)
11541+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
11542+ =/ mod=module p.parsed
11543+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
11544+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
11545+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
11546+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
11547+ =/ p=iapi-path-typed i.paths.ev
11548+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
11549+ ?~ parts [%| 'request components need unsupported inference']
11550+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
11551+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
11552+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
11553+ =/ valid-marks=?
11554+ ?~ fold.u.parts ?=([* ~] marks.support)
11555+ ?=([* [* ~]] marks.support)
11556+ ?. valid-marks [%| 'request marks need unsupported inference']
11557+ =/ fold-open=?
11558+ ?~ fold.u.parts |
11559+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
11560+ ?: fold-open [%| 'request fold needs unsupported inference']
11561+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
11562+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
11563+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
11564+ ?~ ask [%| 'request ask needs unsupported inference']
11565+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
11566+ ?~ result [%| 'request ask needs unsupported inference']
11567+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
11568+ =/ sample=itype
11569+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
11570+ ?~ parameters.u.parts callback
11571+ [%cell typ.i.parameters.u.parts callback]
11572+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
11573+ =/ exports=imold-types
11574+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
11575+ =/ prelude=iprelude prepared.ev
11576+ =/ public=ifile iface.prelude
11577+ ?~ source.public [%| 'request prelude source needs unsupported inference']
11578+ =/ private=(list iwidth-dependency)
11579+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
11580+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
11581+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
11582+ =/ req=irequest-evidence
11583+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
11584+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
11585+ [%& [support u.parts interface]]
11586+:: Graph-aware request artifact; resolver use remains type-only.
11587+++ one-request-interface-graph
11588+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11589+ ^- (each ione-request-interface @t)
11590+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
11591+ ?: ?=(%| -.out) [%| p.out]
11592+ =/ support=iapi-support-evidence p.out
11593+ =/ ev=iapi-path-evidence paths.support
11594+ =/ parsed (parse file src)
11595+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
11596+ =/ mod=module p.parsed
11597+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
11598+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
11599+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
11600+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
11601+ =/ p=iapi-path-typed i.paths.ev
11602+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
11603+ ?~ parts [%| 'request components need unsupported inference']
11604+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
11605+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
11606+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
11607+ =/ valid-marks=?
11608+ ?~ fold.u.parts ?=([* ~] marks.support)
11609+ ?=([* [* ~]] marks.support)
11610+ ?. valid-marks [%| 'request marks need unsupported inference']
11611+ =/ fold-open=?
11612+ ?~ fold.u.parts |
11613+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
11614+ ?: fold-open [%| 'request fold needs unsupported inference']
11615+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
11616+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
11617+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
11618+ ?~ ask [%| 'request ask needs unsupported inference']
11619+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
11620+ ?~ result [%| 'request ask needs unsupported inference']
11621+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
11622+ =/ sample=itype
11623+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
11624+ ?~ parameters.u.parts callback
11625+ [%cell typ.i.parameters.u.parts callback]
11626+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
11627+ =/ exports=imold-types
11628+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
11629+ =/ prelude=iprelude prepared.ev
11630+ =/ public=ifile iface.prelude
11631+ ?~ source.public [%| 'request prelude source needs unsupported inference']
11632+ =/ private=(list iwidth-dependency)
11633+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
11634+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
11635+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
11636+ =/ req=irequest-evidence
11637+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
11638+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
11639+ [%& [support u.parts interface]]
11640+::
11641+++ api-mark-exports
11642+ |= [marks=(list term) all=(list term) externals=imark-externals]
11643+ ^- imold-types
11644+ ?~ marks ~
11645+ =/ t=(unit itype) (find-imported-mark i.marks externals all)
11646+ ?~ t $(marks t.marks)
11647+ [[i.marks [u.t ~]] $(marks t.marks)]
11648+::
11649+:: Experimental direct poke-only API. Unsupported API declarations fail
11650+:: as a whole; supplied mark reader results retain their existing boundary.
11651+++ api-poke-interface
11652+ |= [at=path mod=module mark-externals=imark-externals prelude-values=(list term) prelude-molds=(list term) prelude=(unit ifile)]
11653+ ^- (unit ifile)
11654+ ?: (lien defs.mod def-has-hole) ~
11655+ ?. ?=([%ui %api @ %jibb ~] at) ~
11656+ ?^ (duplicate-defs defs.mod) ~
11657+ ?~ prelude ~
11658+ ?. =(at.u.prelude /lib/jibb/prelude/jibb) ~
11659+ =/ poke=(unit ischeme) (find-jibb-mold %poke u.prelude)
11660+ ?~ poke ~
11661+ ?. ?=(%union -.typ.u.poke) ~
11662+ ?^ vars.u.poke ~
11663+ =/ compatible=?
11664+ %+ lien cases.typ.u.poke
11665+ |= c=itype
11666+ ?=([%cell [%const [%term %tas %agent *]] [%cell [%face %agent [%atom %tas]] [%cell [%face %mark [%atom %tas]] [%face %payload [%noun ~]]]]] c)
11667+ ?. compatible ~
11668+ ?. (module-scope-valid mod(defs ~) prelude-values prelude-molds) ~
11669+ ?. (levy imports.mod |=(i=import ?=(%mark -.i))) ~
11670+ =/ marks=(list term) (collect-mark-imports imports.mod)
11671+ ?. ?=([@ ~] marks) ~
11672+ =/ ds=(list def) defs.mod
11673+ ?. ?=([[%mold *] ~] ds) ~
11674+ ?. =(%poke name.i.ds) ~
11675+ =/ sh=shape shape.i.ds
11676+ ?. ?=([%ref *] sh) ~
11677+ ?. ?=([@ ~] names.sh) ~
11678+ =/ n=term i.names.sh
11679+ ?. (unique-value-name n marks) ~
11680+ ?: |((lien prelude-values |=(x=term =(n x))) (lien prelude-molds |=(x=term =(n x)))) ~
11681+ =/ mark=(unit itype) (find-imported-mark n mark-externals marks)
11682+ ?~ mark ~
11683+ =/ sc=ischeme [[%fn u.mark typ.u.poke] ~]
11684+ `[~[[n sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]] ~ ~ ~ ~]
11685+::
11686+:: Source-proven ordinary helpers validate each selected /sur dependency.
11687+:: Unused or less direct cores remain unsupported by this first interface.
11688+++ api-sur-covered
11689+ |= [surs=(list term) defs=(list def) externals=iexternals all=(list term)]
11690+ ^- ?
11691+ ?~ surs &
11692+ =/ found=(list def)
11693+ %+ skim defs
11694+ |= d=def
11695+ ?. ?=(%mold -.d) |
11696+ ?. ?=(%ref -.shape.d) |
11697+ ?. ?=([@ [@ ~]] names.shape.d) |
11698+ =(i.t.names.shape.d i.surs)
11699+ ?~ found |
11700+ =/ selected=def i.found
11701+ ?. ?=(%mold -.selected) |
11702+ =/ sh=shape shape.selected
11703+ ?. ?=(%ref -.sh) |
11704+ ?. ?=([@ [@ ~]] names.sh) |
11705+ =/ checked=(unit itype) (find-imported-mold i.surs i.names.sh externals all)
11706+ ?~ checked |
11707+ $(surs t.surs)
11708+::
11709++$ imulti-request-gates [values=ienv requests=(list irequest-evidence)]
11710+++ api-request-gates
11711+ |= [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]
11712+ ^- (unit imulti-request-gates)
11713+ ?~ paths `[~ ~]
11714+ ?: =(0 fuel) ~
11715+ =/ p=iapi-path-typed i.paths
11716+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
11717+ ?~ parts ~
11718+ ?. ?=(?(~ [* ~]) parameters.u.parts) ~
11719+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) ~
11720+ ?^ scry.path.p ~
11721+ ?^ (itype-vars reply-sample.u.parts) ~
11722+ ?: (itype-has-tag reply-sample.u.parts) ~
11723+ =/ open-fold=?
11724+ ?~ fold.u.parts |
11725+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
11726+ ?: open-fold ~
11727+ =/ result=(unit itype) (template-apply ask ~[[%var 0]])
11728+ ?~ result ~
11729+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
11730+ =/ sample=itype
11731+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
11732+ ?~ parameters.u.parts callback
11733+ [%cell typ.i.parameters.u.parts callback]
11734+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
11735+ =/ prep=iprelude prepared.ev
11736+ =/ req=irequest-evidence
11737+ [file name.path.p p src public internal values.prep molds.prep externals marks]
11738+ =/ rest=(unit imulti-request-gates)
11739+ $(paths t.paths, fuel (dec fuel))
11740+ ?~ rest ~
11741+ `[[[name.path.p scheme] values.u.rest] [req requests.u.rest]]
11742+::
11743+++ api-poke-from-checked
11744+ |= [file=path mod=module marks=imark-externals values=(list term) molds=(list term) prelude=(unit ifile)]
11745+ ^- (unit [values=ienv derived=(list iderived)])
11746+ =/ pokes=(list def)
11747+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11748+ ?~ pokes `[~ ~]
11749+ ?. ?=([* ~] pokes) ~
11750+ =/ declared=(list term) (collect-mark-imports imports.mod)
11751+ =/ ns=(unit (list term)) (api-poke-mark-names pokes declared)
11752+ ?~ ns ~
11753+ ?. ?=([@ ~] u.ns) ~
11754+ =/ matching=(list import)
11755+ %+ skim imports.mod
11756+ |= i=import
11757+ ?. ?=(%mark -.i) |
11758+ =(mark.i i.u.ns)
11759+ ?. ?=([* ~] matching) ~
11760+ =/ checked=(unit ifile)
11761+ (api-poke-interface file mod(defs pokes, imports matching) marks values molds prelude)
11762+ ?~ checked ~
11763+ `[values.u.checked derived.u.checked]
11764+::
11765+:: The partial interface is published atomically: all paths, ordinary
11766+:: source definitions, declared marks and the poke must check. Unselected
11767+:: /sur bindings, runtime validation and value watchability remain unproved.
11768+++ multi-request-interface-graph
11769+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11770+ ^- (each [iface=ifile cache=jcache] @t)
11771+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
11772+ ?: ?=(%| -.out) [%| p.out]
11773+ =/ support=iapi-support-evidence p.out
11774+ =/ ev=iapi-path-evidence paths.support
11775+ =/ parsed (parse file src)
11776+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
11777+ =/ mod=module p.parsed
11778+ ?. (levy imports.mod |=(i=import ?=(?(%mark %sur) -.i)))
11779+ [%| 'request imports need unsupported inference']
11780+ =/ surs=(list term) (collect-sur-imports imports.mod)
11781+ ?. (api-sur-covered surs defs.mod externals surs)
11782+ [%| 'API source dependency needs unsupported inference']
11783+ ?~ paths.ev [%| 'request count needs unsupported inference']
11784+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
11785+ ?~ ask [%| 'request ask needs unsupported inference']
11786+ =/ prep=iprelude prepared.ev
11787+ =/ public=ifile iface.prep
11788+ ?~ source.public [%| 'request prelude source needs unsupported inference']
11789+ =/ private=(list iwidth-dependency)
11790+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
11791+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
11792+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
11793+ =/ gates=(unit imulti-request-gates)
11794+ (api-request-gates paths.ev ev u.ask file src u.source.public u.source.i.private externals marks 256)
11795+ ?~ gates [%| 'request paths need unsupported inference']
11796+ =/ poke=(unit [values=ienv derived=(list iderived)])
11797+ (api-poke-from-checked file mod marks values.prep molds.prep `public)
11798+ ?~ poke [%| 'API poke needs unsupported inference']
11799+ =/ mark-molds=imold-types
11800+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
11801+ =/ exports=imold-types (weld mark-molds molds.support)
11802+ =/ names=(list term) (turn exports |=(m=[name=term template=ischeme] name.m))
11803+ ?. (levy names |=(n=term (unique-value-name n names)))
11804+ [%| 'API exported molds need unsupported inference']
11805+ =/ env=ienv (weld values.u.gates (weld values.u.poke values.support))
11806+ =/ graph=irequest-graph
11807+ [(silt `(list path)`~[file]) requests.u.gates modules `public values.prep molds.prep externals marks]
11808+ =/ iface=ifile
11809+ [env exports file derived.u.poke elaborations.support ~ `src `graph]
11810+ [%& [iface dependencies.ev]]
11811+::
828411812++ infer-jibb-file
828511813 |= [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)]
828611814 ^- jfile-result
8287− ?: ?=([%ui %api *] at) [%| (crip "API module needs unsupported inference: {(spud at)}")]
828811815 =/ parsed (parse at src)
828911816 ?: ?=(%| -.parsed) [%| (crip "module source does not parse: {(spud at)}")]
829011817 =/ mod=module p.parsed
8291− ?. (module-scope-valid mod prelude-values prelude-molds) [%| (crip "module has conflicting names: {(spud at)}")]
11818+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
11819+ ?^ duplicate [%| (show-duplicate-fields at src u.duplicate)]
11820+ ?: ?=([%ui %api *] at)
11821+ =/ iface=(unit ifile) (api-poke-interface at mod mark-externals prelude-values prelude-molds prelude)
11822+ ?^ iface
11823+ =/ checked=ifile u.iface(source `src, graph `[(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals])
11824+ [%& [checked [[at checked] cache]]]
11825+ ?~ prelude [%| (crip "API module needs unsupported inference: {(spud at)}")]
11826+ =/ prepared=iprelude [u.prelude prelude-values prelude-molds]
11827+ =/ narrow=?
11828+ ?. ?=([[%mark *] ~] imports.mod) |
11829+ ?. ?=([[%mold *] ~] defs.mod) |
11830+ ?. =(%paths name.i.defs.mod) |
11831+ !?=(%union -.shape.i.defs.mod)
11832+ ?: narrow
11833+ =/ request=(each ione-request-interface @t)
11834+ (one-request-interface-graph at src externals mark-externals modules active cache `prepared)
11835+ ?: ?=(%| -.request) [%| (crip "API module needs unsupported inference: {(spud at)}")]
11836+ =/ checked=ifile iface.p.request
11837+ [%& [checked [[at checked] dependencies.paths.support.p.request]]]
11838+ =/ multi=(each [iface=ifile cache=jcache] @t)
11839+ (multi-request-interface-graph at src externals mark-externals modules active cache `prepared)
11840+ ?: ?=(%| -.multi) [%| (crip "API module needs unsupported inference: {(spud at)}")]
11841+ [%& [iface.p.multi [[at iface.p.multi] cache.p.multi]]]
11842+ ?. (module-scope-valid mod prelude-values prelude-molds)
11843+ ?: (pending-declared-poke at mod prelude-values prelude-molds)
11844+ [%| (crip "module kind or scope needs unsupported inference: {(spud at)}")]
11845+ [%| (crip "module has conflicting names: {(spud at)}")]
829211846 =/ vals=(list term) (global-value-names defs.mod)
829311847 ?: (lien vals |=(n=term =(n %main)))
829411848 [%| (crip "module kind needs unsupported inference: {(spud at)}")]
829511849 =/ js=jimports-result (resolve-jibb-imports imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
829611850 ?: ?=(%| -.js) [%| p.js]
8297− =/ molds=imolds (collect-simple-molds defs.mod)
11851+ =/ collected=grec-collected
11852+ ?^ imports.mod [(collect-simple-molds defs.mod) *(map term shape)]
11853+ (grec-collect-molds defs.mod)
11854+ =/ molds=imolds molds.collected
829811855 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
829911856 =/ surs=(list term) (collect-sur-imports imports.mod)
830011857 =/ marks=(list term) (collect-mark-imports imports.mod)
830111858 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
830211859 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8303− =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude]
11860+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~]
11861+ :: Source and scope were checked above; preserve that exact root and prelude.
11862+ :: This first integration only indexes import-free library sources.
11863+ =/ index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])
11864+ ?^ imports.mod ~
11865+ ?~ prelude ~
11866+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude)
11867+ ?~ standard ~
11868+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
11869+ =/ index=(map term shape) proofs.collected
11870+ ?. !=(index *(map term shape)) ~
11871+ ?: (lien molds |=(m=[name=term body=shape] =(%list name.m))) ~
11872+ `[at src u.prelude index]
11873+ =. grec-index.state index
830411874 =/ mts=(each imold-types @t) (module-mold-types molds state)
830511875 ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
8306− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
11876+ =/ resolution=iresolved
11877+ ?~ index
11878+ (resolve-groups defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
11879+ (resolve-groups-core defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude index)
11880+ =/ env=ienv env.resolution
830711881 ?. (module-values-complete defs.mod env)
830811882 [%| (crip "module definitions need unsupported inference: {(spud at)}")]
8309− [%& [[env p.mts at] [[at [env p.mts at]] cache.p.js]]]
11883+ =/ initial=irequest-graph [(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals]
11884+ =/ graph=(unit irequest-graph) (request-graph-merge resolved.p.js initial (add 1 (lent resolved.p.js)))
11885+ ?~ graph [%| 'module request evidence needs unsupported inference']
11886+ =/ iface=ifile [env p.mts at ~ artifacts.resolution ~ `src graph]
11887+ [%& [iface [[at iface] cache.p.js]]]
11888+::
11889+:: A source-bound analysis of one named mold, not a module, island,
11890+:: request, watchability or runtime check. The host owns the trusted
11891+:: prepared prelude, canonical paths and reader/source version identities.
11892+:: The 256-node cap covers only classification, not source/graph work.
11893++$ igate-free-mold
11894+ [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]
11895+++ gate-free-mold-source
11896+ |= [file=path src=@t name=term externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude) fuel=@ud]
11897+ ^- (each igate-free-mold @t)
11898+ ?~ file [%| 'mold analysis needs a path ending in jibb']
11899+ ?. =(%jibb (rear file)) [%| 'mold analysis needs a path ending in jibb']
11900+ ?: |(=(file /lib/jibb/internal/jibb) =(file /lib/jibb/primitives/jibb))
11901+ [%| 'the prelude internal modules are private']
11902+ ?: ?=([%ui %api *] file) [%| 'API declarations need unsupported mold analysis']
11903+ ?: ?=([%ui %stores *] file) [%| 'store declarations need unsupported mold analysis']
11904+ =/ entries=jbundle (skim modules |=(m=jsource =(file at.m)))
11905+ ?: (gth (lent entries) 1) [%| 'duplicate root module sources']
11906+ =/ wrong-root=? ?~(entries | !=(source.i.entries src))
11907+ ?: wrong-root [%| 'root module source does not match bundle']
11908+ =/ parsed (parse file src)
11909+ ?: ?=(%| -.parsed) [%| 'mold source does not parse']
11910+ =/ mod=module p.parsed
11911+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
11912+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11913+ ?~ prepared [%| 'mold analysis needs the prepared prelude']
11914+ ?. (module-scope-valid mod values.u.prepared molds.u.prepared)
11915+ [%| 'mold source has conflicting or unsupported scope']
11916+ =/ selected=(list def)
11917+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(name.d name))))
11918+ ?~ selected [%| 'selected mold is not declared']
11919+ ?^ t.selected [%| 'selected mold is not unique']
11920+ ?> ?=(%mold -.i.selected)
11921+ =/ public=ifile iface.u.prepared
11922+ =/ js=jimports-result
11923+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
11924+ ?: ?=(%| -.js) [%| p.js]
11925+ =/ ms=imolds (collect-simple-molds defs.mod)
11926+ =/ vals=(list term) (global-value-names defs.mod)
11927+ =/ globals=(list term) (weld values.u.prepared (weld (import-binding-names imports.mod) vals))
11928+ =/ surs=(list term) (collect-sur-imports imports.mod)
11929+ =/ declared=(list term) (collect-mark-imports imports.mod)
11930+ =/ reserved=(list term) (weld molds.u.prepared (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
11931+ =/ top=(list term) (turn ms |=(m=[name=term body=shape] name.m))
11932+ =/ state=istate [0 ~ ~ ~ ms globals externals surs marks declared resolved.p.js reserved ~ ~ ~ | file top `public ~ 256 ~ ~ ~ ~]
11933+ =/ inferred=(unit [template=ischeme state=istate])
11934+ (infer-mold-template shape.i.selected state(active ~[name], in-mold &))
11935+ ?~ inferred [%| 'selected mold needs unsupported inference']
11936+ =/ template=ischeme template.u.inferred
11937+ =. typ.template (label-direct-union typ.template shape.i.selected name state)
11938+ =. typ.template (itype-normalize typ.template sub.state.u.inferred)
11939+ =/ cap=@ud (min fuel 256)
11940+ =/ analysis=igate-free (gate-free-type typ.template cap ~)
11941+ [%& [file src name u.prepared externals marks modules cache.p.js template fuel cap analysis]]
831011942::
831111943:: +golden-types-with-modules fails closed for imports without prelude
831211944:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -8317,6 +11949,8 @@
831711949 ^- @t
831811950 =/ parsed (parse file src)
831911951 ?: ?=(%| -.parsed) (show-error src p.parsed)
11952+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11953+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
832011954 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
832111955 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
832211956 (golden-types-with-marks file src externals mark-externals)
@@ -8331,6 +11965,8 @@
833111965 ^- @t
833211966 =/ parsed (parse file src)
833311967 ?: ?=(%| -.parsed) (show-error src p.parsed)
11968+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11969+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
833411970 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
833511971 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
833611972 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
@@ -8338,16 +11974,26 @@
833811974 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
833911975 (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
834011976::
11977+++ golden-types-with-prelude-and-internal
11978+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prelude-source=@t internal-source=@t]
11979+ ^- @t
11980+ =/ prepared=(unit iprelude) (prepare-prelude-with-internal prelude-source internal-source)
11981+ (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
11982+::
834111983++ golden-types-with-prepared-prelude
834211984 |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prepared=(unit iprelude)]
834311985 ^- @t
834411986 =/ parsed (parse file src)
834511987 ?: ?=(%| -.parsed) (show-error src p.parsed)
11988+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11989+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
834611990 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
834711991 =/ prelude-values=(list term) values.u.prepared
834811992 =/ prelude-molds=(list term) molds.u.prepared
834911993 =/ iface=(unit ifile) `iface.u.prepared
835011994 ?. (module-scope-valid p.parsed prelude-values prelude-molds)
11995+ ?: (pending-declared-poke file p.parsed prelude-values prelude-molds)
11996+ 'partial inference; module not checked\0amodule kind or scope needs unsupported inference'
835111997 'partial inference; module not checked\0amodule has conflicting names'
835211998 =/ js=jimports-result
835311999 (resolve-jibb-imports imports.p.parsed externals mark-externals modules ~[file] prelude-values prelude-molds ~ iface)
@@ -8388,13 +12034,20 @@
838812034 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
838912035 =/ parsed (parse file src)
839012036 ?: ?=(%| -.parsed) (show-error src p.parsed)
12037+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12038+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
12039+ ?: (module-has-reserved-proj p.parsed)
12040+ 'module has reserved proj name'
839112041 =/ ds=(list def) defs.p.parsed
839212042 =/ molds=imolds (collect-simple-molds ds)
839312043 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
839412044 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
839512045 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
839612046 =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
12047+ =/ cycles=(list icycle) (definite-value-cycles ds globals)
839712048 =/ env=ienv env.resolution
12049+ =/ source-defs=(map term def) (direct-checked-gates ds env)
12050+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
839812051 =/ lines=(list @t) ~
839912052 |-
840012053 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -8403,6 +12056,10 @@
840312056 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
840412057 ?. (unique-value-name name.d globals)
840512058 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
12059+ =/ cycle=(list icycle) (skim cycles |=(c=icycle =(name.c name.d)))
12060+ ?^ cycle
12061+ =/ diag=idiag ["non-gate value depends on itself through a cycle" ~[[first.i.cycle "value in cycle"] [next.i.cycle "dependency in cycle"]]]
12062+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d diag) lines])
840612063 ?: (lien grouped.resolution |=(n=term =(n name.d)))
840712064 =/ found=(unit ischeme) (ienv-lookup name.d env)
840812065 ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
@@ -8410,7 +12067,9 @@
841012067 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
841112068 $(ds t.ds, lines [line lines])
841212069 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8413− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude]
12070+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~]
12071+ =. gate-defs.initial source-defs
12072+ =. head-evidence.initial heads
841412073 =. initial (reserve-def-caps val.d initial)
841512074 =/ result=iresult
841612075 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
@@ -8418,6 +12077,11 @@
841812077 (infer-fragment val.d env initial)
841912078 ?: ?=(%| -.result)
842012079 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
12080+ =. state.p.result (promote-restricted-numbers state.p.result env)
12081+ =. 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)))
12082+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.result holes.initial state.p.result)
12083+ ?^ hole
12084+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d u.hole) lines])
842112085 =/ merged=(unit [first=icap second=icap])
842212086 (merged-capitals caps.state.p.result sub.state.p.result)
842312087 ?^ merged
@@ -8440,7 +12104,126 @@
844012104 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
844112105 ?: (gth (lent vars) 26)
844212106 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
12107+ ?~ (width-finalize projections.state.p.result sub.state.p.result vars)
12108+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: record projection elaboration needs unsupported inference") lines])
844312109 =/ printable=itype (canonical-itype typ vars)
844412110 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
844512111 $(ds t.ds, lines [line lines])
12112+:: Experimental per-module, source-derived recursive tree index.
12113+:: The two tags and the exact children/list/self layout are fixed-shape
12114+:: checks, so ordinary definitions incur no type-tree or source scans.
12115+++ grec-tagged-fields
12116+ |= sh=shape
12117+ ^- (unit [tag=@ fields=(list field)])
12118+ ?. ?=(%cell -.sh) ~
12119+ ?~ fields.sh ~
12120+ =/ head=field i.fields.sh
12121+ ?. ?=(%bare -.head) ~
12122+ ?. ?=(%const -.shape.head) ~
12123+ ?. &(?=(%term form.lit.shape.head) =(%tas aura.lit.shape.head)) ~
12124+ `[val.lit.shape.head t.fields.sh]
12125+++ grec-tree-children
12126+ |= [fs=(list field) param=@t]
12127+ ^- (unit field)
12128+ ?~ fs ~
12129+ ?~ t.fs `i.fs
12130+ ?^ t.t.fs ~
12131+ =/ event=field i.fs
12132+ =/ kids=field i.t.fs
12133+ ?. &(?=(%face -.event) ?=(%face -.kids)) ~
12134+ ?. !=(name.event name.kids) ~
12135+ ?. ?=(%fn -.shape.event) ~
12136+ ?. ?=(%aura -.sample.shape.event) ~
12137+ ?. =(%t aura.sample.shape.event) ~
12138+ ?. ?=(%tvar -.product.shape.event) ~
12139+ ?. =(param name.product.shape.event) ~
12140+ `kids
12141+::
12142+++ grec-tree-proof
12143+ |= [name=term sh=shape]
12144+ ^- ?
12145+ ?. ?=(%generic -.sh) |
12146+ ?. ?=([@ ~] vars.sh) |
12147+ =/ param=@t i.vars.sh
12148+ ?. ?=(%union -.body.sh) |
12149+ ?. ?=([* [* ~]] cases.body.sh) |
12150+ =/ a=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.cases.body.sh)
12151+ =/ b=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.t.cases.body.sh)
12152+ ?~ a |
12153+ ?~ b |
12154+ ?. !=(tag.u.a tag.u.b) |
12155+ ?. ?=([* ~] fields.u.a) |
12156+ =/ value=field i.fields.u.a
12157+ ?. ?=(%face -.value) |
12158+ ?. ?=(%aura -.shape.value) |
12159+ ?. =(%t aura.shape.value) |
12160+ =/ selected=(unit field) (grec-tree-children fields.u.b param)
12161+ ?~ selected |
12162+ =/ kids=field u.selected
12163+ ?. ?=(%face -.kids) |
12164+ ?. ?=(%apply -.shape.kids) |
12165+ ?. =(ref.shape.kids ~[%list]) |
12166+ ?. ?=([* ~] args.shape.kids) |
12167+ =/ self=shape i.args.shape.kids
12168+ ?. ?=(%apply -.self) |
12169+ ?. =(ref.self ~[name]) |
12170+ ?. ?=([* ~] args.self) |
12171+ ?. ?=(%tvar -.i.args.self) |
12172+ =(name.i.args.self param)
12173++$ grec-collected [molds=imolds proofs=(map term shape)]
12174+:: Experimental one-layer analysis view, never an exported mold identity.
12175+++ grec-unfold-view
12176+ |= [typ=itype fuel=@ud]
12177+ ^- (unit [view=itype left=@ud])
12178+ ?. ?=(%grec -.typ) ~
12179+ ?: =(fuel 0) ~
12180+ ?. ?=([* ~] args.typ) ~
12181+ =/ sh=shape proof.typ
12182+ ?. (grec-tree-proof name.typ sh) ~
12183+ ?> ?=(%generic -.sh)
12184+ ?> ?=([@ ~] vars.sh)
12185+ ?> ?=(%union -.body.sh)
12186+ ?> ?=([* [* ~]] cases.body.sh)
12187+ =/ ca=shape i.cases.body.sh
12188+ =/ cb=shape i.t.cases.body.sh
12189+ ?> ?=(%cell -.ca)
12190+ ?> ?=(%cell -.cb)
12191+ ?> ?=([* [* ~]] fields.ca)
12192+ ?> ?=([* *] fields.cb)
12193+ =/ tag-a=field i.fields.ca
12194+ =/ tag-b=field i.fields.cb
12195+ ?> ?=(%bare -.tag-a)
12196+ ?> ?=(%bare -.tag-b)
12197+ ?> ?=(%const -.shape.tag-a)
12198+ ?> ?=(%const -.shape.tag-b)
12199+ =/ text-field=field i.t.fields.ca
12200+ ?> ?=(%face -.text-field)
12201+ =/ branch=(list field) t.fields.cb
12202+ =/ kids=(unit field) (grec-tree-children branch i.vars.sh)
12203+ ?~ kids ~
12204+ ?> ?=(%face -.u.kids)
12205+ =/ children=itype [%face name.u.kids [%collection %list ~[typ]]]
12206+ ?> ?=(^ branch)
12207+ =/ payload=itype
12208+ ?~ t.branch children
12209+ =/ event=field i.branch
12210+ ?> ?=(%face -.event)
12211+ [%cell [%face name.event [%fn [%atom %t] i.args.typ]] children]
12212+ =/ leaf=itype [%cell [%const lit.shape.tag-a] [%face name.text-field [%atom %t]]]
12213+ =/ node=itype [%cell [%const lit.shape.tag-b] payload]
12214+ `[[%union ~[leaf node] ~ ~ ~] (dec fuel)]
12215+::
12216+++ grec-collect-molds
12217+ |= ds=(list def)
12218+ ^- grec-collected
12219+ ?~ ds [~ *(map term shape)]
12220+ =/ rest=grec-collected $(ds t.ds)
12221+ ?. ?=(%mold -.i.ds) rest
12222+ =/ name=term name.i.ds
12223+ =/ body=shape shape.i.ds
12224+ =/ proofs=(map term shape) proofs.rest
12225+ =? proofs (grec-tree-proof name body) (~(put by proofs) name body)
12226+ [[[name body] molds.rest] proofs]
12227+::
12228+
844612229--