Skip to content

Resolve instance for SymFn in global/naked asm #140374

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

compiler-errors
Copy link
Member

Instance::expect_resolve ensures that we're actually going from trait item -> impl item.

Fixes #140373

@rustbot
Copy link
Collaborator

rustbot commented Apr 27, 2025

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 27, 2025

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@lcnr
Copy link
Contributor

lcnr commented Apr 28, 2025

r=me after comment/rename on Instance::new

@lcnr lcnr assigned lcnr and unassigned davidtwco Apr 28, 2025
@rustbot
Copy link
Collaborator

rustbot commented Apr 28, 2025

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred in coverage instrumentation.

cc @Zalathar

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@compiler-errors
Copy link
Member Author

@bors r=lcnr rollup

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

📌 Commit 844b1e2 has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 28, 2025
pub fn new(def_id: DefId, args: GenericArgsRef<'tcx>) -> Instance<'tcx> {
/// Creates a new [`InstanceKind::Item`] from the `def_id` and `args`. Note that this
/// does not resolve trait items to their corresponding impl items -- to do that, use
/// [`Instance::expect_resolve`] instead.
Copy link
Member

@RalfJung RalfJung Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a compiler dev I would be rather clueless about whether I want to "resolve trait items to their corresponding impl items" or not -- I'm not even sure what exactly this means. So I'm afraid this comment isn't very helpful in terms of giving guidance for when I should use which of these functions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion for a new comment? Because just saying it is not very helpful as a comment is... well, also not very actionable 😆

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment on https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/struct.Instance.html#method.try_resolve to understand what it means to resolve a trait item to its corresponding impl item.

Copy link
Contributor

@lcnr lcnr Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what matters is: "Are you certain that the body of def_id is the actual body you want to use. This is not the case for trait methods or functions we may stub out with a separate implementation"

Copy link
Member

@RalfJung RalfJung Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a suggestion for a new comment? Because just saying it is not very helpful as a comment is... well, also not very actionable 😆

I'm not sure how to suggest a better comment without having any clue about when this function should or should not be used.^^ You made const-eval use new_raw so I guess it is the right thing to use for anything I encountered in the compiler so far...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You made const-eval use new_raw so I guess it is the right thing to use for anything I encountered in the compiler so far...

CTFE uses Instance::expect_resolve all throughout, so that's definitely not true. The only usage sites I've touched are the ones that attempt to directly evaluate const bodies.

Copy link
Member

@RalfJung RalfJung Apr 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what matters is: "Are you certain that the body of def_id is the actual body you want to use. This is not the case for trait methods or functions we may stub out with a separate implementation"

That sounds helpful. Are there docs for the concept of "resolve" that we can link to? I guess it refers to going from a trait-method pair to the actual impl? Also, is there ever a downside to using resolve when we don't have to?

new_raw is scary as a name so now I feel like every use of this function needs a comment justifying it, but I'm not sure what the justification looks like in the query wrappers.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is there ever a downside to using resolve when we don't have to?

Query calls, so perf. I'll open a follow-up to reduce the number of new_raw calls b/c it'll need a perf run and I see no reason to block this PR unnecessarily, but yes, the name was intentionally chosen to discourage usage of this function and to prompt compiler devs to question whether it's the appropriate function to call -- it's the root cause of this bug after all.

@compiler-errors compiler-errors force-pushed the global_asm-bug branch 3 times, most recently from d30ad80 to 9ac697f Compare April 28, 2025 15:48
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

📌 Commit 9ac697f has been approved by lcnr

It is now in the queue for this repository.

Comment on lines 433 to 436
/// implementation, and which may not even have a body themselves. Usages of
/// this function should probably use [`Instance::expect_resolve`], or if run
/// in a polymorphic environment or within a lint (that may encounter ambiguity)
/// [`Instance::expect_resolve`] instead.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// implementation, and which may not even have a body themselves. Usages of
/// this function should probably use [`Instance::expect_resolve`], or if run
/// in a polymorphic environment or within a lint (that may encounter ambiguity)
/// [`Instance::expect_resolve`] instead.
/// implementation, and which may not even have a body themselves. Instead of
/// this function, you probably should use use [`Instance::expect_resolve`], or if run
/// in a polymorphic environment or within a lint (that may encounter ambiguity)
/// [`Instance::expect_resolve`] instead.

Also, this recommends expect_resolve twice now...

@compiler-errors
Copy link
Member Author

@bors r=lcnr rollup

@bors
Copy link
Collaborator

bors commented Apr 28, 2025

📌 Commit 8f55844 has been approved by lcnr

It is now in the queue for this repository.

ChrisDenton added a commit to ChrisDenton/rust that referenced this pull request Apr 28, 2025
…lcnr

Resolve instance for SymFn in global/naked asm

`Instance::expect_resolve` ensures that we're actually going from trait item -> impl item.

Fixes rust-lang#140373
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 28, 2025
…enton

Rollup of 9 pull requests

Successful merges:

 - rust-lang#139308 (add autodiff inline)
 - rust-lang#140276 (Do not compute type_of for impl item if impl where clauses are unsatisfied)
 - rust-lang#140302 (Move inline asm check to typeck, properly handle aliases)
 - rust-lang#140323 (Implement the internal feature `cfg_target_has_reliable_f16_f128`)
 - rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
 - rust-lang#140391 (Rename sub_ptr to offset_from_unsigned in docs)
 - rust-lang#140394 (Make bootstrap git tests more self-contained)
 - rust-lang#140396 (Workaround for windows-gnu rust-lld test failure)
 - rust-lang#140402 (only return nested goals for `Certainty::Yes`)

r? `@ghost`
`@rustbot` modify labels: rollup
@ChrisDenton
Copy link
Member

failed in rollup #140411 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Link-time error when referencing symbols through generic types in naked_asm! block
7 participants