-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
1 / 21 of 2 issues completedLabels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_heap`#[feature(const_heap)]``#[feature(const_heap)]`Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.This change is large or controversial enough that it should have an RFC accepted before doing it.
Description
This is a tracking issue for rust-lang/const-eval#20
The feature gate for the issue is #![feature(const_heap)]
.
The general design can be found here
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Steps
- Implement Heap allocations in constants const-eval#20 experimentallyAdjust documentation (see instructions on rustc-dev-guide)Stabilization PR (see instructions on rustc-dev-guide)To pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Unresolved Questions
- Do we want to allow the regular
Global
allocator? This would give us post-monomorpization errors. More details can be found in https://hackmd.io/h2O2vkj3RimrBTfm9hvZWA#Transient-heap-allocations-via-Global - If we stabilize this, we fundamentally change the nature of
const fn
: before this change, aconst fn() -> T
would inevitably have to always return the same value; after this change, that is no longer the case. Withptr_guaranteed_eq
, this can even to some extend be observed during CTFE. So in that sense, this feature is much bigger than anything we ever stabilized for CTFE. - We can already emulate all this via
build.rs
scripts or proc macros that generate the appropriate constants/statics and references them. Const heap will "just" make generating static/const allocations more convenient. - Once we permit references to things that (can) contain interior mutability, it would be possible for users to write a
const fn foo() -> &'static Cell<i32>
, which could then be used to initialize aconst FOO: &'static Cell<i32>
which is unsound (and only caught by dynamic checks). The tracking issue for interior mutability behind references is Tracking Issue forconst_refs_to_cell
#80384 - const_heap feature can be used to leak mutable memory into final value of constant #129233
- ICEs when making self-referential values: dealing with cyclic (self-referential) values with const_heap #143869
- Whether or not
const_make_global
can be called twice on the same allocation.
Implementation history
- add const_allocate intrinsic #79594 adds the base intrinsic for telling the miri-engine to create a virtual heap allocation
- move interpret::MemoryKind::Heap to const eval #79664 makes sure that code outside of the const evaluator has no knowledge about heap allocations
- add
const_make_global
; err forconst_allocate
ptrs if didn't call #143595
Zymlex, stepancheg, toiglak, VladasZ, orzogc and 3 morevn-ki, tesuji, darksv, Zymlex, toiglak and 2 morebjoernager and bbb651Zymlex, ShadowJonathan and bbb651
Sub-issues
Collapse Sub-issuesSub-issues
- Manage this item control⌃ shift⇧ uU
- Manage this item control⌃ shift⇧ uU
To pick up a draggable item, press the space bar.
While dragging, use the arrow keys to move the item.
Press space again to drop the item in its new position, or press escape to cancel.
Metadata
Metadata
Assignees
Labels
A-allocatorsArea: Custom and system allocatorsArea: Custom and system allocatorsA-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCF-const_heap`#[feature(const_heap)]``#[feature(const_heap)]`Libs-TrackedLibs issues that are tracked on the team's project board.Libs issues that are tracked on the team's project board.S-tracking-impl-incompleteStatus: The implementation is incomplete.Status: The implementation is incomplete.T-langRelevant to the language teamRelevant to the language teamT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.needs-rfcThis change is large or controversial enough that it should have an RFC accepted before doing it.This change is large or controversial enough that it should have an RFC accepted before doing it.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
RalfJung commentedon Dec 1, 2020
As discussed here, this feature makes
const fn
observably impure:let x = f(); (x, x)
is no longer always equivalent to(f(), f())
. We are at a crossroads for the language here: if we want to support heap allocations inconst fn
, we have to either introduce some kind of effect system or say goodbye to the idea thatconst fn
denotes a form of purity that would be useful to unsafe code.RalfJung commentedon Dec 19, 2020
Btw, given how far-reaching the consequences of this feature are, I wonder if doing this without an RFC is really appropriate. But it could make sense to experiment some more with what can be done for transient vs. non-transient allocations, and how
Global
comes in, so that we have a better idea of the design space.@oli-obk something is wrong with "implementation history", it links to the same PR twice.
oli-obk commentedon Dec 20, 2020
The experimentation that @vn-ki has been doing has exposed various problems that aren't even related to heap stuff itself, but are prerequisites. I believe we should keep on doing this experimentation, just to find out what all the problems are and how a possible implementation could look. Doing this in the abstract has not allowed us to realize what the dependency graph actually is and I will be updating the skill tree to reflect that as we gain more information. Some examples off the top of my head:
impl const Fn for const fn()
Allocation
to make sure that we report an error instead of crashing rustc with OOM (this can be done on stable via the use of large arrays)RalfJung commentedon Dec 20, 2020
The first three points don't seem really related to heap allocations though?
oli-obk commentedon Dec 20, 2020
They are not, they are prerequisites for
Box::new_in
and whatever things are called by that.RalfJung commentedon Dec 21, 2020
Is there a separate issue for this? I think this is closely related to some of the other issues that came up over the last year -- where we have a restriction that applies to the final value of all consts, but be unnecessarily apply it even during the course of the computation -- since we have no good way to otherwise ensure that the final value is okay.
&mut
references have basically the same problem.oli-obk commentedon Dec 21, 2020
There is not. I have a local branch that generalizes to all such checks, so we'll be able to just check them on the final value
RalfJung commentedon Dec 21, 2020
For associated consts, I assume that's a post-monomorphization error then?
(I know this is off-topic here, that's why I asked if there is a better place.^^)
12 remaining items
enum_properties_lazy
macro that allows arbitrary values. cofinite/enum_properties#6Rollup merge of rust-lang#92274 - woppopo:const_deallocate, r=oli-obk
const
? rust-lang/unsafe-code-guidelines#502