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

Improve migration lint #58

Draft
wants to merge 33 commits into
base: rfc2229-migration-capture-kind
Choose a base branch
from

Conversation

roxelo
Copy link
Member

@roxelo roxelo commented Jul 7, 2021

Current state of the migration lint improvement.

Example of drop migration lint:

error: changes to closure capture in Rust 2021 will affect drop order
  --> $DIR/significant_drop.rs:163:21
   |
LL |               let c = || {
   |  _____________________^
LL | |
LL | |
LL | |
LL | |                 tuple.0;
   | |                 ------- in Rust 2018, closure captures all of `tuple`, but in Rust 2021, it only captures `tuple.0`
LL | |
LL | |             };
   | |_____________^
...
LL |           }
   |           - in Rust 2018, `tuple` would be dropped here, but in Rust 2021, only `tuple.0` would be dropped here alongside the closure

Example of trait migration lint:

error: changes to closure capture in Rust 2021 will affect `Send` closure trait implementation
  --> $DIR/auto_traits.rs:14:19
   |
LL |       thread::spawn(move || unsafe {
   |  ___________________^
LL | |
LL | |
LL | |
LL | |         *fptr.0 = 20;
   | |         ------- in Rust 2018, closure captures all of `fptr`, but in Rust 2021, it only captures `fptr.0`
LL | |
LL | |     });
   | |     ^ in Rust 2018, this closure would implement `Send` as `fptr` implements `Send`, but in Rust 2021, this closure will no longer implement `Send` as `fptr.0` does not implement `Send`
   | |_____|

arora-aman and others added 8 commits June 29, 2021 03:16
One key observation while going over the closure size profile of rustc
was that we are disjointly capturing one or more fields starting at an
immutable reference.

Disjoint capture over immutable reference doesn't add too much value
because the fields can either be borrowed immutably or copied.

One possible edge case of the optimization is when a fields of a struct
have a longer lifetime than the structure, therefore we can't completely
get rid of all the accesses on top of sharef refs, only the rightmost
one. Here is a possible example:

```rust
struct MyStruct<'a> {
   a: &'static A,
   b: B,
   c: C<'a>,
}

fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static {
    let c = || drop(&*m.a.field_of_a);
    // Here we really do want to capture `*m.a` because that outlives `'static`

    // If we capture `m`, then the closure no longer outlives `'static'
    // it is constrained to `'a`
}
```
@roxelo roxelo force-pushed the rfc2229-improve-lint branch 2 times, most recently from 9ef334f to dc20230 Compare July 7, 2021 23:09
m-ou-se and others added 3 commits July 8, 2021 11:33
special case for integer log10

Now that rust-lang#80918 has been merged, this PR provides a faster version of `log10`.

The PR also adds some tests for values close to all powers of 10.
@roxelo roxelo force-pushed the rfc2229-migration-capture-kind branch from 94530e3 to 7c15fc1 Compare July 8, 2021 21:08
@roxelo roxelo force-pushed the rfc2229-improve-lint branch from dc20230 to 64383fa Compare July 8, 2021 21:38
@roxelo roxelo force-pushed the rfc2229-improve-lint branch 2 times, most recently from 9b0e94d to 10088df Compare July 8, 2021 22:04
@roxelo roxelo force-pushed the rfc2229-improve-lint branch from 10088df to a298535 Compare July 8, 2021 22:31
bors added 3 commits July 9, 2021 01:13
2229: Reduce the size of closures with `capture_disjoint_fields`

One key observation while going over the closure size profile of rustc
was that we are disjointly capturing one or more fields starting at an
immutable reference.

Disjoint capture over immutable reference doesn't add too much value
because the fields can either be borrowed immutably or copied.

One possible edge case of the optimization is when a fields of a struct
have a longer lifetime than the structure, therefore we can't completely
get rid of all the accesses on top of sharef refs, only the rightmost
one. Here is a possible example:

```rust
struct MyStruct<'a> {
   a: &'static A,
   b: B,
   c: C<'a>,
}

fn foo<'a, 'b>(m: &'a MyStruct<'b>) -> impl FnMut() + 'static {
    let c = || drop(&*m.a.field_of_a);
    // Here we really do want to capture `*m.a` because that outlives `'static`

    // If we capture `m`, then the closure no longer outlives `'static'
    // it is constrained to `'a`
}
```

r? `@nikomatsakis`
…-kind, r=nikomatsakis

Account for capture kind in auto traits migration

Modifies the current auto traits migration for RFC2229 so it takes into account capture kind

Closes rust-lang/project-rfc-2229#51

r? `@nikomatsakis`
…, r=nikomatsakis

Check FromIterator trait impl in prelude collision check.

Fixes rust-lang#86902.
bors and others added 9 commits July 9, 2021 09:16
Stop generating `alloca`s & `memcmp` for simple short array equality

Example:
```rust
pub fn demo(x: [u16; 6], y: [u16; 6]) -> bool { x == y }
```

Before:
```llvm
define zeroext i1 `@_ZN10playground4demo17h48537f7eac23948fE(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %y = alloca [6 x i16], align 8
  %x = alloca [6 x i16], align 8
  %.0..sroa_cast = bitcast [6 x i16]* %x to i96*
  store i96 %0, i96* %.0..sroa_cast, align 8
  %.0..sroa_cast3 = bitcast [6 x i16]* %y to i96*
  store i96 %1, i96* %.0..sroa_cast3, align 8
  %_11.i.i.i = bitcast [6 x i16]* %x to i8*
  %_14.i.i.i = bitcast [6 x i16]* %y to i8*
  %bcmp.i.i.i = call i32 `@bcmp(i8*` nonnull dereferenceable(12) %_11.i.i.i, i8* nonnull dereferenceable(12) %_14.i.i.i, i64 12) #2, !alias.scope !2
  %2 = icmp eq i32 %bcmp.i.i.i, 0
  ret i1 %2
}
```
```x86
playground::demo: # `@playground::demo`
	sub	rsp, 32
	mov	qword ptr [rsp], rdi
	mov	dword ptr [rsp + 8], esi
	mov	qword ptr [rsp + 16], rdx
	mov	dword ptr [rsp + 24], ecx
	xor	rdi, rdx
	xor	esi, ecx
	or	rsi, rdi
	sete	al
	add	rsp, 32
	ret
```

After:
```llvm
define zeroext i1 `@_ZN4mini4demo17h7a8994aaa314c981E(i96` %0, i96 %1) unnamed_addr #0 {
start:
  %2 = icmp eq i96 %0, %1
  ret i1 %2
}
```
```x86
_ZN4mini4demo17h7a8994aaa314c981E:
	xor	rcx, r8
	xor	edx, r9d
	or	rdx, rcx
	sete	al
	ret
```
@roxelo roxelo force-pushed the rfc2229-improve-lint branch from a298535 to 8cbeaf7 Compare July 9, 2021 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants