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

Rename assert_uninit_valid intrinsic #105613

Merged
merged 2 commits into from
Dec 22, 2022

Conversation

Noratrieb
Copy link
Member

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with -Zstrict-init-checks. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if #100423 lands so removing it may be a bit over eager.

r? @RalfJung

@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 Dec 12, 2022
@rustbot
Copy link
Collaborator

rustbot commented Dec 12, 2022

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

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 to the CTFE / Miri engine

cc @rust-lang/miri

///
/// This intrinsic does not have a stable counterpart.
#[rustc_const_unstable(feature = "const_assert_type2", issue = "none")]
#[rustc_safe_intrinsic]
pub fn assert_uninit_valid<T>();
#[cfg(not(bootstrap))]
pub fn assert_ones_valid<T>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads to me like is about if all bytes being 0b11111111 is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally it still seems to check uninit, not 0x01.

Copy link
Member

@saethlin saethlin Dec 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the better approach here is probably to document and rename to match what this intrinsic is for: Checking if it is valid to call mem::uninitialized::<T>(). This whole thing is a wart on a wart, and we should probably just own that this is so special-cased.

Calling it ones_valid still leads to confusion, because the behavior changes to something else with -Zstrict-init-checks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think the better approach here is probably to document and rename to match what this intrinsic is for: Checking if it is valid to call mem::uninitialized::().

Agreed. So what would be a good name? assert_mem_uninitialized_valid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, that's what I would go for.

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

This is actually not fully correct though, as it does still panic for all uninit with -Zstrict-init-checks. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag?

I think that flag is still quite useful, e.g. for cargo careful.

It's not about "uninit" anymore but about "filling with 0x01 bytes" so
the name should at least try to reflect that.
@@ -959,13 +959,14 @@ extern "rust-intrinsic" {
#[rustc_safe_intrinsic]
pub fn assert_zero_valid<T>();

/// A guard for unsafe functions that cannot ever be executed if `T` has invalid
/// bit patterns: This will statically either panic, or do nothing.
/// A guard for `std::mem::uninitialized`. Checks whether a repeated bit pattern `0x01`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks whether a repeated bit pattern 0x01 is legal for T

Except if we decide to change the bit pattern (unlikely) or -Zstrict-init-checks is passed. Yes it's redundant, but it might be better to just say "Checks whether mem::uninitialized should panic for T" 🤷

@RalfJung
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Dec 21, 2022

📌 Commit 6f21ba4 has been approved by RalfJung

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 Dec 21, 2022
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Dec 21, 2022
…id, r=RalfJung

Rename `assert_uninit_valid` intrinsic

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if rust-lang#100423 lands so removing it may be a bit over eager.

r? `@RalfJung`
fee1-dead added a commit to fee1-dead-contrib/rust that referenced this pull request Dec 21, 2022
…id, r=RalfJung

Rename `assert_uninit_valid` intrinsic

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if rust-lang#100423 lands so removing it may be a bit over eager.

r? ``@RalfJung``
@bors
Copy link
Contributor

bors commented Dec 21, 2022

⌛ Testing commit 6f21ba4 with merge bdbe392...

@bors
Copy link
Contributor

bors commented Dec 22, 2022

☀️ Test successful - checks-actions
Approved by: RalfJung
Pushing bdbe392 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 22, 2022
@bors bors merged commit bdbe392 into rust-lang:master Dec 22, 2022
@rustbot rustbot added this to the 1.68.0 milestone Dec 22, 2022
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (bdbe392): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.1% [3.1%, 3.1%] 1
Regressions ❌
(secondary)
2.3% [2.0%, 3.3%] 14
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.1% [3.1%, 3.1%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

@Noratrieb Noratrieb deleted the rename-assert_uninit_valid branch December 22, 2022 05:24
Aaron1011 pushed a commit to Aaron1011/rust that referenced this pull request Jan 6, 2023
…, r=RalfJung

Rename `assert_uninit_valid` intrinsic

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if rust-lang#100423 lands so removing it may be a bit over eager.

r? `@RalfJung`
celinval added a commit to celinval/kani-dev that referenced this pull request Jan 24, 2023
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Jan 24, 2023
…, r=RalfJung

Rename `assert_uninit_valid` intrinsic

It's not about "uninit" anymore but about "filling with 0x01 bytes" so the name should at least try to reflect that.

This is actually not fully correct though, as it does still panic for all uninit with `-Zstrict-init-checks`. I'm not sure what the best way is to deal with that not causing confusion. I guess we could just remove the flag? I don't think having it makes a lot of sense anymore with the direction that we have chose to go. It could be relevant again if rust-lang#100423 lands so removing it may be a bit over eager.

r? `@RalfJung`
celinval added a commit to model-checking/kani that referenced this pull request Mar 8, 2023
Upgrade our toolchain to `nightly-2023-01-23`. The changes here are related to the following changes:
- rust-lang/rust#104986
- rust-lang/rust#105657
- rust-lang/rust#105603
- rust-lang/rust#105613
- rust-lang/rust#105977
- rust-lang/rust#104645
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

8 participants