Skip to content

Resolve instance for SymFn in global/naked asm - #140374

Merged
bors merged 2 commits into
rust-lang:masterfrom
compiler-errors:global_asm-bug
May 6, 2025
Merged

Resolve instance for SymFn in global/naked asm#140374
bors merged 2 commits into
rust-lang:masterfrom
compiler-errors:global_asm-bug

Conversation

@compiler-errors

Copy link
Copy Markdown
Contributor

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

Fixes#140373

@rustbot

Copy link
Copy Markdown
Collaborator

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

@rustbotrustbot 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
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

Comment threadtests/ui/asm/naked-asm-mono-sym-fn.rs Outdated
@lcnr

lcnr commented Apr 28, 2025

Copy link
Copy Markdown
Contributor

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

@rustbot

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
ContributorAuthor

@bors r=lcnr rollup

@bors

bors commented Apr 28, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 844b1e2 has been approved by lcnr

It is now in the queue for this repository.

@borsbors 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.

@RalfJungRalfJungApr 28, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.

@lcnrlcnrApr 28, 2025

Copy link
Copy Markdown
Contributor

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"

@RalfJungRalfJungApr 28, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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.

@RalfJungRalfJungApr 28, 2025

Copy link
Copy Markdown
Member

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
Copy Markdown
ContributorAuthor

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-errorsforce-pushed the global_asm-bug branch 3 times, most recently from d30ad80 to 9ac697fCompareApril 28, 2025 15:48
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

@bors r=lcnr

@bors

bors commented Apr 28, 2025

Copy link
Copy Markdown
Collaborator

📌 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
Copy Markdown
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
Copy Markdown
ContributorAuthor

@bors r=lcnr rollup

@bors

bors commented Apr 28, 2025

Copy link
Copy Markdown
Collaborator

📌 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.
Fixesrust-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
Copy Markdown
Member

failed in rollup #140411 (comment)

@bors r-

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 30, 2025
…w, r=<try>
Less `Instance::new_raw`
For perf. Based on rust-lang#140374.
r? `@ghost`
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 30, 2025
…iaskrgr
Rollup of 9 pull requests
Successful merges:
- rust-lang#134232 (Share the naked asm impl between cg_ssa and cg_clif)
- rust-lang#139624 (Don't allow flattened format_args in const.)
- rust-lang#140090 (Check bare function idents for non snake-case name)
- rust-lang#140203 (Issue an error when using `no_mangle` on language items)
- rust-lang#140450 (ast: Remove token visiting from AST visitor)
- rust-lang#140498 (Misc tweaks to HIR typeck (mostly w.r.t. checking calls))
- rust-lang#140504 (transmutability: ensure_sufficient_stack when answering query)
- rust-lang#140506 (unstable-book: fix capitalization)
- rust-lang#140516 (Replace use of rustc_type_ir by rustc_middle)
Failed merges:
- rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors

bors commented Apr 30, 2025

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #140520) made this pull request unmergeable. Please resolve the merge conflicts.

@borsbors 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 30, 2025
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

@bors r=lcnr

@bors

bors commented Apr 30, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 0b3b674 has been approved by lcnr

It is now in the queue for this repository.

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 30, 2025
@rust-log-analyzer

This comment has been minimized.

@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

@bors r-

@borsbors 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 May 1, 2025
@compiler-errors

Copy link
Copy Markdown
ContributorAuthor

@bors r=lcnr

@bors

bors commented May 5, 2025

Copy link
Copy Markdown
Collaborator

📌 Commit 833c212 has been approved by lcnr

It is now in the queue for this repository.

@borsbors 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 5, 2025
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request May 5, 2025
…lcnr
Resolve instance for SymFn in global/naked asm
`Instance::expect_resolve` ensures that we're actually going from trait item -> impl item.
Fixesrust-lang#140373
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
…llaumeGomez
Rollup of 11 pull requests
Successful merges:
- rust-lang#139764 (Consistent trait bounds for ExtractIf Debug impls)
- rust-lang#140035 (Implement RFC 3503: frontmatters)
- rust-lang#140080 (mir-opt: Use one MirPatch in MatchBranchSimplification)
- rust-lang#140115 (mir-opt: execute MatchBranchSimplification after GVN)
- rust-lang#140357 (bypass linker configuration and cross target check on `x check`)
- rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
- rust-lang#140393 (std: get rid of `sys_common::process`)
- rust-lang#140532 (Fix RustAnalyzer discovery of rustc's `stable_mir` crate)
- rust-lang#140559 (Removing rustc_type_ir in the rustc_infer codebase)
- rust-lang#140636 (implement `PanicTracker` to track `t` panics)
- rust-lang#140661 (Make `-Zfixed-x18` into a target modifier)
r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request May 5, 2025
…llaumeGomez
Rollup of 11 pull requests
Successful merges:
- rust-lang#140080 (mir-opt: Use one MirPatch in MatchBranchSimplification)
- rust-lang#140115 (mir-opt: execute MatchBranchSimplification after GVN)
- rust-lang#140357 (bypass linker configuration and cross target check on `x check`)
- rust-lang#140374 (Resolve instance for SymFn in global/naked asm)
- rust-lang#140559 (Removing rustc_type_ir in the rustc_infer codebase)
- rust-lang#140605 (`fn check_opaque_type_parameter_valid` defer error)
- rust-lang#140636 (implement `PanicTracker` to track `t` panics)
- rust-lang#140661 (Make `-Zfixed-x18` into a target modifier)
- rust-lang#140670 (calculate step duration in a panic-safe way)
- rust-lang#140672 (Deeply normalize in the new solver in WF)
- rust-lang#140676 (Update books)
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit 1e90557 into rust-lang:masterMay 6, 2025
@rustbotrustbot added this to the 1.88.0 milestone May 6, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request May 6, 2025
Rollup merge of rust-lang#140374 - compiler-errors:global_asm-bug, r=lcnr
Resolve instance for SymFn in global/naked asm
`Instance::expect_resolve` ensures that we're actually going from trait item -> impl item.
Fixesrust-lang#140373
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

8 participants

@compiler-errors@rustbot@lcnr@bors@ChrisDenton@rust-log-analyzer@RalfJung@davidtwco