Skip to content
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ac3e70e
WIP: R2 Substrate
briansrls Apr 26, 2026
92d2e93
Revert "WIP: R2 Substrate"
briansrls Apr 26, 2026
7ec9aa0
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
dcbcd06
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
e67e4e0
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
e58ce49
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
1ad44f5
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
712e26d
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
6642817
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
6dc0194
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
b992ab6
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
810f2ab
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
6e3112e
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
d1c0ba5
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 26, 2026
d86cd56
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 27, 2026
bbfea70
WIP: R2 Substrate
briansrls Apr 27, 2026
b799e81
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 27, 2026
f1e2e7b
Merge remote-tracking branch 'origin/main' into session/lively-ferret-24
briansrls Apr 27, 2026
6b20dd8
fix(v3): preserve opacity through instantiation walks
briansrls Apr 27, 2026
b65b6cb
fix(v3): fail closed when bootstrap Secret is missing
briansrls Apr 27, 2026
903a7df
WIP: R2 Substrate
briansrls Apr 27, 2026
8493cab
fix(v3): include opacity in instantiation interning
briansrls Apr 27, 2026
346d08b
fix(v3): cover opacity diagnostic in testgen helpers
briansrls Apr 27, 2026
f4304a7
fix(v3): refresh parse manifest for opacity diagnostics
briansrls Apr 27, 2026
96752ca
WIP: R2 Substrate
briansrls Apr 27, 2026
9b38574
chore: apply cargo fmt
briansrls Apr 27, 2026
f757f1c
WIP: R2 Substrate
briansrls Apr 27, 2026
208ef5b
fix(v3): update verification diagnostic fixture
briansrls Apr 27, 2026
85c6213
WIP: R2 Substrate
briansrls Apr 27, 2026
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
16 changes: 16 additions & 0 deletions src/v3/compiler/src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,7 @@ pub struct Dag {

static BOOTSTRAPPED_DAG: LazyLock<Dag> = LazyLock::new(|| {
let mut dag = bootstrap_generated::bootstrapped_fixture_dag();
dag.mark_bootstrap_secret_nominal_opacity();
assert_extdeps_bootstrap_fixture_paths_match_regen_keys(&dag);
dag.populate_primitive_cache();
dag
Expand All @@ -2239,13 +2240,15 @@ static BOOTSTRAPPED_DAG: LazyLock<Dag> = LazyLock::new(|| {
// sole writer and the PB-1 equivalence tests ratchet generated == runtime.
static BOOTSTRAPPED_STD_FIXTURE_DAG: LazyLock<Dag> = LazyLock::new(|| {
let mut dag = bootstrap_std_generated::bootstrapped_std_fixture_dag();
dag.mark_bootstrap_secret_nominal_opacity();
dag.populate_primitive_cache();
dag
});

static BOOTSTRAPPED_DAG_WITHOUT_PARSE_SURFACE_FIXTURE: LazyLock<Dag> = LazyLock::new(|| {
let mut dag =
bootstrap_generated_without_parse_surface::bootstrapped_fixture_without_parse_surface_dag();
dag.mark_bootstrap_secret_nominal_opacity();
assert_extdeps_bootstrap_fixture_paths_match_regen_keys(&dag);
dag.populate_primitive_cache();
dag
Expand Down Expand Up @@ -2286,6 +2289,19 @@ impl Dag {
(*BOOTSTRAPPED_DAG).clone()
}

fn mark_bootstrap_secret_nominal_opacity(&mut self) {

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid. The current Rust post-load mutation is a second authority for std Secret nominal_opacity; the proper fix is to move the marking into the .dag authority/lowering path and regenerate bootstrap snapshots so the fact crosses the .dag→stage0 boundary normally. I am leaving PR #937 draft because this container still has no cargo/rustc/rustup, and grep confirms lower.rs currently has no source-level nominal_opacity lowering path to complete that fix here. The branch should not be marked ready until a toolchain-bearing pass replaces this name-keyed bootstrap patch with authority-backed source + regenerated snapshots (or explicitly removes Secret marking from this PR scope).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current origin/main after #937 merge. The observation remains valid as bridge debt: std Secret nominal_opacity is still stamped by name after bootstrap load rather than sourced from .dag authority and carried through generated snapshots. Current code now documents that bridge inline and names the deletion trigger; #937 status to #856/#858 explicitly says this is not full Secret readiness. The remaining fix is the next Secret graduation/source-level-opacity authority work, not a hidden completed dissolution in #937.

let Some(secret) = self
.declarations
.iter()
.position(|decl| decl.name.as_deref() == Some("Secret"))
else {
return;
};
self.declarations[secret].nominal_opacity = Some(NominalOpacity {
permitted_accessors: Vec::new(),
});
}

/// Clone of the bootstrapped Dag used by [`crate::compile_parse_surface_std_authority_dag`]:
/// every fixture except `src/v3/std/parse_surface.dag`, so that file can be
/// parsed and lowered again without duplicate top-level names.
Expand Down
24 changes: 22 additions & 2 deletions src/v3/compiler/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ pub enum Diagnostic {
span: SourceSpan,
fixes: Vec<Correction>,
},
NominalOpacityViolation {
declaration: DeclarationId,
accessor: Option<DeclarationId>,
span: SourceSpan,
fixes: Vec<Correction>,
},
}

impl Diagnostic {
Expand All @@ -212,7 +218,8 @@ impl Diagnostic {
| Diagnostic::UnitMismatch { span, .. }
| Diagnostic::BranchConditionNotBool { span, .. }
| Diagnostic::MagnitudeOutOfRange { span, .. }
| Diagnostic::MalformedIntegerRangeFact { span, .. } => span,
| Diagnostic::MalformedIntegerRangeFact { span, .. }
| Diagnostic::NominalOpacityViolation { span, .. } => span,
}
}

Expand All @@ -226,7 +233,8 @@ impl Diagnostic {
| Diagnostic::UnitMismatch { fixes, .. }
| Diagnostic::BranchConditionNotBool { fixes, .. }
| Diagnostic::MagnitudeOutOfRange { fixes, .. }
| Diagnostic::MalformedIntegerRangeFact { fixes, .. } => fixes,
| Diagnostic::MalformedIntegerRangeFact { fixes, .. }
| Diagnostic::NominalOpacityViolation { fixes, .. } => fixes,
}
}

Expand Down Expand Up @@ -269,6 +277,18 @@ impl Diagnostic {
"integer literal `{literal}` is out of range for `{target}` (expected {range_min_inclusive}..={range_max_inclusive}, declared type {expected:?}); use a wider target"
),
Diagnostic::MalformedIntegerRangeFact { message, .. } => message.clone(),
Diagnostic::NominalOpacityViolation {
declaration,
accessor,
..
} => match accessor {
Some(accessor) => format!(
"nominal-opaque declaration `{declaration:?}` may only be structurally accessed through permitted accessor `{accessor:?}`"
),
None => format!(
"nominal-opaque declaration `{declaration:?}` cannot be structurally descended without a permitted accessor"
),
},
}
}
}
Expand Down
127 changes: 124 additions & 3 deletions src/v3/compiler/src/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use std::collections::HashSet;

use crate::dag::{
ArrowBody, AtomPayload, Behavior, BindNode, Dag, Declaration, DeclarationId, Field,
LiteralBits, Lookup, PhantomParameter, PortId, PortState, TemplateArgument, TransformNode,
TransformTarget, TypeConnective,
LiteralBits, Lookup, NominalOpacity, PhantomParameter, PortId, PortState, TemplateArgument,
TransformNode, TransformTarget, TypeConnective,
};
use crate::diagnostics::{
declaration_display_name, example_source_for_decl, witness_correction_for_decl, Correction,
Expand Down Expand Up @@ -3302,7 +3302,7 @@ pub(crate) fn concretize_decl_with_subst(
inhabits: None,
value_body: None,
refinement: None,
nominal_opacity: None,
nominal_opacity: decl.nominal_opacity.clone(),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Preserve opacity when interning specialized instantiations

concretize_decl_with_subst now writes nominal_opacity into synthesized anonymous Instantiation declarations, but those declarations are still interned via find_equivalent_anonymous_instantiation using only template + arguments. In programs that materialize the same instantiation through both opaque and non-opaque aliases, the first-created anonymous node wins and later calls reuse it, which can silently drop required opacity (or incorrectly add it) based on evaluation order; that makes the new fail-closed field-projection check unreliable for those inputs.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid. Fixed in 8493cab: find_equivalent_anonymous_instantiation now includes nominal_opacity in the interning key, and concretize_decl_with_subst passes the source declaration carrier into that lookup. Added regression coverage proving an otherwise identical anonymous instantiation with a distinct NominalOpacity carrier does not dedup against the non-opaque instance. I could not run cargo tests locally because this container still lacks cargo/rustc; CI is running on the pushed head.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current origin/main after #937 merge. This was valid on the reviewed commit and is fixed in the merged squash 31be84f: find_equivalent_anonymous_instantiation includes nominal_opacity in the interning key, concretization passes the carrier through the lookup, and the regression covers otherwise-identical anonymous instantiations with distinct opacity carriers.

span: decl.span,
});
id
Expand Down Expand Up @@ -3935,6 +3935,15 @@ fn resolve_field_project(
};

let mut subst = SubstStack::new();
if let Some(opaque_decl) = first_nominal_opaque_on_conj_walk(dag, input_ty.declaration, &subst)
{
return FieldProjectResolution::Fail(Diagnostic::NominalOpacityViolation {
declaration: opaque_decl,
accessor: None,
span: t.span.clone(),
fixes: Vec::new(),
});
}
let Some(actual_conj_id) = walk_to_conj_decl_with_subst(dag, input_ty.declaration, &mut subst)
else {
return FieldProjectResolution::Fail(Diagnostic::ResolveError {
Expand Down Expand Up @@ -4001,6 +4010,35 @@ fn resolve_field_project(
}
}

fn first_nominal_opaque_on_conj_walk(
dag: &Dag,
start: DeclarationId,
subst: &SubstStack,
) -> Option<DeclarationId> {
let mut current = start;
for _ in 0..WALK_DEPTH_LIMIT {
let decl = dag.declaration(current);
if decl.nominal_opacity.is_some() {
return Some(current);
}
match &decl.connective {
TypeConnective::Conj { .. } => return None,
TypeConnective::Instantiation { template, .. } => {

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid. Fixed in 6b20dd8: first_nominal_opaque_on_conj_walk now clones the active SubstStack and pushes Instantiation arguments before following the template, matching the substitution behavior the Conj walk relies on. Added regression coverage for the generic alias path (BoxAlias) so this case fails closed with NominalOpacityViolation instead of projecting through the substituted Secret payload.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current origin/main after #937 merge. This was valid on b799e81 and is fixed in the merged squash 31be84f: opacity and ordinary Conj descent now share walk_to_conj_decl_with_subst_or_opacity, so Instantiation arguments are pushed through the same substitution path. The merged PR includes the generic alias regression covering this fail-closed case.

current = *template;
}
TypeConnective::Atom(AtomPayload::ResolvedByStructure(next))
| TypeConnective::Atom(AtomPayload::ResolvedByName(next)) => {
current = *next;
}
TypeConnective::Atom(AtomPayload::TypeParam(_)) => {
current = subst.lookup(current)?;
}
_ => return None,
}
}
None
}

fn decide_field_project(
dag: &Dag,
t: &TransformNode,
Expand Down Expand Up @@ -4870,6 +4908,89 @@ mod bool_logical_operator_arrow_tests {
use crate::infer_helpers::filter_non_self_template_arguments;
use crate::operators::ArithmeticOp;

#[test]
fn nominal_opaque_field_project_fails_closed_before_structural_descent() {
let mut dag = Dag::new();
let span = SourceSpan::new("<nominal-opacity-test>", 0, 1);
let int = dag.int_shape().expect("bootstrap Int").declaration;

let payload = dag.alloc_declaration_id();
dag.push_declaration(Declaration {
id: payload,
name: Some("OpaquePayload".to_string()),
connective: TypeConnective::Conj {
children: vec![Field {
label: "value".to_string(),
ty: int,
}],
},
type_params: Vec::new(),
phantom_params: Vec::new(),
meta_tag: None,
specialization_parent: None,
inhabits: None,
value_body: None,
refinement: None,
nominal_opacity: None,
span: span.clone(),
});

let opaque = dag.alloc_declaration_id();
dag.push_declaration(Declaration {
id: opaque,
name: Some("OpaqueWrapper".to_string()),
connective: TypeConnective::Atom(AtomPayload::ResolvedByStructure(payload)),
type_params: Vec::new(),
phantom_params: Vec::new(),
meta_tag: None,
specialization_parent: None,
inhabits: None,
value_body: None,
refinement: None,
nominal_opacity: Some(NominalOpacity {
permitted_accessors: Vec::new(),
}),
span: span.clone(),
});

let input = dag.alloc_port_with_shape(TypeShape::new(opaque));
let output = dag.push_transform(
TransformTarget::FieldProject {
field_label: "value".to_string(),
field_child: None,
},
vec![input],
span,
);

infer(&mut dag);

assert!(matches!(
dag.diagnostics().get(output),
Some(Diagnostic::NominalOpacityViolation {
declaration,
accessor: None,
..
}) if *declaration == opaque
));
assert!(
matches!(dag.port(output).state(), PortState::Unresolved),
"opacity violation must leave the projected output unresolved"
);
}

#[test]
fn bootstrapped_secret_is_marked_nominal_opaque() {
let dag = Dag::new();
let secret = dag
.declaration_by_name("Secret")
.expect("bootstrap Secret declaration");
assert!(
secret.nominal_opacity.is_some(),
"Secret must consume the nominal-opacity carrier before Modeling dispatch"
);
}

#[test]
fn bool_logical_and_resolves_via_boolean_algebra_meet_not_pending_fallback() {
let dag = Dag::new();
Expand Down
12 changes: 12 additions & 0 deletions src/v3/compiler/src/regen_bootstrap_emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ fn render_diagnostic(diagnostic: &Diagnostic) -> String {
render_source_span(span),
render_corrections(fixes),
),
Diagnostic::NominalOpacityViolation {
declaration,
accessor,
span,
fixes,
} => format!(
"Diagnostic::NominalOpacityViolation {{ declaration: {}, accessor: {}, span: {}, fixes: {} }}",
render_declaration_id(*declaration),
render_opt_declaration_id(*accessor),
render_source_span(span),
render_corrections(fixes),
),
}
}

Expand Down
1 change: 1 addition & 0 deletions src/v3/compiler/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2460,6 +2460,7 @@ fn diagnostic_kind(diagnostic: &Diagnostic) -> &'static str {
Diagnostic::BranchConditionNotBool { .. } => "BranchConditionNotBool",
Diagnostic::MagnitudeOutOfRange { .. } => "MagnitudeOutOfRange",
Diagnostic::MalformedIntegerRangeFact { .. } => "MalformedIntegerRangeFact",
Diagnostic::NominalOpacityViolation { .. } => "NominalOpacityViolation",
}
}

Expand Down
1 change: 1 addition & 0 deletions src/v3/std/diagnostics.dag
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type CompilerDiagnosticKind
| UnitMismatch
| ArityMismatch
| ResolveError
| NominalOpacityViolation

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid. This remains blocked, not disputed: src/v3/std/diagnostics.dag changed and generated bootstrap snapshots have not been regenerated. The PR is still draft, and the PR body now calls out the required regen_bootstrap/fmt/test gates. I cannot run regen in this restored container because cargo/rustc/rustup are absent on PATH.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current origin/main after #937 merge. This was valid when posted, but the merged head regenerated the bootstrap snapshots and passed the v3 and self_host_ratchet GitHub checks. Current #937 merged at 31be84f with the diagnostics.dag authority and generated runtime fixture back in sync.


// 🟢 TERMINAL for DB-1's source-level correction carrier. Corrections
// replace a span in user-authored `.dag` source with new `.dag`
Expand Down
1 change: 1 addition & 0 deletions src/v3/std/verification.dag
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ type DiagnosticKind
| UnitMismatch
| ArityMismatch
| ResolveError
| NominalOpacityViolation

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid. This remains blocked for the same reason as the diagnostics.dag comment: src/v3/std/verification.dag changed without regenerated bootstrap snapshots. The PR remains draft and the body lists regen_bootstrap plus fmt/test/self-host ratchet as required before ready-for-review; this container currently lacks the Rust toolchain needed to run them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current origin/main after #937 merge. This was valid when posted, but the merged head refreshed the generated bootstrap snapshots and parse manifest, and GitHub v3/self_host_ratchet were green before merge. Current #937 merged at 31be84f with verification.dag diagnostic references reflected in the generated fixture.


// **🟡 Scaffold — DiagnosticDetailExpectation.** Bootstrap-local bridge
// for kind-only vs detail-narrowed diagnostic matching while
Expand Down