forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#98337 - c410-f3r:assert-compiler, r=oli-obk
[RFC 2011] Optimize non-consuming operators Tracking issue: rust-lang#44838 Fifth step of rust-lang#96496 The most non-invasive approach that will probably have very little to no performance impact. ## Current behaviour Captures are handled "on-the-fly", i.e., they are performed in the same place expressions are located. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( { ***try capture `a` and then return `a`*** } > 1 && { ***try capture `b` and then return `b`*** } < 100 ) { panic!( ... ); } ``` As such, some overhead is likely to occur (Specially with very large chains of conditions). ## New behaviour for non-consuming operators When an operator is known to not take `self`, then it is possible to capture variables **AFTER** the condition. ```rust // `let a = 1; let b = 2; assert!(a > 1 && b < 100);` if !( a > 1 && b < 100 ) { { ***try capture `a`*** } { ***try capture `b`*** } panic!( ... ); } ``` So the possible impact on the runtime execution time will be diminished. r? ````@oli-obk````
- Loading branch information
Showing
5 changed files
with
260 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
src/test/ui/macros/rfc-2011-nicer-assert-messages/codegen.stdout
This file was deleted.
Oops, something went wrong.
32 changes: 32 additions & 0 deletions
32
.../ui/macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// check-pass | ||
// compile-flags: -Z unpretty=expanded | ||
|
||
#![feature(core_intrinsics, generic_assert, generic_assert_internals)] | ||
|
||
fn arbitrary_consuming_method_for_demonstration_purposes() { | ||
let elem = 1i32; | ||
assert!(elem as usize); | ||
} | ||
|
||
fn addr_of() { | ||
let elem = 1i32; | ||
assert!(&elem); | ||
} | ||
|
||
fn binary() { | ||
let elem = 1i32; | ||
assert!(elem == 1); | ||
assert!(elem >= 1); | ||
assert!(elem > 0); | ||
assert!(elem < 3); | ||
assert!(elem <= 3); | ||
assert!(elem != 3); | ||
} | ||
|
||
fn unary() { | ||
let elem = &1i32; | ||
assert!(*elem); | ||
} | ||
|
||
fn main() { | ||
} |
147 changes: 147 additions & 0 deletions
147
...macros/rfc-2011-nicer-assert-messages/non-consuming-methods-have-optimized-codegen.stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
#![feature(prelude_import)] | ||
#![no_std] | ||
// check-pass | ||
// compile-flags: -Z unpretty=expanded | ||
|
||
#![feature(core_intrinsics, generic_assert, generic_assert_internals)] | ||
#[prelude_import] | ||
use ::std::prelude::rust_2015::*; | ||
#[macro_use] | ||
extern crate std; | ||
|
||
fn arbitrary_consuming_method_for_demonstration_purposes() { | ||
let elem = 1i32; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*{ | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
__local_bind0 | ||
} as usize)) { | ||
|
||
|
||
|
||
|
||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem as usize\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
} | ||
fn addr_of() { | ||
let elem = 1i32; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!&*__local_bind0) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: &elem\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
} | ||
fn binary() { | ||
let elem = 1i32; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 == 1)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem == 1\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 >= 1)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem >= 1\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 > 0)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem > 0\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 < 3)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem < 3\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 <= 3)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem <= 3\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!(*__local_bind0 != 3)) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: elem != 3\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
} | ||
fn unary() { | ||
let elem = &1i32; | ||
{ | ||
#[allow(unused_imports)] | ||
use ::core::asserting::{TryCaptureGeneric, TryCapturePrintable}; | ||
let mut __capture0 = ::core::asserting::Capture::new(); | ||
let __local_bind0 = &elem; | ||
if ::core::intrinsics::unlikely(!**__local_bind0) { | ||
(&::core::asserting::Wrapper(__local_bind0)).try_capture(&mut __capture0); | ||
{ | ||
::std::rt::panic_fmt(::core::fmt::Arguments::new_v1(&["Assertion failed: *elem\nWith captures:\n elem = ", | ||
"\n"], &[::core::fmt::ArgumentV1::new_debug(&__capture0)])) | ||
} | ||
} | ||
}; | ||
} | ||
fn main() {} |