Fix an ICE observed with an explicit tail-call in a default trait method#145270
Fix an ICE observed with an explicit tail-call in a default trait method#145270rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
I don't think this is the right approach. Frankly, using caller_ty seems a bit unnecessary throughout check_tail_calls, though that's preexisting.
I think it's better if we refactor check_tail_calls to no longer rely at all on caller_ty and instead just have a body def id which corresponds to the item that has the THIR. We shouldn't need substs either -- those are always identity.
Then we shouldn't need to use Instance::expect_resolve at all here.
09eede7 to
f41a618
Compare
Thank you for your feedback! I addressed it. There's a test failing in LLVM codegen, but this may be a pre-existing issue. |
This comment has been minimized.
This comment has been minimized.
|
Unfortunately, that's a legitimate bug. I think the problem with I'm gonna mark this as blocked on #145321 (edit: actually #144755) @rustbot blocked As a side-note, please make sure your commits are squashed. It's not a requirement that you have 1 commit per PR, but this PR definitely shouldn't need 4 commits for a single change like this :) |
|
r? compiler-errors |
|
|
@compiler-errors, thanks for elaborating on this! So, as I gather from #145321 and #144755, if this is a pre-existing issue, would it be okay for us to move forward with this PR if we change the relevant test to be
Sure. I tend to make a commit per a logical chunk of work, and then in the course of PR’s review, only add new commits to make it clear what new changes have been made. But, of course, I’ll adjust and squash this, if you can confirm that converting the test to |
|
☔ The latest upstream changes (presumably #145423) made this pull request unmergeable. Please resolve the merge conflicts. |
|
unblocking as #144755 is resolved |
|
@jakubadamw could you rebase this PR? |
|
@jakubadamw looks like you've opened some PRs here again, any chance you can rebase this? We'd like to move forward here, so if you're not able to that's also fine and we'll take it from here. I tried to rebase locally but keep running into some weird linting errors, but maybe I'm missing something. |
|
Turns out the troublesome lint was not properly registered. I've got things working on this branch main...folkertdev:rust:tail-call-trait-method, feel free to take things from there, otherwise I'll force push at some point. |
f41a618 to
1156f2a
Compare
This comment has been minimized.
This comment has been minimized.
|
@WaffleLapkin, oops, my apologies, this one has slipped my attention/notifications. 🙂 |
This comment has been minimized.
This comment has been minimized.
1156f2a to
fdd5b0d
Compare
This comment has been minimized.
This comment has been minimized.
| } | ||
|
|
||
| fn foo(&self) -> usize { | ||
| #[allow(tail_call_track_caller)] |
There was a problem hiding this comment.
| #[allow(tail_call_track_caller)] | |
| #[expect(tail_call_track_caller)] |
There was a problem hiding this comment.
Turns out this does not work
error: 2 diagnostics reported in JSON output but not expected in test file
tests/ui/explicit-tail-calls/default-trait-method.rs:17:18: WARN: this lint expectation is unfulfilled [unfulfilled_lint_expectations]
tests/ui/explicit-tail-calls/default-trait-method.rs:17:18: WARN: this lint expectation is unfulfilled [unfulfilled_lint_expectations]
I think that is because there is some inconsistency between which HIR id is used, I actually suspect that we can/should emit this lint earlier so that we have more HIR stuff available.
I suspect that's blocked on some of the other work moving tail call logic to earlier stages, and in any case doesn't seem that relevant to this PR.
There was a problem hiding this comment.
Actually, at least part of the issue is that the instance on Struct does not use track_caller, so the expect fails on that monomorphization anyway.
|
Also you can after making that fix just squash everything together into one commit |
|
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
| } | ||
|
|
||
| fn foo(&self) -> usize { | ||
| #[allow(tail_call_track_caller)] |
There was a problem hiding this comment.
Turns out this does not work
error: 2 diagnostics reported in JSON output but not expected in test file
tests/ui/explicit-tail-calls/default-trait-method.rs:17:18: WARN: this lint expectation is unfulfilled [unfulfilled_lint_expectations]
tests/ui/explicit-tail-calls/default-trait-method.rs:17:18: WARN: this lint expectation is unfulfilled [unfulfilled_lint_expectations]
I think that is because there is some inconsistency between which HIR id is used, I actually suspect that we can/should emit this lint earlier so that we have more HIR stuff available.
I suspect that's blocked on some of the other work moving tail call logic to earlier stages, and in any case doesn't seem that relevant to this PR.
The logic determining whether the relevant function is marked as `#[track_caller]` only worked with functions that could be resolved to a concrete instance, which default trait methods cannot. We need to check the codegen attribute on the default method itself. Co-authored-by: Folkert de Vries <folkert@folkertdev.nl>
fdd5b0d to
ac5734a
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@folkertdev, hey, apologies for not having been responsive, it was a very hectic week, and I didn't find the time. Thank you for doing the rebase for me! |
|
Thanks for your work here! @bors r=WaffleLapkin |
…uwer Rollup of 11 pull requests Successful merges: - #154654 (Move `std::io::ErrorKind` to `core::io`) - #145270 (Fix an ICE observed with an explicit tail-call in a default trait method) - #154895 (borrowck: Apply `user_arg_index` nomenclature more broadly) - #155213 (resolve: Make sure visibilities of import declarations make sense) - #155346 (`single_use_lifetimes`: respect `anonymous_lifetime_in_impl_trait`) - #155517 (Add a test for Mach-O `#[link_section]` API inherited from LLVM) - #155549 (Remove some unnecessary lifetimes.) - #154248 (resolve : mark repr_simd as internal) - #154772 (slightly optimize the `non-camel-case-types` lint) - #155541 (Add `#[rust_analyzer::prefer_underscore_import]` to the traits in `rustc_type_ir::inherent`) - #155544 (bootstrap: Make "detected modifications" for download-rustc less verbose)
Rollup merge of #145270 - jakubadamw:issue-144985, r=WaffleLapkin Fix an ICE observed with an explicit tail-call in a default trait method Right now, explicit tail-calls cannot be used in functions that hold the `#[track_caller]` attribute. This check is performed on a resolved concrete instance of a function, which would be absent for a tail-call performed from the body of a default trait method. This PR fixes the issue by checking for the relevant attribute in default trait methods separately, without expecting a specific resolved instance. Closes #144985.
…uwer Rollup of 11 pull requests Successful merges: - rust-lang/rust#154654 (Move `std::io::ErrorKind` to `core::io`) - rust-lang/rust#145270 (Fix an ICE observed with an explicit tail-call in a default trait method) - rust-lang/rust#154895 (borrowck: Apply `user_arg_index` nomenclature more broadly) - rust-lang/rust#155213 (resolve: Make sure visibilities of import declarations make sense) - rust-lang/rust#155346 (`single_use_lifetimes`: respect `anonymous_lifetime_in_impl_trait`) - rust-lang/rust#155517 (Add a test for Mach-O `#[link_section]` API inherited from LLVM) - rust-lang/rust#155549 (Remove some unnecessary lifetimes.) - rust-lang/rust#154248 (resolve : mark repr_simd as internal) - rust-lang/rust#154772 (slightly optimize the `non-camel-case-types` lint) - rust-lang/rust#155541 (Add `#[rust_analyzer::prefer_underscore_import]` to the traits in `rustc_type_ir::inherent`) - rust-lang/rust#155544 (bootstrap: Make "detected modifications" for download-rustc less verbose)
View all comments
tracking issue: #112788
Right now, explicit tail-calls cannot be used in functions that hold the
#[track_caller]attribute. This check is performed on a resolved concrete instance of a function, which would be absent for a tail-call performed from the body of a default trait method. This PR fixes the issue by checking for the relevant attribute in default trait methods separately, without expecting a specific resolved instance.Closes #144985.