Skip to content

Add contracts for all functions in Alignment #136578

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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

tautschnig
Copy link

Uses the contracts syntax introduced in #128045.

@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2025

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 5, 2025
@rust-log-analyzer

This comment has been minimized.

@jieyouxu jieyouxu added the F-contracts `#![feature(contracts)]` label Feb 5, 2025
@jieyouxu
Copy link
Member

jieyouxu commented Feb 5, 2025

You could also tag contracts-related PRs with F-contracts in the future via

@rustbot label: +F-contracts

in a comment / PR description.

@jieyouxu jieyouxu mentioned this pull request Feb 5, 2025
9 tasks
@tgross35
Copy link
Contributor

tgross35 commented Feb 5, 2025

Could you say some more about the motivation? This feature was merged only a number of hours ago, that seems soon to start using in std. Even once it is more stable, what should and shouldn't get contracts is probably something that needs to get discussed.

@rust-lang/libs any thoughts here?

@jieyouxu
Copy link
Member

jieyouxu commented Feb 5, 2025

Yeah, this was only approved as a lang experiment on the lang/compiler side, no idea what the situation is libs side (which certainly should be discussed).

cc @pnkfelix @nikomatsakis @celinval (lang liason and ppl who were implementing this feature compiler side)

@Noratrieb Noratrieb added the I-libs-nominated Nominated for discussion during a libs team meeting. label Feb 5, 2025
@Noratrieb
Copy link
Member

I'll libs nominate this for discussion (this should only be discussed after the contracts people mentioned above have replied).

@celinval
Copy link
Contributor

celinval commented Feb 5, 2025

Totally worth discussion, and it would be great to get some feedback on the features that are needed to meet the libs team bar. I am especially curious to see how you think contracts and ub_checks will interact.

@Noratrieb
Copy link
Member

It would be useful to know what your plan/intention is with adding contracts here. Is it just to try them out or is annotating the standard library with contracts for downstream consumers part of the goal of contracts?

@tautschnig
Copy link
Author

Could you say some more about the motivation? This feature was merged only a number of hours ago, that seems soon to start using in std. Even once it is more stable, what should and shouldn't get contracts is probably something that needs to get discussed.

As far as the motivation is concerned: we're working towards https://rust-lang.github.io/rust-project-goals/2025h1/std-contracts.html, and I created this (draft) PR with the hope to initiate discussion while knowing there is a lot more work to be done on our end.

As I am new contributor: is there other information that I can provide or another forum that I should use rather than this PR?

@tautschnig
Copy link
Author

It would be useful to know what your plan/intention is with adding contracts here. Is it just to try them out or is annotating the standard library with contracts for downstream consumers part of the goal of contracts?

Our current goal is https://rust-lang.github.io/rust-project-goals/2025h1/std-contracts.html, though we are in early stages and it indeed is about trying out what works best. Eventually we want to enable verification of downstream consumers, but a lot more work will be required before we get there.

@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from d46f868 to 7288286 Compare February 5, 2025 22:06
@rust-log-analyzer

This comment has been minimized.

@tgross35
Copy link
Contributor

tgross35 commented Feb 5, 2025

As far as the motivation is concerned: we're working towards https://rust-lang.github.io/rust-project-goals/2025h1/std-contracts.html, and I created this (draft) PR with the hope to initiate discussion while knowing there is a lot more work to be done on our end.

As I am new contributor: is there other information that I can provide or another forum that I should use rather than this PR?

Are there any docs on how contracts work as they exist today? Ignoring the stability question, we need something to refer to about how to use these properly, e.g. in https://doc.rust-lang.org/nightly/unstable-book/. Also, how are contracts that get merged into r-l/rust being verified?

