Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove const-support for align_offset and is_aligned #132423

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Oct 31, 2024

As part of the recent discussion to stabilize ptr.is_null() in const context, the general vibe was that it's okay for a const function to panic when the same operation would work at runtime (that's just a case of "dynamically detecting that something is not supported as a const operation"), but it is not okay for a const function to just return a different result.

Following that, is_aligned and is_aligned_to have their const status revoked in this PR, since they do return actively wrong results at const time. In the future we can consider having a new intrinsic or so that can check whether a pointer is "guaranteed to be aligned", but the current implementation based on align_offset does not have the behavior we want.

In fact align_offset itself behaves quite strangely in const, and that support needs a bunch of special hacks. That doesn't seem worth it. Instead, the users that can fall back to a different implementation should just use const_eval_select directly, and everything else should not be made const-callable. So this PR does exactly that, and entirely removes const support for align_offset.

Closes some tracking issues by removing the associated features:
Closes #90962
Closes #104203

Cc @rust-lang/wg-const-eval @rust-lang/libs-api

@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2024

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. 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 31, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the const-eval-align-offset branch 3 times, most recently from c22d079 to 026a080 Compare November 1, 2024 11:07
@bors

This comment was marked as resolved.

Operations like is_aligned would return actively wrong results at compile-time,
i.e. calling it on the same pointer at compiletime and runtime could yield
different results. That's no good.

Instead of having hacks to make align_offset kind-of work in const-eval, just
use const_eval_select in the few places where it makes sense, which also ensures
those places are all aware they need to make sure the fallback behavior is
consistent.
@dtolnay
Copy link
Member

dtolnay commented Nov 3, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Nov 3, 2024

📌 Commit 19e2870 has been approved by dtolnay

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 3, 2024
@dtolnay dtolnay assigned dtolnay and unassigned workingjubilee Nov 3, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2024
…kingjubilee

Rollup of 4 pull requests

Successful merges:

 - rust-lang#131222 (Generate correct symbols.o for sparc-unknown-none-elf)
 - rust-lang#132423 (remove const-support for align_offset and is_aligned)
 - rust-lang#132565 (Reduce dependence on the target name)
 - rust-lang#132576 (remove attribute ids from hir stats (they're simply not needed))

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 3313e76 into rust-lang:master Nov 4, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 4, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 4, 2024
Rollup merge of rust-lang#132423 - RalfJung:const-eval-align-offset, r=dtolnay

remove const-support for align_offset and is_aligned

As part of the recent discussion to stabilize `ptr.is_null()` in const context, the general vibe was that it's okay for a const function to panic when the same operation would work at runtime (that's just a case of "dynamically detecting that something is not supported as a const operation"), but it is *not* okay for a const function to just return a different result.

Following that, `is_aligned` and `is_aligned_to` have their const status revoked in this PR, since they do return actively wrong results at const time. In the future we can consider having a new intrinsic or so that can check whether a pointer is "guaranteed to be aligned", but the current implementation based on `align_offset` does not have the behavior we want.

In fact `align_offset` itself behaves quite strangely in const, and that support needs a bunch of special hacks. That doesn't seem worth it. Instead, the users that can fall back to a different implementation should just use const_eval_select directly, and everything else should not be made const-callable. So this PR does exactly that, and entirely removes const support for align_offset.

Closes some tracking issues by removing the associated features:
Closes rust-lang#90962
Closes rust-lang#104203

Cc `@rust-lang/wg-const-eval` `@rust-lang/libs-api`
@RalfJung RalfJung deleted the const-eval-align-offset branch November 4, 2024 12:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking Issue for const_pointer_is_aligned Tracking Issue for const_align_offset
6 participants