Stream: t-compiler/const-eval

Topic: const in array repeat expressions


RalfJ (Jul 19 2019 at 11:17, on Zulip):

@eddyb @davidtwco @Matthew Jasper any idea why "const array repeat expressions" don't work in liballoc even with the feature set? See https://github.com/rust-lang/rust/commit/4c2c7e0cc9b2b589fe2bab44173acc2170b20c09 for the code, and https://github.com/rust-lang/rust/issues/53491#issuecomment-513147996 for the error. Inlining the macro makes no difference so that's not it.

RalfJ (Jul 19 2019 at 11:21, on Zulip):

maybe the problem is that he const fn being called is not in the same crate?

RalfJ (Jul 19 2019 at 11:21, on Zulip):

I seem to recall that being an issue for some stuff @oli did in the past. Seems like a bad footgun.

oli (Jul 19 2019 at 11:56, on Zulip):

Did you enable the appropriate feature gate for the method to be const fn

eddyb (Jul 19 2019 at 12:08, on Zulip):

@RalfJ are you trying to use it at stage0?

eddyb (Jul 19 2019 at 12:09, on Zulip):

hmm, looks like no

eddyb (Jul 19 2019 at 12:09, on Zulip):

@RalfJ @oli ohhh you need to manually allow promotion on MaybeUninit::uninit

eddyb (Jul 19 2019 at 12:09, on Zulip):

ugh this is annoying

eddyb (Jul 19 2019 at 12:10, on Zulip):

@oli @RalfJ can we special-case zero-arg const fn's as always promotable? they're effectively constants that you call like a function for no real reason other than aesthetics :P

eddyb (Jul 19 2019 at 12:11, on Zulip):

we should even intern their computation like constants

eddyb (Jul 19 2019 at 12:11, on Zulip):

not unlike the zero-arg intrinsics that are supported by CTFE, now that I think about it

RalfJ (Jul 19 2019 at 12:26, on Zulip):

RalfJ oli ohhh you need to manually allow promotion on MaybeUninit::uninit

promotion is involved, then? also why does it work in libcore?

RalfJ (Jul 19 2019 at 12:27, on Zulip):

oli RalfJ can we special-case zero-arg const fn's as always promotable? they're effectively constants that you call like a function for no real reason other than aesthetics :P

please no let's not make more things promotable^^

eddyb (Jul 19 2019 at 12:27, on Zulip):

ugh

RalfJ (Jul 19 2019 at 12:29, on Zulip):

@eddyb is right though in the sense that adding #[rustc_promotable] to MaybeUninit::uninit fixes it

RalfJ (Jul 19 2019 at 12:29, on Zulip):

but why is that not needed within the same crate?

eddyb (Jul 19 2019 at 12:29, on Zulip):

alternatively, we could move the Copy analysis involved here into the borrowck but id khow much I like that

eddyb (Jul 19 2019 at 12:29, on Zulip):

@RalfJ that it works same-crate without promotable is weird

eddyb (Jul 19 2019 at 12:29, on Zulip):

maybe report as a bug, especially if you can repro in a small standalone crate

eddyb (Jul 19 2019 at 12:31, on Zulip):

@RalfJ so, some back story: this idea that [expr; n] could use promotion on expr to bypass the Copy requirement... predates the discovery of how annoying promoting const fn's is

RalfJ (Jul 19 2019 at 12:32, on Zulip):

funny that I wrote a comment about promotion and array-repeat earlier today without having any idea^^

RalfJ (Jul 19 2019 at 12:32, on Zulip):

https://github.com/rust-lang/rust/issues/49147#issuecomment-513148454

RalfJ (Jul 19 2019 at 12:33, on Zulip):

and no I cannot repro... seems to be a libcore magic thing

RalfJ (Jul 19 2019 at 12:38, on Zulip):

oh

RalfJ (Jul 19 2019 at 12:39, on Zulip):

I think the uses in libcore just are Copy, actually^^

RalfJ (Jul 19 2019 at 12:42, on Zulip):

yeah. since introducing the macro we got MaybeUninit<T>: Copy if T: Copy, so it's not as needed any more as it was. but in liballoc it still truly is needed.

RalfJ (Jul 19 2019 at 12:50, on Zulip):

see https://github.com/rust-lang/rust/pull/62799

oli (Jul 20 2019 at 06:08, on Zulip):

@eddyb let's rather add AnonConst as something users can write via const{} blocks or sth

oli (Jul 20 2019 at 06:09, on Zulip):

We can even create diagnostics suggesting such blocks in case some code errors due to not getting promoted when it could have been const

eddyb (Jul 20 2019 at 13:31, on Zulip):

ugh

eddyb (Jul 20 2019 at 13:32, on Zulip):

I mean, feel free to RFC it

eddyb (Jul 20 2019 at 13:32, on Zulip):

but it will be a minor nightmare

eddyb (Jul 20 2019 at 13:33, on Zulip):

unlike consts of array lengths or const generic path args, for example, you'll need shared inference with the parent

oli (Jul 20 2019 at 14:11, on Zulip):

Hm

RalfJ (Jul 20 2019 at 20:47, on Zulip):

a replacement for (complex) promotion would also need to share inference with the parent though I guess?

Last update: Nov 15 2019 at 20:45UTC