lang-team icon indicating copy to clipboard operation
lang-team copied to clipboard

const-evaluation

Open nikomatsakis opened this issue 5 years ago • 21 comments

Summary

Const-evaluation, language team impact

Links

nikomatsakis avatar Jun 11 '20 19:06 nikomatsakis

  • Oli working on skill-tree to help plan next steps for const-eval
    • loop and while (not for) is the next candidate for stabilization.
      • Main blocker was questions around qualification à la if and match.
      • Having if and match w/o loop and while will push people to use recursion for loops in a const context (I believe this happened with C++’s constexpr).
      • Having no for loops, which would require const trdait methods, is painful though.
  • Inline const { … } expressions (and patterns)
    • https://github.com/rust-lang/rfcs/pull/2920
    • Do we allow code inside a const { … } to depend on generic parameters?
    • Does unsafe { const { … } } allow unsafe operations inside the inline const?
      • See https://github.com/rust-lang/rust/issues/72359 for background
    • Do we allow const { … } in fallible patterns?

nikomatsakis avatar Jun 11 '20 19:06 nikomatsakis

nikomatsakis avatar Jun 11 '20 19:06 nikomatsakis

nikomatsakis avatar Jun 11 '20 19:06 nikomatsakis

  • #71824, Check for live drops in constants after drop elaboration
    • This is enabled by moving const-checking after drop elaboration
      • Additional precision in what is availible
      • Concern: This makes drop elaboration more of the public facing languge/”spec”
    • Drop elaboration removes most frivolous Drop terminators. It seems silly to duplicate this work during const-checking.
    • Allows Option::unwrap to become (unstably) const: https://github.com/rust-lang/rust/issues/66753
    • Does this want its own feature gate, or wrap into above? (nominated below)

nikomatsakis avatar Jun 11 '20 19:06 nikomatsakis

Update from meeting:

  • rust-lang/rust#71824 has been merged.

nikomatsakis avatar Jun 15 '20 19:06 nikomatsakis

2020-06-22:

  • Have the https://github.com/rust-lang/lang-team/issues/18 design meeting this week about the skill tree and unsafe and so forth.

nikomatsakis avatar Jun 22 '20 19:06 nikomatsakis

const_if_match and const_loop stabilization PR merged (rust-lang/rust#72437). On track for stabilization in 1.46.

ecstatic-morse avatar Jun 29 '20 19:06 ecstatic-morse

2020-07-06:

  • No updates we are aware of :)

nikomatsakis avatar Jul 06 '20 19:07 nikomatsakis

2020-08-3:

  • No updates

nikomatsakis avatar Aug 03 '20 19:08 nikomatsakis

2020-08-10:

  • No updates

joshtriplett avatar Aug 10 '20 19:08 joshtriplett

2020-08-31:

No updates.

nikomatsakis avatar Aug 31 '20 19:08 nikomatsakis

2020-09-21:

We have entered the "const evaluatable" check that allows you to have array sizes beyond [u8; N] (e.g., [u8; N+1]), but still lots of work before that would be considered possible on stable.

nikomatsakis avatar Sep 21 '20 19:09 nikomatsakis

@RalfJung opened https://github.com/rust-lang/rfcs/pull/3016 with the following summary:

Define how UB during const evaluation is treated: some kinds of UB must be detected, the rest leads to an unspecified result for the affected CTFE query (but does not otherwise "taint" the compilation process).

nikomatsakis avatar Nov 13 '20 16:11 nikomatsakis

The blog post (in the skill-tree meeting it was discussed that basically all that is missing is a blog post referencing the current status of the skill tree that the lang team will sign off on) is now also ready: https://github.com/rust-lang/blog.rust-lang.org/pull/719

oli-obk avatar Nov 13 '20 16:11 oli-obk

Status update

From my perspective, the main thing happening here that is relevant for t-lang is https://github.com/rust-lang/rfcs/pull/3016. This will unblock stabilizing some unsafe operations in const fn.

There's also a bunch of work going on under the hood on the implementation side (moving towards valtrees), but at least for now these should not have any visible effects. Longer-term I think this will be a great foundation for cleaning up our "structural equality" story around consts in patterns.

RalfJung avatar Apr 10 '21 08:04 RalfJung

https://github.com/rust-lang/rfcs/pull/3016 has been merged, we can now start stabilization requests to the lang team for individual unsafe things like transmute or raw pointer derefs.

valtrees are on ice until July and look promising except for some perf things that need to be figured out

there's some discussion going on around panics with user defined messages during CTFE

explicit promotion is being removed from the compiler (https://github.com/rust-lang/rust/pull/85110). It was only used for SIMD intrinsic array lengths. Instead one now needs to specify a constant item and reference that in the length argument. There's work going on to replace all of these "magic arguments that must be constant" with const generics. This should simplify the compiler further and avoid having multiple schemes that do the same thing in slightly different ways.

oli-obk avatar May 13 '21 01:05 oli-obk

I am particularly happy about the last point. :D We are almost done with the multi-year effort of cleaning up the story around promotion. There is one last thread left to discuss, see https://github.com/rust-lang/rust/issues/80619 for details.

RalfJung avatar May 13 '21 14:05 RalfJung

Status update

https://github.com/rust-lang/rust/pull/85769 has been proposed for FCP, as our first foray into wildly unsafe things inside const fn. The tricky part is that this breaks the property that const fn will be deterministic even when invoked at runtime. (However, if ptr-to-int transmutes are indeed UB at runtime, then this issue would not come up. Though one could say then we have a bigger problem. ;)

There's been some setback with panic! inside consts due to edition 2021 issues (the old hacks we used to only evaluate argumentless format strings don't work any more), but just today a new proposal to solve this was made: https://github.com/rust-lang/rust/pull/86830.

There was some more talk about floats and in particular NaNs during CTFE, but again it is unknown how to avoid introducing const fn that are non-deterministic at runtime.

There might be more things, honestly I am not entirely sure.^^

RalfJung avatar Jul 03 '21 07:07 RalfJung

Ah, I guess there's also inline consts. No progress, to my knowledge, but it would be really good to figure out what it would take to make progress here. :)

RalfJung avatar Jul 07 '21 16:07 RalfJung

@RalfJung It'd be helpful to make forward progress on inline consts for the benefit of inline assembly. cc @Amanieu.

joshtriplett avatar Jul 07 '21 17:07 joshtriplett

Yeah, that's one reason why I brought it up.

I don't really have any free cycles to work on this though, so I am not sure how much I can do.

RalfJung avatar Jul 07 '21 17:07 RalfJung