diff --git a/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications.rs b/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications.rs index a49fc0ec88a2..43c1d7bfdf2a 100644 --- a/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications.rs +++ b/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications.rs @@ -463,6 +463,20 @@ impl<'a> DefaultRequirements<'a> { path: &[StructuralPathSegment], carrier: StructuralTypeId, demand: DefaultDemand<'_>, + ) -> Judged> { + self.at_except(root, path, carrier, demand, &[]) + } + + /// The default clauses at one place, leaving out the named domains in + /// `delivered`: a whole stored value carries those memberships itself, + /// so they owe no clause and need no storage predicate theory. + fn at_except( + &self, + root: PlaceId, + path: &[StructuralPathSegment], + carrier: StructuralTypeId, + demand: DefaultDemand<'_>, + delivered: &[StructuralDomainId], ) -> Judged> { let mut result = Vec::new(); for position in 0..self.declaration(carrier)?.requires.len() { @@ -475,7 +489,7 @@ impl<'a> DefaultRequirements<'a> { } let mut named = Vec::new(); for id in self.declared.at(root, path).whole { - named.extend(self.domain_clauses(id, carrier, path, demand)?); + named.extend(self.domain_clauses(id, carrier, path, demand, delivered)?); } named.sort_unstable(); named.dedup(); @@ -495,6 +509,7 @@ impl<'a> DefaultRequirements<'a> { carrier: StructuralTypeId, path: &[StructuralPathSegment], demand: DefaultDemand<'_>, + delivered: &[StructuralDomainId], ) -> Judged> { let mut named = Vec::new(); let row = self @@ -510,6 +525,9 @@ impl<'a> DefaultRequirements<'a> { .required_domain_closure(self.domains) .ok_or_else(|| self.error("a named default has incomplete membership requirements"))?; for domain in closure { + if delivered.contains(&domain.id) { + continue; + } // Snapshot demand names predicate operands. Restoring storage additionally // owes the value's content, which predicate clauses cannot establish. if !domain.complete_predicate_theory @@ -649,6 +667,7 @@ impl<'a> DefaultRequirements<'a> { leaf, &qualified.path, demand, + &[], )? .is_empty(); } @@ -1043,11 +1062,12 @@ impl<'a> DefaultRequirements<'a> { ) -> Judged<()> { let displayed = self.declared.at(displayed_root, displayed_path); let lost = self - .at( + .at_except( root, path, self.carrier(root, path)?, DefaultDemand::Restoration, + &displayed.whole, )? .into_iter() .filter(|required| { diff --git a/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications/default_requirement_tests.rs b/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications/default_requirement_tests.rs index c81cb6f9ae12..44e0e4b9dd85 100644 --- a/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications/default_requirement_tests.rs +++ b/source-rust/subsystems/compiler/psi/semantics/src/structural_qualifications/default_requirement_tests.rs @@ -161,6 +161,55 @@ fn inventory_keeps_a_content_domains_predicate_without_proving_a_changed_value() ); } +/// A whole stored value carries the content domain its destination displays, +/// so the lender owes no predicate for it (allocation's `bump.omg` stores a +/// split's `rest` into its `@mutable` strategy's `tail`). Under a destination +/// that does not display the domain, the lender's content still owes a proof. +#[test] +fn a_whole_stored_value_delivers_the_content_domain_its_destination_displays() { + use semantic_vocabulary::{ + ContentAlgebra, ContentAlgebraKind, ContentDomainId, ContentProjectionExpression, + ContentProjectionIdentity, ContentProjectionScalar, + }; + let types = types(2); + let mut machine = machine(); + let mut owner = domain(types[1].id); + owner.predicate.as_mut().unwrap().proposition = Proposition::Truth; + machine.structural_parameters[0] + .qualifications + .push(owner.id); + let algebra = ContentAlgebra { + kind: ContentAlgebraKind::CountedQuantity, + parameter: "Bytes".into(), + }; + let value = + ContentProjectionExpression::CountedQuantity(ContentProjectionScalar::Natural("2".into())); + owner.content_projection = Some(terminal_psi::StructuralContentProjection { + identity: ContentProjectionIdentity { + domain: ContentDomainId::new(owner.semantic_domain.get()).unwrap(), + projection_report_fingerprint: value.report_fingerprint(&algebra), + }, + algebra, + expression: value, + }); + let domains = [owner]; + let defaults = DefaultRequirements::new(&types, &domains, &machine).unwrap(); + let root = PlaceId::new(2).unwrap(); + let mut lost = Vec::new(); + defaults + .append_lost(&mut lost, root, &[], root, &[]) + .unwrap(); + assert!(lost.is_empty(), "{lost:?}"); + let element = [StructuralPathSegment::FixedIndex(0)]; + let error = defaults + .append_lost(&mut lost, root, &element, root, &[]) + .unwrap_err(); + assert_eq!( + error.detail, + "a named default has no complete storage predicate theory" + ); +} + #[test] fn named_defaults_are_rerooted_goals_not_membership_truth() { let mut types = types(2); @@ -333,7 +382,9 @@ fn a_window_requires_coordinates_only_for_its_potential_owners() { types[0].requires.clear(); let owner = domain(types[1].id); - machine.structural_parameters[0].qualifications.push(owner.id); + machine.structural_parameters[0] + .qualifications + .push(owner.id); assert!(!handback(&types, &machine, &selected, element)); assert!(!project(&types, &[owner], &machine)); }