Skip to content

Constify pointer::is_aligned{,to} - #102753

Closed
lukas-code wants to merge 7 commits into
rust-lang:masterfrom
lukas-code:constify-is-aligned
Closed

Constify pointer::is_aligned{,to}#102753
lukas-code wants to merge 7 commits into
rust-lang:masterfrom
lukas-code:constify-is-aligned

Conversation

@lukas-code

Copy link
Copy Markdown
Contributor

In this PR i've made <*const T>::is_aligned and <*const T>::is_aligned_to unstably const.
The main motivation here is to allow something like debug_assert!(is_aligned_and_not_null(ptr)) in const fns without any const_eval_select hacks.

If we don't know the address of a pointer in const eval, this function only returns true if we know for sure that the pointer is aligned. This means that in some cases a pointer can never be aligned, which matches the behavior of align_offset1.

Tracking issue for is_aligned: #96284

Footnotes

  1. Note that currently align_offset will always return usize::MAX in CTFE, but it could return a useful value for some alignments in the future.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @joshtriplett

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbotrustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Oct 6, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 6, 2022
@rustbot

Copy link
Copy Markdown
Collaborator

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

@RalfJung

Copy link
Copy Markdown
Member

Cc @rust-lang/wg-const-eval

I am not entirely sure about this... pointers are wonky in const and this function does not behave the way people will expect it to behave.

Also I think we should keep this and align_offset consistent, and we don't need a new intrinsic for this if we just do align_offset == 0.

@oli-obk

Copy link
Copy Markdown
Contributor

Also I think we should keep this and align_offset consistent, and we don't need a new intrinsic for this if we just do align_offset == 0.

yea, it should not add a new intrinsic, but be implemented in terms of the existing one.

@oli-obk

Copy link
Copy Markdown
Contributor

I am not entirely sure about this... pointers are wonky in const and this function does not behave the way people will expect it to behave.

the same is true for align_offset and [T]::align_to... which kind makes me want to just declare them "never gonna be const" and instead push the obligation to the caller who can use const_eval_select to skip the check

@saethlin

Copy link
Copy Markdown
Member

I think doing that would make those interfaces more popular, people should be using the standard library instead of re-implementing these. Right now I know of a few people who specifically avoid them because of the vague caveat in the docs. If we remove that, there should be a proper announcement of the change in direction we're taking in designing pointer interfaces.

And I for one would like pressure for const_eval_select to be more usable.

@RalfJung

Copy link
Copy Markdown
Member

Pressure doesn't help. People doing the work help. :)

@oli-obk

Copy link
Copy Markdown
Contributor

And I for one would like pressure for const_eval_select to be more usable.

I'm on it 😆

@saethlin

Copy link
Copy Markdown
Member

I think I meant a different kind of pressure. If I can tell a compelling story, it's easy to motivate community members to pitch in.

@lukas-code

Copy link
Copy Markdown
ContributorAuthor

I've put up an alternate PR which doesn't need a new intrinsic and uses align_offset instead: #102795

@rustbot

Copy link
Copy Markdown
Collaborator

The Miri subtree was changed

cc @rust-lang/miri

@rustbotrustbot added T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) A-meta Area: Issues & PRs about the rust-lang/rust repository itself A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) A-testsuite Area: The testsuite used to check the correctness of rustc A-translation Area: Translation infrastructure, and migrating existing diagnostics to SessionDiagnostic labels Oct 20, 2022
@rustbotrustbot added T-infra Relevant to the infrastructure team, which will review and decide on the PR/issue. T-style Relevant to the style team, which will review and decide on the PR/issue. labels Oct 20, 2022
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred in const_evaluatable.rs

cc @lcnr

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

Some changes occurred in HTML/CSS themes.

cc @GuillaumeGomez

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

rustc_error_messages was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

Some changes occurred in src/tools/rustfmt

cc @rust-lang/rustfmt

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in HTML/CSS/JS.

cc @GuillaumeGomez, @Folyd, @jsha

Some changes occurred in src/tools/cargo

cc @ehuss

rustc_macros::diagnostics was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

Some changes occurred in need_type_info.rs

cc @lcnr

rustc_errors::translation was changed

cc @davidtwco, @compiler-errors, @JohnTitor, @estebank, @TaKO8Ki

A change occurred in the Ayu theme.

cc @Cldfire

@lukas-code

Copy link
Copy Markdown
ContributorAuthor

Whoops, sorry for the massive ping. Pushed something here that I shouldn't have. Anyway, closing this in favor of #102795.

@lukas-code
lukas-code deleted the constify-is-aligned branch October 20, 2022 19:42
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 19, 2022
…lign-offset, r=oli-obk
Constify `is_aligned` via `align_offset`
Alternative to rust-lang#102753
Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.
Tracking Issue: rust-lang#104203
RalfJung pushed a commit to RalfJung/miri that referenced this pull request Nov 20, 2022
…et, r=oli-obk
Constify `is_aligned` via `align_offset`
Alternative to rust-lang/rust#102753
Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.
Tracking Issue: rust-lang/rust#104203
thomcc pushed a commit to pgcentralfoundation/postgrestd that referenced this pull request Feb 10, 2023
…et, r=oli-obk
Constify `is_aligned` via `align_offset`
Alternative to rust-lang/rust#102753
Make `align_offset` work in const eval (and not always return `usize::MAX`) and then use that to constify `is_aligned{_to}`.
Tracking Issue: rust-lang/rust#104203
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-metaArea: Issues & PRs about the rust-lang/rust repository itselfA-query-systemArea: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html)A-testsuiteArea: The testsuite used to check the correctness of rustcA-translationArea: Translation infrastructure, and migrating existing diagnostics to SessionDiagnosticS-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-bootstrapRelevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-infraRelevant to the infrastructure team, which will review and decide on the PR/issue.T-libsRelevant to the library team, which will review and decide on the PR/issue.T-styleRelevant to the style team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@lukas-code@rust-highfive@rustbot@RalfJung@oli-obk@saethlin@joshtriplett