Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions src/v3/compiler/tests/integration/m2_substrate_inhabitance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2186,3 +2186,80 @@ fn runtime_value_carrier_matches_pb_runtime_shape_and_marker_boundary() {
"Dag::value_marker() must keep returning the L1 behavior marker"
);
}

#[test]
fn pr_a_2_eval_frame_and_state_stack_carriers_match_pb_runtime_section_3_3() {
let dag = v3_compiler::generated_full_bootstrap_dag();

let frame = dag
.declaration_by_name("EvalFrame")
.expect("PR-A.2 EvalFrame missing from full bootstrap");
assert_eq!(
frame.span.file, "src/v3/std/runtime.dag",
"EvalFrame must live in the single runtime authority module"
);
let bindings_ty = conj_field_by_id(&dag, frame.id, "bindings");
match &dag.declaration(bindings_ty).connective {
TypeConnective::Instantiation {
template,
arguments,
} => {
let template_name = dag
.declaration(*template)
.name
.as_deref()
.expect("Map template must be a named declaration");
assert!(
template_name == "Map" || template_name == "PartialFunction",
"EvalFrame.bindings template must be Map / PartialFunction, got `{template_name}`"
);
assert_eq!(
arguments.len(),
2,
"EvalFrame.bindings must have exactly two type arguments (key, value)"
);
assert_eq!(
arguments[0].value,
find_named(&dag, "PortId"),
"EvalFrame.bindings key must be PortId"
);
assert_eq!(
arguments[1].value,
find_named(&dag, "Value"),
"EvalFrame.bindings value must be runtime Value"
);
}
other => panic!("EvalFrame.bindings is not an Instantiation: {other:?}"),
}

let stack = dag
.declaration_by_name("EvalStateStack")
.expect("PR-A.2 EvalStateStack missing from full bootstrap");
assert_eq!(
stack.span.file, "src/v3/std/runtime.dag",
"EvalStateStack must live in the single runtime authority module"
);
assert_runtime_value_instantiation(
&dag,
conj_field_by_id(&dag, stack.id, "frames"),
"Stack",
"EvalFrame",
);

let value = dag
.declaration_by_name("Value")
.expect("runtime Value missing from full bootstrap");
let labels: Vec<&str> = match &value.connective {
TypeConnective::Disj { variants } => variants.iter().map(|f| f.label.as_str()).collect(),
other => panic!("runtime Value is not a Disj: {other:?}"),
};
assert!(
!labels.contains(&"ClosureValue"),
"PR-A.2 must not introduce ClosureValue; closed-over environments \
are evaluator-internal state, not observable Value variants"
);
assert!(
!labels.contains(&"EvalFrame") && !labels.contains(&"EvalStateStack"),
"EvalFrame / EvalStateStack are evaluator state, never Value variants"
);
}
31 changes: 30 additions & 1 deletion src/v3/std/runtime.dag
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
module v3.std.runtime

import std.list { List }
import std.types { Map }
import std.stack { Stack }
import v3.std.substrate { LiteralBits, LoopBound }
import v3.std.substrate_minimal { NodeId, DeclarationId }
import v3.std.substrate_minimal { NodeId, PortId, DeclarationId }

type NamedField {
label: String
Expand Down Expand Up @@ -46,3 +48,30 @@ type Value
| VariantValue { tag: DeclarationId, payload: Value }
| NodeRef(NodeId)
| CardinalityValue(LoopBound)

// 🟢 TERMINAL at PR-A.2 evaluator-state scope. Per
// docs/briefs/r2-pr-a-runtime-value-model.md §Substrate Targets and
// docs/design-pb-runtime-interpreter.md §3.3, closed-over environments are
// evaluator-internal state, not observable `Value` inhabitants. `EvalFrame`
// is one binding scope: a finite partial function from `PortId` to runtime
// `Value`. `Map<PortId, Value>` (= `PartialFunction<PortId, Value>` per
// `dsl/std/types.dag:213`) makes duplicate binding for one `PortId`
// unrepresentable at the carrier boundary; this is the locked shape and
// must not be replaced with a duplicate-admitting `List<EvalBinding>`.
type EvalFrame {
bindings: Map<PortId, Value>
}

// 🟢 TERMINAL at PR-A.2 evaluator-state scope. LIFO stack of `EvalFrame`s
// for nested calls, branch path bindings, and bounded loop iterations.
// Uses `Stack<EvalFrame>` (= cons list, `dsl/std/stack.dag:37`) rather
// than `List<EvalFrame>`: per M9, the concept-DAG ground for an evaluator
// frame stack is `Stack<T>`, whose `push`/`pop`/`peek` are O(1); the
// `List<EvalFrame>` shape sketched in the PR-A.0 brief draft would lose
// that orientation and force every push/pop through O(n) prepend. Frame
// push/pop is evaluator-internal; the stack is not observable as a
// `Value`. PR-A.3 owns `EvalThunk` / `EvalStrategy` / `EvalMemoKey`;
// they are not added here.
type EvalStateStack {
frames: Stack<EvalFrame>
}