The linked page is somewhat vague about what this means for std. I think we could also use a policy page in the library dev guide (https://std-dev-guide.rust-lang.org) giving guidelines for their use, based on the outcome of any discussion that happens.

Bringing this up on the libs zulip would be a good idea to get the ball rolling https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs.

@@ -43,6 +43,8 @@ impl Alignment {
#[unstable(feature = "ptr_alignment_type", issue = "102070")]
#[inline]
#[must_use]
#[cfg_attr(not(bootstrap), contracts::requires(mem::align_of::<T>().is_power_of_two()))]

This comment was marked as resolved.

@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from 7288286 to c180bd0 Compare February 6, 2025 13:23
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@Amanieu
Copy link
Member

Amanieu commented Feb 12, 2025

We discussed this in the libs meeting today. We're happy to add contracts to the standard library as an experiment, as long as this doesn't get in the way of normal standard library development. Depending on how the contracts feature evolves, we may reconsider our level of support.

@Amanieu Amanieu removed the I-libs-nominated Nominated for discussion during a libs team meeting. label Feb 12, 2025
@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Mar 17, 2025
@tautschnig
Copy link
Author

Since this is still a draft and has failing tests:

@rustbot author

CI is expected to pass once the fix for #136925 lands.

@RalfJung
Copy link
Member

This will make the MIR of these functions significantly bigger, right? It's going to be cleaned up eventually once contract_checks() is expanded to false, but that might be too late for a bunch of MIR inliner decisions. Cc @saethlin @scottmcm

@scottmcm
Copy link
Member

Question from ignorance on my part: how do we encode contracts? Are they in statements/terminators, or in some other communication channel?

@saethlin
Copy link
Member

saethlin commented Mar 20, 2025

COMEFROM rust-lang/compiler-team#813 (comment)

Based on the writeup that @celinval has provided, it looks like contracts will cause us to have new Call terminators in MIR, and that would indeed be quite an unfortunate situation for the MIR optimization pipeline.

That being said, I don't think I have anything useful/actionable to say other than "yeah that sounds like it could be bad" until we have actual data to work with. The Alignment type has become a lot less perf-sensitive since I polymorphized RawVec, and as Celina points out in the doc there is an obvious symmetry between the well-designed contracts and the pile of hacks I've driven forward for the ub_checks feature. I managed to land nearly all the UB checks I wanted with a collective <1% compile time overhead. It took some work to get there, so contracts might need some work too. We'll see.

@celinval
Copy link
Contributor

COMEFROM rust-lang/compiler-team#813 (comment)

Based on the writeup that @celinval has provided, it looks like contracts will cause us to have new Call terminators in MIR, and that would indeed be quite an unfortunate situation for the MIR optimization pipeline.

That being said, I don't think I have anything useful/actionable to say other than "yeah that sounds like it could be bad" until we have actual data to work with. The Alignment type has become a lot less perf-sensitive since I polymorphized RawVec, and as Celina points out in the doc there is an obvious symmetry between the well-designed contracts and the pile of hacks I've driven forward for the ub_checks feature. I managed to land nearly all the UB checks I wanted with a collective <1% compile time overhead. It took some work to get there, so contracts might need some work too. We'll see.

For sure, we'll have to be cautious about performance. I think one possibility is to remove the existing mechanism to delay enable/disable contract as late as codegen.

I kinda wish there was a rustup component std-debug which would allow users to compile against debug friendly std library.

@RalfJung
Copy link
Member

I kinda wish there was a rustup component std-debug which would allow users to compile against debug friendly std library.

-Zbuild-std is a project goal for 2025h1, so hopefully it will not be too long until users can just build a debug-friendly std.

@rust-log-analyzer

This comment has been minimized.

@tautschnig
Copy link
Author

My reading of the remaining CI failure is that indeed some optimizations no longer work out as expected once contracts are added. Advice would be appreciated!

@saethlin
Copy link
Member

The point of this PR is to change the MIR, so you just need to x test mir-opt --bless to check in the new MIR.

I suspect you'll then fail codegen tests, and those may be much more troublesome.

@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from 3ae396f to 78aad63 Compare April 15, 2025 18:36
@tautschnig
Copy link
Author

@RalfJung (or others in @rust-lang/miri): what are my next steps now that I see

  error: unsupported operation: Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `contract_check_ensures` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that
  Error:   --> /checkout/library/core/src/ptr/alignment.rs:106:32
     |
  LL |       #[cfg_attr(not(bootstrap), core::contracts::ensures(
     |  ________________________________^
  LL | |             |result: &usize| result.is_power_of_two()))]
     | |______________________________________________________^ Miri can only use intrinsic fallback bodies that exactly reflect the specification: they fully check for UB and are as non-deterministic as possible. After verifying that `contract_check_ensures` does so, add the `#[miri::intrinsic_fallback_is_spec]` attribute to it; also ping @rust-lang/miri when you do that

in the above CI failure logs? Thank you!

@RalfJung
Copy link
Member

For now, adding #[miri::intrinsic_fallback_is_spec] seems fine. We may want to change contract_checks() to return true under Miri... but that's probably best done together with making it something like cfg!(contract_checks) which Miri can then set.

tautschnig added a commit to tautschnig/verify-rust-std that referenced this pull request Apr 15, 2025
@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from 78aad63 to 38f3d67 Compare April 15, 2025 20:35
@rust-log-analyzer

This comment has been minimized.

