runtimeverification / runtimeverification/mir-semantics
Investigate closure variable capture semantics in MIR
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 52
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
Context
While reviewing code in PR #657 (related to struct field access), a question arose about how closures capture variables from their enclosing scope in MIR semantics.
Current State
Currently, the test file kmir/src/tests/integration/data/prove-rs/closure_access_struct-fail.rs shows a closure that takes a struct reference as an explicit parameter:
let get_value = |struct_ref: &MyStruct| {
struct_ref.data
};
Investigation Needed
We should investigate how MIR handles closures that capture variables from their enclosing scope, such as:
let struct_list = [/* ... */];
let get_value = |i: usize| {
struct_list[i].data // Capturing struct_list in the closure
};
Tasks
- Research how MIR represents variable capture in closures
- Test different closure capture scenarios (by value, by reference, by mutable reference)
- Document the semantics of closure captures in MIR
- Add test cases for various closure capture patterns
- Verify that our MIR semantics correctly handles all capture modes
Questions to Answer
- How does MIR differentiate between different capture modes?
- What are the memory/ownership implications of captures?
- How are captured variables represented in the MIR closure environment?
- Are there any edge cases or limitations we need to be aware of?
Related Files
kmir/src/tests/integration/data/prove-rs/closure_access_struct-fail.rskmir/src/tests/integration/data/run-rs/closures/closure-args.rskmir/src/tests/integration/data/run-rs/closures/closure-no-args.rs
Priority
Medium - This is not blocking current work but would improve our understanding and coverage of Rust's closure semantics.
Source
This investigation was prompted by a comment in PR #657: https://github.com/runtimeverification/mir-semantics/pull/657#pullrequestreview-3142664083
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading kmir/src/tests/integration/data/prove-rs/closure_access_struct-fail.rs and the closure cases in kmir/src/tests/integration/data/run-rs/closures/closure-args.rs and closure-no-args.rs. Compare the existing behavior with by-value, by-reference, and by-mutable-reference capture scenarios. Done means the capture semantics and limitations are documented, representative tests are added, and the MIR handling is verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100