about summary refs log tree commit diff
path: root/compiler/rustc_mir_transform/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-20 21:47:54 +0000
committerbors <bors@rust-lang.org>2023-09-20 21:47:54 +0000
commit3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e (patch)
tree9c7159d33ff2fa0368661315745e6174ec6eac15 /compiler/rustc_mir_transform/src
parentad36b5a622b0d6d6f0f3260049b2245ee1f27a07 (diff)
parent6cee6b0bdecc0cc18074fc1bb61b39bcc14573d8 (diff)
downloadrust-3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e.tar.gz
rust-3223b0b5e8dadda3f76c3fd1a8d6c5addc09599e.zip
Auto merge of #115542 - saethlin:fileencoder-is-bufwriter, r=WaffleLapkin
Simplify/Optimize FileEncoder

FileEncoder is basically a BufWriter except that it exposes access to the not-written-to-yet region of the buffer so that some users can write directly to the buffer. This strategy is awesome because it lets us avoid calling memcpy for small copies, but the previous strategy was based on the writer accessing a `&mut [MaybeUninit<u8>; N]` and returning a `&[u8]` which is an API which currently mandates the use of unsafe code, making that interface in general not that appealing.

So this PR cleans up the FileEncoder implementation and builds on that general idea of direct buffer access in order to prevent `memcpy` calls in a few key places when encoding the dep graph and rmeta tables. The interface used here is now 100% safe, but with the caveat that internally we need to avoid trusting the number of bytes that the provided function claims to have written.

The original primary objective of this PR was to clean up the FileEncoder implementation so that the fix for the following issues would be easy to implement. The fix for these issues is to correctly update self.buffered even when writes fail, which I think it's easy to verify manually is now done, because all the FileEncoder methods are small.

Fixes https://github.com/rust-lang/rust/issues/115298
Fixes https://github.com/rust-lang/rust/issues/114671
Fixes https://github.com/rust-lang/rust/issues/114045
Fixes https://github.com/rust-lang/rust/issues/108100
Fixes https://github.com/rust-lang/rust/issues/106787
Diffstat (limited to 'compiler/rustc_mir_transform/src')
0 files changed, 0 insertions, 0 deletions