From 92faf559541d2032b3d9361173062604caa9c125 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Tue, 29 Oct 2024 13:38:30 -0700 Subject: [PATCH 1/2] rust-analyzer: `rustc_abi::Abi` => `BackendRepr` --- crates/hir-ty/src/layout.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs index 9f4cc98993..c5fa20bc8a 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -6,7 +6,7 @@ use base_db::ra_salsa::Cycle; use chalk_ir::{AdtId, FloatTy, IntTy, TyKind, UintTy}; use hir_def::{ layout::{ - Abi, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData, + BackendRepr, FieldsShape, Float, Integer, LayoutCalculator, LayoutCalculatorError, LayoutData, Primitive, ReprOptions, Scalar, Size, StructKind, TargetDataLayout, WrappingRange, }, LocalFieldId, StructId, @@ -168,7 +168,7 @@ fn layout_of_simd_ty( // Compute the ABI of the element type: let e_ly = db.layout_of_ty(e_ty, env)?; - let Abi::Scalar(e_abi) = e_ly.abi else { + let BackendRepr::Scalar(e_abi) = e_ly.backend_repr else { return Err(LayoutError::Unknown); }; @@ -190,7 +190,7 @@ fn layout_of_simd_ty( Ok(Arc::new(Layout { variants: Variants::Single { index: struct_variant_idx() }, fields, - abi: Abi::Vector { element: e_abi, count: e_len }, + backend_repr: BackendRepr::Vector { element: e_abi, count: e_len }, largest_niche: e_ly.largest_niche, size, align, @@ -294,10 +294,10 @@ pub fn layout_of_ty_query( .checked_mul(count, dl) .ok_or(LayoutError::BadCalc(LayoutCalculatorError::SizeOverflow))?; - let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) { - Abi::Uninhabited + let backend_repr = if count != 0 && matches!(element.backend_repr, BackendRepr::Uninhabited) { + BackendRepr::Uninhabited } else { - Abi::Aggregate { sized: true } + BackendRepr::Memory { sized: true } }; let largest_niche = if count != 0 { element.largest_niche } else { None }; @@ -305,7 +305,7 @@ pub fn layout_of_ty_query( Layout { variants: Variants::Single { index: struct_variant_idx() }, fields: FieldsShape::Array { stride: element.size, count }, - abi, + backend_repr, largest_niche, align: element.align, size, @@ -318,7 +318,7 @@ pub fn layout_of_ty_query( Layout { variants: Variants::Single { index: struct_variant_idx() }, fields: FieldsShape::Array { stride: element.size, count: 0 }, - abi: Abi::Aggregate { sized: false }, + backend_repr: BackendRepr::Memory { sized: false }, largest_niche: None, align: element.align, size: Size::ZERO, @@ -329,7 +329,7 @@ pub fn layout_of_ty_query( TyKind::Str => Layout { variants: Variants::Single { index: struct_variant_idx() }, fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 }, - abi: Abi::Aggregate { sized: false }, + backend_repr: BackendRepr::Memory { sized: false }, largest_niche: None, align: dl.i8_align, size: Size::ZERO, @@ -379,8 +379,8 @@ pub fn layout_of_ty_query( TyKind::Never => cx.calc.layout_of_never_type(), TyKind::Dyn(_) | TyKind::Foreign(_) => { let mut unit = layout_of_unit(&cx)?; - match &mut unit.abi { - Abi::Aggregate { sized } => *sized = false, + match &mut unit.backend_repr { + BackendRepr::Memory { sized } => *sized = false, _ => return Err(LayoutError::Unknown), } unit From ad858841e76a1dc2c033193bfc1bf0b1bf876e03 Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Thu, 31 Oct 2024 12:18:20 +0000 Subject: [PATCH 2/2] Remove support for compressed dylib metadata from rust-analyzer --- Cargo.lock | 7 ------- Cargo.toml | 1 - crates/proc-macro-srv/Cargo.toml | 1 - crates/proc-macro-srv/src/dylib/version.rs | 17 ++++------------- 4 files changed, 4 insertions(+), 22 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 695c37f6d7..424357e847 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1364,7 +1364,6 @@ dependencies = [ "proc-macro-api", "proc-macro-test", "ra-ap-rustc_lexer", - "snap", "span", "stdx", "syntax-bridge", @@ -1888,12 +1887,6 @@ dependencies = [ "serde", ] -[[package]] -name = "snap" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b6b67fb9a61334225b5b790716f609cd58395f895b3fe8b328786812a40bc3b" - [[package]] name = "span" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 3aa93b7b7b..1099d2cb91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -145,7 +145,6 @@ smallvec = { version = "1.10.0", features = [ "const_generics", ] } smol_str = "0.3.2" -snap = "1.1.0" text-size = "1.1.1" tracing = "0.1.40" tracing-tree = "0.3.0" diff --git a/crates/proc-macro-srv/Cargo.toml b/crates/proc-macro-srv/Cargo.toml index e8d9677c92..4fabcc9006 100644 --- a/crates/proc-macro-srv/Cargo.toml +++ b/crates/proc-macro-srv/Cargo.toml @@ -16,7 +16,6 @@ doctest = false object.workspace = true libloading.workspace = true memmap2.workspace = true -snap.workspace = true stdx.workspace = true tt.workspace = true diff --git a/crates/proc-macro-srv/src/dylib/version.rs b/crates/proc-macro-srv/src/dylib/version.rs index 1f7ef7914b..7f0e95c50d 100644 --- a/crates/proc-macro-srv/src/dylib/version.rs +++ b/crates/proc-macro-srv/src/dylib/version.rs @@ -8,7 +8,6 @@ use std::{ use memmap2::Mmap; use object::read::{File as BinaryFile, Object, ObjectSection}; use paths::AbsPath; -use snap::read::FrameDecoder as SnapDecoder; #[derive(Debug)] #[allow(dead_code)] @@ -123,9 +122,8 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result { let version = u32::from_be_bytes([dot_rustc[4], dot_rustc[5], dot_rustc[6], dot_rustc[7]]); // Last supported version is: // https://github.com/rust-lang/rust/commit/b94cfefc860715fb2adf72a6955423d384c69318 - let (snappy_portion, bytes_before_version) = match version { - 5 | 6 => (&dot_rustc[8..], 13), - 7 | 8 => { + let (mut metadata_portion, bytes_before_version) = match version { + 8 => { let len_bytes = &dot_rustc[8..12]; let data_len = u32::from_be_bytes(len_bytes.try_into().unwrap()) as usize; (&dot_rustc[12..data_len + 12], 13) @@ -143,13 +141,6 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result { } }; - let mut uncompressed: Box = if &snappy_portion[0..4] == b"rust" { - // Not compressed. - Box::new(snappy_portion) - } else { - Box::new(SnapDecoder::new(snappy_portion)) - }; - // We're going to skip over the bytes before the version string, so basically: // 8 bytes for [b'r',b'u',b's',b't',0,0,0,5] // 4 or 8 bytes for [crate root bytes] @@ -157,11 +148,11 @@ pub fn read_version(dylib_path: &AbsPath) -> io::Result { // so 13 or 17 bytes in total, and we should check the last of those bytes // to know the length let mut bytes = [0u8; 17]; - uncompressed.read_exact(&mut bytes[..bytes_before_version])?; + metadata_portion.read_exact(&mut bytes[..bytes_before_version])?; let length = bytes[bytes_before_version - 1]; let mut version_string_utf8 = vec![0u8; length as usize]; - uncompressed.read_exact(&mut version_string_utf8)?; + metadata_portion.read_exact(&mut version_string_utf8)?; let version_string = String::from_utf8(version_string_utf8); version_string.map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)) }