{"title": "Context Requirements",
 "producer":
 ["GENERATED by tools/Drivers/Semantics.lean (make gen-semantics); do not edit",
  "format: effect4-semantics-report v8",
  "command: make gen-semantics",
  "inputs: tools/ProofGraph/Registry.lean, tools/Tools/Semantics.lean, tools/Drivers/Semantics.lean, tools/Tools/SemanticsDisplay.lean, tools/Tools/SemanticsDocument.lean, tools/Tools/Document.lean, tools/Tools/Document/Json.lean, src/Effect4/Laws/Auto/Semantics.lean, Test/Counterexamples/REGISTER.md, docs/core/decisions.md, lean-toolchain"],
 "format": "effect4-document/1",
 "body":
 [{"line":
   [{"text": "Graded coeffects, requirement rows, and layer discharge. "},
    {"text": "8 claims: "},
    {"text": "8 "},
    {"status": "proved"},
    {"text": "."}],
   "kind": "para"},
  {"title": "Context requirements and provision",
   "kind": "part",
   "key": "about:concept:context-requirements",
   "body":
   [{"line":
     [{"text":
       "This page explains context requirements and provision in Effect4. It covers how environmental service dependencies are tracked through requirement rows and discharged by layer construction."}],
     "kind": "para"},
    {"title": "The runtime concept",
     "kind": "part",
     "key": "about:concept:context-requirements:runtime-concept",
     "body":
     [{"line":
       [{"text":
         "Effect programs declare service dependencies using ambient context parameters in the "},
        {"code": "R"},
        {"text":
         " type parameter of an effect. In Effect rc.112, layers build and supply services before execution begins."}],
       "kind": "para"},
      {"line":
       [{"text": "Effect4 models context mapping in "},
        {"code": "Context"},
        {"text": " ("},
        {"code": "src/Effect4/Machine/ContextMap.lean"},
        {"text": "). Services are keyed by unique "},
        {"code": "ServiceKey"},
        {"text": " identifiers."}],
       "kind": "para"},
      {"line":
       [{"text":
         "A program executes only after required services are provided by enclosing layers."}],
       "kind": "para"}]},
    {"title": "Literature foundations",
     "kind": "part",
     "key": "about:concept:context-requirements:literature",
     "body":
     [{"line":
       [{"text":
         "The metatheory adapts coeffect calculi from Petricek, Orchard, and Mycroft (2014). Coeffects grade computational terms by the context resources required for execution."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Row operations adapt the row polymorphism principles of Leijen (2014). Operations like union and difference track capability requirements across composition boundaries."}],
       "kind": "para"}]},
    {"title": "What Effect4 keeps and what it cuts",
     "kind": "part",
     "key": "about:concept:context-requirements:adaptations-and-cuts",
     "body":
     [{"line":
       [{"text":
         "Effect4 adapts flat coeffects where a requirement row is a flat collection of service keys ("},
        {"code": "Row ServiceKey"},
        {"text": "). Context satisfaction is simple subset inclusion ("},
        {"code": "Satisfies self r := r.Subset self.keysRow"},
        {"text": ", "},
        {"code": "src/Effect4/Machine/Context.lean"},
        {"text": ")."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Effect4 cuts comonadic adjunctions and complex grading semirings. Flat key inclusion models service availability directly."}],
       "kind": "para"},
      {"line":
       [{"text":
         "Top-level program execution requires an empty requirement row at load time (decisions row 117). Frames transporting a missing service defect across boundaries are excluded ("},
        {"code": "E4-TYPED-CE-008"},
        {"text": ")."}],
       "kind": "para"},
      {"line":
       [{"text": "Layer bodies build at closed lexical points ("},
        {"code": "Point.layerBuild"},
        {"text":
         "), and produced services must fit declared types (decisions rows 104 and 105)."}],
       "kind": "para"},
      {"line":
       [{"text": "A shared layer is built once: "},
        {"code": "Test/Program/LayerSharingContract.lean"},
        {"text":
         " compares one reference site with two nested ones under the same table."}],
       "kind": "para"}]},
    {"title": "How to read the claims",
     "kind": "part",
     "key": "about:concept:context-requirements:reading-claims",
     "body":
     [{"line":
       [{"text":
         "The claims under this concept state that context satisfaction behaves monotonically and that layer provision discharges service requirements cleanly."}],
       "kind": "para"},
      {"line": [{"text": "Key properties to inspect:"}], "kind": "para"},
      {"lines":
       [[{"ref": "claim:satisfies-empty", "label": "`satisfies-empty`"},
         {"text":
          ": An empty requirement row is unconditionally satisfied by any context."}],
        [{"ref": "claim:satisfies-weaken", "label": "`satisfies-weaken`"},
         {"text":
          ": Context satisfaction is monotone under context extension."}],
        [{"ref": "claim:provide-discharges", "label": "`provide-discharges`"},
         {"text":
          ": Providing a layer discharges its declared requirement keys from the program."}]],
       "kind": "items"},
      {"line":
       [{"text":
         "The table of claims on this page gives each claim's status and its statement."}],
       "kind": "para"}]}]},
  {"rows":
   [[[{"ref": "claim:satisfies-empty", "label": "satisfies-empty"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Machine.Env.Context.satisfies_empty"}]],
    [[{"ref": "claim:satisfies-single", "label": "satisfies-single"}],
     [{"text": "inversion"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Machine.Env.Context.satisfies_single"}]],
    [[{"ref": "claim:satisfies-union", "label": "satisfies-union"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Machine.Env.Context.satisfies_union"}]],
    [[{"ref": "claim:satisfies-weaken", "label": "satisfies-weaken"}],
     [{"text": "weakening"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Machine.Env.Context.satisfies_weaken"}]],
    [[{"ref": "claim:emission-requirements-complete",
       "label": "emission-requirements-complete"}],
     [{"text": "compatibility"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Codegen.ModuleEmission.annotation_complete"}]],
    [[{"ref": "claim:provide-discharges", "label": "provide-discharges"}],
     [{"text": "preservation"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Provision.LayerTy.provide_discharges"}]],
    [[{"ref": "claim:provide-closed", "label": "provide-closed"}],
     [{"text": "fundamentalProperty"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Provision.LayerTy.provide_closed"}]],
    [[{"ref": "claim:build-total", "label": "build-total"}],
     [{"text": "progress"}],
     [{"status": "proved"}],
     [{"code": "Effect4.Program.Provision.build_total"}]]],
   "kind": "table",
   "headers": ["Claim", "Role", "Status", "Evidence"]},
  {"title": "satisfies-empty",
   "kind": "part",
   "key": "claim:satisfies-empty",
   "body":
   [{"line": [{"text": "The empty requirement is satisfied by every context"}],
     "kind": "para"},
    {"line":
     [{"text":
       "Law 7 (satisfaction, empty): every environment satisfies the empty row."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Machine.Context"}], "label": "Module"},
      {"line":
       [{"text": "PetricekOrchardMycroft2014"},
        {"text": ", "},
        {"text": "audit C8"},
        {"text": " (analogy)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {U : Effect4.ServiceUniverse} (self : Effect4.Machine.Env.Context U),\n  self.Satisfies Effect4.Machine.Env.Requirement.empty"}]},
  {"title": "satisfies-single",
   "kind": "part",
   "key": "claim:satisfies-single",
   "body":
   [{"line":
     [{"text":
       "A singleton requirement is satisfied iff the key is present in the context"}],
     "kind": "para"},
    {"line":
     [{"text": "Law 8 (satisfaction, singleton): iff the key is bound."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Machine.Context"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {U : Effect4.ServiceUniverse} (self : Effect4.Machine.Env.Context U) (key : Effect4.ServiceKey),\n  Iff (self.Satisfies (Effect4.Machine.Env.Requirement.single key))\n    (Eq (self.get? key).isSome Bool.true)"}]},
  {"title": "satisfies-union",
   "kind": "part",
   "key": "claim:satisfies-union",
   "body":
   [{"line":
     [{"text": "Union requirement satisfaction splits across components"}],
     "kind": "para"},
    {"line":
     [{"text": "Law 9 (satisfaction, union): iff both rows are satisfied."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Machine.Context"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {U : Effect4.ServiceUniverse} (self : Effect4.Machine.Env.Context U)\n  (r s : Effect4.Machine.Env.Requirement),\n  Iff (self.Satisfies (r.union s)) (And (self.Satisfies r) (self.Satisfies s))"}]},
  {"title": "satisfies-weaken",
   "kind": "part",
   "key": "claim:satisfies-weaken",
   "body":
   [{"line":
     [{"text":
       "Context satisfaction is monotone under requirement row inclusion"}],
     "kind": "para"},
    {"line":
     [{"text": "Law 10 (weakening): satisfying a row satisfies every subrow."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Machine.Context"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {U : Effect4.ServiceUniverse} (self : Effect4.Machine.Env.Context U)\n  {r s : Effect4.Machine.Env.Requirement},\n  self.Satisfies s → Effect4.Row.Subset r s → self.Satisfies r"}]},
  {"title": "emission-requirements-complete",
   "kind": "part",
   "key": "claim:emission-requirements-complete",
   "body":
   [{"line":
     [{"text":
       "A checked emission's main declaration carries its answer, error and complete requirement row"}],
     "kind": "para"},
    {"line":
     [{"text":
       "R5/R8: a checked emission retains an explicit answer, error and complete requirement annotation on its main declaration. This certifies generated syntax, not TypeScript execution."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Codegen.Checked"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {program : Effect4.Program.NativeEff} {table : Effect4.Program.RowTable} {name : String}\n  (emission : Effect4.Codegen.ModuleEmission program table name),\n  Exists fun layers =>\n    Exists fun main =>\n      Exists fun body =>\n        Exists fun answer =>\n          Exists fun error =>\n            And\n              (Eq emission.declarations\n                (instHAppendOfAppend.hAppend layers (List.cons main List.nil)))\n              (And\n                (Eq\n                  (Effect4.Program.printDecl name emission.typing.ty body\n                    Effect4.Program.nativeScopeKey)\n                  (Except.ok main))\n                (Eq main.type\n                  (Option.some\n                    (TypeScript.TypeRef.name (List.cons \"Effect\" (List.cons \"Effect\" List.nil))\n                      (List.cons answer\n                        (List.cons error\n                          (List.cons\n                            (Effect4.Program.requirementType Effect4.Program.nativeScopeKey\n                              emission.typing.ty.requires)\n                            List.nil)))))))"}]},
  {"title": "provide-discharges",
   "kind": "part",
   "key": "claim:provide-discharges",
   "body":
   [{"line":
     [{"text":
       "Providing a layer discharges its output services from requirement rows"}],
     "kind": "para"},
    {"line":
     [{"text":
       "A requirement of the dependent that the dependency provides is discharged."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Program.Provision"}], "label": "Module"},
      {"line":
       [{"text": "Leijen2014"},
        {"text": ", "},
        {"text": "audit P22"},
        {"text": " (adaptedResult)"}],
       "label": "Literature"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (s t : Effect4.Program.LayerTy) (key : Effect4.ServiceKey),\n  Effect4.Row.instMembership.mem t.out key →\n    Not (Effect4.Row.instMembership.mem t.requires key) →\n      Not (Effect4.Row.instMembership.mem (s.provide t).requires key)"}]},
  {"title": "provide-closed",
   "kind": "part",
   "key": "claim:provide-closed",
   "body":
   [{"line":
     [{"text":
       "A closed dependency layer that covers all requirements yields a closed program"}],
     "kind": "para"},
    {"line":
     [{"text":
       "The closure theorem. A dependency that is itself closed and provides everything the dependent needs closes the dependent: "},
      {"code": "Layer<ROut, E, never>"},
      {"text": ". This is the sentence "},
      {"code": "Effect.provide(program, layer)"},
      {"text":
       " type-checks by, and the sentence a deployment is checked by."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Program.Provision"}], "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ (s t : Effect4.Program.LayerTy),\n  t.Closed → Effect4.Row.Subset s.requires t.out → (s.provide t).Closed"}]},
  {"title": "build-total",
   "kind": "part",
   "key": "claim:build-total",
   "body":
   [{"line":
     [{"text":
       "Build totality: under a typed leaf semantics, a layer the checker types builds under every context satisfying its requirement row, and the built context satisfies its output row (restored, decisions row 147)"}],
     "kind": "para"},
    {"line":
     [{"text": "Build totality ("},
      {"code": "build_total"},
      {"text": ", cut at "},
      {"code": "b08f3b58"},
      {"text":
       ", restored under decisions row 147): under a typed leaf semantics, a layer the checker types builds under every context that satisfies its requirement row, and the built context satisfies its output row."}],
     "kind": "para"},
    {"rows":
     [{"line": [{"code": "Effect4.Laws.Program.BuildTotal"}],
       "label": "Module"}],
     "kind": "fields"},
    {"language": "lean",
     "kind": "code",
     "body":
     "∀ {Op : Type} (sig : Effect4.Program.Signature Op) (sem : Effect4.Program.Provision.LeafSem Op),\n  Effect4.Program.Provision.LeafSem.Typed sig sem →\n    ∀ (l : Effect4.Program.LayerTerm Op) (t : Effect4.Program.LayerTy)\n      (ctx : Effect4.Machine.Env.Ctx),\n      Eq (Effect4.Program.layerTy sig l) (Option.some t) →\n        Effect4.Machine.Env.Context.Satisfies ctx t.requires →\n          Exists fun out =>\n            And (Eq (Effect4.Program.Provision.build sem l ctx) (Option.some out))\n              (Effect4.Machine.Env.Context.Satisfies out t.out)"}]}]}