@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from 38f3d67 to 667454b Compare April 16, 2025 07:44
@@ -20,6 +20,6 @@ fn main() {
// CHECK: debug a => [[a:_.*]];
// We may check other inlined functions as well...

// CHECK: {{_.*}} = const Box::<[bool]>(
// CHECK: {{_.*}} = {{(const )?}}Box::<[bool]>(
Copy link
Member

Choose a reason for hiding this comment

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

Having to change this is problematic, since apparently the intent of the test was to ensure that this indeed turns into a constant.

Copy link
Author

Choose a reason for hiding this comment

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

Oh, I entirely agree with that. I feel like at this point we are rather exploring the impact of adding those contracts than producing final solutions.

@rust-log-analyzer

This comment has been minimized.

Updated via `./x.py test mir-opt --bless --stage 1`
@tautschnig tautschnig force-pushed the upstream-contracts/alignment branch from 667454b to bef04bf Compare April 16, 2025 08:53
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-19 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#19 exporting to docker image format
#19 sending tarball 19.9s done
#19 DONE 26.1s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-19]
[CI_JOB_NAME=x86_64-gnu-llvm-19]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Listening on address 127.0.0.1:4226
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-19', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--set', 'build.print-step-timings', '--enable-verbose-tests', '--set', 'build.metrics', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: build.build          := x86_64-unknown-linux-gnu
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-19/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
  Number of decisions:   4447
  longest path:          1159 (code:    152)
  longest backtrack:       66 (code:    428)
Shared 86733 out of 152951 states by creating 14756 new states, saving 71977
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/expmed.cc: In function ‘rtx_def* extract_bit_field_1(rtx, poly_uint64, poly_uint64, int, rtx, machine_mode, machine_mode, bool, bool, rtx_def**)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/expmed.cc:1864:45: warning: ‘*(unsigned int*)((char*)&imode + offsetof(scalar_int_mode, scalar_int_mode::m_mode))’ may be used uninitialized [-Wmaybe-uninitialized]
 1864 |       rtx sub = extract_bit_field_as_subreg (mode1, op0, imode,
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~
 1865 |                                              bitsize, bitnum);
      |                                              ~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/expmed.cc:1824:19: note: ‘*(unsigned int*)((char*)&imode + offsetof(scalar_int_mode, scalar_int_mode::m_mode))’ was declared here
 1824 |   scalar_int_mode imode;
      |                   ^~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/gimple-range-gori.cc: In member function ‘void range_def_chain::dump(FILE*, basic_block, const char*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/gimple-range-gori.cc:319:19: warning: format not a string literal and no format arguments [-Wformat-security]
  319 |           fprintf (f, prefix);
      |           ~~~~~~~~^~~~~~~~~~~
---
                 from /checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/region-model.h:33,
                 from /checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/access-diagram.cc:39:
In constructor ‘ana::byte_range::byte_range(ana::byte_offset_t, ana::byte_size_t)’,
    inlined from ‘virtual text_art::table ana::string_literal_spatial_item::make_table(const ana::bit_to_table_map&, text_art::style_manager&) const’ at /checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/access-diagram.cc:1812:18:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/store.h:312:5: warning: ‘size_in_bytes.generic_wide_int<fixed_wide_int_storage<128> >::fixed_wide_int_storage<128>.fixed_wide_int_storage<128>::val[1]’ may be used uninitialized [-Wmaybe-uninitialized]
  312 |     m_size_in_bytes (size_in_bytes)
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/access-diagram.cc: In member function ‘virtual text_art::table ana::string_literal_spatial_item::make_table(const ana::bit_to_table_map&, text_art::style_manager&) const’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/analyzer/access-diagram.cc:1808:28: note: ‘size_in_bytes.generic_wide_int<fixed_wide_int_storage<128> >::fixed_wide_int_storage<128>.fixed_wide_int_storage<128>::val[1]’ was declared here
 1808 |                byte_size_t size_in_bytes
      |                            ^~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/diagnostic.cc: In function ‘void fancy_abort(const char*, int, const char*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/diagnostic.cc:1677:15: warning: format not a string literal and no format arguments [-Wformat-security]
 1677 |       fnotice (stderr, diagnostic_kind_text[DK_ICE]);
---
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/gcc.cc:7930:9: warning: ignoring return value of ‘ssize_t write(int, const void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 7930 |   write (fd, "\n\n", 2);
      |   ~~~~~~^~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/gcc.cc: In member function ‘void driver::final_actions() const’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/gcc.cc:9307:13: warning: ignoring return value of ‘int truncate(const char*, __off_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 9307 |     truncate(totruncate_file, 0);
      |     ~~~~~~~~^~~~~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto-wrapper.cc: In function ‘bool find_and_merge_options(int, off_t, const char*, vec<cl_decoded_option>, bool, vec<cl_decoded_option>*, const char*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto-wrapper.cc:1165:8: warning: ignoring return value of ‘ssize_t read(int, void*, size_t)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 1165 |   read (fd, data, length);
      |   ~~~~~^~~~~~~~~~~~~~~~~~
---
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto/lto-common.cc: In function ‘void lto_resolution_read(splay_tree, FILE*, lto_file*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto/lto-common.cc:2091:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 2091 |   fscanf (resolution, " ");   /* Read white space.  */
      |   ~~~~~~~^~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto/lto-common.cc:2093:9: warning: ignoring return value of ‘size_t fread(void*, size_t, size_t, FILE*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 2093 |   fread (obj_name, sizeof (char), name_len, resolution);
      |   ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/lto/lto-common.cc:2113:10: warning: ignoring return value of ‘int fscanf(FILE*, const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
 2113 |   fscanf (resolution, "%u", &num_symbols);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/gcc/jit/jit-recording.cc:32:
---
Applying io_quotes_use            to linux/blkzoned.h
Applying io_quotes_use            to linux/ipmi.h
Applying io_quotes_use            to linux/psp-dbc.h
Applying io_quotes_use            to linux/bt-bmc.h
Applying io_quotes_use            to linux/tps6594_pfsm.h
Applying io_quotes_use            to linux/cxl_mem.h
Applying io_quotes_use            to linux/wmi.h
Applying io_quotes_use            to linux/auto_fs.h
Applying io_quotes_use            to linux/mmtimer.h
Applying io_quotes_use            to linux/f2fs.h
Applying io_quotes_use            to linux/vhost.h
---
Applying io_quotes_use            to sound/asound.h
Applying io_quotes_use            to sound/compress_offload.h
Applying hpux8_bogus_inlines      to math.h
Applying pthread_incomplete_struct_argument to pthread.h
Fixed:  pthread.h
Applying io_quotes_use            to misc/mrvl_cn10k_dpi.h
Applying io_quotes_use            to misc/ocxl.h
Applying io_quotes_use            to misc/cxl.h
Applying io_quotes_use            to misc/xilinx_sdfec.h
Applying io_quotes_def            to unicode/platform.h
Applying sun_malloc               to malloc.h
Applying io_quotes_use            to scsi/cxlflash_ioctl.h
---
Applying machine_name             to x86_64-linux-gnu/bits/unistd_ext.h
Applying io_quotes_use            to x86_64-linux-gnu/asm/mtrr.h
Applying io_quotes_use            to x86_64-linux-gnu/asm/amd_hsmp.h
Applying machine_name             to openssl/e_os2.h
Applying io_quotes_use            to drm/xe_drm.h
Applying io_quotes_use            to drm/radeon_drm.h
Applying io_quotes_use            to drm/panfrost_drm.h
Applying io_quotes_use            to drm/etnaviv_drm.h
Applying io_quotes_use            to drm/lima_drm.h
Applying io_quotes_use            to drm/qaic_accel.h
Applying io_quotes_use            to drm/vc4_drm.h
Applying io_quotes_use            to drm/i915_drm.h
Applying io_quotes_use            to drm/omap_drm.h
Applying io_quotes_use            to drm/pvr_drm.h
Applying io_quotes_use            to drm/amdgpu_drm.h
Applying io_quotes_use            to drm/vgem_drm.h
Applying io_quotes_use            to drm/msm_drm.h
Applying io_quotes_use            to drm/v3d_drm.h
Applying io_quotes_use            to drm/exynos_drm.h
Applying io_quotes_use            to drm/nouveau_drm.h
Applying io_quotes_use            to drm/drm.h
Applying io_quotes_use            to drm/habanalabs_accel.h
Applying io_quotes_use            to drm/tegra_drm.h
Applying io_quotes_use            to rdma/rdma_user_ioctl.h
cc1: note: self-tests are not enabled in this build
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/c++tools/server.cc: In function ‘void server(bool, int, module_resolver*)’:
/checkout/obj/build/x86_64-unknown-linux-gnu/gcc/src/c++tools/server.cc:620:10: warning: ignoring return value of ‘int pipe(int*)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
---
test [mir-opt] tests/mir-opt/inline/polymorphic_recursion.rs ... ok

failures:

---- [mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs stdout ----
16           scope 4 (inlined Unique::<[bool; 0]>::dangling) {
17               let mut _5: std::ptr::NonNull<[bool; 0]>;
18               scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
-                   let mut _6: std::num::NonZero<usize>;
+                   let _6: std::ptr::Alignment;
+                   let mut _7: std::num::NonZero<usize>;
20                   scope 6 {
-                       scope 8 (inlined std::ptr::Alignment::as_nonzero) {
+                       scope 10 (inlined std::ptr::Alignment::as_nonzero) {
+                           let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}};
+                           let mut _9: std::num::NonZero<usize>;
+                           scope 11 {
+                           }
+                           scope 12 (inlined core::contracts::build_check_ensures::<NonZero<usize>, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) {
+                           }
22                       }
-                       scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
-                           let _7: *const [bool; 0];
-                           scope 10 {
+                       scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) {
+                           let _10: *const [bool; 0];
+                           scope 14 {
26                           }
-                           scope 11 (inlined NonZero::<usize>::get) {
+                           scope 15 (inlined NonZero::<usize>::get) {
28                           }
-                           scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) {
-                               scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
+                           scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) {
+                               scope 17 (inlined without_provenance_mut::<[bool; 0]>) {
31                               }
32                           }
33                       }

34                   }
35                   scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
+                       scope 8 {
+                       }
+                       scope 9 (inlined core::contracts::build_check_ensures::<std::ptr::Alignment, {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}>) {
+                       }
36                   }
37               }
38           }

45           StorageLive(_4);
46           StorageLive(_5);
47           StorageLive(_6);
- -         _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
- +         _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
-           StorageLive(_7);
- -         _7 = copy _6 as *const [bool; 0] (Transmute);
- -         _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
- +         _7 = const {0x1 as *const [bool; 0]};
- +         _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
-           StorageDead(_7);
-           StorageDead(_6);
- -         _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
- +         _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
-           StorageDead(_5);
- -         _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit));
- +         _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
-           StorageDead(_4);
- -         _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
- +         _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
-           StorageDead(_3);
- -         _1 = A { foo: move _2 };
- +         _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
-           StorageDead(_2);
-           _0 = const ();
-           drop(_1) -> [return: bb1, unwind: bb2];
+           _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue];
71       }
72   
73       bb1: {

78       bb2 (cleanup): {
79           resume;
80       }
+   
+       bb3: {
+           StorageLive(_7);
+           StorageLive(_8);
+           _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 };
+           StorageLive(_9);
+           _9 = copy _6 as std::num::NonZero<usize> (Transmute);
+           _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero<usize>>(move _8, move _9) -> [return: bb4, unwind continue];
+       }
+   
+       bb4: {
+           StorageDead(_9);
+           StorageDead(_8);
+           StorageLive(_10);
+           _10 = copy _7 as *const [bool; 0] (Transmute);
+           _5 = NonNull::<[bool; 0]> { pointer: copy _10 };
+           StorageDead(_10);
+           StorageDead(_7);
+           StorageDead(_6);
+           _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
+           StorageDead(_5);
+           _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit));
+           StorageDead(_4);
+           _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
+           StorageDead(_3);
+           _1 = A { foo: move _2 };
+           StorageDead(_2);
+           _0 = const ();
+           drop(_1) -> [return: bb1, unwind: bb2];
+       }
81   }
- + 
- + ALLOC2 (size: 16, align: 8) { .. }
- + 
- + ALLOC1 (size: 16, align: 8) { .. }
- + 
- + ALLOC0 (size: 16, align: 8) { .. }
88   
89 


