From 8f8200eb14bb409d5e94240dea911c0734070211 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Wed, 21 Dec 2022 21:34:01 +0100 Subject: [PATCH] Simplify --- Cargo.lock | 8 +-- crates/hir-def/Cargo.toml | 4 +- crates/hir-ty/Cargo.toml | 2 +- crates/hir-ty/src/layout/target.rs | 99 +----------------------------- 4 files changed, 9 insertions(+), 104 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 3d9f0d7cc5b..275b77ce4ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -586,9 +586,9 @@ dependencies = [ [[package]] name = "hkalbasi-rustc-ap-rustc_abi" -version = "0.0.20221125" +version = "0.0.20221221" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29c8368a30e518c0102d670d8515f7d424d875ee615ec7a7b6d29217b57a0371" +checksum = "adabaadad9aa7576f97af02241cdf5554d62fb3d51a84cb05d77ba28edd3013f" dependencies = [ "bitflags", "hkalbasi-rustc-ap-rustc_index", @@ -597,9 +597,9 @@ dependencies = [ [[package]] name = "hkalbasi-rustc-ap-rustc_index" -version = "0.0.20221125" +version = "0.0.20221221" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c07bba80d7f6a8e1efb0f3e2115ef1eecbf97292dc8cad84e4982226b9aa12e2" +checksum = "f4d3c48474e09afb0f5efbd6f758e05411699301a113c47d454d28ec7059d00e" dependencies = [ "arrayvec", "smallvec", diff --git a/crates/hir-def/Cargo.toml b/crates/hir-def/Cargo.toml index 9ecce46601b..698be76656c 100644 --- a/crates/hir-def/Cargo.toml +++ b/crates/hir-def/Cargo.toml @@ -33,8 +33,8 @@ base-db = { path = "../base-db", version = "0.0.0" } syntax = { path = "../syntax", version = "0.0.0" } profile = { path = "../profile", version = "0.0.0" } hir-expand = { path = "../hir-expand", version = "0.0.0" } -rustc_abi = { version = "0.0.20221125", package = "hkalbasi-rustc-ap-rustc_abi", default-features = false } -rustc_index = { version = "0.0.20221125", package = "hkalbasi-rustc-ap-rustc_index", default-features = false } +rustc_abi = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_abi", default-features = false } +rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false } mbe = { path = "../mbe", version = "0.0.0" } cfg = { path = "../cfg", version = "0.0.0" } tt = { path = "../tt", version = "0.0.0" } diff --git a/crates/hir-ty/Cargo.toml b/crates/hir-ty/Cargo.toml index e4dd244ab85..c72199c37fe 100644 --- a/crates/hir-ty/Cargo.toml +++ b/crates/hir-ty/Cargo.toml @@ -25,7 +25,7 @@ chalk-derive = "0.88.0" la-arena = { version = "0.3.0", path = "../../lib/la-arena" } once_cell = "1.15.0" typed-arena = "2.0.1" -rustc_index = { version = "0.0.20221125", package = "hkalbasi-rustc-ap-rustc_index", default-features = false } +rustc_index = { version = "0.0.20221221", package = "hkalbasi-rustc-ap-rustc_index", default-features = false } stdx = { path = "../stdx", version = "0.0.0" } hir-def = { path = "../hir-def", version = "0.0.0" } diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs index 54fa0fd9ea5..37b831652f5 100644 --- a/crates/hir-ty/src/layout/target.rs +++ b/crates/hir-ty/src/layout/target.rs @@ -3,12 +3,10 @@ use std::sync::Arc; use base_db::CrateId; -use hir_def::layout::{TargetDataLayout, TargetDataLayoutErrors}; +use hir_def::layout::{Endian, Size, TargetDataLayout}; use crate::db::HirDatabase; -use hir_def::layout::{AbiAndPrefAlign, AddressSpace, Align, Endian, Size}; - pub fn target_data_layout_query(db: &dyn HirDatabase, krate: CrateId) -> Arc { let crate_graph = db.crate_graph(); let target_layout = &crate_graph[krate].target_layout; @@ -16,7 +14,7 @@ pub fn target_data_layout_query(db: &dyn HirDatabase, krate: CrateId) -> Arc Endian::Big, @@ -36,96 +34,3 @@ pub fn target_data_layout_query(db: &dyn HirDatabase, krate: CrateId) -> Arc( - input: &'a str, -) -> Result> { - // Parse an address space index from a string. - let parse_address_space = |s: &'a str, cause: &'a str| { - s.parse::().map(AddressSpace).map_err(|err| { - TargetDataLayoutErrors::InvalidAddressSpace { addr_space: s, cause, err } - }) - }; - - // Parse a bit count from a string. - let parse_bits = |s: &'a str, kind: &'a str, cause: &'a str| { - s.parse::().map_err(|err| TargetDataLayoutErrors::InvalidBits { - kind, - bit: s, - cause, - err, - }) - }; - - // Parse a size string. - let size = |s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits); - - // Parse an alignment string. - let align = |s: &[&'a str], cause: &'a str| { - if s.is_empty() { - return Err(TargetDataLayoutErrors::MissingAlignment { cause }); - } - let align_from_bits = |bits| { - Align::from_bits(bits) - .map_err(|err| TargetDataLayoutErrors::InvalidAlignment { cause, err }) - }; - let abi = parse_bits(s[0], "alignment", cause)?; - let pref = s.get(1).map_or(Ok(abi), |pref| parse_bits(pref, "alignment", cause))?; - Ok(AbiAndPrefAlign { abi: align_from_bits(abi)?, pref: align_from_bits(pref)? }) - }; - - let mut dl = TargetDataLayout::default(); - let mut i128_align_src = 64; - for spec in input.split('-') { - let spec_parts = spec.split(':').collect::>(); - - match &*spec_parts { - ["e"] => dl.endian = Endian::Little, - ["E"] => dl.endian = Endian::Big, - [p] if p.starts_with('P') => { - dl.instruction_address_space = parse_address_space(&p[1..], "P")? - } - ["a", ref a @ ..] => dl.aggregate_align = align(a, "a")?, - ["f32", ref a @ ..] => dl.f32_align = align(a, "f32")?, - ["f64", ref a @ ..] => dl.f64_align = align(a, "f64")?, - [p @ "p", s, ref a @ ..] | [p @ "p0", s, ref a @ ..] => { - dl.pointer_size = size(s, p)?; - dl.pointer_align = align(a, p)?; - } - [s, ref a @ ..] if s.starts_with('i') => { - let Ok(bits) = s[1..].parse::() else { - size(&s[1..], "i")?; // For the user error. - continue; - }; - let a = align(a, s)?; - match bits { - 1 => dl.i1_align = a, - 8 => dl.i8_align = a, - 16 => dl.i16_align = a, - 32 => dl.i32_align = a, - 64 => dl.i64_align = a, - _ => {} - } - if bits >= i128_align_src && bits <= 128 { - // Default alignment for i128 is decided by taking the alignment of - // largest-sized i{64..=128}. - i128_align_src = bits; - dl.i128_align = a; - } - } - [s, ref a @ ..] if s.starts_with('v') => { - let v_size = size(&s[1..], "v")?; - let a = align(a, s)?; - if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) { - v.1 = a; - continue; - } - // No existing entry, add a new one. - dl.vector_align.push((v_size, a)); - } - _ => {} // Ignore everything else. - } - } - Ok(dl) -}