@@ -13338,21 +13338,6 @@
1333813338 %body ?~(defs.e $(e final.e) e)
1333913339 * e
1334013340 ==
13341−++ program-init-tuple-null
13342− |= d=def
13343− ^- ?
13344− ?. ?=(%value -.d) |
13345− ?. |(?=(%gate -.val.d) ?=(%gate-wide -.val.d)) |
13346− =/ body=expr
13347− ?- -.val.d
13348− %gate body.val.d
13349− %gate-wide body.val.d
13350− * !!
13351− ==
13352− =. body (program-transparent body)
13353− ?. ?=(%tuple -.body) |
13354− ?~ items.body |
13355− (program-empty-null val:(rear items.body))
1335613341::
1335713342:: Recover only the update of an already recognized direct program main.
1335813343:: Its written sample determines the message/model relationship; the canonical
@@ -14169,21 +14154,89 @@
1416914154 ?. ?=(~ (itype-vars typ.u.recovered)) ~
1417014155 `[env.u.added grouped.resolution artifacts.u.added]
1417114156::
14172−++ program-init-null-sample
14173− |= d=def
14174− ^- ?
14175− =/ written=(unit sample) (direct-gate-sample d)
14176− ?~ written |
14177− ?. ?=(%bare -.u.written) |
14178− =/ sh=shape shape.u.written
14179− ?. ?=(%const -.sh) |
14180− =(%null form.lit.sh)
14181−::
14182−:: The tuple-ending-null initializer retry above intentionally keeps its own
14183−:: boundary. A direct null-sample initializer can instead receive the closed
14184−:: model already established by update, view and subscriptions.
14157+:: The model a direct program's initializer must produce. Update's written
14158+:: two-item sample gives it when it can be read. Otherwise main's own program
14159+:: fit does: update, view and subs are fitted together against the prelude
14160+:: program's sample, as main's call will fit them, with the initializer an
14161+:: open variable. Only the initializer's data may stay open, a replay of the
14162+:: fit must not move, and the model must come out closed and tag-free.
14163+++ program-init-model
14164+ |= [main=def parts=[init=term update=term view=term subs=term] ds=(list def) env=ienv program=ischeme program-def=def initial=istate]
14165+ ^- (unit itype)
14166+ =/ relation=(unit [message=itype model=itype])
14167+ (program-update-relation update.parts ds env)
14168+ ?^ relation `model.u.relation
14169+ =/ args=(unit (list expr)) (program-main-args main)
14170+ ?~ args ~
14171+ =/ written=(unit sample) (direct-gate-sample program-def)
14172+ ?~ written ~
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)
14178+ ?~ update ~
14179+ ?~ view ~
14180+ ?~ subs ~
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]]]
14197+ =/ fit=ifit
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)) ~
14206+ =/ replay=ifit
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) ~
14213+ `product.expected
14214+::
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]
14220+ ^- iresult
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" ~]]
14226+ =/ fit=ifit
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)]
14230+::
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.
1418514238++ 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]
1418714240 ^- (unit iresolved)
1418814241 =/ env=ienv env.resolution
1418914242 ?^ (ienv-lookup %main env) ~
@@ -14191,15 +14244,11 @@
1419114244 ?~ (ienv-lookup update.parts env) ~
1419214245 ?~ (ienv-lookup view.parts env) ~
1419314246 ?~ (ienv-lookup subs.parts env) ~
14194− =/ relation=(unit [message=itype model=itype])
14195− (program-update-relation update.parts ds env)
14196− ?~ relation ~
1419714247 =/ inits=(list def)
1419814248 (skim ds |=(d=def &(?=(%value -.d) =(init.parts name.d))))
1419914249 ?. ?=([* ~] inits) ~
1420014250 =/ init-def=def i.inits
1420114251 ?> ?=(%value -.init-def)
14202− ?. (program-init-null-sample init-def) ~
1420314252 =/ written=(unit sample) (direct-gate-sample init-def)
1420414253 ?~ written ~
1420514254 =/ body=expr
@@ -14209,10 +14258,12 @@
1420914258 * !!
1421014259 ==
1421114260 ?~ prelude.initial ~
14212− ?~ (ienv-lookup %program values.u.prelude.initial) ~
14261+ =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
14262+ ?~ program ~
1421314263 =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
1421414264 ?~ heads ~
14215− ?~ (~(get by gates.u.heads) %program) ~
14265+ =/ program-def=(unit def) (~(get by gates.u.heads) %program)
14266+ ?~ program-def ~
1421614267 =/ checked=(map term def) (direct-checked-gates ds env)
1421714268 =/ templates=ienv
1421814269 (turn molds.u.prelude.initial |=(x=[name=term template=ischeme] [name.x template.x]))
@@ -14220,130 +14271,31 @@
1422014271 (ienv-fresh-id (weld env (weld values.u.prelude.initial templates)))
1422114272 ?~ fresh ~
1422214273 =. 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)
14278+ ==
14279+ ?~ model ~
1422314280 =/ init-state=istate (reserve-def-caps val.init-def initial)
1422414281 =/ sam=isample-result (infer-sample u.written env init-state)
1422514282 ?: ?=(%| -.sam) ~
1422614283 ?. ?=(~ (itype-vars typ.p.sam)) ~
1422714284 ?: (itype-has-tag typ.p.sam) ~
1422814285 =/ 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))
1422914288 =/ 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))
1423114291 ?: ?=(%| -.inferred) ~
1423214292 =/ 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)
1423414294 ?. ?=(%ok -.product-fit) ~
1423514295 =/ 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)
1423714297 =/ actual-cast=itype [%fn typ.p.sam merged-product]
14238− =/ closed=itype [%fn typ.p.sam model.u.relation]
14239− =/ cast=ifit
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)
14247− ?~ added ~
14248− =/ recovered=(unit ischeme) (ienv-lookup init.parts env.u.added)
14249− ?~ recovered ~
14250− ?. ?=(~ vars.u.recovered) ~
14251− ?. ?=(~ (itype-vars typ.u.recovered)) ~
14252− `[env.u.added grouped.resolution artifacts.u.added]
14253−::
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)
14266− ?~ update ~
14267− ?~ view ~
14268− ?~ subs ~
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)
14276− ?~ args ~
14277− ?~ prelude.initial ~
14278− =/ program=(unit ischeme) (ienv-lookup %program values.u.prelude.initial)
14279− ?~ program ~
14280− =/ heads=(unit igate-prelude-evidence) (direct-prelude-evidence ds prelude.initial)
14281− ?~ heads ~
14282− =/ written=(unit def) (~(get by gates.u.heads) %program)
14283− ?~ written ~
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)
14289− =/ templates=ienv
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)))
14293− ?~ fresh ~
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]]]
14311− =/ fit=ifit
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)) ~
14320− =/ replay=ifit
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) ~
14333− =/ data-fit=ifit
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) ~
14344− =/ product=itype
14345− (itype-merge-faces product.typ.p.inferred product.closed sub.product-fit)
14346− =/ actual-cast=itype [%fn sample.typ.p.inferred product]
14298+ =/ closed=itype [%fn typ.p.sam u.model]
1434714299 =/ cast=ifit
1434814300 (itype-fit actual-cast closed sub.product-fit next.product-fit)
1434914301 ?. ?=(%ok -.cast) ~
@@ -14847,11 +14799,8 @@
1484714799 ?^(viewed ~ (program-plain-view-context u.main-parts ds with-keyed-view state))
1484814800 =/ with-view=iresolved ?~(plain-view with-keyed-view u.plain-view)
1484914801 =/ initialized=(unit iresolved)
14850− (program-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)
14802+ (program-plain-init-context u.main u.main-parts ds with-view state)
14803+ =/ components=iresolved ?~(initialized with-view u.initialized)
1485514804 (program-main-context u.main ds components state)
1485614805 =. env env.recovered
1485714806 =. artifacts.resolution artifacts.recovered