@@ -13338,21 +13338,6 @@
13338 %body ?~(defs.e $(e final.e) e)
13338 %body ?~(defs.e $(e final.e) e)
13341−++ program-init-tuple-null
13344− ?. ?=(%value -.d) |
13345− ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) |
13349− %gate-wide body.val.d
13352− =. body (program-transparent body)
13353− ?. ?=(%tuple -.body) |
13355− (program-empty-null val:(rear items.body))
13357:: Recover only the update of an already recognized direct program main.
13342:: Recover only the update of an already recognized direct program main.
13358:: Its written sample determines the message/model relationship; the canonical
13343:: Its written sample determines the message/model relationship; the canonical
@@ -14169,21 +14154,89 @@
14169 ?. ?=(~ (itype-vars typ.u.recovered)) ~
14154 ?. ?=(~ (itype-vars typ.u.recovered)) ~
14170 `[env.u.added grouped.resolution artifacts.u.added]
14155 `[env.u.added grouped.resolution artifacts.u.added]
14172−++ program-init-null-sample
14157+:: The model a direct program's initializer must produce. Update's written
14173− |= d=def
14158+:: two-item sample gives it when it can be read. Otherwise main's own program
14174− ^- ?
14159+:: fit does: update, view and subs are fitted together against the prelude
14175− =/ written=(unit sample) (direct-gate-sample d)
14160+:: program's sample, as main's call will fit them, with the initializer an
14176− ?~ written |
14161+:: open variable. Only the initializer's data may stay open, a replay of the
14177− ?. ?=(%bare -.u.written) |
14162+:: fit must not move, and the model must come out closed and tag-free.
14178− =/ sh=shape shape.u.written
14163+++ program-init-model
14179− ?. ?=(%const -.sh) |
14164+ |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) env=ienv program=ischeme program-def=def initial=istate]
14180− =(%null form.lit.sh)
14165+ ^- (unit itype)
14181−::
14166+ =/ relation=(unit [message=itype model=itype])
14182−:: The tuple-ending-null initializer retry above intentionally keeps its own
14167+ (program-update-relation update.parts ds env)
14183−:: boundary. A direct null-sample initializer can instead receive the closed
14168+ ?^ relation `model.u.relation
14184−:: model already established by update, view and subscriptions.
14169+ =/ args=(unit (list expr)) (program-main-args main)
14171+ =/ written=(unit sample) (direct-gate-sample program-def)
14173+ ?. ?=(%cell -.u.written) ~
14174+ ?~ items.u.written ~
14175+ =/ update=(unit ischeme) (ienv-lookup update.parts env)
14176+ =/ view=(unit ischeme) (ienv-lookup view.parts env)
14177+ =/ subs=(unit ischeme) (ienv-lookup subs.parts env)
14181+ =/ instance=[typ=itype state=istate] (instantiate-scheme program initial)
14182+ ?. ?=(%fn -.typ.instance) ~
14183+ ?. ?=(%cell -.sample.typ.instance) ~
14184+ =/ expected-init=(unit itype)
14185+ (direct-slot-body hed.sample.typ.instance (direct-sample-name i.items.u.written))
14186+ ?~ expected-init ~
14187+ ?. ?=(%fn -.u.expected-init) ~
14188+ ?. ?=(%var -.sample.u.expected-init) ~
14189+ =/ data=@ud id.sample.u.expected-init
14190+ =/ init-var=itype [%var next.state.instance]
14191+ =/ up=[typ=itype state=istate]
14192+ (instantiate-scheme u.update state.instance(next +(next.state.instance)))
14193+ =/ vw=[typ=itype state=istate] (instantiate-scheme u.view state.up)
14194+ =/ sb=[typ=itype state=istate] (instantiate-scheme u.subs state.vw)
14195+ =/ st=istate state.sb
14196+ =/ actual=itype [%cell init-var [%cell typ.up [%cell typ.vw typ.sb]]]
14198+ (direct-positional-fit u.args items.u.written actual sample.typ.instance env st sub.st next.st)
14199+ ?. ?=(%ok -.fit) ~
14200+ =/ actual-final=itype (itype-normalize actual sub.fit)
14201+ =/ expected-final=itype (itype-normalize sample.typ.instance sub.fit)
14202+ =/ open=(list @ud)
14203+ (unique-type-vars (weld (itype-vars actual-final) (itype-vars expected-final)))
14204+ ?. (levy open |=(n=@ud =(data n))) ~
14205+ ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
14207+ (direct-positional-fit u.args items.u.written actual sample.typ.instance env st sub.fit next.fit)
14208+ ?. ?=(%ok -.replay) ~
14209+ ?. &(=(sub.fit sub.replay) =(next.fit next.replay)) ~
14210+ =/ expected=itype (itype-normalize u.expected-init sub.fit)
14211+ ?. ?=(%fn -.expected) ~
14212+ ?^ (itype-vars product.expected) ~
14215+:: The product of an initializer inferred ordinarily, as a whole gate with no
14216+:: expected type, for a body that context inference cannot take, such as a
14217+:: branch over a nested call's union. Its sample must fit the written one.
14218+++ program-init-ordinary
14219+ |= [init-def=def env=ienv sample=itype state=istate]
14221+ ?> ?=(%value -.init-def)
14222+ =/ gate=iresult (infer-fragment val.init-def env state)
14223+ =? gate ?=(%| -.gate) (infer-recursive-gate init-def env state)
14224+ ?: ?=(%| -.gate) gate
14225+ ?. ?=(%fn -.typ.p.gate) [%| ["initializer is not a gate" ~]]
14227+ (itype-fit sample.typ.p.gate sample sub.state.p.gate next.state.p.gate)
14228+ ?. ?=(%ok -.fit) [%| ["initializer sample differs" ~]]
14229+ [%& product.typ.p.gate state.p.gate(sub sub.fit, next next.fit)]
14231+:: Recover a direct program's initializer once update, view and
14232+:: subscriptions are resolved: its body is inferred against their closed
14233+:: model (+program-init-model), under its own closed written sample. This one
14234+:: path replaced a separate retry for bodies ending in null and a gate that
14235+:: took only a null sample, so any body and any closed sample check the same
14236+:: way (review question 8). The fresh ordinary main inference afterwards
14237+:: checks that all four components agree.
14185++ program-plain-init-context
14238++ program-plain-init-context
14186− |= [parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
14239+ |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
14187 ^- (unit iresolved)
14240 ^- (unit iresolved)
14188 =/ env=ienv env.resolution
14241 =/ env=ienv env.resolution
14189 ?^ (ienv-lookup %main env) ~
14242 ?^ (ienv-lookup %main env) ~
@@ -14191,15 +14244,11 @@
14191 ?~ (ienv-lookup update.parts env) ~
14244 ?~ (ienv-lookup update.parts env) ~
14192 ?~ (ienv-lookup view.parts env) ~
14245 ?~ (ienv-lookup view.parts env) ~
14193 ?~ (ienv-lookup subs.parts env) ~
14246 ?~ (ienv-lookup subs.parts env) ~
14194− =/ relation=(unit [message=itype model=itype])
14195− (program-update-relation update.parts ds env)
14197 =/ inits=(list def)
14247 =/ inits=(list def)
14198 (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
14248 (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
14199 ?. ?=([* ~] inits) ~
14249 ?. ?=([* ~] inits) ~
14200 =/ init-def=def i.inits
14250 =/ init-def=def i.inits
14201 ?> ?=(%value -.init-def)
14251 ?> ?=(%value -.init-def)
14202− ?. (program-init-null-sample init-def) ~
14203 =/ written=(unit sample) (direct-gate-sample init-def)
14252 =/ written=(unit sample) (direct-gate-sample init-def)
14204 ?~ written ~
14253 ?~ written ~
14205 =/ body=expr
14254 =/ body=expr
@@ -14209,10 +14258,12 @@
14211 ?~ prelude.initial ~
14260 ?~ prelude.initial ~
14212− ?~ (ienv-lookup %program values.u.prelude.initial) ~
14261+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
14213 =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
14263 =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
14214 ?~ heads ~
14264 ?~ heads ~
14215− ?~ (~(get by gates.u.heads) %program) ~
14265+ =/ program-def=(unit def) (~(get by gates.u.heads) %program)
14216 =/ checked=(map term def) (direct-checked-gates ds env)
14267 =/ checked=(map term def) (direct-checked-gates ds env)
14217 =/ templates=ienv
14268 =/ templates=ienv
14218 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14269 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
@@ -14220,130 +14271,31 @@
14220 (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14271 (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14221 ?~ fresh ~
14272 ?~ fresh ~
14222 =. next.initial u.fresh
14273 =. next.initial u.fresh
14274+ =/ model=(unit itype)
14275+ %: program-init-model
14276+ main parts ds env u.program u.program-def
14277+ initial(gate-defs checked, head-evidence heads)
14223 =/ init-state=istate (reserve-def-caps val.init-def initial)
14280 =/ init-state=istate (reserve-def-caps val.init-def initial)
14224 =/ sam=isample-result (infer-sample u.written env init-state)
14281 =/ sam=isample-result (infer-sample u.written env init-state)
14225 ?: ?=(%| -.sam) ~
14282 ?: ?=(%| -.sam) ~
14226 ?. ?=(~ (itype-vars typ.p.sam)) ~
14283 ?. ?=(~ (itype-vars typ.p.sam)) ~
14227 ?: (itype-has-tag typ.p.sam) ~
14284 ?: (itype-has-tag typ.p.sam) ~
14228 =/ st=istate state.p.sam(gate-defs checked, head-evidence heads)
14285 =/ st=istate state.p.sam(gate-defs checked, head-evidence heads)
14286+ =/ contextual=iresult
14287+ (infer-call-context-arg body u.model env.p.sam st (span-of body))
14229 =/ inferred=iresult
14288 =/ inferred=iresult
14230− (infer-call-context-arg body model.u.relation env.p.sam st (span-of body))
14289+ ?: ?=(%& -.contextual) contextual
14290+ (program-init-ordinary init-def env typ.p.sam init-state(gate-defs checked, head-evidence heads))
14231 ?: ?=(%| -.inferred) ~
14291 ?: ?=(%| -.inferred) ~
14232 =/ product-fit=ifit
14292 =/ product-fit=ifit
14233− (itype-fit typ.p.inferred model.u.relation sub.state.p.inferred next.state.p.inferred)
14293+ (itype-fit typ.p.inferred u.model sub.state.p.inferred next.state.p.inferred)
14234 ?. ?=(%ok -.product-fit) ~
14294 ?. ?=(%ok -.product-fit) ~
14235 =/ merged-product=itype
14295 =/ merged-product=itype
14236− (itype-merge-faces typ.p.inferred model.u.relation sub.product-fit)
14296+ (itype-merge-faces typ.p.inferred u.model sub.product-fit)
14237 =/ actual-cast=itype [%fn typ.p.sam merged-product]
14297 =/ actual-cast=itype [%fn typ.p.sam merged-product]
14238− =/ closed=itype [%fn typ.p.sam model.u.relation]
14298+ =/ closed=itype [%fn typ.p.sam u.model]
14240− (itype-fit actual-cast closed sub.product-fit next.product-fit)
14241− ?. ?=(%ok -.cast) ~
14242− =/ merged=itype (itype-merge-faces actual-cast closed sub.cast)
14243− =/ adjusted=iresult
14244− [%& merged state.p.inferred(sub sub.cast, next next.cast)]
14245− =/ added=(unit iadded-definition)
14246− (add-supported-result init-def adjusted init-state env checked artifacts.resolution)
14248− =/ recovered=(unit ischeme) (ienv-lookup init.parts env.u.added)
14250− ?. ?=(~ vars.u.recovered) ~
14251− ?. ?=(~ (itype-vars typ.u.recovered)) ~
14252− `[env.u.added grouped.resolution artifacts.u.added]
14254−:: Recover only the initializer of an already recognized direct program main.
14255−:: The derived call is evidence for an ordinary init/main retry, never an
14256−:: interface to publish on its own. Any failure returns the original resolution.
14257−++ program-init-context
14258− |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) resolution=iresolved initial=istate]
14259− ^- (unit iresolved)
14260− =/ env=ienv env.resolution
14261− ?^ (ienv-lookup %main env) ~
14262− ?^ (ienv-lookup init.parts env) ~
14263− =/ update=(unit ischeme) (ienv-lookup update.parts env)
14264− =/ view=(unit ischeme) (ienv-lookup view.parts env)
14265− =/ subs=(unit ischeme) (ienv-lookup subs.parts env)
14269− =/ inits=(list def)
14270− (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
14271− ?. ?=([* ~] inits) ~
14272− =/ init-def=def i.inits
14273− ?> ?=(%value -.init-def)
14274− ?. (program-init-tuple-null init-def) ~
14275− =/ args=(unit (list expr)) (program-main-args main)
14277− ?~ prelude.initial ~
14278− =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
14280− =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
14282− =/ written=(unit def) (~(get by gates.u.heads) %program)
14284− =/ written-sample=(unit sample) (direct-gate-sample u.written)
14285− ?~ written-sample ~
14286− ?. ?=(%cell -.u.written-sample) ~
14287− ?~ items.u.written-sample ~
14288− =/ checked=(map term def) (direct-checked-gates ds env)
14290− (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
14291− =/ fresh=(unit @ud)
14292− (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
14294− =. next.initial u.fresh
14295− =/ instance=[typ=itype state=istate] (instantiate-scheme u.program initial)
14296− ?. ?=(%fn -.typ.instance) ~
14297− ?. ?=(%cell -.sample.typ.instance) ~
14298− =/ expected-init=(unit itype)
14299− (direct-slot-body hed.sample.typ.instance (direct-sample-name i.items.u.written-sample))
14300− ?~ expected-init ~
14301− ?. ?=(%fn -.u.expected-init) ~
14302− ?. ?=(%var -.sample.u.expected-init) ~
14303− =/ data=@ud id.sample.u.expected-init
14304− =/ init-var=itype [%var next.state.instance]
14305− =/ st=istate state.instance(next +(next.state.instance))
14306− =/ up=[typ=itype state=istate] (instantiate-scheme u.update st)
14307− =/ vw=[typ=itype state=istate] (instantiate-scheme u.view state.up)
14308− =/ sb=[typ=itype state=istate] (instantiate-scheme u.subs state.vw)
14309− =. st state.sb(gate-defs checked, head-evidence heads)
14310− =/ actual=itype [%cell init-var [%cell typ.up [%cell typ.vw typ.sb]]]
14312− (direct-positional-fit u.args items.u.written-sample actual sample.typ.instance env st sub.st next.st)
14313− ?. ?=(%ok -.fit) ~
14314− =/ actual-final=itype (itype-normalize actual sub.fit)
14315− =/ expected-final=itype (itype-normalize sample.typ.instance sub.fit)
14316− =/ open=(list @ud)
14317− (unique-type-vars (weld (itype-vars actual-final) (itype-vars expected-final)))
14318− ?. (levy open |=(n=@ud =(data n))) ~
14319− ?: |((itype-has-tag actual-final) (itype-has-tag expected-final)) ~
14321− (direct-positional-fit u.args items.u.written-sample actual sample.typ.instance env st sub.fit next.fit)
14322− ?. ?=(%ok -.replay) ~
14323− ?. &(=(sub.fit sub.replay) =(next.fit next.replay)) ~
14324− =/ expected=itype (itype-normalize u.expected-init sub.fit)
14325− ?. ?=(%fn -.expected) ~
14326− =. st st(sub sub.fit, next next.fit)
14327− =/ init-state=istate (reserve-def-caps val.init-def st)
14328− =/ inferred=iresult (infer-fragment val.init-def env init-state)
14329− =? inferred ?=(%| -.inferred) (infer-recursive-gate init-def env init-state)
14330− ?: ?=(%| -.inferred) ~
14331− ?. ?=(%fn -.typ.p.inferred) ~
14332− ?^ (itype-vars sample.typ.p.inferred) ~
14334− (itype-fit sample.typ.p.inferred sample.expected sub.state.p.inferred next.state.p.inferred)
14335− ?. ?=(%ok -.data-fit) ~
14336− =/ closed=itype (itype-normalize expected sub.data-fit)
14337− ?. ?=(%fn -.closed) ~
14338− :: Resolve the ordinary tuple cast first, then check the complete gate.
14339− :: General function fit remains unchanged; only this recovered candidate
14340− :: receives the derived result context before its whole-type cast fit.
14341− =/ product-fit=ifit
14342− (itype-fit product.typ.p.inferred product.closed sub.data-fit next.data-fit)
14343− ?. ?=(%ok -.product-fit) ~
14345− (itype-merge-faces product.typ.p.inferred product.closed sub.product-fit)
14346− =/ actual-cast=itype [%fn sample.typ.p.inferred product]
14347 =/ cast=ifit
14299 =/ cast=ifit
14348 (itype-fit actual-cast closed sub.product-fit next.product-fit)
14300 (itype-fit actual-cast closed sub.product-fit next.product-fit)
14349 ?. ?=(%ok -.cast) ~
14301 ?. ?=(%ok -.cast) ~
@@ -14847,11 +14799,8 @@
14847 ?^(viewed ~ (program-plain-view-context u.main-parts ds with-keyed-view state))
14799 ?^(viewed ~ (program-plain-view-context u.main-parts ds with-keyed-view state))
14848 =/ with-view=iresolved ?~(plain-view with-keyed-view u.plain-view)
14800 =/ with-view=iresolved ?~(plain-view with-keyed-view u.plain-view)
14849 =/ initialized=(unit iresolved)
14801 =/ initialized=(unit iresolved)
14850− (program-init-context u.main u.main-parts ds with-view state)
14802+ (program-plain-init-context u.main u.main-parts ds with-view state)
14851− =/ with-initialized=iresolved ?~(initialized with-view u.initialized)
14852− =/ plain-init=(unit iresolved)
14853− ?^(initialized ~ (program-plain-init-context u.main-parts ds with-initialized state))
14854− =/ components=iresolved ?~(plain-init with-initialized u.plain-init)
14803+ =/ components=iresolved ?~(initialized with-view u.initialized)
14855 (program-main-context u.main ds components state)
14804 (program-main-context u.main ds components state)
14856 =. env env.recovered
14805 =. env env.recovered
14857 =. artifacts.resolution artifacts.recovered
14806 =. artifacts.resolution artifacts.recovered