-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Fix reassignment of struct members in impl self #1173
Conversation
entry: | ||
v0 = const { u64 } { u64 undef }, !1 | ||
v1 = const u64 0, !2 | ||
v2 = insert_value v0, { u64 }, v1, 0, !1 |
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.
@otrho this looks a bit weird to me even though it's functional. I understand that this IR is before the optimizer runs, but the fact that we're inserting into a const
seems odd. Is this expected?
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.
Yep, conceptually I was thinking functional style, so insert_value
isn't modifying the original, but creating a new value. v2
is not a modified v0
, it's a whole new value. But this will go away with the struct refactor and everything goes on the stack.
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.
Right, yeah that makes sense. This is SSA anyways.. I don't know what I was thinking 😂
@@ -15,18 +15,18 @@ script { | |||
|
|||
while_body: | |||
v4 = get_ptr mut ptr bool a, ptr bool, 0, !4 | |||
v5 = load ptr v4, !4 | |||
cbr v5, block0, block1, !5 | |||
v5 = get_ptr mut ptr bool a, ptr bool, 0, !5 |
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.
I think these changes are due to the fact that we're now creating get_ptr
before compiling the RHS.
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.
OK, v4
is used way down below for the store
in block1
, where the old get_ptr
was, which is a bit unfortunate.
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.
I've come across a slightly different scenario where the AST is saying that the following:
fn f(a: u64) {
let a = a + 1;
...
}
Is a re-assignment, where IMO this is a new declaration which is shadowing the function argument. I didn't raise an issue at the time though...
This change is necessary, because it (e.g. self.a = 0
from the test) is a genuine re-assignment, but it'll also hide the above issue. But maybe the above issue isn't an issue.
@@ -15,18 +15,18 @@ script { | |||
|
|||
while_body: | |||
v4 = get_ptr mut ptr bool a, ptr bool, 0, !4 | |||
v5 = load ptr v4, !4 | |||
cbr v5, block0, block1, !5 | |||
v5 = get_ptr mut ptr bool a, ptr bool, 0, !5 |
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.
OK, v4
is used way down below for the store
in block1
, where the old get_ptr
was, which is a bit unfortunate.
You're right.. a new variable is being declared via |
@otrho I looked at the AST of the following code: fn foo(a: u64) {
let a = a + 1;
}
fn main() {
foo(5);
} and I don't see a local ptr u64 a_ |
Argh. It was something like that..! I think it was in the |
Closes: #1169
When looking for the value to reassign, also look for it in the argument list of the function.