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

Use transmute_unchecked in NonZero::new. #120809

Merged
merged 1 commit into from
Feb 9, 2024

Conversation

reitermarkus
Copy link
Contributor

@reitermarkus reitermarkus commented Feb 8, 2024

Tracking issue: #120257

See #120521 (comment).

@rustbot
Copy link
Collaborator

rustbot commented Feb 8, 2024

r? @cuviper

rustbot has assigned @cuviper.
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-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 8, 2024
@reitermarkus reitermarkus force-pushed the generic-nonzero-constructors branch from 8c613db to d70d320 Compare February 8, 2024 19:44
@Noratrieb
Copy link
Member

cool!
@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 8, 2024

📌 Commit d70d320 has been approved by Nilstrieb

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 Feb 8, 2024
@scottmcm
Copy link
Member

scottmcm commented Feb 8, 2024

Thanks! This should save a bunch of MIR.

Per https://rust.godbolt.org/z/Ecjsvd9MM, this makes it just

fn demo_new(_1: u32) -> f32 {
    debug n => _1;
    let mut _0: f32;

    bb0: {
        _0 = _1 as f32 (Transmute);
        return;
    }
}

instead of all this with the pointers

fn demo_old(_1: u32) -> f32 {
    debug n => _1;
    let mut _0: f32;
    let mut _2: *const f32;
    let mut _3: *const u32;
    scope 1 (inlined std::ptr::const_ptr::<impl *const u32>::cast::<f32>) {
        debug self => _3;
    }
    scope 2 (inlined std::ptr::read::<f32>) {
        debug src => _2;
        let mut _4: *const f32;
        scope 3 {
            scope 4 (inlined std::ptr::read::runtime::<f32>) {
                debug src => _4;
                scope 5 (inlined intrinsics::is_aligned_and_not_null::<f32>) {
                    debug ptr => _4;
                    scope 6 (inlined std::ptr::const_ptr::<impl *const f32>::is_null) {
                        debug self => _4;
                        let mut _5: *const u8;
                        scope 7 {
                            scope 8 (inlined std::ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
                                debug ptr => _5;
                                scope 9 (inlined std::ptr::const_ptr::<impl *const u8>::addr) {
                                    debug self => _5;
                                    scope 10 {
                                        scope 11 (inlined std::ptr::const_ptr::<impl *const u8>::cast::<()>) {
                                            debug self => _5;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    scope 12 (inlined std::ptr::const_ptr::<impl *const f32>::is_aligned) {
                        debug self => _4;
                        scope 13 (inlined align_of::<f32>) {
                        }
                    }
                }
            }
        }
    }

    bb0: {
        StorageLive(_2);
        StorageLive(_3);
        _3 = &raw const _1;
        _2 = _3 as *const f32 (PtrToPtr);
        StorageDead(_3);
        StorageLive(_4);
        StorageLive(_5);
        _0 = (*_2);
        StorageDead(_5);
        StorageDead(_4);
        StorageDead(_2);
        return;
    }
}

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 9, 2024
…ructors, r=Nilstrieb

Use `transmute_unchecked` in `NonZero::new`.

Tracking issue: rust-lang#120257

See rust-lang#120521 (comment).
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120589 (std::thread::available_parallelism merging linux/android/freebsd version)
 - rust-lang#120596 ([rustdoc] Correctly generate path for non-local items in source code pages)
 - rust-lang#120672 (std::thread update freebsd stack guard handling.)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120806 (Clippy subtree update)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 9, 2024
…ructors, r=Nilstrieb

Use `transmute_unchecked` in `NonZero::new`.

Tracking issue: rust-lang#120257

See rust-lang#120521 (comment).
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120596 ([rustdoc] Correctly generate path for non-local items in source code pages)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)
 - rust-lang#120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 9, 2024
…ructors, r=Nilstrieb

Use `transmute_unchecked` in `NonZero::new`.

Tracking issue: rust-lang#120257

See rust-lang#120521 (comment).
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#113026 (Introduce `run-make` V2 infrastructure, a `run_make_support` library and port over 2 tests as example)
 - rust-lang#113671 (Make privacy visitor use types more (instead of HIR))
 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)
 - rust-lang#120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)
 - rust-lang#120831 (Startup objects disappearing from sysroot)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#113671 (Make privacy visitor use types more (instead of HIR))
 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)
 - rust-lang#120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)
 - rust-lang#120831 (Startup objects disappearing from sysroot)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 475c47a into rust-lang:master Feb 9, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 9, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 9, 2024
Rollup merge of rust-lang#120809 - reitermarkus:generic-nonzero-constructors, r=Nilstrieb

Use `transmute_unchecked` in `NonZero::new`.

Tracking issue: rust-lang#120257

See rust-lang#120521 (comment).
@reitermarkus reitermarkus deleted the generic-nonzero-constructors branch February 9, 2024 19:05
@scottmcm
Copy link
Member

scottmcm commented Feb 9, 2024

Since the rollup showed perf changes, I'm curious

@rust-timer build 1476217

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1476217): comparison URL.

Overall result: ❌✅ regressions and improvements - ACTION NEEDED

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please fix the regressions and do another perf run. If the next run shows neutral or positive results, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
1.3% [1.3%, 1.3%] 1
Improvements ✅
(primary)
-0.4% [-0.8%, -0.2%] 6
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) -0.4% [-0.8%, -0.2%] 6

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)
7.4% [4.3%, 10.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.2% [-3.2%, -3.2%] 1
Improvements ✅
(secondary)
-5.0% [-5.0%, -5.0%] 1
All ❌✅ (primary) 3.9% [-3.2%, 10.5%] 3

Cycles

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

Binary size

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)
0.1% [0.0%, 0.4%] 8
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.4%, -0.0%] 30
Improvements ✅
(secondary)
-1.2% [-1.3%, -1.2%] 3
All ❌✅ (primary) -0.0% [-0.4%, 0.4%] 38

Bootstrap: 663.818s -> 665.912s (0.32%)
Artifact size: 308.01 MiB -> 308.06 MiB (0.01%)

@rustbot rustbot added the perf-regression Performance regression. label Feb 9, 2024
@reitermarkus
Copy link
Contributor Author

Seems like the -0.4% here pretty much undid the 0.5% regression, if I'm reading that correctly.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Feb 26, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#113671 (Make privacy visitor use types more (instead of HIR))
 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)
 - rust-lang#120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)
 - rust-lang#120831 (Startup objects disappearing from sysroot)

r? `@ghost`
`@rustbot` modify labels: rollup
bjorn3 pushed a commit to bjorn3/rust that referenced this pull request Mar 8, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#113671 (Make privacy visitor use types more (instead of HIR))
 - rust-lang#120308 (core/time: avoid divisions in Duration::new)
 - rust-lang#120693 (Invert diagnostic lints.)
 - rust-lang#120704 (A drive-by rewrite of `give_region_a_name()`)
 - rust-lang#120809 (Use `transmute_unchecked` in `NonZero::new`.)
 - rust-lang#120817 (Fix more `ty::Error` ICEs in MIR passes)
 - rust-lang#120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.)
 - rust-lang#120831 (Startup objects disappearing from sysroot)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

7 participants