Switch to Snappy compression for metadata

This commit is contained in:
Josh Triplett 2020-08-20 16:16:30 -07:00
parent 814d252417
commit 574f6bed62
6 changed files with 16 additions and 11 deletions

View File

@ -3344,7 +3344,6 @@ name = "rustc_codegen_llvm"
version = "0.0.0"
dependencies = [
"bitflags",
"flate2",
"libc",
"measureme",
"rustc-demangle",
@ -3365,6 +3364,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"smallvec 1.4.2",
"snap",
"tracing",
]
@ -3689,7 +3689,6 @@ dependencies = [
name = "rustc_metadata"
version = "0.0.0"
dependencies = [
"flate2",
"libc",
"memmap",
"rustc_ast",
@ -3707,6 +3706,7 @@ dependencies = [
"rustc_span",
"rustc_target",
"smallvec 1.4.2",
"snap",
"stable_deref_trait",
"tracing",
"winapi 0.3.9",
@ -4377,6 +4377,12 @@ version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fbee7696b84bbf3d89a1c2eccff0850e3047ed46bfcd2e92c29a2d074d57e252"
[[package]]
name = "snap"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da73c8f77aebc0e40c300b93f0a5f1bece7a248a36eee287d4e095f35c7b7d6e"
[[package]]
name = "socket2"
version = "0.3.12"

View File

@ -12,9 +12,9 @@ doctest = false
[dependencies]
bitflags = "1.0"
flate2 = "1.0"
libc = "0.2"
measureme = "0.7.1"
snap = "1"
tracing = "0.1"
rustc_middle = { path = "../librustc_middle" }
rustc-demangle = "0.1"

View File

@ -45,15 +45,12 @@ pub fn write_compressed_metadata<'tcx>(
metadata: &EncodedMetadata,
llvm_module: &mut ModuleLlvm,
) {
use flate2::write::DeflateEncoder;
use flate2::Compression;
use snap::write::FrameEncoder;
use std::io::Write;
let (metadata_llcx, metadata_llmod) = (&*llvm_module.llcx, llvm_module.llmod());
let mut compressed = tcx.metadata_encoding_version();
DeflateEncoder::new(&mut compressed, Compression::fast())
.write_all(&metadata.raw_data)
.unwrap();
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
let llmeta = common::bytes_in_context(metadata_llcx, &compressed);
let llconst = common::struct_in_context(metadata_llcx, &[llmeta], false);

View File

@ -10,8 +10,8 @@ path = "lib.rs"
doctest = false
[dependencies]
flate2 = "1.0"
libc = "0.2"
snap = "1"
tracing = "0.1"
memmap = "0.7"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

View File

@ -229,7 +229,7 @@
use rustc_span::Span;
use rustc_target::spec::{Target, TargetTriple};
use flate2::read::DeflateDecoder;
use snap::read::FrameDecoder;
use std::io::{Read, Result as IoResult, Write};
use std::ops::Deref;
use std::path::{Path, PathBuf};
@ -766,7 +766,7 @@ fn get_metadata_section(
let compressed_bytes = &buf[header_len..];
debug!("inflating {} bytes of compressed metadata", compressed_bytes.len());
let mut inflated = Vec::new();
match DeflateDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
match FrameDecoder::new(compressed_bytes).read_to_end(&mut inflated) {
Ok(_) => rustc_erase_owner!(OwningRef::new(inflated).map_owner_box()),
Err(_) => {
return Err(format!("failed to decompress metadata: {}", filename.display()));

View File

@ -42,6 +42,7 @@
("crossbeam-queue", "MIT/Apache-2.0 AND BSD-2-Clause"), // rls via rayon
("arrayref", "BSD-2-Clause"), // cargo-miri/directories/.../rust-argon2 (redox)
("instant", "BSD-3-Clause"), // rustc_driver/tracing-subscriber/parking_lot
("snap", "BSD-3-Clause"), // rustc
// FIXME: this dependency violates the documentation comment above:
("fortanix-sgx-abi", "MPL-2.0"), // libstd but only for `sgx` target
];
@ -159,6 +160,7 @@
"serde_derive",
"sha-1",
"smallvec",
"snap",
"stable_deref_trait",
"stacker",
"syn",