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

Return `false` from `needs_drop` for all zero-sized arrays. #65389

Merged
merged 3 commits into from Oct 16, 2019

Conversation

@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Oct 13, 2019

Resolves #65348.

This changes the result of the needs_drop query from true to false for types such as [Box<i32>; 0]. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving #65348 and #64945, but obviously it has much broader implications.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Oct 13, 2019

r? @davidtwco

(rust_highfive has picked a reviewer for you, use r? to override)

@ecstatic-morse

This comment has been minimized.

Copy link
Contributor Author

ecstatic-morse commented Oct 13, 2019

Not sure that this is ultimately the way to go, but may be worth discussing. We may want a more targeted fix.

cc @eddyb @oli-obk @RalfJung.

@davidtwco

This comment has been minimized.

Copy link
Member

davidtwco commented Oct 13, 2019

r? @eddyb

@rust-highfive rust-highfive assigned eddyb and unassigned davidtwco Oct 13, 2019
@Centril

This comment has been minimized.

Copy link
Member

Centril commented Oct 13, 2019

We already special case zero sized arrays in other places so I'm comfortable with doing it here as well. However, cc @rust-lang/lang

@ecstatic-morse ecstatic-morse force-pushed the ecstatic-morse:zero-sized-array-no-drop branch from 82e9edc to c08a871 Oct 13, 2019
@ecstatic-morse

This comment has been minimized.

Copy link
Contributor Author

ecstatic-morse commented Oct 13, 2019

I added a regression test for the underlying const validation issue as well. A perf run might be informative here. This will result in more calls to try_eval_usize, but will also emit fewer drop terminators in code that constructs an empty array or slice whose element type may have a Drop impl.

@Centril

This comment has been minimized.

Copy link
Member

Centril commented Oct 14, 2019

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Oct 14, 2019

Awaiting bors try build completion

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 14, 2019

⌛️ Trying commit c08a871 with merge e823bc1...

bors added a commit that referenced this pull request Oct 14, 2019
Return `false` from `needs_drop` for all zero-sized arrays.

Resolves #65348.

This changes the result of the `needs_drop` query from `true` to `false` for types such as `[Box<i32>; 0]`. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving #65348 and #64945, but obviously it has much broader implications.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 14, 2019

☀️ Try build successful - checks-azure
Build commit: e823bc1 (e823bc1930f285a41408feda9a2dfc80bffbb5b8)

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Oct 14, 2019

Queued e823bc1 with parent 36d4506, future comparison URL.

@eddyb
eddyb approved these changes Oct 14, 2019
Copy link
Member

eddyb left a comment

r=me

@rust-timer

This comment has been minimized.

Copy link

rust-timer commented Oct 14, 2019

Finished benchmarking try commit e823bc1, comparison URL.

@ecstatic-morse

This comment has been minimized.

Copy link
Contributor Author

ecstatic-morse commented Oct 15, 2019

Perf impact is negligible. Just needs an r+.

@eddyb

This comment has been minimized.

Copy link
Member

eddyb commented Oct 15, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 15, 2019

📌 Commit c08a871 has been approved by eddyb

Centril added a commit to Centril/rust that referenced this pull request Oct 15, 2019
…drop, r=eddyb

Return `false` from `needs_drop` for all zero-sized arrays.

Resolves rust-lang#65348.

This changes the result of the `needs_drop` query from `true` to `false` for types such as `[Box<i32>; 0]`. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving rust-lang#65348 and rust-lang#64945, but obviously it has much broader implications.
bors added a commit that referenced this pull request Oct 15, 2019
Rollup of 9 pull requests

Successful merges:

 - #65094 (Prefer statx on linux if available)
 - #65235 (don't assume we can *always* find a return type hint in async fn)
 - #65242 (Fix suggestion to constrain trait for method to be found)
 - #65307 (Try fix incorrect "explicit lifetime name needed")
 - #65389 (Return `false` from `needs_drop` for all zero-sized arrays.)
 - #65402 (Add troubleshooting section to PGO chapter in rustc book.)
 - #65435 (Fix #64153)
 - #65438 (Organize `never_type`  tests)
 - #65444 (Implement AsRef<[T]> for List<T>)

Failed merges:

r? @ghost
Centril added a commit to Centril/rust that referenced this pull request Oct 15, 2019
…drop, r=eddyb

Return `false` from `needs_drop` for all zero-sized arrays.

Resolves rust-lang#65348.

This changes the result of the `needs_drop` query from `true` to `false` for types such as `[Box<i32>; 0]`. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving rust-lang#65348 and rust-lang#64945, but obviously it has much broader implications.
bors added a commit that referenced this pull request Oct 15, 2019
Rollup of 8 pull requests

Successful merges:

 - #64603 (Reducing spurious unused lifetime warnings.)
 - #65235 (don't assume we can *always* find a return type hint in async fn)
 - #65307 (Try fix incorrect "explicit lifetime name needed")
 - #65389 (Return `false` from `needs_drop` for all zero-sized arrays.)
 - #65402 (Add troubleshooting section to PGO chapter in rustc book.)
 - #65435 (Fix #64153)
 - #65438 (Organize `never_type`  tests)
 - #65444 (Implement AsRef<[T]> for List<T>)

Failed merges:

r? @ghost
tmandry added a commit to tmandry/rust that referenced this pull request Oct 15, 2019
…drop, r=eddyb

Return `false` from `needs_drop` for all zero-sized arrays.

Resolves rust-lang#65348.

This changes the result of the `needs_drop` query from `true` to `false` for types such as `[Box<i32>; 0]`. I believe this change to be sound because a zero-sized array can never actually hold a value. This is an elegant way of resolving rust-lang#65348 and rust-lang#64945, but obviously it has much broader implications.
bors added a commit that referenced this pull request Oct 15, 2019
Rollup of 14 pull requests

Successful merges:

 - #64603 (Reducing spurious unused lifetime warnings.)
 - #64623 (Remove last uses of gensyms)
 - #65235 (don't assume we can *always* find a return type hint in async fn)
 - #65242 (Fix suggestion to constrain trait for method to be found)
 - #65265 (Cleanup librustc mir err codes)
 - #65293 (Optimize `try_expand_impl_trait_type`)
 - #65307 (Try fix incorrect "explicit lifetime name needed")
 - #65308 (Add long error explanation for E0574)
 - #65353 (save-analysis: Don't ICE when resolving qualified type paths in struct members)
 - #65389 (Return `false` from `needs_drop` for all zero-sized arrays.)
 - #65402 (Add troubleshooting section to PGO chapter in rustc book.)
 - #65425 (Optimize `BitIter`)
 - #65438 (Organize `never_type`  tests)
 - #65444 (Implement AsRef<[T]> for List<T>)

Failed merges:

 - #65390 (Add long error explanation for E0576)

r? @ghost
@bors bors merged commit c08a871 into rust-lang:master Oct 16, 2019
5 checks passed
5 checks passed
homu Test successful
Details
pr Build #20191013.63 succeeded
Details
pr (Linux mingw-check) Linux mingw-check succeeded
Details
pr (Linux x86_64-gnu-llvm-6.0) Linux x86_64-gnu-llvm-6.0 succeeded
Details
pr (LinuxTools) LinuxTools succeeded
Details
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Oct 16, 2019

☔️ The latest upstream changes (presumably #65454) made this pull request unmergeable. Please resolve the merge conflicts.

@ecstatic-morse ecstatic-morse deleted the ecstatic-morse:zero-sized-array-no-drop branch Oct 16, 2019
bors added a commit that referenced this pull request Oct 25, 2019
[DO NOT MERGE] Crater test

#64470 + #65389 for a crater run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants
You can’t perform that action at this time.