Skip to content

Add support for accessing single-element aggregates in #traverseProjection #657

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Stevengre
Copy link
Contributor

@Stevengre Stevengre commented Aug 21, 2025

  • Updated documentation to explain how to directly access elements of an Aggregate when #traverseProjection becomes stuck.
  • Introduced a new rule for handling single-element aggregates in the semantics.
  • Added a new test case for closure access to a struct, ensuring correct behavior.
  • Updated integration tests to include the new failure case for closure access to structs.

…ction

- Updated documentation to explain how to directly access elements of an Aggregate when #traverseProjection becomes stuck.
- Introduced a new rule for handling single-element aggregates in the semantics.
- Added a new test case for closure access to a struct, ensuring correct behavior.
- Updated integration tests to include the new failure case for closure access to structs.
@Stevengre Stevengre changed the title Jh/deref aggregate Add support for accessing single-element aggregates in #traverseProjection Aug 21, 2025
@Stevengre Stevengre self-assigned this Aug 21, 2025
@Stevengre Stevengre marked this pull request as ready for review August 21, 2025 05:54
Comment on lines +15 to +18
// Closure function that takes &MyStruct reference
let get_value = |struct_ref: &MyStruct| {
struct_ref.data
};
Copy link
Member

Choose a reason for hiding this comment

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

(probably off-topic)
While reading this code, I was thinking, what if we were using the struct_list in scope (capturing the variable in the closure), like this:

let get_value = | i: usize | { struct_list[i].data }

We should investigate closures a bit more (but unrelated to p-token)

@@ -418,6 +418,19 @@ This is done without consideration of the validity of the Downcast[^downcast].
</k>
```

If an Aggregate contains only one element and #traverseProjection becomes stuck, you can directly access this element. For more details, you may remove this rule and run `tests/integration/data/prove-rs/closure_access_struct.rs`.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add text describing what we would see in that test when removing the rule.
Anyone who reads it will understand better without having to repeat your experiments.

│ (277 steps)
└─ 3 (stuck, leaf)
#traverseProjection ( toLocal ( 19 ) , thunk ( #decodeConstant ( constantKindAll
Copy link
Member

Choose a reason for hiding this comment

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

Could we write the test program in a way that avoids this constant allocation?
Maybe using a literal array of i32 and producing the struct_list via into_iter, map, and collect?
Would be nicer to have a test that terminates with the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants