Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 0 additions & 1 deletion TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ Find Rust owners in the [compiler map](source-rust/README.md#where-code-belongs)
- Qualify `positional_implementation_binder`/`open_const_implementation`/`open_record_const_implementation`/`named_conformance_dispatch`/`generic_calling_policy`/`domain_selected_cleanup` on all hosts.
- Move Build facets to `Build::*` and retire `machine Data::operation` and attached helpers.
- Keep live loans and their backing valid across suspension.
- Select a conformance member through a static binder that a type parameter applies or that is itself generic. `machine use_map<T, const E: Render<T>>(x: T) -> bool { E::paint(x) }` called as `use_map::<u8, Red>(x)` is refused in preparation ("a static record operand has another declared schema"), and `E::keep::<u8>(x)` or `E::pick::<4>(x)` on a member declared `machine keep<T>` or `machine pick<const N: u64>` is refused in lowering ("closed requirement call has an incomplete bound argument tuple"). Named directly, `Local::keep::<u8>(x)` and `Local::pick::<4>(x)` enter the member instance prepared for their arguments and run. A selection row of a generic member (`Keep::keep = hold;` with `machine hold<T>`) is still refused ("generic machine read without arguments"), as a generic reference row of a boundary trait is.
- Migrate remaining attached machines in samples, targets and system fixtures with their original execution oracles.
- Recover the authored `Count` and nominal callback contract in [package review](source-rust/subsystems/compiler/tests/fixtures/facts/pass/static_callback_reach_boundary_schema/main.omg). Preserve `Step<2>` and `Step<3>`, the unused effectful selection and the recovered schema. Migrate the free boundary machine under the [supply rules](wiki/spec/language/machines.md#supply).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -324,15 +324,28 @@ mod types {
self.type_parameters(definition.type_parameters)?;
self.type_arguments(definition.arguments)?;
for row in &definition.rows {
let machine =
crate::resolution::names::owned_conformance_realization(self.program, row)?;
if crate::resolution::names::owned_conformance_namespace(self.program, machine)?
!= symbol
{
return Err(
"constant dependency implementation member lost its exact owner".into(),
);
}
let machine = if row.source.owns_realization() {
let machine =
crate::resolution::names::owned_conformance_realization(self.program, row)?;
if crate::resolution::names::owned_conformance_namespace(self.program, machine)?
!= symbol
{
return Err(
"constant dependency implementation member lost its exact owner".into(),
);
}
machine
} else {
let machine = row.realization_machine;
if !machine.is_valid()
|| self.program.machines.unique_by_symbol(machine).is_none()
{
return Err(
"constant dependency reference row lost its selected machine".into(),
);
}
machine
};
self.machines.push(machine);
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2577,12 +2577,16 @@ fn substitute_arguments(
.map(|(handle, _)| handle)
.collect::<Vec<_>>();
for handle in calls {
let mut machine_arguments = match program.expression_table.expression(handle) {
ExpressionNode::Call(call) if !call.build_selection.is_valid() => {
Some(call.machine_arguments.clone())
}
_ => None,
};
let (mut machine_arguments, closed_template) =
match program.expression_table.expression(handle) {
ExpressionNode::Call(call) if !call.build_selection.is_valid() => (
Some(call.machine_arguments.clone()),
program
.closed_requirement_application(call.target_symbol)
.map(|closed| closed.template),
),
_ => (None, None),
};
if let Some(arguments) = machine_arguments.as_mut() {
replace(program, arguments);
}
Expand All @@ -2592,6 +2596,9 @@ fn substitute_arguments(
if let Some(arguments) = machine_arguments {
call.machine_arguments = arguments;
}
if let Some(template) = closed_template {
call.target_symbol = template;
}
if let Some(target) = selected_callable(call.target_symbol) {
call.static_machine_parameter = call.target_symbol;
call.target_symbol = target;
Expand All @@ -2600,10 +2607,16 @@ fn substitute_arguments(
}
}
for &handle in &body.statements {
let mut machine_arguments = match program.statement_table.statement(handle) {
StatementNode::Call(call) => Some(call.machine_arguments.clone()),
_ => None,
};
let (mut machine_arguments, closed_template) =
match program.statement_table.statement(handle) {
StatementNode::Call(call) => (
Some(call.machine_arguments.clone()),
program
.closed_requirement_application(call.target_symbol)
.map(|closed| closed.template),
),
_ => (None, None),
};
if let Some(arguments) = machine_arguments.as_mut() {
replace(program, arguments);
}
Expand All @@ -2613,6 +2626,9 @@ fn substitute_arguments(
if let Some(arguments) = machine_arguments {
call.machine_arguments = arguments;
}
if let Some(template) = closed_template {
call.target_symbol = template;
}
if let Some(target) = selected_callable(call.target_symbol) {
call.static_machine_parameter = call.target_symbol;
call.target_symbol = target;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,8 @@ fn application_bindings_commitment(
// Boolean is stated the same way, by `true` or `false`: its
// parameter's type is `bool`, which no integer literal lands in.
StaticMachineBindingValue::Const(value_reference) => {
let argument = const_argument(typed, binding.parameter, *value_reference)?;
let argument =
const_argument(typed, binding.parameter, *value_reference, bindings)?;
commitment.const_argument(&argument)?;
if let Some(prepared) = prepared.as_mut() {
prepared.parameter_kinds.push(1);
Expand Down Expand Up @@ -1375,6 +1376,7 @@ fn const_argument(
typed: &TypedTrees,
binder: SymbolHandle,
reference: crate::source_state::types::TypeReferenceHandle,
bindings: &[crate::source_state::static_applications::StaticMachineBinding],
) -> Result<application_identity::const_value::CanonicalConstValue, &'static str> {
use crate::source_state::data::TypeParameterKind;
use application_identity::const_value::CanonicalConstValue;
Expand All @@ -1387,9 +1389,25 @@ fn const_argument(
else {
return Err("an application's value binding belongs to another binder kind");
};
if let Some(required) =
typed.static_record_schema(type_reference, typed.symbols.get(binder).parent)
{
let owner = typed.symbols.get(binder).parent;
if let Some(required) = typed.static_record_schema(type_reference, owner) {
let type_bindings = bindings
.iter()
.filter_map(|binding| match binding.value {
crate::source_state::static_applications::StaticMachineBindingValue::Type(
reference,
)
| crate::source_state::static_applications::StaticMachineBindingValue::Const(
reference,
) => reference
.is_valid()
.then_some((binding.parameter, reference)),
_ => None,
})
.collect::<Vec<_>>();
let required = required
.under_invocation(typed, owner, owner, &type_bindings, &[])
.ok_or("an application's record argument lost its instantiated schema")?;
let operand = typed.static_operand_from_type_reference(reference)?;
if operand.application.is_some()
|| operand.evidence_projection.is_some()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2139,6 +2139,17 @@ impl<'t> Program<'t> {
if !authored_arguments.is_empty() && authored_arguments != arguments {
return unserved("requirement call whose static arguments differ from its application");
}
if binders.is_empty()
&& self
.typed
.closed_requirement_application(declaration)
.is_some()
{
self.typed
.require_closed_requirement_call_application(declaration, application_handle)
.map_err(|reason| refuse_at(id, Unserved::Call(reason)))?;
return Ok(Vec::new());
}
if arguments.len() != binders.len() || bindings.len() != binders.len() {
return unserved("requirement call with static arguments");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ impl<'t> Program<'t> {
self.implementation_body = Some(id);
}
Ok(id)
} else if self.rigid && matches!(reading, Reading::Implementation) {
let id = self.read_machine(id, symbol, reading)?;
self.implementation_body = Some(id);
Ok(id)
} else {
self.machine(symbol)
}
Expand Down Expand Up @@ -1135,6 +1139,7 @@ impl<'t> Program<'t> {
.is_some_and(|owner| {
!owner.type_parameters.is_empty() || !owner.lifetime_parameters.is_empty()
})
|| (!self.rigid && !declared.type_parameters.is_empty())
{
// A body a reference row selects (`Render::paint = red;`) owns
// no map, so the requirement it refines is the one the selecting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ impl Program<'_> {
let signature = binding.signatures.get(position).ok_or_else(|| {
crate::read::unavailable(id, "const record requirement lost its prepared signature")
})?;
let mut resolved = signature;
if signature.symbol != target {
// A receiver can name the original requirement or its prepared
// application. The receiver's declared schema must select this
Expand All @@ -171,28 +172,31 @@ impl Program<'_> {
.typed
.static_record_bound_requirement(binding.account.owner, receiver, target)
.map_err(|reason| crate::read::unavailable(id, reason))?;
let same_member = exact.is_some_and(|required| {
required.signature.symbol == signature.symbol
|| self
.typed
.closed_requirement_application(target)
.is_some_and(|closed| {
closed.template == origin
&& closed.local_arguments.is_empty()
&& self.typed.requirement_application_matches_scope(
target,
&required.application,
)
})
});
if !same_member {
if let Some(required) = exact.as_ref()
&& required.signature.symbol == signature.symbol
{
// Same requirement signature.
} else if let Some(required) = exact.as_ref()
&& self
.typed
.closed_requirement_application(target)
.is_some_and(|closed| {
closed.template == origin
&& self.typed.requirement_application_matches_scope(
target,
&required.application,
)
})
{
resolved = required.signature;
} else {
return Err(crate::read::unavailable(
id,
"const record call has an unrepresented local requirement application",
));
}
}
Ok(Some((position, signature.clone())))
Ok(Some((position, resolved.clone())))
}

pub(super) fn record_requirement(
Expand All @@ -206,10 +210,10 @@ impl Program<'_> {
.record_parameter(receiver)
.and_then(|binding| binding.account.members.get(position))
.and_then(|member| {
member
.instances
.iter()
.find(|instance| instance.arguments == arguments)
member.instances.iter().find(|instance| {
self.symbols.get(instance.machine) == Some(&signature.symbol)
&& instance.arguments == arguments
})
})
{
return Ok(instance.machine);
Expand Down Expand Up @@ -249,6 +253,7 @@ impl Program<'_> {
})?;
member.instances.push(StaticRecordRequirementInstance {
machine: id,
signature: signature.symbol,
arguments: arguments.to_vec(),
});
Ok(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,12 +626,14 @@ pub(crate) fn admit(elaboration: &Elaboration) -> Checked<()> {
));
}
members.push(member.requirement);
let mut arguments = Vec::new();
let mut seen = Vec::new();
for instance in &member.instances {
let key = (instance.signature, &instance.arguments);
if instances.contains(&instance.machine)
|| arguments.contains(&instance.arguments)
|| seen.contains(&key)
|| !instance.signature.is_valid()
|| !elaboration.requirements.contains(&instance.machine)
|| elaboration.machines.get(instance.machine) != Some(&member.signature)
|| elaboration.machines.get(instance.machine) != Some(&instance.signature)
|| elaboration.value_arguments.get(instance.machine)
!= Some(&instance.arguments)
|| elaboration
Expand All @@ -645,7 +647,7 @@ pub(crate) fn admit(elaboration: &Elaboration) -> Checked<()> {
));
}
instances.push(instance.machine);
arguments.push(instance.arguments.clone());
seen.push(key);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,3 +316,82 @@ fn a_named_call_of_a_generic_member_enters_the_instance_for_its_arguments() {
"{generic:?}"
);
}

#[test]
fn a_static_binder_applied_by_a_type_parameter_selects_its_member() {
let positive = "trait Render<T> { machine paint(x: T) -> bool; }
machine red(x: u8) -> bool { true }
Red satisfies Render<u8> { Render::paint = red; }
machine use_map<T, const E: Render<T>>(x: T) -> bool { E::paint(x) }
machine call(x: u8) -> bool { use_map::<u8, Red>(x) }";
accepted(positive);

let wrong_schema = "trait Render<T> { machine paint(x: T) -> bool; }
machine red(x: u8) -> bool { true }
Red satisfies Render<u8> { Render::paint = red; }
machine use_map<T, const E: Render<T>>(x: T) -> bool { E::paint(x) }
machine call(x: u16) -> bool { use_map::<u16, Red>(x) }";
let refusal = Program::try_of(&[("product/main.omg", wrong_schema)])
.err()
.expect("Red satisfies Render<u8>, not Render<u16>");
assert!(
format!("{refusal:?}").contains("a static record operand has another declared schema"),
"{refusal:?}"
);
}

#[test]
fn a_generic_member_called_through_a_static_binder_enters_its_instance() {
let source = |requires: &str| {
format!(
"trait Keep {{
machine keep<T>(x: T, n: u8) -> T;
machine pick<const N: u8>(x: u8) -> u8;
}}
Local satisfies Keep {{
machine keep<T>(x: T, n: u8) -> T {requires} {{ x }}
machine pick<const N: u8>(x: u8) -> u8 {{ x +% N }}
}}
machine use_keep<const E: Keep>(x: u8) -> u8 {{ E::pick::<5>(E::pick::<4>(E::keep::<u8>(x, 0u8))) }}
machine call(x: u8) -> u8 {{ use_keep::<Local>(x) }}"
)
};
accepted(&source(""));

let twin = verdict(&source("requires n != 0")).rejected();
assert!(
twin.unproved
.iter()
.any(|kind| kind.starts_with("CallRequirement")),
"{twin:?}"
);
}

#[test]
fn a_selection_row_of_a_generic_member_checks_and_enters_its_instance() {
let source = |requires: &str| {
format!(
"trait Keep {{
machine keep<T>(x: T, n: u8) -> T;
machine pick<const N: u8>(x: u8) -> u8;
}}
machine hold<T>(x: T, n: u8) -> T {requires} {{ x }}
machine step<const N: u8>(x: u8) -> u8 {{ x +% N }}
Local satisfies Keep {{
Keep::keep = hold;
Keep::pick = step;
}}
machine use_keep<const E: Keep>(x: u8) -> u8 {{ E::pick::<5>(E::pick::<4>(E::keep::<u8>(x, 0u8))) }}
machine call(x: u8) -> u8 {{ use_keep::<Local>(x) }}"
)
};
accepted(&source(""));

let twin = verdict(&source("requires n != 0")).rejected();
assert!(
twin.unproved
.iter()
.any(|kind| kind.starts_with("CallRequirement")),
"{twin:?}"
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ impl StaticRecordBinding {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StaticRecordRequirementInstance {
pub machine: MachineId,
pub signature: SymbolHandle,
pub arguments: Vec<semantic_vocabulary::ScalarTerm>,
}

Expand Down Expand Up @@ -475,6 +476,7 @@ mod static_record_instance_tests {
application: "Ops<u32>".into(),
instances: vec![StaticRecordRequirementInstance {
machine: machine(instance),
signature: symbol(3),
arguments: Vec::new(),
}],
}],
Expand Down
Loading
Loading