Stream: t-compiler/help

Topic: Const support for asm


Amanieu (May 09 2020 at 19:24, on Zulip):

I'm having a bit of trouble with const support for asm! (that is, taking integer constants and embedding them directly into the asm string).

Amanieu (May 09 2020 at 19:24, on Zulip):

Basically, ConstValue::try_to_bits_for_ty is failing here because the ConstValue is not a Scalar.

Amanieu (May 09 2020 at 19:26, on Zulip):

This happens because asm! uses constant promotion (following the same logic as #[rustc_args_required_const]), but this always results in a ConstValue::ByRef instead of a ConstValue::Scalar even though I've already checked that the input type is an integer or a float.

Amanieu (May 09 2020 at 19:27, on Zulip):

The cause seems to be this code in eval_queries.rs which always uses ByRef for promoted constants.

Amanieu (May 09 2020 at 19:28, on Zulip):

Do you have any suggestions on how const operands should be handled?

Amanieu (May 09 2020 at 19:29, on Zulip):

cc @oli since you seem to have written the code that forces ByRef for promoted constants.

oli (May 11 2020 at 09:48, on Zulip):

we force ByRef, because promoteds used to be just those that you took references to

oli (May 11 2020 at 09:49, on Zulip):

we could have some way to differentiate between value and ref promoteds

oli (May 11 2020 at 09:52, on Zulip):

less invasive would be to teach all the to_bits logic to read from a ByRef

oli (May 11 2020 at 09:53, on Zulip):

but that feels like we're running dangerously close to mixing up const values and static memory locations containing const values

oli (May 11 2020 at 09:54, on Zulip):

since you know it's always ByRef, you can just match on that and bug! out in all other cases and use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/interpret/struct.Allocation.html#method.read_scalar to read a scalar from that allocation

oli (May 11 2020 at 09:55, on Zulip):

or, if you feel like this will only ever allow usize, use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_mir/interpret/struct.Allocation.html#method.read_ptr_sized

Amanieu (May 11 2020 at 16:45, on Zulip):

@oli Thanks! I got it to work.

Last update: Sep 28 2020 at 16:00UTC