-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Remove CHECK
from GetCurrentReturnSlot
#4688
Conversation
`GetCurrentReturnSlot` is sometimes called when there is no return slot while checking incorrect Carbon code. This change also updates `fail_returned_var_no_return_type.carbon` to cover one such case.
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.
It looks like you're trying to test the behavior for BuildReturnVar
. What is the effect on BuildReturnWithExpr
, which appears to have no handling for Invalid
?
@@ -16,7 +16,7 @@ fn Procedure() { | |||
// CHECK:STDERR: fn Procedure() { | |||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~ | |||
returned var v: () = (); | |||
return; | |||
return var; |
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.
Why is this removing the test of return;
? Should that be retained?
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.
My original rationale was that this code has two distinct errors (forgetting the return type and forgetting to return the returned var), and it would be more orthogonal to have only one. But on reflection, arguably it's only one error (accidentally adding a returned var
declaration), so it's probably worth keeping.
We do also need a test for the "forgot return type" case, because that's what would fail the CHECK
that's being removed here, so I've added that below.
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.
Thanks, I must be missing the change. Can you please link to it?
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.
Ah, I see it now.
Would it make sense to use split files (// --- ...
) in order to force each failure to be independently verified?
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.
Sure, done.
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.
It looks like you're trying to test the behavior for
BuildReturnVar
. What is the effect onBuildReturnWithExpr
, which appears to have no handling forInvalid
?
If you're asking whether BuildReturnWithExpr
could ever benefit from the CHECK
being removed here, I believe the answer is "not as it's currently written", because it only calls GetCurrentReturnSlot
under conditions that ensure it will return a valid result. It also looks like it may implicitly handle invalid values, because there are other paths through that function that seem to leave return_slot_id
invalid.
If that doesn't answer your question, can you rephrase it?
@@ -16,7 +16,7 @@ fn Procedure() { | |||
// CHECK:STDERR: fn Procedure() { | |||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~ | |||
returned var v: () = (); | |||
return; | |||
return var; |
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.
My original rationale was that this code has two distinct errors (forgetting the return type and forgetting to return the returned var), and it would be more orthogonal to have only one. But on reflection, arguably it's only one error (accidentally adding a returned var
declaration), so it's probably worth keeping.
We do also need a test for the "forgot return type" case, because that's what would fail the CHECK
that's being removed here, so I've added that below.
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.
It looks like you're trying to test the behavior for
BuildReturnVar
. What is the effect onBuildReturnWithExpr
, which appears to have no handling forInvalid
?If you're asking whether
BuildReturnWithExpr
could ever benefit from theCHECK
being removed here, I believe the answer is "not as it's currently written", because it only callsGetCurrentReturnSlot
under conditions that ensure it will return a valid result. It also looks like it may implicitly handle invalid values, because there are other paths through that function that seem to leavereturn_slot_id
invalid.If that doesn't answer your question, can you rephrase it?
Rather than assuming BuildReturnWithExpr
would work, my leaning here would be to either:
- Add a "valid"
CHECK
to theBuildReturnWithExpr
code, to maintain the current behavior (essentially forcing a change/test if it's actually possible) - Add a test that
BuildReturnWithExpr
correctly handles invalid, to test that the new behavior doesn't lead to a bug.
Thoughts?
@@ -16,7 +16,7 @@ fn Procedure() { | |||
// CHECK:STDERR: fn Procedure() { | |||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~ | |||
returned var v: () = (); | |||
return; | |||
return var; |
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.
Thanks, I must be missing the change. Can you please link to it?
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.
Rather than assuming
BuildReturnWithExpr
would work, my leaning here would be to either:
- Add a "valid"
CHECK
to theBuildReturnWithExpr
code, to maintain the current behavior (essentially forcing a change/test if it's actually possible)- Add a test that
BuildReturnWithExpr
correctly handles invalid, to test that the new behavior doesn't lead to a bug.Thoughts?
#2 is infeasible, because AFAIK there's no input that can cause BuildReturnWithExpr
to get an invalid result from its GetCurrentReturnSlot
call. I've implemented #1 now, but it feels a bit redundant: in the space of three lines the code checks that there's a return slot to get, gets the return slot, and then checks that the result is valid.
@@ -16,7 +16,7 @@ fn Procedure() { | |||
// CHECK:STDERR: fn Procedure() { | |||
// CHECK:STDERR: ^~~~~~~~~~~~~~~~ | |||
returned var v: () = (); | |||
return; | |||
return var; |
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.
Sure, done.
Fair enough. My own thought here though is that it's getting the information in a different path, and assuming they'll match. But maybe this is an indicator that there's a cleaner fix? Had you considered changing
->
i.e., instead of the |
Actually, maybe that approach is better since it avoids a name lookup in the case? Maybe the CHECK in GetCurrentReturnSlot is correct on that basis? |
That's a good idea, and I tried it, but it turns out not to work, because (We really ought to get rid of that distinction; it's so confusing.) I do think the logic in this whole area could be improved, but I think that's out of scope for this PR, so I'm merging this as-is. |
GetCurrentReturnSlot
is sometimes called when there is no return slot while checking incorrect Carbon code. This change also updatesfail_returned_var_no_return_type.carbon
to cover one such case.