Documentation

Complexity.Computability.Ram.Compiler.Language.Arena.FunctionResources.Call

Composing calls with shared-heap resource contracts #

Returning calls retain the callee's actual heap and arena cursor. The continuation runs at the caller's depth, so sequential calls reuse that depth rather than adding their depths. Complete-signature transport permits arbitrary typed arguments.

ArenaExecutionCost.call_measuredOfEq composes existing exact observations. Its postcondition retains the continuation's count, including exact counts and cursor equations supplied by a client. FunctionArenaResources.call_measuredOfEq first uses an independent source total-correctness contract and the callee's existing resource and cost contracts. It then applies the same exact rule and transports the bound through the compiler-derived call overhead.

These rules introduce neither execution semantics nor a cost model. They charge callee body initialization once; the enclosing function's own initialization and outer invocation remain the enclosing caller's responsibility.

theorem Ram.LanguageCompiler.ArenaExecutionCost.call_measuredOfEq {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {fn : Fin signatures.length} {signature : Complexity.Language.Signature} (same : signatures[fn] = signature) {w heapLimit depth cursor calleeCursor : ℕ} {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {args : Complexity.Language.Args Γ signature.params} {continuation : Complexity.Language.Stmt signatures (signature.result :: Γ) result} {entry : Complexity.Language.State Γ} {calleeFinish : Complexity.Language.State signature.params} {value : Complexity.Language.Value signature.result} {callee : Complexity.Language.Exec program (cast ⋯ (program.body fn)) (entry.enter (args.eval entry.locals)) calleeFinish (Complexity.Language.Control.returned value)} {calleeReady : ArenaReady callee w heapLimit depth cursor calleeCursor} {calleeSteps : ℕ} (arguments : EnvFits w (args.eval entry.locals)) (calleeCost : ArenaExecutionCost calleeReady calleeSteps) {property : Complexity.Language.State Γ → Complexity.Language.Control result → ℕ → ℕ → Prop} (body : ∃ (finish : Complexity.Language.State (signature.result :: Γ)) (control : Complexity.Language.Control result) (finalCursor : ℕ) (tailSteps : ℕ) (execution : Complexity.Language.Exec program continuation (Complexity.Language.State.cons value (entry.restore calleeFinish)) finish control) (ready : ArenaReady execution w heapLimit (depth + 1) calleeCursor finalCursor), ArenaExecutionCost ready tailSteps ∧ property finish.tail control finalCursor tailSteps) :
∃ (finish : Complexity.Language.State Γ) (control : Complexity.Language.Control result) (finalCursor : ℕ) (tailSteps : ℕ) (execution : Complexity.Language.Exec program (Complexity.Language.Stmt.callOfEq fn same args continuation) entry finish control) (ready : ArenaReady execution w heapLimit (depth + 1) cursor finalCursor), ArenaExecutionCost ready (callCost program fn (calleeSteps + 2) + tailSteps) ∧ property finish control finalCursor tailSteps

Compose an exactly measured callee with its actual continuation. The final property can retain the continuation's exact count as well as its heap and cursor. The continuation and the whole call have the same available call depth.

theorem Ram.LanguageCompiler.FunctionArenaResources.call_measuredOfEq {X : Type u} {signatures : List Complexity.Language.Signature} {program : Complexity.Language.Program signatures} {fn : Fin signatures.length} {signature : Complexity.Language.Signature} (same : signatures[fn] = signature) {calleeArgs : X → Complexity.Language.Env signature.params} {resourcePre : X → Complexity.Language.Heap → Prop} {sourcePre : Complexity.Language.Env signature.params → Complexity.Language.Heap → Prop} {sourcePost : Complexity.Language.Env signature.params → Complexity.Language.Heap → Complexity.Language.Value signature.result → Complexity.Language.Heap → Prop} {w heapLimit depth : ℕ} {reserve bound : X → ℕ} (total : Complexity.Language.FunctionTotal program fn (cast ⋯ sourcePre) (cast ⋯ sourcePost)) (resources : FunctionArenaResources program (cast ⋯ (program.body fn)) calleeArgs resourcePre w heapLimit depth reserve) (bounded : FunctionArenaCostBound program (cast ⋯ (program.body fn)) calleeArgs resourcePre w heapLimit depth bound) {Γ : List Complexity.Language.Ty} {result : Complexity.Language.Ty} {args : Complexity.Language.Args Γ signature.params} {continuation : Complexity.Language.Stmt signatures (signature.result :: Γ) result} {entry : Complexity.Language.State Γ} {cursor tailBudget : ℕ} (x : X) (arguments_eq : calleeArgs x = args.eval entry.locals) (allowed : resourcePre x entry.heap) (sourceAllowed : sourcePre (args.eval entry.locals) entry.heap) (arguments : EnvFits w (args.eval entry.locals)) (capacity : cursor + reserve x ≤ heapLimit) {property : Complexity.Language.State Γ → Complexity.Language.Control result → ℕ → Prop} (body : ∀ (value : Complexity.Language.Value signature.result) (heap : Complexity.Language.Heap) (calleeCursor : ℕ), sourcePost (args.eval entry.locals) entry.heap value heap → ValueFits w value → calleeCursor ≤ cursor + reserve x → ∃ (finish : Complexity.Language.State (signature.result :: Γ)) (control : Complexity.Language.Control result) (finalCursor : ℕ) (tailSteps : ℕ) (execution : Complexity.Language.Exec program continuation (Complexity.Language.State.cons value { locals := entry.locals, heap := heap }) finish control) (ready : ArenaReady execution w heapLimit (depth + 1) calleeCursor finalCursor), ArenaExecutionCost ready tailSteps ∧ tailSteps ≤ tailBudget ∧ property finish.tail control finalCursor) :
∃ (finish : Complexity.Language.State Γ) (control : Complexity.Language.Control result) (finalCursor : ℕ) (steps : ℕ) (execution : Complexity.Language.Exec program (Complexity.Language.Stmt.callOfEq fn same args continuation) entry finish control) (ready : ArenaReady execution w heapLimit (depth + 1) cursor finalCursor), ArenaExecutionCost ready steps ∧ steps ≤ callCost program fn (bound x) + tailBudget ∧ property finish control finalCursor

Invoke an independently specified function and continue from its actual heap and cursor. The mathematical index supplies arguments and budgets without choosing a canonical heap representation. The continuation bound is fixed for this invocation but may depend on any of its mathematical inputs. Its proof receives the actual returned value, heap, range and retained-cursor bound.

The resulting bound includes the actual call frame and callee initialization; the continuation's cost is charged at the same caller depth.