Open
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 experimentally
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
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
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
Metadata
Metadata
Assignees
Labels
Area: Custom and system allocatorsArea: Constant evaluation, covers all const contexts (static, const fn, ...)Category: An issue tracking the progress of sth. like the implementation of an RFC`#[feature(const_heap)]`Libs issues that are tracked on the team's project board.Status: The implementation is incomplete.Relevant to the language 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.This change is large or controversial enough that it should have an RFC accepted before doing it.