Repository navigation
feat(v3): enforce NominalOpacity fail-closed field projection #937
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
ac3e70e
92d2e93
7ec9aa0
dcbcd06
e67e4e0
e58ce49
1ad44f5
712e26d
6642817
6dc0194
b992ab6
810f2ab
6e3112e
d1c0ba5
d86cd56
bbfea70
b799e81
f1e2e7b
6b20dd8
b65b6cb
903a7df
8493cab
346d08b
f4304a7
96752ca
9b38574
f757f1c
208ef5b
85c6213
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Useful? React with 👍 / 👎.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
@@ -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 { | ||
|
|
@@ -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.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
|
|
@@ -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(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,7 @@ type CompilerDiagnosticKind | |
| | UnitMismatch | ||
| | ArityMismatch | ||
| | ResolveError | ||
| | NominalOpacityViolation | ||
This comment was marked as resolved.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,6 +33,7 @@ type DiagnosticKind | |
| | UnitMismatch | ||
| | ArityMismatch | ||
| | ResolveError | ||
| | NominalOpacityViolation | ||
This comment was marked as resolved.
Sorry, something went wrong.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
This comment was marked as resolved.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.