-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
struct MyStruct { | ||
data: i32 | ||
} | ||
|
||
fn main() { | ||
// List of MyStruct instances | ||
let struct_list = [ | ||
MyStruct { data: 10 }, | ||
MyStruct { data: 20 }, | ||
MyStruct { data: 30 }, | ||
MyStruct { data: 40 }, | ||
MyStruct { data: 50 } | ||
]; | ||
|
||
// Closure function that takes &MyStruct reference | ||
let get_value = |struct_ref: &MyStruct| { | ||
struct_ref.data | ||
}; | ||
|
||
// Use list call style, passing reference | ||
let result = get_value(&struct_list[2]); | ||
|
||
// Verify result | ||
assert_eq!(result, 30); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
┌─ 1 (root, init) | ||
│ #execTerminator ( terminator ( ... kind: terminatorKindCall ( ... func: operandC | ||
│ span: 0 | ||
│ | ||
│ (277 steps) | ||
└─ 3 (stuck, leaf) | ||
#traverseProjection ( toLocal ( 19 ) , thunk ( #decodeConstant ( constantKindAll | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is that something like: struct MyStruct {
data: i32
}
fn main() {
// Create data dynamically using iterator pattern to avoid constant allocation
let data = vec![10, 20, 30, 40, 50];
let struct_list: Vec<MyStruct> = data.into_iter()
.map(|d| MyStruct { data: d })
.collect();
// Closure function that takes &MyStruct reference
let get_value = |struct_ref: &MyStruct| {
struct_ref.data
};
// Use closure to access struct field
let result = get_value(&struct_list[2]);
// Verify result
assert!(result == 30);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It encounters a more weird issue than before. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK nevermind, then we keep this test for now . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. I'm still learning. So it is a bug in smir-json? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a bug, just that we don't extract all types. (take a look at the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you. Let me learn about this. |
||
function: main | ||
span: 106 | ||
|
||
|
||
┌─ 2 (root, leaf, target, terminal) | ||
│ #EndProgram ~> .K | ||
|
||
|
There was a problem hiding this comment.
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:We should investigate closures a bit more (but unrelated to p-token)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provided an issue here: #660