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

Codegen ZSTs without an allocation #123936

Merged
merged 2 commits into from
Apr 17, 2024
Merged

Conversation

Mark-Simulacrum
Copy link
Member

This makes sure that &[] is equivalent to unsafe code (from_raw_parts(dangling, 0)). No new stable guarantee is intended about whether or not we do this, this is just an optimization.

This regressed in #67000 (no comments I can see about that regression in the PR, though it did change the test modified here). We had previously performed this optimization since #63635.

@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2024

r? @lcnr

rustbot has assigned @lcnr.
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

@Mark-Simulacrum
Copy link
Member Author

@bors try @rust-timer queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 14, 2024
@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 14, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2024
Codegen ZSTs without an allocation

This makes sure that &[] is equivalent to unsafe code (from_raw_parts(dangling, 0)). No new stable guarantee is intended about whether or not we do this, this is just an optimization.

This regressed in rust-lang#67000 (no comments I can see about that regression in the PR, though it did change the test modified here). We had previously performed this optimization since rust-lang#63635.
@bors
Copy link
Contributor

bors commented Apr 14, 2024

⌛ Trying commit 1266e22 with merge f266dba...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 14, 2024

💔 Test failed - checks-actions

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 14, 2024
@rust-log-analyzer

This comment has been minimized.

@Mark-Simulacrum
Copy link
Member Author

@bors try

@bors
Copy link
Contributor

bors commented Apr 14, 2024

⌛ Trying commit 388646a with merge 0d984e9...

bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 14, 2024
Codegen ZSTs without an allocation

This makes sure that &[] is equivalent to unsafe code (from_raw_parts(dangling, 0)). No new stable guarantee is intended about whether or not we do this, this is just an optimization.

This regressed in rust-lang#67000 (no comments I can see about that regression in the PR, though it did change the test modified here). We had previously performed this optimization since rust-lang#63635.
@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Apr 14, 2024

☀️ Try build successful - checks-actions
Build commit: 0d984e9 (0d984e9cba0b38db05ce9ac01597ab4b04604840)

@rust-timer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Apr 14, 2024

Some changes occurred in run-make tests.

cc @jieyouxu

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (0d984e9): comparison URL.

Overall result: no relevant changes - no 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.

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

Instruction count

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

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.5% [-2.4%, -0.1%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.5% [-2.4%, -0.1%] 3

Cycles

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.1% [-2.1%, -2.1%] 1
All ❌✅ (primary) - - 0

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.3%, -0.0%] 61
Improvements ✅
(secondary)
-0.8% [-2.3%, -0.0%] 16
All ❌✅ (primary) -0.1% [-0.3%, -0.0%] 61

Bootstrap: 677.239s -> 677.892s (0.10%)
Artifact size: 315.99 MiB -> 315.96 MiB (-0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Apr 14, 2024
@Mark-Simulacrum
Copy link
Member Author

Rebased atop #123941, but otherwise this looks ready for review. Perf results indicate neutral runtime performance but a clear, though small, improvement in binary sizes.

@lcnr
Copy link
Contributor

lcnr commented Apr 15, 2024

cc @RalfJung

This seems totally fine to me, I didn't try to understand the changes to the llvm wrapper yet 🤔 intend to look at it in-depth in a few days and then merge it unless there are any concerns

@Mark-Simulacrum
Copy link
Member Author

Those changes will get squashed/rebased away (already approved in a separate PR).

IMO the fact that this found 1 case of UB and 1 broken test is actually pretty good justification for wanting to do it :)

@oli-obk oli-obk assigned RalfJung and unassigned lcnr Apr 17, 2024
@RalfJung
Copy link
Member

Sorry, I'm not comfortable approving codegen PRs...
r? compiler

@rustbot rustbot assigned wesleywiser and unassigned RalfJung Apr 17, 2024
@oli-obk
Copy link
Contributor

oli-obk commented Apr 17, 2024

r? @oli-obk

@bors r+

@bors
Copy link
Contributor

bors commented Apr 17, 2024

📌 Commit 9ab6e36 has been approved by oli-obk

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 Apr 17, 2024
@bors
Copy link
Contributor

bors commented Apr 17, 2024

⌛ Testing commit 9ab6e36 with merge 38104f3...

@bors
Copy link
Contributor

bors commented Apr 17, 2024

