Stream: t-compiler/wg-mir-opt

Topic: uninhabited enum dead code elimination


Wesley Wiser (Oct 22 2019 at 01:58, on Zulip):

@oli Following up from this comment here, I've started working on implementing an optimization pass to remove dead code when switching on an enum with uninhabited variants. This is my first time implementing a MIR optimization from scratch so feedback is definitely appreciated! How does this look? https://github.com/rust-lang/rust/compare/master...wesleywiser:uninhabited_enum_variants_pass?expand=1

oli (Oct 22 2019 at 09:34, on Zulip):

I like it. The actual elimination is a bit convoluted, but I see no way around it. Maybe the values and targets fields of the SwitchInt variant could be merged into a single list, then one could use retain on the list

oli (Oct 22 2019 at 09:35, on Zulip):

the otherwise branch would then need a custom field, but that would be fine I think

oli (Oct 22 2019 at 09:35, on Zulip):

not sure how much other could would be affected by that (I think there's some code that just wants to know about all targets, but that could be helped by creating an accessor function returning an iterator)

Wesley Wiser (Oct 22 2019 at 09:57, on Zulip):

Thanks!

I like it. The actual elimination is a bit convoluted, but I see no way around it. Maybe the values and targets fields of the SwitchInt variant could be merged into a single list, then one could use retain on the list

Do you want me to start working on that as part of this change or leave it for another time?

oli (Oct 22 2019 at 10:08, on Zulip):

We can leave it for later. Please open an issue about it or leave a FIXME on the fields

Wesley Wiser (Oct 22 2019 at 10:13, on Zulip):

Ok. I'll open a PR with this and get a perf run started.

Last update: Nov 17 2019 at 07:40UTC