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
2 changes: 0 additions & 2 deletions TASKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Find Rust owners in the [compiler map](source-rust/README.md#where-code-belongs)

- Carry the checked bounds of `size_of` and `align_of` through arithmetic on them and validate them at installation. Exercise [record geometry](samples/cli/probes/record_geometry), scalar and generic carriers, and the value form `align_of(view)`.

- Give an array extent that names a constant read from the target's layout the length each deployment closes, as in `const SIZE: u64 = size_of::<u64>(); machine sized(a: [u8; SIZE]) -> [u8; SIZE] { a }` ([evaluation.md](wiki/spec/language/evaluation.md#target-dependent-applications): an observation "can occupy any position available to an equivalent ordinary constant, including array length"). The [source driver](source-rust/subsystems/compiler/source-to-psi/driver/compile_time_invocations/constants/initializers.rs) leaves such a scalar constant unevaluated on purpose, and a scalar read of `SIZE` lowers to its retained application and runs, but the [array extent reader](source-rust/subsystems/compiler/source-to-psi/pipeline/05_prepared-typed-trees-to-lowered-program/src/read/arrays.rs) refuses the extent ("array extent that names a constant with no evaluated array length"), under `omega --check` and standalone application execution alike. Lowering the extent to that application (`ArrayExtent::Application`) next stops at element reads and array literals, which accept only literal, const-parameter and stored-length extents ("index or literal of a non-array type"), so the application extent must also reach `CollectionExtent`, the checker and native layout.

- Require [type annotations on named locals](wiki/spec/language/ownership.md#local-type-annotations) in both source compilers. Migrate authored sources, positive examples and fixtures alongside enforcement. Reject a missing annotation on both an ordinary and a mutable local even with a typed initializer. Accept a typed copy retaining its domain and reject the same destination given a plain value. Preserve constant typing and generic argument inference.

- Check a recursive walk that hands itself a smaller view, `clear_all(@mutable items[1..])` from a `head(items)` state under `terminates by items -> Slice::Length` ([termination.md](wiki/spec/language/termination.md#ranked-callees-on-projected-receivers): a traversal "may carry a changing node reference as an ordinary cursor parameter"). `core::for_each` and five walks in the [Hollow engine](samples/gui/dungeon_crawler/README.md) use this shape, so the sample builds on no target. Acceptance: Hollow's smoke test prints `PASS: dungeon campaign, collision, combat, pixels` with exit 0 on native and Psi for `windows_x86_64`, then the window opens, draws and takes keys on Windows. Branch `work/samples-hollow-windows-wip` (97742e0a411b, rebased on 02e751659eb5) holds the untested Windows window providers, the `tmp-repro/` programs and three `EXPERIMENT(hollow)` relaxations with no negative twins. Under them the shared walk passes the checker; its native build now stops at `SelectedOptimization(Liveness(Analysis(FunctionMismatch ..)))`, which clean main also gives a non-recursive store through a mutable view. The mutating walk and `for_each` stop at "call reference formation overlaps another activation of itself" in [reference results](source-rust/subsystems/compiler/source-to-psi/pipeline/05_prepared-typed-trees-to-lowered-program/src/reference_results.rs), where the loop's one Loan row stands for every pass. Next: admit an exclusive reborrow only when its source is the previous pass's own result (here and in [checker loans](source-rust/subsystems/compiler/source-to-psi/pipeline/06_lowered-program-to-checked-program/src/places/loans.rs)), refuse an independent exclusive borrow kept across passes, and pin both with a positive/negative pair.
Expand Down
101 changes: 101 additions & 0 deletions source-rust/application/tests/computed_array_extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,104 @@ fn a_literal_initializer_supplies_its_declared_array_length() {
let expected = std::fs::read_to_string(fixture("fail").join("expected.txt")).unwrap();
assert!(report.contains(expected.trim_end()), "{report}");
}

fn target_const_array_program(literal: &str, last_index: u64) -> String {
format!(
r#"const SIZE: u64 = size_of::<u64>();

machine sized(a: [u8; SIZE]) -> [u8; SIZE] {{ a }}

machine read_at(a: @[u8; SIZE], i: u64) -> u8 requires i < SIZE {{
a[i]
}}

machine make_literal() -> [u8; SIZE] {{
{literal}
}}

machine main() crashes Trap {{
let zeroed: [u8; SIZE];
let items: [u8; SIZE] = sized(make_literal());
transition zeroed.length == SIZE && 0u64 < SIZE && {last_index}u64 < SIZE {{
true -> check(@items),
false -> failed()
}}
machine check(items: @[u8; SIZE]) crashes Trap
requires 0u64 < SIZE && {last_index}u64 < SIZE
{{
transition read_at(items, 0u64) == 10u8 && read_at(items, {last_index}u64) == 80u8 {{
true -> done(),
false -> failed()
}}
}}
machine done() {{}}
machine failed() crashes Trap {{ crash Trap; }}
}}
"#
)
}

#[test]
fn target_layout_const_array_extent_checks_and_runs_on_native_and_psi() {
let source = target_const_array_program("[10u8, 20u8, 30u8, 40u8, 50u8, 60u8, 70u8, 80u8]", 7);
let (check_output, check_report) = invoke(&source, &["--check"]);
assert!(check_output.status.success(), "{check_report}");
program::assert_silent_return(&source);
}

#[test]
fn target_layout_const_array_extent_refuses_unproved_index() {
let source = r#"const SIZE: u64 = size_of::<u64>();

machine read_at(a: @[u8; SIZE], i: u64) -> u8 {
a[i]
}

machine main() {
let zeroed: [u8; SIZE];
let _: u8 = read_at(@zeroed, 0u64);
}
"#;
let (output, report) = invoke(source, &["--check"]);
assert!(!output.status.success(), "{report}");
assert!(
report.contains("index") || report.contains("bounds") || report.contains("cannot prove"),
"expected index-bound refusal:\n{report}"
);
}

#[test]
fn target_layout_const_array_extent_refuses_out_of_bounds_index_at_closure() {
let source = target_const_array_program("[10u8, 20u8, 30u8, 40u8, 50u8, 60u8, 70u8, 80u8]", 8);
let (check_output, check_report) = invoke(&source, &["--check"]);
assert!(!check_output.status.success(), "{check_report}");
assert!(
check_report.contains("scalar predicate is false"),
"expected target-closure predicate refusal:\n{check_report}"
);
for engine in ["psi", "native"] {
let (output, report) = invoke(&source, &["run", "--engine", engine]);
assert!(
!output.status.success(),
"expected {engine} refusal for out-of-bounds index:\n{report}"
);
}
}

#[test]
fn target_layout_const_array_extent_refuses_mismatched_literal_length_at_closure() {
let source = target_const_array_program("[10u8, 20u8, 30u8]", 2);
let (check_output, check_report) = invoke(&source, &["--check"]);
assert!(!check_output.status.success(), "{check_report}");
assert!(
check_report.contains("array literal length (3) matches target-dependent extent"),
"expected literal-extent mismatch refusal:\n{check_report}"
);
for engine in ["psi", "native"] {
let (output, report) = invoke(&source, &["run", "--engine", engine]);
assert!(
!output.status.success(),
"expected {engine} refusal for mismatched literal length:\n{report}"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,8 @@ pub(crate) mod element_views {
.and_then(|span| span.checked_add(8))
}
terminal_semantics::CollectionExtent::StoredLength
| terminal_semantics::CollectionExtent::Parameter { .. } => None,
| terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_) => None,
}
}) != Some(u64::from(collection.byte_size))
}
Expand All @@ -1373,6 +1374,7 @@ pub(crate) mod element_views {
terminal_semantics::CollectionExtent::StoredLength => 16,
terminal_semantics::CollectionExtent::Fixed(_) => 8,
terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_)
| terminal_semantics::CollectionExtent::LiveLength { .. } => {
return Err(invalid());
}
Expand Down Expand Up @@ -1415,7 +1417,11 @@ pub(crate) mod element_views {
(None, terminal_semantics::CollectionExtent::LiveLength { .. }) => {
(8, target_operations::TargetViewExtent::LiveLength)
}
(None, terminal_semantics::CollectionExtent::Parameter { .. }) => {
(
None,
terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_),
) => {
return Err(invalid());
}
(None, terminal_semantics::CollectionExtent::StoredLength) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1885,7 +1885,8 @@ pub(crate) mod element_establishment {
return Err(invalid());
}
let length = match element_count {
terminal_semantics::CollectionExtent::Parameter { .. } => return Err(invalid()),
terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_) => return Err(invalid()),
terminal_semantics::CollectionExtent::Fixed(length) => {
constant(builder, row, 8, length)?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,7 @@ pub mod structural_reference_input {
}
terminal_semantics::CollectionExtent::StoredLength => {}
terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_)
| terminal_semantics::CollectionExtent::LiveLength { .. } => return None,
}
representation_source_stride = Some(source_layout.size);
Expand Down Expand Up @@ -1318,7 +1319,11 @@ pub mod structural_reference_input {
length,
terminal_semantics::CollectionExtent::Fixed(length),
),
(None, terminal_semantics::CollectionExtent::Parameter { .. }) => return None,
(
None,
terminal_semantics::CollectionExtent::Parameter { .. }
| terminal_semantics::CollectionExtent::Application(_),
) => return None,
(None, terminal_semantics::CollectionExtent::StoredLength) => {
(0, 0, terminal_semantics::CollectionExtent::StoredLength)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5015,6 +5015,20 @@ pub(crate) mod scalar_applications {
);
}
}
for expected in terminal_semantics::array_extent_literal_conditions(module, machine)
.map_err(CodecError::MalformedStructuralFoundation)?
{
let ScalarConditionSubject::Declaration(owner) = expected.subject else {
return malformed(
"array extent literal condition has no exact declaration owner",
);
};
if !pending.contains(&owner) || !conditions.predicates().contains(&expected) {
return malformed(
"array literal lost its exact pending target extent condition",
);
}
}
if !module.scalars.scalar_applications.declarations().is_empty() {
let types = terminal_semantics::SortedValueTypes::new(
super::proof_values(machine)
Expand Down Expand Up @@ -10242,8 +10256,17 @@ pub(crate) mod value_foundations {
|element| scalar_index.constant_value(element),
)
|| !super::is_op_result_place(machine, operation, result)
|| scalar_array_leaf_shape(module.types.structural_types.iter(), result.structural_type)
.is_none_or(|(_, count)| u64::try_from(elements.len()).ok() != Some(count))
|| match scalar_array_leaf_shape(
module.types.structural_types.iter(),
result.structural_type,
) {
Some((_, count)) => u64::try_from(elements.len()).ok() != Some(count),
None => terminal_semantics::scalar_array_application_leaf(
module.types.structural_types.iter(),
result.structural_type,
)
.is_none(),
}
{
return malformed("scalar array establishment has an invalid result shape");
}
Expand All @@ -10252,6 +10275,11 @@ pub(crate) mod value_foundations {
result.structural_type,
)
.is_some_and(|(leaf, count)| count != 0 && leaf.scalar_restriction.is_some())
|| terminal_semantics::scalar_array_application_leaf(
module.types.structural_types.iter(),
result.structural_type,
)
.is_some_and(|(leaf, _)| !elements.is_empty() && leaf.scalar_restriction.is_some())
{
return malformed("scalar array initializer lacks receiving restriction obligations");
}
Expand Down Expand Up @@ -10718,11 +10746,16 @@ pub(crate) mod value_foundations {
.shape;
let element = match shape {
StructuralTypeShape::FixedArray { element, length } => {
let Some(length) = length.literal() else {
return malformed("array construction requires a closed element count");
};
if u64::try_from(elements.len()).ok() != Some(length) {
return malformed("array element count differs");
match length {
terminal_psi::ArrayExtent::Literal(length) => {
if u64::try_from(elements.len()).ok() != Some(*length) {
return malformed("array element count differs");
}
}
terminal_psi::ArrayExtent::Application(_) => {}
terminal_psi::ArrayExtent::Parameter { .. } => {
return malformed("array construction requires a closed element count");
}
}
*element
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ impl<'module> MachineEvidenceGoals<'module> {
fn new(
machine: &'module terminal_psi::TerminalMachine,
structural_types: &'module [terminal_psi::StructuralTypeDeclaration],
scalar_applications: &'module terminal_psi::ScalarApplications,
indexed_types: &mut Option<Vec<&'module terminal_psi::StructuralTypeDeclaration>>,
) -> Self {
let types = terminal_semantics::SortedValueTypes::new(
Expand Down Expand Up @@ -528,6 +529,11 @@ impl<'module> MachineEvidenceGoals<'module> {
root,
projection.path,
types,
|application| {
scalar_applications
.declaration(application)
.and_then(|declaration| declaration.scalar_type())
},
|prefix| {
terminal_semantics::preceding_collection_length(
preceding,
Expand Down Expand Up @@ -614,7 +620,12 @@ impl<'module, 'seals> EvidenceSealValidator<'module, 'seals> {
.iter()
.filter(|machine| selected.binary_search(&machine.id).is_ok())
.map(|machine| {
MachineEvidenceGoals::new(machine, &module.types.structural_types, &mut indexed_types)
MachineEvidenceGoals::new(
machine,
&module.types.structural_types,
&module.scalars.scalar_applications,
&mut indexed_types,
)
})
.collect::<Vec<_>>();
machines.sort_unstable_by_key(|row| row.machine.id);
Expand Down Expand Up @@ -1309,7 +1320,8 @@ mod projection_tests {
},
),
];
let goals = MachineEvidenceGoals::new(&body, &[], &mut None);
let empty_applications = terminal_psi::ScalarApplications::default();
let goals = MachineEvidenceGoals::new(&body, &[], &empty_applications, &mut None);
let obligation = ObligationId::new(number).unwrap();
let goal = goals
.obligation(obligation)
Expand Down Expand Up @@ -1578,7 +1590,8 @@ mod projection_tests {
];
// This API checks goal correspondence. Descriptor formation and
// backing custody are the independent checker's separate obligations.
let goals = MachineEvidenceGoals::new(&body, &[], &mut None);
let empty_applications = terminal_psi::ScalarApplications::default();
let goals = MachineEvidenceGoals::new(&body, &[], &empty_applications, &mut None);
let seals = (1..=2)
.map(|raw| {
let obligation = ObligationId::new(raw).unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,22 @@ pub(crate) fn scalar_storage_writes(
.result
.structural()
.ok_or("scalar array initializer has no structural result")?;
for (ordinal, value) in elements.iter().enumerate() {
let path = crate::scalar_array_leaf_path(
module.types.structural_types.iter(),
result.structural_type,
u64::try_from(ordinal)
.map_err(|_| "scalar array initializer ordinal is too large")?,
)
.ok_or("scalar array initializer has no declared scalar leaf")?;
write(result.place, &path, None, *value)?;
if crate::scalar_array_application_leaf(
module.types.structural_types.iter(),
result.structural_type,
)
.is_none()
{
for (ordinal, value) in elements.iter().enumerate() {
let path = crate::scalar_array_leaf_path(
module.types.structural_types.iter(),
result.structural_type,
u64::try_from(ordinal)
.map_err(|_| "scalar array initializer ordinal is too large")?,
)
.ok_or("scalar array initializer has no declared scalar leaf")?;
write(result.place, &path, None, *value)?;
}
}
}
OperationKind::EstablishScalarCase {
Expand Down
Loading
Loading