Stream: t-compiler

Topic: associated const in array size


Simon Sapin (Apr 07 2020 at 14:38, on Zulip):

Associated consts cannot be used in array sizes today: https://github.com/rust-lang/rust/issues/61730
I have some recollection that fixing this is almost as complex as implementing const generics. Is that the case?

eddyb (Apr 07 2020 at 14:38, on Zulip):

@Simon Sapin completely orthogonal

eddyb (Apr 07 2020 at 14:38, on Zulip):

also why does that issue exist?

eddyb (Apr 07 2020 at 14:39, on Zulip):

@Simon Sapin the only place where they really intersect is #[feature(const_generics)] turns on the fix for #43408 (which is like a one-line thing in one place in the compiler) which can break code

eddyb (Apr 07 2020 at 14:40, on Zulip):

the trick is letting people use parameters in array lengths without breaking stable code and we've been paranoid (or at least I have been) about this aspect

eddyb (Apr 07 2020 at 14:41, on Zulip):

"lazy normalization" is the feature that solves this uniformly without breaking stable code, and there are PRs open related to it (finally), but it seems to be moving slow

Simon Sapin (Apr 07 2020 at 14:42, on Zulip):

@eddyb What kind of breakage does this cause?

eddyb (Apr 07 2020 at 14:42, on Zulip):

query cycle errors

eddyb (Apr 07 2020 at 14:42, on Zulip):

due to circular dependencies between something using a constant expression and the constant expression itself

eddyb (Apr 07 2020 at 14:42, on Zulip):

most notably visible when arrays are used in impl headers and anything's where clauses

eddyb (Apr 07 2020 at 14:43, on Zulip):

but it might be more than that, we're not sure of the extent to which things break

eddyb (Apr 07 2020 at 14:44, on Zulip):

@Simon Sapin in the meanwhile, I've opened #70452 to try and carve out subsets, because @Esteban K├╝ber was getting impatient and wanted to add diagnostics to deal with the confusion caused by #43408

eddyb (Apr 07 2020 at 14:44, on Zulip):

it's in crater now and if this is a success we can move to array types

eddyb (Apr 07 2020 at 14:44, on Zulip):

I'm sorry I didn't do this years ago, this was the correct thing to do

eddyb (Apr 07 2020 at 14:44, on Zulip):

I just didn't think of blacklist vs whitelist

Simon Sapin (Apr 07 2020 at 14:45, on Zulip):

Yeah the "add a bound" (which is already there) diagnostic is confusing

Simon Sapin (Apr 07 2020 at 14:45, on Zulip):

No worries, thanks for taking care of it

eddyb (Apr 07 2020 at 14:46, on Zulip):

@Simon Sapin bonus: you can figure out if a crate would break w/o lazy normalization by adding #![feature(const_generics)] to it :P

eddyb (Apr 07 2020 at 14:46, on Zulip):

it's what I've been doing to test things out before I make the actual change

eddyb (Apr 07 2020 at 14:47, on Zulip):

we wanted to let people write [T; N+1] even though WF restrictions means it's kind of useless :P

eddyb (Apr 07 2020 at 14:47, on Zulip):

(until #68436 is solved)

eddyb (Apr 07 2020 at 14:48, on Zulip):

maybe I should've made it another opt-in but eh

eddyb (Apr 07 2020 at 14:48, on Zulip):

I think people's const-generics-using crates did break (with query cycle errors) when we made it opt into fixing #43408, so it's not a theoretical problem

Last update: May 29 2020 at 17:45UTC