☀️ Test successful - checks-actions
Approved by: oli-obk
Pushing 38104f3 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 17, 2024
@bors bors merged commit 38104f3 into rust-lang:master Apr 17, 2024
13 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Apr 17, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (38104f3): comparison URL.

Overall result: ✅ improvements - no action needed

@rustbot label: -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)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.3%] 1
All ❌✅ (primary) - - 0

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)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-1.6% [-3.3%, -0.1%] 3
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -1.6% [-3.3%, -0.1%] 3

Cycles

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.4%, -1.9%] 2
All ❌✅ (primary) - - 0

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
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.3%, -0.0%] 64
Improvements ✅
(secondary)
-0.7% [-2.3%, -0.0%] 19
All ❌✅ (primary) -0.1% [-0.3%, -0.0%] 64

Bootstrap: 677.444s -> 677.262s (-0.03%)
Artifact size: 316.09 MiB -> 316.13 MiB (0.01%)

@alice-i-cecile
Copy link

FYI, this PR seems to have somehow broken Bevy's rendering with Rust 1.79, but only on Windows, and only with some hardware. Any tips on where to start debugging or resolving this would be appreciated.

@janhohenheim
Copy link
Contributor

^ and only when using DX12 as a backend

@workingjubilee
Copy link
Member

workingjubilee commented Jun 14, 2024

FYI, this PR seems to have somehow broken Bevy's rendering with Rust 1.79, but only on Windows, and only with some hardware. Any tips on where to start debugging or resolving this would be appreciated.

The issue is most likely that something was inappropriately relying on pointer equalities or inequalities that changed. Statics are not constants, but people slip up and address them as the same thing. Even if the Rust code itself doesn't do address equating, Rust coerces references to pointers, so often people directly pass a reference to a constant into FFI. Some DX12 code could have been happily reading some random uninit garbage and not really caring because it wasn't really using that read for anything important (i.e. "UB, but it had no significant effect in actual executions of a short-lived, very simple demo program"), but with this change, decided to deref a pointer into the zeroth page today, causing a segfault.

@workingjubilee
Copy link
Member

( It is of course entirely plausible I am talking nonsense and it is a much more exotic problem or at least a more interesting bug, but I would first try to eliminate that case, which is why the curiosity about a backtrace in #126442 (comment) )

@Mark-Simulacrum Mark-Simulacrum deleted the zst-no-alloc branch June 15, 2024 15:06
BurntSushi added a commit to BurntSushi/rust-pcre2 that referenced this pull request Jul 30, 2024
To work around likely bugs in (older versions of) PCRE2. Namely, at one
point, PCRE2 would dereference the haystack pointer even when the length
was zero.

This was reported in #10 and we worked around this in #11 by passing a
pointer to a const `&[]`, with the (erroneous) presumption that this
would be a valid pointer to dereference. In retrospect though, this was
a little silly, because you should never be dereferencing a pointer to
an empty slice. It's not valid. Alas, at that time, Rust did actually
hand you a valid pointer that could be dereferenced. But [this
PR][rust-pull] changed that. And thus, we're back to where we started:
handing buggy versions of PCRE2 a zero length haystack with a dangling
pointer.

So we fix this once and for all by passing a slice of length 1, but with
a haystack length of 0, to the PCRE2 search routine when searching an
empty haystack. This will guarantee the provision of a dereferencable
pointer should PCRE2 decide to dereference it.

Fixes #42

[rust-pull]: rust-lang/rust#123936
BurntSushi added a commit to BurntSushi/rust-pcre2 that referenced this pull request Jul 30, 2024
To work around likely bugs in (older versions of) PCRE2. Namely, at one
point, PCRE2 would dereference the haystack pointer even when the length
was zero.

This was reported in #10 and we worked around this in #11 by passing a
pointer to a const `&[]`, with the (erroneous) presumption that this
would be a valid pointer to dereference. In retrospect though, this was
a little silly, because you should never be dereferencing a pointer to
an empty slice. It's not valid. Alas, at that time, Rust did actually
hand you a valid pointer that could be dereferenced. But [this
PR][rust-pull] changed that. And thus, we're back to where we started:
handing buggy versions of PCRE2 a zero length haystack with a dangling
pointer.

So we fix this once and for all by passing a slice of length 1, but with
a haystack length of 0, to the PCRE2 search routine when searching an
empty haystack. This will guarantee the provision of a dereferencable
pointer should PCRE2 decide to dereference it.

Fixes #42

[rust-pull]: rust-lang/rust#123936
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant 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.