Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upTracking issue for RFC 2342, "Allow `if` and `match` in constants" #49146
Comments
Centril
added
B-RFC-approved
T-lang
C-tracking-issue
labels
Mar 18, 2018
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@eddyb A good starting point would probably be to take my |
This comment has been minimized.
This comment has been minimized.
|
Any news on this? |
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m Alas no. I think @eddyb has been very busy indeed, because I've not even been able to ping him on IRC for the last few weeks hah. Sadly my const-qualif branch doesn't even compile since I last rebased it over master. (I don't believe I've pushed yet though.)
|
This comment has been minimized.
This comment has been minimized.
|
Okay, funnily enough, I rebased again just today and it seems to be building all fine now! Looks like there was a regression, and it just got fixed. All over to @eddyb now. |
This comment has been minimized.
This comment has been minimized.
|
@alexreg Sorry, I've switched to a local sleep schedule and I see you've pinged me when I wake up but then you're offline all day when I'm awake (ugh timezones). |
This comment has been minimized.
This comment has been minimized.
|
@eddyb That's alright heh. You must be off to bed early, since I'm usually on from 8:00PM GMT, but it's all good! :-) |
kennytm
added a commit
to kennytm/rust
that referenced
this issue
Apr 30, 2018
hdhoang
referenced this issue
May 2, 2018
Merged
lint: deny incoherent_fundamental_impls by default #50390
This comment has been minimized.
This comment has been minimized.
|
I'm really sorry, took me a while to realize that the series of patches in question requires removing #![feature(const_fn)]
const fn read<T: Copy>(x: &T) -> T { *x }
static FOO: u32 = read(&BAR);
static BAR: u32 = 5;
fn main() {
println!("{}", FOO);
}This is not detected statically, instead So I think reading I think then we can keep statically denying mentioning Do we need an RFC for this? |
This comment has been minimized.
This comment has been minimized.
|
Sounds fair w.r.t. reading from statics. Doubt it needs an RFC, maybe just a crater run, but then I’m probably not the best one to say. |
This comment has been minimized.
This comment has been minimized.
|
Note that we wouldn't be restricting anything, we'd be relaxing a restriction that's already broken. |
This comment has been minimized.
This comment has been minimized.
|
Oh, I misread. So const evaluation would still be sound, just not referentially transparent? |
This comment has been minimized.
This comment has been minimized.
|
The last paragraph describes a referentially transparent approach (but we lose that property if we start allowing mentioning |
This comment has been minimized.
This comment has been minimized.
|
Well, "dangling pointer" sure sounds like a soundness issue, but I'll trust you on this! |
This comment has been minimized.
This comment has been minimized.
|
"dangling pointer" is a bad error message, that's just miri forbidding reading from (from IRC) To summarize, referentially transparent |
This comment has been minimized.
This comment has been minimized.
|
I do like preserving referential transparency so @eddyb's idea sounds fantastic! |
This comment has been minimized.
This comment has been minimized.
|
Yeah I’m pro making const fns pure as well. |
This comment has been minimized.
This comment has been minimized.
|
Please note that certain seemingly harmless plans could ruin referential transparency, e.g.: let x = 0;
let non_deterministic = &x as *const _ as usize;
if non_deterministic.count_ones() % 2 == 0 {
// do one thing
} else {
// do a completely different thing
}This would fail with a miri error at compile-time, but would be non-deterministic at runtime (because we can't mark that memory address as "abstract" like miri can). EDIT: @Centril had the idea of making certain raw pointer operations (such as comparisons and casts to integers) |
This comment has been minimized.
This comment has been minimized.
|
Depends what you mean by "harmless"... I can certainly see reason we'd want to ban such non-deterministic behaviour. |
bors
added a commit
that referenced
this issue
May 8, 2018
This comment has been minimized.
This comment has been minimized.
lachlansneff
commented
Jun 18, 2018
|
It would be fantastic if work were continued on this. |
This comment has been minimized.
This comment has been minimized.
|
@lachlansneff It's moving... not as quickly as we'd like, but work is being done. At the moment we're waiting on #51110 as a blocker. |
This comment has been minimized.
This comment has been minimized.
lachlansneff
commented
Jun 18, 2018
|
@alexreg Ah, thank you. It would be very useful to be able to mark a match or if as const even when not in a const fn. |
This comment has been minimized.
This comment has been minimized.
programmerjake
commented
Aug 20, 2018
|
any status updates now that #51110 is merged? |
This comment has been minimized.
This comment has been minimized.
|
@programmerjake I'm waiting for some feedback from @eddyb on #52518 before it can get merged (hopefully very soon). He's been very busy lately (always in high demand), but he's gotten back to reviews and whatnot in the past few days, so I'm hopeful. After that, it will need some work by him personally, I suspect, since adding proper dataflow analysis is a complicated affair. We'll see though. |
mark-i-m
referenced this issue
Aug 21, 2018
Closed
[WIP] Preliminary work splitting const qualification into separate passes #52518
Centril
referenced this issue
Aug 21, 2018
Closed
Tracking issue for a minimal subset of RFC 911, const fn #53555
This comment has been minimized.
This comment has been minimized.
|
Somewhere to the TODO lists in the first post(s), it should be added to remove the current horrible hack that translates |
This comment has been minimized.
This comment has been minimized.
|
@RalfJung Wasn't that part of the old const eval, that's complete gone now that MIRI CTFE is in place? |
This comment has been minimized.
This comment has been minimized.
|
AFAIK we do that translation somewhere in HIR lowering, because we have code in Also,another point: @oli-obk said somewhere (but I cannot find where) that conditionals are somehow more complicated than one would naively think... was that "just" about the analysis for drop/interior mutability? |
This comment has been minimized.
This comment has been minimized.
I'm currently trying to clear that up. Will get back to you when I have all the information |
TimDiekmann
referenced this issue
Sep 3, 2018
Open
Tracking Issue for more const int functions #53718
This was referenced Dec 6, 2018
Centril
added
A-const-fn
A-const-eval
labels
Dec 31, 2018
This comment has been minimized.
This comment has been minimized.
|
What's the status of this? Is this in need of manpower or is it blocked on solving some problem? |
This comment has been minimized.
This comment has been minimized.
|
@mark-i-m It's blocked on implementing proper dataflow analysis for const qualification. @eddyb is the most knowledgeable in this area, and he had previously done some work on this. (So had I, but that sort of stagnated...) If @eddyb still doesn't have time, perhaps @oli-obk or @RalfJung could tackle this at some point soon. :-) |
This comment has been minimized.
This comment has been minimized.
|
#58403 is a small step towards dataflow-based qualification. |
Centril commentedMar 18, 2018
•
edited
This is a tracking issue for the RFC "Allow
ifandmatchin constants" (rust-lang/rfcs#2342).Steps:
letbindings in constants that use&&and||short circuiting operations. These are treated as&and|insideconstandstaticitems right now.Unresolved questions:
None