Stream: t-compiler/wg-mir-opt

Topic: const prop `len` function on unpropped arrays


oli (Sep 24 2019 at 21:14, on Zulip):

@Wesley Wiser idea by @Santiago Pastorino: if we have a runtime value of array type and we call len on it, we should still const prop that call, because its result is obviously known

oli (Sep 24 2019 at 21:14, on Zulip):

I think it can be done without much additional magic

oli (Sep 24 2019 at 21:15, on Zulip):

some magic may still be required in the unsizing cast

oli (Sep 24 2019 at 21:15, on Zulip):

basically the data pointer would be Undef and only the length would be set

Wesley Wiser (Sep 24 2019 at 21:15, on Zulip):

I feel like I looked at writing an optimization to do that like a year ago and found it already happened.

oli (Sep 24 2019 at 21:16, on Zulip):

something similar could be done for vtable casts

oli (Sep 24 2019 at 21:16, on Zulip):

huh

Wesley Wiser (Sep 24 2019 at 21:17, on Zulip):

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=122730c2a83131198a16080ac6f7a562

oli (Sep 24 2019 at 21:17, on Zulip):

we don't even propagate function calls yet, so I don't see how that could happen (well in llvm it probably will)

Wesley Wiser (Sep 24 2019 at 21:17, on Zulip):

Unless I'm misunderstanding the case you're thinking of

oli (Sep 24 2019 at 21:17, on Zulip):

ah

oli (Sep 24 2019 at 21:17, on Zulip):

yes the Len statement works

oli (Sep 24 2019 at 21:18, on Zulip):

I literally mean [T]::len

Wesley Wiser (Sep 24 2019 at 21:18, on Zulip):

Ah

oli (Sep 24 2019 at 21:18, on Zulip):

so if the user writes some_arg.len()

Wesley Wiser (Sep 24 2019 at 21:18, on Zulip):

Gotcha

oli (Sep 24 2019 at 21:18, on Zulip):

though it may just work

oli (Sep 24 2019 at 21:19, on Zulip):

since the miri engine may do the unsizing cast without ever checking whether the pointer is Undef

Wesley Wiser (Sep 24 2019 at 21:19, on Zulip):

We've got to get const prop turned on for mir-level < 2 first :p

Wesley Wiser (Sep 24 2019 at 21:19, on Zulip):

As it is, miri and src/test/mir-opt are pretty much the only things that actually do the optimization.

oli (Sep 24 2019 at 21:20, on Zulip):

whoops

oli (Sep 24 2019 at 21:20, on Zulip):

I don't remember the blockers for that

oli (Sep 24 2019 at 21:21, on Zulip):

https://github.com/rust-lang/rust/blob/6ef275e6c3cb1384ec78128eceeb4963ff788dca/src/librustc_mir/interpret/cast.rs#L256 yay, the engine does the right thing

Wesley Wiser (Sep 24 2019 at 21:21, on Zulip):

I don't know either

Wesley Wiser (Sep 24 2019 at 21:21, on Zulip):

lol

oli (Sep 24 2019 at 21:21, on Zulip):

so we just need to start const propping arguments now?! XD

Wesley Wiser (Sep 24 2019 at 21:21, on Zulip):

Once we do function calls, we can do that I think

oli (Sep 24 2019 at 21:22, on Zulip):

oh, for function calls we don't need to do any argument propping

oli (Sep 24 2019 at 21:22, on Zulip):

we never do any const prop for function call bodies, that will be all in the miri engine

Santiago Pastorino (Sep 24 2019 at 21:23, on Zulip):

all these stuff seems exciting :)

Wesley Wiser (Sep 24 2019 at 21:24, on Zulip):

Well this at least was motivated because doing things with args in ConstProp was ICE-ing the compiler https://github.com/rust-lang/rust/pull/64419/commits/281cfbf6c38b3d9b3d50b48857e48dab93a0f3aa

Wesley Wiser (Sep 24 2019 at 21:25, on Zulip):

Er, I guess the better link was my original change

Wesley Wiser (Sep 24 2019 at 21:25, on Zulip):

https://github.com/rust-lang/rust/pull/64419/commits/39d6305ef918858ae871da815040ebfc91612a49

Wesley Wiser (Sep 24 2019 at 21:25, on Zulip):

Since that shows the conversation

Wesley Wiser (Sep 24 2019 at 21:26, on Zulip):

Anyway I've got to run :wave:

oli (Sep 24 2019 at 21:26, on Zulip):

:wave:

Last update: Nov 17 2019 at 08:15UTC