Skip to content

Commit 145f9cf

Browse files
committed
Auto merge of rust-lang#132402 - bjorn3:remove_snap_decompression, r=jieyouxu,Veykril
Remove support for decompressing dylib metadata We haven't been compressing dylib metadata for a while now. Removing decompression support will regress error messages about an incompatible rustc version being used, but dylibs are pretty rare anyway. Fixes rust-lang/rust-analyzer#18451
2 parents 9fa9ef3 + 3cc0ba8 commit 145f9cf

File tree

8 files changed

+8
-58
lines changed

8 files changed

+8
-58
lines changed

Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -4006,7 +4006,6 @@ dependencies = [
40064006
"rustc_span",
40074007
"rustc_target",
40084008
"rustc_type_ir",
4009-
"snap",
40104009
"tempfile",
40114010
"tracing",
40124011
]
@@ -4891,12 +4890,6 @@ version = "1.13.2"
48914890
source = "registry+https://github.com/rust-lang/crates.io-index"
48924891
checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67"
48934892

4894-
[[package]]
4895-
name = "snap"
4896-
version = "1.1.1"
4897-
source = "registry+https://github.com/rust-lang/crates.io-index"
4898-
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
4899-
49004893
[[package]]
49014894
name = "socket2"
49024895
version = "0.5.7"

compiler/rustc_metadata/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_session = { path = "../rustc_session" }
2727
rustc_span = { path = "../rustc_span" }
2828
rustc_target = { path = "../rustc_target" }
2929
rustc_type_ir = { path = "../rustc_type_ir" }
30-
snap = "1"
3130
tempfile = "3.2"
3231
tracing = "0.1"
3332
# tidy-alphabetical-end

compiler/rustc_metadata/src/locator.rs

+4-25
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@
213213
//! metadata::locator or metadata::creader for all the juicy details!
214214
215215
use std::borrow::Cow;
216-
use std::io::{Read, Result as IoResult, Write};
216+
use std::io::{Result as IoResult, Write};
217217
use std::ops::Deref;
218218
use std::path::{Path, PathBuf};
219219
use std::{cmp, fmt};
@@ -232,7 +232,6 @@ use rustc_session::utils::CanonicalizedPath;
232232
use rustc_span::Span;
233233
use rustc_span::symbol::Symbol;
234234
use rustc_target::spec::{Target, TargetTriple};
235-
use snap::read::FrameDecoder;
236235
use tracing::{debug, info};
237236

238237
use crate::creader::{Library, MetadataLoader};
@@ -792,7 +791,6 @@ fn get_metadata_section<'p>(
792791
CrateFlavor::Dylib => {
793792
let buf =
794793
loader.get_dylib_metadata(target, filename).map_err(MetadataError::LoadFailure)?;
795-
// The header is uncompressed
796794
let header_len = METADATA_HEADER.len();
797795
// header + u64 length of data
798796
let data_start = header_len + 8;
@@ -806,37 +804,18 @@ fn get_metadata_section<'p>(
806804
)));
807805
}
808806

809-
// Length of the compressed stream - this allows linkers to pad the section if they want
807+
// Length of the metadata - this allows linkers to pad the section if they want
810808
let Ok(len_bytes) =
811809
<[u8; 8]>::try_from(&buf[header_len..cmp::min(data_start, buf.len())])
812810
else {
813811
return Err(MetadataError::LoadFailure(
814812
"invalid metadata length found".to_string(),
815813
));
816814
};
817-
let compressed_len = u64::from_le_bytes(len_bytes) as usize;
815+
let metadata_len = u64::from_le_bytes(len_bytes) as usize;
818816

