-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fall back to the unoptimized implementation in read_binary_file if File::metadata lies #115549
Conversation
@@ -133,7 +133,29 @@ impl FileLoader for RealFileLoader { | |||
file.read_buf_exact(buf.unfilled())?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong because some files lie and have metadata size much larger than the actual file's size:
e.g. on linux /sys/class/tty/console/dev
is like that:
full contents:
5:1
stat
gives:
File: /sys/class/tty/console/dev
Size: 4096 Blocks: 0 IO Block: 4096 regular file
Device: 17h/23d Inode: 15051 Links: 1
Access: (0444/-r--r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-09-04 17:01:42.101801391 -0700
Modify: 2023-09-04 17:01:42.101801391 -0700
Change: 2023-09-04 17:01:42.101801391 -0700
Birth: -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error: couldn't read /sys/class/tty/console/dev: failed to fill buffer
--> demo.rs:1:22
|
1 | const BYTES: &[u8] = include_bytes!("/sys/class/tty/console/dev");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the macro `include_bytes` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to previous error
I've been wondering if there was such a case! I'll adjust this in a bit...
(does this work here?) (neat it does)
@rustbot author
This code was previously using |
I do not think that is possible. The whole point of this change is to allow reading large files without peak memory use which is twice the size of the file. |
57cb6d9
to
272cd38
Compare
rust/compiler/rustc_span/src/source_map.rs Line 274 in 272cd38
It looks like we're allocating a String (i.e., |
I thought I had done a review on this. Maybe i was just looking into this. I don't really like that we are essentially just duplicating the logic in std for this. Is there a way to reuse the same code? Or, at the very least, we should do our best to point to std as a "reference impl" for future maintenance. |
The whole point of this is to read file bytes into an So unless the standard library produces an API to read a file into a |
Is there a test we can add? If so, can we add it. Otherwise, r=me. |
for testing on linux, you could try reading: |
turns out |
I tried to make them reasonably resilient, but I can imagine the tests going wrong on the numerous platforms I don't understand. |
…jackh726 Fall back to the unoptimized implementation in read_binary_file if File::metadata lies Fixes rust-lang#115458 r? `@jackh726` because you approved the previous PR
@@ -567,3 +567,30 @@ fn test_next_point() { | |||
assert_eq!(span.hi().0, 6); | |||
assert!(sm.span_to_snippet(span).is_err()); | |||
} | |||
|
|||
#[cfg(unix)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[cfg(unix)] | |
#[cfg(linux)] |
this should be #[cfg(linux)]
since those files aren't available on some other systems, e.g. I'd be surprised if /sys/devices/system/cpu/kernel_max
was available on macOS or BSDs.
fb50270
to
5f33647
Compare
@bors r=jackh726 |
☀️ Test successful - checks-actions |
Finished benchmarking commit (4fda889): comparison URL. Overall result: ✅ improvements - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
Max RSS (memory usage)ResultsThis 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.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 632.213s -> 631.763s (-0.07%) |
Fixes #115458
r? @jackh726 because you approved the previous PR