mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-19 01:50:32 +00:00
Calculate the TargetDataLayout correctly for the selected target
This commit is contained in:
parent
9ed1829f1f
commit
33591cd3f4
15 changed files with 247 additions and 62 deletions
|
@ -162,6 +162,7 @@ impl ChangeFixture {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
origin,
|
origin,
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let prev = crates.insert(crate_name.clone(), crate_id);
|
let prev = crates.insert(crate_name.clone(), crate_id);
|
||||||
assert!(prev.is_none());
|
assert!(prev.is_none());
|
||||||
|
@ -197,6 +198,7 @@ impl ChangeFixture {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
for (from, to, prelude) in crate_deps {
|
for (from, to, prelude) in crate_deps {
|
||||||
|
@ -234,6 +236,7 @@ impl ChangeFixture {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::Lang(LangCrateOrigin::Core),
|
CrateOrigin::Lang(LangCrateOrigin::Core),
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
for krate in all_crates {
|
for krate in all_crates {
|
||||||
|
@ -271,6 +274,7 @@ impl ChangeFixture {
|
||||||
Ok(proc_macro),
|
Ok(proc_macro),
|
||||||
true,
|
true,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
|
|
||||||
for krate in all_crates {
|
for krate in all_crates {
|
||||||
|
|
|
@ -270,6 +270,7 @@ pub struct CrateData {
|
||||||
pub display_name: Option<CrateDisplayName>,
|
pub display_name: Option<CrateDisplayName>,
|
||||||
pub cfg_options: CfgOptions,
|
pub cfg_options: CfgOptions,
|
||||||
pub potential_cfg_options: CfgOptions,
|
pub potential_cfg_options: CfgOptions,
|
||||||
|
pub target_layout: Option<Arc<str>>,
|
||||||
pub env: Env,
|
pub env: Env,
|
||||||
pub dependencies: Vec<Dependency>,
|
pub dependencies: Vec<Dependency>,
|
||||||
pub proc_macro: ProcMacroLoadResult,
|
pub proc_macro: ProcMacroLoadResult,
|
||||||
|
@ -328,6 +329,7 @@ impl CrateGraph {
|
||||||
proc_macro: ProcMacroLoadResult,
|
proc_macro: ProcMacroLoadResult,
|
||||||
is_proc_macro: bool,
|
is_proc_macro: bool,
|
||||||
origin: CrateOrigin,
|
origin: CrateOrigin,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) -> CrateId {
|
) -> CrateId {
|
||||||
let data = CrateData {
|
let data = CrateData {
|
||||||
root_file_id,
|
root_file_id,
|
||||||
|
@ -340,6 +342,7 @@ impl CrateGraph {
|
||||||
proc_macro,
|
proc_macro,
|
||||||
dependencies: Vec::new(),
|
dependencies: Vec::new(),
|
||||||
origin,
|
origin,
|
||||||
|
target_layout,
|
||||||
is_proc_macro,
|
is_proc_macro,
|
||||||
};
|
};
|
||||||
let crate_id = CrateId(self.arena.len() as u32);
|
let crate_id = CrateId(self.arena.len() as u32);
|
||||||
|
@ -649,6 +652,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId(2u32),
|
||||||
|
@ -661,6 +665,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate3 = graph.add_crate_root(
|
let crate3 = graph.add_crate_root(
|
||||||
FileId(3u32),
|
FileId(3u32),
|
||||||
|
@ -673,6 +678,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(graph
|
assert!(graph
|
||||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||||
|
@ -699,6 +705,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId(2u32),
|
||||||
|
@ -711,6 +718,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(graph
|
assert!(graph
|
||||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||||
|
@ -734,6 +742,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId(2u32),
|
||||||
|
@ -746,6 +755,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate3 = graph.add_crate_root(
|
let crate3 = graph.add_crate_root(
|
||||||
FileId(3u32),
|
FileId(3u32),
|
||||||
|
@ -758,6 +768,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(graph
|
assert!(graph
|
||||||
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
.add_dep(crate1, Dependency::new(CrateName::new("crate2").unwrap(), crate2))
|
||||||
|
@ -781,6 +792,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
let crate2 = graph.add_crate_root(
|
let crate2 = graph.add_crate_root(
|
||||||
FileId(2u32),
|
FileId(2u32),
|
||||||
|
@ -793,6 +805,7 @@ mod tests {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
assert!(graph
|
assert!(graph
|
||||||
.add_dep(
|
.add_dep(
|
||||||
|
|
|
@ -6,7 +6,7 @@ use la_arena::{Idx, RawIdx};
|
||||||
pub use rustc_abi::{
|
pub use rustc_abi::{
|
||||||
Abi, AbiAndPrefAlign, AddressSpace, Align, Endian, FieldsShape, Integer, IntegerType,
|
Abi, AbiAndPrefAlign, AddressSpace, Align, Endian, FieldsShape, Integer, IntegerType,
|
||||||
LayoutCalculator, Niche, Primitive, ReprFlags, ReprOptions, Scalar, Size, StructKind,
|
LayoutCalculator, Niche, Primitive, ReprFlags, ReprOptions, Scalar, Size, StructKind,
|
||||||
TargetDataLayout, WrappingRange,
|
TargetDataLayout, TargetDataLayoutErrors, WrappingRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::LocalEnumVariantId;
|
use crate::LocalEnumVariantId;
|
||||||
|
|
|
@ -64,8 +64,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
|
||||||
#[salsa::cycle(crate::layout::layout_of_adt_recover)]
|
#[salsa::cycle(crate::layout::layout_of_adt_recover)]
|
||||||
fn layout_of_adt(&self, def: AdtId, subst: Substitution) -> Result<Layout, LayoutError>;
|
fn layout_of_adt(&self, def: AdtId, subst: Substitution) -> Result<Layout, LayoutError>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::layout::current_target_data_layout_query)]
|
#[salsa::invoke(crate::layout::target_data_layout_query)]
|
||||||
fn current_target_data_layout(&self) -> Arc<TargetDataLayout>;
|
fn target_data_layout(&self, krate: CrateId) -> Arc<TargetDataLayout>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::lower::callable_item_sig)]
|
#[salsa::invoke(crate::lower::callable_item_sig)]
|
||||||
fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig;
|
fn callable_item_signature(&self, def: CallableDefId) -> PolyFnSig;
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use base_db::CrateId;
|
||||||
use chalk_ir::{AdtId, TyKind};
|
use chalk_ir::{AdtId, TyKind};
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
layout::{
|
layout::{
|
||||||
|
@ -17,7 +18,7 @@ use crate::{db::HirDatabase, Interner, Substitution, Ty};
|
||||||
use self::adt::struct_variant_idx;
|
use self::adt::struct_variant_idx;
|
||||||
pub use self::{
|
pub use self::{
|
||||||
adt::{layout_of_adt_query, layout_of_adt_recover},
|
adt::{layout_of_adt_query, layout_of_adt_recover},
|
||||||
target::current_target_data_layout_query,
|
target::target_data_layout_query,
|
||||||
};
|
};
|
||||||
|
|
||||||
macro_rules! user_error {
|
macro_rules! user_error {
|
||||||
|
@ -31,6 +32,7 @@ mod target;
|
||||||
|
|
||||||
struct LayoutCx<'a> {
|
struct LayoutCx<'a> {
|
||||||
db: &'a dyn HirDatabase,
|
db: &'a dyn HirDatabase,
|
||||||
|
krate: CrateId,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutCalculator for LayoutCx<'_> {
|
impl LayoutCalculator for LayoutCx<'_> {
|
||||||
|
@ -41,7 +43,7 @@ impl LayoutCalculator for LayoutCx<'_> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn current_data_layout(&self) -> Arc<TargetDataLayout> {
|
fn current_data_layout(&self) -> Arc<TargetDataLayout> {
|
||||||
self.db.current_target_data_layout()
|
self.db.target_data_layout(self.krate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,9 +55,9 @@ fn scalar(dl: &TargetDataLayout, value: Primitive) -> Layout {
|
||||||
Layout::scalar(dl, scalar_unit(dl, value))
|
Layout::scalar(dl, scalar_unit(dl, value))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError> {
|
pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty, krate: CrateId) -> Result<Layout, LayoutError> {
|
||||||
let dl = &*db.current_target_data_layout();
|
let cx = LayoutCx { db, krate };
|
||||||
let cx = LayoutCx { db };
|
let dl = &*cx.current_data_layout();
|
||||||
Ok(match ty.kind(Interner) {
|
Ok(match ty.kind(Interner) {
|
||||||
TyKind::Adt(AdtId(def), subst) => db.layout_of_adt(*def, subst.clone())?,
|
TyKind::Adt(AdtId(def), subst) => db.layout_of_adt(*def, subst.clone())?,
|
||||||
TyKind::Scalar(s) => match s {
|
TyKind::Scalar(s) => match s {
|
||||||
|
@ -84,7 +86,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError
|
||||||
chalk_ir::IntTy::I64 => Integer::I64,
|
chalk_ir::IntTy::I64 => Integer::I64,
|
||||||
chalk_ir::IntTy::I128 => Integer::I128,
|
chalk_ir::IntTy::I128 => Integer::I128,
|
||||||
},
|
},
|
||||||
false,
|
true,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
chalk_ir::Scalar::Uint(i) => scalar(
|
chalk_ir::Scalar::Uint(i) => scalar(
|
||||||
|
@ -98,7 +100,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError
|
||||||
chalk_ir::UintTy::U64 => Integer::I64,
|
chalk_ir::UintTy::U64 => Integer::I64,
|
||||||
chalk_ir::UintTy::U128 => Integer::I128,
|
chalk_ir::UintTy::U128 => Integer::I128,
|
||||||
},
|
},
|
||||||
true,
|
false,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
chalk_ir::Scalar::Float(f) => scalar(
|
chalk_ir::Scalar::Float(f) => scalar(
|
||||||
|
@ -114,7 +116,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError
|
||||||
|
|
||||||
let fields = tys
|
let fields = tys
|
||||||
.iter(Interner)
|
.iter(Interner)
|
||||||
.map(|k| layout_of_ty(db, k.assert_ty_ref(Interner)))
|
.map(|k| layout_of_ty(db, k.assert_ty_ref(Interner), krate))
|
||||||
.collect::<Result<Vec<_>, _>>()?;
|
.collect::<Result<Vec<_>, _>>()?;
|
||||||
let fields = fields.iter().collect::<Vec<_>>();
|
let fields = fields.iter().collect::<Vec<_>>();
|
||||||
let fields = fields.iter().collect::<Vec<_>>();
|
let fields = fields.iter().collect::<Vec<_>>();
|
||||||
|
@ -132,7 +134,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError
|
||||||
},
|
},
|
||||||
_ => return Err(LayoutError::HasPlaceholder),
|
_ => return Err(LayoutError::HasPlaceholder),
|
||||||
};
|
};
|
||||||
let element = layout_of_ty(db, element)?;
|
let element = layout_of_ty(db, element, krate)?;
|
||||||
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
|
let size = element.size.checked_mul(count, dl).ok_or(LayoutError::SizeOverflow)?;
|
||||||
|
|
||||||
let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) {
|
let abi = if count != 0 && matches!(element.abi, Abi::Uninhabited) {
|
||||||
|
@ -153,7 +155,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty) -> Result<Layout, LayoutError
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TyKind::Slice(element) => {
|
TyKind::Slice(element) => {
|
||||||
let element = layout_of_ty(db, element)?;
|
let element = layout_of_ty(db, element, krate)?;
|
||||||
Layout {
|
Layout {
|
||||||
variants: Variants::Single { index: struct_variant_idx() },
|
variants: Variants::Single { index: struct_variant_idx() },
|
||||||
fields: FieldsShape::Array { stride: element.size, count: 0 },
|
fields: FieldsShape::Array { stride: element.size, count: 0 },
|
||||||
|
|
|
@ -5,7 +5,7 @@ use std::ops::Bound;
|
||||||
use hir_def::{
|
use hir_def::{
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
layout::{Integer, IntegerExt, Layout, LayoutCalculator, LayoutError, RustcEnumVariantIdx},
|
layout::{Integer, IntegerExt, Layout, LayoutCalculator, LayoutError, RustcEnumVariantIdx},
|
||||||
AdtId, EnumVariantId, LocalEnumVariantId, VariantId,
|
AdtId, EnumVariantId, HasModule, LocalEnumVariantId, VariantId,
|
||||||
};
|
};
|
||||||
use la_arena::RawIdx;
|
use la_arena::RawIdx;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
@ -23,12 +23,12 @@ pub fn layout_of_adt_query(
|
||||||
def: AdtId,
|
def: AdtId,
|
||||||
subst: Substitution,
|
subst: Substitution,
|
||||||
) -> Result<Layout, LayoutError> {
|
) -> Result<Layout, LayoutError> {
|
||||||
let dl = db.current_target_data_layout();
|
let cx = LayoutCx { db, krate: def.module(db.upcast()).krate() };
|
||||||
let cx = LayoutCx { db };
|
let dl = cx.current_data_layout();
|
||||||
let handle_variant = |def: VariantId, var: &VariantData| {
|
let handle_variant = |def: VariantId, var: &VariantData| {
|
||||||
var.fields()
|
var.fields()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(fd, _)| layout_of_ty(db, &field_ty(db, def, fd, &subst)))
|
.map(|(fd, _)| layout_of_ty(db, &field_ty(db, def, fd, &subst), cx.krate))
|
||||||
.collect::<Result<Vec<_>, _>>()
|
.collect::<Result<Vec<_>, _>>()
|
||||||
};
|
};
|
||||||
let (variants, is_enum, is_union, repr) = match def {
|
let (variants, is_enum, is_union, repr) = match def {
|
||||||
|
|
|
@ -2,45 +2,130 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use hir_def::layout::TargetDataLayout;
|
use base_db::CrateId;
|
||||||
|
use hir_def::layout::{TargetDataLayout, TargetDataLayoutErrors};
|
||||||
|
|
||||||
use crate::db::HirDatabase;
|
use crate::db::HirDatabase;
|
||||||
|
|
||||||
use hir_def::layout::{AbiAndPrefAlign, AddressSpace, Align, Endian, Integer, Size};
|
use hir_def::layout::{AbiAndPrefAlign, AddressSpace, Align, Endian, Size};
|
||||||
|
|
||||||
pub fn current_target_data_layout_query(db: &dyn HirDatabase) -> Arc<TargetDataLayout> {
|
pub fn target_data_layout_query(db: &dyn HirDatabase, krate: CrateId) -> Arc<TargetDataLayout> {
|
||||||
let crate_graph = db.crate_graph();
|
let crate_graph = db.crate_graph();
|
||||||
let cfg_options = &crate_graph[crate_graph.iter().next().unwrap()].cfg_options;
|
let target_layout = &crate_graph[krate].target_layout;
|
||||||
let endian = match cfg_options.get_cfg_values("target_endian").next() {
|
let cfg_options = &crate_graph[krate].cfg_options;
|
||||||
Some(x) if x.as_str() == "big" => Endian::Big,
|
Arc::new(
|
||||||
_ => Endian::Little,
|
target_layout
|
||||||
};
|
.as_ref()
|
||||||
let pointer_size =
|
.and_then(|it| parse_from_llvm_datalayout_string(it).ok())
|
||||||
Size::from_bytes(match cfg_options.get_cfg_values("target_pointer_width").next() {
|
.unwrap_or_else(|| {
|
||||||
Some(x) => match x.as_str() {
|
let endian = match cfg_options.get_cfg_values("target_endian").next() {
|
||||||
"16" => 2,
|
Some(x) if x.as_str() == "big" => Endian::Big,
|
||||||
"32" => 4,
|
_ => Endian::Little,
|
||||||
_ => 8,
|
};
|
||||||
},
|
let pointer_size = Size::from_bytes(
|
||||||
_ => 8,
|
match cfg_options.get_cfg_values("target_pointer_width").next() {
|
||||||
});
|
Some(x) => match x.as_str() {
|
||||||
// FIXME: These values are incorrect for many architectures, at least for aarch64 and riscv64,
|
"16" => 2,
|
||||||
// use `rustc +nightly -Z unstable-options --print target-spec-json` or something similar instead.
|
"32" => 4,
|
||||||
Arc::new(TargetDataLayout {
|
_ => 8,
|
||||||
endian,
|
},
|
||||||
i1_align: AbiAndPrefAlign::new(Align::from_bytes(1).unwrap()),
|
_ => 8,
|
||||||
i8_align: AbiAndPrefAlign::new(Align::from_bytes(1).unwrap()),
|
},
|
||||||
i16_align: AbiAndPrefAlign::new(Align::from_bytes(2).unwrap()),
|
);
|
||||||
i32_align: AbiAndPrefAlign::new(Align::from_bytes(4).unwrap()),
|
TargetDataLayout { endian, pointer_size, ..TargetDataLayout::default() }
|
||||||
i64_align: AbiAndPrefAlign::new(Align::from_bytes(8).unwrap()),
|
}),
|
||||||
i128_align: AbiAndPrefAlign::new(Align::from_bytes(8).unwrap()),
|
)
|
||||||
f32_align: AbiAndPrefAlign::new(Align::from_bytes(4).unwrap()),
|
}
|
||||||
f64_align: AbiAndPrefAlign::new(Align::from_bytes(8).unwrap()),
|
|
||||||
pointer_size,
|
/// copied from rustc as it is not exposed yet
|
||||||
pointer_align: AbiAndPrefAlign::new(Align::from_bytes(pointer_size.bytes()).unwrap()),
|
fn parse_from_llvm_datalayout_string<'a>(
|
||||||
aggregate_align: AbiAndPrefAlign::new(Align::from_bytes(1).unwrap()),
|
input: &'a str,
|
||||||
vector_align: vec![],
|
) -> Result<TargetDataLayout, TargetDataLayoutErrors<'a>> {
|
||||||
instruction_address_space: AddressSpace(0),
|
// Parse an address space index from a string.
|
||||||
c_enum_min_size: Integer::I32,
|
let parse_address_space = |s: &'a str, cause: &'a str| {
|
||||||
})
|
s.parse::<u32>().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::<u64>().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::<Vec<_>>();
|
||||||
|
|
||||||
|
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::<u64>() 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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,15 +34,17 @@ fn eval_goal(ra_fixture: &str) -> Result<Layout, LayoutError> {
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let goal_ty = TyKind::Adt(AdtId(adt_id), Substitution::empty(Interner)).intern(Interner);
|
let goal_ty = TyKind::Adt(AdtId(adt_id), Substitution::empty(Interner)).intern(Interner);
|
||||||
layout_of_ty(&db, &goal_ty)
|
layout_of_ty(&db, &goal_ty, module_id.krate())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
fn check_size_and_align(ra_fixture: &str, size: u64, align: u64) {
|
fn check_size_and_align(ra_fixture: &str, size: u64, align: u64) {
|
||||||
let l = eval_goal(ra_fixture).unwrap();
|
let l = eval_goal(ra_fixture).unwrap();
|
||||||
assert_eq!(l.size.bytes(), size);
|
assert_eq!(l.size.bytes(), size);
|
||||||
assert_eq!(l.align.abi.bytes(), align);
|
assert_eq!(l.align.abi.bytes(), align);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[track_caller]
|
||||||
fn check_fail(ra_fixture: &str, e: LayoutError) {
|
fn check_fail(ra_fixture: &str, e: LayoutError) {
|
||||||
let r = eval_goal(ra_fixture);
|
let r = eval_goal(ra_fixture);
|
||||||
assert_eq!(r, Err(e));
|
assert_eq!(r, Err(e));
|
||||||
|
|
|
@ -866,7 +866,7 @@ impl Field {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn layout(&self, db: &dyn HirDatabase) -> Result<Layout, LayoutError> {
|
pub fn layout(&self, db: &dyn HirDatabase) -> Result<Layout, LayoutError> {
|
||||||
layout_of_ty(db, &self.ty(db).ty)
|
layout_of_ty(db, &self.ty(db).ty, self.parent.module(db).krate().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parent_def(&self, _db: &dyn HirDatabase) -> VariantDef {
|
pub fn parent_def(&self, _db: &dyn HirDatabase) -> VariantDef {
|
||||||
|
|
|
@ -236,6 +236,7 @@ impl Analysis {
|
||||||
Ok(Vec::new()),
|
Ok(Vec::new()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::CratesIo { repo: None, name: None },
|
CrateOrigin::CratesIo { repo: None, name: None },
|
||||||
|
None,
|
||||||
);
|
);
|
||||||
change.change_file(file_id, Some(Arc::new(text)));
|
change.change_file(file_id, Some(Arc::new(text)));
|
||||||
change.set_crate_graph(crate_graph);
|
change.set_crate_graph(crate_graph);
|
||||||
|
|
|
@ -36,6 +36,7 @@ pub(crate) fn shuffle_crate_graph(db: &mut RootDatabase) {
|
||||||
data.proc_macro.clone(),
|
data.proc_macro.clone(),
|
||||||
data.is_proc_macro,
|
data.is_proc_macro,
|
||||||
data.origin.clone(),
|
data.origin.clone(),
|
||||||
|
data.target_layout.clone(),
|
||||||
);
|
);
|
||||||
map.insert(old_id, new_id);
|
map.insert(old_id, new_id);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ fn get_rust_cfgs(
|
||||||
cargo_config.envs(extra_env);
|
cargo_config.envs(extra_env);
|
||||||
cargo_config
|
cargo_config
|
||||||
.current_dir(cargo_toml.parent())
|
.current_dir(cargo_toml.parent())
|
||||||
.args(&["-Z", "unstable-options", "rustc", "--print", "cfg"])
|
.args(&["rustc", "-Z", "unstable-options", "--print", "cfg"])
|
||||||
.env("RUSTC_BOOTSTRAP", "1");
|
.env("RUSTC_BOOTSTRAP", "1");
|
||||||
if let Some(target) = target {
|
if let Some(target) = target {
|
||||||
cargo_config.args(&["--target", target]);
|
cargo_config.args(&["--target", target]);
|
||||||
|
|
|
@ -29,6 +29,7 @@ fn load_cargo_with_overrides(file: &str, cfg_overrides: CfgOverrides) -> CrateGr
|
||||||
rustc_cfg: Vec::new(),
|
rustc_cfg: Vec::new(),
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
toolchain: None,
|
toolchain: None,
|
||||||
|
target_layout: None,
|
||||||
};
|
};
|
||||||
to_crate_graph(project_workspace)
|
to_crate_graph(project_workspace)
|
||||||
}
|
}
|
||||||
|
|
|
@ -79,6 +79,7 @@ pub enum ProjectWorkspace {
|
||||||
rustc_cfg: Vec<CfgFlag>,
|
rustc_cfg: Vec<CfgFlag>,
|
||||||
cfg_overrides: CfgOverrides,
|
cfg_overrides: CfgOverrides,
|
||||||
toolchain: Option<Version>,
|
toolchain: Option<Version>,
|
||||||
|
target_layout: Option<String>,
|
||||||
},
|
},
|
||||||
/// Project workspace was manually specified using a `rust-project.json` file.
|
/// Project workspace was manually specified using a `rust-project.json` file.
|
||||||
Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> },
|
Json { project: ProjectJson, sysroot: Option<Sysroot>, rustc_cfg: Vec<CfgFlag> },
|
||||||
|
@ -108,6 +109,7 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
rustc_cfg,
|
rustc_cfg,
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
toolchain,
|
toolchain,
|
||||||
|
target_layout: data_layout,
|
||||||
} => f
|
} => f
|
||||||
.debug_struct("Cargo")
|
.debug_struct("Cargo")
|
||||||
.field("root", &cargo.workspace_root().file_name())
|
.field("root", &cargo.workspace_root().file_name())
|
||||||
|
@ -120,6 +122,7 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
.field("n_rustc_cfg", &rustc_cfg.len())
|
.field("n_rustc_cfg", &rustc_cfg.len())
|
||||||
.field("n_cfg_overrides", &cfg_overrides.len())
|
.field("n_cfg_overrides", &cfg_overrides.len())
|
||||||
.field("toolchain", &toolchain)
|
.field("toolchain", &toolchain)
|
||||||
|
.field("data_layout", &data_layout)
|
||||||
.finish(),
|
.finish(),
|
||||||
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => {
|
ProjectWorkspace::Json { project, sysroot, rustc_cfg } => {
|
||||||
let mut debug_struct = f.debug_struct("Json");
|
let mut debug_struct = f.debug_struct("Json");
|
||||||
|
@ -140,6 +143,40 @@ impl fmt::Debug for ProjectWorkspace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn data_layout(
|
||||||
|
cargo_toml: Option<&ManifestPath>,
|
||||||
|
target: Option<&str>,
|
||||||
|
extra_env: &FxHashMap<String, String>,
|
||||||
|
) -> Option<String> {
|
||||||
|
let output = (|| {
|
||||||
|
if let Some(cargo_toml) = cargo_toml {
|
||||||
|
let mut cmd = Command::new(toolchain::rustc());
|
||||||
|
cmd.envs(extra_env);
|
||||||
|
cmd.current_dir(cargo_toml.parent())
|
||||||
|
.args(&["-Z", "unstable-options", "rustc", "--print", "target-spec-json"])
|
||||||
|
.env("RUSTC_BOOTSTRAP", "1");
|
||||||
|
if let Some(target) = target {
|
||||||
|
cmd.args(&["--target", target]);
|
||||||
|
}
|
||||||
|
match utf8_stdout(cmd) {
|
||||||
|
Ok(it) => return Ok(it),
|
||||||
|
Err(e) => tracing::debug!("{e:?}: falling back to querying rustc for cfgs"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// using unstable cargo features failed, fall back to using plain rustc
|
||||||
|
let mut cmd = Command::new(toolchain::rustc());
|
||||||
|
cmd.envs(extra_env)
|
||||||
|
.args(&["-Z", "unstable-options", "rustc", "--print", "target-spec-json"])
|
||||||
|
.env("RUSTC_BOOTSTRAP", "1");
|
||||||
|
if let Some(target) = target {
|
||||||
|
cmd.args(&["--target", target]);
|
||||||
|
}
|
||||||
|
utf8_stdout(cmd)
|
||||||
|
})()
|
||||||
|
.ok()?;
|
||||||
|
Some(output.split_once(r#""data-layout": "#)?.1.trim_matches('"').to_owned())
|
||||||
|
}
|
||||||
|
|
||||||
impl ProjectWorkspace {
|
impl ProjectWorkspace {
|
||||||
pub fn load(
|
pub fn load(
|
||||||
manifest: ProjectManifest,
|
manifest: ProjectManifest,
|
||||||
|
@ -241,6 +278,8 @@ impl ProjectWorkspace {
|
||||||
rustc_cfg::get(Some(&cargo_toml), config.target.as_deref(), &config.extra_env);
|
rustc_cfg::get(Some(&cargo_toml), config.target.as_deref(), &config.extra_env);
|
||||||
|
|
||||||
let cfg_overrides = config.cfg_overrides();
|
let cfg_overrides = config.cfg_overrides();
|
||||||
|
let data_layout =
|
||||||
|
data_layout(Some(&cargo_toml), config.target.as_deref(), &config.extra_env);
|
||||||
ProjectWorkspace::Cargo {
|
ProjectWorkspace::Cargo {
|
||||||
cargo,
|
cargo,
|
||||||
build_scripts: WorkspaceBuildScripts::default(),
|
build_scripts: WorkspaceBuildScripts::default(),
|
||||||
|
@ -249,6 +288,7 @@ impl ProjectWorkspace {
|
||||||
rustc_cfg,
|
rustc_cfg,
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
toolchain,
|
toolchain,
|
||||||
|
target_layout: data_layout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -435,6 +475,7 @@ impl ProjectWorkspace {
|
||||||
cfg_overrides: _,
|
cfg_overrides: _,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
toolchain: _,
|
toolchain: _,
|
||||||
|
target_layout: _,
|
||||||
} => {
|
} => {
|
||||||
cargo
|
cargo
|
||||||
.packages()
|
.packages()
|
||||||
|
@ -530,6 +571,7 @@ impl ProjectWorkspace {
|
||||||
project,
|
project,
|
||||||
sysroot,
|
sysroot,
|
||||||
extra_env,
|
extra_env,
|
||||||
|
None,
|
||||||
),
|
),
|
||||||
ProjectWorkspace::Cargo {
|
ProjectWorkspace::Cargo {
|
||||||
cargo,
|
cargo,
|
||||||
|
@ -539,6 +581,7 @@ impl ProjectWorkspace {
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
toolchain: _,
|
toolchain: _,
|
||||||
|
target_layout,
|
||||||
} => cargo_to_crate_graph(
|
} => cargo_to_crate_graph(
|
||||||
load_proc_macro,
|
load_proc_macro,
|
||||||
load,
|
load,
|
||||||
|
@ -548,9 +591,10 @@ impl ProjectWorkspace {
|
||||||
rustc_cfg.clone(),
|
rustc_cfg.clone(),
|
||||||
cfg_overrides,
|
cfg_overrides,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
|
target_layout.as_deref().map(Arc::from),
|
||||||
),
|
),
|
||||||
ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => {
|
ProjectWorkspace::DetachedFiles { files, sysroot, rustc_cfg } => {
|
||||||
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot)
|
detached_files_to_crate_graph(rustc_cfg.clone(), load, files, sysroot, None)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if crate_graph.patch_cfg_if() {
|
if crate_graph.patch_cfg_if() {
|
||||||
|
@ -569,11 +613,18 @@ fn project_json_to_crate_graph(
|
||||||
project: &ProjectJson,
|
project: &ProjectJson,
|
||||||
sysroot: &Option<Sysroot>,
|
sysroot: &Option<Sysroot>,
|
||||||
extra_env: &FxHashMap<String, String>,
|
extra_env: &FxHashMap<String, String>,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) -> CrateGraph {
|
) -> CrateGraph {
|
||||||
let mut crate_graph = CrateGraph::default();
|
let mut crate_graph = CrateGraph::default();
|
||||||
let sysroot_deps = sysroot
|
let sysroot_deps = sysroot.as_ref().map(|sysroot| {
|
||||||
.as_ref()
|
sysroot_to_crate_graph(
|
||||||
.map(|sysroot| sysroot_to_crate_graph(&mut crate_graph, sysroot, rustc_cfg.clone(), load));
|
&mut crate_graph,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg.clone(),
|
||||||
|
target_layout.clone(),
|
||||||
|
load,
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
let mut cfg_cache: FxHashMap<&str, Vec<CfgFlag>> = FxHashMap::default();
|
let mut cfg_cache: FxHashMap<&str, Vec<CfgFlag>> = FxHashMap::default();
|
||||||
let crates: NoHashHashMap<CrateId, CrateId> = project
|
let crates: NoHashHashMap<CrateId, CrateId> = project
|
||||||
|
@ -625,6 +676,7 @@ fn project_json_to_crate_graph(
|
||||||
} else {
|
} else {
|
||||||
CrateOrigin::CratesIo { repo: None, name: None }
|
CrateOrigin::CratesIo { repo: None, name: None }
|
||||||
},
|
},
|
||||||
|
target_layout.clone(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
@ -665,11 +717,18 @@ fn cargo_to_crate_graph(
|
||||||
rustc_cfg: Vec<CfgFlag>,
|
rustc_cfg: Vec<CfgFlag>,
|
||||||
override_cfg: &CfgOverrides,
|
override_cfg: &CfgOverrides,
|
||||||
build_scripts: &WorkspaceBuildScripts,
|
build_scripts: &WorkspaceBuildScripts,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) -> CrateGraph {
|
) -> CrateGraph {
|
||||||
let _p = profile::span("cargo_to_crate_graph");
|
let _p = profile::span("cargo_to_crate_graph");
|
||||||
let mut crate_graph = CrateGraph::default();
|
let mut crate_graph = CrateGraph::default();
|
||||||
let (public_deps, libproc_macro) = match sysroot {
|
let (public_deps, libproc_macro) = match sysroot {
|
||||||
Some(sysroot) => sysroot_to_crate_graph(&mut crate_graph, sysroot, rustc_cfg.clone(), load),
|
Some(sysroot) => sysroot_to_crate_graph(
|
||||||
|
&mut crate_graph,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg.clone(),
|
||||||
|
target_layout.clone(),
|
||||||
|
load,
|
||||||
|
),
|
||||||
None => (SysrootPublicDeps::default(), None),
|
None => (SysrootPublicDeps::default(), None),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -732,6 +791,7 @@ fn cargo_to_crate_graph(
|
||||||
file_id,
|
file_id,
|
||||||
&cargo[tgt].name,
|
&cargo[tgt].name,
|
||||||
cargo[tgt].is_proc_macro,
|
cargo[tgt].is_proc_macro,
|
||||||
|
target_layout.clone(),
|
||||||
);
|
);
|
||||||
if cargo[tgt].kind == TargetKind::Lib {
|
if cargo[tgt].kind == TargetKind::Lib {
|
||||||
lib_tgt = Some((crate_id, cargo[tgt].name.clone()));
|
lib_tgt = Some((crate_id, cargo[tgt].name.clone()));
|
||||||
|
@ -811,6 +871,7 @@ fn cargo_to_crate_graph(
|
||||||
&cfg_options,
|
&cfg_options,
|
||||||
override_cfg,
|
override_cfg,
|
||||||
build_scripts,
|
build_scripts,
|
||||||
|
target_layout,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -822,11 +883,18 @@ fn detached_files_to_crate_graph(
|
||||||
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
||||||
detached_files: &[AbsPathBuf],
|
detached_files: &[AbsPathBuf],
|
||||||
sysroot: &Option<Sysroot>,
|
sysroot: &Option<Sysroot>,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) -> CrateGraph {
|
) -> CrateGraph {
|
||||||
let _p = profile::span("detached_files_to_crate_graph");
|
let _p = profile::span("detached_files_to_crate_graph");
|
||||||
let mut crate_graph = CrateGraph::default();
|
let mut crate_graph = CrateGraph::default();
|
||||||
let (public_deps, _libproc_macro) = match sysroot {
|
let (public_deps, _libproc_macro) = match sysroot {
|
||||||
Some(sysroot) => sysroot_to_crate_graph(&mut crate_graph, sysroot, rustc_cfg.clone(), load),
|
Some(sysroot) => sysroot_to_crate_graph(
|
||||||
|
&mut crate_graph,
|
||||||
|
sysroot,
|
||||||
|
rustc_cfg.clone(),
|
||||||
|
target_layout.clone(),
|
||||||
|
load,
|
||||||
|
),
|
||||||
None => (SysrootPublicDeps::default(), None),
|
None => (SysrootPublicDeps::default(), None),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -859,6 +927,7 @@ fn detached_files_to_crate_graph(
|
||||||
repo: None,
|
repo: None,
|
||||||
name: display_name.map(|n| n.canonical_name().to_string()),
|
name: display_name.map(|n| n.canonical_name().to_string()),
|
||||||
},
|
},
|
||||||
|
target_layout.clone(),
|
||||||
);
|
);
|
||||||
|
|
||||||
public_deps.add_to_crate_graph(&mut crate_graph, detached_file_crate);
|
public_deps.add_to_crate_graph(&mut crate_graph, detached_file_crate);
|
||||||
|
@ -879,6 +948,7 @@ fn handle_rustc_crates(
|
||||||
cfg_options: &CfgOptions,
|
cfg_options: &CfgOptions,
|
||||||
override_cfg: &CfgOverrides,
|
override_cfg: &CfgOverrides,
|
||||||
build_scripts: &WorkspaceBuildScripts,
|
build_scripts: &WorkspaceBuildScripts,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) {
|
) {
|
||||||
let mut rustc_pkg_crates = FxHashMap::default();
|
let mut rustc_pkg_crates = FxHashMap::default();
|
||||||
// The root package of the rustc-dev component is rustc_driver, so we match that
|
// The root package of the rustc-dev component is rustc_driver, so we match that
|
||||||
|
@ -935,6 +1005,7 @@ fn handle_rustc_crates(
|
||||||
file_id,
|
file_id,
|
||||||
&rustc_workspace[tgt].name,
|
&rustc_workspace[tgt].name,
|
||||||
rustc_workspace[tgt].is_proc_macro,
|
rustc_workspace[tgt].is_proc_macro,
|
||||||
|
target_layout.clone(),
|
||||||
);
|
);
|
||||||
pkg_to_lib_crate.insert(pkg, crate_id);
|
pkg_to_lib_crate.insert(pkg, crate_id);
|
||||||
// Add dependencies on core / std / alloc for this crate
|
// Add dependencies on core / std / alloc for this crate
|
||||||
|
@ -999,6 +1070,7 @@ fn add_target_crate_root(
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
cargo_name: &str,
|
cargo_name: &str,
|
||||||
is_proc_macro: bool,
|
is_proc_macro: bool,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
) -> CrateId {
|
) -> CrateId {
|
||||||
let edition = pkg.edition;
|
let edition = pkg.edition;
|
||||||
let mut potential_cfg_options = cfg_options.clone();
|
let mut potential_cfg_options = cfg_options.clone();
|
||||||
|
@ -1045,6 +1117,7 @@ fn add_target_crate_root(
|
||||||
proc_macro,
|
proc_macro,
|
||||||
is_proc_macro,
|
is_proc_macro,
|
||||||
CrateOrigin::CratesIo { repo: pkg.repository.clone(), name: Some(pkg.name.clone()) },
|
CrateOrigin::CratesIo { repo: pkg.repository.clone(), name: Some(pkg.name.clone()) },
|
||||||
|
target_layout,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1066,6 +1139,7 @@ fn sysroot_to_crate_graph(
|
||||||
crate_graph: &mut CrateGraph,
|
crate_graph: &mut CrateGraph,
|
||||||
sysroot: &Sysroot,
|
sysroot: &Sysroot,
|
||||||
rustc_cfg: Vec<CfgFlag>,
|
rustc_cfg: Vec<CfgFlag>,
|
||||||
|
target_layout: Option<Arc<str>>,
|
||||||
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
load: &mut dyn FnMut(&AbsPath) -> Option<FileId>,
|
||||||
) -> (SysrootPublicDeps, Option<CrateId>) {
|
) -> (SysrootPublicDeps, Option<CrateId>) {
|
||||||
let _p = profile::span("sysroot_to_crate_graph");
|
let _p = profile::span("sysroot_to_crate_graph");
|
||||||
|
@ -1089,6 +1163,7 @@ fn sysroot_to_crate_graph(
|
||||||
Err("no proc macro loaded for sysroot crate".into()),
|
Err("no proc macro loaded for sysroot crate".into()),
|
||||||
false,
|
false,
|
||||||
CrateOrigin::Lang(LangCrateOrigin::from(&*sysroot[krate].name)),
|
CrateOrigin::Lang(LangCrateOrigin::from(&*sysroot[krate].name)),
|
||||||
|
target_layout.clone(),
|
||||||
);
|
);
|
||||||
Some((krate, crate_id))
|
Some((krate, crate_id))
|
||||||
})
|
})
|
||||||
|
|
|
@ -226,6 +226,7 @@ impl GlobalState {
|
||||||
|
|
||||||
build_scripts: _,
|
build_scripts: _,
|
||||||
toolchain: _,
|
toolchain: _,
|
||||||
|
target_layout: _,
|
||||||
} => Some((cargo, sysroot, rustc, rustc_cfg, cfg_overrides)),
|
} => Some((cargo, sysroot, rustc, rustc_cfg, cfg_overrides)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue