Stream: t-compiler/wg-mir-opt

Topic: const prop `Rvalue::Len`


oli (May 22 2019 at 14:05, on Zulip):

ooooh

Wesley Wiser (May 22 2019 at 14:06, on Zulip):

I think the main issue is some unimplemented Place handling in eval_place

oli (May 22 2019 at 14:06, on Zulip):

unimplemented?

Wesley Wiser (May 22 2019 at 14:06, on Zulip):

Unhandled is probably a better term

Wesley Wiser (May 22 2019 at 14:08, on Zulip):

For example, ProjectionElem::Deref falls into this branch https://github.com/rust-lang/rust/blob/37ff5d388f8c004ca248adb635f1cc84d347eda0/src/librustc_mir/transform/const_prop.rs#L312

oli (May 22 2019 at 14:09, on Zulip):

oh. Hmm... I think we should be able to do even Indexnowadays

oli (May 22 2019 at 14:09, on Zulip):

it would just be fairly unfun to do, maybe we can share more code with InterpCx, let's see

oli (May 22 2019 at 14:12, on Zulip):

hmmmmmm. evil idea: we can actually create the stackframe of the InterpCx used in const propagation and just treat all kinds of errors as "don't propagate"

Wesley Wiser (May 22 2019 at 14:12, on Zulip):

There's a comment about using ecx.operand_projection() but it seems to imply that doesn't work because we don't have a proper evaluation stack?

Wesley Wiser (May 22 2019 at 14:12, on Zulip):

Interesting

oli (May 22 2019 at 14:12, on Zulip):

yea, InterpCx has a fake Frame

oli (May 22 2019 at 14:13, on Zulip):

fake meaning: no local variables

oli (May 22 2019 at 14:13, on Zulip):

but I mean, nowadays we are keeping around our own local variables

Wesley Wiser (May 22 2019 at 14:13, on Zulip):

Ok

oli (May 22 2019 at 14:13, on Zulip):

I haven't looked at it too closely

oli (May 22 2019 at 14:13, on Zulip):

but it may be an avenue we can go into in the future

Wesley Wiser (May 22 2019 at 14:13, on Zulip):

I'd started going down the path of implementing support for Deref and some other stuff but it was beginning to feel like I was just duplicating operand_projection()

oli (May 22 2019 at 14:14, on Zulip):

for now, you are mainly missing Deref right now for Len?

Wesley Wiser (May 22 2019 at 14:14, on Zulip):

There's at least another Place case I need to implement as well. Something to do with the other StaticKinds https://github.com/rust-lang/rust/blob/37ff5d388f8c004ca248adb635f1cc84d347eda0/src/librustc_mir/transform/const_prop.rs#L315

oli (May 22 2019 at 14:15, on Zulip):

hmm... what happens if you just invoke operand_projection?

oli (May 22 2019 at 14:16, on Zulip):

oh that calls ref_to_mplace

oli (May 22 2019 at 14:16, on Zulip):

not good

Wesley Wiser (May 22 2019 at 14:17, on Zulip):

Because it returns an mplace or because of const eval stuff?

Wesley Wiser (May 22 2019 at 14:17, on Zulip):

Sorry, miri is still kind of a black box to me

oli (May 22 2019 at 14:20, on Zulip):

yea, mplace would point into the local stack

oli (May 22 2019 at 14:20, on Zulip):

it may work out, but InterpCx is not setup to handle thsi

oli (May 22 2019 at 14:20, on Zulip):

*this

oli (May 22 2019 at 14:20, on Zulip):

so for now, feel free to create some duplication

oli (May 22 2019 at 14:20, on Zulip):

I'll look into merging miri and const prop

Wesley Wiser (May 22 2019 at 14:21, on Zulip):

Does the mplace stuff impact interpreting Immediates? That's another thing on my list to add support for

oli (May 22 2019 at 14:21, on Zulip):

what do you mean by "interpreting"? like operations on Immediate?

Wesley Wiser (May 22 2019 at 14:21, on Zulip):

We hit that in https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/const.20propagation/near/165707831

Wesley Wiser (May 22 2019 at 14:21, on Zulip):

Yeah

Wesley Wiser (May 22 2019 at 14:21, on Zulip):

Const propagating I should say

oli (May 22 2019 at 14:37, on Zulip):

hmm

oli (May 22 2019 at 14:37, on Zulip):

ok, this may actually work

oli (May 22 2019 at 14:37, on Zulip):

even with the mplace

oli (May 22 2019 at 14:38, on Zulip):

because if you input an Immediate, and it is a Pointer, then the Allocation exists, and we can read from it, never even looking at the stack

oli (May 22 2019 at 14:38, on Zulip):

so yea, just call operand_projection

Wesley Wiser (May 22 2019 at 14:39, on Zulip):

Ok

Wesley Wiser (May 22 2019 at 14:40, on Zulip):

Thanks for your help btw, I really enjoy working in this part of the compiler! :slight_smile:

oli (May 22 2019 at 14:42, on Zulip):

and if you have an Indirect e.g. after casting, you should be able to try_read_immediate

oli (May 22 2019 at 14:43, on Zulip):

great you like it! I think it's a fun part, too

Wesley Wiser (May 28 2019 at 15:19, on Zulip):

I'm going to close #61081 for now since:

1. The current implementation has some undesirable changes like the stuff to support statics and bare slices
2. I don't see anyway to actually exercise the code that handles the Len operand and I don't think we should be adding dead code to the compiler
However, I think this comment about supporting propagation from let bindings has some potential so I'm going to play with that a bit.

oli (May 29 2019 at 07:14, on Zulip):

have you tried doing it all in one expressions so it'd all be temporaries? Like (&[5, 6] as &[u8])[42]?

Wesley Wiser (May 29 2019 at 11:49, on Zulip):

I tried that but as doesn't want to do the cast:

error[E0605]: non-primitive cast: `&[i32; 2]` as `&[u8]`
 --> src/main.rs:3:13
  |
3 |     let x = (&[5, 6] as &[u8]);
  |             ^^^^^^^^^^^^^^^^^^
  |
  = note: an `as` expression can only be used to convert between primitive types. Consider using the `From` trait
oli (May 29 2019 at 11:51, on Zulip):

oh well, inference strikes again

oli (May 29 2019 at 11:51, on Zulip):

&[5, 6] as &[i32] or &[5u8, 6] as &[u8]

Wesley Wiser (May 29 2019 at 12:01, on Zulip):

Ah ok

Wesley Wiser (May 29 2019 at 12:01, on Zulip):

I thought it was complaining because of the array -> slice conversion

Last update: Nov 17 2019 at 06:55UTC