-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tweak type inference for const
operands in inline asm
#125558
Conversation
rustbot has assigned @michaelwoerister. Use |
Unfortunately this fails in tests when an invalid type is passed to
This happens because the invalid type now reaches a later compilation stage and is processed by the borrow checker. This seems similar to #96304. @compiler-errors had a PR to fix this in #116087 but that was closed. I'm not exactly sure what the correct approach is for solving this. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
// - Typeck has checked that Const operands are integers. | ||
// - AST lowering guarantees that SymStatic points to a static. | ||
hir::InlineAsmOperand::Const { .. } | hir::InlineAsmOperand::SymStatic { .. } => {} | ||
hir::InlineAsmOperand::Const { anon_const } => { |
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.
a suggestion: you can move this check into fn anon_const_type_of
and return the returned type with ty::Error
if it's not an int. THis should also fix the ICE in mir borrowck
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 tried this here master...folkertdev:rust:const-asm-type-fix and that makes the test work! However, error messages are now emitted out of order. I'm not sure how big a problem that is, and how to fix it if needed.
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.
as an extra note, this issue appears to be entirely unrelated to #96304, lifetimes work fine in these const expressions.
core::arch::global_asm!("/* {} */", const Foo::<'static>::X);
struct Foo<'a>(&'a ());
impl<'a> Foo<'a> {
const X: u64 = 42;
}
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.
👍 yeah, that's my preferred solution, though I'd maybe keep the check in intrinsicck
as an assert in case type_of
gets changed in the future. I don't think the message order is something we should worry about here.
@rustbot ready |
Ty::new_error_with_message( | ||
tcx, | ||
span, | ||
format!("invalid type for `sym` operand"), |
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.
use the ErrorGuaranteed
from the above emit
Ty::new_error_with_message( | ||
tcx, | ||
span, | ||
format!("invalid type for `const` operand"), |
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.
same here
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Previously these would be treated like integer literals and default to `i32` if a type could not be determined. To allow for forward-compatibility with `str` constants in the future, this PR changes type inference to use an unbound type variable instead. The actual type checking is deferred until after typeck where we still ensure that the final type for the `const` operand is an integer type.
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
time to try again? or should we try some specific things? messing with the asm tests is kind of annoying, maybe we could have some sort of lint for the |
Failed to set assignee to
|
ok lol I can't mark this as ready, @Amanieu can you do that? |
@rustbot ready |
@folkertdev what did you change since the last merge attempt? Would like to avoid having unstable tests in the ui test suite 🤔 could you try and look through the backtrace for the error to check where a hashmap may be involved as suggested by @oli-obk. Alternatively, put the backtrace into a gist and I can take a quick look |
since the last merge attempt, only eb726a5 was added because that broke a test. The tests in question are, based on the CI that we've run so far, completely stable in their current form. In any case, here is a reduced testcase that, based on my understanding of the problem, should have the error in CI https://gist.github.com/folkertdev/1afae9ede304e8c14040458039bd70c3 it triggers the same error using an invalid "hash" does not occur, so it might be something different. But again, to my knowledge, this is not a problem any more for the current PR. |
@bors r+ |
Tweak type inference for `const` operands in inline asm Previously these would be treated like integer literals and default to `i32` if a type could not be determined. To allow for forward-compatibility with `str` constants in the future, this PR changes type inference to use an unbound type variable instead. The actual type checking is deferred until after typeck where we still ensure that the final type for the `const` operand is an integer type. <!-- If this PR is related to an unstable feature or an otherwise tracked effort, please link to the relevant tracking issue here. If you don't know of a related tracking issue or there are none, feel free to ignore this. This PR will get automatically assigned to a reviewer. In case you would like a specific user to review your work, you can assign it to them by using r? <reviewer name> -->
Rollup of 8 pull requests Successful merges: - rust-lang#122049 (Promote riscv64gc-unknown-linux-musl to tier 2) - rust-lang#125558 (Tweak type inference for `const` operands in inline asm) - rust-lang#128638 (run-make: enable msvc for `link-dedup`) - rust-lang#128647 (Enable msvc for link-args-order) - rust-lang#128649 (run-make: Enable msvc for `no-duplicate-libs` and `zero-extend-abi-param-passing`) - rust-lang#128656 (Enable msvc for run-make/rust-lld) - rust-lang#128688 (custom MIR: add support for tail calls) - rust-lang#128691 (Update `compiler-builtins` to 0.1.115) r? `@ghost` `@rustbot` modify labels: rollup
☀️ Test successful - checks-actions |
Finished benchmarking commit (c9687a9): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -2.1%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (secondary -6.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 761.437s -> 762.407s (0.13%) |
…m-const, r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang#129462 fixes rust-lang#126896 fixes rust-lang#124164 I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? `@lcnr`
…m-const, r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang#129462 fixes rust-lang#126896 fixes rust-lang#124164 I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? ``@lcnr``
…m-const, r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang#129462 fixes rust-lang#126896 fixes rust-lang#124164 I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? ```@lcnr```
…m-const, r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang#129462 fixes rust-lang#126896 fixes rust-lang#124164 I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? ````@lcnr````
Rollup merge of rust-lang#129472 - folkertdev:const-refs-to-static-asm-const, r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang#129462 fixes rust-lang#126896 fixes rust-lang#124164 I think this is a case that was missed in the fix for rust-lang#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? ``@lcnr``
…r=lcnr fix ICE when `asm_const` and `const_refs_to_static` are combined fixes rust-lang/rust#129462 fixes #126896 fixes #124164 I think this is a case that was missed in the fix for rust-lang/rust#125558, which inserts a type error in the case of an invalid (that is, non-integer) type being passed to an asm `const` operand. I'm not 100% sure that `span_mirbug_and_err` is the right macro here, but it is used earlier with `builtin_deref` and seems to do the trick. r? ``@lcnr``
Previously these would be treated like integer literals and default to
i32
if a type could not be determined. To allow for forward-compatibility withstr
constants in the future, this PR changes type inference to use an unbound type variable instead.The actual type checking is deferred until after typeck where we still ensure that the final type for the
const
operand is an integer type.