@@ -5839,6 +5839,51 @@
58395839 ?: ?=(^ (itype-vars typ.u.out)) ~
58405840 `[[typ.u.out ~] state.u.out(params params.state, in-mold in-mold.state)]
58415841::
5842+:: A direct imported reference may carry definite reader evidence. Only
5843+:: uniquely supplied, declared inputs are used; unsupported data stay generic.
5844+++ direct-import-invalid
5845+ |= [sh=shape state=istate]
5846+ ^- (unit idiag)
5847+ ?. ?=(%ref -.sh) ~
5848+ ?~ names.sh ~
5849+ =/ n=term i.names.sh
5850+ =/ raw=*
5851+ ?~ t.names.sh
5852+ ?. (unique-value-name n marks.state) ~
5853+ ?: (lien surs.state |=(x=term =(x n))) ~
5854+ ?: ?=(^ (find-jibb-interface n jimports.state)) ~
5855+ ?: (lien globals.state |=(x=term =(x n))) ~
5856+ ?: (lien reserved-molds.state |=(x=term =(x n))) ~
5857+ ?: (lien molds.state |=(m=[name=term body=shape] =(n name.m))) ~
5858+ =/ found=imark-externals (skim mark-externals.state |=(e=[mark=term result=*] =(mark.e n)))
5859+ ?~ found ~
5860+ ?^ t.found ~
5861+ result.i.found
5862+ ?^ t.t.names.sh ~
5863+ =/ mod=term i.t.names.sh
5864+ ?: ?=(^ (find-jibb-interface mod jimports.state)) ~
5865+ ?. (unique-value-name mod surs.state) ~
5866+ ?: (lien marks.state |=(x=term =(x mod))) ~
5867+ ?: (lien globals.state |=(x=term =(x mod))) ~
5868+ ?: (lien reserved-molds.state |=(x=term =(x mod))) ~
5869+ ?: (lien molds.state |=(m=[name=term body=shape] =(mod name.m))) ~
5870+ =/ found=iexternals (skim externals.state |=(e=[module=term name=term result=*] &(=(module.e mod) =(name.e n))))
5871+ ?~ found ~
5872+ ?^ t.found ~
5873+ result.i.found
5874+ ?. ?=([%invalid ?(%aura %core) @] raw) ~
5875+ `["{(trip +>.raw)}" ~[[at.sh "invalid imported mold"]]]
5876+::
5877+++ direct-sample-invalid
5878+ |= [s=sample state=istate]
5879+ ^- (unit idiag)
5880+ ?- s
5881+ [%face *] (direct-import-invalid shape.s state)
5882+ [%bare *] (direct-import-invalid shape.s state)
5883+ [%pun *] (direct-import-invalid [%ref at.s ~[name.s]] state)
5884+ * ~
5885+ ==
5886+::
58425887++ infer-simple-shape
58435888 |= [sh=shape state=istate]
58445889 ^- (unit [typ=itype state=istate])
@@ -6086,6 +6131,145 @@
60866131 ?~ inferred |
60876132 $(locals t.locals)
60886133::
6134+:: Gather written capitals belonging to one ++. Nested local definitions
6135+:: establish their own scopes; inline gates remain in the enclosing scope.
6136++$ icap-site [name=@t at=span]
6137+++ scope-shape
6138+ |= s=shape
6139+ ^- (list icap-site)
6140+ ?- -.s
6141+ %tvar ~[[name.s at.s]]
6142+ %apply (zing (turn args.s scope-shape))
6143+ %cell (zing (turn fields.s scope-field))
6144+ %union (zing (turn cases.s scope-shape))
6145+ %fn (weld (scope-shape sample.s) (scope-shape product.s))
6146+ %generic
6147+ =/ inside=(list icap-site) (scope-shape body.s)
6148+ (skim inside |=(site=icap-site !(lien vars.s |=(v=@t =(v name.site)))))
6149+ * ~
6150+ ==
6151+::
6152+++ scope-field
6153+ |= f=field
6154+ ^- (list icap-site)
6155+ ?- -.f
6156+ %face (scope-shape shape.f)
6157+ %bare (scope-shape shape.f)
6158+ %pun ~
6159+ ==
6160+::
6161+++ scope-sample
6162+ |= s=sample
6163+ ^- (list icap-site)
6164+ ?- -.s
6165+ %face (scope-shape shape.s)
6166+ %bare (scope-shape shape.s)
6167+ %cell (zing (turn items.s scope-sample))
6168+ * ~
6169+ ==
6170+::
6171+++ scope-pieces
6172+ |= ps=(list piece)
6173+ ^- (list icap-site)
6174+ ?~ ps ~
6175+ =/ first=(list icap-site)
6176+ ?- -.i.ps
6177+ %expr (scope-expr p.i.ps)
6178+ %text ~
6179+ ==
6180+ (weld first $(ps t.ps))
6181+::
6182+++ scope-qsegs
6183+ |= ps=(list qseg)
6184+ ^- (list icap-site)
6185+ ?~ ps ~
6186+ =/ first=(list icap-site)
6187+ ?- -.i.ps
6188+ %expr (scope-expr p.i.ps)
6189+ %knot ~
6190+ ==
6191+ (weld first $(ps t.ps))
6192+::
6193+++ scope-edits
6194+ |= xs=(list edit)
6195+ ^- (list icap-site)
6196+ ?~ xs ~
6197+ =/ first=(list icap-site) (scope-expr val.i.xs)
6198+ (weld first $(xs t.xs))
6199+::
6200+++ scope-items
6201+ |= xs=(list item)
6202+ ^- (list icap-site)
6203+ ?~ xs ~
6204+ =/ first=(list icap-site) (scope-expr val.i.xs)
6205+ (weld first $(xs t.xs))
6206+::
6207+++ scope-arms
6208+ |= xs=(list arm)
6209+ ^- (list icap-site)
6210+ ?~ xs ~
6211+ =/ first=(list icap-site) (scope-expr val.i.xs)
6212+ (weld first $(xs t.xs))
6213+::
6214+++ scope-exprs
6215+ |= xs=(list expr)
6216+ ^- (list icap-site)
6217+ ?~ xs ~
6218+ =/ first=(list icap-site) (scope-expr i.xs)
6219+ (weld first $(xs t.xs))
6220+::
6221+++ scope-expr
6222+ |= e=expr
6223+ ^- (list icap-site)
6224+ ?- -.e
6225+ %str (scope-pieces pieces.e)
6226+ %qath (scope-qsegs segs.e)
6227+ %change (scope-edits edits.e)
6228+ %pair (scope-expr val.e)
6229+ %unit (scope-expr val.e)
6230+ %group (scope-expr inner.e)
6231+ %list (scope-exprs items.e)
6232+ %tuple (scope-items items.e)
6233+ %gate
6234+ =/ first=(list icap-site) (scope-sample sample.e)
6235+ =/ last=(list icap-site) (scope-expr body.e)
6236+ (weld first last)
6237+ %gate-wide
6238+ =/ first=(list icap-site) (scope-sample sample.e)
6239+ =/ last=(list icap-site) (scope-expr body.e)
6240+ (weld first last)
6241+ %call
6242+ =/ first=(list icap-site) (scope-expr head.e)
6243+ =/ last=(list icap-site) (scope-exprs args.e)
6244+ (weld first last)
6245+ %cast
6246+ =/ first=(list icap-site) (scope-shape shape.e)
6247+ =/ last=(list icap-site) (scope-expr val.e)
6248+ (weld first last)
6249+ %trace
6250+ =/ first=(list icap-site) (scope-expr val.e)
6251+ =/ last=(list icap-site) (scope-expr then.e)
6252+ (weld first last)
6253+ %branch
6254+ =/ first=(list icap-site) (scope-expr subject.e)
6255+ =/ last=(list icap-site) (scope-arms arms.e)
6256+ (weld first last)
6257+ %body (scope-expr final.e)
6258+ * ~
6259+ ==
6260+::
6261+++ reserve-cap-sites
6262+ |= [sites=(list icap-site) state=istate]
6263+ ^- istate
6264+ ?~ sites state
6265+ ?: ?=(^ (icap-lookup name.i.sites caps.state)) $(sites t.sites)
6266+ $(sites t.sites, state state(next +(next.state), caps [[name.i.sites next.state at.i.sites] caps.state]))
6267+::
6268+++ reserve-def-caps
6269+ |= [e=expr state=istate]
6270+ ^- istate
6271+ (reserve-cap-sites (scope-expr e) state)
6272+::
60896273++ infer-local-defs
60906274 |= [ds=(list def) env=ienv state=istate]
60916275 ^- ilocal-result
@@ -6098,24 +6282,27 @@
60986282 $(ds (flop remaining), remaining ~, progressed |)
60996283 =/ d=def i.ds
61006284 ?> ?=(%value -.d)
6101− =/ inferred=iresult (infer-fragment val.d env state)
6285+ =/ local-state=istate (reserve-def-caps val.d state)
6286+ =/ inferred=iresult (infer-fragment val.d env local-state)
61026287 =/ retried=? ?=(%| -.inferred)
6103− =? inferred retried (infer-recursive-gate d env state)
6288+ =? inferred retried (infer-recursive-gate d env local-state)
61046289 ?: ?=(%| -.inferred) $(ds t.ds, remaining [d remaining])
6105− :: A new local capital needs lexical scope collection before it can be
6106− :: generalized independently or shared with a later enclosing occurrence.
6107− ?. (levy caps.state.p.inferred |=(cap=icap ?=(^ (icap-lookup name.cap caps.state))))
6108− $(ds t.ds, remaining [d remaining])
6290+ =/ merged=(unit [first=icap second=icap])
6291+ (merged-capitals caps.state.p.inferred sub.state.p.inferred)
6292+ ?^ merged
6293+ [%| ["distinct type variables `{(trip name.first.u.merged)}` and `{(trip name.second.u.merged)}` must not be forced equal; use the same capital for a shared type" ~[[at.first.u.merged "first type variable"] [at.second.u.merged "second type variable"]]]]
6294+ ?: (constrained-capitals caps.state.p.inferred sub.state.p.inferred)
6295+ [%| ["explicit capital constraints are not supported by partial inference" ~]]
61096296 =/ typ=itype (itype-normalize typ.p.inferred sub.state.p.inferred)
61106297 ?: |((pending-tags tags.state.p.inferred sub.state.p.inferred) (itype-has-tag typ))
61116298 $(ds t.ds, remaining [d remaining])
61126299 ?: (unsupported-atom-vars typ caps.state.p.inferred binders.state.p.inferred sub.state.p.inferred)
61136300 $(ds t.ds, remaining [d remaining])
61146301 =/ free=(list @ud)
6115− (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state.p.inferred sub.state.p.inferred))
6302+ (weld (free-env-vars env sub.state.p.inferred) (free-cap-vars caps.state sub.state.p.inferred))
61166303 =/ vars=(list @ud) (unique-type-vars (itype-vars typ))
61176304 =. vars (skim vars |=(n=@ud !(lien free |=(f=@ud =(f n)))))
6118− $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred, progressed &)
6305+ $(ds t.ds, env [[name.d [typ vars]] env], state state.p.inferred(caps caps.state), progressed &)
61196306::
61206307:: Read only fields of a known record. Unresolved field constraints and
61216308:: ambiguous repeated faces are outside this fragment. Imported record
@@ -6540,7 +6727,10 @@
65406727 [%& typ.p.left state.p.right(sub u.joined)]
65416728 %cast
65426729 =/ target=(unit [typ=itype state=istate]) (infer-simple-shape shape.e state)
6543− ?~ target [%| ["cast mold is not supported by partial inference" ~]]
6730+ ?~ target
6731+ =/ diag=(unit idiag) (direct-import-invalid shape.e state)
6732+ ?^ diag [%| u.diag]
6733+ [%| ["cast mold is not supported by partial inference" ~]]
65446734 =/ value=iresult
65456735 ?: &(?=(%union -.typ.u.target) (context-union-branch val.e))
65466736 (infer-union-context val.e typ.u.target env state.u.target at.shape.e)
@@ -6559,13 +6749,19 @@
65596749 %crash [%& [%var next.state] state(next +(next.state))]
65606750 %gate
65616751 =/ sam=isample-result (infer-sample sample.e env state)
6562− ?: ?=(%| -.sam) [%| [p.sam ~]]
6752+ ?: ?=(%| -.sam)
6753+ =/ diag=(unit idiag) (direct-sample-invalid sample.e state)
6754+ ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
6755+ [%| [p.sam ~]]
65636756 =/ body=iresult $(e body.e, env env.p.sam, state state.p.sam)
65646757 ?: ?=(%| -.body) body
65656758 [%& [%fn typ.p.sam typ.p.body] state.p.body]
65666759 %gate-wide
65676760 =/ sam=isample-result (infer-sample sample.e env state)
6568− ?: ?=(%| -.sam) [%| [p.sam ~]]
6761+ ?: ?=(%| -.sam)
6762+ =/ diag=(unit idiag) (direct-sample-invalid sample.e state)
6763+ ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
6764+ [%| [p.sam ~]]
65696765 =/ body=iresult $(e body.e, env env.p.sam, state state.p.sam)
65706766 ?: ?=(%| -.body) body
65716767 [%& [%fn typ.p.sam typ.p.body] state.p.body]
@@ -7042,7 +7238,15 @@
70427238 %gate-wide (infer-sample sample.gate env state)
70437239 * !!
70447240 ==
7045− ?: ?=(%| -.sam) [%| [p.sam ~]]
7241+ ?: ?=(%| -.sam)
7242+ =/ diag=(unit idiag)
7243+ ?- -.gate
7244+ %gate (direct-sample-invalid sample.gate state)
7245+ %gate-wide (direct-sample-invalid sample.gate state)
7246+ * ~
7247+ ==
7248+ ?: &(=(p.sam "sample mold is not supported by partial inference") ?=(^ diag)) [%| u.diag]
7249+ [%| [p.sam ~]]
70467250 =/ id=@ud next.state.p.sam
70477251 =/ product=itype ?~(result [%var id] u.result)
70487252 =/ st=istate state.p.sam(next +(id))
@@ -7070,6 +7274,7 @@
70707274 ?^ (ienv-lookup name.d env) $(ds t.ds)
70717275 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
70727276 =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | at top prelude]
7277+ =. initial (reserve-def-caps val.d initial)
70737278 =/ result=iresult (infer-fragment val.d env initial)
70747279 =? result ?=(%| -.result) (infer-recursive-gate d env initial)
70757280 ?: ?=(%| -.result) $(ds t.ds)
@@ -7541,6 +7746,23 @@
75417746:: entries, as [mark result] with the result from +read-mark:jibb-import.
75427747:: Unknown, duplicated, failed and undeclared entries never resolve a mold.
75437748::
7749+:: Callers pass unchanged structured reader results; graph validation
7750+:: remains in the existing bridge, and failures stay available lazily.
7751+++ reader-result-for-checker
7752+ |= result=*
7753+ ^- *
7754+ ?: ?=([%ok *] result) [%& +.result]
7755+ result
7756+::
7757+++ golden-types-with-reader-diagnostics
7758+ |= [file=path src=@t externals=iexternals mark-externals=imark-externals]
7759+ ^- @t
7760+ =/ ex=iexternals
7761+ (turn externals |=(e=[module=term name=term result=*] [module.e name.e (reader-result-for-checker result.e)]))
7762+ =/ mx=imark-externals
7763+ (turn mark-externals |=(e=[mark=term result=*] [mark.e (reader-result-for-checker result.e)]))
7764+ (golden-types-with-marks file src ex mx)
7765+::
75447766++ golden-types-with-marks
75457767 |= [file=path src=@t externals=iexternals mark-externals=imark-externals]
75467768 ^- @t
@@ -7568,6 +7790,7 @@
75687790 $(ds t.ds, lines [(crip "++ {(trip name.d)}: name already in scope") lines])
75697791 =/ top=(list term) (turn molds |=(m=[name=term body=shape] name.m))
75707792 =/ initial=istate [0 ~ ~ ~ molds globals externals surs mark-externals marks jimports reserved-molds ~ ~ ~ | file top prelude]
7793+ =. initial (reserve-def-caps val.d initial)
75717794 =/ result=iresult
75727795 ?: |(?=(%gate -.val.d) ?=(%gate-wide -.val.d))
75737796 (infer-recursive-gate d env initial)