@@ -874,7 +874,7 @@
874 %'~[' %'|=(' %'$-(' :: openers
874 %'~[' %'|=(' %'$-(' :: openers
875 %'%/' %'/' :: paths
875 %'%/' %'/' :: paths
876 %'+' %'`' %'=' :: pair, unit, face
876 %'+' %'`' %'=' :: pair, unit, face
877− %'*' %'?' :: noun, loobean mold
877+ %'*' %'?' %'_' :: noun, loobean, type hole
878 %'++' %'+$' %'|=' %'|$' :: runes
878 %'++' %'+$' %'|=' %'|$' :: runes
879 %'^-' %'~&' %'?-' %'!!' :: runes
879 %'^-' %'~&' %'?-' %'!!' :: runes
880 %'/-' %'/%' %'/=' :: imports
880 %'/-' %'/%' %'/=' :: imports
@@ -1016,6 +1016,7 @@
1016 [%const at=span =lit] :: ~ %add %.y
1016 [%const at=span =lit] :: ~ %add %.y
1017 [%ref at=span names=(list term)] :: state item.todo
1017 [%ref at=span names=(list term)] :: state item.todo
1018 [%tvar at=span name=@t] :: M
1018 [%tvar at=span name=@t] :: M
1019+ [%hole at=span ~] :: _
1019 [%path at=span segs=(list pseg)] :: / /todos /todo/[id=@ud]
1020 [%path at=span segs=(list pseg)] :: / /todos /todo/[id=@ud]
1020 [%apply at=span ref=(list term) args=(list shape)] :: (list @t)
1021 [%apply at=span ref=(list term) args=(list shape)] :: (list @t)
1021 [%cell at=span fields=(list field)] :: [text=@t done=?]
1022 [%cell at=span fields=(list field)] :: [text=@t done=?]
@@ -1024,9 +1025,9 @@
1024 [%generic at=span vars=(list @t) body=shape] :: +$ name |$ [M] …
1025 [%generic at=span vars=(list @t) body=shape] :: +$ name |$ [M] …
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=_]
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])
@@ -1295,6 +1296,7 @@
1295 (emit 1 %'=')
1296 (emit 1 %'=')
1296 ?: =('`' a) (emit 1 %'`')
1297 ?: =('`' a) (emit 1 %'`')
1297 ?: =('*' a) (emit 1 %'*')
1298 ?: =('*' a) (emit 1 %'*')
1299+ ?: =('_' a) (emit 1 %'_')
1298 ?: =('~' a)
1300 ?: =('~' a)
1299 ?: =('[' b) (emit 2 %'~[')
1301 ?: =('[' b) (emit 2 %'~[')
1300 ?: =('&' b) (emit 2 %'~&')
1302 ?: =('&' b) (emit 2 %'~&')
@@ -1670,14 +1672,14 @@
1670:: What may begin each place the parser reads (section 3, Errors):
1672:: What may begin each place the parser reads (section 3, Errors):
1671:: an expression a-z 0-9 " ( [ ~ % / ` | ^ ? !
1673:: an expression a-z 0-9 " ( [ ~ % / ` | ^ ? !
1672:: an operand a-z 0-9 " ( [ ~ % / ` | !
1674:: an operand a-z 0-9 " ( [ ~ % / ` | !
1673−:: a mold a-z A-Z @ * ! ? ~ % / ( [ $
1675+:: a mold a-z A-Z @ * ! ? ~ % / ( [ $ _
1674:: a pattern a-z 0-9 " ~ % * [
1676:: a pattern a-z 0-9 " ~ % * [
1675:: and what may go tight after an operand: . ( + = after a name, a
1677:: and what may go tight after an operand: . ( + = after a name, a
1676:: closer ) ] }, or the : of a comment
1678:: closer ) ] }, or the : of a comment
1678++ expr-mask 0x57ff.ffff.4800.0000.83ff.8126.0000.0000
1680++ expr-mask 0x57ff.ffff.4800.0000.83ff.8126.0000.0000
1679++ operand-mask 0x57ff.ffff.0800.0000.03ff.8126.0000.0000
1681++ 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
1681++ bar-mask 0x1000.0000.0000.0000.0000.0000.0000.0000
1683++ bar-mask 0x1000.0000.0000.0000.0000.0000.0000.0000
1682++ pattern-mask 0x47ff.fffe.0800.0000.03ff.0424.0000.0000
1684++ pattern-mask 0x47ff.fffe.0800.0000.03ff.0424.0000.0000
1683++ after-mask 0x2000.0000.2000.0000.2400.4b00.0000.0000
1685++ after-mask 0x2000.0000.2000.0000.2400.4b00.0000.0000
@@ -2107,6 +2109,7 @@
2108 %knot (weld "/" (trip p.s))
2110 %knot (weld "/" (trip p.s))
2109 %typed "/[{(trip name.s)}=@{(trip aura.s)}]"
2111 %typed "/[{(trip name.s)}=@{(trip aura.s)}]"
2112+ %inferred "/[{(trip name.s)}=_]"
2112++ show-tvars
2115++ show-tvars
@@ -2318,6 +2321,7 @@
2318 %const (nod "const" at.s (show-lit lit.s) ~)
2321 %const (nod "const" at.s (show-lit lit.s) ~)
2319 %ref (nod "ref" at.s (show-names names.s) ~)
2322 %ref (nod "ref" at.s (show-names names.s) ~)
2320 %tvar (nod "tvar" at.s (trip name.s) ~)
2323 %tvar (nod "tvar" at.s (trip name.s) ~)
2324+ %hole (nod "hole" at.s "" ~)
2321 %path (nod "path" at.s (show-psegs segs.s) ~)
2325 %path (nod "path" at.s (show-psegs segs.s) ~)
2322 %apply (nod "apply" at.s (show-names ref.s) (turn args.s sexp-shape))
2326 %apply (nod "apply" at.s (show-names ref.s) (turn args.s sexp-shape))
2323 %cell (nod "cell" at.s "" (turn fields.s sexp-field))
2327 %cell (nod "cell" at.s "" (turn fields.s sexp-field))
@@ -3842,6 +3846,7 @@
3842 %'*' [%& [%noun at.t ~] t.ts]
3846 %'*' [%& [%noun at.t ~] t.ts]
3843 %'!!' [%& [%void at.t ~] t.ts]
3847 %'!!' [%& [%void at.t ~] t.ts]
3844 %'?' [%& [%flag at.t ~] t.ts]
3848 %'?' [%& [%flag at.t ~] t.ts]
3849+ %'_' [%& [%hole at.t ~] t.ts]
3845 [%name *] [%& [%ref at.t ~[p.lex.t]] t.ts]
3850 [%name *] [%& [%ref at.t ~[p.lex.t]] t.ts]
3846 [%wing *] [%& [%ref at.t p.lex.t] t.ts]
3851 [%wing *] [%& [%ref at.t p.lex.t] t.ts]
3847 [%tvar *] [%& [%tvar at.t p.lex.t] t.ts]
3852 [%tvar *] [%& [%tvar at.t p.lex.t] t.ts]
@@ -4058,7 +4063,7 @@
4058 ?: &(?=(^ nex) tight.i.nex) (bad nex "a path segment")
4063 ?: &(?=(^ nex) tight.i.nex) (bad nex "a path segment")
4059 (bad-space i.after nex "a path segment")
4064 (bad-space i.after nex "a path segment")
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
4062 :: spaces, and where it ends
4067 :: spaces, and where it ends
4064 ++ read-pseg
4069 ++ read-pseg
@@ -4075,13 +4080,16 @@
4075 ?: |(?=(~ r2) !tight.i.r2) (bad-space i.r1 r2 "`=`")
4080 ?: |(?=(~ r2) !tight.i.r2) (bad-space i.r1 r2 "`=`")
4076 ?. ?=([[* * %'='] *] r2) (bad-in r2 "`=`" tis-mask)
4081 ?. ?=([[* * %'='] *] r2) (bad-in r2 "`=`" tis-mask)
4077 =/ r3=(list token) t.r2
4082 =/ r3=(list token) t.r2
4078− ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura")
4083+ ?: |(?=(~ r3) !tight.i.r3) (bad-space i.r2 r3 "an aura or type hole")
4079− ?. ?=([[* * [%aura *]] *] r3) (bad-in r3 "an aura" pat-mask)
4084+ ?. ?=([[* * ?([%aura *] %'_')] *] r3) (bad-in r3 "an aura or type hole" (con pat-mask (bex 95)))
4080 =/ r4=(list token) t.r3
4085 =/ r4=(list token) t.r3
4081 ?: |(?=(~ r4) !tight.i.r4) (bad-space i.r3 r4 "`]`")
4086 ?: |(?=(~ r4) !tight.i.r4) (bad-space i.r3 r4 "`]`")
4082 ?. ?=([[* * %']'] *] r4) (bad-in r4 "`]`" ser-mask)
4087 ?. ?=([[* * %']'] *] r4) (bad-in r4 "`]`" ser-mask)
4083 =/ at=span [beg.at.op end.at.i.r4]
4088 =/ at=span [beg.at.op end.at.i.r4]
4090+ ?: ?=(%'_' lex.i.r3) [%inferred at p.lex.i.r1 at.i.r3]
4084− [%& [[%typed at p.lex.i.r1 p.lex.i.r3] end.at.i.r4] t.r4]
4091+ [%typed at p.lex.i.r1 p.lex.i.r3]
4092+ [%& [seg end.at.i.r4] t.r4]
4087+| %span-check
4095+| %span-check
@@ -4465,6 +4473,7 @@
4465 %const [%const at.s ~[%lit] %one ~]
4473 %const [%const at.s ~[%lit] %one ~]
4466 %ref [%ref at.s ~[%name %wing] %one ~]
4474 %ref [%ref at.s ~[%name %wing] %one ~]
4467 %tvar [%tvar at.s ~[%tvar] %one ~]
4475 %tvar [%tvar at.s ~[%tvar] %one ~]
4476+ %hole [%hole at.s ~[%'_'] %one ~]
4468 %apply [%apply at.s ~[%'('] %shut (turn args.s outline-shape)]
4477 %apply [%apply at.s ~[%'('] %shut (turn args.s outline-shape)]
4469 %cell [%cell at.s ~[%'['] %shut (turn fields.s outline-sample)]
4478 %cell [%cell at.s ~[%'['] %shut (turn fields.s outline-sample)]
@@ -4473,8 +4482,11 @@
4473 %+ murn segs.s
4482 %+ murn segs.s
4474 |= g=pseg
4483 |= g=pseg
4475 ^- (unit outline)
4484 ^- (unit outline)
4476− ?. ?=(%typed -.g) ~
4487+ %typed `[%typed at.g ~[%'['] %shut ~]
4477− `[%typed at.g ~[%'['] %shut ~]
4488+ %inferred `[%typed at.g ~[%'['] %shut ~[[%hole hole-at.g ~[%'_'] %one ~]]]
4478 [%path at.s ~[%'/'] %run ks]
4490 [%path at.s ~[%'/'] %run ks]
@@ -4534,6 +4546,8 @@
4534 [%path [1 9] [1 9] [1 21]]
4546 [%path [1 9] [1 9] [1 21]]
4535 [%face [1 7] [1 7] [1 21]]
4547 [%face [1 7] [1 7] [1 21]]
4549+ :: an inferred path aura's hole spanning its = as well
4550+ ['+$ x /a/[id=_]' ~[[%hole [1 13] [1 12] [1 14]]]]
4537 :: an import's path cut short
4551 :: an import's path cut short
4538 ['/= c /ui/c' ~[[%jibb [1 1] [1 1] [1 11]]]]
4552 ['/= c /ui/c' ~[[%jibb [1 1] [1 1] [1 11]]]]
4539 :: brackets that close with the deeper lines, cut at their line's
4553 :: brackets that close with the deeper lines, cut at their line's
@@ -4593,6 +4607,8 @@
4593:: Atom constraints tied to an explicit capital or an inferred sample
4607:: Atom constraints tied to an explicit capital or an inferred sample
4594:: are generalized and printed. Other aura variables remain unsupported until
4608:: are generalized and printed. Other aura variables remain unsupported until
4595:: their defaulting and inferred generalization are implemented.
4609:: 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.
4596:: Bare @ is a separate unrestricted atom type. A directional fit check
4612:: Bare @ is a separate unrestricted atom type. A directional fit check
4597:: permits concrete atoms to widen to it, never the reverse. A fit that
4613:: permits concrete atoms to widen to it, never the reverse. A fit that
4598:: needs a not-yet-implemented constraint remains unsupported. Named unions
4614:: needs a not-yet-implemented constraint remains unsupported. Named unions
@@ -4600,18 +4616,64 @@
4600:: from their display name. Generic cases must be disjoint for all arguments.
4616:: from their display name. Generic cases must be disjoint for all arguments.
4601:: Unnamed union printing is informational; it is not Jibb syntax.
4617:: Unnamed union printing is informational; it is not Jibb syntax.
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.
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.
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.
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.
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.
4604 $~ [%var 0]
4660 $~ [%var 0]
4605 $% [%var id=@ud]
4661 $% [%var id=@ud]
4606 [%avar id=@ud]
4662 [%avar id=@ud]
4607 [%nvar id=@ud]
4664 [%nvar id=@ud]
4608 [%atom aura=@ta]
4666 [%atom aura=@ta]
4609 [%any-atom ~]
4667 [%any-atom ~]
4610 [%flag ~]
4668 [%flag ~]
4611 [%tag id=@ud literal=lit constructor=?]
4671 [%tag id=@ud literal=lit constructor=?]
4612 [%const literal=lit]
4672 [%const literal=lit]
4613 [%collection name=term args=(list itype)]
4673 [%collection name=term args=(list itype)]
4614 [%recursive module=term name=term label=(unit @t)]
4674 [%recursive module=term name=term label=(unit @t)]
4675+ [%jrec at=path name=term label=(unit @t) head=term aura=@ta tail=term]
4676+ [%grec at=path name=term label=(unit @t) proof=shape args=(list itype)]
4615 [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t) args=(list itype)]
4677 [%union cases=(list itype) origin=(unit [at=path name=term]) label=(unit @t) args=(list itype)]
4616 [%face name=term body=itype]
4678 [%face name=term body=itype]
4617 [%fn sample=itype product=itype]
4679 [%fn sample=itype product=itype]
@@ -4635,21 +4697,117 @@
4636 =/ found=(unit itype) (itype-lookup id.t sub)
4698 =/ found=(unit itype) (itype-lookup id.t sub)
4637 ?~ found t
4699 ?~ found t
4700+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4638 $(t u.found)
4701 $(t u.found)
4640 =/ found=(unit itype) (itype-lookup id.t sub)
4703 =/ found=(unit itype) (itype-lookup id.t sub)
4641 ?~ found t
4704 ?~ found t
4705+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4708+ =/ found=(unit itype) (itype-lookup id.t sub)
4710+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4642 $(t u.found)
4711 $(t u.found)
4644 =/ found=(unit itype) (itype-lookup id.t sub)
4713 =/ found=(unit itype) (itype-lookup id.t sub)
4645 ?~ found t
4714 ?~ found t
4715+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4718+ =/ found=(unit itype) (itype-lookup id.t sub)
4720+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4646 $(t u.found)
4721 $(t u.found)
4648 =/ found=(unit itype) (itype-lookup id.t sub)
4723 =/ found=(unit itype) (itype-lookup id.t sub)
4649 ?~ found t
4724 ?~ found t
4725+ ?: &(|(?=(%rvar -.u.found) ?=(%rnvar -.u.found)) =(id.t +.u.found)) u.found
4650 $(t u.found)
4726 $(t u.found)
4729+:: Prove only emptiness; unknown types are never treated as empty.
4730+:: A shared node budget bounds each proof attempt.
4731+++ itype-empty-cases
4732+ |= [xs=(list itype) sub=isub fuel=@ud]
4733+ ^- (unit [empty=? left=@ud])
4735+ =/ first=(unit [empty=? left=@ud]) (itype-empty-proof i.xs sub fuel)
4737+ ?. empty.u.first `[| left.u.first]
4738+ $(xs t.xs, fuel left.u.first)
4739+++ itype-empty-proof
4740+ |= [typ=itype sub=isub fuel=@ud]
4741+ ^- (unit [empty=? left=@ud])
4744+ =. typ (itype-walk typ sub)
4747+ %face $(typ body.typ)
4749+ =/ left=(unit [empty=? left=@ud]) $(typ hed.typ)
4751+ ?: empty.u.left `[& left.u.left]
4752+ $(typ tal.typ, fuel left.u.left)
4753+ %union (itype-empty-cases cases.typ sub fuel)
4756+:: Prove reachability separately from emptiness. An unresolved fixed
4757+:: recursive type is not presumed inhabited. A written, still-unconstrained
4758+:: capital is existentially inhabited for pattern reachability; the normal
4759+:: definition-boundary checks reject subsequently constrained capitals.
4760+++ itype-inhabited-cases
4761+ |= [xs=(list itype) sub=isub caps=icaps fuel=@ud pending=?]
4762+ ^- (unit [result=?(%yes %no %unknown) left=@ud])
4763+ ?~ xs `[?:(pending %unknown %no) fuel]
4764+ =/ first=(unit [result=?(%yes %no %unknown) left=@ud])
4765+ (itype-inhabited-proof i.xs sub caps fuel)
4767+ ?: =(%yes result.u.first) first
4768+ $(xs t.xs, fuel left.u.first, pending |(pending =(%unknown result.u.first)))
4769+++ itype-inhabited-proof
4770+ |= [typ=itype sub=isub caps=icaps fuel=@ud]
4771+ ^- (unit [result=?(%yes %no %unknown) left=@ud])
4774+ =. typ (itype-walk typ sub)
4777+ ?(%atom %any-atom %flag %const %noun %avar %rvar %nvar %rnvar %fn %jrec) `[%yes fuel]
4779+ ?: (lien caps |=(c=icap (hole-same-variable typ (itype-walk [%var id.c] sub)))) `[%yes fuel]
4781+ %face $(typ body.typ)
4783+ =/ head=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ hed.typ)
4785+ ?: =(%no result.u.head) head
4786+ =/ tail=(unit [result=?(%yes %no %unknown) left=@ud]) $(typ tal.typ, fuel left.u.head)
4788+ ?: =(%no result.u.tail) tail
4789+ ?: |(=(%unknown result.u.head) =(%unknown result.u.tail)) `[%unknown left.u.tail]
4790+ `[%yes left.u.tail]
4791+ %union (itype-inhabited-cases cases.typ sub caps fuel |)
4793+ ?. &(|(=(%list name.typ) =(%unit name.typ)) ?=([* ~] args.typ)) `[%unknown fuel]
4795+ %grec ?:((grec-tree-proof name.typ proof.typ) `[%yes fuel] `[%unknown fuel])
4799+ |= [xs=(list itype) sub=isub caps=icaps fuel=@ud]
4800+ ^- (unit (list itype))
4802+ =/ first=(unit [result=?(%yes %no %unknown) left=@ud])
4803+ (itype-inhabited-proof i.xs sub caps fuel)
4805+ ?: =(%unknown result.u.first) ~
4806+ =/ rest=(unit (list itype)) $(xs t.xs, fuel left.u.first)
4808+ ?: =(%no result.u.first) rest
4653++ itype-occurs
4811++ itype-occurs
4654 |= [n=@ud t=itype sub=isub]
4812 |= [n=@ud t=itype sub=isub]
@@ -4657,14 +4815,20 @@
4658 %var =(n id.t)
4816 %var =(n id.t)
4659 %avar =(n id.t)
4817 %avar =(n id.t)
4660 %nvar =(n id.t)
4819 %nvar =(n id.t)
4662 %any-atom |
4822 %any-atom |
4664 %tag =(n id.t)
4826 %tag =(n id.t)
4665 %const |
4827 %const |
4666 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
4828 %union |((lien cases.t |=(c=itype (itype-occurs n c sub))) (lien args.t |=(c=itype (itype-occurs n c sub))))
4667 %recursive |
4829 %recursive |
4831+ %grec (lien args.t |=(c=itype (itype-occurs n c sub)))
4668 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
4832 %collection (lien args.t |=(c=itype (itype-occurs n c sub)))
4669 %face $(t body.t)
4833 %face $(t body.t)
4670 %fn |($(t sample.t) $(t product.t))
4834 %fn |($(t sample.t) $(t product.t))
@@ -4683,6 +4847,11 @@
4683 =. a (itype-walk a sub)
4847 =. a (itype-walk a sub)
4684 =. b (itype-walk b sub)
4848 =. b (itype-walk b sub)
4685 ?: =(a b) `sub
4849 ?: =(a b) `sub
4850+ ?: &(?=(%grec -.a) ?=(%grec -.b))
4851+ ?. &(=(at.a at.b) =(name.a name.b)) ~
4852+ (itype-unify-args args.a args.b sub)
4853+ ?: &(?=(%jrec -.a) ?=(%jrec -.b))
4854+ ?:(&(=(at.a at.b) =(name.a name.b) =(head.a head.b) =(aura.a aura.b) =(tail.a tail.b)) `sub ~)
4686 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
4855 ?: &(?=(%recursive -.a) ?=(%recursive -.b))
4687 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
4856 ?:(&(=(module.a module.b) =(name.a name.b)) `sub ~)
4688 ?: &(?=(%union -.a) ?=(%union -.b))
4857 ?: &(?=(%union -.a) ?=(%union -.b))
@@ -4699,6 +4868,32 @@
4699 ?: ?=(%var -.b)
4868 ?: ?=(%var -.b)
4700 ?: (itype-occurs id.b a sub) ~
4869 ?: (itype-occurs id.b a sub) ~
4701 `[[id.b a] sub]
4870 `[[id.b a] sub]
4871+ :: Arithmetic's aura variable excludes loobeans; decimal literals
4872+ :: remain defaultable until a later constraint makes them concrete.
4873+ ?: &(?=(%nvar -.a) ?=(%rvar -.b))
4874+ `[[id.b [%rnvar id.a]] [id.a [%rnvar id.a]] sub]
4875+ ?: &(?=(%rvar -.a) ?=(%nvar -.b))
4876+ `[[id.a [%rnvar id.b]] [id.b [%rnvar id.b]] sub]
4877+ ?: &(?=(%rnvar -.a) ?=(%rvar -.b)) `[[id.b a] sub]
4878+ ?: &(?=(%rvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4879+ ?: &(?=(%rnvar -.a) ?=(%nvar -.b)) `[[id.b a] sub]
4880+ ?: &(?=(%nvar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4881+ ?: &(?=(%rnvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4882+ ?: &(?=(%avar -.a) ?=(%rnvar -.b)) `[[id.a b] sub]
4884+ ?. |(?=(%rnvar -.b) ?=(%atom -.b)) ~
4889+ ?: &(?=(%avar -.a) ?=(%rvar -.b)) `[[id.a b] sub]
4890+ ?: &(?=(%rvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4892+ ?. |(?=(%rvar -.b) ?=(%atom -.b)) ~
4702 :: The narrower decimal constraint survives a match with an atom
4897 :: The narrower decimal constraint survives a match with an atom
4703 :: variable; decimal syntax alone does not make it a loobean.
4898 :: variable; decimal syntax alone does not make it a loobean.
4704 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
4899 ?: &(?=(%nvar -.a) ?=(%avar -.b)) `[[id.b a] sub]
@@ -4753,14 +4948,20 @@
4758 %any-atom &
4955 %any-atom &
4761 %const |
4960 %const |
4762 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
4961 %union |((lien cases.t |=(c=itype (itype-has-any-atom c sub))) (lien args.t |=(c=itype (itype-has-any-atom c sub))))
4763 %recursive |
4962 %recursive |
4964+ %grec (lien args.t |=(c=itype (itype-has-any-atom c sub)))
4764 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
4965 %collection (lien args.t |=(c=itype (itype-has-any-atom c sub)))
4765 %face $(t body.t)
4966 %face $(t body.t)
4766 %fn |($(t sample.t) $(t product.t))
4967 %fn |($(t sample.t) $(t product.t))
@@ -4823,14 +5024,20 @@
4823 ?- -.typ
5024 ?- -.typ
4828 %any-atom &
5031 %any-atom &
4831 %const &
5036 %const &
4832 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
5037 %union |((lien cases.typ |=(c=itype (itype-has-fixed-atom c))) (lien args.typ |=(c=itype (itype-has-fixed-atom c))))
4833 %recursive |
5038 %recursive |
5040+ %grec (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
4834 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
5041 %collection (lien args.typ |=(c=itype (itype-has-fixed-atom c)))
4835 %face $(typ body.typ)
5042 %face $(typ body.typ)
4836 %fn |($(typ sample.typ) $(typ product.typ))
5043 %fn |($(typ sample.typ) $(typ product.typ))
@@ -4859,6 +5066,7 @@
4860 =. t (itype-walk t sub)
5067 =. t (itype-walk t sub)
5069+ %grec (lien args.t |=(c=itype (itype-has-face c sub)))
4862 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
5070 %collection (lien args.t |=(c=itype (itype-has-face c sub)))
4864 %cell |($(t hed.t) $(t tal.t))
5072 %cell |($(t hed.t) $(t tal.t))
@@ -4866,6 +5074,42 @@
5077+:: Closed function samples may omit a slot face, but a known name must
5078+:: match another known name. Keep nested value faces and require exact
5079+:: invariant compatibility; a faced tail against a cell is ambiguous.
5080+++ itype-closed-slot-match
5081+ |= [a=itype b=itype]
5083+ ?: &(?=(%face -.a) ?=(%face -.b))
5084+ ?. =(name.a name.b) |
5085+ ?=(^ (itype-unify body.a body.b ~))
5086+ ?: ?=(%face -.a) ?=(^ (itype-unify body.a b ~))
5087+ ?: ?=(%face -.b) ?=(^ (itype-unify a body.b ~))
5088+ ?=(^ (itype-unify a b ~))
5089+++ itype-closed-sample-match
5090+ |= [a=itype b=itype fuel=@ud]
5093+ ?. &(?=(%cell -.a) ?=(%cell -.b)) |
5094+ ?. (itype-closed-slot-match hed.a hed.b) |
5097+ ?: &(?=(%cell -.x) ?=(%cell -.y))
5098+ ?=(^ (itype-unify x y ~))
5099+ ?: |(&(?=(%face -.x) ?=(%cell -.y)) &(?=(%cell -.x) ?=(%face -.y))) |
5100+ (itype-closed-slot-match x y)
5101+++ itype-closed-gates-match
5102+ |= [a=itype b=itype]
5104+ ?. &(?=(%fn -.a) ?=(%fn -.b)) |
5105+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) |
5106+ ?. =(product.a product.b) |
5107+ ?^ (itype-vars a) |
5108+ ?^ (itype-vars b) |
5109+ ?: |((itype-has-tag a) (itype-has-tag b)) |
5110+ ?. (itype-closed-sample-match sample.a sample.b 1.024) |
5111+ ?=(^ (itype-unify product.a product.b ~))
4869++ itype-face-asym-collection-args
5113++ itype-face-asym-collection-args
4870 |= [as=(list itype) bs=(list itype) sub=isub]
5114 |= [as=(list itype) bs=(list itype) sub=isub]
@@ -4879,12 +5123,15 @@
4880 =. a (itype-walk a sub)
5124 =. a (itype-walk a sub)
4881 =. b (itype-walk b sub)
5125 =. b (itype-walk b sub)
5126+ ?: &(?=(%grec -.a) ?=(%grec -.b))
5127+ ?. &(=(at.a at.b) =(name.a name.b)) |
5128+ (itype-face-asym-collection-args args.a args.b sub)
4882 ?: &(?=(%collection -.a) ?=(%collection -.b))
5129 ?: &(?=(%collection -.a) ?=(%collection -.b))
4883 ?. =(name.a name.b) |
5130 ?. =(name.a name.b) |
4884 (itype-face-asym-collection-args args.a args.b sub)
5131 (itype-face-asym-collection-args args.a args.b sub)
4885 ?: &(?=(%face -.a) ?=(%face -.b)) $(a body.a, b body.b)
5132 ?: &(?=(%face -.a) ?=(%face -.b)) $(a body.a, b body.b)
4886− ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%nvar -.b))
5133+ ?: ?=(%face -.a) !|(?=(%var -.b) ?=(%avar -.b) ?=(%rvar -.b) |(?=(%nvar -.b) ?=(%rnvar -.b)))
4887− ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%nvar -.a))
5134+ ?: ?=(%face -.b) !|(?=(%var -.a) ?=(%avar -.a) ?=(%rvar -.a) |(?=(%nvar -.a) ?=(%rnvar -.a)))
4888 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
5135 ?: &(?=(%cell -.a) ?=(%cell -.b)) |($(a hed.a, b hed.b) $(a tal.a, b tal.b))
4889 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
5136 ?: &(?=(%fn -.a) ?=(%fn -.b)) |($(a sample.a, b sample.b) $(a product.a, b product.b))
@@ -4907,6 +5154,30 @@
4907 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
5154 [%cell $(actual hed.actual, expected hed.expected) $(actual tal.actual, expected tal.expected)]
4908 expected
5155 expected
5157+:: Positional call arguments do not write the sample's enclosing field
5158+:: labels. Ignore one raw sample-slot face per written argument while
5159+:: checking value faces as usual. An unknown or variable-bound cell spine
5160+:: cannot justify this distinction, so keep the existing conservative guard.
5161+++ itype-positional-slot-face-asym
5162+ |= [actual=itype expected=itype sub=isub]
5164+ ?: &(?=(%fn -.actual) ?=(%fn -.expected) (itype-closed-gates-match actual expected)) |
5165+ (itype-face-asym actual expected sub)
5167+++ itype-positional-face-asym
5168+ |= [args=(list expr) actual=itype expected=itype sub=isub]
5172+ =/ slot=itype expected
5173+ =? slot ?=(%face -.slot) body.slot
5174+ (itype-positional-slot-face-asym actual slot sub)
5175+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) &
5176+ =/ slot=itype hed.expected
5177+ =? slot ?=(%face -.slot) body.slot
5178+ ?: (itype-positional-slot-face-asym hed.actual slot sub) &
5179+ $(args t.args, actual tal.actual, expected tal.expected)
4910++ itype-output-may-be-cell
5181++ itype-output-may-be-cell
4911 |= [t=itype sub=isub]
5182 |= [t=itype sub=isub]
@@ -4916,6 +5187,9 @@
4917 %union &
5188 %union &
4918 %recursive &
5189 %recursive &
4919 %collection &
5193 %collection &
4920 %face $(t body.t)
5194 %face $(t body.t)
4921 %fn |($(t sample.t) $(t product.t))
5195 %fn |($(t sample.t) $(t product.t))
@@ -4944,6 +5218,7 @@
5221+ %grec (lien args.t |=(c=itype (itype-has-tag c)))
4947 %collection (lien args.t |=(c=itype (itype-has-tag c)))
5222 %collection (lien args.t |=(c=itype (itype-has-tag c)))
4948 %face $(t body.t)
5223 %face $(t body.t)
4949 %fn |($(t sample.t) $(t product.t))
5224 %fn |($(t sample.t) $(t product.t))
@@ -4957,6 +5232,7 @@
4959 %union &
5234 %union &
5235+ %grec (lien args.t |=(c=itype (itype-has-union c)))
4960 %collection (lien args.t |=(c=itype (itype-has-union c)))
5236 %collection (lien args.t |=(c=itype (itype-has-union c)))
4961 %face $(t body.t)
5237 %face $(t body.t)
4962 %fn |($(t sample.t) $(t product.t))
5238 %fn |($(t sample.t) $(t product.t))
@@ -4975,6 +5251,7 @@
4976 ?: &(?=(~ label.t) ?=(^ args.t)) &
5252 ?: &(?=(~ label.t) ?=(^ args.t)) &
4977 (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-generic c)))
5253 (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-generic c)))
5254+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-generic c))))
4978 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
5255 %collection (lien args.t |=(c=itype (itype-has-hidden-generic c)))
4979 %face $(t body.t)
5256 %face $(t body.t)
4980 %fn |($(t sample.t) $(t product.t))
5257 %fn |($(t sample.t) $(t product.t))
@@ -4987,6 +5264,8 @@
4989 %recursive &
5266 %recursive &
4990 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
5269 %collection (lien args.t |=(c=itype (itype-has-recursive c)))
4991 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
5270 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-recursive c)))
4992 %face $(t body.t)
5271 %face $(t body.t)
@@ -5000,6 +5279,8 @@
5002 %recursive ?=(~ label.t)
5281 %recursive ?=(~ label.t)
5282+ %jrec ?=(~ label.t)
5283+ %grec |(?=(~ label.t) (lien args.t |=(c=itype (itype-has-hidden-recursive c))))
5003 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
5284 %collection (lien args.t |=(c=itype (itype-has-hidden-recursive c)))
5004 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
5285 %union (lien (weld args.t cases.t) |=(c=itype (itype-has-hidden-recursive c)))
5005 %face $(t body.t)
5286 %face $(t body.t)
@@ -5027,34 +5308,107 @@
5027 $(cases t.cases, good `trial)
5308 $(cases t.cases, good `trial)
5030−:: A constructor needs a case with its tag at the head and a payload
5311+:: A constructor needs a case whose head has the same literal noun as its
5031−:: compatible with the expected gate sample. Other case forms do not
5312+:: tag. An unresolved or opaque case may reveal one later, so it cannot
5032−:: identify a constructor.
5313+:: prove a mismatch or a unique match. A broad atom mold is not a case.
5034++ itype-fit-ctor-cases
5315++ itype-fit-ctor-cases
5035 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
5316 |= [tag=lit sample=itype cases=(list itype) sub=isub next=@ud]
5037 =/ found=(unit ifit) ~
5318 =/ found=(unit ifit) ~
5322+ ?: pending [%unknown ~]
5039− ?~ cases ?~(found [%bad ~] u.found)
5323+ ?~ found [%bad ~]
5325+ =/ raw=itype i.cases
5327+ $(cases t.cases, pending &)
5040− =/ c=itype (itype-walk i.cases sub)
5328+ =/ c=itype (itype-walk raw sub)
5329+ ?: ?=(?(%var %tag %recursive %jrec %grec %union %face) -.c)
5330+ $(cases t.cases, pending &)
5041 ?. ?=(%cell -.c) $(cases t.cases)
5331 ?. ?=(%cell -.c) $(cases t.cases)
5042− =/ head=itype (itype-walk hed.c sub)
5332+ =/ raw-head=itype hed.c
5333+ ?: ?=(%var -.raw-head)
5334+ $(cases t.cases, pending &)
5335+ =/ head=itype (itype-walk raw-head sub)
5336+ :: A single faced, explicitly atom-only head cannot be the tag case.
5337+ :: Do not follow variables or peel nested faces for this negative proof.
5338+ ?: ?=(%face -.head)
5339+ ?: ?=(?(%atom %any-atom %flag %avar %rvar %nvar %rnvar) -.body.head)
5341+ $(cases t.cases, pending &)
5342+ ?: ?=(?(%var %tag %recursive %jrec %grec %union) -.head)
5343+ $(cases t.cases, pending &)
5043 ?. ?=(%const -.head) $(cases t.cases)
5344 ?. ?=(%const -.head) $(cases t.cases)
5044− ?. =(%term form.literal.head) $(cases t.cases)
5045 ?. =(val.literal.head val.tag) $(cases t.cases)
5345 ?. =(val.literal.head val.tag) $(cases t.cases)
5046− ?^ found [%unknown ~]
5346+ :: Equal heads can have disjoint payloads. Test each from the original
5347+ :: substitution; a unique success is usable only with no unknown rival.
5047 =/ trial=ifit (itype-fit sample tal.c sub next)
5348 =/ trial=ifit (itype-fit sample tal.c sub next)
5350+ %bad $(cases t.cases)
5351+ %unknown $(cases t.cases, pending &)
5353+ ?^ found [%unknown ~]
5048− $(cases t.cases, found `trial)
5354+ $(cases t.cases, found `trial)
5050++ itype-fit
5357++ itype-fit
5051 |= [actual=itype expected=itype sub=isub next=@ud]
5358 |= [actual=itype expected=itype sub=isub next=@ud]
5360+ =/ result=ifit (itype-fit-inner actual expected sub next | |)
5361+ ?: ?=(%ok -.result) result
5362+ =/ source=itype (itype-walk actual sub)
5363+ ?. ?=(?(%empty %face %cell %union) -.source) result
5364+ =/ empty=(unit [empty=? left=@ud]) (itype-empty-proof actual sub 256)
5365+ ?~ empty [%unknown ~]
5366+ ?: empty.u.empty [%ok sub next]
5369+ |= [actual=itype expected=itype sub=isub next=@ud skip-width=? spine-proof=?]
5371+ ?: &(!skip-width ?=(%cell -.actual) ?=(%cell -.expected) |((width-spine-exhausted actual 1.024) (width-spine-exhausted expected 1.024)))
5373+ =/ known=(unit [source=iwfields target=iwfields])
5375+ (width-known-shape actual expected sub)
5376+ =/ too-wide=? ?~(known | (gth (lent order.source.u.known) (lent order.target.u.known)))
5377+ ?: too-wide [%unknown ~]
5378+ =/ spine-checked=? |(spine-proof ?=(^ known))
5053 =/ uncertain=?
5379 =/ uncertain=?
5054− |(?=(%var -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%var -.expected) ?=(%avar -.expected) ?=(%nvar -.expected))
5380+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)))
5382+ |(?=(%var -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))
5055 =. actual (itype-walk actual sub)
5383 =. actual (itype-walk actual sub)
5056 =. expected (itype-walk expected sub)
5384 =. expected (itype-walk expected sub)
5057 ?: =(actual expected) [%ok sub next]
5385 ?: =(actual expected) [%ok sub next]
5386+ ?: &(?=(%empty -.expected) |(?=(%cell -.actual) ?=(%face -.actual) ?=(%union -.actual) ?=(%grec -.actual) ?=(%recursive -.actual))) [%unknown ~]
5387+ :: The relation of the source loobean mold to explicit @f is not yet
5388+ :: established. Keep it unsupported rather than asserting a mismatch.
5389+ ?: &(?=(%flag -.actual) ?=(%atom -.expected) =(%f aura.expected)) [%unknown ~]
5390+ :: Any value can be used where a noun is expected. An unresolved
5391+ :: bare tag is fixed as a constant; a constructor still needs a gate.
5392+ ?: ?=(%noun -.expected)
5393+ ?: ?=(%tag -.actual)
5394+ ?: constructor.actual [%unknown ~]
5395+ [%ok [[id.actual expected] sub] next]
5397+ :: An arbitrary noun is not known to fit a narrower type.
5398+ ?: &(?=(%noun -.actual) !?=(%var -.expected)) [%unknown ~]
5399+ ?: &(!uncertain ?=(%grec -.actual) ?=(%face -.expected)) $(expected body.expected)
5400+ ?: &(!uncertain ?=(%face -.actual) ?=(%grec -.expected)) $(actual body.actual)
5401+ ?: &(?=(%grec -.actual) ?=(%grec -.expected))
5402+ ?. &(=(at.actual at.expected) =(name.actual name.expected)) [%unknown ~]
5403+ =/ matched=(unit isub) (itype-unify-args args.actual args.expected sub)
5404+ ?~ matched [%unknown ~]
5405+ [%ok u.matched next]
5406+ ?: &(|(?=(%grec -.actual) ?=(%grec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5407+ ?: &(!uncertain ?=(%jrec -.actual) ?=(%face -.expected)) $(expected body.expected)
5408+ ?: &(!uncertain ?=(%face -.actual) ?=(%jrec -.expected)) $(actual body.actual)
5409+ ?: &(?=(%jrec -.actual) ?=(%jrec -.expected))
5410+ ?:(&(=(at.actual at.expected) =(name.actual name.expected) =(head.actual head.expected) =(aura.actual aura.expected) =(tail.actual tail.expected)) [%ok sub next] [%bad ~])
5411+ ?: &(|(?=(%jrec -.actual) ?=(%jrec -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5058 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
5412 ?: &(?=(%recursive -.actual) ?=(%recursive -.expected))
5059 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
5413 ?:(&(=(module.actual module.expected) =(name.actual name.expected)) [%ok sub next] [%bad ~])
5060 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
5414 ?: &(|(?=(%recursive -.actual) ?=(%recursive -.expected)) !|(?=(%var -.actual) ?=(%var -.expected))) [%unknown ~]
@@ -5066,8 +5420,21 @@
5066 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
5420 =/ unified=(unit isub) (itype-unify-args args.actual args.expected sub)
5067 ?^ unified [%ok u.unified next]
5421 ?^ unified [%ok u.unified next]
5068 [%unknown ~]
5422 [%unknown ~]
5423+ :: A known union can instantiate an unconstrained sample directly;
5424+ :: preserve unknown results for variable-bound union origins.
5425+ ?: &(!actual-open ?=(%union -.actual) ?=(%var -.expected))
5426+ ?~ origin.actual [%unknown ~]
5427+ =/ normalized=itype (itype-normalize actual sub)
5428+ ?: |((itype-has-tag normalized) (itype-has-recursive normalized) (itype-has-any-atom actual sub)) [%unknown ~]
5429+ =/ unified=(unit isub) (itype-unify actual expected sub)
5430+ ?~ unified [%unknown ~]
5431+ [%ok u.unified next]
5432+ :: A concrete union value in a tuple may acquire the expected field's
5433+ :: face. A variable-bound union still needs face propagation support.
5434+ ?: &(!uncertain ?=(%union -.actual) ?=(%face -.expected))
5435+ $(expected body.expected)
5069 ?: ?=(%union -.actual) [%unknown ~]
5436 ?: ?=(%union -.actual) [%unknown ~]
5070− ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%nvar -.actual))) [%unknown ~]
5437+ ?: &(?=(%union -.expected) |(?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)))) [%unknown ~]
5071 ?: &(?=(%union -.expected) !?=(%var -.actual))
5438 ?: &(?=(%union -.expected) !?=(%var -.actual))
5072 (itype-fit-cases actual cases.expected sub next)
5439 (itype-fit-cases actual cases.expected sub next)
5073 ?: ?=(%tag -.actual)
5440 ?: ?=(%tag -.actual)
@@ -5075,7 +5442,7 @@
5075 =/ u=(unit isub) (itype-unify actual expected sub)
5442 =/ u=(unit isub) (itype-unify actual expected sub)
5076 ?~ u [%bad ~]
5443 ?~ u [%bad ~]
5077 [%ok u.u next]
5444 [%ok u.u next]
5078− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5445+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
5079 ?: ?=(%face -.expected) $(expected body.expected)
5446 ?: ?=(%face -.expected) $(expected body.expected)
5080 ?: constructor.actual
5447 ?: constructor.actual
5081 ?. ?=(%fn -.expected) [%bad ~]
5448 ?. ?=(%fn -.expected) [%bad ~]
@@ -5103,13 +5470,17 @@
5103 =/ u=(unit isub) (itype-unify actual expected sub)
5470 =/ u=(unit isub) (itype-unify actual expected sub)
5104 ?~ u [%bad ~]
5471 ?~ u [%bad ~]
5105 [%ok u.u next]
5472 [%ok u.u next]
5106− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5473+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
5107 ?: ?=(%face -.expected) $(expected body.expected)
5474 ?: ?=(%face -.expected) $(expected body.expected)
5108 ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
5475 ?: &(?=(%collection -.expected) =(%list name.expected) =(0 val.literal.actual))
5109 [%unknown ~]
5476 [%unknown ~]
5110 ?: ?=(%const -.expected)
5477 ?: ?=(%const -.expected)
5111 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
5478 ?:(=(val.literal.actual val.literal.expected) [%ok sub next] [%bad ~])
5112 ?: ?=(%atom -.expected)
5479 ?: ?=(%atom -.expected)
5480+ :: A loobean singleton must not silently widen into another aura.
5481+ ?: =(%loobean form.literal.actual)
5482+ ?: =(%f aura.expected) [%unknown ~]
5113 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
5484 ?: |(=(%tas aura.expected) =(%ta aura.expected)) [%ok sub next]
5114 [%bad ~]
5485 [%bad ~]
5115 ?: ?=(%flag -.expected)
5486 ?: ?=(%flag -.expected)
@@ -5117,8 +5488,14 @@
5117 ?: ?=(%any-atom -.expected) [%ok sub next]
5488 ?: ?=(%any-atom -.expected) [%ok sub next]
5118 [%bad ~]
5489 [%bad ~]
5119 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
5490 ?: &(uncertain (itype-face-asym actual expected sub)) [%unknown ~]
5491+ :: A known face labels the same noun. Peel it before applying the
5492+ :: directional unrestricted-atom rule, preserving raw-variable guards.
5493+ ?: &(!uncertain ?=(%any-atom -.actual) ?=(%face -.expected))
5494+ $(expected body.expected, skip-width |, spine-proof |)
5495+ ?: &(!uncertain ?=(%any-atom -.expected) ?=(%face -.actual))
5496+ $(actual body.actual, skip-width |, spine-proof |)
5120 ?: ?=(%any-atom -.expected)
5497 ?: ?=(%any-atom -.expected)
5121− ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%nvar -.actual) ?=(%flag -.actual)) [%ok sub next]
5498+ ?: |(?=(%atom -.actual) ?=(%avar -.actual) ?=(%rvar -.actual) |(?=(%nvar -.actual) ?=(%rnvar -.actual)) ?=(%flag -.actual)) [%ok sub next]
5122 ?: ?=(%var -.actual)
5499 ?: ?=(%var -.actual)
5123 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
5500 =/ unified=(unit isub) (itype-unify actual [%avar next] sub)
5124 ?~ unified [%bad ~]
5501 ?~ unified [%bad ~]
@@ -5129,16 +5506,16 @@
5129 =/ unified=(unit isub) (itype-unify actual expected sub)
5506 =/ unified=(unit isub) (itype-unify actual expected sub)
5130 ?~ unified [%bad ~]
5507 ?~ unified [%bad ~]
5131 [%ok u.unified next]
5508 [%ok u.unified next]
5132− ?: |(?=(%avar -.expected) ?=(%nvar -.expected)) [%unknown ~]
5509+ ?: |(?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected))) [%unknown ~]
5133 [%bad ~]
5510 [%bad ~]
5134 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
5511 ?: &(?=(%atom -.actual) ?=(%atom -.expected))
5135 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
5512 ?: (aura-prefix aura.expected aura.actual) [%ok sub next]
5136 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
5513 ?: &((aura-prefix aura.actual aura.expected) uncertain) [%unknown ~]
5137 [%bad ~]
5514 [%bad ~]
5138 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5515 ?: &(?=(%cell -.actual) ?=(%cell -.expected))
5139− =/ first=ifit $(actual hed.actual, expected hed.expected)
5516+ =/ first=ifit $(actual hed.actual, expected hed.expected, skip-width |, spine-proof |)
5140 ?. ?=(%ok -.first) first
5517 ?. ?=(%ok -.first) first
5141− $(actual tal.actual, expected tal.expected, sub sub.first, next next.first)
5518+ $(actual tal.actual, expected tal.expected, sub sub.first, next next.first, skip-width spine-checked, spine-proof spine-checked)
5142 :: A field may add a face to an occurrence of the very same type
5519 :: A field may add a face to an occurrence of the very same type
5143 :: variable. Binding that variable to a face around itself would fail
5520 :: variable. Binding that variable to a face around itself would fail
5144 :: the occurs check, but its underlying type has already matched.
5521 :: the occurs check, but its underlying type has already matched.
@@ -5160,9 +5537,10 @@
5160 [%ok u.unified next]
5537 [%ok u.unified next]
5161 ?: &(?=(%face -.actual) ?=(%face -.expected))
5538 ?: &(?=(%face -.actual) ?=(%face -.expected))
5162 ?. =(name.actual name.expected) [%bad ~]
5539 ?. =(name.actual name.expected) [%bad ~]
5163− $(actual body.actual, expected body.expected)
5540+ $(actual body.actual, expected body.expected, skip-width |, spine-proof |)
5164− ?: ?=(%face -.actual) $(actual body.actual)
5541+ ?: ?=(%face -.actual) $(actual body.actual, skip-width |, spine-proof |)
5165− ?: ?=(%face -.expected) $(expected body.expected)
5542+ ?: ?=(%face -.expected) $(expected body.expected, skip-width |, spine-proof |)
5543+ ?: &(!uncertain (itype-closed-gates-match actual expected)) [%ok sub next]
5166 ?: (itype-face-asym actual expected sub) [%unknown ~]
5544 ?: (itype-face-asym actual expected sub) [%unknown ~]
5167 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
5545 ?: |((itype-has-any-atom actual sub) (itype-has-any-atom expected sub))
5168 [%unknown ~]
5546 [%unknown ~]
@@ -5238,7 +5616,18 @@
5238+$ ischeme [typ=itype vars=(list @ud)]
5616+$ ischeme [typ=itype vars=(list @ud)]
5239+$ ienv (list [name=term scheme=ischeme])
5617+$ ienv (list [name=term scheme=ischeme])
5240+$ imold-types (list [name=term template=ischeme])
5618+$ imold-types (list [name=term template=ischeme])
5241−+$ ifile [values=ienv molds=imold-types at=path]
5619++$ iderived [name=term agent=term mark=term]
5620++$ iwidth-definition [name=term original=expr typ=itype sub=isub projections=(list iwprojection)]
5621++$ iwidth-dependency [at=path source=(unit @t) definitions=(list iwidth-definition)]
5622+:: Nonrecursive request evidence is compiler-owned metadata, not a property
5623+:: of an arbitrary ask value. Reader graphs and source inputs are trusted.
5624++$ irequest-evidence
5625+ [api-at=path name=term path=iapi-path-typed api-source=@t public-source=@t internal-source=@t prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5626+:: A unit distinguishes a verified empty closure from a detached legacy file.
5627+:: The opaque prelude is an exact trusted input, not a recursive interface mold.
5629+ [paths=(set path) requests=(list irequest-evidence) bundle-input=* prelude-input=* prelude-values=(list term) prelude-molds=(list term) externals=iexternals marks=imark-externals]
5630++$ ifile [values=ienv molds=imold-types at=path derived=(list iderived) elaborations=(list iwidth-definition) dependencies=(list iwidth-dependency) source=(unit @t) graph=(unit irequest-graph)]
5242+$ ijimports (list [face=term interface=ifile])
5631+$ ijimports (list [face=term interface=ifile])
5243+$ icap [name=@t id=@ud at=span]
5632+$ icap [name=@t id=@ud at=span]
5244+$ icaps (list icap)
5633+$ icaps (list icap)
@@ -5248,7 +5637,170 @@
5248:: This core has no Ford dependencies; unrecognized payloads fail closed.
5637:: This core has no Ford dependencies; unrecognized payloads fail closed.
5249+$ iexternals (list [module=term name=term result=*])
5638+$ iexternals (list [module=term name=term result=*])
5250+$ imark-externals (list [mark=term result=*])
5639+$ imark-externals (list [mark=term result=*])
5640+:: Hole obligations survive discarded expressions until their owning
5641+:: definition has inferred; their source spans support unresolved reports.
5642++$ ihole [id=@ud at=span]
5643+:: Recursive-mold unfolding spends fuel in the threaded inference state.
5644+:: Retries can restart from an earlier state, so this bounds an attempt,
5645+:: not all parsing or module-checking work.
5646+:: Experimental: only closed, uniquely faced records have known axes.
5647++$ iwfield [name=term axis=@ud typ=itype]
5648++$ iwfields [order=(list iwfield) index=(map term iwfield)]
5649++$ iwstep [name=term axis=@ud]
5650++$ iwidth-result [steps=(list iwstep) sub=isub next=@ud]
5651++$ iwprojection [at=span original=expr source=itype target=itype steps=(list iwstep)]
5653+ |= [typ=itype sub=isub axis=@ud fuel=@ud]
5655+ =/ order=(list iwfield) ~
5656+ =/ index=(map term iwfield) *(map term iwfield)
5659+ ?: |(?=(%var -.typ) ?=(%avar -.typ) ?=(%rvar -.typ) ?=(%nvar -.typ) ?=(%rnvar -.typ)) ~
5661+ =/ entry=iwfield [name.typ axis body.typ]
5662+ ?: ?=(^ (~(get by index) name.entry)) ~
5663+ `[(flop [entry order]) (~(put by index) name.entry entry)]
5664+ ?. ?=(%cell -.typ) ~
5665+ =/ head=itype hed.typ
5666+ ?: |(?=(%var -.head) ?=(%avar -.head) ?=(%rvar -.head) ?=(%nvar -.head) ?=(%rnvar -.head)) ~
5667+ ?. ?=(%face -.head) ~
5668+ =/ entry=iwfield [name.head (mul 2 axis) body.head]
5669+ ?: ?=(^ (~(get by index) name.entry)) ~
5670+ $(typ tal.typ, axis +((mul 2 axis)), fuel (dec fuel), order [entry order], index (~(put by index) name.entry entry))
5672+ |= [source=(list iwfield) target=(list iwfield)]
5676+ ?: =(name.i.source name.i.target) $(source t.source, target t.target)
5679+ |= [source=(map term iwfield) target=(list iwfield) sub=isub next=@ud]
5680+ ^- (unit iwidth-result)
5681+ ?~ target `[~ sub next]
5682+ =/ found=(unit iwfield) (~(get by source) name.i.target)
5684+ =/ fit=ifit (itype-fit typ.u.found typ.i.target sub next)
5686+ =/ rest=(unit iwidth-result) $(target t.target, sub sub.fit, next next.fit)
5688+ `[[[name.i.target axis.u.found] steps.u.rest] sub.u.rest next.u.rest]
5689+++ width-spine-exhausted
5690+ |= [t=itype fuel=@ud]
5694+ ?. ?=(%face -.hed.t) |
5695+ $(t tal.t, fuel (dec fuel))
5696+++ width-known-shape
5697+ |= [actual=itype expected=itype sub=isub]
5698+ ^- (unit [source=iwfields target=iwfields])
5699+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5700+ =/ source=(unit iwfields) (width-scan actual sub 1 1.024)
5701+ =/ target=(unit iwfields) (width-scan expected sub 1 1.024)
5704+ `[u.source u.target]
5707+ |= [actual=itype expected=itype sub=isub]
5708+ ^- (unit [source=iwfields target=iwfields])
5709+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
5710+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5711+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5714+ ?. (gth (lent order.u.source) (lent order.u.target)) ~
5715+ `[u.source u.target]
5717+ |= [actual=itype expected=itype sub=isub]
5718+ ^- (unit [source=iwfields target=iwfields])
5719+ ?. &(|(?=(%cell -.actual) ?=(%face -.actual)) |(?=(%cell -.expected) ?=(%face -.expected))) ~
5720+ =/ source=(unit iwfields) (width-scan actual sub 1 4.096)
5721+ =/ target=(unit iwfields) (width-scan expected sub 1 4.096)
5724+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
5725+ `[u.source u.target]
5728+ |= [shape=[source=iwfields target=iwfields] sub=isub next=@ud]
5729+ ^- (unit iwidth-result)
5730+ ?. (width-in-order order.source.shape order.target.shape) ~
5731+ (width-fit-fields index.source.shape order.target.shape sub next)
5733+:: Provisional, globally budgeted gate-free proof. %no includes a
5734+:: gate-bearing witness; an uninhabited sibling could invalidate it.
5735+:: Input types must be resolved and normalized under valid substitutions,
5736+:: from trusted source-backed interfaces and reader results. Collection
5737+:: list/unit names rely on their existing identity invariant; this arm
5738+:: does not validate fabricated internal types.
5740+ $% [%field name=term]
5746++$ igate-free [verdict=?(%yes %no %unknown) inhabited=? left=@ud path=(unit (list igf-segment))]
5748+ |= [types=(list itype) fuel=@ud path=(list igf-segment) index=@ud]
5750+ ?~ types [%yes | fuel ~]
5751+ ?: =(0 fuel) [%unknown | 0 ~]
5752+ =/ first=igate-free (gate-free-type i.types fuel [[%case index] path])
5753+ ?: =(%no verdict.first) first
5754+ =/ rest=igate-free $(types t.types, fuel left.first, index +(index))
5755+ ?: =(%no verdict.rest) rest
5756+ =/ inhabited=? |(inhabited.first inhabited.rest)
5757+ ?: |(=(%unknown verdict.first) =(%unknown verdict.rest)) [%unknown inhabited left.rest ~]
5758+ [%yes inhabited left.rest ~]
5760+ |= [typ=itype fuel=@ud path=(list igf-segment)]
5762+ ?: =(0 fuel) [%unknown | 0 ~]
5765+ %fn [%no & fuel `(flop path)]
5766+ %atom [%yes & fuel ~]
5767+ %any-atom [%yes & fuel ~]
5768+ %flag [%yes & fuel ~]
5769+ %const [%yes & fuel ~]
5770+ %face $(typ body.typ, path [[%field name.typ] path])
5772+ =/ head=igate-free $(typ hed.typ, path [[%head ~] path])
5773+ =/ tail=igate-free $(typ tal.typ, fuel left.head, path [[%tail ~] path])
5774+ =/ inhabited=? &(inhabited.head inhabited.tail)
5775+ ?: |(&(=(%yes verdict.head) !inhabited.head) &(=(%yes verdict.tail) !inhabited.tail)) [%yes | left.tail ~]
5776+ ?: &(=(%no verdict.head) inhabited.tail) head(left left.tail)
5777+ ?: &(=(%no verdict.tail) inhabited.head) tail
5778+ ?: |(!=(%yes verdict.head) !=(%yes verdict.tail)) [%unknown inhabited left.tail ~]
5779+ [%yes inhabited left.tail ~]
5781+ ?. |(=(%list name.typ) =(%unit name.typ)) [%unknown | fuel ~]
5782+ ?. ?=([* ~] args.typ) [%unknown | fuel ~]
5783+ =/ item=igate-free $(typ i.args.typ, path [[%item ~] path])
5786+ ?~ cases.typ [%unknown | fuel ~]
5787+ (gate-free-types cases.typ fuel path 0)
5788+ %noun [%unknown & fuel ~]
5789+ %empty [%yes | fuel ~]
5790+ %var [%unknown | fuel ~]
5791+ %avar [%yes & fuel ~]
5792+ %rvar [%yes & fuel ~]
5793+ %nvar [%yes & fuel ~]
5794+ %rnvar [%yes & fuel ~]
5795+ %tag [%unknown | fuel ~]
5796+ %recursive [%unknown | fuel ~]
5797+ %jrec [%yes & fuel ~]
5798+ %grec [%unknown | fuel ~]
5801++$ igate-prelude-evidence [iface=ifile gates=(map term def)]
5802++$ dgo [left=itype right=itype at=span context=span]
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)]
5803++$ istate [next=@ud sub=isub caps=icaps binders=(list @ud) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) params=iparams active=(list term) tags=(list ipending) in-mold=? at=path top-molds=(list term) prelude=(unit ifile) holes=(list ihole) jrec-fuel=@ud projections=(list iwprojection) gate-defs=(map term def) head-evidence=(unit igate-prelude-evidence) grec-index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)]) defer=(unit ~) obligations=(list dgo)]
5252+$ idiag [msg=tape sites=(list [at=span note=tape])]
5804+$ idiag [msg=tape sites=(list [at=span note=tape])]
5253+$ iresult (each [typ=itype state=istate] idiag)
5805+$ iresult (each [typ=itype state=istate] idiag)
5254+$ isample-result (each [typ=itype env=ienv state=istate] tape)
5806+$ isample-result (each [typ=itype env=ienv state=istate] tape)
@@ -5268,6 +5820,7 @@
5268 |= [t=itype sub=isub]
5820 |= [t=itype sub=isub]
5269 ^- itype
5821 ^- itype
5270 =. t (itype-walk t sub)
5822 =. t (itype-walk t sub)
5823+ ?: ?=(%grec -.t) t(args (turn args.t |=(c=itype (itype-normalize c sub))))
5271 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
5824 ?: ?=(%collection -.t) [%collection name.t (turn args.t |=(c=itype (itype-normalize c sub)))]
5272 ?: ?=(%union -.t)
5825 ?: ?=(%union -.t)
5273 [%union (turn cases.t |=(c=itype (itype-normalize c sub))) origin.t label.t (turn args.t |=(c=itype (itype-normalize c sub)))]
5826 [%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 +5837,8 @@
5284:: generalize an aura from its sample, which requires constraint analysis
5837:: generalize an aura from its sample, which requires constraint analysis
5285:: beyond this fragment; leave those cases unresolved.
5838:: beyond this fragment; leave those cases unresolved.
5840+:: This helper only controls decimal defaulting in visible types. A noun
5841+:: may contain gates and is not proof of a gate-free value.
5287++ itype-has-gate
5842++ itype-has-gate
5288 |= t=itype
5843 |= t=itype
@@ -5291,6 +5846,8 @@
5292 %cell |($(t hed.t) $(t tal.t))
5847 %cell |($(t hed.t) $(t tal.t))
5293 %recursive |
5848 %recursive |
5294 %collection (lien args.t |=(c=itype (itype-has-gate c)))
5851 %collection (lien args.t |=(c=itype (itype-has-gate c)))
5295 %face $(t body.t)
5852 %face $(t body.t)
5296 %union (lien cases.t |=(c=itype (itype-has-gate c)))
5853 %union (lien cases.t |=(c=itype (itype-has-gate c)))
@@ -5298,10 +5855,14 @@
5298 %const |
5855 %const |
5303 %any-atom |
5862 %any-atom |
5307++ default-decimals
5868++ default-decimals
@@ -5310,26 +5871,136 @@
5310 ?: (itype-has-gate t) t
5871 ?: (itype-has-gate t) t
5312 %nvar [%atom %ud]
5873 %nvar [%atom %ud]
5875+ %grec t(args (turn args.t |=(c=itype (default-decimals c))))
5313 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
5876 %collection [%collection name.t (turn args.t |=(c=itype (default-decimals c)))]
5314 %face [%face name.t $(t body.t)]
5877 %face [%face name.t $(t body.t)]
5315 %cell [%cell $(t hed.t) $(t tal.t)]
5878 %cell [%cell $(t hed.t) $(t tal.t)]
5882+:: A hole is solved only by a fully determined type or a written
5883+:: in-scope type variable. Ordinary fresh variables are not evidence.
5884+:: Compare representatives after substitution, since unification can
5885+:: orient a written capital toward the hole rather than the reverse.
5898+++ hole-same-variable
5899+ |= [a=itype b=itype]
5901+ =/ x=(unit @ud) (hole-variable-id a)
5903+ =/ y=(unit @ud) (hole-variable-id b)
5907+ |= [t=itype state=istate]
5909+ =. t (itype-walk t sub.state)
5911+ ?(%var %avar %rvar %nvar %rnvar)
5912+ ?: (lien caps.state |=(c=icap (hole-same-variable t (itype-walk [%var id.c] sub.state)))) &
5913+ (lien params.state |=(p=[name=@t typ=itype] (hole-same-variable t (itype-walk typ.p sub.state))))
5916+ %union &((levy cases.t |=(c=itype (hole-known c state))) (levy args.t |=(c=itype (hole-known c state))))
5917+ %grec (levy args.t |=(c=itype (hole-known c state)))
5918+ %collection (levy args.t |=(c=itype (hole-known c state)))
5920+ %fn &($(t sample.t) $(t product.t))
5921+ %cell &($(t hed.t) $(t tal.t))
5924+++ promote-restricted-numbers
5925+ |= [state=istate env=ienv]
5927+ :: With no written capitals, there is nothing to promote.
5928+ ?~ caps.state state
5929+ =/ ids=(list @ud) (turn caps.state |=(c=icap id.c))
5930+ =/ free=(list @ud) (free-env-vars env sub.state)
5933+ =/ t=itype (itype-walk [%var i.ids] sub.state)
5934+ ?: &(?=(%rnvar -.t) !(lien free |=(n=@ud =(n +.t))))
5935+ $(ids t.ids, state state(sub [[+.t [%rvar +.t]] sub.state]))
5938+++ default-hole-numbers
5939+ |= [all=(list ihole) prior=(list ihole) state=istate env=ienv permit=?]
5941+ :: Do not default a named capital or a variable captured from env.
5943+ ?: =(all prior) state
5945+ =/ t=itype (itype-walk [%var id.i.all] sub.state)
5946+ =/ free=(list @ud) (free-env-vars env sub.state)
5947+ =? state &(?=(?(%nvar %rnvar) -.t) !(hole-known t state) !(lien free |=(id=@ud =(id id.t))))
5948+ state(sub [[id.t [%atom %ud]] sub.state])
5951+:: Only obligations created inside this definition belong to it.
5953+ |= [all=(list ihole) prior=(list ihole)]
5957+ [i.all $(all t.all)]
5959+ |= [t=itype state=istate]
5961+ =. t (itype-walk t sub.state)
5963+ ?(%tag %nvar %rnvar %avar %rvar) !(hole-known t state)
5964+ %union |((lien cases.t |=(c=itype (hole-uncertain c state))) (lien args.t |=(c=itype (hole-uncertain c state))))
5965+ %grec (lien args.t |=(c=itype (hole-uncertain c state)))
5966+ %collection (lien args.t |=(c=itype (hole-uncertain c state)))
5968+ %fn |($(t sample.t) $(t product.t))
5969+ %cell |($(t hed.t) $(t tal.t))
5974+ |= [all=(list ihole) prior=(list ihole) state=istate]
5976+ =/ work=(list ihole) (flop (holes-created all prior))
5979+ ?: (hole-known [%var id.i.work] state) $(work t.work)
5980+ ?: (hole-uncertain [%var id.i.work] state)
5981+ `["type hole needs unsupported inference" ~[[at.i.work "type hole"]]]
5982+ `["type hole needs a determined type" ~[[at.i.work "unresolved type hole"]]]
5319++ itype-vars
5984++ itype-vars
5320 |= t=itype
5985 |= t=itype
5321 ^- (list @ud)
5986 ^- (list @ud)
5323 %var ~[id.t]
5988 %var ~[id.t]
5324 %avar ~[id.t]
5989 %avar ~[id.t]
5325 %nvar ~[id.t]
5991 %nvar ~[id.t]
5327 %any-atom ~
5994 %any-atom ~
5330 %const ~
5999 %const ~
5331 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
6000 %union (zing (turn (weld args.t cases.t) |=(c=itype (itype-vars c))))
5332 %recursive ~
6001 %recursive ~
6003+ %grec (zing (turn args.t |=(c=itype (itype-vars c))))
5333 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
6004 %collection (zing (turn args.t |=(c=itype (itype-vars c))))
5334 %face $(t body.t)
6005 %face $(t body.t)
5335 %fn (weld $(t sample.t) $(t product.t))
6006 %fn (weld $(t sample.t) $(t product.t))
@@ -5357,17 +6028,29 @@
5357 =/ found=(unit itype) (itype-lookup id.t ren)
6028 =/ found=(unit itype) (itype-lookup id.t ren)
5358 ?~ found t
6029 ?~ found t
6032+ =/ found=(unit itype) (itype-lookup id.t ren)
5361 =/ found=(unit itype) (itype-lookup id.t ren)
6036 =/ found=(unit itype) (itype-lookup id.t ren)
5362 ?~ found t
6037 ?~ found t
6040+ =/ found=(unit itype) (itype-lookup id.t ren)
5365 %any-atom t
6044 %any-atom t
5368 %const t
6049 %const t
5369 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
6050 %union [%union (turn cases.t |=(c=itype (itype-rename c ren))) origin.t label.t (turn args.t |=(c=itype (itype-rename c ren)))]
5370 %recursive t
6051 %recursive t
6053+ %grec t(args (turn args.t |=(c=itype (itype-rename c ren))))
5371 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
6054 %collection [%collection name.t (turn args.t |=(c=itype (itype-rename c ren)))]
5372 %face [%face name.t $(t body.t)]
6055 %face [%face name.t $(t body.t)]
5373 %fn [%fn $(t sample.t) $(t product.t)]
6056 %fn [%fn $(t sample.t) $(t product.t)]
@@ -5383,19 +6066,50 @@
5385 %avar =(n id.t)
6068 %avar =(n id.t)
5386 %nvar =(n id.t)
6070 %nvar =(n id.t)
5388 %any-atom |
6073 %any-atom |
5391 %const |
6078 %const |
5392 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
6079 %union |((lien cases.t |=(c=itype (itype-var-is-atom n c))) (lien args.t |=(c=itype (itype-var-is-atom n c))))
5393 %recursive |
6080 %recursive |
6082+ %grec (lien args.t |=(c=itype (itype-var-is-atom n c)))
5394 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
6083 %collection (lien args.t |=(c=itype (itype-var-is-atom n c)))
5395 %face $(t body.t)
6084 %face $(t body.t)
5396 %fn |($(t sample.t) $(t product.t))
6085 %fn |($(t sample.t) $(t product.t))
5397 %cell |($(t hed.t) $(t tal.t))
6086 %cell |($(t hed.t) $(t tal.t))
6088+++ itype-var-is-restricted
6104+ %union |((lien cases.t |=(c=itype (itype-var-is-restricted n c))) (lien args.t |=(c=itype (itype-var-is-restricted n c))))
6107+ %grec (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6108+ %collection (lien args.t |=(c=itype (itype-var-is-restricted n c)))
6110+ %fn |($(t sample.t) $(t product.t))
6111+ %cell |($(t hed.t) $(t tal.t))
5400:: Canonical numbering makes printed variables independent of the order
6114:: Canonical numbering makes printed variables independent of the order
5401:: the unifier happened to allocate intermediates.
6115:: the unifier happened to allocate intermediates.
@@ -5407,7 +6121,7 @@
5407 =/ n=@ud 0
6121 =/ n=@ud 0
5409 ?~ vars (itype-rename t ren)
6123 ?~ vars (itype-rename t ren)
5410− =/ replacement=itype ?:((itype-var-is-atom i.vars t) [%avar n] [%var n])
6124+ =/ replacement=itype ?:((itype-var-is-restricted i.vars t) [%rvar n] ?:((itype-var-is-atom i.vars t) [%avar n] [%var n]))
5411 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
6125 $(vars t.vars, ren [[i.vars replacement] ren], n +(n))
5413++ instantiate-scheme
6127++ instantiate-scheme
@@ -5418,11 +6132,11 @@
5419 ?~ vars [(itype-rename typ.scheme ren) state]
6133 ?~ vars [(itype-rename typ.scheme ren) state]
5420 =/ replacement=itype
6134 =/ replacement=itype
5421− ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state])
6135+ ?:((itype-var-is-restricted i.vars typ.scheme) [%rvar next.state] ?:((itype-var-is-atom i.vars typ.scheme) [%avar next.state] [%var next.state]))
5422 :: A generalized atom variable is a valid origin for re-generalizing
6136 :: A generalized atom variable is a valid origin for re-generalizing
5423 :: an alias, just as a sample binder is.
6137 :: an alias, just as a sample binder is.
5424 =/ st=istate state(next +(next.state))
6138 =/ st=istate state(next +(next.state))
5425− =? binders.st ?=(%avar -.replacement) [next.state binders.state]
6139+ =? binders.st |(?=(%avar -.replacement) ?=(%rvar -.replacement)) [next.state binders.state]
5426 $(vars t.vars, ren [[i.vars replacement] ren], state st)
6140 $(vars t.vars, ren [[i.vars replacement] ren], state st)
5428++ icap-lookup
6142++ icap-lookup
@@ -5493,6 +6207,11 @@
5493 ?. ?=([%ref @ @] node) ~
6207 ?. ?=([%ref @ @] node) ~
5494 ?. &(=(module +<.node) =(name +>.node)) ~
6208 ?. &(=(module +<.node) =(name +>.node)) ~
5495 `[[%unknown ~] &]
6209 `[[%unknown ~] &]
6211+ ?. ?=([%apply %list [* ~]] node) ~
6212+ =/ item $(node -.+>.node)
6214+ `[[%or ~[[%atom `0] [%cell pat.u.item [%unknown ~]]]] has.u.item]
5497 ?. ?=([%face @ *] node) ~
6216 ?. ?=([%face @ *] node) ~
5498 ?. (jibb-face-name +<.node) ~
6217 ?. (jibb-face-name +<.node) ~
@@ -5547,6 +6266,10 @@
5547 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
6266 %cell ?:(?=([%cell * *] node) (imported-record-faces-valid node ~) |)
5548 %fork (imported-faces-valid-list +.node)
6267 %fork (imported-faces-valid-list +.node)
5549 %apply ?:(?=([%apply @ *] node) (imported-faces-valid-list +>.node) |)
6268 %apply ?:(?=([%apply @ *] node) (imported-faces-valid-list +>.node) |)
6270+ ?. ?=([%named @ @ *] node) |
6271+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6272+ (imported-faces-valid body.n)
5552++ imported-faces-valid-list
6275++ imported-faces-valid-list
@@ -5578,7 +6301,19 @@
5578 ^- (unit itype)
6301 ^- (unit itype)
5579 ?@ node ~
6302 ?@ node ~
5580 ?+ -.node ~
6303 ?+ -.node ~
6304+ %noun ?:(=(node [%noun ~]) `[%noun ~] ~)
6306+ :: A Hoon loobean singleton is one of the two Jibb loobeans.
6307+ ?: ?=([%atom %f [~ @]] node)
6308+ =/ value=@ +>+.node
6309+ ?. |(=(value 0) =(value 1)) ~
6310+ =/ printed=@t ?:(=(value 0) '%.y' '%.n')
6311+ `[%const [%loobean %f value printed]]
6312+ :: Hoon's null singleton is the same noun as Jibb's `~` mold.
6313+ :: Other non-term singleton atoms remain unsupported here.
6314+ ?: ?=([%atom %n [~ @]] node)
6316+ `[%const [%null %n 0 '~']]
5582 ?: ?=([%atom %tas [~ @]] node)
6317 ?: ?=([%atom %tas [~ @]] node)
5583 =/ value=@ +>+.node
6318 =/ value=@ +>+.node
5584 ?. |(=(value 0) (jibb-face-name value)) ~
6319 ?. |(=(value 0) (jibb-face-name value)) ~
@@ -5588,6 +6323,15 @@
5588 =/ aura=@ta (@ta +<.node)
6323 =/ aura=@ta (@ta +<.node)
5589 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
6324 ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
5590 `[%atom aura]
6325 `[%atom aura]
6327+ ?. ?=([%named @ @ *] node) ~
6328+ =/ n=[%named module=@ name=@ body=*] ;;([%named module=@ name=@ body=*] node)
6329+ ?. &((jibb-face-name module.n) (jibb-face-name name.n)) ~
6330+ ?. ?=([%fork *] body.n) ~
6331+ =/ proof=(unit irec-pattern) (rec-pattern body.n (@tas module.n) (@tas name.n))
6334+ `[%recursive (@tas module.n) (@tas name.n) `(crip "{(trip name.n)}.{(trip module.n)}")]
5592 ?. ?=([%apply @ *] node) ~
6336 ?. ?=([%apply @ *] node) ~
5593 =/ name=term (@tas +<.node)
6337 =/ name=term (@tas +<.node)
@@ -5601,10 +6345,15 @@
5601 ?. =(arity (lent u.args)) ~
6345 ?. =(arity (lent u.args)) ~
5602 `[%collection name u.args]
6346 `[%collection name u.args]
6348+ :: Hoon's ordinary ? mold is the fork of its two %f singletons.
6350+ ?: |(=(raw ~[[%atom %f `0] [%atom %f `1]]) =(raw ~[[%atom %f `1] [%atom %f `0]]))
5604− =/ cases=(unit (list itype)) (import-to-itypes +.node)
6352+ =/ cases=(unit (list itype)) (import-to-itypes raw)
5605 ?~ cases ~
6353 ?~ cases ~
5606 ?~ u.cases ~
6354 ?~ u.cases ~
5607 ?~ t.u.cases ~
6355 ?~ t.u.cases ~
6356+ ?: (import-has-loobean-singleton u.cases) ~
5608 ?. (import-cases-disjoint u.cases) ~
6357 ?. (import-cases-disjoint u.cases) ~
5609 `[%union u.cases ~ ~ ~]
6358 `[%union u.cases ~ ~ ~]
@@ -5623,6 +6372,20 @@
5623 `[%cell u.left u.right]
6372 `[%cell u.left u.right]
6375+++ import-direct-loobean
6378+ ?: ?=(%face -.t) $(t body.t)
6379+ ?: ?=(%union -.t) (import-has-loobean-singleton cases.t)
6380+ ?=([%const [%loobean *]] t)
6382+++ import-has-loobean-singleton
6383+ |= cases=(list itype)
6386+ ?: (import-direct-loobean i.cases) &
5626++ import-to-itypes
6389++ import-to-itypes
5627 |= nodes=*
6390 |= nodes=*
5628 ^- (unit (list itype))
6391 ^- (unit (list itype))
@@ -5637,7 +6400,10 @@
5637 |= typ=itype
6400 |= typ=itype
5639 ?- -.typ
6402 ?- -.typ
5640 %atom [%atom ~]
6405 %atom [%atom ~]
6406+ %flag [%or ~[[%atom `0] [%atom `1]]]
5641 %const [%atom `val.literal.typ]
6407 %const [%atom `val.literal.typ]
5642 %face $(typ body.typ)
6408 %face $(typ body.typ)
5643 %cell [%cell $(typ hed.typ) $(typ tal.typ)]
6409 %cell [%cell $(typ hed.typ) $(typ tal.typ)]
@@ -5732,25 +6498,85 @@
5732 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
6498 ?:(=(`origin origin.typ.template) `name.i.molds $(molds t.molds))
5733 $(molds t.molds)
6499 $(molds t.molds)
6501+:: A prelude union alias is a display name, not a new union identity. An
6502+:: identity-generic alias can carry the origin's arguments only when the
6503+:: origin, arity and ordered parameters match. Swapped, repeated, fixed
6504+:: or phantom parameters cannot be printed that way and remain unsupported
6505+:: when their only available name is private. A nongeneric alias of a
6506+:: generic instantiation cannot be printed with the origin's arguments.
6507+++ identity-union-parameters
6508+ |= [vars=(list @ud) args=(list itype)]
6512+ ?. =([%var i.vars] i.args) |
6513+ $(vars t.vars, args t.args)
6514+++ prelude-union-alias
6515+ |= [origin=[at=path name=term] args=(list itype) molds=imold-types]
6518+ =/ template=ischeme template.i.molds
6519+ ?. ?=(%union -.typ.template) $(molds t.molds)
6520+ ?. =(`origin origin.typ.template) $(molds t.molds)
6522+ ?^ args $(molds t.molds)
6523+ ?:(=(args args.typ.template) `name.i.molds $(molds t.molds))
6524+ ?: &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args)))
5735−:: Only names exported by this directly imported module are visible through
6528+:: Names exported by the directly imported module are visible through its
5736−:: its face. Other origins retain identity but print as unnamed unions.
6529+:: face; a matching prelude alias is also visible without a qualifier.
6532+ |= [origin=path name=term molds=imold-types]
6535+ =/ template=ischeme template.i.molds
6536+ ?: &(?=(~ vars.template) ?=(%jrec -.typ.template) =(at.typ.template origin) =(name.typ.template name)) `name.i.molds
6539+++ grec-visible-alias
6540+ |= [origin=path name=term proof=shape args=(list itype) molds=imold-types]
6543+ =/ template=ischeme template.i.molds
6544+ ?. ?=(%grec -.typ.template) $(molds t.molds)
6545+ ?. &(=(at.typ.template origin) =(name.typ.template name) =(proof.typ.template proof)) $(molds t.molds)
6546+ ?. &((identity-union-parameters vars.template args.typ.template) =((lent vars.template) (lent args))) $(molds t.molds)
5738++ itype-in-import
6549++ itype-in-import
5739− |= [t=itype iface=ifile face=term]
6550+ |= [t=itype iface=ifile face=term prelude=(unit ifile)]
5740 ^- itype
6551 ^- itype
5743 =/ label=(unit @t)
6554 =/ label=(unit @t)
5744 ?~ origin.t ~
6555 ?~ origin.t ~
5745 ?: =(at.u.origin.t /lib/jibb/prelude/jibb) `name.u.origin.t
6556 ?: =(at.u.origin.t /lib/jibb/prelude/jibb) `name.u.origin.t
6557+ =/ public=(unit term)
6559+ (prelude-union-alias u.origin.t args.t molds.u.prelude)
6560+ ?^ public `u.public
5746 =/ alias=(unit term) ~
6561 =/ alias=(unit term) ~
5747 =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
6562 =? alias &(=(at.u.origin.t at.iface) ?=(^ (find-jibb-mold name.u.origin.t iface))) `name.u.origin.t
5748 =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
6563 =? alias ?=(~ alias) (imported-union-alias u.origin.t molds.iface)
5749 ?~ alias ~
6564 ?~ alias ~
5750 `(crip "{(trip u.alias)}.{(trip face)}")
6565 `(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)))]
6566+ [%union (turn cases.t |=(c=itype (itype-in-import c iface face prelude))) origin.t label (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
5752 %recursive [%recursive module.t name.t ~]
6567 %recursive [%recursive module.t name.t ~]
6569+ =/ public=(unit term) ?~(prelude ~ (grec-visible-alias at.t name.t proof.t args.t molds.u.prelude))
6570+ =/ alias=(unit term) ?~(public (grec-visible-alias at.t name.t proof.t args.t molds.iface) public)
6571+ =/ label=(unit @t) ?~(alias ~ ?~(public `(crip "{(trip u.alias)}.{(trip face)}") `u.alias))
6572+ t(label label, args (turn args.t |=(c=itype (itype-in-import c iface face prelude))))
6574+ =/ public=(unit term) ?~(prelude ~ (jrec-alias at.t name.t molds.u.prelude))
6575+ ?^ public t(label `u.public)
6576+ =/ alias=(unit term) (jrec-alias at.t name.t molds.iface)
6577+ ?~ alias t(label ~)
6578+ t(label `(crip "{(trip u.alias)}.{(trip face)}"))
5753− %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face)))]
6579+ %collection [%collection name.t (turn args.t |=(c=itype (itype-in-import c iface face prelude)))]
5754 %face [%face name.t $(t body.t)]
6580 %face [%face name.t $(t body.t)]
5755 %fn [%fn $(t sample.t) $(t product.t)]
6581 %fn [%fn $(t sample.t) $(t product.t)]
5756 %cell [%cell $(t hed.t) $(t tal.t)]
6582 %cell [%cell $(t hed.t) $(t tal.t)]
@@ -5823,9 +6649,66 @@
5823 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
6649 =/ rest=[params=iparams vars=(list @ud) next=@ud] $(names t.names, next +(next))
5824 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
6650 [[[i.names [%var next]] params.rest] [next vars.rest] next.rest]
6652+:: Recognize a unique top-level source mold with exactly a null case and a
6653+:: faced atom-headed cell whose faced tail names that same mold. Its Jibb
6654+:: path and name provide nominal identity. Other recursive shapes fail closed;
6655+:: construction and matching expose the proven shape one layer at a time.
6656+++ simple-source-recursive
6657+ |= [name=term sh=shape state=istate]
6659+ ?. (lien top-molds.state |=(n=term =(n name))) ~
6660+ =/ original=(unit shape) (find-simple-mold name molds.state)
6662+ ?. =(u.original sh) ~
6663+ ?. ?=(%union -.sh) ~
6664+ =/ cs=(list shape) cases.sh
6668+ ?. ?=(%const -.i.cs) ~
6669+ ?. =(%null form.lit.i.cs) ~
6670+ ?. ?=(%cell -.i.t.cs) ~
6671+ =/ fs=(list field) fields.i.t.cs
6675+ ?. ?=(%face -.i.fs) ~
6676+ ?. ?=(%aura -.shape.i.fs) ~
6677+ ?. !=(0 aura.shape.i.fs) ~
6678+ ?. ?=(%face -.i.t.fs) ~
6679+ ?. !=(name.i.fs name.i.t.fs) ~
6680+ =/ tail=shape shape.i.t.fs
6681+ ?. ?=(%ref -.tail) ~
6682+ ?. =(names.tail ~[name]) ~
6683+ `[%jrec at.state name `name name.i.fs aura.shape.i.fs name.i.t.fs]
6685+++ simple-source-generic-recursive
6686+ |= [name=term sh=shape args=(list itype) state=istate]
6688+ ?. ?=(%generic -.sh) ~
6689+ ?. ?=([@ ~] vars.sh) ~
6690+ ?. ?=([* ~] args) ~
6691+ ?~ grec-index.state ~
6692+ ?. =(at.u.grec-index.state at.state) ~
6694+ ?. =(prelude.u.grec-index.state u.prelude.state) ~
6695+ =/ proof=(unit shape) (~(get by shapes.u.grec-index.state) name)
6698+ `[%grec at.state name `name sh args]
5826++ infer-mold-template
6701++ infer-mold-template
5827 |= [sh=shape state=istate]
6702 |= [sh=shape state=istate]
5828 ^- (unit [template=ischeme state=istate])
6703 ^- (unit [template=ischeme state=istate])
6704+ =/ generic=(unit itype)
6705+ ?. ?=([@ ~] active.state) ~
6706+ (simple-source-generic-recursive i.active.state sh ~[[%var next.state]] state)
6707+ ?^ generic `[[u.generic ~[next.state]] state(next +(next.state))]
6708+ =/ direct=(unit itype)
6709+ ?. ?=([@ ~] active.state) ~
6710+ (simple-source-recursive i.active.state sh state)
6711+ ?^ direct `[[u.direct ~] state]
5829 ?: ?=(%generic -.sh)
6712 ?: ?=(%generic -.sh)
5830 ?~ vars.sh ~
6713 ?~ vars.sh ~
5831 ?. (distinct-params vars.sh) ~
6714 ?. (distinct-params vars.sh) ~
@@ -5833,17 +6716,19 @@
5833 =/ out=(unit [typ=itype state=istate])
6716 =/ out=(unit [typ=itype state=istate])
5834 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
6717 (infer-simple-shape body.sh state(next next.fresh, params params.fresh, in-mold &))
5835 ?~ out ~
6718 ?~ out ~
6719+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
5836 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
6720 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.sh) ?=(~ origin.typ.u.out)) ~
5837 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
6721 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.sh))
5838 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
6722 typ.u.out(args (turn vars.fresh |=(n=@ud `itype`[%var n])))
5839 =/ used=(list @ud) (itype-vars typ.u.out)
6723 =/ used=(list @ud) (itype-vars typ.u.out)
5840 ?. (levy used |=(n=@ud (lien vars.fresh |=(p=@ud =(p n))))) ~
6724 ?. (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)]
6725+ `[[typ.u.out vars.fresh] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
5842 =/ out=(unit [typ=itype state=istate])
6726 =/ out=(unit [typ=itype state=istate])
5843 (infer-simple-shape sh state(params ~, in-mold &))
6727 (infer-simple-shape sh state(params ~, in-mold &))
5844 ?~ out ~
6728 ?~ out ~
6729+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.out) ~
5845 ?: ?=(^ (itype-vars typ.u.out)) ~
6730 ?: ?=(^ (itype-vars typ.u.out)) ~
5846− `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state)]
6731+ `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state, holes holes.state)]
5848:: A direct imported reference may carry definite reader evidence. Only
6733:: A direct imported reference may carry definite reader evidence. Only
5849:: uniquely supplied, declared inputs are used; unsupported data stay generic.
6734:: uniquely supplied, declared inputs are used; unsupported data stay generic.
@@ -5877,7 +6762,7 @@
5877 ?~ found ~
6762 ?~ found ~
5878 ?^ t.found ~
6763 ?^ t.found ~
5879 result.i.found
6764 result.i.found
5880− ?. ?=([%invalid ?(%aura %core) @] raw) ~
6765+ ?. ?=([%invalid ?(%aura %core %overlap) @] raw) ~
5881 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
6766 `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
5883:: Replay only the shape branches whose evaluation order we can prove.
6768:: Replay only the shape branches whose evaluation order we can prove.
@@ -5946,16 +6831,24 @@
5946 |= [sh=shape state=istate]
6831 |= [sh=shape state=istate]
5947 ^- (unit [typ=itype state=istate])
6832 ^- (unit [typ=itype state=istate])
6834+ %hole `[[%var next.state] state(next +(next.state), holes [[next.state at.sh] holes.state])]
5950 ?: =(0 aura.sh) `[[%any-atom ~] state]
6836 ?: =(0 aura.sh) `[[%any-atom ~] state]
5951 `[[%atom aura.sh] state]
6837 `[[%atom aura.sh] state]
5952 %flag `[[%flag ~] state]
6838 %flag `[[%flag ~] state]
6839+ %noun `[[%noun ~] state]
6840+ %void `[[%empty ~] state]
5954− ?. |(=(%term form.lit.sh) =(%null form.lit.sh)) ~
6842+ ?. |(=(%term form.lit.sh) =(%null form.lit.sh) =(%loobean form.lit.sh)) ~
6843+ ?: &(=(%loobean form.lit.sh) !|(=(0 val.lit.sh) =(1 val.lit.sh))) ~
5955 `[[%const lit.sh] state]
6844 `[[%const lit.sh] state]
5957 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
6846 =/ pairs=(list upair) (union-pairs cases.sh molds.state)
6847+ ?: (lien pairs |=(p=upair =(%overlap relation.p))) ~
5958− ?. (levy pairs |=(p=upair =(%disjoint relation.p))) ~
6849+ ?: (levy pairs |=(p=upair =(%disjoint relation.p))) &
6850+ &((union-source-state-safe state 256) (union-source-distinct-tags cases.sh molds.state 256))
5959 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
6852 =/ cs=(unit [types=(list itype) state=istate]) (infer-shape-args cases.sh state)
5961 `[[%union types.u.cs ~ ~ ~] state.u.cs]
6854 `[[%union types.u.cs ~ ~ ~] state.u.cs]
@@ -5976,7 +6869,7 @@
5976 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
6869 =/ found=(unit ischeme) (find-jibb-mold n u.iface)
5977 ?~ found ~
6870 ?~ found ~
5978 ?^ vars.u.found ~
6871 ?^ vars.u.found ~
5979− `[(itype-in-import typ.u.found u.iface i.t.names.sh) state]
6872+ `[(itype-in-import typ.u.found u.iface i.t.names.sh prelude.state) state]
5980 =/ found=(unit itype)
6873 =/ found=(unit itype)
5981 (find-imported-mold i.t.names.sh n externals.state surs.state)
6874 (find-imported-mold i.t.names.sh n externals.state surs.state)
5982 ?~ found ~
6875 ?~ found ~
@@ -5995,10 +6888,13 @@
5995 ?~ prelude-entry ~
6888 ?~ prelude-entry ~
5996 ?^ vars.u.prelude-entry ~
6889 ?^ vars.u.prelude-entry ~
5997 `[typ.u.prelude-entry state]
6890 `[typ.u.prelude-entry state]
6891+ =/ direct=(unit itype) (simple-source-recursive n u.found state)
6892+ ?^ direct `[u.direct state]
5998 =/ out=(unit [typ=itype state=istate])
6893 =/ out=(unit [typ=itype state=istate])
5999 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
6894 $(sh u.found, state state(active [n active.state], in-mold &, params ~))
6000 ?~ out ~
6895 ?~ out ~
6896+ ?^ (unresolved-hole holes.state.u.out holes.state state.u.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)]
6897+ `[(label-direct-union typ.u.out u.found n state) state.u.out(active active.state, in-mold in-mold.state, params params.state, holes holes.state)]
6003 ?~ ref.sh ~
6899 ?~ ref.sh ~
6004 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
6900 =/ args=(unit [types=(list itype) state=istate]) (infer-shape-args args.sh state)
@@ -6013,7 +6909,7 @@
6013 ?~ vars.u.template ~
6909 ?~ vars.u.template ~
6014 =/ applied=(unit itype) (template-apply u.template types.u.args)
6910 =/ applied=(unit itype) (template-apply u.template types.u.args)
6015 ?~ applied ~
6911 ?~ applied ~
6016− `[(itype-in-import u.applied u.iface i.t.ref.sh) state.u.args]
6912+ `[(itype-in-import u.applied u.iface i.t.ref.sh prelude.state.u.args) state.u.args]
6017 ?: (lien active.state.u.args |=(x=term =(x n))) ~
6913 ?: (lien active.state.u.args |=(x=term =(x n))) ~
6018 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
6914 =/ found=(unit shape) (find-simple-mold n molds.state.u.args)
6019 ?~ found
6915 ?~ found
@@ -6026,17 +6922,20 @@
6026 ?~ applied ~
6922 ?~ applied ~
6027 `[u.applied state.u.args]
6923 `[u.applied state.u.args]
6028 ?. ?=(%generic -.u.found) ~
6924 ?. ?=(%generic -.u.found) ~
6925+ =/ grec=(unit itype) (simple-source-generic-recursive n u.found types.u.args state.u.args)
6926+ ?^ grec `[u.grec state.u.args]
6029 ?. (distinct-params vars.u.found) ~
6927 ?. (distinct-params vars.u.found) ~
6030 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
6928 =/ params=(unit iparams) (bind-params vars.u.found types.u.args)
6031 ?~ params ~
6929 ?~ params ~
6032 =/ out=(unit [typ=itype state=istate])
6930 =/ out=(unit [typ=itype state=istate])
6033 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
6931 $(sh body.u.found, state state.u.args(active [n active.state.u.args], in-mold &, params u.params))
6034 ?~ out ~
6932 ?~ out ~
6933+ ?^ (unresolved-hole holes.state.u.out holes.state.u.args state.u.out) ~
6035 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
6934 ?: &(?=(%union -.typ.u.out) !?=(%union -.body.u.found) ?=(~ origin.typ.u.out)) ~
6036 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
6935 ?: &(?=(%union -.typ.u.out) ?=(%union -.body.u.found) !(lien top-molds.state.u.args |=(x=term =(x n)))) ~
6037 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
6936 =? typ.u.out &(?=(%union -.typ.u.out) ?=(%union -.body.u.found))
6038 (label-direct-union typ.u.out(args types.u.args) u.found n state.u.args)
6937 (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)]
6938+ `[typ.u.out state.u.out(active active.state.u.args, in-mold in-mold.state.u.args, params params.state.u.args, holes holes.state.u.args)]
6041 =/ param=(unit itype) (iparam-lookup name.sh params.state)
6940 =/ param=(unit itype) (iparam-lookup name.sh params.state)
6042 ?^ param `[u.param state]
6941 ?^ param `[u.param state]
@@ -6076,12 +6975,12 @@
6076 ^- isample-result
6975 ^- isample-result
6079− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6978+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6080 [%| "sample shadows a name"]
6979 [%| "sample shadows a name"]
6081 =/ t=itype [%var next.state]
6980 =/ t=itype [%var next.state]
6082 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
6981 [%& t [[name.s [t ~]] env] state(next +(next.state), binders [next.state binders.state])]
6084− ?: |(?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6983+ ?: |(=(name.s %proj) ?=(^ (ienv-lookup name.s env)) (lien globals.state |=(x=term =(x name.s))))
6085 [%| "sample shadows a name"]
6984 [%| "sample shadows a name"]
6086 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
6985 =/ t=(unit [typ=itype state=istate]) (infer-simple-shape shape.s state)
6087 ?~ t [%| "sample mold is not supported by partial inference"]
6986 ?~ t [%| "sample mold is not supported by partial inference"]
@@ -6119,8 +7018,8 @@
6119 [%& [%cell ht typ.p.tail] env.p.tail state.p.tail]
7018 [%& [%cell ht typ.p.tail] env.p.tail state.p.tail]
6121:: Local definitions generalize only variables outside their enclosing
7020:: Local definitions generalize only variables outside their enclosing
6122−:: environment and explicit-capital scope. Single self-recursive gates
7021+:: environment and explicit-capital scope. Recursive gate groups use
6123−:: use a monomorphic placeholder; mutually recursive groups stay unsupported.
7022+:: monomorphic placeholders while their bodies are checked.
6125+$ ilocal-result (each [env=ienv state=istate] idiag)
7024+$ ilocal-result (each [env=ienv state=istate] idiag)
6126++ free-env-vars
7025++ free-env-vars
@@ -6149,6 +7048,7 @@
6151 ?: ?=(%mold -.i.ds) $(ds t.ds)
7050 ?: ?=(%mold -.i.ds) $(ds t.ds)
7051+ ?: =(name.i.ds %proj) |
6152 ?. (unique-value-name name.i.ds names) |
7052 ?. (unique-value-name name.i.ds names) |
6153 ?: ?=(^ (ienv-lookup name.i.ds env)) |
7053 ?: ?=(^ (ienv-lookup name.i.ds env)) |
6154 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
7054 ?: (lien globals.state |=(n=term =(n name.i.ds))) |
@@ -6172,6 +7072,7 @@
6173 ?~ locals &
7073 ?~ locals &
6174 =/ n=term name.i.locals
7074 =/ n=term name.i.locals
6175 ?. (unique-value-name n names) |
7076 ?. (unique-value-name n names) |
6176 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
7077 ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) |
6177 ?: (lien marks.state |=(m=term =(n m))) |
7078 ?: (lien marks.state |=(m=term =(n m))) |
@@ -6336,7 +7237,13 @@
6338 ?~ remaining [%& env state]
7239 ?~ remaining [%& env state]
7241+ =/ pending=(list def) (flop remaining)
7242+ =/ groups=icomponents (graph-components pending (global-value-names pending))
7243+ =/ grouped=(unit [rest=(list def) env=ienv state=istate])
7244+ (try-local-group pending groups env state)
6339− ?. progressed [%| ["local definitions need unsupported inference" ~]]
7245+ ?~ grouped [%| ["local definitions need unsupported inference" ~]]
7246+ $(ds rest.u.grouped, remaining ~, env env.u.grouped, state state.u.grouped, progressed |)
6340 $(ds (flop remaining), remaining ~, progressed |)
7247 $(ds (flop remaining), remaining ~, progressed |)
6341 =/ d=def i.ds
7248 =/ d=def i.ds
6342 ?> ?=(%value -.d)
7249 ?> ?=(%value -.d)
@@ -6345,6 +7252,11 @@
6345 =/ retried=? ?=(%| -.inferred)
7252 =/ retried=? ?=(%| -.inferred)
6346 =? inferred retried (infer-recursive-gate d env local-state)
7253 =? inferred retried (infer-recursive-gate d env local-state)
6347 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
7254 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
7255+ ?: !=(obligations.state.p.inferred obligations.state) [%| ["deferred local definition needs unsupported inference" ~]]
7256+ =. state.p.inferred (promote-restricted-numbers state.p.inferred env)
7257+ =. state.p.inferred (default-hole-numbers holes.state.p.inferred holes.state state.p.inferred env !(itype-has-gate (itype-normalize typ.p.inferred sub.state.p.inferred)))
7258+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.inferred holes.state state.p.inferred)
7259+ ?^ hole [%| u.hole]
6348 =/ merged=(unit [first=icap second=icap])
7260 =/ merged=(unit [first=icap second=icap])
6349 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
7261 (merged-capitals caps.state.p.inferred sub.state.p.inferred)
6350 ?^ merged
7262 ?^ merged
@@ -6360,7 +7272,28 @@
6360 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
7272 (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
6361 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
7273 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
6362 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
7274 =. 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 &)
7275+ $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state, holes holes.state), progressed &)
7277+:: Try complete cyclic local groups after individual definitions stall.
7278+:: Components with non-gates or unresolved constraints stay unavailable.
7281+ |= [ds=(list def) groups=icomponents env=ienv state=istate]
7282+ ^- (unit [rest=(list def) env=ienv state=istate])
7284+ =/ names=(list term) i.groups
7285+ ?. (gth (lent names) 1) $(groups t.groups)
7286+ =/ members=(list def)
7287+ (skim ds |=(d=def &(?=(%value -.d) (lien names |=(n=term =(n name.d))))))
7288+ ?. =((lent members) (lent names)) $(groups t.groups)
7289+ =/ result=ilocal-result (infer-gate-group members env state)
7290+ ?: ?=(%| -.result) $(groups t.groups)
7292+ (skim ds |=(d=def !(lien names |=(n=term =(n name.d)))))
7293+ =/ more=(unit [rest=(list def) env=ienv state=istate])
7294+ $(ds rest, groups t.groups, env env.p.result, state state.p.result)
7296+ `[rest env.p.result state.p.result]
6365:: Read only fields of a known record. Unresolved field constraints and
7298:: Read only fields of a known record. Unresolved field constraints and
6366:: ambiguous repeated faces are outside this fragment. Imported record
7299:: ambiguous repeated faces are outside this fragment. Imported record
@@ -6383,17 +7316,29 @@
6383 ^- iresult
7316 ^- iresult
6384 =/ reverse=(list term) (flop names)
7317 =/ reverse=(list term) (flop names)
6385 ?~ reverse [%| ["empty wing" ~]]
7318 ?~ reverse [%| ["empty wing" ~]]
6386− =/ scheme=(unit ischeme) (ienv-lookup i.reverse env)
7319+ =/ iface=(unit ifile) (find-jibb-interface i.reverse jimports.state)
6387− ?~ scheme [%| ["field access is not supported by partial inference" ~]]
6388− =/ inst=[typ=itype state=istate] (instantiate-scheme u.scheme state)
6389 =/ fields=(list term) t.reverse
7320 =/ fields=(list term) t.reverse
7321+ ?~ fields [%| ["field access is not supported by partial inference" ~]]
7322+ =/ scheme=(unit ischeme)
7324+ (ienv-lookup i.reverse env)
7325+ (ienv-lookup i.fields values.u.iface)
7327+ ?^ iface [%| ["module member is not available to partial inference" ~]]
7328+ [%| ["field access is not supported by partial inference" ~]]
7329+ =/ inst=[typ=itype state=istate]
7330+ ?~ iface (instantiate-scheme u.scheme state)
7331+ =/ imported=ischeme u.scheme
7332+ =. typ.imported (itype-in-import typ.imported u.iface i.reverse prelude.state)
7333+ (instantiate-scheme imported state)
7334+ =/ remaining=(list term) ?~(iface fields t.fields)
6390 =/ typ=itype typ.inst
7335 =/ typ=itype typ.inst
6392− ?~ fields [%& typ state.inst]
7337+ ?~ remaining [%& typ state.inst]
6393− =/ found=(list itype) (record-fields-named i.fields typ sub.state.inst)
7338+ =/ found=(list itype) (record-fields-named i.remaining typ sub.state.inst)
6394 ?~ found [%| ["field is not available to partial inference" ~]]
7339 ?~ found [%| ["field is not available to partial inference" ~]]
6395 ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
7340 ?^ t.found [%| ["field name is ambiguous in partial inference" ~]]
6396− $(fields t.fields, typ i.found)
7341+ $(remaining t.remaining, typ i.found)
6398:: Propagate a known union or list through supported loobean, unit and list
7343:: Propagate a known union or list through supported loobean, unit and list
6399:: branches. Empty bodies and groups are transparent; bodies with definitions
7344:: branches. Empty bodies and groups are transparent; bodies with definitions
@@ -6417,6 +7362,8 @@
6417 ?: &(?=(%collection -.expected) =(%list name.expected) (context-list-expression e))
7362 ?: &(?=(%collection -.expected) =(%list name.expected) (context-list-expression e))
6418 (infer-list-context e expected env state context)
7363 (infer-list-context e expected env state context)
6419 ?: ?=(%branch -.e)
7364 ?: ?=(%branch -.e)
7365+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[expected context])
7366+ ?^ empty-list u.empty-list
6420 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
7367 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
6421 ?~ t.arms.e [%| ["branch pattern is not supported by partial inference" ~]]
7368 ?~ t.arms.e [%| ["branch pattern is not supported by partial inference" ~]]
6422 ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
7369 ?^ t.t.arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -6448,10 +7395,17 @@
6448 ?: ?=(%unknown -.fit)
7395 ?: ?=(%unknown -.fit)
6449 ?: &(?=(%collection -.expected) =(%list name.expected))
7396 ?: &(?=(%collection -.expected) =(%list name.expected))
6450 [%| ["branch list constraint is not supported by partial inference" ~]]
7397 [%| ["branch list constraint is not supported by partial inference" ~]]
7398+ ?: ?=(%flag -.expected) [%| ["branch loobean constraint is not supported by partial inference" ~]]
6451 [%| ["branch union constraint is not supported by partial inference" ~]]
7399 [%| ["branch union constraint is not supported by partial inference" ~]]
6452 ?: ?=(%bad -.fit)
7400 ?: ?=(%bad -.fit)
7401+ =/ missing=(unit idiag) (missing-union-tag e expected sub.state.p.value context)
7402+ ?^ missing [%| u.missing]
7403+ =/ nested=(unit idiag) (nested-missing-tag e typ.p.value expected sub.state.p.value next.state.p.value context)
7404+ ?^ nested [%| u.nested]
6453 ?: &(?=(%collection -.expected) =(%list name.expected))
7405 ?: &(?=(%collection -.expected) =(%list name.expected))
6454 [%| ["branch arm does not fit its expected list" ~[[context "expected list"] [(span-of e) "branch arm"]]]]
7406 [%| ["branch arm does not fit its expected list" ~[[context "expected list"] [(span-of e) "branch arm"]]]]
7407+ ?: ?=(%flag -.expected)
7408+ [%| ["branch arm does not fit its expected loobean" ~[[context "expected loobean"] [(span-of e) "branch arm"]]]]
6455 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
7409 [%| ["branch arm does not fit its expected union" ~[[context "expected union"] [(span-of e) "branch arm"]]]]
6456 [%& expected state.p.value(sub sub.fit, next next.fit)]
7410 [%& expected state.p.value(sub sub.fit, next next.fit)]
@@ -6516,23 +7470,37 @@
6516 [%| ["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)]]]]
7470 [%| ["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)]]]]
6517 [%& target state.p.tail(sub sub.fit, next next.fit)]
7471 [%& target state.p.tail(sub sub.fit, next next.fit)]
7473+++ infer-open-list-items
7474+ |= [items=(list expr) expected=itype env=ienv state=istate context=span]
7476+ ?~ items [%& expected state]
7477+ =/ target=itype (itype-walk expected sub.state)
7478+ =/ value=iresult (infer-call-context-arg i.items target env state context)
7479+ ?: ?=(%| -.value) value
7480+ =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7481+ ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
7483+ ?: |((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))
7484+ [%| ["list item widening is not supported by partial inference" ~]]
7485+ [%| ["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)]]]]
7486+ ?: (itype-has-tag (itype-normalize expected sub.fit))
7487+ [%| ["list item needs context in partial inference" ~]]
7488+ $(items t.items, state state.p.value(sub sub.fit, next next.fit))
6519++ infer-list-items
7490++ infer-list-items
6520 |= [items=(list expr) expected=itype env=ienv state=istate context=span]
7491 |= [items=(list expr) expected=itype env=ienv state=istate context=span]
6521 ^- iresult
7492 ^- iresult
6522 ?~ items [%& expected state]
7493 ?~ items [%& expected state]
6523 =/ target=itype (itype-walk expected sub.state)
7494 =/ target=itype (itype-walk expected sub.state)
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)
7495+ =/ value=iresult (infer-call-context-arg i.items target env state context)
6531− (infer-fragment i.items env state)
6532 ?: ?=(%| -.value) value
7496 ?: ?=(%| -.value) value
6533 =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
7497 =/ fit=ifit (itype-fit typ.p.value target sub.state.p.value next.state.p.value)
6534 ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
7498 ?: ?=(%unknown -.fit) [%| ["list item constraint is not supported by partial inference" ~]]
6535 ?: ?=(%bad -.fit)
7499 ?: ?=(%bad -.fit)
7500+ =/ missing=(unit idiag) (missing-union-tag i.items target sub.state.p.value context)
7501+ ?^ missing [%| u.missing]
7502+ =/ nested=(unit idiag) (nested-missing-tag i.items typ.p.value target sub.state.p.value next.state.p.value context)
7503+ ?^ nested [%| u.nested]
6536 [%| ["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)]]]]
7504 [%| ["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)]]]]
6537 $(items t.items, state state.p.value(sub sub.fit, next next.fit))
7505 $(items t.items, state state.p.value(sub sub.fit, next next.fit))
@@ -6613,6 +7581,11 @@
6613 [%| ["list pattern needs the standard prelude in partial inference" ~]]
7581 [%| ["list pattern needs the standard prelude in partial inference" ~]]
6614 ?~ args.typ [%| ["list pattern is not supported by partial inference" ~]]
7582 ?~ args.typ [%| ["list pattern is not supported by partial inference" ~]]
6615 ?^ t.args.typ [%| ["list pattern is not supported by partial inference" ~]]
7583 ?^ t.args.typ [%| ["list pattern is not supported by partial inference" ~]]
7584+ =/ item-live=(unit [result=?(%yes %no %unknown) left=@ud])
7585+ (itype-inhabited-proof i.args.typ sub.state caps.state 256)
7586+ ?~ item-live [%| ["list element reachability needs unsupported inference" ~]]
7587+ ?: =(%unknown result.u.item-live) [%| ["list element reachability needs unsupported inference" ~]]
7588+ ?: =(%no result.u.item-live) [%| ["list nonempty pattern is unreachable" ~]]
6616 ?~ arms.e [%| ["list branch is not supported by partial inference" ~]]
7589 ?~ arms.e [%| ["list branch is not supported by partial inference" ~]]
6617 ?~ t.arms.e [%| ["list branch is not supported by partial inference" ~]]
7590 ?~ t.arms.e [%| ["list branch is not supported by partial inference" ~]]
6618 ?^ t.t.arms.e [%| ["list branch is not supported by partial inference" ~]]
7591 ?^ t.t.arms.e [%| ["list branch is not supported by partial inference" ~]]
@@ -6625,7 +7598,7 @@
6625 [%| ["list branch pattern is not supported by partial inference" ~]]
7598 [%| ["list branch pattern is not supported by partial inference" ~]]
6626 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
7599 =/ binder=(unit [head=term tail=term]) ?:(first-empty second-name first-name)
6627 ?~ binder [%| ["list branch pattern is not supported by partial inference" ~]]
7600 ?~ 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)))))
7601+ ?: |(=(head.u.binder %proj) =(tail.u.binder %proj) =(head.u.binder tail.u.binder) ?=(^ (ienv-lookup head.u.binder env)) ?=(^ (ienv-lookup tail.u.binder env)) (lien globals.state |=(n=term |(=(n head.u.binder) =(n tail.u.binder)))))
6629 [%| ["pattern binder shadows a name" ~]]
7602 [%| ["pattern binder shadows a name" ~]]
6630 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
7603 =/ extended=ienv [[head.u.binder [i.args.typ ~]] [tail.u.binder [typ ~]] env]
6631 =/ left=iresult
7604 =/ left=iresult
@@ -6662,10 +7635,15 @@
6662 [%| ["unit branch pattern is not supported by partial inference" ~]]
7635 [%| ["unit branch pattern is not supported by partial inference" ~]]
6663 =/ binder=(unit term) ?:(first-empty second-name first-name)
7636 =/ binder=(unit term) ?:(first-empty second-name first-name)
6664 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
7637 ?~ binder [%| ["unit branch pattern is not supported by partial inference" ~]]
6665− ?: |(?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
7638+ ?: |(=(u.binder %proj) ?=(^ (ienv-lookup u.binder env)) (lien globals.state |=(n=term =(n u.binder))))
6666 [%| ["pattern binder shadows a name" ~]]
7639 [%| ["pattern binder shadows a name" ~]]
6667 =/ payload=(unit itype) (unit-union-payload typ)
7640 =/ payload=(unit itype) (unit-union-payload typ)
6668 ?~ payload [%| ["unit branch subject is not supported by partial inference" ~]]
7641 ?~ payload [%| ["unit branch subject is not supported by partial inference" ~]]
7642+ =/ payload-live=(unit [result=?(%yes %no %unknown) left=@ud])
7643+ (itype-inhabited-proof u.payload sub.state.p.subject caps.state.p.subject 256)
7644+ ?~ payload-live [%| ["unit payload reachability needs unsupported inference" ~]]
7645+ ?: =(%unknown result.u.payload-live) [%| ["unit payload reachability needs unsupported inference" ~]]
7646+ ?: =(%no result.u.payload-live) [%| ["unit present pattern is unreachable" ~]]
6669 =/ extended=ienv [[u.binder [u.payload ~]] env]
7647 =/ extended=ienv [[u.binder [u.payload ~]] env]
6670 =/ left=iresult
7648 =/ left=iresult
6671 ?~ expected (infer-fragment val.x ?:(first-empty env extended) state.p.subject)
7649 ?~ expected (infer-fragment val.x ?:(first-empty env extended) state.p.subject)
@@ -6694,12 +7672,14 @@
6694 =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
7672 =/ t=itype (itype-normalize typ.p.item sub.state.p.item)
6695 ?: |(?=(%atom -.t) ?=(%any-atom -.t))
7673 ?: |(?=(%atom -.t) ?=(%any-atom -.t))
6696 $(ps t.ps, state state.p.item)
7674 $(ps t.ps, state state.p.item)
6697− ?: &(?=(%nvar -.t) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
7675+ ?: &(|(?=(%nvar -.t) ?=(%rnvar -.t)) ?=(%lit -.p.i.ps) =(%number form.lit.p.i.ps))
6698 $(ps t.ps, state state.p.item)
7676 $(ps t.ps, state state.p.item)
6699 ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
7677 ?: &(?=(%collection -.t) =(%list name.t) =(~[[%atom 'tD']] args.t))
6700 $(ps t.ps, state state.p.item)
7678 $(ps t.ps, state state.p.item)
6701 ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7679 ?: &(?=(%avar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
6702 [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7680 [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
7681+ ?: &(?=(%rvar -.t) (atom-var-from-cap id.t caps.state.p.item sub.state.p.item))
7682+ [%| ["a generic atom in interpolation needs an aura" ~[[(span-of p.i.ps) "atom with a generic aura"]]]]
6703 ?: ?=(%cell -.t)
7683 ?: ?=(%cell -.t)
6704 [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
7684 [%| ["a cell in interpolation needs a printer" ~[[(span-of p.i.ps) "cell without a printer"]]]]
6705 [%| ["interpolation type needs unsupported inference" ~]]
7685 [%| ["interpolation type needs unsupported inference" ~]]
@@ -6762,7 +7742,7 @@
6762 ^- (unit ienv)
7742 ^- (unit ienv)
6763 =. t ?:(?=(%face -.t) body.t t)
7743 =. t ?:(?=(%face -.t) body.t t)
6764 ?: ?=(%bind -.p)
7744 ?: ?=(%bind -.p)
6765− ?: |(?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
7745+ ?: |(=(name.p %proj) ?=(^ (ienv-lookup name.p env)) (lien globals |=(n=term =(n name.p)))) ~
6766 `[[name.p [t ~]] env]
7746 `[[name.p [t ~]] env]
6767 ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
7747 ?: ?=(%cell -.p) (union-pattern-bind-items items.p t env globals)
@@ -6810,14 +7790,15 @@
6810 $(xs t.xs, out (weld out rows), origin +(origin))
7790 $(xs t.xs, out (weld out rows), origin +(origin))
6812++ infer-known-union-whole
7792++ infer-known-union-whole
6813− |= [e=expr env=ienv state=istate]
7793+ |= [e=expr env=ienv subject=iresult]
6814 ^- (unit iresult)
7794 ^- (unit iresult)
6815 ?> ?=(%branch -.e)
7795 ?> ?=(%branch -.e)
6816− =/ subject=iresult (infer-fragment subject.e env state)
6817 ?: ?=(%| -.subject) `subject
7796 ?: ?=(%| -.subject) `subject
6818 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7797 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
6819 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
7798 ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
6820− =/ cases=(list itype) cases.typ
7799+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7801+ =/ cases=(list itype) u.live
6821 =/ remaining=(list itype) cases
7802 =/ remaining=(list itype) cases
6822 =/ arms=(list arm) arms.e
7803 =/ arms=(list arm) arms.e
6823 =/ st=istate state.p.subject
7804 =/ st=istate state.p.subject
@@ -6847,15 +7828,62 @@
6847 ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
7828 ?: mismatch `[%| ["union branch result matching needs unsupported inference" ~]]
6848 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
7829 $(arms t.arms, remaining (skim remaining |=(c=itype !=(%full (union-pattern pat.a c)))), st state.p.body, answer `result)
7831+++ infer-known-union-context-whole
7832+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
7835+ ?: ?=(%| -.subject) `subject
7836+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7837+ ?. ?=(%union -.typ) `[%| ["branch is not supported by partial inference" ~]]
7838+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7840+ =/ cases=(list itype) u.live
7841+ =/ remaining=(list itype) cases
7842+ =/ arms=(list arm) arms.e
7843+ =/ st=istate state.p.subject
7844+ =/ answer=(unit itype) ~
7848+ `[%| ["missing union case {(show-itype i.remaining sub.st)}" ~]]
7849+ ?~ answer `[%| ["empty union branch is not supported by partial inference" ~]]
7852+ ?: (lien remaining |=(c=itype =(%unknown (union-pattern pat.a c))))
7854+ =/ matching=(list itype) (skim remaining |=(c=itype =(%full (union-pattern pat.a c))))
7856+ ?: (lien cases |=(c=itype =(%full (union-pattern pat.a c))))
7857+ `[%| ["branch arm is covered by earlier arms" ~[[at.pat.a "covered arm"]]]]
7858+ `[%| ["union pattern is not supported by partial inference" ~]]
7859+ ?: &(?=(^ t.matching) (union-pattern-has-bind pat.a))
7860+ `[%| ["a union pattern binding several cases is not supported by partial inference" ~]]
7861+ =/ bound=(unit ienv) (union-pattern-bind pat.a i.matching env globals.st)
7862+ ?~ bound `[%| ["pattern binder shadows a name" ~]]
7863+ =/ body=iresult (infer-call-context-arg val.a expected u.bound st context)
7864+ ?: ?=(%| -.body) `body
7865+ =/ fit=ifit (itype-fit typ.p.body expected sub.state.p.body next.state.p.body)
7866+ ?: ?=(%unknown -.fit) `[%| ["union branch result constraint is not supported by partial inference" ~]]
7868+ =/ missing=(unit idiag) (missing-union-tag val.a expected sub.state.p.body context)
7869+ ?^ missing `[%| u.missing]
7870+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body expected sub.state.p.body next.state.p.body context)
7871+ ?^ nested `[%| u.nested]
7872+ `[%| ["union branch arm does not fit its expected type" ~[[context "expected type"] [(span-of val.a) "branch arm"]]]]
7873+ ?: (itype-has-tag (itype-normalize expected sub.fit))
7874+ `[%| ["union branch result needs context in partial inference" ~]]
7875+ $(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)
6850++ infer-known-union-finite
7877++ infer-known-union-finite
6851− |= [e=expr env=ienv state=istate]
7878+ |= [e=expr env=ienv subject=iresult expected=(unit [typ=itype context=span])]
6852 ^- iresult
7879 ^- iresult
6853 ?> ?=(%branch -.e)
7880 ?> ?=(%branch -.e)
6854− =/ subject=iresult (infer-fragment subject.e env state)
6855 ?: ?=(%| -.subject) subject
7881 ?: ?=(%| -.subject) subject
6856 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7882 =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
6857 ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
7883 ?. ?=(%union -.typ) [%| ["branch is not supported by partial inference" ~]]
7884+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
7885+ ?~ live [%| ["union emptiness needs unsupported inference" ~]]
6858− =/ expanded=(unit (list ifinite)) (finite-cases cases.typ ~ 0)
7886+ =/ expanded=(unit (list ifinite)) (finite-cases u.live ~ 0)
6859 ?~ expanded [%| ["union pattern expansion needs unsupported inference" ~]]
7887 ?~ expanded [%| ["union pattern expansion needs unsupported inference" ~]]
6860 =/ cases=(list ifinite) u.expanded
7888 =/ cases=(list ifinite) u.expanded
6861 =/ remaining=(list ifinite) cases
7889 =/ remaining=(list ifinite) cases
@@ -6867,7 +7895,8 @@
6867 ?^ remaining
7895 ?^ remaining
6868 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
7896 [%| ["missing union case {(show-itype part.i.remaining sub.st)}" ~]]
6869 ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
7897 ?~ answer [%| ["empty union branch is not supported by partial inference" ~]]
6870− [%& u.answer st]
7898+ ?~ expected [%& u.answer st]
7899+ [%& typ.u.expected st]
6871 =/ a=arm i.arms
7900 =/ a=arm i.arms
6872 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
7901 ?: (lien remaining |=(c=ifinite =(%unknown (union-pattern pat.a part.c))))
6873 [%| ["partial union pattern is not supported by partial inference" ~]]
7902 [%| ["partial union pattern is not supported by partial inference" ~]]
@@ -6880,39 +7909,454 @@
6880 [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
7909 [%| ["a union pattern binding several cases is not supported by partial inference" ~]]
6881 =/ bound=(unit ienv) (union-pattern-bind pat.a base.i.matching env globals.st)
7910 =/ bound=(unit ienv) (union-pattern-bind pat.a base.i.matching env globals.st)
6882 ?~ bound [%| ["pattern binder shadows a name" ~]]
7911 ?~ bound [%| ["pattern binder shadows a name" ~]]
6883− =/ body=iresult (infer-fragment val.a u.bound st)
7913+ ?~ expected (infer-fragment val.a u.bound st)
7914+ (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
6884 ?: ?=(%| -.body) body
7915 ?: ?=(%| -.body) body
7917+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7918+ ?: ?=(%unknown -.fit) [%| ["union branch result constraint is not supported by partial inference" ~]]
7920+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7921+ ?^ missing [%| u.missing]
7922+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body typ.u.expected sub.state.p.body next.state.p.body context.u.expected)
7923+ ?^ nested [%| u.nested]
7924+ [%| ["union branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7925+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7926+ [%| ["union branch result needs context in partial inference" ~]]
7927+ $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body(sub sub.fit, next next.fit), answer `typ.u.expected)
6885 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
7928 =/ result=itype (itype-normalize typ.p.body sub.state.p.body)
6886 =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
7929 =/ mismatch=? ?~(answer | !=((itype-normalize u.answer sub.state.p.body) result))
6887 ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
7930 ?: mismatch [%| ["union branch result matching needs unsupported inference" ~]]
6888 $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
7931 $(arms t.arms, remaining (skim remaining |=(c=ifinite !=(%full (union-pattern pat.a part.c)))), st state.p.body, answer `result)
7933+:: Prove a one-arm record pattern covers a known, non-union subject.
7934+:: Variable or partial matches stay unsupported; binding uses the same
7935+:: scope and original payload types as the existing union matcher.
7936+++ single-structured-pattern
6890−++ infer-known-union-branch
7939+ ?. ?=(%branch -.e) |
7942+ =/ p=pattern pat.i.arms.e
7944+ !(levy items.p |=(x=pattern ?=(%bind -.x)))
7946+++ infer-single-case-branch
7947+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
7949+ ?> (single-structured-pattern e)
7953+ =/ subject=iresult (infer-fragment subject.e env state)
7954+ ?: ?=(%| -.subject) subject
7955+ =/ st=istate state.p.subject
7956+ =/ typ=itype (itype-normalize typ.p.subject sub.st)
7957+ ?: ?=(%union -.typ) [%| ["single-case pattern needs unsupported inference" ~]]
7958+ ?. =(%full (union-pattern pat.a typ))
7959+ [%| ["single-case pattern needs unsupported inference" ~]]
7960+ =/ bound=(unit ienv) (union-pattern-bind pat.a typ env globals.st)
7961+ ?~ bound [%| ["pattern binder shadows a name" ~]]
7962+ ?~ expected (infer-fragment val.a u.bound st)
7963+ =/ body=iresult (infer-call-context-arg val.a typ.u.expected u.bound st context.u.expected)
7964+ ?: ?=(%| -.body) body
7965+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
7966+ ?: ?=(%unknown -.fit) [%| ["single-case branch result constraint is not supported by partial inference" ~]]
7968+ =/ missing=(unit idiag) (missing-union-tag val.a typ.u.expected sub.state.p.body context.u.expected)
7969+ ?^ missing [%| u.missing]
7970+ =/ nested=(unit idiag) (nested-missing-tag val.a typ.p.body typ.u.expected sub.state.p.body next.state.p.body context.u.expected)
7971+ ?^ nested [%| u.nested]
7972+ [%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.a) "branch arm"]]]]
7973+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
7974+ [%| ["single-case branch result needs context in partial inference" ~]]
7975+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
7977+:: This view is used only by pattern analysis, never exported or bound as
7978+:: the subject. Only null plus a two-binder/wildcard cell is supported; its
7979+:: tail keeps the original recursive type. Other patterns fail closed.
7981+ |= [e=expr subject=iresult]
7983+ ?: ?=(%| -.subject) subject
7984+ ?. ?=(%branch -.e) subject
7985+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
7986+ ?. ?=(%jrec -.typ) subject
7988+ ?~ t.arms.e subject
7989+ ?^ t.t.arms.e subject
7990+ =/ x=pattern pat.i.arms.e
7991+ =/ y=pattern pat.i.t.arms.e
7992+ =/ empty=? &(?=(%lit -.x) =(%null form.lit.x))
7993+ =/ full=pattern ?:(empty y x)
7994+ ?. |(empty &(?=(%lit -.y) =(%null form.lit.y))) subject
7995+ ?. ?=(%cell -.full) subject
7996+ ?~ items.full subject
7997+ ?~ t.items.full subject
7998+ ?^ t.t.items.full subject
7999+ ?. |(?=(%bind -.i.items.full) ?=(%any -.i.items.full)) subject
8000+ ?. |(?=(%bind -.i.t.items.full) ?=(%any -.i.t.items.full)) subject
8001+ ?: =(0 jrec-fuel.state.p.subject)
8002+ [%| ["recursive mold unfolding needs unsupported inference" ~]]
8003+ =/ nil=itype [%const [%null %n 0 '~']]
8004+ =/ cell=itype [%cell [%face head.typ [%atom aura.typ]] [%face tail.typ typ]]
8005+ [%& [%union ~[nil cell] ~ ~ ~] state.p.subject(jrec-fuel (dec jrec-fuel.state.p.subject))]
8007+:: A bounded source-proven tree match permits flat tag patterns and
8008+:: nonbinding catch-alls. Whole-case binders cannot consume the temporary
8009+:: structural view. Pattern count and field arity are checked first.
8010+++ grec-simple-pattern
8011+ |= [pat=pattern view=itype]
8013+ ?. ?=(%cell -.pat) |
8015+ =/ first=pattern i.items.pat
8016+ ?. ?=(%lit -.first) |
8017+ ?. =(%term form.lit.first) |
8018+ =/ chosen=(unit itype) (contextual-tagged-case view val.lit.first ~)
8020+ ?> ?=(%cell -.u.chosen)
8021+ =/ rest=(list pattern) t.items.pat
8022+ =/ arity=? ?:(?=(%cell -.tal.u.chosen) ?=([* [* ~]] rest) ?=([* ~] rest))
8024+ (levy rest |=(p=pattern |(?=(%bind -.p) ?=(%any -.p))))
8026+:: A catch-all with no binder is safe even when it covers both cases.
8027+:: A bound whole case still declines to avoid exporting the analysis view.
8028+++ grec-patterns-eligible
8029+ |= [arms=(list arm) view=itype left=@ud]
8033+ =/ pat=pattern pat.i.arms
8034+ ?. |(?=(%any -.pat) (grec-simple-pattern pat view)) |
8035+ $(arms t.arms, left (dec left))
8037+ |= [e=expr subject=iresult]
8039+ ?: ?=(%| -.subject) subject
8040+ ?. ?=(%branch -.e) subject
8041+ ?. (grec-direct-context typ.p.subject sub.state.p.subject) subject
8042+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8043+ ?. ?=(%grec -.typ) subject
8045+ =/ view=(unit [view=itype left=@ud]) (grec-unfold-view typ jrec-fuel.state.p.subject)
8046+ ?~ view [%| ["recursive mold unfolding needs unsupported inference" ~]]
8047+ ?. (grec-patterns-eligible arms.e view.u.view 128) subject
8048+ [%& view.u.view state.p.subject(jrec-fuel left.u.view)]
8050+:: A single-arm diagnostic only probes a direct, source-typed in-scope wing;
8051+:: other subjects retain the prior single-pattern inference path.
8052+++ grec-single-wing-subject
6891 |= [e=expr env=ienv state=istate]
8053 |= [e=expr env=ienv state=istate]
8056+ ?. ?=([@ ~] names.e) ~
8057+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8059+ ?. (grec-direct-context typ.u.scheme sub.state) ~
8060+ `(infer-fragment e env state)
8062+++ infer-known-union-branch-subject
8063+ |= [e=expr env=ienv subject=iresult]
6892 ^- iresult
8064 ^- iresult
8065+ =. subject (grec-match-view e subject)
8066+ =. subject (jrec-match-view e subject)
6893− =/ whole=(unit iresult) (infer-known-union-whole e env state)
8067+ =/ whole=(unit iresult) (infer-known-union-whole e env subject)
6894− ?~ whole (infer-known-union-finite e env state)
8068+ ?~ whole (infer-known-union-finite e env subject ~)
6897−++ known-union-subject
8071+++ infer-known-union-branch
6898 |= [e=expr env=ienv state=istate]
8072 |= [e=expr env=ienv state=istate]
6899− ^- (unit itype)
8073+ ^- iresult
6900− ?. ?=(%wing -.e) ~
8074+ ?> ?=(%branch -.e)
6901− =/ subject=iresult (infer-fragment e env state)
8075+ (infer-known-union-branch-subject e env (infer-fragment subject.e env state))
6902− ?: ?=(%| -.subject) ~
6903− =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
6904− ?. ?=(%union -.typ) ~
6907−++ infer-fragment
8077+++ infer-known-union-context-subject
6908− |= [e=expr env=ienv state=istate]
8078+ |= [e=expr expected=itype env=ienv subject=iresult context=span]
6909 ^- iresult
8079 ^- iresult
8080+ =. subject (grec-match-view e subject)
8081+ =. subject (jrec-match-view e subject)
8082+ =/ whole=(unit iresult) (infer-known-union-context-whole e expected env subject context)
8083+ ?~ whole (infer-known-union-finite e env subject `[expected context])
8086+:: Limit speculative subject inference to wings and shallow calls;
8087+:: grouping is peeled linearly and cannot introduce a nested branch.
8088+++ simple-union-subject-arg
6912− ?- form.lit.e
8093+ %lit &
6913− %number ?: =(%ud aura.lit.e)
8094+ %str !(lien pieces.e |=(p=piece ?=(%expr -.p)))
6914− [%& [%nvar next.state] state(next +(next.state))]
8095+ * |
6915− [%& [%atom aura.lit.e] state]
8096+ ==
8098+++ safe-union-subject
8101+ ?: ?=(%group -.e) $(e inner.e)
8104+ ?. ?=(%wing -.head.e) |
8105+ (levy args.e simple-union-subject-arg)
8107+++ duplicate-loobean-arms
8110+ ?. ?=(%branch -.e) |
8114+ =/ x=pattern pat.i.arms.e
8115+ =/ y=pattern pat.i.t.arms.e
8116+ ?. &(?=(%lit -.x) ?=(%lit -.y)) |
8117+ ?. &(=(%loobean form.lit.x) =(%loobean form.lit.y)) |
8118+ =(val.lit.x val.lit.y)
8120+++ union-subject-call
8123+ ?: ?=(%group -.e) $(e inner.e)
8126+++ known-union-subject
8127+ |= [e=expr env=ienv state=istate]
8129+ ?. (safe-union-subject e) ~
8130+ =/ subject=iresult (infer-fragment e env state)
8131+ ?: ?=(%| -.subject) ?:((union-subject-call e) `subject ~)
8132+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8133+ ?. |(?=(%union -.typ) ?=(%jrec -.typ) &(?=(%grec -.typ) (grec-direct-context typ.p.subject sub.state.p.subject))) ~
8136+:: A direct wing with an already-known union may skip genuinely empty cases
8137+:: when checking a one-arm match. Other subjects keep their existing path.
8138+:: A directly known canonical list of an empty element contains only null.
8139+:: This helper never refines an opaque or variable-bound subject.
8140+++ empty-list-null-branch
8141+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
8143+ ?. ?=(%branch -.e) ~
8146+ ?. (unit-empty-pattern pat.i.arms.e) ~
8147+ ?. ?=(%wing -.subject.e) ~
8148+ ?. ?=([@ ~] names.subject.e) ~
8149+ =/ scheme=(unit ischeme) (ienv-lookup i.names.subject.e env)
8151+ ?. ?=(%collection -.typ.u.scheme) ~
8152+ ?. =(%list name.typ.u.scheme) ~
8154+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb) ~
8155+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8157+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
8158+ =/ subject=iresult (infer-fragment subject.e env state)
8159+ ?: ?=(%| -.subject) ~
8160+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8161+ ?. ?=(%collection -.typ) ~
8162+ ?. =(%list name.typ) ~
8165+ =/ proof=(unit [empty=? left=@ud]) (itype-empty-proof i.args.typ sub.state.p.subject 256)
8168+ ?~ expected `(infer-fragment val.i.arms.e env state.p.subject)
8169+ =/ body=iresult (infer-call-context-arg val.i.arms.e typ.u.expected env state.p.subject context.u.expected)
8170+ ?: ?=(%| -.body) `body
8171+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
8172+ ?: ?=(%unknown -.fit) `[%| ["single-case branch result constraint is not supported by partial inference" ~]]
8173+ ?: ?=(%bad -.fit) `[%| ["single-case branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.i.arms.e) "branch arm"]]]]
8174+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
8175+ `[%| ["single-case branch result needs context in partial inference" ~]]
8176+ `[%& typ.p.body state.p.body(sub sub.fit, next next.fit)]
8178+++ known-empty-union-wing
8179+ |= [e=expr env=ienv state=istate]
8182+ ?. ?=([@ ~] names.e) ~
8183+ =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8185+ ?. (contextual-direct-union typ.u.scheme) ~
8186+ =/ subject=iresult (infer-fragment e env state)
8187+ ?: ?=(%| -.subject) ~
8188+ =/ typ=itype (itype-normalize typ.p.subject sub.state.p.subject)
8189+ ?. ?=(%union -.typ) ~
8190+ =/ live=(unit (list itype)) (itype-live-cases cases.typ sub.state.p.subject caps.state.p.subject 4.096)
8192+ ?: =(u.live cases.typ) ~
8195+:: Infer changes only against a fully known record spine. Retain the
8196+:: target type; unknown spines and repeated edits remain unsupported.
8197+++ change-spine-known
8198+ |= [t=itype sub=isub]
8200+ =. t (itype-walk t sub)
8203+ =/ first=itype (itype-walk hed.t sub)
8204+ ?. ?=(%face -.first) |
8207+++ infer-change-edits
8208+ |= [edits=(list edit) target=itype env=ienv state=istate seen=(list term)]
8210+ ?~ edits [%& target state]
8211+ =/ entry=edit i.edits
8212+ ?: (lien seen |=(name=term =(name name.entry)))
8213+ [%| ["repeated change fields are not supported by partial inference" ~]]
8214+ ?. (change-spine-known target sub.state)
8215+ [%| ["change target needs a known record in partial inference" ~]]
8216+ =/ found=(list itype) (record-fields-named name.entry target sub.state)
8218+ [%| ["record has no field `{(trip name.entry)}`" ~[[at.entry "unknown field"]]]]
8219+ ?^ t.found [%| ["change field is ambiguous in partial inference" ~]]
8220+ =/ expected=itype i.found
8221+ =/ value=iresult (infer-call-context-arg val.entry expected env state at.entry)
8222+ ?: ?=(%| -.value) value
8223+ =/ fit=ifit (itype-fit typ.p.value expected sub.state.p.value next.state.p.value)
8224+ ?: ?=(%unknown -.fit) [%| ["change field constraint is not supported by partial inference" ~]]
8226+ [%| ["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)]]]]
8227+ $(edits t.edits, state state.p.value(sub sub.fit, next next.fit), seen [name.entry seen])
8229+:: Backtick constructs the canonical prelude unit, after checking its
8230+:: prepared template has the standard null and [~ u=A] cases.
8231+++ standard-unit-template
8232+ |= [template=ischeme at=path]
8234+ ?. =(at /lib/jibb/prelude/jibb) |
8236+ ?^ t.vars.template |
8237+ =/ v=@ud i.vars.template
8238+ =/ nil=itype [%const [%null %n 0 '~']]
8240+ [%union ~[nil [%cell nil [%face %u [%var v]]]] `[at %unit] `%unit ~[[%var v]]]
8241+ =(typ.template expected)
8243+:: A named missing-case diagnostic needs more than a failed fit: a case
8244+:: with that tag but the wrong payload is not a missing case. Unknown
8245+:: shapes and atom types that accept terms keep the proof conservative.
8246++$ itag-presence ?(%yes %no %maybe)
8247+++ tag-presence-cases
8248+ |= [cases=(list itype) value=@ sub=isub]
8251+ =/ first=itag-presence (tag-presence i.cases value sub)
8252+ ?: =(%yes first) %yes
8253+ =/ rest=itag-presence $(cases t.cases)
8254+ ?: =(%yes rest) %yes
8255+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8259+ |= [t=itype value=@ sub=isub]
8261+ =. t (itype-walk t sub)
8263+ %const ?:(=(value val.literal.t) %yes %no)
8264+ %flag ?:(|(=(value 0) =(value 1)) %yes %no)
8265+ %atom ?:(|(=(%tas aura.t) =(%ta aura.t)) %maybe %no)
8268+ =/ first=itag-presence $(t hed.t)
8269+ ?: =(%yes first) %yes
8270+ =/ rest=itag-presence $(t tal.t)
8271+ ?: =(%yes rest) %yes
8272+ ?: |(=(%maybe first) =(%maybe rest)) %maybe
8274+ %union (tag-presence-cases cases.t value sub)
8278+++ missing-union-tag
8279+ |= [e=expr expected=itype sub=isub context=span]
8282+ ?. =(%term form.lit.e) ~
8283+ =. expected (itype-walk expected sub)
8285+ ?: ?=(%face -.expected) $(expected (itype-walk body.expected sub))
8286+ ?. ?=(%union -.expected) ~
8287+ ?. =(%no (tag-presence-cases cases.expected val.lit.e sub)) ~
8289+ ?~ label.expected "union {(show-itype expected sub)}"
8290+ (show-itype expected sub)
8291+ `["{label} has no case `{(trip txt.lit.e)}`" ~[[context "expected union"] [(span-of e) "tag"]]]
8293+:: Locate a missing tag inside a syntactic tuple only by replaying the
8294+:: directional fit in source order. Uncertain or earlier failures stop
8295+:: the walk, preserving the generic diagnostic rather than guessing.
8296+++ nested-missing-tag
8297+ |= [e=expr actual=itype expected=itype sub=isub next=@ud context=span]
8299+ =/ original=[left=itype right=itype] [actual expected]
8300+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
8301+ =/ fit=ifit (itype-fit actual expected sub next)
8302+ ?. ?=(%bad -.fit) ~
8303+ =. actual (itype-walk actual sub)
8304+ =. expected (itype-walk expected sub)
8305+ ?: &(?=(%face -.actual) ?=(%face -.expected))
8306+ ?. =(name.actual name.expected) ~
8307+ $(actual body.actual, expected body.expected)
8308+ ?: ?=(%face -.actual) $(actual body.actual)
8309+ ?: ?=(%face -.expected) $(expected body.expected)
8310+ =/ direct=(unit idiag) (missing-union-tag e expected sub context)
8312+ ?. ?=(%tuple -.e) ~
8313+ (nested-missing-items items.e actual expected sub next context)
8315+++ nested-missing-items
8316+ |= [items=(list item) actual=itype expected=itype sub=isub next=@ud context=span]
8319+ ?~ t.items (nested-missing-tag val.i.items actual expected sub next context)
8320+ =/ original=[left=itype right=itype] [actual expected]
8321+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
8322+ =. actual (itype-walk actual sub)
8323+ =. expected (itype-walk expected sub)
8324+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8325+ =/ first=ifit (itype-fit hed.actual hed.expected sub next)
8326+ ?: ?=(%bad -.first)
8327+ (nested-missing-tag val.i.items hed.actual hed.expected sub next context)
8328+ ?. ?=(%ok -.first) ~
8329+ $(items t.items, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
8331+:: A term-headed pair is the same noun as a two-item cell. Preserve the
8332+:: whole pair span for the synthetic head and the value's own span for
8333+:: the payload; unresolved term constraints follow ordinary cell inference.
8338+ =/ head=expr [%lit at.e [%term %tas tag.e (crip ['%' (trip tag.e)])]]
8339+ [%tuple at.e ~[[at.e ~ head] [(span-of val.e) ~ val.e]]]
8341+:: A segment costs one shared step; dynamic segments are not handled yet.
8343+ |= [segs=(list qseg) fuel=@ud]
8347+ ?. ?=(%knot -.i.segs) ~
8348+ $(segs t.segs, fuel (dec fuel))
8351+ |= [e=expr env=ienv state=istate]
8354+ %pair $(e (pair-as-cell e))
8357+ %number ?: =(%ud aura.lit.e)
8358+ [%& [%nvar next.state] state(next +(next.state))]
8359+ [%& [%atom aura.lit.e] state]
6916 %ship [%& [%atom %p] state]
8360 %ship [%& [%atom %p] state]
6917 %date [%& [%atom %da] state]
8361 %date [%& [%atom %da] state]
6918 %duration [%& [%atom %dr] state]
8362 %duration [%& [%atom %dr] state]
@@ -6921,7 +8365,45 @@
6921 %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
8365 %term [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
6922 %null [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
8366 %null [%& [%tag next.state lit.e |] state(next +(next.state), tags [[next.state lit.e] tags.state])]
8369+ ?~ prelude.state [%| ["unit construction needs the standard prelude in partial inference" ~]]
8370+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
8371+ ?~ standard [%| ["unit construction needs the standard prelude in partial inference" ~]]
8372+ ?. (standard-unit-template u.standard at.u.prelude.state)
8373+ [%| ["unit construction needs the standard prelude in partial inference" ~]]
8374+ =/ value=iresult $(e val.e)
8375+ ?: ?=(%| -.value) value
8376+ =/ result=(unit itype) (template-apply u.standard ~[typ.p.value])
8377+ ?~ result [%| ["unit construction is not supported by partial inference" ~]]
8378+ [%& u.result state.p.value]
8380+ ?~ prelude.state [%| ["list literal needs the standard prelude in partial inference" ~]]
8381+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8382+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8383+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude.state)
8384+ ?~ standard [%| ["list literal needs the standard prelude in partial inference" ~]]
8385+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]])
8386+ [%| ["list literal needs the standard prelude in partial inference" ~]]
8387+ =/ element=itype [%var next.state]
8388+ =/ result=iresult (infer-open-list-items items.e element env state(next +(next.state)) at.e)
8389+ ?: ?=(%| -.result) result
8390+ [%& [%collection %list ~[element]] state.p.result]
6924 %str (infer-string-pieces pieces.e env state)
8391 %str (infer-string-pieces pieces.e env state)
8393+ ?~ prelude.state [%| ["application path needs the standard prelude in partial inference" ~]]
8394+ ?. =(at.u.prelude.state /lib/jibb/prelude/jibb)
8395+ [%| ["application path needs the standard prelude in partial inference" ~]]
8396+ =/ standard=(unit ischeme) (find-jibb-mold %qath u.prelude.state)
8397+ ?~ standard [%| ["application path needs the standard prelude in partial inference" ~]]
8398+ ?. ?=(~ vars.u.standard) [%| ["application path mold needs unsupported inference" ~]]
8399+ =/ typ=itype typ.u.standard
8400+ ?. ?=(%jrec -.typ) [%| ["application path mold needs unsupported inference" ~]]
8401+ ?. &(=(at.typ /lib/jibb/internal/jibb) =(%qath name.typ) =(%i head.typ) =(%ta aura.typ) =(%t tail.typ))
8402+ [%| ["application path mold needs unsupported inference" ~]]
8403+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
8404+ =/ remain=(unit @ud) (qath-static-fuel segs.e (dec jrec-fuel.state))
8405+ ?~ remain [%| ["application path segments need unsupported inference" ~]]
8406+ [%& typ state(jrec-fuel u.remain)]
6926 ?~ names.e [%| ["empty wing" ~]]
8408 ?~ names.e [%| ["empty wing" ~]]
6927 ?^ t.names.e
8409 ?^ t.names.e
@@ -6930,7 +8412,7 @@
6930 ?~ iface (infer-field-wing names.e env state)
8412 ?~ iface (infer-field-wing names.e env state)
6931 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
8413 =/ member=(unit ischeme) (ienv-lookup i.names.e values.u.iface)
6932 ?~ member [%| ["module member is not available to partial inference" ~]]
8414 ?~ 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)
8415+ =. typ.u.member (itype-in-import typ.u.member u.iface i.t.names.e prelude.state)
6934 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
8416 =/ instance=[typ=itype state=istate] (instantiate-scheme u.member state)
6935 [%& typ.instance state.instance]
8417 [%& typ.instance state.instance]
6936 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
8418 =/ scheme=(unit ischeme) (ienv-lookup i.names.e env)
@@ -6943,6 +8425,11 @@
6943 =/ instance=[typ=itype state=istate] (instantiate-scheme u.scheme state)
8425 =/ instance=[typ=itype state=istate] (instantiate-scheme u.scheme state)
6944 [%& typ.instance state.instance]
8426 [%& typ.instance state.instance]
6945 %group $(e inner.e)
8427 %group $(e inner.e)
8429+ ?~ edits.e [%| ["a change takes at least one field" ~[[at.e "empty change"]]]]
8430+ =/ target=iresult $(e [%wing at.e target.e])
8431+ ?: ?=(%| -.target) target
8432+ (infer-change-edits edits.e typ.p.target env state.p.target ~)
6946 %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [[next.state tag.e] tags.state])]
8433 %ctor [%& [%tag next.state tag.e &] state(next +(next.state), tags [[next.state tag.e] tags.state])]
6948 =/ traced=iresult $(e val.e)
8435 =/ traced=iresult $(e val.e)
@@ -6959,6 +8446,9 @@
6959 [%| ["local molds shadow a name" ~]]
8446 [%| ["local molds shadow a name" ~]]
6960 =/ local-state=istate
8447 =/ local-state=istate
6961 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8448 state(globals (weld local-names globals.state), molds (weld local-molds molds.state))
8449+ =/ mold-hole=(unit span) (simple-local-mold-hole defs.e)
8451+ [%| ["type hole needs a determined type" ~[[u.mold-hole "unresolved type hole"]]]]
6962 ?. (local-molds-supported local-molds local-state)
8452 ?. (local-molds-supported local-molds local-state)
6963 [%| ["local molds need unsupported inference" ~]]
8453 [%| ["local molds need unsupported inference" ~]]
6964 =/ values=(list def) (local-value-defs defs.e)
8454 =/ values=(list def) (local-value-defs defs.e)
@@ -6968,12 +8458,22 @@
6968 ?: ?=(%| -.result) result
8458 ?: ?=(%| -.result) result
6969 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
8459 [%& typ.p.result state.p.result(globals globals.state, molds molds.state)]
8461+ ?^ defer.state (dg-boolean-branch e env state)
6971 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
8462 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
6972− ?~ t.arms.e (infer-cell-branch e env state)
8463+ ?~ t.arms.e
8464+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state ~)
8465+ ?^ empty-list u.empty-list
8466+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
8467+ ?^ empty-union (infer-known-union-branch-subject e env u.empty-union)
8468+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
8469+ ?^ single (infer-known-union-branch-subject e env u.single)
8470+ ?: (single-structured-pattern e) (infer-single-case-branch e env state ~)
8471+ (infer-cell-branch e env state ~)
6973 ?^ t.t.arms.e (infer-known-union-branch e env state)
8472 ?^ t.t.arms.e (infer-known-union-branch e env state)
6974− =/ known=(unit itype) (known-union-subject subject.e env state)
8473+ =/ known=(unit iresult) (known-union-subject subject.e env state)
6975− ?: &(?=(^ known) ?=(~ (unit-union-payload u.known)))
8474+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
6976− (infer-known-union-branch e env state)
8475+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
8476+ (infer-known-union-branch-subject e env u.known)
6977 =/ x=arm i.arms.e
8477 =/ x=arm i.arms.e
6978 =/ y=arm i.t.arms.e
8478 =/ y=arm i.t.arms.e
6979 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
8479 ?: |((unit-empty-pattern pat.x) (unit-empty-pattern pat.y))
@@ -6982,7 +8482,7 @@
6982 ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
8482 ?. ?=(%lit -.pat.y) (infer-known-union-branch e env state)
6983 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
8483 ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y))
6984 (infer-known-union-branch e env state)
8484 (infer-known-union-branch e env state)
6985− ?^ known (infer-known-union-branch e env state)
8485+ ?: &(?=(^ known) ?=(%& -.u.known)) (infer-known-union-branch-subject e env u.known)
6986 ?: =(val.lit.pat.x val.lit.pat.y)
8486 ?: =(val.lit.pat.x val.lit.pat.y)
6987 [%| ["branch does not cover both loobeans" ~]]
8487 [%| ["branch does not cover both loobeans" ~]]
6988 =/ subject=iresult $(e subject.e)
8488 =/ subject=iresult $(e subject.e)
@@ -7021,18 +8521,21 @@
7021 ?^ diag [%| u.diag]
8521 ?^ diag [%| u.diag]
7022 [%| ["cast mold is not supported by partial inference" ~]]
8522 [%| ["cast mold is not supported by partial inference" ~]]
7023 =/ value=iresult
8523 =/ value=iresult
7024− ?: &(?=(%union -.typ.u.target) (context-union-branch val.e))
8524+ (infer-call-context-arg val.e typ.u.target env state.u.target at.shape.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)
7031 ?: ?=(%| -.value) value
8525 ?: ?=(%| -.value) value
8526+ =/ shape=(unit [source=iwfields target=iwfields])
8527+ (width-shape typ.p.value typ.u.target sub.state.p.value)
8528+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
7032 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
8529 =/ fit=ifit (itype-fit typ.p.value typ.u.target sub.state.p.value next.state.p.value)
7033 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
8530 ?: ?=(%unknown -.fit) [%| ["cast constraint is not supported by partial inference" ~]]
7034 ?: ?=(%bad -.fit)
8531 ?: ?=(%bad -.fit)
8532+ =/ missing=(unit idiag) (missing-union-tag val.e typ.u.target sub.state.p.value at.shape.e)
8533+ ?^ missing [%| u.missing]
8534+ =/ 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)
8535+ ?^ nested [%| u.nested]
7035 [%| ["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)]]]]
8536 [%| ["cast mold and expression type do not unify" ~[[at.shape.e (site-type-note "cast mold" typ.u.target sub.state.p.value)] [(span-of val.e) (site-type-note "expression" typ.p.value sub.state.p.value)]]]]
8537+ ?: &(?=(^ defer.state.p.value) !(dg-stable-fit typ.p.value typ.u.target sub.fit))
8538+ [%| ["deferred cast fit needs stable inference" ~]]
7036 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
8539 =/ merged=itype (itype-merge-faces typ.p.value typ.u.target sub.fit)
7037 [%& merged state.p.value(sub sub.fit, next next.fit)]
8540 [%& merged state.p.value(sub sub.fit, next next.fit)]
7038 %crash [%& [%var next.state] state(next +(next.state))]
8541 %crash [%& [%var next.state] state(next +(next.state))]
@@ -7056,43 +8559,9 @@
7056 [%& [%fn typ.p.sam typ.p.body] state.p.body]
8559 [%& [%fn typ.p.sam typ.p.body] state.p.body]
7058 ?~ args.e [%| ["call has no argument" ~]]
8561 ?~ args.e [%| ["call has no argument" ~]]
7059− =/ head=iresult $(e head.e)
8562+ ?: (explicit-proj-call e env state)
7060− ?: ?=(%| -.head) head
8563+ [%| ["proj needs an expected record type" ~]]
7061− =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
8564+ (infer-call-with-head e env state (infer-fragment head.e env state))
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)
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" ~]]
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))
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)
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)]
7096 * [%| ["expression is not supported by partial inference" ~]]
8565 * [%| ["expression is not supported by partial inference" ~]]
@@ -7100,12 +8569,322 @@
7100:: failed. If an intermediate fit is uncertain, retain the whole argument
8569:: failed. If an intermediate fit is uncertain, retain the whole argument
7101:: span rather than assigning blame to a particular argument.
8570:: span rather than assigning blame to a particular argument.
8572+:: Check a call using the head already inferred in this state. Keeping
8573+:: this shared avoids evaluating or instantiating a contextual head twice.
8574+++ width-has-projections
8575+ |= ps=(list iwprojection)
8580++$ iwidth-elaboration [original=expr typ=itype sub=isub projections=(list iwprojection)]
8581+++ infer-width-elaboration
8582+ |= [e=expr env=ienv state=istate]
8583+ ^- (each iwidth-elaboration idiag)
8584+ =/ out=iresult (infer-fragment e env state)
8585+ ?: ?=(%| -.out) [%| p.out]
8586+ [%& [e typ.p.out sub.state.p.out (flop projections.state.p.out)]]
8588+:: Source-bound gate-layout evidence, confined to checked root gate
8589+:: definitions and direct unshadowed prelude calls. The prepared prelude
8590+:: interface and its retained source are trusted as a matching artifact.
8591+:: Layouts identify sample binder faces; they do not change call arity or
8592+:: authorize stripping nested value faces. Unknown origins use ordinary fit.
8593+++ direct-written-gates
8594+ |= [ds=(list def) out=ivisited]
8597+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8598+ ?. |(?=(%gate -.val.i.ds) ?=(%gate-wide -.val.i.ds)) $(ds t.ds)
8599+ $(ds t.ds, out (~(put by out) name.i.ds &))
8600+++ direct-may-use-prelude
8601+ |= [ds=(list def) root=ivisited heads=ivisited]
8604+ ?: ?=(%mold -.i.ds) $(ds t.ds)
8605+ =/ refs=(list term) (dependency-expr val.i.ds)
8606+ =/ has-root=? (lien refs |=(n=term ?=(^ (~(get by root) n))))
8607+ =/ has-head=? (lien refs |=(n=term ?=(^ (~(get by heads) n))))
8608+ ?: &(has-root has-head) &
8610+++ direct-unique-names
8611+ |= [names=(list term) seen=ivisited]
8614+ ?: ?=(^ (~(get by seen) i.names)) |
8615+ $(names t.names, seen (~(put by seen) i.names &))
8616+++ direct-prelude-evidence
8617+ |= [ds=(list def) prelude=(unit ifile)]
8618+ ^- (unit igate-prelude-evidence)
8620+ ?~ source.u.prelude ~
8621+ =/ root=ivisited (direct-written-gates ds ~)
8622+ =/ names=(list term) (turn values.u.prelude |=(e=[name=term scheme=ischeme] name.e))
8623+ =/ heads=ivisited (graph-nameset names ~)
8624+ ?. (direct-may-use-prelude ds root heads) ~
8625+ =/ parsed (parse at.u.prelude u.source.u.prelude)
8626+ ?: ?=(%| -.parsed) ~
8627+ ?^ (duplicate-defs defs.p.parsed) ~
8628+ ?. (direct-unique-names (global-value-names defs.p.parsed) ~) ~
8629+ =/ gates=(map term def) (direct-checked-gates defs.p.parsed values.u.prelude)
8631+++ direct-checked-gates
8632+ |= [ds=(list def) env=ienv]
8634+ =/ names=(list term) (turn env |=(e=[name=term scheme=ischeme] name.e))
8635+ =/ known=ivisited (graph-nameset names ~)
8636+ =/ out=(map term def) ~
8640+ ?: ?=(%mold -.d) $(ds t.ds)
8641+ ?. ?=(^ (~(get by known) name.d)) $(ds t.ds)
8642+ ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) $(ds t.ds)
8643+ $(ds t.ds, out (~(put by out) name.d d))
8645+ |= [n=term ds=(list def)]
8648+ ?: &(?=(%value -.i.ds) =(n name.i.ds)) `i.ds
8650+++ direct-gate-sample
8653+ ?. ?=(%value -.d) ~
8655+ %gate `sample.val.d
8656+ %gate-wide `sample.val.d
8659+++ direct-sample-name
8668+++ direct-field-name
8677+ |= [typ=itype name=(unit term)]
8680+ ?. ?=(%face -.typ) ~
8681+ ?. =(name.typ u.name) ~
8684+ |= [a=itype b=itype sub=isub next=@ud]
8686+ ?: (itype-face-asym a b sub) [%unknown ~]
8687+ =/ forward=ifit (itype-fit a b sub next)
8688+ ?. ?=(%ok -.forward) [%unknown ~]
8689+ ?: (itype-face-asym a b sub.forward) [%unknown ~]
8690+ =/ reverse=ifit (itype-fit b a sub.forward next.forward)
8691+ ?. ?=(%ok -.reverse) [%unknown ~]
8693+++ direct-function-fit
8694+ |= [a=itype b=itype sam=sample sh=shape sub=isub next=@ud]
8696+ ?. &(?=(%fn -.a) ?=(%fn -.b) ?=(%cell -.sam) ?=(%fn -.sh)) [%unknown ~]
8697+ ?. ?=(%cell -.sample.sh) [%unknown ~]
8698+ =/ as=(list sample) items.sam
8699+ =/ bs=(list field) fields.sample.sh
8701+ ?~ t.as [%unknown ~]
8702+ ?^ t.t.as [%unknown ~]
8704+ ?~ t.bs [%unknown ~]
8705+ ?^ t.t.bs [%unknown ~]
8706+ ?. &(?=(%cell -.sample.a) ?=(%cell -.sample.b)) [%unknown ~]
8707+ =/ an=(unit term) (direct-sample-name i.as)
8708+ =/ bn=(unit term) (direct-field-name i.bs)
8709+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8710+ =/ x=(unit itype) (direct-slot-body hed.sample.a an)
8711+ =/ y=(unit itype) (direct-slot-body hed.sample.b bn)
8714+ =/ first=ifit (direct-invariant u.x u.y sub next)
8715+ ?. ?=(%ok -.first) [%unknown ~]
8716+ =. an (direct-sample-name i.t.as)
8717+ =. bn (direct-field-name i.t.bs)
8718+ ?: &(?=(^ an) ?=(^ bn) !=(u.an u.bn)) [%unknown ~]
8719+ =/ x2=(unit itype) (direct-slot-body tal.sample.a an)
8720+ =/ y2=(unit itype) (direct-slot-body tal.sample.b bn)
8723+ =/ second=ifit (direct-invariant u.x2 u.y2 sub.first next.first)
8724+ ?. ?=(%ok -.second) [%unknown ~]
8725+ (direct-invariant product.a product.b sub.second next.second)
8726+:: This is a tentative proof: its caller must require closed call samples
8727+:: and repeat every positional check under the stable final substitution.
8728+++ direct-positional-fit
8729+ |= [args=(list expr) slots=(list sample) actual=itype expected=itype env=ienv state=istate sub=isub next=@ud]
8731+ ?~ args [%unknown ~]
8732+ ?~ slots [%unknown ~]
8733+ =/ last=? ?=(~ t.args)
8734+ ?: !=(last ?=(~ t.slots)) [%unknown ~]
8735+ =/ split=(unit [left=itype right=itype])
8736+ ?: last `[actual expected]
8737+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8738+ `[hed.actual hed.expected]
8739+ ?~ split [%unknown ~]
8740+ =/ x=itype left.u.split
8741+ =/ y=itype right.u.split
8742+ =/ expected-name=(unit term) (direct-sample-name i.slots)
8743+ =/ expected-body=(unit itype) (direct-slot-body y expected-name)
8744+ ?~ expected-body [%unknown ~]
8745+ =. y u.expected-body
8746+ =/ fit=ifit (itype-fit x y sub next)
8747+ =/ accepted=? &(?=(%ok -.fit) !(itype-positional-slot-face-asym x y sub.fit))
8748+ =/ result=(unit ifit)
8750+ ?. &(?=(%face -.i.slots) ?=(%fn -.shape.i.slots)) ~
8751+ ?. ?=(%wing -.i.args) ~
8752+ ?. ?=([@ ~] names.i.args) ~
8753+ ?. (unique-value-name i.names.i.args globals.state) ~
8754+ =/ source=(unit def) (~(get by gate-defs.state) i.names.i.args)
8756+ =/ sample=(unit sample) (direct-gate-sample u.source)
8758+ =/ trial=ifit (direct-function-fit x y u.sample shape.i.slots sub next)
8759+ ?. ?=(%ok -.trial) ~
8761+ ?~ result [%unknown ~]
8764+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) [%unknown ~]
8765+ ?. ?=(%ok -.fit) [%unknown ~]
8766+ $(args t.args, slots t.slots, actual tal.actual, expected tal.expected, sub sub.fit, next next.fit)
8767+++ direct-any-gate-arg
8768+ |= [args=(list expr) defs=(map term def)]
8772+ ?. ?=(%wing -.i.args) |
8773+ ?. ?=([@ ~] names.i.args) |
8774+ ?=(^ (~(get by defs) i.names.i.args))
8777+++ direct-gate-call-fit
8778+ |= [e=expr actual=itype expected=itype env=ienv state=istate]
8783+ ?. &(?=(%cell -.actual) ?=(%cell -.expected)) ~
8784+ ?. ?=(%wing -.head.e) ~
8785+ ?. ?=([@ ~] names.head.e) ~
8786+ ?. ?=(~ (ienv-lookup i.names.head.e env)) ~
8787+ ?. (unique-value-name i.names.head.e globals.state) ~
8788+ ?. (direct-any-gate-arg args.e gate-defs.state) ~
8790+ ?~ source.u.prelude.state ~
8791+ ?~ head-evidence.state ~
8792+ ?. =(u.prelude.state iface.u.head-evidence.state) ~
8793+ ?. ?=(^ (ienv-lookup i.names.head.e values.u.prelude.state)) ~
8794+ =/ head=(unit def) (~(get by gates.u.head-evidence.state) i.names.head.e)
8796+ =/ sam=(unit sample) (direct-gate-sample u.head)
8798+ ?. ?=(%cell -.u.sam) ~
8799+ =/ fit=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.state next.state)
8801+ :: Enclosing inference may add constraints after this call. Only a
8802+ :: closed call-sample proof can remain stable under those later bindings.
8803+ =/ actual-final=itype (itype-normalize actual sub.fit)
8804+ =/ expected-final=itype (itype-normalize expected sub.fit)
8805+ ?^ (itype-vars actual-final) ~
8806+ ?^ (itype-vars expected-final) ~
8807+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
8808+ :: A later argument may resolve a variable used by an earlier slot.
8809+ :: Recheck every fit and face against the completed substitution; no
8810+ :: additional binding or fresh variable is permitted in the second pass.
8811+ =/ verified=ifit (direct-positional-fit args.e items.u.sam actual expected env state sub.fit next.fit)
8812+ ?. ?=(%ok -.verified) ~
8813+ ?. &(=(sub.fit sub.verified) =(next.fit next.verified)) ~
8816+++ infer-call-with-head
8817+ |= [e=expr env=ienv state=istate head=iresult]
8820+ ?~ args.e [%| ["call has no argument" ~]]
8821+ ?: ?=(%| -.head) head
8822+ =/ head-type=itype (itype-walk typ.p.head sub.state.p.head)
8825+ ?: ?=(%fn -.head-type)
8826+ (infer-call-context-args args.e sample.head-type env state.p.head (span-of head.e))
8827+ (infer-simple-items (turn args.e |=(a=expr [(span-of a) ~ a])) env state.p.head)
8828+ ?: ?=(%fn -.head-type)
8829+ (infer-call-context-arg i.args.e sample.head-type env state.p.head (span-of head.e))
8830+ (infer-fragment i.args.e env state.p.head)
8831+ ?: ?=(%| -.arg) arg
8832+ =/ st=istate state.p.arg
8833+ =/ ht=itype (itype-walk typ.p.head sub.st)
8835+ =/ shape=(unit [source=iwfields target=iwfields])
8837+ (width-shape typ.p.arg sample.ht sub.st)
8838+ ?^ shape [%| ["record width constraint needs unsupported inference" ~]]
8840+ ?^ t.args.e (itype-fit-inner typ.p.arg sample.ht sub.st next.st & |)
8841+ (itype-fit typ.p.arg sample.ht sub.st next.st)
8842+ =/ direct=(unit ifit)
8844+ (direct-gate-call-fit e typ.p.arg sample.ht env st)
8845+ =. fit ?~(direct fit u.direct)
8846+ ?: ?=(%unknown -.fit)
8847+ ?~ defer.st [%| ["call constraint is not supported by partial inference" ~]]
8848+ =/ edge=(unit dgo) (dg-eligible-ctor e typ.p.head typ.p.arg sample.ht st)
8849+ ?~ edge [%| ["call constraint is not supported by partial inference" ~]]
8850+ ?: (gth (lent obligations.st) 63) [%| ["call constraint is not supported by partial inference" ~]]
8851+ [%& product.ht st(obligations [u.edge obligations.st])]
8855+ =/ missing=(unit idiag) (missing-union-tag i.args.e sample.ht sub.st (span-of head.e))
8856+ ?^ missing [%| u.missing]
8857+ =/ nested=(unit idiag) (nested-missing-tag i.args.e typ.p.arg sample.ht sub.st next.st (span-of head.e))
8858+ ?^ nested [%| u.nested]
8859+ [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [(span-of i.args.e) (site-type-note "argument" typ.p.arg sub.st)]]]]
8860+ =/ bad=(unit [at=span typ=itype])
8861+ (call-error-site args.e typ.p.arg sample.ht sub.st next.st)
8863+ [beg:(span-of i.args.e) end:(span-of (rear args.e))]
8864+ =/ arg-at=span ?~(bad whole-args at.u.bad)
8865+ =/ arg-type=itype ?~(bad typ.p.arg typ.u.bad)
8866+ [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [arg-at (site-type-note "argument" arg-type sub.st)]]]]
8867+ ?: &(?=(^ defer.st) !(dg-stable-call-fit typ.p.arg sample.ht product.ht sub.fit ?=(^ t.args.e)))
8868+ [%| ["deferred call fit needs stable inference" ~]]
8871+ ?^ t.args.e (itype-positional-face-asym args.e typ.p.arg sample.ht sub.fit)
8872+ (itype-face-asym typ.p.arg sample.ht sub.fit)
8873+ ?: &((itype-has-face typ.p.arg sub.fit) face-asym (itype-output-may-be-cell product.ht sub.fit))
8874+ [%| ["call result face propagation is not supported by partial inference" ~]]
8875+ [%& product.ht st(sub sub.fit, next next.fit)]
8876+ =/ result=itype [%var next.st]
8877+ =/ uni=(unit isub) (itype-unify ht [%fn typ.p.arg result] sub.st)
8879+ [%| ["call's sample and argument types do not unify" ~[[(span-of head.e) (site-type-note "called gate" ht sub.st)] [(span-of i.args.e) (site-type-note "argument" typ.p.arg sub.st)]]]]
8880+ [%& result st(next +(next.st), sub u.uni)]
7103++ call-error-site
8882++ call-error-site
7104 |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
8883 |= [args=(list expr) actual=itype expected=itype sub=isub next=@ud]
7105 ^- (unit [at=span typ=itype])
8884 ^- (unit [at=span typ=itype])
7106 ?~ args ~
8885 ?~ args ~
7107 =/ original=[left=itype right=itype] [actual expected]
8886 =/ 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)) ~
8887+ ?: |(?=(%var -.left.original) ?=(%avar -.left.original) ?=(%rvar -.left.original) |(?=(%nvar -.left.original) ?=(%rnvar -.left.original)) ?=(%var -.right.original) ?=(%avar -.right.original) ?=(%rvar -.right.original) |(?=(%nvar -.right.original) ?=(%rnvar -.right.original))) ~
7109 =. actual (itype-walk actual sub)
8888 =. actual (itype-walk actual sub)
7110 =. expected (itype-walk expected sub)
8889 =. expected (itype-walk expected sub)
7111 ?: &(?=(%face -.expected) !?=(%face -.actual))
8890 ?: &(?=(%face -.expected) !?=(%face -.actual))
@@ -7120,34 +8899,505 @@
7120 ?: ?=(%unknown -.first) ~
8899 ?: ?=(%unknown -.first) ~
7121 $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
8900 $(args t.args, actual tal.actual, expected tal.expected, sub sub.first, next next.first)
7123−:: Context can help each argument while the final fit still checks the
8902+:: Context can help a call argument or cast value while the final fit
7124−:: complete right-nested sample, including any faces on its positions.
8903+:: checks the complete right-nested type, including any written faces.
8905+:: Context can resolve the payload of a canonical prelude unit, but an
8906+:: unrelated union with a similar noun shape is not the same mold.
8907+++ infer-unit-context
8908+ |= [e=expr expected=itype env=ienv state=istate context=span]
8911+ ?> ?=(%union -.expected)
8912+ ?~ prelude.state (infer-fragment e env state)
8913+ =/ standard=(unit ischeme) (find-jibb-mold %unit u.prelude.state)
8914+ ?~ standard (infer-fragment e env state)
8915+ ?. (standard-unit-template u.standard at.u.prelude.state) (infer-fragment e env state)
8916+ ?. =(origin.expected `[at.u.prelude.state %unit]) (infer-fragment e env state)
8917+ ?~ args.expected (infer-fragment e env state)
8918+ ?^ t.args.expected (infer-fragment e env state)
8919+ =/ payload=itype i.args.expected
8920+ =/ canonical=(unit itype) (template-apply u.standard ~[payload])
8921+ ?~ canonical (infer-fragment e env state)
8922+ ?> ?=(%union -.u.canonical)
8923+ ?. =((itype-normalize expected(label ~) sub.state) (itype-normalize u.canonical(label ~) sub.state))
8924+ (infer-fragment e env state)
8925+ =/ value=iresult (infer-call-context-arg val.e payload env state context)
8926+ ?: ?=(%| -.value) value
8927+ =/ fit=ifit (itype-fit typ.p.value payload sub.state.p.value next.state.p.value)
8928+ ?: ?=(%unknown -.fit) [%| ["unit payload constraint is not supported by partial inference" ~]]
8930+ =/ missing=(unit idiag) (missing-union-tag val.e payload sub.state.p.value context)
8931+ ?^ missing [%| u.missing]
8932+ =/ nested=(unit idiag) (nested-missing-tag val.e typ.p.value payload sub.state.p.value next.state.p.value context)
8933+ ?^ nested [%| u.nested]
8934+ [%| ["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)]]]]
8935+ [%& expected state.p.value(sub sub.fit, next next.fit)]
8937+:: A known gate may receive an enclosing target before its argument is
8938+:: inferred when its result is open or a direct, matching named generic
8939+:: union. Opaque, recursive, tag-constrained and variable-bound union
8940+:: results keep the existing directional path.
8941+++ infer-contextual-call
8942+ |= [e=expr expected=itype env=ienv state=istate]
8945+ ?~ args.e [%| ["call has no argument" ~]]
8946+ =/ head=iresult (infer-fragment head.e env state)
8947+ ?: ?=(%| -.head) head
8948+ =/ ht=itype (itype-walk typ.p.head sub.state.p.head)
8949+ ?. ?=(%fn -.ht) (infer-call-with-head e env state head)
8950+ =/ result=itype (itype-walk product.ht sub.state.p.head)
8952+ ?: ?=(%var -.result) &
8953+ :: A direct known generic union may receive the same nominal result
8954+ :: context before its arguments are checked. Variable-bound origins,
8955+ :: pending tags, recursive identities and unknown atoms stay open.
8956+ ?. &(?=(%union -.product.ht) ?=(%union -.result) ?=(%union -.expected)) |
8958+ ?. =(origin.result origin.expected) |
8960+ ?. =((lent args.result) (lent args.expected)) |
8961+ ?: |((itype-has-tag (itype-normalize result sub.state.p.head)) (itype-has-tag (itype-normalize expected sub.state.p.head))) |
8962+ ?: |((itype-has-recursive (itype-normalize result sub.state.p.head)) (itype-has-recursive (itype-normalize expected sub.state.p.head))) |
8963+ ?: |((itype-has-any-atom result sub.state.p.head) (itype-has-any-atom expected sub.state.p.head)) |
8965+ ?. eligible (infer-call-with-head e env state head)
8966+ ?: |(?=(%var -.expected) ?=(%avar -.expected) ?=(%rvar -.expected) |(?=(%nvar -.expected) ?=(%rnvar -.expected)) (itype-has-tag (itype-normalize expected sub.state.p.head)))
8967+ (infer-call-with-head e env state head)
8968+ =/ sub=(unit isub) (itype-unify result expected sub.state.p.head)
8969+ ?~ sub (infer-call-with-head e env state head)
8970+ (infer-call-with-head e env state [%& typ.p.head state.p.head(sub u.sub)])
8972+:: An eligible fully faced literal receives context by name, in source order.
8973+++ width-literal-fields
8974+ |= [items=(list item) axis=@ud fuel=@ud]
8976+ =/ order=(list iwfield) ~
8977+ =/ index=(map term iwfield) *(map term iwfield)
8982+ =/ at-axis=@ud ?~(t.items axis (mul 2 axis))
8983+ =/ entry=iwfield [u.face.i.items at-axis [%noun ~]]
8984+ ?: ?=(^ (~(get by index) name.entry)) ~
8985+ =. index (~(put by index) name.entry entry)
8986+ =. order [entry order]
8987+ ?~ t.items `[(flop order) index]
8988+ $(items t.items, axis +((mul 2 axis)), fuel (dec fuel))
8989+++ width-infer-items
8990+ |= [items=(list item) expected=(map term iwfield) env=ienv state=istate context=span]
8992+ ?~ items [%| ["empty record is not supported" ~]]
8993+ ?~ face.i.items [%| ["record face needs unsupported inference" ~]]
8994+ =/ field=(unit iwfield) (~(get by expected) u.face.i.items)
8996+ ?~ field (infer-fragment val.i.items env state)
8997+ (infer-call-context-arg val.i.items typ.u.field env state context)
8998+ ?: ?=(%| -.head) head
8999+ =/ typ=itype [%face u.face.i.items typ.p.head]
9000+ ?~ t.items [%& typ state.p.head]
9001+ =/ tail=iresult $(items t.items, state state.p.head)
9002+ ?: ?=(%| -.tail) tail
9003+ [%& [%cell typ typ.p.tail] state.p.tail]
9004+++ width-infer-literal
9005+ |= [e=expr expected=itype env=ienv state=istate context=span]
9007+ ?. ?=(%tuple -.e) ~
9008+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) ~
9009+ =/ source=(unit iwfields) (width-literal-fields items.e 1 4.096)
9010+ =/ target=(unit iwfields) (width-scan expected sub.state 1 4.096)
9013+ ?: (lth (lent order.u.source) (lent order.u.target)) ~
9014+ ?. (width-in-order order.u.source order.u.target)
9015+ `(infer-simple-items items.e env state)
9016+ `(width-infer-items items.e index.u.target env state context)
9018+:: Experimental intrinsic recognition; real bindings retain normal calls.
9019+++ explicit-proj-call
9020+ |= [e=expr env=ienv state=istate]
9023+ ?. ?=([* ~] args.e) |
9024+ ?. ?=(%wing -.head.e) |
9025+ ?. =(names.head.e ~[%proj]) |
9026+ ?: ?=(^ (ienv-lookup %proj env)) |
9027+ ?: (lien globals.state |=(n=term =(n %proj))) |
9029+ ?:(?=(^ (ienv-lookup %proj values.u.prelude.state)) | &)
9030+++ infer-proj-source
9031+ |= [e=expr expected=itype env=ienv state=istate context=span]
9033+ ?: ?=(%group -.e) $(e inner.e)
9034+ =/ literal=(unit iresult) (width-infer-literal e expected env state context)
9035+ ?^ literal u.literal
9036+ (infer-fragment e env state)
9037+++ infer-proj-context
9038+ |= [e=expr expected=itype env=ienv state=istate context=span]
9041+ ?~ args.e [%| ["proj needs one record" ~]]
9042+ ?. |(?=(%cell -.expected) ?=(%face -.expected)) [%| ["proj needs an expected record type" ~]]
9043+ =/ value=iresult (infer-proj-source i.args.e expected env state context)
9044+ ?: ?=(%| -.value) value
9045+ =/ shape=(unit [source=iwfields target=iwfields])
9046+ (width-proj-shape typ.p.value expected sub.state.p.value)
9047+ ?~ shape [%| ["proj needs a known record containing its expected fields" ~]]
9048+ =/ project=(unit iwidth-result) (width-project u.shape sub.state.p.value next.state.p.value)
9049+ ?~ project [%| ["proj constraint needs unsupported inference" ~]]
9050+ =/ st=istate state.p.value(sub sub.u.project, next next.u.project)
9051+ [%& expected st(projections [[at.e e typ.p.value expected steps.u.project] projections.st])]
9053+:: A known literal singleton in a direct union can contextualize a
9054+:: loobean literal of the same noun. Only explicit singleton and cell
9055+:: competitors are considered; opaque or variable cases stay unknown.
9056+++ explicit-singleton-in-union
9057+ |= [t=itype noun=@]
9059+ ?. ?=(%union -.t) |
9060+ =/ cases=(list itype) cases.t
9065+ ?: ?=(%cell -.c) $(cases t.cases)
9066+ ?. ?=(%const -.c) |
9067+ ?: =(noun val.literal.c)
9069+ $(cases t.cases, found &)
9072+:: Select a written literal-headed case only when every competing case is
9073+:: also an explicit singleton-headed cell and exactly one matches. Opaque,
9074+:: variable-bound and differently shaped cases keep inference unchanged.
9075+:: This first slice supplies context to a directly called payload. Plain
9076+:: literal data and other expressions retain their existing inference path.
9077+++ contextual-atomic-arguments
9078+ |= args=(list expr)
9081+ ?. ?=(?(%lit %wing %ctor) -.i.args) |
9083+++ contextual-direct-payload-call
9086+ ?: ?=(%group -.e) $(e inner.e)
9088+ ?. ?=(%wing -.head.e) |
9090+ (contextual-atomic-arguments args.e)
9092+:: A walked variable may have concealed a union inside a substituted
9093+:: structure before this arm was called. Decline in that case rather than
9094+:: deriving provenance from the already-walked type.
9095+++ contextual-simple-sub
9099+ ?: ?=(?(%cell %face %fn %union %collection) -.val.i.sub) |
9102+:: Check the syntactic root before scanning; scan substitutions once.
9103+++ grec-direct-context
9104+ |= [expected=itype sub=isub]
9108+ ?: ?=(%face -.expected)
9110+ $(expected body.expected, left (dec left))
9111+ ?. ?=(%grec -.expected) |
9114+ ?: ?=(?(%cell %face %fn %union %collection %grec) -.val.i.sub) |
9115+ $(sub t.sub, left (dec left))
9116+++ contextual-direct-union
9119+ ?: ?=(%face -.target) $(target body.target)
9120+ ?=(%union -.target)
9121+++ contextual-tagged-case
9122+ |= [target=itype tag=@ sub=isub]
9124+ ?. ?=(%union -.target) ~
9125+ =/ remaining=(list itype) cases.target
9126+ =/ found=(unit itype) ~
9127+ =/ seen=(set @) *(set @)
9130+ =/ c=itype i.remaining
9132+ =/ head=itype hed.c
9133+ ?. ?=(%const -.head) ~
9134+ ?: (~(has in:..zuse seen) val.literal.head) ~
9135+ =. seen (~(put in:..zuse seen) val.literal.head)
9136+ ?: =(tag val.literal.head)
9137+ $(remaining t.remaining, found `c)
9138+ $(remaining t.remaining)
9140+:: A bounded syntactic screen: no nested branch, cast, gate or local body
9141+:: can re-enter cell-branch retry during either inference attempt.
9142+++ closed-cell-retry-safe
9143+ |= [todo=(list expr) fuel=@ud]
9150+ %lit $(todo t.todo)
9151+ %wing $(todo t.todo)
9152+ %ctor $(todo t.todo)
9153+ %path $(todo t.todo)
9154+ %crash $(todo t.todo)
9156+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) |
9158+ %group $(todo [inner.e t.todo])
9159+ %pair $(todo [val.e t.todo])
9160+ %unit $(todo [val.e t.todo])
9161+ %list $(todo (weld items.e t.todo))
9162+ %tuple $(todo (weld (turn items.e |=(i=item val.i)) t.todo))
9163+ %change $(todo (weld (turn edits.e |=(ed=edit val.ed)) t.todo))
9164+ %call $(todo [head.e (weld args.e t.todo)])
9165+ %trace $(todo [val.e then.e t.todo])
9168+++ closed-cell-sub-safe
9169+ |= [sub=isub fuel=@ud]
9173+ ?: ?=(?(%cell %face %fn %union %collection %grec %jrec %recursive) -.val.i.sub) |
9174+ $(sub t.sub, fuel (dec fuel))
9176+++ closed-cell-branch-eligible
9177+ |= [e=expr expected=itype sub=isub]
9179+ ?. &(?=(%branch -.e) ?=(%cell -.expected) (closed-cell-sub-safe sub 512)) |
9184+ =/ y=arm i.t.arms.e
9185+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
9186+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
9187+ ?: =(val.lit.pat.x val.lit.pat.y) |
9188+ (closed-cell-retry-safe ~[subject.e val.x val.y] 512)
9190+:: Attempt ordinary inference first; retry from the same state only for
9191+:: the bounded non-reentrant syntax above. Preserve original value faces.
9192+++ infer-closed-cell-branch
9193+ |= [e=expr expected=itype env=ienv state=istate context=span]
9195+ ?> (closed-cell-branch-eligible e expected sub.state)
9199+ =/ ordinary=iresult (infer-fragment e env state)
9201+ ?: ?=(%| -.ordinary) |
9202+ =/ fit=ifit (itype-fit typ.p.ordinary expected sub.state.p.ordinary next.state.p.ordinary)
9204+ ?: ordinary-good ordinary
9205+ =/ attempt=(unit iresult)
9207+ =/ y=arm i.t.arms.e
9208+ =/ subject=iresult (infer-fragment subject.e env state)
9209+ ?: ?=(%| -.subject) ~
9210+ =/ subject-type=itype (itype-normalize typ.p.subject sub.state.p.subject)
9211+ ?: ?=(%union -.subject-type) ~
9212+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
9214+ =/ left=iresult (infer-call-context-arg val.x expected env state.p.subject(sub u.su) context)
9216+ =/ lf=ifit (itype-fit typ.p.left expected sub.state.p.left next.state.p.left)
9218+ =/ right=iresult (infer-call-context-arg val.y expected env state.p.left(sub sub.lf, next next.lf) context)
9219+ ?: ?=(%| -.right) ~
9220+ =/ rf=ifit (itype-fit typ.p.right expected sub.state.p.right next.state.p.right)
9223+ =/ next=@ud next.rf
9224+ =/ lt=itype (itype-normalize typ.p.left sub)
9225+ =/ rt=itype (itype-normalize typ.p.right sub)
9226+ =/ et=itype (itype-normalize expected sub)
9228+ ?: |(?=(^ (itype-vars lt)) ?=(^ (itype-vars rt)) ?=(^ (itype-vars et))) ~
9229+ ?: |((itype-has-tag lt) (itype-has-tag rt) (itype-has-tag et)) ~
9230+ =/ lcheck=ifit (itype-fit typ.p.left expected sub next)
9231+ ?. ?=(%ok -.lcheck) ~
9232+ ?. &(=(sub.lcheck sub) =(next.lcheck next)) ~
9233+ =/ rcheck=ifit (itype-fit typ.p.right expected sub next)
9234+ ?. ?=(%ok -.rcheck) ~
9235+ ?. &(=(sub.rcheck sub) =(next.rcheck next)) ~
9236+ `[%& typ.p.left state.p.right(sub sub, next next)]
9237+ ?~ attempt ordinary
7126++ infer-call-context-arg
9240++ infer-call-context-arg
7127 |= [e=expr expected=itype env=ienv state=istate context=span]
9241 |= [e=expr expected=itype env=ienv state=istate context=span]
7128 ^- iresult
9242 ^- iresult
9243+ ?: &(?=(^ defer.state) ?=(%branch -.e)) (infer-fragment e env state)
9244+ ?: ?=(%pair -.e) $(e (pair-as-cell e))
9245+ ?: ?=(%group -.e) $(e inner.e)
9246+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
9248+ =/ traced=iresult (infer-fragment val.e env state)
9249+ ?: ?=(%| -.traced) traced
9250+ $(e then.e, state state.p.traced)
7129 =/ target=itype (itype-walk expected sub.state)
9251 =/ target=itype (itype-walk expected sub.state)
7131 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9253 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9254+ ?: (explicit-proj-call e env state)
9255+ (infer-proj-context e expected env state context)
9256+ :: Experimental construction only for a source-proven direct target.
9257+ :: Decline any walked structural binding to retain raw-variable provenance.
9258+ ?: &(?=(%grec -.target) ?=(%tuple -.e) (grec-direct-context expected sub.state))
9259+ =/ unfolded=(unit [view=itype left=@ud]) (grec-unfold-view target jrec-fuel.state)
9260+ ?~ unfolded [%| ["recursive mold unfolding needs unsupported inference" ~]]
9261+ ?~ items.e [%| ["recursive mold constructor needs unsupported inference" ~]]
9262+ =/ first=item i.items.e
9263+ ?. &(?=(~ face.first) ?=(%lit -.val.first) =(%term form.lit.val.first))
9264+ [%| ["recursive mold constructor needs unsupported inference" ~]]
9265+ =/ chosen=(unit itype) (contextual-tagged-case view.u.unfolded val.lit.val.first sub.state)
9266+ ?~ chosen [%| ["recursive mold constructor has no matching case" ~]]
9267+ =/ value=iresult (infer-call-context-items items.e u.chosen env state(jrec-fuel left.u.unfolded) context)
9268+ ?: ?=(%| -.value) value
9269+ =/ fit=ifit (itype-fit typ.p.value u.chosen sub.state.p.value next.state.p.value)
9270+ ?: ?=(%unknown -.fit) [%| ["recursive mold case needs unsupported inference" ~]]
9271+ ?: ?=(%bad -.fit) [%| ["recursive mold case does not fit its source shape" ~]]
9272+ [%& target state.p.value(sub sub.fit, next next.fit)]
9273+ :: Only the source-proven one-layer cell is exposed. Each recursive
9274+ :: descent consumes one written tuple; named values use ordinary fit.
9275+ ?: &(?=(%jrec -.target) ?=(%lit -.e) =(%null form.lit.e))
9276+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9277+ [%& target state(jrec-fuel (dec jrec-fuel.state))]
9278+ ?: &(?=(%jrec -.target) ?=(%tuple -.e))
9279+ ?: =(0 jrec-fuel.state) [%| ["recursive mold unfolding needs unsupported inference" ~]]
9280+ =. state state(jrec-fuel (dec jrec-fuel.state))
9282+ [%cell [%face head.target [%atom aura.target]] [%face tail.target target]]
9283+ =/ value=iresult (infer-call-context-items items.e shape env state context)
9284+ ?: ?=(%| -.value) value
9285+ =/ fit=ifit (itype-fit typ.p.value shape sub.state.p.value next.state.p.value)
9286+ ?: ?=(%unknown -.fit) [%| ["recursive mold cell constraint needs unsupported inference" ~]]
9287+ ?: ?=(%bad -.fit) [%| ["recursive mold cell does not fit its source shape" ~]]
9288+ [%& target state.p.value(sub sub.fit, next next.fit)]
9289+ ?: ?=(%call -.e) (infer-contextual-call e target env state)
9290+ =/ empty-list=(unit iresult) (empty-list-null-branch e env state `[target context])
9291+ ?^ empty-list u.empty-list
9292+ ?: (single-structured-pattern e)
9294+ =/ empty-union=(unit iresult) (known-empty-union-wing subject.e env state)
9295+ ?^ empty-union (infer-known-union-context-subject e target env u.empty-union context)
9296+ =/ single=(unit iresult) (grec-single-wing-subject subject.e env state)
9297+ ?^ single (infer-known-union-context-subject e target env u.single context)
9298+ (infer-single-case-branch e env state `[target context])
9299+ ?: (cell-binder-pattern e)
9300+ (infer-cell-branch e env state `[target context])
9301+ :: In an explicit singleton context retain the written loobean noun;
9302+ :: the ordinary singleton fit compares its noun, not its spelling.
9303+ =/ singleton=(unit itype)
9305+ ?. =(%loobean form.lit.e) ~
9306+ ?. |(?=(%const -.target) &(?=(%union -.expected) (explicit-singleton-in-union expected val.lit.e))) ~
9308+ ?^ singleton [%& u.singleton state]
9309+ =/ known=(unit iresult)
9310+ ?: ?=(%branch -.e) (known-union-subject subject.e env state)
9312+ ?: &(?=(^ known) ?=(%| -.u.known) !(duplicate-loobean-arms e)) u.known
9313+ ?: &(?=(^ known) ?=(%& -.u.known) ?=(~ (unit-union-payload (itype-normalize typ.p.u.known sub.state.p.u.known))))
9314+ (infer-known-union-context-subject e target env u.known context)
9315+ ?: &(?=(%union -.target) ?=(%unit -.e))
9316+ (infer-unit-context e target env state context)
9317+ ?: (closed-cell-branch-eligible e expected sub.state)
9318+ (infer-closed-cell-branch e expected env state context)
9319+ ?: &(?=(%flag -.target) (context-union-branch e))
9320+ (infer-union-context e target env state context)
7132 ?: &(?=(%union -.target) (context-union-branch e))
9321 ?: &(?=(%union -.target) (context-union-branch e))
7133 (infer-union-context e target env state context)
9322 (infer-union-context e target env state context)
7134 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
9323 ?: &(?=(%collection -.target) =(%list name.target) (context-union-branch e))
7135 (infer-union-context e target env state context)
9324 (infer-union-context e target env state context)
7136 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
9325 ?: &(?=(%collection -.target) =(%list name.target) (context-list-expression e))
7137 (infer-list-context e target env state context)
9326 (infer-list-context e target env state context)
9327+ :: A literal-headed tuple can receive the unique case's payload
9328+ :: context. The ordinary final fit still checks the complete union.
9329+ =/ selected=(unit itype)
9330+ ?. &((contextual-simple-sub sub.state) (contextual-direct-union expected) ?=(%union -.target) ?=(%tuple -.e) ?=(^ items.e)) ~
9333+ ?. (contextual-direct-payload-call val.i.t.items.e) ~
9334+ =/ first=item i.items.e
9335+ ?. &(?=(~ face.first) ?=(%lit -.val.first) |(=(%term form.lit.val.first) =(%null form.lit.val.first) =(%loobean form.lit.val.first))) ~
9336+ (contextual-tagged-case target val.lit.val.first sub.state)
9339+ :: On this bounded shallow-call shape, preserve any inference that
9340+ :: already fits before trying the new contextual path. Neither pass
9341+ :: can recursively select a nested tuple from the atomic arguments.
9342+ =/ ordinary=(unit iresult)
9343+ =/ initial=iresult (infer-fragment e env state)
9344+ ?: ?=(%| -.initial) ~
9345+ =/ fit=ifit (itype-fit typ.p.initial target sub.state.p.initial next.state.p.initial)
9348+ ?^ ordinary u.ordinary
9349+ =/ value=iresult (infer-call-context-items items.e u.selected env state context)
9350+ ?: ?=(%| -.value) value
9351+ =/ fit=ifit (itype-fit typ.p.value u.selected sub.state.p.value next.state.p.value)
9352+ ?: ?=(%unknown -.fit) [%| ["tagged case needs unsupported inference" ~]]
9353+ ?: ?=(%bad -.fit) [%| ["tagged case does not fit its expected type" ~[[context "expected union case"] [(span-of e) "value"]]]]
9354+ [%& typ.p.value state.p.value(sub sub.fit, next next.fit)]
9355+ ?: &(?=(%cell -.target) ?=(%tuple -.e))
9356+ (infer-call-context-items items.e target env state context)
7138 (infer-fragment e env state)
9357 (infer-fragment e env state)
9359+:: Preserve each written face; the final complete sample fit checks faces.
9360+:: A tuple or positional field face belongs to the enclosing sample,
9361+:: not to the expression at that position. A second face, if present,
9362+:: is part of the value's own expected type.
9363+++ projection-field-target
9366+ ?:(?=(%face -.expected) body.expected expected)
9368+++ infer-call-context-items
9369+ |= [items=(list item) expected=itype env=ienv state=istate context=span]
9371+ ?~ items [%| ["empty cell is not supported by partial inference" ~]]
9373+ =/ last=iresult (infer-call-context-arg val.i.items (projection-field-target expected) env state context)
9374+ ?: ?=(%| -.last) last
9375+ =/ typ=itype typ.p.last
9376+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9377+ [%& typ state.p.last]
9378+ =/ target=itype (itype-walk expected sub.state)
9380+ ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9381+ ?. ?=(%cell -.target) (infer-simple-items items env state)
9382+ =/ head=iresult (infer-call-context-arg val.i.items (projection-field-target hed.target) env state context)
9383+ ?: ?=(%| -.head) head
9384+ =/ typ=itype typ.p.head
9385+ =. typ ?~(face.i.items typ [%face u.face.i.items typ])
9386+ =/ tail=iresult (infer-call-context-items t.items tal.target env state.p.head context)
9387+ ?: ?=(%| -.tail) tail
9388+ [%& [%cell typ typ.p.tail] state.p.tail]
7140++ infer-call-context-args
9390++ infer-call-context-args
7141 |= [args=(list expr) expected=itype env=ienv state=istate context=span]
9391 |= [args=(list expr) expected=itype env=ienv state=istate context=span]
7142 ^- iresult
9392 ^- iresult
7143 ?~ args [%| ["call has no argument" ~]]
9393 ?~ args [%| ["call has no argument" ~]]
7144− ?~ t.args (infer-call-context-arg i.args expected env state context)
9394+ ?~ t.args (infer-call-context-arg i.args (projection-field-target expected) env state context)
7145 =/ target=itype (itype-walk expected sub.state)
9395 =/ target=itype (itype-walk expected sub.state)
7147 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
9397 ?: ?=(%face -.target) $(target (itype-walk body.target sub.state))
7148 ?. ?=(%cell -.target)
9398 ?. ?=(%cell -.target)
7149 (infer-simple-items (turn args |=(a=expr [(span-of a) ~ a])) env state)
9399 (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)
9400+ =/ head=iresult (infer-call-context-arg i.args (projection-field-target hed.target) env state context)
7151 ?: ?=(%| -.head) head
9401 ?: ?=(%| -.head) head
7152 =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
9402 =/ tail=iresult (infer-call-context-args t.args tal.target env state.p.head context)
7153 ?: ?=(%| -.tail) tail
9403 ?: ?=(%| -.tail) tail
@@ -7168,11 +9418,55 @@
7168 ?: ?=(%| -.tail) tail
9418 ?: ?=(%| -.tail) tail
7169 [%& [%cell ht typ.p.tail] state.p.tail]
9419 [%& [%cell ht typ.p.tail] state.p.tail]
7171−:: A single two-binder cell pattern covers every value of a cell type.
9421+:: A single all-binder cell pattern covers a known cell spine; the final
7172−:: No other pattern matrix is implemented here.
9422+:: binder captures the remaining noun. Other pattern matrices stay partial.
9424+:: Validate binders before reading the subject, preserving shadow-error
9425+:: precedence. The last binder receives the entire remaining tail.
9426+++ cell-pattern-names
9427+ |= [pats=(list pattern) env=ienv globals=(list term) seen=(list term)]
9428+ ^- (each (list term) @t)
9430+ ?. ?=(%bind -.i.pats) [%| 'branch pattern is not supported by partial inference']
9431+ =/ name=term name.i.pats
9432+ ?: |(=(name %proj) ?=(^ (ienv-lookup name env)) (lien globals |=(n=term =(n name))) (lien seen |=(n=term =(n name))))
9433+ [%| 'pattern shadows a name']
9434+ =/ rest=(each (list term) @t) $(pats t.pats, seen [name seen])
9435+ ?: ?=(%| -.rest) rest
9438+++ cell-pattern-types
9439+ |= [names=(list term) env=ienv next=@ud]
9440+ ^- [typ=itype env=ienv next=@ud]
9442+ =/ head=itype [%var next]
9443+ =/ scope=ienv [[i.names [head ~]] env]
9444+ ?~ t.names [head scope +(next)]
9445+ =/ tail=[typ=itype env=ienv next=@ud] $(names t.names, env scope, next +(next))
9446+ [[%cell head typ.tail] env.tail next.tail]
9448+:: At every position that must be a cell, opaque or sum types may still
9449+:: contain cells. Do not report a definite mismatch without unfolding them.
9450+++ cell-pattern-spine-unknown
9451+ |= [typ=itype names=(list term) sub=isub]
9455+ =. typ (itype-walk typ sub)
9456+ ?: ?=(%cell -.typ) $(typ tal.typ, names t.names)
9457+ |(?=(%union -.typ) ?=(%collection -.typ) ?=(%recursive -.typ) ?=(%jrec -.typ) ?=(%grec -.typ) ?=(%noun -.typ) ?=(%fn -.typ) ?=(%tag -.typ))
9459+++ cell-binder-pattern
9462+ ?. ?=(%branch -.e) |
9465+ ?. ?=(%cell -.pat.i.arms.e) |
9466+ !(single-structured-pattern e)
7174++ infer-cell-branch
9468++ infer-cell-branch
7175− |= [e=expr env=ienv state=istate]
9469+ |= [e=expr env=ienv state=istate expected=(unit [typ=itype context=span])]
7176 ^- iresult
9470 ^- iresult
7177 ?> ?=(%branch -.e)
9471 ?> ?=(%branch -.e)
7178 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
9472 ?~ arms.e [%| ["branch is not supported by partial inference" ~]]
@@ -7181,25 +9475,31 @@
7181 =/ pats=(list pattern) items.pat.arm
9475 =/ pats=(list pattern) items.pat.arm
7182 ?~ pats [%| ["branch pattern is not supported by partial inference" ~]]
9476 ?~ pats [%| ["branch pattern is not supported by partial inference" ~]]
7183 ?~ t.pats [%| ["branch pattern is not supported by partial inference" ~]]
9477 ?~ t.pats [%| ["branch pattern is not supported by partial inference" ~]]
7184− ?^ t.t.pats [%| ["branch pattern is not supported by partial inference" ~]]
9478+ =/ names=(each (list term) @t) (cell-pattern-names pats env globals.state ~)
7185− ?. ?=(%bind -.i.pats) [%| ["branch pattern is not supported by partial inference" ~]]
9479+ ?: ?=(%| -.names) [%| [(trip p.names) ~]]
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" ~]]
7191 =/ subject=iresult (infer-fragment subject.e env state)
9480 =/ subject=iresult (infer-fragment subject.e env state)
7192 ?: ?=(%| -.subject) subject
9481 ?: ?=(%| -.subject) subject
7193 =/ st=istate state.p.subject
9482 =/ st=istate state.p.subject
7194− ?: (itype-has-recursive (itype-normalize typ.p.subject sub.st))
9483+ =/ subject-type=itype (itype-normalize typ.p.subject sub.st)
9484+ ?: (itype-has-recursive subject-type)
7195 [%| ["recursive pattern is not supported by partial inference" ~]]
9485 [%| ["recursive pattern is not supported by partial inference" ~]]
7196 ?: (itype-has-face typ.p.subject sub.st)
9486 ?: (itype-has-face typ.p.subject sub.st)
7197 [%| ["record patterns are not supported by partial inference" ~]]
9487 [%| ["record patterns are not supported by partial inference" ~]]
7198− =/ head=itype [%var next.st]
9488+ ?: (cell-pattern-spine-unknown subject-type p.names sub.st)
7199− =/ tail=itype [%var +(next.st)]
9489+ [%| ["cell pattern subject is not supported by partial inference" ~]]
7200− =/ sub=(unit isub) (itype-unify typ.p.subject [%cell head tail] sub.st)
9490+ =/ binders=[typ=itype env=ienv next=@ud] (cell-pattern-types p.names env next.st)
9491+ =/ sub=(unit isub) (itype-unify typ.p.subject typ.binders sub.st)
7201 ?~ sub [%| ["cell pattern does not match the subject type" ~]]
9492 ?~ 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))
9493+ =. st st(next next.binders, sub u.sub)
9494+ ?~ expected (infer-fragment val.arm env.binders st)
9495+ =/ body=iresult (infer-call-context-arg val.arm typ.u.expected env.binders st context.u.expected)
9496+ ?: ?=(%| -.body) body
9497+ =/ fit=ifit (itype-fit typ.p.body typ.u.expected sub.state.p.body next.state.p.body)
9498+ ?: ?=(%unknown -.fit) [%| ["cell branch result constraint is not supported by partial inference" ~]]
9499+ ?: ?=(%bad -.fit) [%| ["cell branch arm does not fit its expected type" ~[[context.u.expected "expected type"] [(span-of val.arm) "branch arm"]]]]
9500+ ?: (itype-has-tag (itype-normalize typ.u.expected sub.fit))
9501+ [%| ["cell branch result needs context in partial inference" ~]]
9502+ [%& typ.u.expected state.p.body(sub sub.fit, next next.fit)]
7204++ show-itype
9504++ show-itype
7205 |= [t=itype sub=isub]
9505 |= [t=itype sub=isub]
@@ -7212,12 +9512,20 @@
7213 ?: (lth id.t 26) [(add 65 id.t) ~]
9513 ?: (lth id.t 26) [(add 65 id.t) ~]
7214 "T{<id.t>}"
9514 "T{<id.t>}"
9516+ ?: (lth id.t 26) [(add 65 id.t) ~]
7216 ?: (lth id.t 26) [(add 65 id.t) ~]
9519 ?: (lth id.t 26) [(add 65 id.t) ~]
7217 "T{<id.t>}"
9520 "T{<id.t>}"
9522+ ?: (lth id.t 26) [(add 65 id.t) ~]
7218 %atom "@{(trip aura.t)}"
9524 %atom "@{(trip aura.t)}"
7219 %any-atom "@"
9525 %any-atom "@"
7220 %flag "?"
9526 %flag "?"
7221 %tag (trip txt.literal.t)
9529 %tag (trip txt.literal.t)
7222 %const (trip txt.literal.t)
9530 %const (trip txt.literal.t)
@@ -7225,6 +9533,8 @@
7225 ?~ args.t (trip u.label.t)
9533 ?~ args.t (trip u.label.t)
7226 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
9534 "({(trip u.label.t)} {(show-itype-cases args.t sub)})"
7227 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9535 %recursive ?~(label.t "recursive mold" (trip u.label.t))
9536+ %jrec ?~(label.t "recursive mold" (trip u.label.t))
9537+ %grec ?~(label.t "recursive mold" "({(trip u.label.t)} {(show-itype-cases args.t sub)})")
7228 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
9538 %collection "({(trip name.t)} {(show-itype-cases args.t sub)})"
7229 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
9539 %face "[{(trip name.t)}={(show-itype-context body.t sub)}]"
7230 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
9540 %fn "$-({(show-itype-context sample.t sub)} {(show-itype-context product.t sub)})"
@@ -7260,15 +9570,21 @@
7261 ?- -.typ
9571 ?- -.typ
7266 %any-atom |
9578 %any-atom |
7269 %const |
9583 %const |
7270 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
9584 %union |((lien cases.typ |=(c=itype (itype-has-nvar c))) (lien args.typ |=(c=itype (itype-has-nvar c))))
7271 %recursive |
9585 %recursive |
9587+ %grec (lien args.typ |=(c=itype (itype-has-nvar c)))
7272 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
9588 %collection (lien args.typ |=(c=itype (itype-has-nvar c)))
7273 %face $(typ body.typ)
9589 %face $(typ body.typ)
7274 %fn |($(typ sample.typ) $(typ product.typ))
9590 %fn |($(typ sample.typ) $(typ product.typ))
@@ -7279,7 +9595,7 @@
7279 |= [label=tape typ=itype sub=isub]
9595 |= [label=tape typ=itype sub=isub]
7281 =/ normalized=itype (itype-normalize typ sub)
9597 =/ normalized=itype (itype-normalize typ sub)
7282− ?: |(?=(%var -.normalized) ?=(%avar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
9598+ ?: |(?=(%var -.normalized) ?=(%avar -.normalized) ?=(%rvar -.normalized) (itype-has-nvar normalized) (itype-has-tag normalized) (itype-has-union normalized)) label
7283 ?: (itype-has-hidden-recursive normalized) label
9599 ?: (itype-has-hidden-recursive normalized) label
7284 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
9600 =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
7285 ?: (gth (lent vars) 26) label
9601 ?: (gth (lent vars) 26) label
@@ -7301,6 +9617,7 @@
7301 ?+ -.resolved ~
9617 ?+ -.resolved ~
7302 %var `id.resolved
9618 %var `id.resolved
7303 %avar `id.resolved
9619 %avar `id.resolved
7305 ?~ ident $(caps t.caps)
9622 ?~ ident $(caps t.caps)
7306 ?: =(n u.ident) &
9623 ?: =(n u.ident) &
@@ -7315,6 +9632,7 @@
7315 ?+ -.resolved ~
9632 ?+ -.resolved ~
7316 %var `id.resolved
9633 %var `id.resolved
7317 %avar `id.resolved
9634 %avar `id.resolved
7319 ?~ ident $(caps t.caps)
9637 ?~ ident $(caps t.caps)
7320 ?: =(n u.ident) `i.caps
9638 ?: =(n u.ident) `i.caps
@@ -7329,6 +9647,7 @@
7329 ?+ -.resolved ~
9647 ?+ -.resolved ~
7330 %var `id.resolved
9648 %var `id.resolved
7331 %avar `id.resolved
9649 %avar `id.resolved
7333 ?~ ident $(caps t.caps)
9652 ?~ ident $(caps t.caps)
7334 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
9653 =/ found=(unit icap) (cap-with-id u.ident t.caps sub)
@@ -7344,6 +9663,7 @@
7344 ?+ -.resolved ~
9663 ?+ -.resolved ~
7345 %var `id.resolved
9664 %var `id.resolved
7346 %avar `id.resolved
9665 %avar `id.resolved
7348 ?~ ident &
9668 ?~ ident &
7349 ?: (cap-id-in u.ident t.caps sub) &
9669 ?: (cap-id-in u.ident t.caps sub) &
@@ -7358,8 +9678,8 @@
7359 ?~ caps |
9679 ?~ caps |
7360 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
9680 =/ resolved=itype (itype-walk [%var id.i.caps] sub)
7361− ?: ?=(%avar -.resolved)
9681+ ?: |(?=(%avar -.resolved) ?=(%rvar -.resolved))
7362− ?: =(n id.resolved) &
9682+ ?: =(n +.resolved) &
7363 $(caps t.caps)
9683 $(caps t.caps)
7364 $(caps t.caps)
9684 $(caps t.caps)
@@ -7369,14 +9689,20 @@
7371 %avar =(n id.t)
9691 %avar =(n id.t)
7374 %any-atom |
9696 %any-atom |
7377 %const |
9701 %const |
7378 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
9702 %union |((lien cases.t |=(c=itype (has-atom-var n c))) (lien args.t |=(c=itype (has-atom-var n c))))
7379 %recursive |
9703 %recursive |
9705+ %grec (lien args.t |=(c=itype (has-atom-var n c)))
7380 %collection (lien args.t |=(c=itype (has-atom-var n c)))
9706 %collection (lien args.t |=(c=itype (has-atom-var n c)))
7381 %face $(t body.t)
9707 %face $(t body.t)
7382 %fn |($(t sample.t) $(t product.t))
9708 %fn |($(t sample.t) $(t product.t))
@@ -7416,6 +9742,10 @@
7416 =/ out=tape ""
9742 =/ out=tape ""
7418 ?~ vars out
9744 ?~ vars out
9745+ ?: (itype-var-is-restricted i.vars t)
9746+ =/ sep=tape ?:(printed ", " " where ")
9747+ =/ clause=tape "{sep}{(show-itype [%rvar i.vars] ~)} is an atom other than ?"
9748+ $(vars t.vars, printed &, out (weld out clause))
7419 ?: (itype-var-is-atom i.vars t)
9749 ?: (itype-var-is-atom i.vars t)
7420 =/ sep=tape ?:(printed ", " " where ")
9750 =/ sep=tape ?:(printed ", " " where ")
7421 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
9751 =/ clause=tape "{sep}{(show-itype [%avar i.vars] ~)} is an atom"
@@ -7424,9 +9754,9 @@
7425:: Build the supported part of the value environment in dependency order.
9755:: Build the supported part of the value environment in dependency order.
7426:: Each pass adds successful definitions. Forward references become
9756:: Each pass adds successful definitions. Forward references become
7427−:: available on a later pass; mutually recursive groups and unsupported
9757+:: available on a later pass; unsupported syntax does not enter the
7428−:: syntax do not enter the environment. Generalized definitions are closed, so a
9758+:: environment. Generalized definitions are closed, so a use instantiates
7429−:: use instantiates its variables afresh.
9759+:: its variables afresh.
7431++ global-value-names
9761++ global-value-names
7432 |= ds=(list def)
9762 |= ds=(list def)
@@ -7516,6 +9846,8 @@
7516++ infer-recursive-gate
9846++ infer-recursive-gate
7517 |= [d=def env=ienv state=istate]
9847 |= [d=def env=ienv state=istate]
7518 ^- iresult
9848 ^- iresult
9849+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
9850+ =. gate-defs.state ~
7519 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
9851 ?. ?=(%value -.d) [%| ["recursive definition is not a gate" ~]]
7520 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
9852 ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
7521 [%| ["recursive definition is not a gate" ~]]
9853 [%| ["recursive definition is not a gate" ~]]
@@ -7656,9 +9988,9 @@
7659−:: Infer a cyclic top-level component with one monomorphic seed per gate.
9991+:: Infer a cyclic component with one monomorphic seed per gate. All members
7660−:: All members must succeed before any scheme is available; local cyclic
9992+:: must succeed before any scheme is available; pending constraints and
7661−:: groups, pending constraints and unresolved branch joins remain partial.
9993+:: unresolved branch joins remain partial.
7662+$ igate-entry [name=term typ=itype body=expr env=ienv caps=icaps]
9994+$ igate-entry [name=term typ=itype body=expr env=ienv caps=icaps]
7663+$ igate-seeds (each [entries=(list igate-entry) state=istate] idiag)
9995+$ igate-seeds (each [entries=(list igate-entry) state=istate] idiag)
7664++ seed-gate-group
9996++ seed-gate-group
@@ -7725,6 +10057,7 @@
7725 ?: (constrained-capitals caps.entry sub.state)
10057 ?: (constrained-capitals caps.entry sub.state)
7726 [%| ["explicit capital constraints are not supported by partial inference" ~]]
10058 [%| ["explicit capital constraints are not supported by partial inference" ~]]
7727 =/ typ=itype (itype-normalize typ.entry sub.state)
10059 =/ typ=itype (itype-normalize typ.entry sub.state)
10060+ ?: (itype-has-nvar typ) [%| ["recursive group needs unsupported inference" ~]]
7728 ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
10061 ?: |((itype-has-tag typ) (itype-has-hidden-generic typ) (itype-has-hidden-recursive typ) (unsupported-atom-vars typ caps.entry binders.state sub.state))
7729 [%| ["recursive group needs unsupported inference" ~]]
10062 [%| ["recursive group needs unsupported inference" ~]]
7730 =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
10063 =/ free=(list @ud) (weld (free-env-vars env sub.state) (free-cap-vars caps.outer sub.state))
@@ -7738,46 +10071,52 @@
7738++ infer-gate-group
10071++ infer-gate-group
7739 |= [ds=(list def) env=ienv state=istate]
10072 |= [ds=(list def) env=ienv state=istate]
7740 ^- ilocal-result
10073 ^- ilocal-result
10074+ ?^ defer.state [%| ["deferred recursive inference is unsupported" ~]]
7741 =/ names=(list term) (global-value-names ds)
10075 =/ names=(list term) (global-value-names ds)
7742 ?. (levy names |=(n=term (unique-value-name n names)))
10076 ?. (levy names |=(n=term (unique-value-name n names)))
7743 [%| ["recursive group contains duplicate names" ~]]
10077 [%| ["recursive group contains duplicate names" ~]]
7744 ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
10078 ?: (lien names |=(n=term ?=(^ (ienv-lookup n env))))
7745 [%| ["recursive group shadows a name" ~]]
10079 [%| ["recursive group shadows a name" ~]]
7746− =/ scoped=istate state(globals (weld names globals.state))
10080+ =/ scoped=istate state(globals (weld names globals.state), gate-defs ~)
7747 =/ seeded=igate-seeds (seed-gate-group ds env scoped)
10081 =/ seeded=igate-seeds (seed-gate-group ds env scoped)
7748 ?: ?=(%| -.seeded) seeded
10082 ?: ?=(%| -.seeded) seeded
7749 =/ seeds=ienv (group-seed-env entries.p.seeded ~)
10083 =/ seeds=ienv (group-seed-env entries.p.seeded ~)
7750 =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
10084 =/ body=igate-seeds (infer-gate-group-bodies entries.p.seeded seeds state.p.seeded)
7751 ?: ?=(%| -.body) body
10085 ?: ?=(%| -.body) body
10086+ :: Per-member ownership through mutual recursion is not implemented.
10087+ ?: !=(projections.state.p.body projections.state)
10088+ [%| ["record projection in recursive groups needs unsupported inference" ~]]
10089+ ?: !=(holes.state.p.body holes.state)
10090+ [%| ["holes in recursive groups need unsupported inference" ~]]
7752 ?: (pending-tags tags.state.p.body sub.state.p.body)
10091 ?: (pending-tags tags.state.p.body sub.state.p.body)
7753 [%| ["recursive group has unresolved literal constraints" ~]]
10092 [%| ["recursive group has unresolved literal constraints" ~]]
7754 =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
10093 =/ schemes=(each ienv idiag) (group-schemes entries.p.body env state state.p.body)
7755 ?: ?=(%| -.schemes) schemes
10094 ?: ?=(%| -.schemes) schemes
7756 [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
10095 [%& [(weld p.schemes env) state.p.body(globals globals.state)]]
10098+ |= [ps=(list iwprojection) sub=isub visible=(list @ud)]
10099+ ^- (unit (list iwprojection))
10101+ ?: (lien t.ps |=(p=iwprojection =(at.p at.i.ps))) ~
10102+ =/ src=itype (default-decimals (itype-normalize source.i.ps sub))
10103+ =/ dst=itype (default-decimals (itype-normalize target.i.ps sub))
10104+ ?: |((itype-has-nvar src) (itype-has-nvar dst) (itype-has-tag src) (itype-has-tag dst)) ~
10105+ =/ vars=(list @ud) (weld (itype-vars src) (itype-vars dst))
10106+ ?. (levy vars |=(n=@ud (lien visible |=(v=@ud =(n v))))) ~
10107+ =/ rest=(unit (list iwprojection)) $(ps t.ps)
10109+ =/ entry=iwprojection i.ps
10110+ =. entry entry(source src, target dst)
7758++ add-supported-defs
10113++ 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)]
10114+ |= [ds=(list def) all-defs=(list def) checked=(map term def) heads=(unit igate-prelude-evidence) env=ienv molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) at=path prelude=(unit ifile) artifacts=(list iwidth-definition)]
7760− ^- ienv
10115+ ^- [env=ienv artifacts=(list iwidth-definition)]
7761− ?~ ds env
10116+ (add-supported-defs-core ds all-defs checked heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts ~)
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])
7780−+$ iresolved [env=ienv grouped=(list term)]
10118+
10119++$ iresolved [env=ienv grouped=(list term) artifacts=(list iwidth-definition)]
7781+$ iadj (map term (list term))
10120+$ iadj (map term (list term))
7782+$ ivisited (map term ?)
10121+$ ivisited (map term ?)
7783+$ iwork (list [name=term done=?])
10122+$ iwork (list [name=term done=?])
@@ -7871,9 +10210,9 @@
7871 (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
10210 (lien (graph-edges i.component graph) |=(x=term =(x i.component)))
7873++ add-groups
10212++ add-groups
7874− |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) state=istate]
10213+ |= [ds=(list def) components=icomponents graph=iadj env=ienv grouped=(list term) artifacts=(list iwidth-definition) state=istate]
7875 ^- iresolved
10214 ^- iresolved
7876− ?~ components [env grouped]
10215+ ?~ components [env grouped artifacts]
7877 =/ component=(list term) i.components
10216 =/ component=(list term) i.components
7878 ?. (graph-cycle component graph) $(components t.components)
10217 ?. (graph-cycle component graph) $(components t.components)
7879 ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
10218 ?: (lien component |=(n=term ?=(^ (ienv-lookup n env)))) $(components t.components)
@@ -7890,24 +10229,185 @@
7890++ resolve-groups
10229++ resolve-groups
7891 |= [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)]
10230 |= [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)]
7892 ^- iresolved
10231 ^- iresolved
7893− =/ env=ienv ~
10232+ (resolve-groups-core ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude ~)
7894− =/ grouped=(list term) ~
10233+::
7895− =/ names=(list term) (global-value-names ds)
10234+
7896− =/ nameset=ivisited (graph-nameset names ~)
10235+++ add-supported-defs-core
7897− =/ graph=iadj (graph-make-forward ds nameset ~)
10236+ |= [ds=(list def) all-defs=(list def) checked=(map term def) heads=(unit igate-prelude-evidence) env=ienv molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) at=path prelude=(unit ifile) artifacts=(list iwidth-definition) index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])]
7898− =/ components=icomponents (graph-components ds names)
10237+ ^- [env=ienv artifacts=(list iwidth-definition)]
7899− =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10238+ ?~ ds [env artifacts]
7900− |-
10239+ =/ d=def i.ds
7901− =/ next=ienv (add-supported-defs ds env molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
10240+ ?: ?=(%mold -.d) $(ds t.ds)
7902− =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
10241+ ?. (unique-value-name name.d globals) $(ds t.ds)
7903− =/ out=iresolved (add-groups ds components graph next grouped initial)
10242+ ?^ (ienv-lookup name.d env) $(ds t.ds)
7904− ?: =(env env.out) out
10243+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
7905− $(env env.out, grouped grouped.out)
10244+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
7906−::
10245+ =. grec-index.initial index
7907−++ resolve-supported-defs
10246+ =. gate-defs.initial checked
7908− |= [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)]
10247+ =. head-evidence.initial heads
7909− ^- ienv
10248+ =. initial (reserve-def-caps val.d initial)
7910− env:(resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
10249+ =/ result=iresult (infer-fragment val.d env initial)
10250+ =? result ?=(%| -.result) (infer-recursive-gate d env initial)
10251+ ?: ?=(%| -.result) $(ds t.ds)
10252+ =. state.p.result (promote-restricted-numbers state.p.result env)
10253+ =. state.p.result (default-hole-numbers holes.state.p.result holes.initial state.p.result env !(itype-has-gate (itype-normalize typ.p.result sub.state.p.result)))
10254+ ?^ (unresolved-hole holes.state.p.result holes.initial state.p.result) $(ds t.ds)
10255+ ?: (constrained-capitals caps.state.p.result sub.state.p.result) $(ds t.ds)
10256+ =/ typ=itype (default-decimals (itype-normalize typ.p.result sub.state.p.result))
10257+ ?: |((pending-tags tags.state.p.result sub.state.p.result) (itype-has-tag typ)) $(ds t.ds)
10258+ ?: (unsupported-atom-vars typ caps.state.p.result binders.state.p.result sub.state.p.result) $(ds t.ds)
10259+ =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
10260+ ?: (gth (lent vars) 26) $(ds t.ds)
10261+ =/ finalized=(unit (list iwprojection))
10262+ (width-finalize projections.state.p.result sub.state.p.result vars)
10263+ ?~ finalized $(ds t.ds)
10264+ =? artifacts ?=(^ u.finalized)
10265+ [[name.d val.d typ sub.state.p.result (flop u.finalized)] artifacts]
10266+ =? checked |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) (~(put by checked) name.d d)
10267+ $(ds t.ds, env [[name.d [typ vars]] env], checked checked)
10269+++ resolve-groups-core
10270+ |= [ds=(list def) molds=imolds globals=(list term) externals=iexternals surs=(list term) mark-externals=imark-externals marks=(list term) jimports=ijimports reserved-molds=(list term) at=path prelude=(unit ifile) index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])]
10273+ =/ grouped=(list term) ~
10274+ =/ artifacts=(list iwidth-definition) ~
10275+ =/ names=(list term) (global-value-names ds)
10276+ =/ nameset=ivisited (graph-nameset names ~)
10277+ =/ graph=iadj (graph-make-forward ds nameset ~)
10278+ =/ components=icomponents (graph-components ds names)
10279+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
10280+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
10282+ =/ next=[env=ienv artifacts=(list iwidth-definition)]
10283+ (add-supported-defs-core ds ds (direct-checked-gates ds env) heads env molds globals externals surs mark-externals marks jimports reserved-molds at prelude artifacts index)
10284+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
10285+ =. grec-index.initial index
10286+ =/ out=iresolved (add-groups ds components graph env.next grouped artifacts.next initial)
10287+ ?: =(env env.out) out
10288+ $(env env.out, grouped grouped.out, artifacts artifacts.out)
10290+++ resolve-supported-defs
10291+ |= [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)]
10293+ env:(resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds at prelude)
10295+:: A diagnostic-only proof for a narrow syntactic value cycle. Every
10296+:: edge is an unqualified wing in a supported expression, and samples
10297+:: may not shadow global bindings. Unknown forms yield no conclusion.
10298++$ icyclesite [name=term at=span]
10299++$ icycle [name=term first=span next=span]
10300+++ cycle-sites-list
10301+ |= [xs=(list expr) globals=(list term) locals=(list term)]
10302+ ^- (unit (list icyclesite))
10304+ =/ first=(unit (list icyclesite)) (cycle-sites i.xs globals locals)
10306+ =/ tail=(unit (list icyclesite)) $(xs t.xs)
10308+ `(weld u.first u.tail)
10310+++ cycle-sample-name
10311+ |= [sam=sample globals=(list term) locals=(list term)]
10312+ ^- (unit (unit term))
10315+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10318+ ?: (lien (weld globals locals) |=(n=term =(n name.sam))) ~
10325+ |= [e=expr globals=(list term) locals=(list term)]
10326+ ^- (unit (list icyclesite))
10329+ ?. ?=([@ ~] names.e) ~
10330+ `~[[i.names.e at.e]]
10333+ ?: (lien pieces.e |=(p=piece ?=(%expr -.p))) ~
10335+ %group $(e inner.e)
10336+ %body ?~(defs.e $(e final.e) ~)
10339+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10341+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10342+ $(e body.e, locals nested)
10344+ =/ binder=(unit (unit term)) (cycle-sample-name sample.e globals locals)
10346+ =/ nested=(list term) ?~(u.binder locals [u.u.binder locals])
10347+ $(e body.e, locals nested)
10349+ =/ first=(unit (list icyclesite)) $(e head.e)
10351+ =/ tail=(unit (list icyclesite)) (cycle-sites-list args.e globals locals)
10353+ `(weld u.first u.tail)
10357+++ cycle-definitely-atom
10360+ ?: ?=(%group -.e) $(e inner.e)
10361+ ?: &(?=(%body -.e) ?=(~ defs.e)) $(e final.e)
10362+ ?. ?=(%cast -.e) |
10363+ |(?=(%aura -.shape.e) ?=(%flag -.shape.e))
10365+++ cycle-proof-group
10366+ |= [members=(list def) globals=(list term)]
10369+ ?. ?=(%value -.i.members) |
10370+ ?. (unique-value-name name.i.members globals) |
10371+ ?. ?=(^ (cycle-sites val.i.members globals ~)) |
10372+ $(members t.members)
10375+ |= [sites=(list icyclesite) component=(list term)]
10378+ ?: (lien component |=(n=term =(n name.i.sites))) `at.i.sites
10381+++ cycle-group-errors
10382+ |= [members=(list def) component=(list term) globals=(list term)]
10385+ =/ d=def i.members
10387+ =/ tail=(list icycle) $(members t.members)
10388+ ?. (cycle-definitely-atom val.d) tail
10389+ =/ sites=(unit (list icyclesite)) (cycle-sites val.d globals ~)
10391+ =/ found=(unit span) (cycle-find-site u.sites component)
10393+ [[name.d at.d u.found] tail]
10395+++ definite-value-cycles
10396+ |= [ds=(list def) globals=(list term)]
10398+ =/ names=(list term) (global-value-names ds)
10399+ =/ graph=iadj (graph-make-forward ds (graph-nameset names ~) ~)
10400+ =/ components=icomponents (graph-components ds names)
10401+ =/ out=(list icycle) ~
10404+ =/ component=(list term) i.components
10405+ ?. (graph-cycle component graph) $(components t.components)
10406+ =/ members=(list def)
10407+ (skim ds |=(d=def &(?=(%value -.d) (lien component |=(n=term =(n name.d))))))
10408+ ?. =((lent members) (lent component)) $(components t.components)
10409+ ?. (cycle-proof-group members globals) $(components t.components)
10410+ $(components t.components, out (weld (cycle-group-errors members component globals) out))
7912+| %union-analysis
10412+| %union-analysis
@@ -8031,6 +10531,257 @@
8031 %overlap
10531 %overlap
8032 %unknown
10532 %unknown
10534+:: A source-only fallback for literal-tagged cells and one-hop local
10535+:: generic applications. It screens all work before ordinary inference.
10536+++ union-simple-shape-budget
10537+ |= [s=shape fuel=@ud vars=(unit (list @t))]
10540+ =. fuel (dec fuel)
10542+ ?(%aura %noun %void %flag) `fuel
10545+ ?:((lien u.vars |=(n=@t =(n name.s))) `fuel ~)
10547+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10548+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10550+ %cell (union-simple-fields-budget fields.s fuel vars)
10552+ =/ left=(unit @ud) $(s sample.s, fuel fuel)
10554+ $(s product.s, fuel u.left)
10557+++ union-simple-fields-budget
10558+ |= [fields=(list field) fuel=@ud vars=(unit (list @t))]
10562+ =/ field-shape=shape
10564+ %bare shape.i.fields
10565+ %face shape.i.fields
10566+ %pun [%ref at.i.fields ~[name.i.fields]]
10568+ =/ head=(unit @ud) (union-simple-shape-budget field-shape (dec fuel) vars)
10570+ $(fields t.fields, fuel u.head)
10571+++ union-source-find
10572+ |= [n=term molds=imolds fuel=@ud]
10573+ ^- (unit [body=shape left=@ud])
10574+ =/ found=(unit shape) ~
10580+ ?: =(n name.i.molds)
10582+ $(molds t.molds, fuel (dec fuel), found `body.i.molds)
10583+ $(molds t.molds, fuel (dec fuel))
10584+++ union-source-args-budget
10585+ |= [vars=(list @t) args=(list shape) fuel=@ud]
10587+ =/ seen=(set @t) *(set @t)
10589+ ?~ vars ?~(args `fuel ~)
10592+ ?: (~(has in:..zuse seen) i.vars) ~
10593+ =/ arg=(unit @ud) (union-simple-shape-budget i.args (dec fuel) ~)
10595+ $(vars t.vars, args t.args, fuel u.arg, seen (~(put in:..zuse seen) i.vars))
10596+++ union-source-cell-tag
10599+ ?. ?=(%cell -.s) ~
10602+ ?. ?=(%bare -.i.fields.s) ~
10603+ =/ head=shape shape.i.fields.s
10604+ ?. ?=(%const -.head) ~
10605+ ?. |(=(%term form.lit.head) =(%null form.lit.head) =(%loobean form.lit.head)) ~
10606+ ?: &(=(%loobean form.lit.head) !|(=(0 val.lit.head) =(1 val.lit.head))) ~
10608+++ union-source-case-tag
10609+ |= [s=shape molds=imolds fuel=@ud]
10610+ ^- (unit [tag=@ left=@ud])
10612+ =/ tag=(unit @) (union-source-cell-tag s)
10614+ =/ left=(unit @ud) (union-simple-shape-budget s fuel ~)
10617+ ?. ?=(%apply -.s) ~
10618+ ?. ?=([@ ~] ref.s) ~
10620+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10622+ ?. ?=(%generic -.body.u.found) ~
10623+ ?~ vars.body.u.found ~
10624+ =/ tag=(unit @) (union-source-cell-tag body.body.u.found)
10626+ =/ args=(unit @ud) (union-source-args-budget vars.body.u.found args.s left.u.found)
10628+ =/ left=(unit @ud) (union-simple-shape-budget body.body.u.found u.args `vars.body.u.found)
10631+++ union-source-distinct-tags
10632+ |= [cases=(list shape) molds=imolds fuel=@ud]
10634+ =/ seen=(set @) *(set @)
10635+ =/ has-application=? |
10637+ ?~ cases has-application
10639+ =/ item=(unit [tag=@ left=@ud]) (union-source-case-tag i.cases molds (dec fuel))
10641+ ?: (~(has in:..zuse seen) tag.u.item) |
10642+ $(cases t.cases, fuel left.u.item, seen (~(put in:..zuse seen) tag.u.item), has-application |(has-application ?=(%apply -.i.cases)))
10644+:: This inference-only screen bounds inherited work that the small source
10645+:: slice may consult. It does not authenticate a caller-created state.
10646+++ union-state-leaf
10649+ ?=(?(%var %avar %rvar %nvar %rnvar %atom %any-atom %flag %noun %empty %const) -.t)
10650+++ union-state-params-budget
10651+ |= [params=iparams fuel=@ud]
10655+ ?. (union-state-leaf typ.i.params) ~
10656+ $(params t.params, fuel (dec fuel))
10657+++ union-state-sub-budget
10658+ |= [sub=isub fuel=@ud]
10662+ ?. (union-state-leaf val.i.sub) ~
10663+ $(sub t.sub, fuel (dec fuel))
10664+++ union-state-caps-budget
10665+ |= [caps=icaps fuel=@ud]
10669+ $(caps t.caps, fuel (dec fuel))
10670+++ union-state-active-budget
10671+ |= [active=(list term) fuel=@ud]
10675+ $(active t.active, fuel (dec fuel))
10676+++ union-state-tags-budget
10677+ |= [tags=(list ipending) fuel=@ud]
10681+ $(tags t.tags, fuel (dec fuel))
10682+++ union-source-state-safe
10683+ |= [state=istate fuel=@ud]
10685+ ?^ grec-index.state |
10688+ ?^ obligations.state |
10689+ =/ params=(unit @ud) (union-state-params-budget params.state fuel)
10691+ =/ sub=(unit @ud) (union-state-sub-budget sub.state u.params)
10693+ =/ caps=(unit @ud) (union-state-caps-budget caps.state u.sub)
10695+ =/ active=(unit @ud) (union-state-active-budget active.state u.caps)
10697+ ?=(^ (union-state-tags-budget tags.state u.active))
10699+:: Positive overlap witnesses from parsed, one-hop local source only.
10700+:: Unknown or exhausted work returns no witness, never disjointness.
10701++$ uow-case [at=span head=@ payload=upat]
10702+++ union-overlap-primitive
10711+ ?. |(=(%term form.lit.s) =(%null form.lit.s) =(%loobean form.lit.s)) ~
10712+ ?: &(=(%loobean form.lit.s) !|(=(0 val.lit.s) =(1 val.lit.s))) ~
10713+ `[%atom `val.lit.s]
10716+++ union-overlap-case
10717+ |= [s=shape molds=imolds fuel=@ud]
10718+ ^- (unit [item=uow-case left=@ud])
10720+ =. fuel (dec fuel)
10721+ :: Each body has exactly two fields; an application has exactly one
10722+ :: parameter and one concrete primitive argument. The full mold table
10723+ :: is scanned to establish unique ownership.
10724+ =/ expanded=(unit [body=shape param=(unit [name=@t pat=upat]) left=@ud])
10725+ ?: ?=(%cell -.s) `[s ~ fuel]
10726+ ?. ?=(%apply -.s) ~
10727+ ?. ?=([@ ~] ref.s) ~
10728+ ?. ?=([* ~] args.s) ~
10730+ =/ found=(unit [body=shape left=@ud]) (union-source-find i.ref.s molds (dec fuel))
10732+ ?. ?=(%generic -.body.u.found) ~
10733+ ?. ?=([@ ~] vars.body.u.found) ~
10734+ ?: =(0 left.u.found) ~
10735+ =/ argument=(unit upat) (union-overlap-primitive i.args.s)
10737+ `[body.body.u.found `[i.vars.body.u.found u.argument] (dec left.u.found)]
10739+ =/ body=shape body.u.expanded
10740+ ?. ?=(%cell -.body) ~
10741+ ?. ?=([* * ~] fields.body) ~
10742+ :: Charge the cell, two fields, and the head and payload nodes.
10743+ ?: (lth left.u.expanded 5) ~
10744+ =/ head=(unit @) (union-source-cell-tag body)
10746+ =/ field=field i.t.fields.body
10751+ %pun [%ref at.field ~[name.field]]
10753+ =/ pattern=(unit upat)
10754+ ?: ?=(%tvar -.payload)
10755+ ?~ param.u.expanded ~
10756+ ?. =(name.payload name.u.param.u.expanded) ~
10757+ `pat.u.param.u.expanded
10758+ (union-overlap-primitive payload)
10760+ `[[at.s u.head u.pattern] (sub left.u.expanded 5)]
10761+++ union-overlap-against
10762+ |= [first=uow-case rest=(list shape) molds=imolds fuel=@ud]
10763+ ^- (unit [witness=(unit upair) left=@ud])
10766+ =/ other=(unit [item=uow-case left=@ud]) (union-overlap-case i.rest molds (dec fuel))
10768+ ?: &(=(head.first head.item.u.other) =(%overlap (union-relate payload.first payload.item.u.other)))
10769+ `[`[at.first at.item.u.other %overlap] left.u.other]
10770+ $(rest t.rest, fuel left.u.other)
10771+++ union-source-overlap
10772+ |= [cases=(list shape) molds=imolds fuel=@ud]
10777+ =/ first=(unit [item=uow-case left=@ud]) (union-overlap-case i.cases molds (dec fuel))
10779+ =/ found=(unit [witness=(unit upair) left=@ud])
10780+ (union-overlap-against item.u.first t.cases molds left.u.first)
10782+ ?^ witness.u.found witness.u.found
10783+ $(cases t.cases, fuel left.u.found)
8034++ union-pairs
10785++ union-pairs
8035 |= [cases=(list shape) molds=imolds]
10786 |= [cases=(list shape) molds=imolds]
8036 ^- (list upair)
10787 ^- (list upair)
@@ -8044,15 +10795,151 @@
8044 [at.first at.second (union-relate a (project-union-mold second molds ~))]
10795 [at.first at.second (union-relate a (project-union-mold second molds ~))]
8045 (weld pairs $(cases t.cases))
10796 (weld pairs $(cases t.cases))
10798+:: A closed structural mold supplies no equation to determine a hole.
10799+:: Applications, references, unbound capitals and unions are unproved.
10800+++ simple-mold-hole
10802+ ^- (unit (unit span))
10803+ ?: ?=(%generic -.sh)
10805+ ?. (distinct-params vars.sh) ~
10806+ (simple-mold-hole-in body.sh vars.sh)
10807+ (simple-mold-hole-in sh ~)
10808+++ simple-mold-hole-in
10809+ |= [sh=shape vars=(list @t)]
10810+ ^- (unit (unit span))
10813+ ?(%aura %noun %void %flag %const) `~
10814+ %tvar ?:((lien vars |=(v=@t =(v name.sh))) `~ ~)
10815+ %cell (simple-mold-field-holes fields.sh vars)
10817+ =/ a=(unit (unit span)) $(sh sample.sh)
10819+ =/ b=(unit (unit span)) $(sh product.sh)
10825+++ simple-mold-field-holes
10826+ |= [fields=(list field) vars=(list @t)]
10827+ ^- (unit (unit span))
10829+ =/ f=field i.fields
10830+ =/ first=(unit (unit span))
10832+ %face (simple-mold-hole-in shape.f vars)
10833+ %bare (simple-mold-hole-in shape.f vars)
10837+ =/ rest=(unit (unit span)) $(fields t.fields)
10839+ `?~(u.first u.rest u.first)
10840+++ simple-local-mold-hole
10841+ |= defs=(list def)
10844+ ?. ?=(%mold -.i.defs) $(defs t.defs)
10845+ =/ found=(unit (unit span)) (simple-mold-hole shape.i.defs)
10846+ ?~ found $(defs t.defs)
10847+ ?^ u.found u.found
10850+:: A partial prelude may omit unsupported declarations, but may not
10851+:: publish an interface while a named mold's hole remains unchecked.
10857+ %path (lien segs.sh |=(s=pseg ?=(%inferred -.s)))
10858+ %apply (lien args.sh shape-has-hole)
10859+ %union (lien cases.sh shape-has-hole)
10860+ %cell (lien fields.sh field-has-hole)
10861+ %fn |($(sh sample.sh) $(sh product.sh))
10862+ %generic $(sh body.sh)
10869+ %face (shape-has-hole shape.f)
10870+ %bare (shape-has-hole shape.f)
10873+++ named-mold-has-hole
10877+ ?: &(?=(%mold -.i.ds) (shape-has-hole shape.i.ds)) &
10884+ %face (shape-has-hole shape.sam)
10885+ %bare (shape-has-hole shape.sam)
10886+ %cell (lien items.sam sample-has-hole)
10893+ %mold (shape-has-hole shape.d)
10894+ %value (expr-has-hole val.d)
10900+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10901+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (expr-has-hole p.p) |)))
10902+ %change (lien edits.e |=(p=edit (expr-has-hole val.p)))
10905+ %group $(e inner.e)
10906+ %list (lien items.e expr-has-hole)
10907+ %tuple (lien items.e |=(i=item (expr-has-hole val.i)))
10908+ ?(%gate %gate-wide) |((sample-has-hole sample.e) $(e body.e))
10909+ %cast |((shape-has-hole shape.e) $(e val.e))
10910+ %call |($(e head.e) (lien args.e expr-has-hole))
10911+ %trace |($(e val.e) $(e then.e))
10912+ %branch |($(e subject.e) (lien arms.e |=(a=arm (expr-has-hole val.a))))
10913+ %body |((lien defs.e def-has-hole) $(e final.e))
10916+++ hole-values-present
10917+ |= [ds=(list def) env=ienv]
10920+ ?. ?=(%value -.i.ds) $(ds t.ds)
10921+ ?: (expr-has-hole val.i.ds)
10922+ ?. ?=(^ (ienv-lookup name.i.ds env)) |
8047++ show-partial-mold
10925++ show-partial-mold
8048 |= [file=path src=@t d=def molds=imolds]
10926 |= [file=path src=@t d=def molds=imolds]
8050 ?> ?=(%mold -.d)
10928 ?> ?=(%mold -.d)
8051 =/ sh=shape shape.d
10929 =/ sh=shape shape.d
10930+ =/ hole=(unit (unit span)) (simple-mold-hole sh)
10931+ ?: &(?=(^ hole) ?=(^ u.hole))
10932+ =/ text=@t (show-error src [file line.beg.u.u.hole col.beg.u.u.hole "unresolved type hole"])
10933+ (of-wain:format ~[(crip "+$ {(trip name.d)}: type hole needs a determined type") text])
8052 =? sh ?=(%generic -.sh) body.sh
10934 =? sh ?=(%generic -.sh) body.sh
8053 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
10935 ?. ?=(%union -.sh) (crip "+$ {(trip name.d)}: not checked")
8054 =/ pairs=(list upair) (union-pairs cases.sh molds)
10936 =/ pairs=(list upair) (union-pairs cases.sh molds)
8055 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
10937 =/ overlapping=(list upair) (skim pairs |=(p=upair =(%overlap relation.p)))
10939+ ?^ overlapping overlapping
10940+ ?. (lien pairs |=(p=upair =(%unknown relation.p))) ~
10941+ =/ witness=(unit upair) (union-source-overlap cases.sh molds 256)
10942+ ?~(witness ~ ~[u.witness])
8056 ?^ overlapping
10943 ?^ overlapping
8057 =/ p=upair i.overlapping
10944 =/ p=upair i.overlapping
8058 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
10945 =/ summary=@t (crip "+$ {(trip name.d)}: overlapping cases; mold not checked")
@@ -8060,7 +10947,9 @@
8060 =/ second=@t (show-error src [file line.beg.second.p col.beg.second.p "overlapping case"])
10947 =/ second=@t (show-error src [file line.beg.second.p col.beg.second.p "overlapping case"])
8061 (of-wain:format ~[summary first second])
10948 (of-wain:format ~[summary first second])
8062 ?: (lien pairs |=(p=upair =(%unknown relation.p)))
10949 ?: (lien pairs |=(p=upair =(%unknown relation.p)))
8063− (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10950+ ?. (union-source-distinct-tags cases.sh molds 256)
10951+ (crip "+$ {(trip name.d)}: case disjointness unresolved; mold not checked")
10952+ (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
8064 (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
10953 (crip "+$ {(trip name.d)}: cases proven disjoint; mold not checked")
8066:: +show-inference-diagnostic: a partial report with both source sites
10955:: +show-inference-diagnostic: a partial report with both source sites
@@ -8075,6 +10964,21 @@
8075 (show-error src [file line.beg.at.site col.beg.at.site note.site])
10964 (show-error src [file line.beg.at.site col.beg.at.site note.site])
8076 (of-wain:format [summary excerpts])
10965 (of-wain:format [summary excerpts])
10967+:: Both written field sites are shown in the source that declares them.
10968+++ show-duplicate-fields
10969+ |= [file=path src=@t diagnostic=idiag]
10971+ =/ excerpts=(list @t)
10972+ %+ turn sites.diagnostic
10973+ |= site=[at=span note=tape]
10974+ (show-error src [file line.beg.at.site col.beg.at.site note.site])
10975+ (of-wain:format [(crip msg.diagnostic) excerpts])
10977+++ duplicate-fields-report
10978+ |= [file=path src=@t diagnostic=idiag]
10980+ (of-wain:format ~['partial inference; module not checked' (show-duplicate-fields file src diagnostic)])
8078:: +golden-types: a partial report; it does not claim the module checks
10982:: +golden-types: a partial report; it does not claim the module checks
8080++ golden-types
10984++ golden-types
@@ -8102,8 +11006,189 @@
8102+$ jbundle (list jsource)
11006+$ jbundle (list jsource)
8103+$ jcache (list [at=path iface=ifile])
11007+$ jcache (list [at=path iface=ifile])
8104+$ jfile-result (each [iface=ifile cache=jcache] @t)
11008+$ jfile-result (each [iface=ifile cache=jcache] @t)
11009+:: Overlap evidence retains the exact source that supplied its spans.
11010+:: Ordinary Jibb imports preserve this evidence through the resolver.
11011++$ jfile-overlap [file=path source=@t name=term cases=upair]
11012++$ jfile-failure [message=@t overlap=(unit jfile-overlap)]
11013++$ jfile-detailed-result (each [iface=ifile cache=jcache] jfile-failure)
8105+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
11014+$ jimports-result (each [resolved=ijimports cache=jcache] @t)
11015+:: Preserve an imported overlap's original file and source across the graph.
11016++$ jimports-detailed-result (each [resolved=ijimports cache=jcache] jfile-failure)
11018+:: Written record fields each have their own lexical record scope.
11019++$ written-fields (map term span)
11020+++ duplicate-written-field
11021+ |= [name=term at=span seen=written-fields]
11023+ =/ prior=(unit span) (~(get by seen) name)
11025+ `["record field `{(trip name)}` is repeated" ~[[u.prior "first field"] [at "repeated field"]]]
11026+++ duplicate-shapes
11027+ |= xs=(list shape)
11030+ =/ first (duplicate-shape i.xs)
11033+++ duplicate-fields
11034+ |= [fields=(list field) seen=written-fields]
11037+ =/ f=field i.fields
11044+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.f seen))
11046+ =/ inner=(unit idiag)
11048+ %face (duplicate-shape shape.f)
11050+ %bare (duplicate-shape shape.f)
11053+ $(fields t.fields, seen ?~(n seen (~(put by seen) u.n at.f)))
11058+ %cell (duplicate-fields fields.s ~)
11059+ %apply (duplicate-shapes args.s)
11060+ %union (duplicate-shapes cases.s)
11062+ =/ left (duplicate-shape sample.s)
11064+ (duplicate-shape product.s)
11065+ %generic (duplicate-shape body.s)
11068+++ duplicate-samples
11069+ |= [items=(list sample) seen=written-fields]
11072+ =/ a=sample i.items
11080+ =/ dup=(unit idiag) ?~(n ~ (duplicate-written-field u.n at.a seen))
11082+ =/ inner (duplicate-sample a)
11084+ $(items t.items, seen ?~(n seen (~(put by seen) u.n at.a)))
11085+++ duplicate-sample
11089+ %cell (duplicate-samples items.s ~)
11090+ %face (duplicate-shape shape.s)
11091+ %bare (duplicate-shape shape.s)
11098+ =/ first (duplicate-expr i.xs)
11102+ |= [items=(list item) seen=written-fields]
11106+ =/ dup=(unit idiag) ?~(face.a ~ (duplicate-written-field u.face.a at.a seen))
11108+ =/ inner (duplicate-expr val.a)
11110+ $(items t.items, seen ?~(face.a seen (~(put by seen) u.face.a at.a)))
11111+++ duplicate-pieces
11112+ |= pieces=(list piece)
11115+ =/ first=(unit idiag) ?:(?=(%expr -.i.pieces) (duplicate-expr p.i.pieces) ~)
11117+ $(pieces t.pieces)
11119+ |= segs=(list qseg)
11122+ =/ first=(unit idiag) ?:(?=(%expr -.i.segs) (duplicate-expr p.i.segs) ~)
11126+ |= edits=(list edit)
11129+ =/ first (duplicate-expr val.i.edits)
11133+ |= arms=(list arm)
11136+ =/ first (duplicate-expr val.i.arms)
11140+ |= defs=(list def)
11143+ =/ first=(unit idiag)
11145+ %mold (duplicate-shape shape.i.defs)
11146+ %value (duplicate-expr val.i.defs)
11154+ %str (duplicate-pieces pieces.e)
11155+ %qath (duplicate-qsegs segs.e)
11156+ %change (duplicate-edits edits.e)
11157+ %pair (duplicate-expr val.e)
11158+ %unit (duplicate-expr val.e)
11159+ %group (duplicate-expr inner.e)
11160+ %list (duplicate-exprs items.e)
11161+ %tuple (duplicate-items items.e ~)
11163+ =/ first (duplicate-sample sample.e)
11165+ (duplicate-expr body.e)
11167+ =/ first (duplicate-sample sample.e)
11169+ (duplicate-expr body.e)
11171+ =/ first (duplicate-shape shape.e)
11173+ (duplicate-expr val.e)
11175+ =/ first (duplicate-expr head.e)
11177+ (duplicate-exprs args.e)
11179+ =/ first (duplicate-expr val.e)
11181+ (duplicate-expr then.e)
11183+ =/ first (duplicate-expr subject.e)
11185+ (duplicate-arms arms.e)
11187+ =/ first (duplicate-defs defs.e)
11189+ (duplicate-expr final.e)
8107++ import-binding-names
11192++ import-binding-names
8108 |= imports=(list import)
11193 |= imports=(list import)
8109 ^- (list term)
11194 ^- (list term)
@@ -8116,6 +11201,60 @@
8117 [n $(imports t.imports)]
11202 [n $(imports t.imports)]
11204+++ reserved-proj-sample
11208+ %bind =(name.sam %proj)
11209+ %face =(name.sam %proj)
11210+ %pun =(name.sam %proj)
11211+ %cell (lien items.sam reserved-proj-sample)
11214+++ reserved-proj-pattern
11218+ %bind =(name.p %proj)
11219+ %cell (lien items.p reserved-proj-pattern)
11222+++ reserved-proj-def
11225+ ?: =(name.d %proj) &
11226+ ?: ?=(%value -.d) (reserved-proj-expr val.d)
11228+++ reserved-proj-expr
11232+ %str (lien pieces.e |=(p=piece ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11233+ %qath (lien segs.e |=(p=qseg ?:(?=(%expr -.p) (reserved-proj-expr p.p) |)))
11234+ %change (lien edits.e |=(p=edit (reserved-proj-expr val.p)))
11237+ %group $(e inner.e)
11238+ %list (lien items.e reserved-proj-expr)
11239+ %tuple (lien items.e |=(i=item (reserved-proj-expr val.i)))
11240+ ?(%gate %gate-wide) |((reserved-proj-sample sample.e) $(e body.e))
11242+ %call |($(e head.e) (lien args.e reserved-proj-expr))
11243+ %trace |($(e val.e) $(e then.e))
11244+ %branch |($(e subject.e) (lien arms.e |=(a=arm |((reserved-proj-pattern pat.a) (reserved-proj-expr val.a)))))
11245+ %body |((lien defs.e reserved-proj-def) $(e final.e))
11249+++ module-has-reserved-proj
11252+ =/ imported=(list term) (import-binding-names imports.mod)
11253+ =/ vals=(list term) (global-value-names defs.mod)
11254+ =/ molds=imolds (collect-simple-molds defs.mod)
11255+ =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11256+ |((lien (weld imported (weld vals mold-names)) |=(n=term =(n %proj))) (lien defs.mod reserved-proj-def))
8119++ module-scope-valid
11258++ module-scope-valid
8120 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
11259 |= [mod=module prelude-values=(list term) prelude-molds=(list term)]
@@ -8123,6 +11262,7 @@
8123 =/ vals=(list term) (global-value-names defs.mod)
11262 =/ vals=(list term) (global-value-names defs.mod)
8124 =/ molds=imolds (collect-simple-molds defs.mod)
11263 =/ molds=imolds (collect-simple-molds defs.mod)
8125 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11264 =/ mold-names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11265+ ?: (module-has-reserved-proj mod) |
8126 ?. %+ levy imported
11266 ?. %+ levy imported
8127 |= n=term
11267 |= n=term
8128 &((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))))
11268 &((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 +11270,59 @@
8130 ?. (levy vals |=(n=term &((unique-value-name n vals) !(lien prelude-values |=(v=term =(n v)))))) |
11270 ?. (levy vals |=(n=term &((unique-value-name n vals) !(lien prelude-values |=(v=term =(n v)))))) |
8131 (levy mold-names |=(n=term &((unique-value-name n mold-names) !(lien prelude-molds |=(m=term =(n m))))))
11271 (levy mold-names |=(n=term &((unique-value-name n mold-names) !(lien prelude-molds |=(m=term =(n m))))))
11273+:: In an API file or before main's kind is known, a lone `+$ poke`
11274+:: may be a declaration rather than a mold that shadows the prelude. Do not call
11275+:: that one collision definite, and do not hide unrelated scope errors.
11276+++ pending-declared-poke
11277+ |= [at=path mod=module prelude-values=(list term) prelude-molds=(list term)]
11279+ ?. (lien prelude-molds |=(n=term =(%poke n))) |
11280+ ?. |(?=([%ui %api @ %jibb ~] at) (lien defs.mod |=(d=def &(?=(%value -.d) =(%main name.d))))) |
11281+ =/ pokes=(list def)
11282+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11285+ =/ remaining=(list def)
11286+ (skim defs.mod |=(d=def !&(?=(%mold -.d) =(%poke name.d))))
11287+ (module-scope-valid mod(defs remaining) prelude-values prelude-molds)
11289+:: A detailed failure is attached only to the first mold that actually
11290+:: failed in this check, using that module's checked source mold table.
11291++$ imold-failure [message=@t overlap=(unit [name=term cases=upair])]
11292+:: Validate a generic wrapper without an unbounded duplicate-name pass.
11293+++ module-mold-params-valid
11294+ |= [vars=(list @t) seen=(set @t) fuel=@ud]
11298+ ?: (~(has in:..zuse seen) i.vars) |
11299+ $(vars t.vars, seen (~(put in:..zuse seen) i.vars), fuel (dec fuel))
11300+++ module-mold-overlap
11301+ |= [m=[name=term body=shape] molds=imolds]
11303+ =/ sh=shape body.m
11305+ ?. ?=(%generic -.sh) &
11307+ (module-mold-params-valid vars.sh *(set @t) 256)
11309+ =? sh ?=(%generic -.sh) body.sh
11310+ ?. ?=(%union -.sh) ~
11311+ (union-source-overlap cases.sh molds 256)
11312+++ module-mold-types-detail
11313+ |= [molds=imolds state=istate]
11314+ ^- (each imold-types imold-failure)
11316+ =/ m=[name=term body=shape] i.molds
11317+ =/ t=(unit [template=ischeme state=istate])
11318+ (infer-mold-template body.m state(active [name.m active.state], in-mold &))
11320+ =/ overlap=(unit upair) (module-mold-overlap m molds.state)
11321+ [%| ['module mold needs unsupported inference' ?~(overlap ~ `[name.m u.overlap])]]
11322+ =. typ.template.u.t (label-direct-union typ.template.u.t body.m name.m state)
11323+ =/ rest=(each imold-types imold-failure) $(molds t.molds)
11324+ ?: ?=(%| -.rest) rest
11325+ [%& [[name.m template.u.t] p.rest]]
8133++ module-mold-types
11326++ module-mold-types
8134 |= [molds=imolds state=istate]
11327 |= [molds=imolds state=istate]
8135 ^- (each imold-types @t)
11328 ^- (each imold-types @t)
@@ -8145,9 +11338,9 @@
8146:: Prepare a provisional interface from the trusted vendored source.
11339:: Prepare a provisional interface from the trusted vendored source.
8147:: Every declared name remains reserved, but only molds and values this
11340:: Every declared name remains reserved, but only molds and values this
8148−:: fragment can infer are usable. Unsupported bodies are not validated,
11341+:: fragment can infer are usable. Unsupported bodies are not validated.
8149−:: and imports into the prelude are not supported yet. The fixed origin
11342+:: An optional internal source supplies the prelude's one supported import;
8150−:: gives its named unions the same identity in every importing module.
11343+:: clients cannot import that path directly. Named unions retain their origin.
8152:: Recognize only the complete standard prelude list shape. Its recursive
11345:: Recognize only the complete standard prelude list shape. Its recursive
8153:: tail uses the same parameter and the unqualified list name. The reader
11346:: tail uses the same parameter and the unqualified list name. The reader
@@ -8187,6 +11380,20 @@
8187 ?. ?=(%tvar -.i.args.tail) |
11380 ?. ?=(%tvar -.i.args.tail) |
8188 =(var name.i.args.tail)
11381 =(var name.i.args.tail)
11384+ |= [typ=itype name=term vars=(list @ud)]
11386+ ?: ?=(%jrec -.typ) typ(label `name)
11387+ ?: ?=(%grec -.typ)
11388+ ?. (identity-union-parameters vars args.typ) typ(label ~)
11390+ ?. ?=(%union -.typ) typ
11391+ ?. (identity-union-parameters vars args.typ)
11393+ ?: =(at.u.origin.typ /lib/jibb/internal/jibb) typ(label ~)
8190++ partial-prelude-molds
11397++ partial-prelude-molds
8191 |= [molds=imolds state=istate]
11398 |= [molds=imolds state=istate]
8192 ^- imold-types
11399 ^- imold-types
@@ -8199,22 +11406,124 @@
8199 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
11406 (infer-mold-template body.m state(active [name.m active.state], in-mold &))
8200 ?~ out $(molds t.molds)
11407 ?~ out $(molds t.molds)
8201 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
11408 =. typ.template.u.out (label-direct-union typ.template.u.out body.m name.m state)
11409+ =. typ.template.u.out (prelude-label typ.template.u.out name.m vars.template.u.out)
8202 [[name.m template.u.out] $(molds t.molds)]
11410 [[name.m template.u.out] $(molds t.molds)]
8204−++ partial-prelude-interface
11412+:: A compiler-owned interface available only to the dedicated
8205− |= src=@t
11413+:: internal-prelude preparation path, never the ordinary module resolver.
11414+++ private-primitive-interface
11416+ =/ a=itype [%avar 0]
11417+ =/ pair=itype [%cell a a]
11418+ =/ b=itype [%rvar 0]
11419+ =/ plus=ischeme [[%fn [%cell b b] b] ~[0]]
11420+ =/ minus=ischeme [[%fn b b] ~[0]]
11421+ =/ greater=ischeme [[%fn pair [%flag ~]] ~[0]]
11422+ [~[[%raw-add plus] [%raw-dec minus] [%raw-gth greater]] ~ /lib/jibb/primitives/jibb ~ ~ ~ ~ ~]
11424+++ infer-private-internal
11425+ |= [src=@t public-source=@t]
11427+ =/ at=path /lib/jibb/internal/jibb
11428+ =/ parsed (parse at src)
11429+ ?: ?=(%| -.parsed) ~
11430+ =/ mod=module p.parsed
11431+ ?^ (duplicate-defs defs.mod) ~
11433+ =/ built=jfile-result (infer-jibb-file at src ~ ~ ~ ~[at] ~ ~ ~ ~)
11434+ ?: ?=(%| -.built) ~
11436+ ?. ?=([[%jibb *] ~] imports.mod) ~
11437+ ?. =(path.i.imports.mod /lib/jibb/primitives) ~
11438+ ?. (module-scope-valid mod ~ ~) ~
11439+ =/ vals=(list term) (global-value-names defs.mod)
11440+ ?: (lien vals |=(n=term =(n %main))) ~
11441+ =/ molds=imolds (collect-simple-molds defs.mod)
11442+ =/ globals=(list term) (weld (import-binding-names imports.mod) vals)
11443+ :: The private source can use the public list and unit molds before the
11444+ :: prelude is otherwise prepared. Re-read the trusted public source here
11445+ :: and admit only its validated canonical templates; do not accept schemes
11446+ :: supplied independently by the caller.
11447+ =/ public=(each module error) (parse /lib/jibb/prelude/jibb public-source)
11448+ ?: ?=(%| -.public) ~
11449+ ?^ (duplicate-defs defs.p.public) ~
11450+ ?. (module-scope-valid p.public ~ ~) ~
11451+ =/ source-molds=imolds (collect-simple-molds defs.p.public)
11452+ =/ written-list=(unit shape) (find-simple-mold %list source-molds)
11453+ =/ source-list=(unit ischeme)
11455+ ?. (standard-prelude-list u.written-list) ~
11456+ `[[%collection %list ~[[%var 0]]] ~[0]]
11457+ :: Derive the public unit template from its actual source, then compare
11458+ :: the complete nominal template before making it available privately.
11459+ =/ unit-decl=(unit shape) (find-simple-mold %unit source-molds)
11460+ =/ source-unit=(unit ischeme)
11462+ =/ unit-molds=imolds ~[[%unit u.unit-decl]]
11463+ =/ unit-state=istate [0 ~ ~ ~ unit-molds ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ | /lib/jibb/prelude/jibb ~[%unit] ~ ~ 256 ~ ~ ~ ~ ~ ~]
11464+ =/ unit-types=imold-types (partial-prelude-molds unit-molds unit-state)
11465+ =/ unit-iface=ifile [~ unit-types /lib/jibb/prelude/jibb ~ ~ ~ ~ ~]
11466+ =/ found=(unit ischeme) (find-jibb-mold %unit unit-iface)
11468+ ?. (standard-unit-template u.found /lib/jibb/prelude/jibb) ~
11470+ =/ primitive=ifile private-primitive-interface
11471+ =? primitive ?=(^ source-list)
11472+ primitive(molds [[%list u.source-list] molds.primitive])
11473+ =? primitive ?=(^ source-unit)
11474+ primitive(molds [[%unit u.source-unit] molds.primitive])
11475+ =/ js=ijimports ~[[face.i.imports.mod primitive]]
11476+ =/ reserved=(list term) ~[face.i.imports.mod]
11477+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11478+ =/ state=istate [0 ~ ~ ~ molds globals ~ ~ ~ ~ js reserved ~ ~ ~ | at top ~ ~ 256 ~ ~ ~ ~ ~ ~]
11479+ =/ mts=(each imold-types @t) (module-mold-types molds state)
11480+ =/ usable=(unit imold-types)
11481+ ?: ?=(%& -.mts) `p.mts
11482+ :: Missing public templates may make an unrelated internal mold
11483+ :: unavailable. Validate all molds once with isolated canonical
11484+ :: templates before admitting only those inferred using the actual
11485+ :: source-backed templates. The proof interface is never exported.
11486+ ?. |(?=(~ source-list) ?=(~ source-unit)) ~
11487+ =/ nil=itype [%const [%null %n 0 '~']]
11488+ =/ canonical-unit=ischeme
11489+ [[%union ~[nil [%cell nil [%face %u [%var 0]]]] `[/lib/jibb/prelude/jibb %unit] `%unit ~[[%var 0]]] ~[0]]
11490+ =/ canonical-list=ischeme [[%collection %list ~[[%var 0]]] ~[0]]
11491+ =/ proof-primitive=ifile private-primitive-interface
11492+ =. molds.proof-primitive ~[[%list canonical-list] [%unit canonical-unit]]
11493+ =/ proof-imports=ijimports ~[[face.i.imports.mod proof-primitive]]
11494+ =/ proof=(each imold-types @t) (module-mold-types molds state(jimports proof-imports))
11495+ ?: ?=(%| -.proof) ~
11496+ `(partial-prelude-molds molds state)
11498+ =/ resolution=iresolved (resolve-groups defs.mod molds globals ~ ~ ~ ~ js reserved at ~)
11499+ =/ env=ienv env.resolution
11500+ ?. (module-values-complete defs.mod env) ~
11501+ `[env u.usable at ~ artifacts.resolution ~ `src ~]
11503+++ partial-prelude-interface-with-internal
11504+ |= [src=@t internal-source=(unit @t)]
8206 ^- (unit ifile)
11505 ^- (unit ifile)
8207 ?: =(0 src) ~
11506 ?: =(0 src) ~
8208 =/ at=path /lib/jibb/prelude/jibb
11507 =/ at=path /lib/jibb/prelude/jibb
8209 =/ parsed (parse at src)
11508 =/ parsed (parse at src)
8210 ?: ?=(%| -.parsed) ~
11509 ?: ?=(%| -.parsed) ~
8211− ?^ imports.p.parsed ~
11510+ ?: (named-mold-has-hole defs.p.parsed) ~
11511+ ?^ (duplicate-defs defs.p.parsed) ~
11512+ =/ private=(unit ijimports)
11513+ ?~ imports.p.parsed `~
11514+ ?. ?=([[%jibb *] ~] imports.p.parsed) ~
11515+ ?. =(path.i.imports.p.parsed /lib/jibb/internal) ~
11516+ ?~ internal-source ~
11517+ =/ built=(unit ifile) (infer-private-internal u.internal-source src)
11519+ `~[[face.i.imports.p.parsed u.built]]
8212 ?~ defs.p.parsed ~
11521 ?~ defs.p.parsed ~
8213 ?. (module-scope-valid p.parsed ~ ~) ~
11522 ?. (module-scope-valid p.parsed ~ ~) ~
8214 =/ ds=(list def) defs.p.parsed
11523 =/ ds=(list def) defs.p.parsed
8215 =/ molds=imolds (collect-simple-molds ds)
11524 =/ molds=imolds (collect-simple-molds ds)
8216 =/ names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
11525 =/ names=(list term) (turn molds |=(m=[name=term body=shape] name.m))
8217− =/ globals=(list term) (global-value-names ds)
11526+ =/ globals=(list term) (weld (import-binding-names imports.p.parsed) (global-value-names ds))
8218 :: Remove raw list before inferring any template, so an altered list
11527 :: Remove raw list before inferring any template, so an altered list
8219 :: cannot leak through an alias. Its name remains reserved either way.
11528 :: cannot leak through an alias. Its name remains reserved either way.
8220 =/ declared=? (lien names |=(name=term =(%list name)))
11529 =/ declared=? (lien names |=(name=term =(%list name)))
@@ -8222,11 +11531,38 @@
8222 =? env-molds declared
11531 =? env-molds declared
8223 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
11532 (skim molds |=(m=[name=term body=shape] !=(%list name.m)))
8224 =/ reserved=(list term) ?:(declared ~[%list] ~)
11533 =/ reserved=(list term) ?:(declared ~[%list] ~)
8225− =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ ~ reserved ~ ~ ~ | at names ~]
11534+ =/ state=istate [0 ~ ~ ~ env-molds globals ~ ~ ~ ~ u.private reserved ~ ~ ~ | at names ~ ~ 256 ~ ~ ~ ~ ~ ~]
8226− =/ mt=imold-types (partial-prelude-molds molds state)
11535+ :: Other prelude molds may use list only after its source has passed
8227− =/ partial=ifile [~ mt at]
11536+ :: the standard-list check. The raw declaration remains removed.
8228− =/ env=ienv (resolve-supported-defs ds env-molds globals ~ ~ ~ ~ ~ reserved at `partial)
11537+ =/ declared-list=(unit shape) (find-simple-mold %list molds)
8229− `[env mt at]
11538+ =/ mold-prelude=(unit ifile)
11539+ ?~ declared-list ~
11540+ ?. (standard-prelude-list u.declared-list) ~
11541+ `[~ ~[[%list [[%collection %list ~[[%var 0]]] ~[0]]]] at ~ ~ ~ ~ ~]
11542+ =/ mt=imold-types (partial-prelude-molds molds state(prelude mold-prelude))
11543+ =/ partial=ifile [~ mt at ~ ~ ~ ~ ~]
11544+ :: An explicitly qualified re-export must resolve. Other unsupported
11545+ :: prelude declarations remain reserved but absent from the interface.
11546+ =/ required=imolds
11548+ |= m=[name=term body=shape]
11549+ =/ sh=shape body.m
11550+ ?. ?=(%ref -.sh) |
11553+ ?. (levy required |=(m=[name=term body=shape] ?=(^ (find-jibb-mold name.m partial)))) ~
11554+ =/ resolution=iresolved (resolve-groups ds env-molds globals ~ ~ ~ ~ u.private reserved at `partial)
11555+ =/ env=ienv env.resolution
11556+ ?. (hole-values-present ds env) ~
11557+ =/ deps=(list iwidth-dependency)
11559+ ~[[at.interface.i.u.private source.interface.i.u.private elaborations.interface.i.u.private]]
11560+ `[env mt at ~ artifacts.resolution deps `src ~]
11562+++ partial-prelude-interface
11565+ (partial-prelude-interface-with-internal src ~)
8231+$ iprelude [iface=ifile values=(list term) molds=(list term)]
11567+$ iprelude [iface=ifile values=(list term) molds=(list term)]
@@ -8241,6 +11577,17 @@
8241 =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
11577 =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
8242 `[u.iface vals ms]
11578 `[u.iface vals ms]
11580+++ prepare-prelude-with-internal
11581+ |= [src=@t internal-source=@t]
11582+ ^- (unit iprelude)
11583+ =/ iface=(unit ifile) (partial-prelude-interface-with-internal src `internal-source)
11585+ =/ parsed (parse /lib/jibb/prelude/jibb src)
11586+ ?: ?=(%| -.parsed) ~
11587+ =/ vals=(list term) (global-value-names defs.p.parsed)
11588+ =/ ms=(list term) (turn (collect-simple-molds defs.p.parsed) |=(m=[name=term body=shape] name.m))
11589+ `[u.iface vals ms]
8244++ module-values-complete
11591++ module-values-complete
8245 |= [ds=(list def) env=ienv]
11592 |= [ds=(list def) env=ienv]
@@ -8261,52 +11608,990 @@
8261 ?: =(at at.i.cache) `iface.i.cache
11608 ?: =(at at.i.cache) `iface.i.cache
8262 $(cache t.cache)
11609 $(cache t.cache)
11611+:: These certificates retain the complete checked source closure. The
11612+:: trusted host must supply the identical prepared prelude and reader nouns.
11613+:: Exact bundle equality binds all source paths and versions; the set
11614+:: retains transitive paths for active-cycle checks. Request-bearing graphs
11615+:: alone have a size limit; incompatible diamond evidence fails closed.
11616+++ request-graph-requests-add
11617+ |= [pending=(list irequest-evidence) acc=(list irequest-evidence) fuel=@ud]
11618+ ^- (unit (list irequest-evidence))
11621+ =/ hit=(list irequest-evidence)
11622+ (skim acc |=(x=irequest-evidence &(=(api-at.x api-at.i.pending) =(name.x name.i.pending))))
11624+ ?. ?=([* ~] hit) ~
11625+ ?. =(i.hit i.pending) ~
11626+ $(pending t.pending, fuel (dec fuel))
11627+ $(pending t.pending, acc [i.pending acc], fuel (dec fuel))
11628+++ request-graph-inputs-match
11629+ |= [g=irequest-graph externals=iexternals marks=imark-externals modules=jbundle values=(list term) molds=(list term) prelude=(unit ifile)]
11631+ ?& =(bundle-input.g modules)
11632+ =(prelude-input.g prelude)
11633+ =(prelude-values.g values)
11634+ =(prelude-molds.g molds)
11635+ =(externals.g externals)
11638+++ request-graph-merge
11639+ |= [imports=ijimports g=irequest-graph fuel=@ud]
11640+ ^- (unit irequest-graph)
11643+ =/ child=ifile interface.i.imports
11645+ =/ cg=irequest-graph u.graph.child
11646+ ?. ?& =(bundle-input.g bundle-input.cg)
11647+ =(prelude-input.g prelude-input.cg)
11648+ =(prelude-values.g prelude-values.cg)
11649+ =(prelude-molds.g prelude-molds.cg)
11650+ =(externals.g externals.cg)
11651+ =(marks.g marks.cg)
11654+ =/ merged=(set path) (~(uni in:..zuse paths.g) paths.cg)
11655+ =/ rs=(unit (list irequest-evidence))
11656+ (request-graph-requests-add requests.cg requests.g (add 1 (lent requests.cg)))
11658+ ?: &(?=(^ u.rs) |((gth (lent ~(tap in:..zuse merged)) 256) (gth (lent u.rs) 256))) ~
11659+ $(imports t.imports, g g(paths merged, requests u.rs), fuel (dec fuel))
11660+++ request-graph-reusable
11661+ |= [f=ifile src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) values=(list term) molds=(list term) prelude=(unit ifile)]
11664+ ?. =(u.source.f src) |
11666+ =/ g=irequest-graph u.graph.f
11667+ ?. (request-graph-inputs-match g externals marks modules values molds prelude) |
11668+ ?. (~(has in:..zuse paths.g) at.f) |
11669+ !(lien active |=(p=path (~(has in:..zuse paths.g) p)))
8264++ resolve-jibb-imports
11671++ resolve-jibb-imports
8265 |= [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)]
11672 |= [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)]
8266 ^- jimports-result
11673 ^- jimports-result
11674+ =/ result=jimports-detailed-result
11675+ (resolve-jibb-imports-detailed imports externals mark-externals modules active prelude-values prelude-molds cache prelude)
11676+ ?: ?=(%| -.result) [%| message.p.result]
11678+++ resolve-jibb-imports-detailed
11679+ |= [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)]
11680+ ^- jimports-detailed-result
8267 ?~ imports [%& [~ cache]]
11681 ?~ imports [%& [~ cache]]
8268 ?. ?=(%jibb -.i.imports) $(imports t.imports)
11682 ?. ?=(%jibb -.i.imports) $(imports t.imports)
8269 =/ at=path (weld path.i.imports `path`~[%jibb])
11683 =/ at=path (weld path.i.imports `path`~[%jibb])
11684+ ?: =(at /lib/jibb/internal/jibb)
11685+ [%| ['the prelude internal module is private' ~]]
11686+ ?: =(at /lib/jibb/primitives/jibb)
11687+ [%| ['the prelude primitive interface is private' ~]]
8270 ?: (lien active |=(p=path =(p at)))
11688 ?: (lien active |=(p=path =(p at)))
8271− [%| (crip "import cycle at {(spud at)}")]
11689+ [%| [(crip "import cycle at {(spud at)}") ~]]
8272 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
11690 =/ found=jbundle (skim modules |=(m=jsource =(at at.m)))
8273− ?~ found [%| (crip "module source missing: {(spud at)}")]
11691+ ?~ found [%| [(crip "module source missing: {(spud at)}") ~]]
8274− ?^ t.found [%| (crip "duplicate module sources: {(spud at)}")]
11692+ ?^ t.found [%| [(crip "duplicate module sources: {(spud at)}") ~]]
8275 =/ cached=(unit ifile) (find-jibb-cache at cache)
11693 =/ cached=(unit ifile) (find-jibb-cache at cache)
8276− =/ iface=jfile-result
11694+ =/ iface=jfile-detailed-result
8277− ?^ cached [%& [u.cached cache]]
11695+ ?^ cached
8278− (infer-jibb-file at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
11696+ ?. =(at.u.cached at) [%| ['cached module identity needs unsupported inference' ~]]
11698+ :: A detached legacy interface has unknown evidence. Rebuild it
11699+ :: against the current graph, without retaining any stale entry.
11700+ =/ clean=jcache (skim cache |=(x=[at=path iface=ifile] !=(at.x at)))
11701+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds clean prelude)
11702+ ?. (request-graph-reusable u.cached source.i.found externals mark-externals modules active prelude-values prelude-molds prelude)
11703+ [%| ['cached module evidence needs unsupported inference' ~]]
11704+ [%& [u.cached cache]]
11705+ (infer-jibb-file-detailed at source.i.found externals mark-externals modules [at active] prelude-values prelude-molds cache prelude)
8279 ?: ?=(%| -.iface) [%| p.iface]
11706 ?: ?=(%| -.iface) [%| p.iface]
8280− =/ rest=jimports-result $(imports t.imports, cache cache.p.iface)
11707+ =/ rest=jimports-detailed-result $(imports t.imports, cache cache.p.iface)
8281 ?: ?=(%| -.rest) rest
11708 ?: ?=(%| -.rest) rest
8282 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
11709 [%& [[[face.i.imports iface.p.iface] resolved.p.rest] cache.p.rest]]
11711+:: Provisional declaration extraction only; this does not derive asks,
11712+:: validate imported types, or claim that an API module has checked.
11713++$ iapi-path [at=span name=term segments=(list pseg) full=term diffs=(list term) scry=(unit (list pseg))]
11715+ |= [sh=shape marks=(list term)]
11717+ ?. ?=(%ref -.sh) ~
11718+ ?. ?=([@ ~] names.sh) ~
11719+ ?. (unique-value-name i.names.sh marks) ~
11723+ |= [shapes=(list shape) marks=(list term) used=(list term)]
11724+ ^- (unit (list term))
11726+ =/ n=(unit term) (api-path-mark i.shapes marks)
11728+ ?: (lien used |=(x=term =(x u.n))) ~
11729+ =/ rest=(unit (list term)) $(shapes t.shapes, used [u.n used])
11733+++ api-path-payload
11734+ |= [sh=shape marks=(list term)]
11735+ ^- (unit [full=term diffs=(list term)])
11736+ =/ direct=(unit term) (api-path-mark sh marks)
11737+ ?^ direct `[u.direct ~]
11738+ ?. ?=(%apply -.sh) ~
11739+ ?. =(~[%facts] ref.sh) ~
11742+ =/ full=(unit term) (api-path-mark i.args.sh marks)
11744+ =/ diffs=(unit (list term)) (api-path-diffs t.args.sh marks ~[u.full])
11748++$ iapi-parameter [name=term aura=@ta at=span]
11749+++ api-path-parameters
11750+ |= [segments=(list pseg) seen=(list term)]
11751+ ^- (unit (list iapi-parameter))
11753+ ?: ?=(%knot -.i.segments) $(segments t.segments)
11754+ =/ seg=pseg i.segments
11755+ ?. ?=(%typed -.seg) ~
11756+ ?: =(0 aura.seg) ~
11757+ ?: (lien seen |=(n=term =(n name.seg))) ~
11758+ =/ rest=(unit (list iapi-parameter)) $(segments t.segments, seen [name.seg seen])
11760+ `[[name.seg aura.seg at.seg] u.rest]
11762+++ api-scry-parameters-compatible
11763+ |= [scry=(list iapi-parameter) watch=(list iapi-parameter)]
11766+ ?. (lien watch |=(p=iapi-parameter &(=(name.p name.i.scry) =(aura.p aura.i.scry)))) |
11770+ |= [sh=shape marks=(list term)]
11771+ ^- (unit iapi-path)
11772+ ?. ?=(%cell -.sh) ~
11773+ =/ fs=(list field) fields.sh
11777+ ?: (gth (lent fs) 4) ~
11778+ ?. ?=(%bare -.i.fs) ~
11779+ =/ tag=shape shape.i.fs
11780+ ?. ?=(%const -.tag) ~
11781+ ?. =(%term form.lit.tag) ~
11782+ =/ name=term val.lit.tag
11783+ ?. (jibb-face-name name) ~
11784+ ?. ?=(%bare -.i.t.fs) ~
11785+ =/ path-shape=shape shape.i.t.fs
11786+ ?. ?=(%path -.path-shape) ~
11787+ ?. ?=(%bare -.i.t.t.fs) ~
11788+ =/ payload=(unit [full=term diffs=(list term)]) (api-path-payload shape.i.t.t.fs marks)
11790+ =/ scry=(unit (unit (list pseg)))
11792+ =/ entry=field i.t.t.t.fs
11793+ ?. ?=(%face -.entry) ~
11794+ ?. =(%scry name.entry) ~
11795+ ?. ?=(%path -.shape.entry) ~
11796+ ``segs.shape.entry
11798+ =/ params=(unit (list iapi-parameter)) (api-path-parameters segs.path-shape ~)
11801+ =/ scry-params=(unit (list iapi-parameter)) (api-path-parameters u.u.scry ~)
11803+ ?. (api-scry-parameters-compatible u.scry-params u.params) ~
11804+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11805+ `[at.sh name segs.path-shape full.u.payload diffs.u.payload u.scry]
11808+ |= [shapes=(list shape) marks=(list term) seen=(list term)]
11809+ ^- (unit (list iapi-path))
11811+ =/ one=(unit iapi-path) (api-path-one i.shapes marks)
11813+ ?: (lien seen |=(n=term =(n name.u.one))) ~
11814+ =/ rest=(unit (list iapi-path)) $(shapes t.shapes, seen [name.u.one seen])
11818+++ api-path-declaration
11819+ |= [sh=shape marks=(list term)]
11820+ ^- (unit (list iapi-path))
11821+ ?: ?=(%union -.sh) (api-path-many cases.sh marks ~)
11822+ (api-path-many ~[sh] marks ~)
11824+:: Derived gates share the value namespace. /% marks name molds; /- and
11825+:: /= also introduce faces that cannot be shadowed by a derived value.
11826+++ api-import-faces
11827+ |= imports=(list import)
11831+ %mark $(imports t.imports)
11832+ %sur [name.i.imports $(imports t.imports)]
11833+ %jibb [face.i.imports $(imports t.imports)]
11836+++ api-derived-names-valid
11837+ |= [paths=(list iapi-path) poke-names=(list term) mod=module prelude-values=(list term)]
11839+ =/ path-names=(list term) (turn paths |=(p=iapi-path name.p))
11840+ =/ derived=(list term) (weld path-names poke-names)
11841+ ?: (lien derived |=(n=term =(n %proj))) |
11842+ =/ outer=(list term) (weld prelude-values (weld (global-value-names defs.mod) (api-import-faces imports.mod)))
11843+ (levy derived |=(n=term &((unique-value-name n derived) !(lien outer |=(x=term =(n x))))))
11845+:: Analysis only. Successful external entries must be unchanged results
11846+:: produced for the declared marks; no request interface is produced.
11847++$ iapi-mark-type [name=term typ=itype]
11848++$ iapi-path-typed [path=iapi-path full=itype diffs=(list iapi-mark-type)]
11850+ |= [names=(list term) externals=imark-externals declared=(list term)]
11851+ ^- (unit (list iapi-mark-type))
11853+ =/ typ=(unit itype) (find-imported-mark i.names externals declared)
11855+ =/ tail=(unit (list iapi-mark-type)) $(names t.names)
11857+ `[[i.names u.typ] u.tail]
11860+ |= [paths=(list iapi-path) externals=imark-externals declared=(list term)]
11861+ ^- (unit (list iapi-path-typed))
11863+ =/ full=(unit itype) (find-imported-mark full.i.paths externals declared)
11865+ =/ diffs=(unit (list iapi-mark-type)) (api-diff-types diffs.i.paths externals declared)
11867+ =/ tail=(unit (list iapi-path-typed)) $(paths t.paths)
11869+ `[[i.paths u.full u.diffs] u.tail]
11871+++ api-poke-mark-names
11872+ |= [pokes=(list def) declared=(list term)]
11873+ ^- (unit (list term))
11877+ ?. ?=(%mold -.d) ~
11878+ =/ sh=shape shape.d
11879+ ?: ?=(%union -.sh) (api-path-diffs cases.sh declared ~)
11880+ =/ name=(unit term) (api-path-mark sh declared)
11884+++ api-path-analysis
11885+ |= [mod=module externals=imark-externals prelude-values=(list term) prelude-molds=(list term)]
11886+ ^- (unit (list iapi-path-typed))
11887+ ?: (lien defs.mod def-has-hole) ~
11888+ ?^ (duplicate-defs defs.mod) ~
11889+ =/ ds=(list def) defs.mod
11890+ =/ declarations=(list def)
11891+ (skim ds |=(d=def &(?=(%mold -.d) =(%paths name.d))))
11892+ ?. ?=([* ~] declarations) ~
11893+ =/ pokes=(list def)
11894+ (skim ds |=(d=def &(?=(%mold -.d) =(%poke name.d))))
11895+ ?: (gth (lent pokes) 1) ~
11896+ =/ ordinary=(list def)
11897+ (skim ds |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
11898+ ?. (module-scope-valid mod(defs ordinary) prelude-values prelude-molds) ~
11899+ =/ declared=(list term) (collect-mark-imports imports.mod)
11900+ =/ poke-names=(unit (list term)) (api-poke-mark-names pokes declared)
11902+ =/ decl=def i.declarations
11903+ ?> ?=(%mold -.decl)
11904+ =/ paths=(unit (list iapi-path)) (api-path-declaration shape.decl declared)
11906+ ?. (api-derived-names-valid u.paths u.poke-names mod prelude-values) ~
11907+ (api-path-types u.paths externals declared)
11909+:: Source/graph entry for path analysis only. The returned paths retain
11910+:: reader-derived mark types and import resolution has checked reachable
11911+:: Jibb dependencies. This is not an API interface or a module check.
11912+++ api-path-analysis-source
11913+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11914+ ^- (each (list iapi-path-typed) @t)
11915+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path analysis requires /ui/api/<agent>.jibb']
11916+ =/ parsed (parse file src)
11917+ ?: ?=(%| -.parsed) [%| 'API path source does not parse']
11918+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11919+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11920+ ?~ prepared [%| 'API path analysis needs the prepared prelude']
11921+ =/ prelude=(unit ifile) `iface.u.prepared
11922+ =/ deps=jimports-result
11923+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ prelude)
11924+ ?: ?=(%| -.deps) [%| p.deps]
11925+ =/ paths=(unit (list iapi-path-typed))
11926+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11927+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11930+:: Analysis evidence retains the API source, the prepared interface, the
11931+:: caller's reader results and the resolved Jibb dependency cache alongside
11932+:: the typed path declarations. Reader results and prepared interfaces are
11933+:: trusted inputs: this does not verify their underlying Hoon source/version,
11934+:: create requests or check the provenance of arbitrary values.
11935++$ iapi-path-evidence
11936+ [at=path source=@t prepared=iprelude externals=iexternals marks=imark-externals dependencies=jcache paths=(list iapi-path-typed)]
11937+++ api-path-evidence-source
11938+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
11939+ ^- (each iapi-path-evidence @t)
11940+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11941+ =/ parsed (parse file src)
11942+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11943+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11944+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11945+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11946+ =/ public=ifile iface.u.prepared
11947+ =/ deps=jimports-result
11948+ (resolve-jibb-imports imports.p.parsed externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
11949+ ?: ?=(%| -.deps) [%| p.deps]
11950+ =/ paths=(unit (list iapi-path-typed))
11951+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11952+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11953+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11954+:: Graph-aware variant preserves the caller active stack and cache.
11955+++ api-path-evidence-graph
11956+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
11957+ ^- (each iapi-path-evidence @t)
11958+ ?~ active [%| 'API analysis needs an active graph']
11959+ ?. =(i.active file) [%| 'API analysis active graph does not start at the source']
11960+ ?: (lien t.active |=(p=path =(p file))) [%| 'API analysis active graph contains a cycle']
11961+ ?. ?=([%ui %api @ %jibb ~] file) [%| 'API path evidence requires /ui/api/<agent>.jibb']
11962+ =/ parsed (parse file src)
11963+ ?: ?=(%| -.parsed) [%| 'API path evidence source does not parse']
11964+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
11965+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
11966+ ?~ prepared [%| 'API path evidence needs the prepared prelude']
11967+ =/ public=ifile iface.u.prepared
11968+ =/ deps=jimports-result
11969+ (resolve-jibb-imports imports.p.parsed externals marks modules active values.u.prepared molds.u.prepared cache `public)
11970+ ?: ?=(%| -.deps) [%| p.deps]
11971+ =/ paths=(unit (list iapi-path-typed))
11972+ (api-path-analysis p.parsed marks values.u.prepared molds.u.prepared)
11973+ ?~ paths [%| 'API path declaration needs unsupported analysis']
11974+ [%& [file src u.prepared externals marks cache.p.deps u.paths]]
11976+:: This query classifies a unique path declaration only. Missing evidence
11977+:: or a nonunique name is unknown; it proves nothing about an ask value.
11978+:: Like prepared interfaces, the supplied evidence is a trusted host input.
11979+++ api-path-watchability
11980+ |= [evidence=(unit iapi-path-evidence) case-name=term]
11981+ ^- ?(%watchable %not-watchable %unknown)
11982+ ?~ evidence %unknown
11983+ =/ found=(list iapi-path-typed)
11984+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
11985+ ?. ?=([* ~] found) %unknown
11986+ ?~ scry.path.i.found %watchable
11989+:: These are declaration-derived request components, not a callable gate,
11990+:: an ask value, or proof of a value's provenance. Keep the exact trusted
11991+:: source/reader evidence until a later checked interface and lowerer can
11992+:: attach it to a generated request. No argument ordering is claimed here.
11993++$ iapi-request-parameter [name=term typ=itype at=span]
11994++$ iapi-request-parts
11995+ [evidence=iapi-path-evidence path=iapi-path-typed parameters=(list iapi-request-parameter) reply-sample=itype fold=(unit itype) watchability=?(%watchable %not-watchable)]
11996+++ api-request-parameter-types
11997+ |= params=(list iapi-parameter)
11998+ ^- (unit (list iapi-request-parameter))
12000+ =/ aura=@ta aura.i.params
12001+ ?. |(?=(?(%u %ud %ux %uv %t %ta %tas %p %da %dr) aura) =('tD' aura)) ~
12002+ =/ rest=(unit (list iapi-request-parameter)) $(params t.params)
12004+ `[[name.i.params [%atom aura] at.i.params] u.rest]
12006+:: A single diff's fold consumes the tagged diff and the previous full value.
12007+:: Multiple-diff unions need a checked union representation and remain open.
12008+++ api-request-fold-type
12009+ |= p=iapi-path-typed
12010+ ^- (unit (unit itype))
12013+ =/ d=iapi-mark-type i.diffs.p
12014+ =/ literal=lit [%term %tas name.d (crip ['%' (trip name.d)])]
12015+ =/ sample=itype [%cell [%cell [%const literal] typ.d] full.p]
12016+ ``[%fn sample full.p]
12018+++ api-request-parts
12019+ |= [evidence=(unit iapi-path-evidence) case-name=term]
12020+ ^- (unit iapi-request-parts)
12022+ =/ found=(list iapi-path-typed)
12023+ (skim paths.u.evidence |=(p=iapi-path-typed =(name.path.p case-name)))
12024+ ?. ?=([* ~] found) ~
12025+ =/ p=iapi-path-typed i.found
12026+ =/ raw=(unit (list iapi-parameter)) (api-path-parameters segments.path.p ~)
12028+ =/ params=(unit (list iapi-request-parameter)) (api-request-parameter-types u.raw)
12030+ =/ fold=(unit (unit itype)) (api-request-fold-type p)
12032+ =/ watch=?(%watchable %not-watchable) ?~(scry.path.p %watchable %not-watchable)
12033+ `[u.evidence p u.params full.p u.fold watch]
12035+:: Check ordinary API molds and values plus every declared mark type using
12036+:: the same trusted source, prepared prelude and reader inputs as path
12037+:: evidence. Keep elaborations with those inputs for a later interface.
12038+:: This is partial analysis: an unused /- core is not independently checked,
12039+:: definitions needing derived values remain unsupported, and no complete
12040+:: API, request or constructor is exported or given runtime behavior.
12041++$ iapi-support-evidence
12042+ [paths=iapi-path-evidence values=ienv molds=imold-types marks=(list iapi-mark-type) elaborations=(list iwidth-definition)]
12043+++ api-support-analysis-source
12044+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12045+ ^- (each iapi-support-evidence @t)
12046+ =/ path-result (api-path-evidence-source file src externals marks modules prepared)
12047+ ?: ?=(%| -.path-result) [%| p.path-result]
12048+ =/ evidence=iapi-path-evidence p.path-result
12049+ =/ parsed (parse file src)
12050+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12051+ =/ mod=module p.parsed
12052+ =/ ordinary=(list def)
12053+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12054+ =/ prep=iprelude prepared.evidence
12055+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12056+ =/ vals=(list term) (global-value-names ordinary)
12057+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12058+ =/ declared=(list term) (collect-mark-imports imports.mod)
12059+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12060+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12061+ =/ prelude=(unit ifile) `iface.prep
12062+ =/ deps=jimports-result
12063+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.prep molds.prep dependencies.evidence prelude)
12064+ ?: ?=(%| -.deps) [%| p.deps]
12065+ =/ molds=imolds (collect-simple-molds ordinary)
12066+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12067+ =/ surs=(list term) (collect-sur-imports imports.mod)
12068+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12069+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12070+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12071+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12072+ ?: ?=(%| -.mts) [%| p.mts]
12073+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12074+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12075+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12076+:: Preserve the same graph context through supporting definitions.
12077+++ api-support-analysis-graph
12078+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12079+ ^- (each iapi-support-evidence @t)
12080+ =/ path-result (api-path-evidence-graph file src externals marks modules active cache prepared)
12081+ ?: ?=(%| -.path-result) [%| p.path-result]
12082+ =/ evidence=iapi-path-evidence p.path-result
12083+ =/ parsed (parse file src)
12084+ ?: ?=(%| -.parsed) [%| 'API source does not parse']
12085+ =/ mod=module p.parsed
12086+ =/ ordinary=(list def)
12087+ (skim defs.mod |=(d=def !&(?=(%mold -.d) |(=(%paths name.d) =(%poke name.d)))))
12088+ =/ prep=iprelude prepared.evidence
12089+ ?. (module-scope-valid mod(defs ordinary) values.prep molds.prep) [%| 'API ordinary scope needs unsupported inference']
12090+ =/ vals=(list term) (global-value-names ordinary)
12091+ ?: (lien vals |=(n=term =(n %main))) [%| 'API module kind needs unsupported inference']
12092+ =/ declared=(list term) (collect-mark-imports imports.mod)
12093+ =/ mark-types=(unit (list iapi-mark-type)) (api-diff-types declared marks declared)
12094+ ?~ mark-types [%| 'API declared marks need unsupported inference']
12095+ =/ prelude=(unit ifile) `iface.prep
12096+ =/ deps=jimports-result
12097+ (resolve-jibb-imports imports.mod externals marks modules active values.prep molds.prep dependencies.evidence prelude)
12098+ ?: ?=(%| -.deps) [%| p.deps]
12099+ =/ molds=imolds (collect-simple-molds ordinary)
12100+ =/ globals=(list term) (weld values.prep (weld (import-binding-names imports.mod) vals))
12101+ =/ surs=(list term) (collect-sur-imports imports.mod)
12102+ =/ reserved=(list term) (weld molds.prep (turn resolved.p.deps |=(j=[face=term interface=ifile] face.j)))
12103+ =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12104+ =/ state=istate [0 ~ ~ ~ molds globals externals surs marks declared resolved.p.deps reserved ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12105+ =/ mts=(each imold-types @t) (module-mold-types molds state)
12106+ ?: ?=(%| -.mts) [%| p.mts]
12107+ =/ resolution=iresolved (resolve-groups ordinary molds globals externals surs marks declared resolved.p.deps reserved file prelude)
12108+ ?. (module-values-complete ordinary env.resolution) [%| 'API ordinary definitions need unsupported inference']
12109+ [%& [evidence env.resolution p.mts u.mark-types artifacts.resolution]]
12111+:: Type-analysis artifact for one plain request. The resolver may publish
12112+:: its interface only together with trusted source and reader evidence.
12113+:: No lowering or runtime validator exists.
12114+:: Value watchability remains unproved even for a watchable declaration.
12115++$ ione-request-interface
12116+ [support=iapi-support-evidence parts=iapi-request-parts iface=ifile]
12117+++ request-compatible-ask
12118+ |= prelude=iprelude
12120+ =/ public=ifile iface.prelude
12121+ ?. =(at.public /lib/jibb/prelude/jibb) ~
12122+ =/ ask=(unit ischeme) (find-jibb-mold %ask public)
12124+ ?. ?=([@ ~] vars.u.ask) ~
12125+ ?. ?=(%union -.typ.u.ask) ~
12126+ ?. =(origin.typ.u.ask `[/lib/jibb/internal/jibb %ask]) ~
12127+ ?. (identity-union-parameters vars.u.ask args.typ.u.ask) ~
12128+ =/ m=@ud i.vars.u.ask
12129+ ?: (itype-var-is-atom m typ.u.ask) ~
12130+ ?. (levy (itype-vars typ.u.ask) |=(n=@ud =(n m))) ~
12131+ ?: (itype-has-tag typ.u.ask) ~
12132+ =/ private=(list iwidth-dependency)
12133+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12134+ ?. ?=([* ~] private) ~
12135+ ?~ source.i.private ~
12136+ =/ path=(unit ischeme) (find-jibb-mold %path public)
12139+ =/ path-type=itype [%collection %list ~[[%atom %ta]]]
12140+ ?. =(typ.u.path path-type) ~
12141+ =/ unit-template=(unit ischeme) (find-jibb-mold %unit public)
12142+ ?~ unit-template ~
12143+ ?. (standard-unit-template u.unit-template /lib/jibb/prelude/jibb) ~
12144+ =/ state-unit=(unit itype) (template-apply u.unit-template ~[[%noun ~]])
12146+ =/ path-unit=(unit itype) (template-apply u.unit-template ~[path-type])
12148+ =/ output=itype [%cell [%face %state [%noun ~]] [%face %message [%var m]]]
12149+ =/ agent-input=itype [%cell [%face %mark [%atom %tas]] [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]]
12150+ =/ store-input=itype [%cell [%face %state u.state-unit] [%face %fact [%noun ~]]]
12151+ =/ pure-case=itype [%cell [%const [%term %tas %pure '%pure']] [%face %value [%var m]]]
12152+ =/ agent-case=itype
12153+ [%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]]]]]]]]
12154+ =/ store-case=itype
12155+ [%cell [%const [%term %tas %store '%store']] [%cell [%face %module [%atom %t]] [%cell [%face %name [%atom %tas]] [%face %receive [%fn store-input output]]]]]
12156+ ?. =(cases.typ.u.ask ~[pure-case agent-case store-case]) ~
12159+:: The first supported standalone API has exactly one mark import and one
12160+:: plain path declaration, with no other definitions or imports. No partial
12161+:: success is published when source, schema, or a required mold is unknown.
12162+++ one-request-interface-source
12163+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude)]
12164+ ^- (each ione-request-interface @t)
12165+ =/ out (api-support-analysis-source file src externals marks modules prepared)
12166+ ?: ?=(%| -.out) [%| p.out]
12167+ =/ support=iapi-support-evidence p.out
12168+ =/ ev=iapi-path-evidence paths.support
12169+ =/ parsed (parse file src)
12170+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12171+ =/ mod=module p.parsed
12172+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12173+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12174+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12175+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12176+ =/ p=iapi-path-typed i.paths.ev
12177+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12178+ ?~ parts [%| 'request components need unsupported inference']
12179+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12180+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12181+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12183+ ?~ fold.u.parts ?=([* ~] marks.support)
12184+ ?=([* [* ~]] marks.support)
12185+ ?. valid-marks [%| 'request marks need unsupported inference']
12188+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12189+ ?: fold-open [%| 'request fold needs unsupported inference']
12190+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12191+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12192+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12193+ ?~ ask [%| 'request ask needs unsupported inference']
12194+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12195+ ?~ result [%| 'request ask needs unsupported inference']
12196+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12198+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12199+ ?~ parameters.u.parts callback
12200+ [%cell typ.i.parameters.u.parts callback]
12201+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12202+ =/ exports=imold-types
12203+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12204+ =/ prelude=iprelude prepared.ev
12205+ =/ public=ifile iface.prelude
12206+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12207+ =/ private=(list iwidth-dependency)
12208+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12209+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12210+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12211+ =/ req=irequest-evidence
12212+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12213+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12214+ [%& [support u.parts interface]]
12215+:: Graph-aware request artifact; resolver use remains type-only.
12216+++ one-request-interface-graph
12217+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12218+ ^- (each ione-request-interface @t)
12219+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12220+ ?: ?=(%| -.out) [%| p.out]
12221+ =/ support=iapi-support-evidence p.out
12222+ =/ ev=iapi-path-evidence paths.support
12223+ =/ parsed (parse file src)
12224+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12225+ =/ mod=module p.parsed
12226+ ?. ?=(?([[%mark *] ~] [[%mark *] [%mark *] ~]) imports.mod) [%| 'request imports need unsupported inference']
12227+ ?. ?=([[%mold *] ~] defs.mod) [%| 'request definitions need unsupported inference']
12228+ ?. =(%paths name.i.defs.mod) [%| 'request declaration needs unsupported inference']
12229+ ?. ?=([* ~] paths.ev) [%| 'request count needs unsupported inference']
12230+ =/ p=iapi-path-typed i.paths.ev
12231+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12232+ ?~ parts [%| 'request components need unsupported inference']
12233+ ?. ?=(?(~ [* ~]) parameters.u.parts) [%| 'request parameters need unsupported inference']
12234+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) [%| 'request parameter and fold need unsupported inference']
12235+ ?^ scry.path.p [%| 'request scry needs unsupported inference']
12237+ ?~ fold.u.parts ?=([* ~] marks.support)
12238+ ?=([* [* ~]] marks.support)
12239+ ?. valid-marks [%| 'request marks need unsupported inference']
12242+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12243+ ?: fold-open [%| 'request fold needs unsupported inference']
12244+ ?^ (itype-vars reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12245+ ?: (itype-has-tag reply-sample.u.parts) [%| 'request payload needs unsupported inference']
12246+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12247+ ?~ ask [%| 'request ask needs unsupported inference']
12248+ =/ result=(unit itype) (template-apply u.ask ~[[%var 0]])
12249+ ?~ result [%| 'request ask needs unsupported inference']
12250+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12252+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12253+ ?~ parameters.u.parts callback
12254+ [%cell typ.i.parameters.u.parts callback]
12255+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12256+ =/ exports=imold-types
12257+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12258+ =/ prelude=iprelude prepared.ev
12259+ =/ public=ifile iface.prelude
12260+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12261+ =/ private=(list iwidth-dependency)
12262+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12263+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12264+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12265+ =/ req=irequest-evidence
12266+ [file name.path.p p src u.source.public u.source.i.private values.prelude molds.prelude externals marks]
12267+ =/ interface=ifile [~[[name.path.p scheme]] exports file ~ ~ ~ `src `[(silt `(list path)`~[file]) ~[req] modules `public values.prelude molds.prelude externals marks]]
12268+ [%& [support u.parts interface]]
12270+++ api-mark-exports
12271+ |= [marks=(list term) all=(list term) externals=imark-externals]
12274+ =/ t=(unit itype) (find-imported-mark i.marks externals all)
12275+ ?~ t $(marks t.marks)
12276+ [[i.marks [u.t ~]] $(marks t.marks)]
12278+:: Experimental direct poke-only API. Unsupported API declarations fail
12279+:: as a whole; supplied mark reader results retain their existing boundary.
12280+++ api-poke-interface
12281+ |= [at=path mod=module mark-externals=imark-externals prelude-values=(list term) prelude-molds=(list term) prelude=(unit ifile)]
12283+ ?: (lien defs.mod def-has-hole) ~
12284+ ?. ?=([%ui %api @ %jibb ~] at) ~
12285+ ?^ (duplicate-defs defs.mod) ~
12287+ ?. =(at.u.prelude /lib/jibb/prelude/jibb) ~
12288+ =/ poke=(unit ischeme) (find-jibb-mold %poke u.prelude)
12290+ ?. ?=(%union -.typ.u.poke) ~
12293+ %+ lien cases.typ.u.poke
12295+ ?=([%cell [%const [%term %tas %agent *]] [%cell [%face %agent [%atom %tas]] [%cell [%face %mark [%atom %tas]] [%face %payload [%noun ~]]]]] c)
12297+ ?. (module-scope-valid mod(defs ~) prelude-values prelude-molds) ~
12298+ ?. (levy imports.mod |=(i=import ?=(%mark -.i))) ~
12299+ =/ marks=(list term) (collect-mark-imports imports.mod)
12300+ ?. ?=([@ ~] marks) ~
12301+ =/ ds=(list def) defs.mod
12302+ ?. ?=([[%mold *] ~] ds) ~
12303+ ?. =(%poke name.i.ds) ~
12304+ =/ sh=shape shape.i.ds
12305+ ?. ?=([%ref *] sh) ~
12306+ ?. ?=([@ ~] names.sh) ~
12307+ =/ n=term i.names.sh
12308+ ?. (unique-value-name n marks) ~
12309+ ?: |((lien prelude-values |=(x=term =(n x))) (lien prelude-molds |=(x=term =(n x)))) ~
12310+ =/ mark=(unit itype) (find-imported-mark n mark-externals marks)
12312+ =/ sc=ischeme [[%fn u.mark typ.u.poke] ~]
12313+ `[~[[n sc]] (api-mark-exports marks marks mark-externals) at ~[[n i.t.t.at n]] ~ ~ ~ ~]
12315+:: Source-proven ordinary helpers validate each selected /sur dependency.
12316+:: Unused or less direct cores remain unsupported by this first interface.
12318+ |= [surs=(list term) defs=(list def) externals=iexternals all=(list term)]
12321+ =/ found=(list def)
12324+ ?. ?=(%mold -.d) |
12325+ ?. ?=(%ref -.shape.d) |
12326+ ?. ?=([@ [@ ~]] names.shape.d) |
12327+ =(i.t.names.shape.d i.surs)
12329+ =/ selected=def i.found
12330+ ?. ?=(%mold -.selected) |
12331+ =/ sh=shape shape.selected
12332+ ?. ?=(%ref -.sh) |
12333+ ?. ?=([@ [@ ~]] names.sh) |
12334+ =/ checked=(unit itype) (find-imported-mold i.surs i.names.sh externals all)
12338++$ imulti-request-gates [values=ienv requests=(list irequest-evidence)]
12339+++ api-request-gates
12340+ |= [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]
12341+ ^- (unit imulti-request-gates)
12344+ =/ p=iapi-path-typed i.paths
12345+ =/ parts=(unit iapi-request-parts) (api-request-parts `ev name.path.p)
12347+ ?. ?=(?(~ [* ~]) parameters.u.parts) ~
12348+ ?: &(?=(^ fold.u.parts) ?=(^ parameters.u.parts)) ~
12350+ ?^ (itype-vars reply-sample.u.parts) ~
12351+ ?: (itype-has-tag reply-sample.u.parts) ~
12354+ |(?=(^ (itype-vars u.fold.u.parts)) (itype-has-tag u.fold.u.parts))
12356+ =/ result=(unit itype) (template-apply ask ~[[%var 0]])
12358+ =/ callback=itype [%fn reply-sample.u.parts [%var 0]]
12360+ ?^ fold.u.parts [%cell callback u.fold.u.parts]
12361+ ?~ parameters.u.parts callback
12362+ [%cell typ.i.parameters.u.parts callback]
12363+ =/ scheme=ischeme [[%fn sample u.result] ~[0]]
12364+ =/ prep=iprelude prepared.ev
12365+ =/ req=irequest-evidence
12366+ [file name.path.p p src public internal values.prep molds.prep externals marks]
12367+ =/ rest=(unit imulti-request-gates)
12368+ $(paths t.paths, fuel (dec fuel))
12370+ `[[[name.path.p scheme] values.u.rest] [req requests.u.rest]]
12372+++ api-poke-from-checked
12373+ |= [file=path mod=module marks=imark-externals values=(list term) molds=(list term) prelude=(unit ifile)]
12374+ ^- (unit [values=ienv derived=(list iderived)])
12375+ =/ pokes=(list def)
12376+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(%poke name.d))))
12378+ ?. ?=([* ~] pokes) ~
12379+ =/ declared=(list term) (collect-mark-imports imports.mod)
12380+ =/ ns=(unit (list term)) (api-poke-mark-names pokes declared)
12382+ ?. ?=([@ ~] u.ns) ~
12383+ =/ matching=(list import)
12384+ %+ skim imports.mod
12386+ ?. ?=(%mark -.i) |
12388+ ?. ?=([* ~] matching) ~
12389+ =/ checked=(unit ifile)
12390+ (api-poke-interface file mod(defs pokes, imports matching) marks values molds prelude)
12392+ `[values.u.checked derived.u.checked]
12394+:: The partial interface is published atomically: all paths, ordinary
12395+:: source definitions, declared marks and the poke must check. Unselected
12396+:: /sur bindings, runtime validation and value watchability remain unproved.
12397+++ multi-request-interface-graph
12398+ |= [file=path src=@t externals=iexternals marks=imark-externals modules=jbundle active=(list path) cache=jcache prepared=(unit iprelude)]
12399+ ^- (each [iface=ifile cache=jcache] @t)
12400+ =/ out (api-support-analysis-graph file src externals marks modules active cache prepared)
12401+ ?: ?=(%| -.out) [%| p.out]
12402+ =/ support=iapi-support-evidence p.out
12403+ =/ ev=iapi-path-evidence paths.support
12404+ =/ parsed (parse file src)
12405+ ?: ?=(%| -.parsed) [%| 'request source does not parse']
12406+ =/ mod=module p.parsed
12407+ ?. (levy imports.mod |=(i=import ?=(?(%mark %sur) -.i)))
12408+ [%| 'request imports need unsupported inference']
12409+ =/ surs=(list term) (collect-sur-imports imports.mod)
12410+ ?. (api-sur-covered surs defs.mod externals surs)
12411+ [%| 'API source dependency needs unsupported inference']
12412+ ?~ paths.ev [%| 'request count needs unsupported inference']
12413+ =/ ask=(unit ischeme) (request-compatible-ask prepared.ev)
12414+ ?~ ask [%| 'request ask needs unsupported inference']
12415+ =/ prep=iprelude prepared.ev
12416+ =/ public=ifile iface.prep
12417+ ?~ source.public [%| 'request prelude source needs unsupported inference']
12418+ =/ private=(list iwidth-dependency)
12419+ (skim dependencies.public |=(d=iwidth-dependency =(at.d /lib/jibb/internal/jibb)))
12420+ ?. ?=([* ~] private) [%| 'request internal source needs unsupported inference']
12421+ ?~ source.i.private [%| 'request internal source needs unsupported inference']
12422+ =/ gates=(unit imulti-request-gates)
12423+ (api-request-gates paths.ev ev u.ask file src u.source.public u.source.i.private externals marks 256)
12424+ ?~ gates [%| 'request paths need unsupported inference']
12425+ =/ poke=(unit [values=ienv derived=(list iderived)])
12426+ (api-poke-from-checked file mod marks values.prep molds.prep `public)
12427+ ?~ poke [%| 'API poke needs unsupported inference']
12428+ =/ mark-molds=imold-types
12429+ (turn marks.support |=(m=iapi-mark-type [name.m [typ.m ~]]))
12430+ =/ exports=imold-types (weld mark-molds molds.support)
12431+ =/ names=(list term) (turn exports |=(m=[name=term template=ischeme] name.m))
12432+ ?. (levy names |=(n=term (unique-value-name n names)))
12433+ [%| 'API exported molds need unsupported inference']
12434+ =/ env=ienv (weld values.u.gates (weld values.u.poke values.support))
12435+ =/ graph=irequest-graph
12436+ [(silt `(list path)`~[file]) requests.u.gates modules `public values.prep molds.prep externals marks]
12438+ [env exports file derived.u.poke elaborations.support ~ `src `graph]
12439+ [%& [iface dependencies.ev]]
8284++ infer-jibb-file
12441++ infer-jibb-file
8285 |= [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)]
12442 |= [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)]
8286 ^- jfile-result
12443 ^- jfile-result
8287− ?: ?=([%ui %api *] at) [%| (crip "API module needs unsupported inference: {(spud at)}")]
12444+ =/ out=jfile-detailed-result
12445+ (infer-jibb-file-detailed at src externals mark-externals modules active prelude-values prelude-molds cache prelude)
12446+ ?: ?=(%| -.out) [%| message.p.out]
12448+:: Returns structured root-source overlap evidence after the same full check.
12449+++ infer-jibb-file-detailed
12450+ |= [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)]
12451+ ^- jfile-detailed-result
8288 =/ parsed (parse at src)
12452 =/ parsed (parse at src)
8289− ?: ?=(%| -.parsed) [%| (crip "module source does not parse: {(spud at)}")]
12453+ ?: ?=(%| -.parsed) [%| [(crip "module source does not parse: {(spud at)}") ~]]
8290 =/ mod=module p.parsed
12454 =/ mod=module p.parsed
8291− ?. (module-scope-valid mod prelude-values prelude-molds) [%| (crip "module has conflicting names: {(spud at)}")]
12455+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12456+ ?^ duplicate [%| [(show-duplicate-fields at src u.duplicate) ~]]
12457+ ?: ?=([%ui %api *] at)
12458+ =/ iface=(unit ifile) (api-poke-interface at mod mark-externals prelude-values prelude-molds prelude)
12460+ =/ checked=ifile u.iface(source `src, graph `[(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals])
12461+ [%& [checked [[at checked] cache]]]
12462+ ?~ prelude [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12463+ =/ prepared=iprelude [u.prelude prelude-values prelude-molds]
12465+ ?. ?=([[%mark *] ~] imports.mod) |
12466+ ?. ?=([[%mold *] ~] defs.mod) |
12467+ ?. =(%paths name.i.defs.mod) |
12468+ !?=(%union -.shape.i.defs.mod)
12470+ =/ request=(each ione-request-interface @t)
12471+ (one-request-interface-graph at src externals mark-externals modules active cache `prepared)
12472+ ?: ?=(%| -.request) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12473+ =/ checked=ifile iface.p.request
12474+ [%& [checked [[at checked] dependencies.paths.support.p.request]]]
12475+ =/ multi=(each [iface=ifile cache=jcache] @t)
12476+ (multi-request-interface-graph at src externals mark-externals modules active cache `prepared)
12477+ ?: ?=(%| -.multi) [%| [(crip "API module needs unsupported inference: {(spud at)}") ~]]
12478+ [%& [iface.p.multi [[at iface.p.multi] cache.p.multi]]]
12479+ ?. (module-scope-valid mod prelude-values prelude-molds)
12480+ ?: (pending-declared-poke at mod prelude-values prelude-molds)
12481+ [%| [(crip "module kind or scope needs unsupported inference: {(spud at)}") ~]]
12482+ [%| [(crip "module has conflicting names: {(spud at)}") ~]]
8292 =/ vals=(list term) (global-value-names defs.mod)
12483 =/ vals=(list term) (global-value-names defs.mod)
8293 ?: (lien vals |=(n=term =(n %main)))
12484 ?: (lien vals |=(n=term =(n %main)))
8294− [%| (crip "module kind needs unsupported inference: {(spud at)}")]
12485+ [%| [(crip "module kind needs unsupported inference: {(spud at)}") ~]]
8295− =/ js=jimports-result (resolve-jibb-imports imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
12486+ =/ js=jimports-detailed-result (resolve-jibb-imports-detailed imports.mod externals mark-externals modules active prelude-values prelude-molds cache prelude)
8296 ?: ?=(%| -.js) [%| p.js]
12487 ?: ?=(%| -.js) [%| p.js]
8297− =/ molds=imolds (collect-simple-molds defs.mod)
12488+ =/ collected=grec-collected
12489+ ?^ imports.mod [(collect-simple-molds defs.mod) *(map term shape)]
12490+ (grec-collect-molds defs.mod)
12491+ =/ molds=imolds molds.collected
8298 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
12492 =/ globals=(list term) (weld prelude-values (weld (import-binding-names imports.mod) vals))
8299 =/ surs=(list term) (collect-sur-imports imports.mod)
12493 =/ surs=(list term) (collect-sur-imports imports.mod)
8300 =/ marks=(list term) (collect-mark-imports imports.mod)
12494 =/ marks=(list term) (collect-mark-imports imports.mod)
8301 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
12495 =/ reserved=(list term) (weld prelude-molds (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
8302 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12496 =/ 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]
12497+ =/ state=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks resolved.p.js reserved ~ ~ ~ | at top prelude ~ 256 ~ ~ ~ ~ ~ ~]
8304− =/ mts=(each imold-types @t) (module-mold-types molds state)
12498+ :: Source and scope were checked above; preserve that exact root and prelude.
8305− ?: ?=(%| -.mts) [%| (crip "{(trip p.mts)}: {(spud at)}")]
12499+ :: This first integration only indexes import-free library sources.
8306− =/ env=ienv (resolve-supported-defs defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12500+ =/ index=(unit [at=path source=@t prelude=ifile shapes=(map term shape)])
12503+ =/ standard=(unit ischeme) (find-jibb-mold %list u.prelude)
12505+ ?. =(u.standard [[%collection %list ~[[%var 0]]] ~[0]]) ~
12506+ =/ index=(map term shape) proofs.collected
12507+ ?. !=(index *(map term shape)) ~
12508+ ?: (lien molds |=(m=[name=term body=shape] =(%list name.m))) ~
12509+ `[at src u.prelude index]
12510+ =. grec-index.state index
12511+ =/ mts=(each imold-types imold-failure) (module-mold-types-detail molds state)
12513+ ?~ overlap.p.mts [%| [(crip "{(trip message.p.mts)}: {(spud at)}") ~]]
12514+ =/ witness=[name=term cases=upair] u.overlap.p.mts
12515+ =/ first=@t (show-error src [at line.beg.first.cases.witness col.beg.first.cases.witness "first union case"])
12516+ =/ second=@t (show-error src [at line.beg.second.cases.witness col.beg.second.cases.witness "overlapping case"])
12517+ =/ msg=@t (of-wain:format ~[(crip "module mold {(trip name.witness)} has overlapping cases") first second])
12518+ [%| [msg `[at src name.witness cases.witness]]]
12519+ =/ resolution=iresolved
12521+ (resolve-groups defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude)
12522+ (resolve-groups-core defs.mod molds globals externals surs mark-externals marks resolved.p.js reserved at prelude index)
12523+ =/ env=ienv env.resolution
12525+ ?: (module-values-complete defs.mod env) env
12526+ ?: |(?=([%ui %stores *] at) ?=(^ imports.mod) ?=(^ prelude) ?=(^ prelude-values) ?=(^ prelude-molds)) env
12527+ ?: (gth (met 3 src) 65.536) env
12528+ ?: (gth (lent defs.mod) 64) env
12529+ ?. (dg-source-candidate defs.mod 64) env
12530+ =/ transaction=(unit dgcommit) (dg-root-source at src)
12531+ ?~ transaction env
12532+ ?: (dg-interface-safe env.u.transaction) env.u.transaction
8307 ?. (module-values-complete defs.mod env)
12534 ?. (module-values-complete defs.mod env)
8308− [%| (crip "module definitions need unsupported inference: {(spud at)}")]
12535+ [%| [(crip "module definitions need unsupported inference: {(spud at)}") ~]]
8309− [%& [[env p.mts at] [[at [env p.mts at]] cache.p.js]]]
12536+ =/ initial=irequest-graph [(silt `(list path)`~[at]) ~ modules prelude prelude-values prelude-molds externals mark-externals]
12537+ =/ graph=(unit irequest-graph) (request-graph-merge resolved.p.js initial (add 1 (lent resolved.p.js)))
12538+ ?~ graph [%| ['module request evidence needs unsupported inference' ~]]
12539+ =/ iface=ifile [env p.mts at ~ artifacts.resolution ~ `src graph]
12540+ [%& [iface [[at iface] cache.p.js]]]
12542+:: A source-bound analysis of one named mold, not a module, island,
12543+:: request, watchability or runtime check. The host owns the trusted
12544+:: prepared prelude, canonical paths and reader/source version identities.
12545+:: The 256-node cap covers only classification, not source/graph work.
12547+ [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]
12548+++ gate-free-mold-source
12549+ |= [file=path src=@t name=term externals=iexternals marks=imark-externals modules=jbundle prepared=(unit iprelude) fuel=@ud]
12550+ ^- (each igate-free-mold @t)
12551+ ?~ file [%| 'mold analysis needs a path ending in jibb']
12552+ ?. =(%jibb (rear file)) [%| 'mold analysis needs a path ending in jibb']
12553+ ?: |(=(file /lib/jibb/internal/jibb) =(file /lib/jibb/primitives/jibb))
12554+ [%| 'the prelude internal modules are private']
12555+ ?: ?=([%ui %api *] file) [%| 'API declarations need unsupported mold analysis']
12556+ ?: ?=([%ui %stores *] file) [%| 'store declarations need unsupported mold analysis']
12557+ =/ entries=jbundle (skim modules |=(m=jsource =(file at.m)))
12558+ ?: (gth (lent entries) 1) [%| 'duplicate root module sources']
12559+ =/ wrong-root=? ?~(entries | !=(source.i.entries src))
12560+ ?: wrong-root [%| 'root module source does not match bundle']
12561+ =/ parsed (parse file src)
12562+ ?: ?=(%| -.parsed) [%| 'mold source does not parse']
12563+ =/ mod=module p.parsed
12564+ =/ duplicate=(unit idiag) (duplicate-defs defs.mod)
12565+ ?^ duplicate [%| (show-duplicate-fields file src u.duplicate)]
12566+ ?~ prepared [%| 'mold analysis needs the prepared prelude']
12567+ ?. (module-scope-valid mod values.u.prepared molds.u.prepared)
12568+ [%| 'mold source has conflicting or unsupported scope']
12569+ =/ selected=(list def)
12570+ (skim defs.mod |=(d=def &(?=(%mold -.d) =(name.d name))))
12571+ ?~ selected [%| 'selected mold is not declared']
12572+ ?^ t.selected [%| 'selected mold is not unique']
12573+ ?> ?=(%mold -.i.selected)
12574+ =/ public=ifile iface.u.prepared
12575+ =/ js=jimports-result
12576+ (resolve-jibb-imports imports.mod externals marks modules ~[file] values.u.prepared molds.u.prepared ~ `public)
12577+ ?: ?=(%| -.js) [%| p.js]
12578+ =/ ms=imolds (collect-simple-molds defs.mod)
12579+ =/ vals=(list term) (global-value-names defs.mod)
12580+ =/ globals=(list term) (weld values.u.prepared (weld (import-binding-names imports.mod) vals))
12581+ =/ surs=(list term) (collect-sur-imports imports.mod)
12582+ =/ declared=(list term) (collect-mark-imports imports.mod)
12583+ =/ reserved=(list term) (weld molds.u.prepared (turn resolved.p.js |=(j=[face=term interface=ifile] face.j)))
12584+ =/ top=(list term) (turn ms |=(m=[name=term body=shape] name.m))
12585+ =/ state=istate [0 ~ ~ ~ ms globals externals surs marks declared resolved.p.js reserved ~ ~ ~ | file top `public ~ 256 ~ ~ ~ ~ ~ ~]
12586+ =/ inferred=(unit [template=ischeme state=istate])
12587+ (infer-mold-template shape.i.selected state(active ~[name], in-mold &))
12588+ ?~ inferred [%| 'selected mold needs unsupported inference']
12589+ =/ template=ischeme template.u.inferred
12590+ =. typ.template (label-direct-union typ.template shape.i.selected name state)
12591+ =. typ.template (itype-normalize typ.template sub.state.u.inferred)
12592+ =/ cap=@ud (min fuel 256)
12593+ =/ analysis=igate-free (gate-free-type typ.template cap ~)
12594+ [%& [file src name u.prepared externals marks modules cache.p.js template fuel cap analysis]]
8311:: +golden-types-with-modules fails closed for imports without prelude
12596:: +golden-types-with-modules fails closed for imports without prelude
8312:: scope. +golden-types-with-prelude resolves supported library graphs;
12597:: scope. +golden-types-with-prelude resolves supported library graphs;
@@ -8317,6 +12602,8 @@
8318 =/ parsed (parse file src)
12603 =/ parsed (parse file src)
8319 ?: ?=(%| -.parsed) (show-error src p.parsed)
12604 ?: ?=(%| -.parsed) (show-error src p.parsed)
12605+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12606+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
8320 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
12607 ?: (lien imports.p.parsed |=(i=import ?=(%jibb -.i)))
8321 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
12608 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
8322 (golden-types-with-marks file src externals mark-externals)
12609 (golden-types-with-marks file src externals mark-externals)
@@ -8331,6 +12618,8 @@
8332 =/ parsed (parse file src)
12619 =/ parsed (parse file src)
8333 ?: ?=(%| -.parsed) (show-error src p.parsed)
12620 ?: ?=(%| -.parsed) (show-error src p.parsed)
12621+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12622+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
8334 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
12623 ?: =(0 prelude-source) 'partial inference; module not checked\0aprelude source missing; module import inference unsupported'
8335 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
12624 =/ prelude (parse /lib/jibb/prelude/jibb prelude-source)
8336 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
12625 ?: ?=(%| -.prelude) 'partial inference; module not checked\0aprelude source does not parse; module import inference unsupported'
@@ -8338,16 +12627,26 @@
8338 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
12627 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
8339 (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
12628 (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
12630+++ golden-types-with-prelude-and-internal
12631+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prelude-source=@t internal-source=@t]
12633+ =/ prepared=(unit iprelude) (prepare-prelude-with-internal prelude-source internal-source)
12634+ (golden-types-with-prepared-prelude file src externals mark-externals modules prepared)
8341++ golden-types-with-prepared-prelude
12636++ golden-types-with-prepared-prelude
8342 |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prepared=(unit iprelude)]
12637 |= [file=path src=@t externals=iexternals mark-externals=imark-externals modules=jbundle prepared=(unit iprelude)]
8344 =/ parsed (parse file src)
12639 =/ parsed (parse file src)
8345 ?: ?=(%| -.parsed) (show-error src p.parsed)
12640 ?: ?=(%| -.parsed) (show-error src p.parsed)
12641+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12642+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
8346 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
12643 ?~ prepared 'partial inference; module not checked\0aprelude interface is not supported'
8347 =/ prelude-values=(list term) values.u.prepared
12644 =/ prelude-values=(list term) values.u.prepared
8348 =/ prelude-molds=(list term) molds.u.prepared
12645 =/ prelude-molds=(list term) molds.u.prepared
8349 =/ iface=(unit ifile) `iface.u.prepared
12646 =/ iface=(unit ifile) `iface.u.prepared
8350 ?. (module-scope-valid p.parsed prelude-values prelude-molds)
12647 ?. (module-scope-valid p.parsed prelude-values prelude-molds)
12648+ ?: (pending-declared-poke file p.parsed prelude-values prelude-molds)
12649+ 'partial inference; module not checked\0amodule kind or scope needs unsupported inference'
8351 'partial inference; module not checked\0amodule has conflicting names'
12650 'partial inference; module not checked\0amodule has conflicting names'
8352 =/ js=jimports-result
12651 =/ js=jimports-result
8353 (resolve-jibb-imports imports.p.parsed externals mark-externals modules ~[file] prelude-values prelude-molds ~ iface)
12652 (resolve-jibb-imports imports.p.parsed externals mark-externals modules ~[file] prelude-values prelude-molds ~ iface)
@@ -8388,13 +12687,45 @@
8388 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
12687 =. reserved-molds (weld reserved-molds (turn jimports |=(j=[face=term interface=ifile] face.j)))
8389 =/ parsed (parse file src)
12688 =/ parsed (parse file src)
8390 ?: ?=(%| -.parsed) (show-error src p.parsed)
12689 ?: ?=(%| -.parsed) (show-error src p.parsed)
12690+ =/ duplicate=(unit idiag) (duplicate-defs defs.p.parsed)
12691+ ?^ duplicate (duplicate-fields-report file src u.duplicate)
12692+ ?: (module-has-reserved-proj p.parsed)
12693+ 'module has reserved proj name'
8391 =/ ds=(list def) defs.p.parsed
12694 =/ ds=(list def) defs.p.parsed
8392 =/ molds=imolds (collect-simple-molds ds)
12695 =/ molds=imolds (collect-simple-molds ds)
8393 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
12696 =/ globals=(list term) (weld prelude-values (weld (turn jimports |=(j=[face=term interface=ifile] face.j)) (global-value-names ds)))
8394 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
12697 =/ surs=(list term) (collect-sur-imports imports.p.parsed)
8395 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
12698 =/ marks=(list term) (collect-mark-imports imports.p.parsed)
8396 =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
12699 =/ resolution=iresolved (resolve-groups ds molds globals externals surs mark-externals marks jimports reserved-molds file prelude)
12700+ =/ cycles=(list icycle) (definite-value-cycles ds globals)
8397 =/ env=ienv env.resolution
12701 =/ env=ienv env.resolution
12702+ =/ recovered=(list term) ~
12704+ ?& ?=(~ imports.p.parsed)
12707+ ?=(~ prelude-values)
12708+ ?=(~ reserved-molds)
12709+ !?=([%ui %api *] file)
12710+ !?=([%ui %stores *] file)
12711+ !(lien (global-value-names ds) |=(n=term =(n %main)))
12712+ (module-scope-valid p.parsed ~ ~)
12713+ !(module-values-complete ds env)
12714+ (lte (met 3 src) 65.536)
12715+ (lte (lent ds) 64)
12716+ (dg-source-candidate ds 64)
12718+ =/ transaction=(unit dgcommit) ?:(eligible (dg-root-source file src) ~)
12721+ ?. &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) ~
12722+ (turn (skim env.u.transaction |=(entry=[name=term scheme=ischeme] ?=(~ (ienv-lookup name.entry env)))) |=(entry=[name=term scheme=ischeme] name.entry))
12724+ ?~ transaction env
12725+ ?: &((module-values-complete ds env.u.transaction) (dg-interface-safe env.u.transaction)) env.u.transaction
12727+ =/ source-defs=(map term def) (direct-checked-gates ds env)
12728+ =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude)
8398 =/ lines=(list @t) ~
12729 =/ lines=(list @t) ~
8400 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
12731 ?~ ds (of-wain:format ['partial inference; module not checked' (flop lines)])
@@ -8403,6 +12734,20 @@
8403 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
12734 $(ds t.ds, lines [(show-partial-mold file src d molds) lines])
8404 ?. (unique-value-name name.d globals)
12735 ?. (unique-value-name name.d globals)
8405 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
12736 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
12737+ =/ cycle=(list icycle) (skim cycles |=(c=icycle =(name.c name.d)))
12739+ =/ diag=idiag ["non-gate value depends on itself through a cycle" ~[[first.i.cycle "value in cycle"] [next.i.cycle "dependency in cycle"]]]
12740+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d diag) lines])
12741+ ?: (lien recovered |=(n=term =(n name.d)))
12742+ =/ found=(unit ischeme) (ienv-lookup name.d env)
12743+ ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: committed definition unavailable") lines])
12744+ ?: (itype-has-hidden-recursive typ.u.found)
12745+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive mold name is not available in this scope") lines])
12746+ ?: (itype-has-hidden-generic typ.u.found)
12747+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: generic union name is not available in this scope") lines])
12748+ =/ typ=itype (canonical-itype typ.u.found vars.u.found)
12749+ =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
12750+ $(ds t.ds, lines [line lines])
8406 ?: (lien grouped.resolution |=(n=term =(n name.d)))
12751 ?: (lien grouped.resolution |=(n=term =(n name.d)))
8407 =/ found=(unit ischeme) (ienv-lookup name.d env)
12752 =/ found=(unit ischeme) (ienv-lookup name.d env)
8408 ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
12753 ?~ found $(ds t.ds, lines [(crip "++ {(trip name.d)}: recursive group unavailable") lines])
@@ -8410,7 +12755,9 @@
8410 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
12755 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype typ ~)}{(show-atom-constraint typ)}")
8411 $(ds t.ds, lines [line lines])
12756 $(ds t.ds, lines [line lines])
8412 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
12757 =/ 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]
12758+ =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude ~ 256 ~ ~ ~ ~ ~ ~]
12759+ =. gate-defs.initial source-defs
12760+ =. head-evidence.initial heads
8414 =. initial (reserve-def-caps val.d initial)
12761 =. initial (reserve-def-caps val.d initial)
8415 =/ result=iresult
12762 =/ result=iresult
8416 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
12763 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
@@ -8418,6 +12765,11 @@
8418 (infer-fragment val.d env initial)
12765 (infer-fragment val.d env initial)
8419 ?: ?=(%| -.result)
12766 ?: ?=(%| -.result)
8420 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
12767 $(ds t.ds, lines [(show-inference-diagnostic file src name.d p.result) lines])
12768+ =. state.p.result (promote-restricted-numbers state.p.result env)
12769+ =. 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)))
12770+ =/ hole=(unit idiag) (unresolved-hole holes.state.p.result holes.initial state.p.result)
12772+ $(ds t.ds, lines [(show-inference-diagnostic file src name.d u.hole) lines])
8421 =/ merged=(unit [first=icap second=icap])
12773 =/ merged=(unit [first=icap second=icap])
8422 (merged-capitals caps.state.p.result sub.state.p.result)
12774 (merged-capitals caps.state.p.result sub.state.p.result)
8423 ?^ merged
12775 ?^ merged
@@ -8440,7 +12792,576 @@
8440 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
12792 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
8441 ?: (gth (lent vars) 26)
12793 ?: (gth (lent vars) 26)
8442 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
12794 $(ds t.ds, lines [(crip "++ {(trip name.d)}: too many variables for partial printer") lines])
12795+ ?~ (width-finalize projections.state.p.result sub.state.p.result vars)
12796+ $(ds t.ds, lines [(crip "++ {(trip name.d)}: record projection elaboration needs unsupported inference") lines])
8443 =/ printable=itype (canonical-itype typ vars)
12797 =/ printable=itype (canonical-itype typ vars)
8444 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
12798 =/ line=@t (crip "++ {(trip name.d)}: {(show-itype printable ~)}{(show-atom-constraint printable)}")
8445 $(ds t.ds, lines [line lines])
12799 $(ds t.ds, lines [line lines])
12800+:: Experimental module-owned pending-constraint generalization only.
12801+:: Inputs, IDs and substitution come from one checker-owned transaction.
12802++$ dgscan [ids=(list @ud) fuel=@ud]
12804+ |= [todo=(list itype) sub=isub fuel=@ud ids=(list @ud)]
12806+ ?~ todo `[ids fuel]
12808+ =. fuel (dec fuel)
12810+ ?: ?=(?(%var %avar %rvar %nvar %rnvar %tag) -.t)
12811+ =/ node-id=@ud ?:(?=(%tag -.t) id.t +.t)
12812+ =/ found=(unit itype) (itype-lookup node-id sub)
12813+ ?~ found $(todo t.todo, ids [node-id ids])
12814+ ?: &(?=(?(%rvar %rnvar) -.u.found) =(node-id +.u.found))
12815+ $(todo t.todo, ids [node-id ids])
12816+ $(todo [u.found t.todo])
12817+ ?: ?=(%jrec -.t) $(todo t.todo)
12819+ %collection $(todo (weld args.t t.todo))
12820+ %union $(todo (weld args.t (weld cases.t t.todo)))
12821+ %face $(todo [body.t t.todo])
12822+ %fn $(todo [sample.t product.t t.todo])
12823+ %cell $(todo [hed.t tal.t t.todo])
12824+ %atom $(todo t.todo)
12825+ %any-atom $(todo t.todo)
12826+ %flag $(todo t.todo)
12827+ %noun $(todo t.todo)
12828+ %empty $(todo t.todo)
12829+ %const $(todo t.todo)
12833+ |= [ids=(list @ud) sub=isub fuel=@ud blocked=(list @ud)]
12835+ ?~ ids `[blocked fuel]
12836+ =/ one=(unit dgscan) (dg-scan ~[[%var i.ids]] sub fuel blocked)
12838+ $(ids t.ids, fuel fuel.u.one, blocked ids.u.one)
12841+ |= [env=ienv sub=isub fuel=@ud blocked=(list @ud)]
12843+ ?~ env `[blocked fuel]
12844+ =/ sc=ischeme scheme.i.env
12845+ :: Quantifiers are local to the scheme: first find raw free IDs, then
12846+ :: follow those IDs in the module substitution without capturing them.
12847+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ fuel ~)
12849+ =/ free=(list @ud) (skim ids.u.raw |=(n=@ud !(lien vars.sc |=(q=@ud =(q n)))))
12850+ =/ resolved=(unit dgscan) (dg-scan-ids free sub fuel.u.raw blocked)
12852+ $(env t.env, fuel fuel.u.resolved, blocked ids.u.resolved)
12855+ |= [pending=(list dgo) sub=isub fuel=@ud blocked=(list @ud)]
12857+ ?~ pending `[blocked fuel]
12858+ =/ found=(unit dgscan) (dg-scan ~[left.i.pending right.i.pending] sub fuel blocked)
12860+ $(pending t.pending, fuel fuel.u.found, blocked ids.u.found)
12863+ |= [tags=(list ipending) sub=isub fuel=@ud blocked=(list @ud)]
12865+ ?~ tags `[blocked fuel]
12867+ =/ found=(unit itype) (itype-lookup id.i.tags sub)
12868+ ?~ found $(tags t.tags, fuel (dec fuel), blocked [id.i.tags blocked])
12869+ :: Until this entry is explicitly discharged, retain variables reachable
12870+ :: through its binding; mere existence of a substitution is not proof.
12871+ =/ reached=(unit dgscan) (dg-scan ~[u.found] sub (dec fuel) blocked)
12873+ $(tags t.tags, fuel fuel.u.reached, blocked ids.u.reached)
12876+ |= [typ=itype env=ienv pending=(list dgo) tags=(list ipending) captured=(list @ud) state=istate fuel=@ud]
12878+ :: Bound the obligation list and all graph/substitution walks. The
12879+ :: substitution is assumed checker-owned and occurs-checked.
12880+ ?: (gth (lent pending) 64) ~
12881+ =/ capt=(unit dgscan) (dg-scan-ids captured sub.state fuel ~)
12883+ =/ env-free=(unit dgscan) (dg-env env sub.state fuel.u.capt ids.u.capt)
12885+ =/ obligations=(unit dgscan) (dg-obligations pending sub.state fuel.u.env-free ids.u.env-free)
12887+ =/ tagged=(unit dgscan) (dg-tags tags sub.state fuel.u.obligations ids.u.obligations)
12889+ =/ bounded=(unit dgscan) (dg-scan ~[typ] sub.state fuel.u.tagged ~)
12891+ =/ normalized=itype (itype-normalize typ sub.state)
12892+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
12893+ =/ quantified=(list @ud) (skim vars |=(n=@ud !(lien ids.u.tagged |=(b=@ud =(b n)))))
12894+ `[[normalized quantified]]
12896++$ dgcommit [env=ienv state=istate]
12897+:: A branch literal must not acquire a value face through replay.
12898+++ dg-literal-target-safe
12901+ ?: ?=(%union -.target)
12902+ (levy cases.target |=(c=itype ?=(?(%const %cell) -.c)))
12903+ ?=(?(%const %atom %any-atom %flag %noun) -.target)
12906+ |= [edges=(list dgo) state=istate fuel=@ud]
12910+ =/ trial=ifit (itype-fit left.i.edges right.i.edges sub.state next.state)
12911+ ?. ?=(%ok -.trial) ~
12913+ ?: ?=(%tag -.left.i.edges)
12914+ ?. constructor.left.i.edges
12915+ =/ closed=(unit dgscan) (dg-scan ~[right.i.edges] sub.trial 512 ~)
12918+ (dg-literal-target-safe (itype-normalize right.i.edges sub.trial))
12919+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12920+ =((itype-walk left.i.edges sub.trial) (itype-walk right.i.edges sub.trial))
12922+ $(edges t.edges, state state(sub sub.trial, next next.trial), fuel (dec fuel))
12925+ |= [env=ienv sub=isub fuel=@ud]
12929+ =/ s=ischeme scheme.i.env
12930+ :: Quantified IDs are scheme-local and cannot be rewritten on publication.
12931+ ?. (levy vars.s |=(n=@ud ?=(~ (itype-lookup n sub)))) ~
12932+ =/ bounded=(unit dgscan) (dg-scan ~[typ.s] sub (dec fuel) ~)
12934+ =/ normalized=itype (itype-normalize typ.s sub)
12935+ ?: (itype-has-tag normalized) ~
12936+ =/ vars=(list @ud) (unique-type-vars (itype-vars normalized))
12937+ ?. (levy vars |=(n=@ud (lien vars.s |=(v=@ud =(v n))))) ~
12938+ =/ rest=(unit ienv) (dg-close-env t.env sub fuel.u.bounded)
12940+ `[[name.i.env [normalized vars.s]] u.rest]
12942+:: A deferred boolean branch has exactly the two literal flag patterns.
12943+:: Arms are inferred in order. Equal types are retained; two direct pending
12944+:: literals may instead retain source-owned obligations for later context.
12945+++ dg-boolean-patterns
12948+ ?. ?=(%branch -.e) |
12953+ =/ y=arm i.t.arms.e
12954+ ?. &(?=(%lit -.pat.x) ?=(%lit -.pat.y)) |
12955+ ?. &(=(%loobean form.lit.pat.x) =(%loobean form.lit.pat.y)) |
12956+ !=(val.lit.pat.x val.lit.pat.y)
12957+:: Only a direct source literal which created its own unbound pending tag
12958+:: may create a branch edge. The caller must retain the exact source and state.
12959+++ dg-owned-arm-literal
12960+ |= [e=expr t=itype tags=(list ipending) sub=isub initial=@ud]
12964+ ?: constructor.t |
12965+ ?. =(lit.e literal.t) |
12966+ ?: (lth id.t initial) |
12967+ ?^ (itype-lookup id.t sub) |
12968+ (lien tags |=(x=ipending &(=(id.x id.t) =(literal.x literal.t))))
12969+++ dg-boolean-branch
12970+ |= [e=expr env=ienv state=istate]
12972+ ?. (dg-boolean-patterns e) [%| ["deferred branch patterns need unsupported inference" ~]]
12973+ ?> ?=(%branch -.e)
12977+ =/ y=arm i.t.arms.e
12978+ =/ subject=iresult (infer-fragment subject.e env state)
12979+ ?: ?=(%| -.subject) subject
12980+ =/ su=(unit isub) (itype-unify typ.p.subject [%flag ~] sub.state.p.subject)
12981+ ?~ su [%| ["deferred branch subject does not unify with ?" ~]]
12982+ =/ left=iresult (infer-fragment val.x env state.p.subject(sub u.su))
12983+ ?: ?=(%| -.left) left
12984+ =/ right=iresult (infer-fragment val.y env state.p.left)
12985+ ?: ?=(%| -.right) right
12986+ ?. (dg-stable-fit typ.p.left typ.p.right sub.state.p.right)
12987+ =/ st=istate state.p.right
12988+ ?. (dg-owned-arm-literal val.x typ.p.left tags.st sub.st next.state)
12989+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12990+ ?. (dg-owned-arm-literal val.y typ.p.right tags.st sub.st next.state)
12991+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12992+ ?> ?=(%tag -.typ.p.left)
12993+ ?> ?=(%tag -.typ.p.right)
12994+ ?: =(id.typ.p.left id.typ.p.right)
12995+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12996+ ?: (gth (lent obligations.st) 62)
12997+ [%| ["deferred branch arm context needs unsupported inference" ~]]
12998+ =/ result=itype [%var next.st]
12999+ =/ ex=dgo [typ.p.left result (span-of val.x) (span-of e)]
13000+ =/ ey=dgo [typ.p.right result (span-of val.y) (span-of e)]
13001+ [%& result st(next +(next.st), obligations [ex ey obligations.st])]
13002+ [%& typ.p.left state.p.right]
13004+:: Deferred inference uses only source forms whose successful fit sites are
13005+:: guarded below; a shared source-node budget bounds this screen.
13006+++ dg-safe-expressions
13007+ |= [todo=(list expr) fuel=@ud]
13010+ =/ first=(unit @ud) (dg-safe-expression i.todo fuel)
13012+ $(todo t.todo, fuel u.first)
13013+++ dg-safe-expression
13014+ |= [e=expr fuel=@ud]
13017+ =. fuel (dec fuel)
13019+ ?(%lit %ctor) `fuel
13020+ %wing ?:(?=([@ ~] names.e) `fuel ~)
13022+ ?. (levy pieces.e |=(p=piece ?=(%text -.p))) ~
13024+ %group $(e inner.e, fuel fuel)
13027+ $(e final.e, fuel fuel)
13028+ %gate $(e body.e, fuel fuel)
13029+ %gate-wide $(e body.e, fuel fuel)
13031+ ?. (dg-boolean-patterns e) ~
13034+ =/ subject=(unit @ud) $(e subject.e, fuel fuel)
13036+ (dg-safe-expressions ~[val.i.arms.e val.i.t.arms.e] u.subject)
13037+ %cast $(e val.e, fuel fuel)
13039+ =/ head=(unit @ud) $(e head.e, fuel fuel)
13041+ (dg-safe-expressions args.e u.head)
13043+:: Exact normalized equality is preserved by all later substitutions.
13044+:: The bounded scan declines opaque types and oversized inputs.
13046+ |= [actual=itype expected=itype sub=isub]
13048+ ?~ (dg-scan ~[actual expected] sub 512 ~) |
13049+ =((itype-normalize actual sub) (itype-normalize expected sub))
13051+:: A positional call peels sample-slot faces during its separate face check.
13052+:: Require its argument, sample and result closed so that check stays valid.
13053+++ dg-stable-call-fit
13054+ |= [actual=itype expected=itype product=itype sub=isub positional=?]
13056+ =/ checked=(unit dgscan) (dg-scan ~[actual expected product] sub 512 ~)
13058+ ?: &(positional ?=(^ ids.u.checked)) |
13059+ =((itype-normalize actual sub) (itype-normalize expected sub))
13061+:: One definition attempt retains state only when inference succeeds.
13062++$ dg-step [env=ienv state=istate pending=(list dgo)]
13064+ |= [d=def env=ienv state=istate]
13067+ ?~ (dg-safe-expression val.d 512) ~
13068+ =/ local=istate (reserve-def-caps val.d state)
13069+ :: This first slice declines all written capitals and holes/projections.
13071+ =/ ordinary=iresult (infer-fragment val.d env local)
13072+ ?: ?=(%| -.ordinary) ~
13073+ =/ typ=itype typ.p.ordinary
13074+ =/ after=istate state.p.ordinary
13075+ =/ edges=(list dgo) obligations.after
13076+ ?. =(binders.after binders.state) ~
13077+ ?. =(molds.after molds.state) ~
13078+ ?. =(globals.after globals.state) ~
13079+ ?. =(externals.after externals.state) ~
13080+ ?. =(surs.after surs.state) ~
13081+ ?. =(mark-externals.after mark-externals.state) ~
13082+ ?. =(marks.after marks.state) ~
13083+ ?. =(jimports.after jimports.state) ~
13084+ ?. =(reserved-molds.after reserved-molds.state) ~
13085+ ?. =(params.after params.state) ~
13086+ ?. =(active.after active.state) ~
13087+ ?. =(in-mold.after in-mold.state) ~
13088+ ?. =(at.after at.state) ~
13089+ ?. =(top-molds.after top-molds.state) ~
13090+ ?. =(prelude.after prelude.state) ~
13091+ ?. =(gate-defs.after gate-defs.state) ~
13092+ ?. =(head-evidence.after head-evidence.state) ~
13093+ ?. =(grec-index.after grec-index.state) ~
13094+ ?. =(defer.after defer.state) ~
13095+ ?. =(holes.after holes.state) ~
13096+ ?. =(caps.after caps.state) ~
13097+ ?. =(projections.after projections.state) ~
13098+ ?: (unsupported-atom-vars (itype-normalize typ sub.after) caps.after binders.after sub.after) ~
13099+ ?: (itype-has-nvar (itype-normalize typ sub.after)) ~
13100+ =/ scheme=(unit ischeme) (dg-generalize typ env edges tags.after ~ after 32.768)
13102+ `[[[name.d u.scheme] env] after edges]
13103+:: Retry only definitions that did not infer. Successful definitions are
13104+:: committed into the local transaction, never published until all close.
13106+ |= [ds=(list def) base=ienv env=ienv state=istate pending=(list dgo) fuel=@ud]
13107+ ^- (unit dgcommit)
13108+ ?: (gth fuel 64) ~
13109+ ?: (gth (lent ds) fuel) ~
13110+ =/ remaining=(list def) ds
13111+ =/ waiting=(list def) ~
13113+ =/ attempts=@ud (mul fuel fuel)
13118+ $(remaining (flop waiting), waiting ~, progress |)
13119+ =/ replayed=(unit istate) (dg-replay-edges pending state 64)
13121+ ?: (pending-tags tags.u.replayed sub.u.replayed) ~
13122+ =/ closed-edges=(unit dgscan) (dg-obligations pending sub.u.replayed 32.768 ~)
13124+ ?^ ids.u.closed-edges ~
13125+ =/ rechecked=(unit istate) (dg-replay-edges pending u.replayed 64)
13127+ ?. =(sub.u.rechecked sub.u.replayed) ~
13128+ ?. =(next.u.rechecked next.u.replayed) ~
13129+ =/ closed=(unit ienv) (dg-close-env env sub.u.replayed 32.768)
13131+ `[[u.closed u.replayed(defer ~, obligations ~)]]
13132+ ?: =(0 attempts) ~
13133+ =. attempts (dec attempts)
13134+ =/ d=def i.remaining
13135+ ?: ?=(%mold -.d) $(remaining t.remaining)
13136+ ?^ (ienv-lookup name.d base) $(remaining t.remaining)
13137+ ?^ (ienv-lookup name.d env) ~
13138+ =/ done=(unit dg-step) (dg-stage-one d env state)
13139+ ?~ done $(remaining t.remaining, waiting [d waiting])
13140+ $(remaining t.remaining, env env.u.done, state state.u.done, pending pending.u.done, progress &)
13142+:: Cheap bounded eligibility check on the already parsed source. This
13143+:: deliberately covers only direct constructor calls beneath transparent
13144+:: groups, gates, casts and definition-free bodies. Other shapes decline
13145+:: this fallback without a second parse or resolution pass.
13146+++ dg-direct-source
13147+ |= [e=expr fuel=@ud]
13151+ %group $(e inner.e, fuel (dec fuel))
13152+ %gate $(e body.e, fuel (dec fuel))
13153+ %gate-wide $(e body.e, fuel (dec fuel))
13154+ %cast $(e val.e, fuel (dec fuel))
13155+ %body ?~(defs.e $(e final.e, fuel (dec fuel)) |)
13157+ ?. ?=([* ~] args.e) |
13158+ ?=(%ctor -.i.args.e)
13160+++ dg-source-candidate
13161+ |= [ds=(list def) fuel=@ud]
13165+ ?. ?=(%value -.i.ds) $(ds t.ds, fuel (dec fuel))
13166+ ?: (dg-direct-source val.i.ds 64) &
13167+ $(ds t.ds, fuel (dec fuel))
13169+++ dg-interface-safe
13173+ =/ sc=ischeme scheme.i.env
13174+ ?: |((itype-has-hidden-recursive typ.sc) (itype-has-hidden-generic typ.sc)) |
13175+ ?: (gth (lent vars.sc) 26) |
13177+:: Parse status and the transaction result come from the same source parse.
13178++$ dgparse [parsed=? result=(unit dgcommit)]
13180+ |= [at=path src=@t]
13181+ ^- (unit dgcommit)
13182+ result:(dg-root-detail at src)
13184+ |= [at=path src=@t]
13186+ =/ parsed (parse at src)
13187+ ?: ?=(%| -.parsed) [| ~]
13190+ ?^ imports.p.parsed ~
13191+ ?. (module-scope-valid p.parsed ~ ~) ~
13192+ ?^ (duplicate-defs defs.p.parsed) ~
13193+ =/ defs=(list def) defs.p.parsed
13194+ ?: (gth (lent defs) 64) ~
13195+ =/ molds=imolds (collect-simple-molds defs)
13196+ =/ globals=(list term) (global-value-names defs)
13197+ =/ resolution=iresolved (resolve-groups defs molds globals ~ ~ ~ ~ ~ ~ at ~)
13198+ ?^ grouped.resolution ~
13199+ ?^ artifacts.resolution ~
13200+ =/ base=ienv env.resolution
13201+ =/ free=(unit dgscan) (dg-env base ~ 32.768 ~)
13204+ =/ all=(unit dgscan) (dg-all-env-ids base 32.768 ~)
13206+ =/ fresh=@ud (dg-next-id ids.u.all 0)
13207+ =/ st=istate *istate
13208+ =. st st(next fresh, defer `~, molds molds, globals globals, at at, top-molds (turn molds |=(m=[name=term body=shape] name.m)), in-mold |, jrec-fuel 256)
13209+ =/ checked-molds=(each imold-types @t) (module-mold-types molds st)
13210+ ?: ?=(%| -.checked-molds) ~
13211+ (dg-stage defs base base st ~ 64)
13215+ |= [env=ienv fuel=@ud ids=(list @ud)]
13217+ ?~ env `[ids fuel]
13219+ =/ sc=ischeme scheme.i.env
13220+ ?: (itype-has-tag typ.sc) ~
13221+ =/ raw=(unit dgscan) (dg-scan ~[typ.sc] ~ (dec fuel) ids)
13223+ =/ quant=(unit dgscan) (dg-scan-ids vars.sc ~ fuel.u.raw ids.u.raw)
13225+ $(env t.env, fuel fuel.u.quant, ids ids.u.quant)
13228+ |= [ids=(list @ud) largest=@ud]
13231+ $(ids t.ids, largest (max largest i.ids))
13233+++ dg-eligible-ctor
13234+ |= [e=expr head=itype actual=itype expected=itype state=istate]
13236+ ?. ?=(%call -.e) ~
13237+ ?. ?=([* ~] args.e) ~
13238+ ?. ?=(%ctor -.i.args.e) ~
13239+ ?. ?=(%fn -.head) ~
13240+ ?. ?=(%fn -.expected) ~
13241+ ?. ?=(%tag -.actual) ~
13242+ ?. constructor.actual ~
13243+ ?. ?=(%var -.product.expected) ~
13244+ ?^ (itype-lookup id.product.expected sub.state) ~
13245+ =/ bounded=(unit dgscan) (dg-scan ~[sample.expected] sub.state 256 ~)
13247+ ?^ ids.u.bounded ~
13248+ `[[actual expected (span-of i.args.e) (span-of head.e)]]
13250+:: Experimental per-module, source-derived recursive tree index.
13251+:: The two tags and the exact children/list/self layout are fixed-shape
13252+:: checks, so ordinary definitions incur no type-tree or source scans.
13253+++ grec-tagged-fields
13255+ ^- (unit [tag=@ fields=(list field)])
13256+ ?. ?=(%cell -.sh) ~
13258+ =/ head=field i.fields.sh
13259+ ?. ?=(%bare -.head) ~
13260+ ?. ?=(%const -.shape.head) ~
13261+ ?. &(?=(%term form.lit.shape.head) =(%tas aura.lit.shape.head)) ~
13262+ `[val.lit.shape.head t.fields.sh]
13263+++ grec-tree-children
13264+ |= [fs=(list field) param=@t]
13269+ =/ event=field i.fs
13270+ =/ kids=field i.t.fs
13271+ ?. &(?=(%face -.event) ?=(%face -.kids)) ~
13272+ ?. !=(name.event name.kids) ~
13273+ ?. ?=(%fn -.shape.event) ~
13274+ ?. ?=(%aura -.sample.shape.event) ~
13275+ ?. =(%t aura.sample.shape.event) ~
13276+ ?. ?=(%tvar -.product.shape.event) ~
13277+ ?. =(param name.product.shape.event) ~
13281+ |= [name=term sh=shape]
13283+ ?. ?=(%generic -.sh) |
13284+ ?. ?=([@ ~] vars.sh) |
13285+ =/ param=@t i.vars.sh
13286+ ?. ?=(%union -.body.sh) |
13287+ ?. ?=([* [* ~]] cases.body.sh) |
13288+ =/ a=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.cases.body.sh)
13289+ =/ b=(unit [tag=@ fields=(list field)]) (grec-tagged-fields i.t.cases.body.sh)
13292+ ?. !=(tag.u.a tag.u.b) |
13293+ ?. ?=([* ~] fields.u.a) |
13294+ =/ value=field i.fields.u.a
13295+ ?. ?=(%face -.value) |
13296+ ?. ?=(%aura -.shape.value) |
13297+ ?. =(%t aura.shape.value) |
13298+ =/ selected=(unit field) (grec-tree-children fields.u.b param)
13300+ =/ kids=field u.selected
13301+ ?. ?=(%face -.kids) |
13302+ ?. ?=(%apply -.shape.kids) |
13303+ ?. =(ref.shape.kids ~[%list]) |
13304+ ?. ?=([* ~] args.shape.kids) |
13305+ =/ self=shape i.args.shape.kids
13306+ ?. ?=(%apply -.self) |
13307+ ?. =(ref.self ~[name]) |
13308+ ?. ?=([* ~] args.self) |
13309+ ?. ?=(%tvar -.i.args.self) |
13310+ =(name.i.args.self param)
13311++$ grec-collected [molds=imolds proofs=(map term shape)]
13312+:: Experimental one-layer analysis view, never an exported mold identity.
13313+++ grec-unfold-view
13314+ |= [typ=itype fuel=@ud]
13315+ ^- (unit [view=itype left=@ud])
13316+ ?. ?=(%grec -.typ) ~
13318+ ?. ?=([* ~] args.typ) ~
13319+ =/ sh=shape proof.typ
13320+ ?. (grec-tree-proof name.typ sh) ~
13321+ ?> ?=(%generic -.sh)
13322+ ?> ?=([@ ~] vars.sh)
13323+ ?> ?=(%union -.body.sh)
13324+ ?> ?=([* [* ~]] cases.body.sh)
13325+ =/ ca=shape i.cases.body.sh
13326+ =/ cb=shape i.t.cases.body.sh
13329+ ?> ?=([* [* ~]] fields.ca)
13330+ ?> ?=([* *] fields.cb)
13331+ =/ tag-a=field i.fields.ca
13332+ =/ tag-b=field i.fields.cb
13333+ ?> ?=(%bare -.tag-a)
13334+ ?> ?=(%bare -.tag-b)
13335+ ?> ?=(%const -.shape.tag-a)
13336+ ?> ?=(%const -.shape.tag-b)
13337+ =/ text-field=field i.t.fields.ca
13338+ ?> ?=(%face -.text-field)
13339+ =/ branch=(list field) t.fields.cb
13340+ =/ kids=(unit field) (grec-tree-children branch i.vars.sh)
13342+ ?> ?=(%face -.u.kids)
13343+ =/ children=itype [%face name.u.kids [%collection %list ~[typ]]]
13346+ ?~ t.branch children
13347+ =/ event=field i.branch
13348+ ?> ?=(%face -.event)
13349+ [%cell [%face name.event [%fn [%atom %t] i.args.typ]] children]
13350+ =/ leaf=itype [%cell [%const lit.shape.tag-a] [%face name.text-field [%atom %t]]]
13351+ =/ node=itype [%cell [%const lit.shape.tag-b] payload]
13352+ `[[%union ~[leaf node] ~ ~ ~] (dec fuel)]
13354+++ grec-collect-molds
13357+ ?~ ds [~ *(map term shape)]
13358+ =/ rest=grec-collected $(ds t.ds)
13359+ ?. ?=(%mold -.i.ds) rest
13360+ =/ name=term name.i.ds
13361+ =/ body=shape shape.i.ds
13362+ =/ proofs=(map term shape) proofs.rest
13363+ =? proofs (grec-tree-proof name body) (~(put by proofs) name body)
13364+ [[[name body] molds.rest] proofs]