rust-lang / rust-lang/rust

const-eval: support (symbolic) distance between two pointers

Open
#160,083 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-const-eval A-linkage C-feature-request needs-triage
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

LLVM and linkers apparently can represents the distance between two symbols symbolically, but currently there is no way to get rustc to emit those instructions. The proper way to implement this would be for const-eval to have symbolic values that represent the distance between two pointers. That's possible but it's a non-trivial extension of the core const-eval machinery.

This comes up in our Windows SEH code that really would like compile-time pointer distance, and works around it with lazy initialization at runtime that is technically UB.

I don't know if that is a strong enough usecase to warrant supporting this, but it is at least worth tracking.

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 Windows SEH use case in library/panic_unwind/src/seh.rs, especially lines 318-337, and then trace the const-eval machinery responsible for pointer values and linker-emitted instructions. Determine the design needed for symbolic distances between pointers and identify the relevant compiler tests before defining completion criteria.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.