819817
// Header is okay -> inflate the actual metadata
820-
let compressed_bytes = buf.slice(|buf| &buf[data_start..(data_start + compressed_len)]);
821-
if &compressed_bytes[..cmp::min(METADATA_HEADER.len(), compressed_bytes.len())]
822-
== METADATA_HEADER
823-
{
824-
// The metadata was not actually compressed.
825-
compressed_bytes
826-
} else {
827-
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
828-
// Assume the decompressed data will be at least the size of the compressed data, so we
829-
// don't have to grow the buffer as much.
830-
let mut inflated = Vec::with_capacity(compressed_bytes.len());
831-
FrameDecoder::new(&*compressed_bytes).read_to_end(&mut inflated).map_err(|_| {
832-
MetadataError::LoadFailure(format!(
833-
"failed to decompress metadata: {}",
834-
filename.display()
835-
))
836-
})?;
837-
838-
slice_owned(inflated, Deref::deref)
839-
}
818+
buf.slice(|buf| &buf[data_start..(data_start + metadata_len)])
840819
}
841820
CrateFlavor::Rmeta => {
842821
// mmap the file, because only a small fraction of it is read.

src/tools/rust-analyzer/Cargo.lock

-7
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,6 @@ dependencies = [
13641364
"proc-macro-api",
13651365
"proc-macro-test",
13661366
"ra-ap-rustc_lexer",
1367-
"snap",
13681367
"span",
13691368
"stdx",
13701369
"syntax-bridge",
@@ -1888,12 +1887,6 @@ dependencies = [
18881887
"serde",
18891888
]
18901889

1891-
[[package]]
1892-
name = "snap"
1893-
version = "1.1.1"
1894-
source = "registry+https://github.com/rust-lang/crates.io-index"
1895-
checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b"
1896-
18971890
[[package]]
18981891
name = "span"
18991892
version = "0.0.0"

src/tools/rust-analyzer/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ smallvec = { version = "1.10.0", features = [
145145
"const_generics",
146146
] }
147147
smol_str = "0.3.2"
148-
snap = "1.1.0"
149148
text-size = "1.1.1"
150149
tracing = "0.1.40"
151150
tracing-tree = "0.3.0"

src/tools/rust-analyzer/crates/proc-macro-srv/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ doctest = false
1616
object.workspace = true
1717
libloading.workspace = true
1818
memmap2.workspace = true
19-
snap.workspace = true
2019

2120
stdx.workspace = true
2221
tt.workspace = true

src/tools/rust-analyzer/crates/proc-macro-srv/src/dylib/version.rs

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::{
88
use memmap2::Mmap;
99
use object::read::{File as BinaryFile, Object, ObjectSection};
1010
use paths::AbsPath;
11-
use snap::read::FrameDecoder as SnapDecoder;
1211

1312
#[derive(Debug)]
1413
#[allow(dead_code)]
@@ -123,9 +122,8 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
123122
let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]);
124123
// Last supported version is:
125124
// https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318
126-
let (snappy_portion, bytes_before_version) = match version {
127-
5 | 6 => (&dot_rustc[8..], 13),
128-
7 | 8 => {
125+
let (mut metadata_portion, bytes_before_version) = match version {
126+
8 => {
129127
let len_bytes = &dot_rustc[8..12];
130128
let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize;
131129
(&dot_rustc[12..data_len + 12], 13)
@@ -143,25 +141,18 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result<String> {
143141
}
144142
};
145143

146-
let mut uncompressed: Box<dyn Read> = if &snappy_portion[0..4] == b"rust" {
147-
// Not compressed.
148-
Box::new(snappy_portion)
149-
} else {
150-
Box::new(SnapDecoder::new(snappy_portion))
151-
};
152-
153144
// We're going to skip over the bytes before the version string, so basically:
154145
// 8 bytes for [b'r',b'u',b's',b't',0,0,0,5]
155146
// 4 or 8 bytes for [crate root bytes]
156147
// 1 byte for length of version string
157148
// so 13 or 17 bytes in total, and we should check the last of those bytes
158149
// to know the length
159150
let mut bytes = [0u8; 17];
160-
uncompressed.read_exact(&mut bytes[..bytes_before_version])?;
151+
metadata_portion.read_exact(&mut bytes[..bytes_before_version])?;
161152
let length = bytes[bytes_before_version - 1];
162153

163154
let mut version_string_utf8 = vec![0u8; length as usize];
164-
uncompressed.read_exact(&mut version_string_utf8)?;
155+
metadata_portion.read_exact(&mut version_string_utf8)?;
165156
let version_string = String::from_utf8(version_string_utf8);
166157
version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e))
167158
}

src/tools/tidy/src/deps.rs

-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ const EXCEPTIONS: ExceptionList = &[
101101
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"), // rustc (license is the same as LLVM uses)
102102
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0 // cargo/... (because of serde)
103103
("self_cell", "Apache-2.0"), // rustc (fluent translations)
104-
("snap", "BSD-3-Clause"), // rustc
105104
("wasi-preview1-component-adapter-provider", "Apache-2.0 WITH LLVM-exception"), // rustc
106105
// tidy-alphabetical-end
107106
];
@@ -163,7 +162,6 @@ const EXCEPTIONS_RUST_ANALYZER: ExceptionList = &[
163162
("rustc_apfloat", "Apache-2.0 WITH LLVM-exception"),
164163
("ryu", "Apache-2.0 OR BSL-1.0"), // BSL is not acceptble, but we use it under Apache-2.0
165164
("scip", "Apache-2.0"),
166-
("snap", "BSD-3-Clause"),
167165
// tidy-alphabetical-end
168166
];
169167

@@ -391,7 +389,6 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[
391389
"sharded-slab",
392390
"shlex",
393391
"smallvec",
394-
"snap",
395392
"stable_deref_trait",
396393
"stacker",
397394
"static_assertions",

0 commit comments

Comments
 (0)