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

Reduce size of InterpErrorInfo to 8 bytes #82116

Merged
merged 2 commits into from
Feb 17, 2021
Merged

Conversation

tmiasko
Copy link
Contributor

@tmiasko tmiasko commented Feb 14, 2021

r? @ghost

@tmiasko
Copy link
Contributor Author

tmiasko commented Feb 14, 2021

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Feb 14, 2021
@bors
Copy link
Contributor

bors commented Feb 14, 2021

⌛ Trying commit c7393c762a516a2151cfbe27f7096f01cbb19933 with merge e868f5cd6ef13410be12eacb2cdf41f68cb1c226...

@bors
Copy link
Contributor

bors commented Feb 14, 2021

☀️ Try build successful - checks-actions
Build commit: e868f5cd6ef13410be12eacb2cdf41f68cb1c226 (e868f5cd6ef13410be12eacb2cdf41f68cb1c226)

@rust-timer
Copy link
Collaborator

Queued e868f5cd6ef13410be12eacb2cdf41f68cb1c226 with parent 5fa22fe, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (e868f5cd6ef13410be12eacb2cdf41f68cb1c226): comparison url.

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying rollup- to bors.

Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up.

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Feb 14, 2021
@tmiasko
Copy link
Contributor Author

tmiasko commented Feb 14, 2021

r? @oli-obk


#[derive(Debug)]
struct InterpErrorInfoInner<'tcx> {
kind: InterpError<'tcx>,
backtrace: Option<Box<Backtrace>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is already in a Box do we need a second Box here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this will be None in most cases (unless debugging the const evaluator), I'd leave this box in in order to not increase the regular size of the InterpErrorInfoInner.

Copy link
Contributor

@pickfire pickfire Feb 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But if kind is used won't backtrace be used as well? Do we need a second indirection?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backtrace is only used if RUSTC_CTFE_BACKTRACE is set. In all other cases there will be no Box allocated. I'm not sure how large a Backtracestruct is, but if it's larger than8bytes, for all normal cases we don't waste space, as noBoxis allocated. It's fine to have arbitrary costs ifRUSTC_CTFE_BACKTRACE` is used, as that is already expensive by itself

@oli-obk
Copy link
Contributor

oli-obk commented Feb 15, 2021

Amazing! Really good find.

@bors r+

@bors
Copy link
Contributor

bors commented Feb 15, 2021

📌 Commit c7393c762a516a2151cfbe27f7096f01cbb19933 has been approved by oli-obk

@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 Feb 15, 2021
@bors
Copy link
Contributor

bors commented Feb 17, 2021

⌛ Testing commit c7393c762a516a2151cfbe27f7096f01cbb19933 with merge d8ac472db5025de359865f5779c9d6b15b893692...

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Feb 17, 2021

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Feb 17, 2021
The test case fails with either one error or two errors.
Use a single code generation unit to avoid nondeterminism.
@tmiasko
Copy link
Contributor Author

tmiasko commented Feb 17, 2021

Used -Ccodegen-units=1 to avoid nondeterminism in failed test case ui/issues/issue-23458.rs.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 17, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Feb 17, 2021

📌 Commit 614b0cc has been approved by oli-obk

@bors bors removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 17, 2021
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Feb 17, 2021
@bors
Copy link
Contributor

bors commented Feb 17, 2021

⌛ Testing commit 614b0cc with merge 5ef2106...

@bors
Copy link
Contributor

bors commented Feb 17, 2021

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

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Feb 17, 2021
@bors bors merged commit 5ef2106 into rust-lang:master Feb 17, 2021
@rustbot rustbot added this to the 1.52.0 milestone Feb 17, 2021
@tmiasko tmiasko deleted the box-error branch February 17, 2021 19:40
@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  CACHE_DOMAIN: ci-caches.rust-lang.org
  TOOLSTATE_REPO_ACCESS_TOKEN: ***
##[endgroup]
Cloning into 'rust-toolstate'...
/home/runner/work/rust/rust/src/tools/publish_toolstate.py:121: DeprecationWarning: 'U' mode is deprecated
📣 Toolstate changed by rust-lang/rust#82116!
  with open(path, 'rU') as f:

Tested on commit rust-lang/rust@5ef21063f0c0fd5b973bfa8cb88c0b70982da977.
Direct link to PR: <https://github.com/rust-lang/rust/pull/82116>

💔 miri on windows: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).
💔 miri on linux: test-fail → build-fail (cc @oli-obk @RalfJung @eddyb).
Traceback (most recent call last):
Traceback (most recent call last):
  File "/home/runner/work/rust/rust/src/tools/publish_toolstate.py", line 338, in <module>
    response = urllib2.urlopen(urllib2.Request(
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 522, in open
    req = meth(req)
  File "/usr/lib/python3.8/urllib/request.py", line 1281, in do_request_
    raise TypeError(msg)
TypeError: POST data should be bytes, an iterable of bytes, or a file object. It cannot be of type str.
##[error]Process completed with exit code 1.

@@ -356,7 +356,7 @@ where
// an allocation, which we should avoid. When that happens,
// dedicated error variants should be introduced instead.
assert!(
!error.kind.allocates(),
!error.kind().allocates(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this stop making any sense now?
The point of this allocates thing was to make sure we don't allocate an error and then "catch" it (for perf reasons we wanted to avoid those allocations). But with this change we now allocate for all errors, so (a) it seems silly to also separately Box some error kinds again, and (b) this check here makes no sense since we always allocate. So shouldn't we get rid of the extra nested Box and the allocates stuff?

(Btw I'd appreciate a Cc for changes like this that affect the Miri/CTFE engine.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unboxing of UndefinedBehaviorInfo::InvalidUninitBytes content would be one thing to consider, but generally this check makes as much sense now as it made before. Heap allocation inside & outside cannot be easily merged together.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this check makes as much sense now as it made before

If that means it didn't make any sense before, that's okay and we should still remove it. ;)

But I feel like the difference between 0 and 1 allocation is much bigger than between 1 and 2, so I am not sure this check is worth keeping. OTOH, maybe the expensive bit we should protect against isn't the allocation itself but the string formatting in the format!-using errors. In that case we should probably rename allocates to pre_formatted or so (and unbox InvalidUninitBytes as you said).

bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 25, 2021
all InterpError allocate now, so adjust alloc-error-check

Cc rust-lang#82116 (comment)
r? `@oli-obk`
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants