rust-lang / rust-lang/rust

dealing with cyclic (self-referential) values with const_heap

Open
#143,869 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval C-bug F-const_heap WG-const-eval
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

See the following snippet: (currently ICEs)

#![feature(core_intrinsics)]
#![feature(const_heap)]

use std::mem::{align_of, size_of};
use std::intrinsics;

struct SelfReferential {
    me: *const SelfReferential,
}

const Y: &'static SelfReferential = unsafe {
    let size = size_of::<SelfReferential>();
    let align = align_of::<SelfReferential>();
    let ptr_raw = intrinsics::const_allocate(size, align);
    let ptr = ptr_raw as *mut SelfReferential;
    let me_addr = &raw mut (*ptr).me;
    *me_addr = ptr;
    intrinsics::const_make_global(ptr_raw, size, align);
    &*ptr
};

fn main() {}

Originally posted by @fee1-dead in https://github.com/rust-lang/rust/pull/143595#discussion_r2192969346

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the const_heap reproducer in the issue and inspect rustc_const_eval/src/interpret/intern.rs at the mutable-pointer check and the intern_shallow filtering around the linked lines. Trace the alloc_id kind, just_interned handling, and todo-list behavior to identify the infinite loop; done means the reproducer no longer ICEs or overflows the stack.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.