Skip to content

[RFC 2011] Optimize non-consuming operators - #98337

Merged
bors merged 1 commit into
rust-lang:masterfrom
c410-f3r:assert-compiler
Jun 28, 2022
Merged

[RFC 2011] Optimize non-consuming operators#98337
bors merged 1 commit into
rust-lang:masterfrom
c410-f3r:assert-compiler

Conversation

@c410-f3r

@c410-f3rc410-f3r commented Jun 21, 2022

Copy link
Copy Markdown
Contributor

Tracking issue: #44838
Fifth step of #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.

// `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.

// `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

@rustbotrustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jun 21, 2022
@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 21, 2022
Comment threadcompiler/rustc_builtin_macros/src/assert/context.rs Outdated
@oli-obk

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Jun 21, 2022

Copy link
Copy Markdown
Collaborator

📌 Commit a0eba66 has been approved by oli-obk

@borsbors 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 Jun 21, 2022
@c410-f3r

Copy link
Copy Markdown
ContributorAuthor

Thank you @oli-obk

Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 22, 2022
[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`
@Dylan-DPCDylan-DPC mentioned this pull request Jun 22, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 24, 2022
[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``
@Dylan-DPCDylan-DPC mentioned this pull request Jun 24, 2022
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Jun 28, 2022
[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```
@Dylan-DPCDylan-DPC mentioned this pull request Jun 28, 2022
@Dylan-DPCDylan-DPC mentioned this pull request Jun 28, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 28, 2022
Rollup of 9 pull requests
Successful merges:
- rust-lang#97346 (Remove a back-compat hack on lazy TAIT)
- rust-lang#98261 (Remove `MAX_SUGGESTION_HIGHLIGHT_LINES`)
- rust-lang#98337 ([RFC 2011] Optimize non-consuming operators)
- rust-lang#98384 (Fix RSS reporting on macOS)
- rust-lang#98420 (translation: lint fix + more migration)
- rust-lang#98430 (Refactor iter adapters with less macros)
- rust-lang#98555 (Hermit: Fix initializing lazy locks)
- rust-lang#98595 (Implement `Send` and `Sync` for `ThinBox<T>`)
- rust-lang#98597 (Remove unstable CStr/CString change from 1.62 release note)
Failed merges:
r? `@ghost`
`@rustbot` modify labels: rollup
@bors
bors merged commit ec8477f into rust-lang:masterJun 28, 2022
@rustbotrustbot added this to the 1.64.0 milestone Jun 28, 2022
@fmeasefmease added the F-generic_assert `#![feature(generic_assert)]` label Apr 8, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-generic_assert`#![feature(generic_assert)]`S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@c410-f3r@oli-obk@bors@rust-highfive@fmease@rustbot