thread '[mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:84:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- [mir-opt] tests/mir-opt/gvn_ptr_eq_with_constant.rs stdout ----
6       let _1: bool;
7       let mut _2: *mut u8;
8       scope 1 (inlined dangling_mut::<u8>) {
+           let mut _3: std::ptr::NonNull<u8>;
9           scope 2 (inlined NonNull::<u8>::dangling) {
-               let mut _3: std::num::NonZero<usize>;
+               let _4: std::ptr::Alignment;
+               let mut _5: std::num::NonZero<usize>;
11               scope 3 {
-                   scope 5 (inlined std::ptr::Alignment::as_nonzero) {
+                   scope 7 (inlined std::ptr::Alignment::as_nonzero) {
+                       let mut _6: {closure@std::ptr::Alignment::as_nonzero::{closure#0}};
+                       let mut _7: std::num::NonZero<usize>;
+                       scope 8 {
+                       }
+                       scope 9 (inlined core::contracts::build_check_ensures::<NonZero<usize>, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) {
+                       }
13                   }
-                   scope 6 (inlined NonNull::<u8>::without_provenance) {
-                       scope 7 {
+                   scope 10 (inlined NonNull::<u8>::without_provenance) {
+                       let _8: *const u8;
+                       scope 11 {
16                       }
-                       scope 8 (inlined NonZero::<usize>::get) {
+                       scope 12 (inlined NonZero::<usize>::get) {
18                       }
-                       scope 9 (inlined std::ptr::without_provenance::<u8>) {
-                           scope 10 (inlined without_provenance_mut::<u8>) {
+                       scope 13 (inlined std::ptr::without_provenance::<u8>) {
+                           scope 14 (inlined without_provenance_mut::<u8>) {
21                           }
22                       }
23                   }

24               }
25               scope 4 (inlined std::ptr::Alignment::of::<u8>) {
+                   scope 5 {
+                   }
+                   scope 6 (inlined core::contracts::build_check_ensures::<std::ptr::Alignment, {closure@std::ptr::Alignment::of<u8>::{closure#0}}>) {
+                   }
26               }
27           }
-           scope 11 (inlined NonNull::<u8>::as_ptr) {
+           scope 15 (inlined NonNull::<u8>::as_ptr) {
29           }
30       }
-       scope 12 (inlined Foo::<u8>::cmp_ptr) {
-           let mut _4: *const u8;
-           let mut _5: *mut u8;
-           let mut _6: *const u8;
-           scope 13 (inlined std::ptr::eq::<u8>) {
+       scope 16 (inlined Foo::<u8>::cmp_ptr) {
+           let mut _9: *const u8;
+           let mut _10: *mut u8;
+           let mut _11: *const u8;
+           scope 17 (inlined std::ptr::eq::<u8>) {
36           }
37       }
38   

39       bb0: {
40           StorageLive(_1);
41           StorageLive(_2);
+ -         StorageLive(_5);
+ +         nop;
42           StorageLive(_3);
- -         _3 = const std::ptr::Alignment::of::<u8>::{constant#0} as std::num::NonZero<usize> (Transmute);
- -         _2 = copy _3 as *mut u8 (Transmute);
- +         _3 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
- +         _2 = const {0x1 as *mut u8};
-           StorageDead(_3);
48           StorageLive(_4);
-           StorageLive(_5);
- -         _5 = copy _2;
- -         _4 = copy _2 as *const u8 (PtrToPtr);
- +         _5 = const {0x1 as *mut u8};
- +         _4 = const {0x1 as *const u8};
-           StorageDead(_5);
+           _4 = contract_check_ensures::<{closure@std::ptr::Alignment::of<u8>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<u8>::{closure#0}}, const std::ptr::Alignment::of::<u8>::{constant#0}) -> [return: bb1, unwind continue];
+       }
+   
+       bb1: {
55           StorageLive(_6);
- -         _6 = const Foo::<u8>::SENTINEL as *const u8 (PtrToPtr);
- -         _1 = Eq(copy _4, copy _6);
- +         _6 = const {0x1 as *const u8};
- +         _1 = const true;
+           _6 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _4 };
+           StorageLive(_7);
+           _7 = copy _4 as std::num::NonZero<usize> (Transmute);
+           _5 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero<usize>>(move _6, move _7) -> [return: bb2, unwind continue];
+       }
+   
+       bb2: {
+           StorageDead(_7);
60           StorageDead(_6);
+ -         StorageLive(_8);
+ +         nop;
+           _8 = copy _5 as *const u8 (Transmute);
+           _3 = NonNull::<u8> { pointer: copy _8 };
+ -         StorageDead(_8);
+ +         nop;
61           StorageDead(_4);
+           _2 = copy _5 as *mut u8 (Transmute);
+           StorageDead(_3);
+ -         StorageDead(_5);
+ +         nop;
+           StorageLive(_9);
+           StorageLive(_10);
+           _10 = copy _2;
+ -         _9 = copy _2 as *const u8 (PtrToPtr);
+ +         _9 = copy _8;
+           StorageDead(_10);
+           StorageLive(_11);
+ -         _11 = const Foo::<u8>::SENTINEL as *const u8 (PtrToPtr);
+ -         _1 = Eq(copy _9, copy _11);
+ +         _11 = const {0x1 as *const u8};
+ +         _1 = Eq(copy _8, const {0x1 as *const u8});
+           StorageDead(_11);
+           StorageDead(_9);
62           StorageDead(_2);
63           StorageDead(_1);
64           _0 = const ();


thread '[mir-opt] tests/mir-opt/gvn_ptr_eq_with_constant.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:84:21:
Actual MIR output differs from expected MIR output /checkout/tests/mir-opt/gvn_ptr_eq_with_constant.main.GVN.diff


failures:
    [mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs
    [mir-opt] tests/mir-opt/gvn_ptr_eq_with_constant.rs

@tautschnig
Copy link
Author

I am now seeing differences in MIR produced for x86_64 vs aarch64, and I'm not sure how to reconcile that with the current test tooling. That is:

./x.py test mir-opt --stage 1 --force-rerun --target x86_64-unknown-linux-gnu

passes, while

./x.py test mir-opt --stage 1 --force-rerun --target aarch64-unknown-linux-gnu

fails. Adding in --bless will happily update the diffs, but then we just get the opposite outcomes for the above two cases. Obviously, both are 64-bit targets, so EMIT_MIR_FOR_EACH_BIT_WIDTH won't do the trick. Would anyone be able to advise?

@RalfJung
Copy link
Member

What is the difference you are seeing?

@tautschnig
Copy link
Author

What is the difference you are seeing?

The following, rather large diff is presented to me:

Testing stage1 compiletest suite=mir-opt mode=mir-opt (x86_64-unknown-linux-gnu -> aarch64-unknown-linux-gnu)

running 335 tests
........................................................................................  88/335
................................
[mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs ... F
...........................................i.....
[mir-opt] tests/mir-opt/gvn_ptr_eq_with_constant.rs ... F
..... 176/335
........................................................................................ 264/335
.......................................................................

failures:

---- [mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs stdout ----
16	          scope 4 (inlined Unique::<[bool; 0]>::dangling) {
17	              let mut _5: std::ptr::NonNull<[bool; 0]>;
18	              scope 5 (inlined NonNull::<[bool; 0]>::dangling) {
-	                  let mut _6: std::num::NonZero<usize>;
+	                  let _6: std::ptr::Alignment;
+	                  let mut _7: std::num::NonZero<usize>;
20	                  scope 6 {
-	                      scope 8 (inlined std::ptr::Alignment::as_nonzero) {
+	                      scope 10 (inlined std::ptr::Alignment::as_nonzero) {
+	                          let mut _8: {closure@std::ptr::Alignment::as_nonzero::{closure#0}};
+	                          let mut _9: std::num::NonZero<usize>;
+	                          scope 11 {
+	                          }
+	                          scope 12 (inlined core::contracts::build_check_ensures::<NonZero<usize>, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) {
+	                          }
22	                      }
-	                      scope 9 (inlined NonNull::<[bool; 0]>::without_provenance) {
-	                          let _7: *const [bool; 0];
-	                          scope 10 {
+	                      scope 13 (inlined NonNull::<[bool; 0]>::without_provenance) {
+	                          let _10: *const [bool; 0];
+	                          scope 14 {
26	                          }
-	                          scope 11 (inlined NonZero::<usize>::get) {
+	                          scope 15 (inlined NonZero::<usize>::get) {
28	                          }
-	                          scope 12 (inlined std::ptr::without_provenance::<[bool; 0]>) {
-	                              scope 13 (inlined without_provenance_mut::<[bool; 0]>) {
+	                          scope 16 (inlined std::ptr::without_provenance::<[bool; 0]>) {
+	                              scope 17 (inlined without_provenance_mut::<[bool; 0]>) {
31	                              }
32	                          }
33	                      }

34	                  }
35	                  scope 7 (inlined std::ptr::Alignment::of::<[bool; 0]>) {
+	                      scope 8 {
+	                      }
+	                      scope 9 (inlined core::contracts::build_check_ensures::<std::ptr::Alignment, {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}>) {
+	                      }
36	                  }
37	              }
38	          }

45	          StorageLive(_4);
46	          StorageLive(_5);
47	          StorageLive(_6);
-	-         _6 = const std::ptr::Alignment::of::<[bool; 0]>::{constant#0} as std::num::NonZero<usize> (Transmute);
-	+         _6 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
-	          StorageLive(_7);
-	-         _7 = copy _6 as *const [bool; 0] (Transmute);
-	-         _5 = NonNull::<[bool; 0]> { pointer: copy _7 };
-	+         _7 = const {0x1 as *const [bool; 0]};
-	+         _5 = const NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }};
-	          StorageDead(_7);
-	          StorageDead(_6);
-	-         _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
-	+         _4 = const Unique::<[bool; 0]> {{ pointer: NonNull::<[bool; 0]> {{ pointer: {0x1 as *const [bool; 0]} }}, _marker: PhantomData::<[bool; 0]> }};
-	          StorageDead(_5);
-	-         _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit));
-	+         _3 = const Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC0, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }};
-	          StorageDead(_4);
-	-         _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
-	+         _2 = const Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC1, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global);
-	          StorageDead(_3);
-	-         _1 = A { foo: move _2 };
-	+         _1 = const A {{ foo: Box::<[bool]>(Unique::<[bool]> {{ pointer: NonNull::<[bool]> {{ pointer: Indirect { alloc_id: ALLOC2, offset: Size(0 bytes) }: *const [bool] }}, _marker: PhantomData::<[bool]> }}, std::alloc::Global) }};
-	          StorageDead(_2);
-	          _0 = const ();
-	          drop(_1) -> [return: bb1, unwind: bb2];
+	          _6 = contract_check_ensures::<{closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<[bool; 0]>::{closure#0}}, const std::ptr::Alignment::of::<[bool; 0]>::{constant#0}) -> [return: bb3, unwind continue];
71	      }
72
73	      bb1: {

78	      bb2 (cleanup): {
79	          resume;
80	      }
+
+	      bb3: {
+	          StorageLive(_7);
+	          StorageLive(_8);
+	          _8 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _6 };
+	          StorageLive(_9);
+	          _9 = copy _6 as std::num::NonZero<usize> (Transmute);
+	          _7 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero<usize>>(move _8, move _9) -> [return: bb4, unwind continue];
+	      }
+
+	      bb4: {
+	          StorageDead(_9);
+	          StorageDead(_8);
+	          StorageLive(_10);
+	          _10 = copy _7 as *const [bool; 0] (Transmute);
+	          _5 = NonNull::<[bool; 0]> { pointer: copy _10 };
+	          StorageDead(_10);
+	          StorageDead(_7);
+	          StorageDead(_6);
+	          _4 = Unique::<[bool; 0]> { pointer: move _5, _marker: const PhantomData::<[bool; 0]> };
+	          StorageDead(_5);
+	          _3 = move _4 as std::ptr::Unique<[bool]> (PointerCoercion(Unsize, Implicit));
+	          StorageDead(_4);
+	          _2 = Box::<[bool]>(copy _3, const std::alloc::Global);
+	          StorageDead(_3);
+	          _1 = A { foo: move _2 };
+	          StorageDead(_2);
+	          _0 = const ();
+	          drop(_1) -> [return: bb1, unwind: bb2];
+	      }
81	  }
-	+
-	+ ALLOC2 (size: 16, align: 8) { .. }
-	+
-	+ ALLOC1 (size: 16, align: 8) { .. }
-	+
-	+ ALLOC0 (size: 16, align: 8) { .. }
88
89


thread '[mir-opt] tests/mir-opt/dataflow-const-prop/default_boxed_slice.rs' panicked at src/tools/compiletest/src/runtest/mir_opt.rs:84:21:
Actual MIR output differs from expected MIR output /home/ub-backup/tautschn/verify-rust-std.git/tests/mir-opt/dataflow-const-prop/default_boxed_slice.main.GVN.64bit.panic-unwind.diff
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- [mir-opt] tests/mir-opt/gvn_ptr_eq_with_constant.rs stdout ----
6	      let _1: bool;
7	      let mut _2: *mut u8;
8	      scope 1 (inlined dangling_mut::<u8>) {
+	          let mut _3: std::ptr::NonNull<u8>;
9	          scope 2 (inlined NonNull::<u8>::dangling) {
-	              let mut _3: std::num::NonZero<usize>;
+	              let _4: std::ptr::Alignment;
+	              let mut _5: std::num::NonZero<usize>;
11	              scope 3 {
-	                  scope 5 (inlined std::ptr::Alignment::as_nonzero) {
+	                  scope 7 (inlined std::ptr::Alignment::as_nonzero) {
+	                      let mut _6: {closure@std::ptr::Alignment::as_nonzero::{closure#0}};
+	                      let mut _7: std::num::NonZero<usize>;
+	                      scope 8 {
+	                      }
+	                      scope 9 (inlined core::contracts::build_check_ensures::<NonZero<usize>, {closure@std::ptr::Alignment::as_nonzero::{closure#0}}>) {
+	                      }
13	                  }
-	                  scope 6 (inlined NonNull::<u8>::without_provenance) {
-	                      scope 7 {
+	                  scope 10 (inlined NonNull::<u8>::without_provenance) {
+	                      let _8: *const u8;
+	                      scope 11 {
16	                      }
-	                      scope 8 (inlined NonZero::<usize>::get) {
+	                      scope 12 (inlined NonZero::<usize>::get) {
18	                      }
-	                      scope 9 (inlined std::ptr::without_provenance::<u8>) {
-	                          scope 10 (inlined without_provenance_mut::<u8>) {
+	                      scope 13 (inlined std::ptr::without_provenance::<u8>) {
+	                          scope 14 (inlined without_provenance_mut::<u8>) {
21	                          }
22	                      }
23	                  }

24	              }
25	              scope 4 (inlined std::ptr::Alignment::of::<u8>) {
+	                  scope 5 {
+	                  }
+	                  scope 6 (inlined core::contracts::build_check_ensures::<std::ptr::Alignment, {closure@std::ptr::Alignment::of<u8>::{closure#0}}>) {
+	                  }
26	              }
27	          }
-	          scope 11 (inlined NonNull::<u8>::as_ptr) {
+	          scope 15 (inlined NonNull::<u8>::as_ptr) {
29	          }
30	      }
-	      scope 12 (inlined Foo::<u8>::cmp_ptr) {
-	          let mut _4: *const u8;
-	          let mut _5: *mut u8;
-	          let mut _6: *const u8;
-	          scope 13 (inlined std::ptr::eq::<u8>) {
+	      scope 16 (inlined Foo::<u8>::cmp_ptr) {
+	          let mut _9: *const u8;
+	          let mut _10: *mut u8;
+	          let mut _11: *const u8;
+	          scope 17 (inlined std::ptr::eq::<u8>) {
36	          }
37	      }
38

39	      bb0: {
40	          StorageLive(_1);
41	          StorageLive(_2);
+	-         StorageLive(_5);
+	+         nop;
42	          StorageLive(_3);
-	-         _3 = const std::ptr::Alignment::of::<u8>::{constant#0} as std::num::NonZero<usize> (Transmute);
-	-         _2 = copy _3 as *mut u8 (Transmute);
-	+         _3 = const NonZero::<usize>(core::num::niche_types::NonZeroUsizeInner(1_usize));
-	+         _2 = const {0x1 as *mut u8};
-	          StorageDead(_3);
48	          StorageLive(_4);
-	          StorageLive(_5);
-	-         _5 = copy _2;
-	-         _4 = copy _2 as *const u8 (PtrToPtr);
-	+         _5 = const {0x1 as *mut u8};
-	+         _4 = const {0x1 as *const u8};
-	          StorageDead(_5);
+	          _4 = contract_check_ensures::<{closure@std::ptr::Alignment::of<u8>::{closure#0}}, std::ptr::Alignment>(const ZeroSized: {closure@std::ptr::Alignment::of<u8>::{closure#0}}, const std::ptr::Alignment::of::<u8>::{constant#0}) -> [return: bb1, unwind continue];
+	      }
+
+	      bb1: {
55	          StorageLive(_6);
-	-         _6 = const Foo::<u8>::SENTINEL as *const u8 (PtrToPtr);
-	-         _1 = Eq(copy _4, copy _6);
-	+         _6 = const {0x1 as *const u8};
-	+         _1 = const true;
+	          _6 = {closure@$SRC_DIR/core/src/ptr/alignment.rs:LL:COL} { 0: copy _4 };
+	          StorageLive(_7);
+	          _7 = copy _4 as std::num::NonZero<usize> (Transmute);
+	          _5 = contract_check_ensures::<{closure@std::ptr::Alignment::as_nonzero::{closure#0}}, NonZero<usize>>(move _6, move _7) -> [return: bb2, unwind continue];
+	      }
+
+	      bb2: {
+	          StorageDead(_7);
60	          StorageDead(_6);
+	-         StorageLive(_8);
+	+         nop;
+	          _8 = copy _5 as *const u8 (Transmute);
+	          _3 = NonNull::<u8> { pointer: copy _8 };
+	-         StorageDead(_8);
+	+         nop;
61	          StorageDead(_4);
+	          _2 = copy _5 as *mut u8 (Transmute);
+	          StorageDead(_3);
+	-         StorageDead(_5);
+	+         nop;
+	          StorageLive(_9);
+	          StorageLive(_10);
+	          _10 = copy _2;
+	-         _9 = copy _2 as *const u8 (PtrToPtr);
+	+         _9 = copy _8;
+	          StorageDead(_10);
+	          StorageLive(_11);
+	-         _11 = const Foo::<u8>::SENTINEL as *const u8 (PtrToPtr);
+	-         _1 = Eq(copy _9, copy _11);
+	+         _11 = const {0x1 as *const u8};
+	+         _1 = Eq(copy _8, const {0x1 as *const u8});
+	          StorageDead(_11);
+	          StorageDead(_9);
62	          StorageDead(_2);
63	          StorageDead(_1);
64	          _0 = const ();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-contracts `#![feature(contracts)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.