Skip to content

Commit c52f1ce

Browse files
committed
Update rustc_abi dependency
1 parent a943b19 commit c52f1ce

File tree

9 files changed

+113
-56
lines changed

9 files changed

+113
-56
lines changed

Cargo.lock

Lines changed: 19 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/hir-def/src/data/adt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn parse_repr_tt(tt: &Subtree) -> Option<ReprOptions> {
178178
}
179179
}
180180

181-
Some(ReprOptions { int, align: max_align, pack: min_pack, flags, field_shuffle_seed: 0 })
181+
Some(ReprOptions { int, align: max_align, pack: min_pack, flags })
182182
}
183183

184184
impl StructData {

crates/hir-ty/src/layout.rs

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ use hir_def::{
99
LocalEnumVariantId, LocalFieldId, StructId,
1010
};
1111
use la_arena::{Idx, RawIdx};
12+
use rustc_dependencies::{
13+
abi::AddressSpace,
14+
index::{IndexSlice, IndexVec},
15+
};
1216
use stdx::never;
1317
use triomphe::Arc;
1418

@@ -34,7 +38,7 @@ mod target;
3438
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
3539
pub struct RustcEnumVariantIdx(pub LocalEnumVariantId);
3640

37-
impl rustc_dependencies::index::vec::Idx for RustcEnumVariantIdx {
41+
impl rustc_dependencies::index::Idx for RustcEnumVariantIdx {
3842
fn new(idx: usize) -> Self {
3943
RustcEnumVariantIdx(Idx::from_raw(RawIdx::from(idx as u32)))
4044
}
@@ -44,9 +48,28 @@ impl rustc_dependencies::index::vec::Idx for RustcEnumVariantIdx {
4448
}
4549
}
4650

47-
pub type Layout = LayoutS<RustcEnumVariantIdx>;
51+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
52+
pub struct RustcFieldIdx(pub LocalFieldId);
53+
54+
impl RustcFieldIdx {
55+
pub fn new(idx: usize) -> Self {
56+
RustcFieldIdx(Idx::from_raw(RawIdx::from(idx as u32)))
57+
}
58+
}
59+
60+
impl rustc_dependencies::index::Idx for RustcFieldIdx {
61+
fn new(idx: usize) -> Self {
62+
RustcFieldIdx(Idx::from_raw(RawIdx::from(idx as u32)))
63+
}
64+
65+
fn index(self) -> usize {
66+
u32::from(self.0.into_raw()) as usize
67+
}
68+
}
69+
70+
pub type Layout = LayoutS<RustcFieldIdx, RustcEnumVariantIdx>;
4871
pub type TagEncoding = hir_def::layout::TagEncoding<RustcEnumVariantIdx>;
49-
pub type Variants = hir_def::layout::Variants<RustcEnumVariantIdx>;
72+
pub type Variants = hir_def::layout::Variants<RustcFieldIdx, RustcEnumVariantIdx>;
5073

5174
#[derive(Debug, PartialEq, Eq, Clone)]
5275
pub enum LayoutError {
@@ -66,7 +89,7 @@ struct LayoutCx<'a> {
6689
impl<'a> LayoutCalculator for LayoutCx<'a> {
6790
type TargetDataLayoutRef = &'a TargetDataLayout;
6891

69-
fn delay_bug(&self, txt: &str) {
92+
fn delay_bug(&self, txt: String) {
7093
never!("{}", txt);
7194
}
7295

@@ -145,6 +168,10 @@ fn layout_of_simd_ty(
145168
largest_niche: e_ly.largest_niche,
146169
size,
147170
align,
171+
// FIXME might be wrong
172+
max_repr_align: e_ly.max_repr_align,
173+
// FIXME might be wrong
174+
unadjusted_abi_align: e_ly.unadjusted_abi_align,
148175
}))
149176
}
150177

@@ -230,7 +257,7 @@ pub fn layout_of_ty_query(
230257
.map(|k| db.layout_of_ty(k.assert_ty_ref(Interner).clone(), trait_env.clone()))
231258
.collect::<Result<Vec<_>, _>>()?;
232259
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
233-
let fields = fields.iter().collect::<Vec<_>>();
260+
let fields = fields.iter().collect::<IndexVec<_, _>>();
234261
cx.univariant(dl, &fields, &ReprOptions::default(), kind).ok_or(LayoutError::Unknown)?
235262
}
236263
TyKind::Array(element, count) => {
@@ -255,6 +282,8 @@ pub fn layout_of_ty_query(
255282
largest_niche,
256283
align: element.align,
257284
size,
285+
max_repr_align: element.max_repr_align,
286+
unadjusted_abi_align: element.unadjusted_abi_align,
258287
}
259288
}
260289
TyKind::Slice(element) => {
@@ -266,11 +295,14 @@ pub fn layout_of_ty_query(
266295
largest_niche: None,
267296
align: element.align,
268297
size: Size::ZERO,
298+
max_repr_align: element.max_repr_align,
299+
unadjusted_abi_align: element.unadjusted_abi_align,
269300
}
270301
}
271302
// Potentially-wide pointers.
272303
TyKind::Ref(_, _, pointee) | TyKind::Raw(_, pointee) => {
273-
let mut data_ptr = scalar_unit(dl, Primitive::Pointer);
304+
// FIXME: fill out AddressSpace
305+
let mut data_ptr = scalar_unit(dl, Primitive::Pointer(AddressSpace(0)));
274306
if matches!(ty.kind(Interner), TyKind::Ref(..)) {
275307
data_ptr.valid_range_mut().start = 1;
276308
}
@@ -294,7 +326,8 @@ pub fn layout_of_ty_query(
294326
scalar_unit(dl, Primitive::Int(dl.ptr_sized_integer(), false))
295327
}
296328
TyKind::Dyn(..) => {
297-
let mut vtable = scalar_unit(dl, Primitive::Pointer);
329+
// FIXME: fill out AddressSpace
330+
let mut vtable = scalar_unit(dl, Primitive::Pointer(AddressSpace(0)));
298331
vtable.valid_range_mut().start = 1;
299332
vtable
300333
}
@@ -315,6 +348,10 @@ pub fn layout_of_ty_query(
315348
largest_niche: None,
316349
align: dl.i8_align,
317350
size: Size::ZERO,
351+
// FIXME
352+
max_repr_align: None,
353+
// FIXME
354+
unadjusted_abi_align: dl.i8_align.abi,
318355
},
319356
TyKind::Never => Layout {
320357
variants: Variants::Single { index: struct_variant_idx() },
@@ -323,6 +360,11 @@ pub fn layout_of_ty_query(
323360
largest_niche: None,
324361
align: dl.i8_align,
325362
size: Size::ZERO,
363+
364+
// FIXME
365+
max_repr_align: None,
366+
// FIXME
367+
unadjusted_abi_align: dl.i8_align.abi,
326368
},
327369
TyKind::Dyn(_) | TyKind::Foreign(_) => {
328370
let mut unit = layout_of_unit(&cx, dl)?;
@@ -333,7 +375,8 @@ pub fn layout_of_ty_query(
333375
unit
334376
}
335377
TyKind::Function(_) => {
336-
let mut ptr = scalar_unit(dl, Primitive::Pointer);
378+
// FOXME: fill out AddressSpace
379+
let mut ptr = scalar_unit(dl, Primitive::Pointer(AddressSpace(0)));
337380
ptr.valid_range_mut().start = 1;
338381
Layout::scalar(dl, ptr)
339382
}
@@ -363,7 +406,7 @@ pub fn layout_of_ty_query(
363406
})
364407
.collect::<Result<Vec<_>, _>>()?;
365408
let fields = fields.iter().map(|it| &**it).collect::<Vec<_>>();
366-
let fields = fields.iter().collect::<Vec<_>>();
409+
let fields = fields.iter().collect::<IndexVec<_, _>>();
367410
cx.univariant(dl, &fields, &ReprOptions::default(), StructKind::AlwaysSized)
368411
.ok_or(LayoutError::Unknown)?
369412
}
@@ -398,9 +441,9 @@ pub fn layout_of_ty_recover(
398441
}
399442

400443
fn layout_of_unit(cx: &LayoutCx<'_>, dl: &TargetDataLayout) -> Result<Layout, LayoutError> {
401-
cx.univariant::<RustcEnumVariantIdx, &&Layout>(
444+
cx.univariant::<RustcFieldIdx, RustcEnumVariantIdx, &&Layout>(
402445
dl,
403-
&[],
446+
IndexSlice::empty(),
404447
&ReprOptions::default(),
405448
StructKind::AlwaysSized,
406449
)

crates/hir-ty/src/layout/adt.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use hir_def::{
88
AdtId, EnumVariantId, LocalEnumVariantId, VariantId,
99
};
1010
use la_arena::RawIdx;
11+
use rustc_dependencies::index::IndexVec;
1112
use smallvec::SmallVec;
1213
use triomphe::Arc;
1314

@@ -74,7 +75,7 @@ pub fn layout_of_adt_query(
7475
.iter()
7576
.map(|it| it.iter().map(|it| &**it).collect::<Vec<_>>())
7677
.collect::<SmallVec<[_; 1]>>();
77-
let variants = variants.iter().map(|it| it.iter().collect()).collect();
78+
let variants = variants.iter().map(|it| it.iter().collect()).collect::<IndexVec<_, _>>();
7879
let result = if matches!(def, AdtId::UnionId(..)) {
7980
cx.layout_of_union(&repr, &variants).ok_or(LayoutError::Unknown)?
8081
} else {
@@ -105,7 +106,7 @@ pub fn layout_of_adt_query(
105106
&& variants
106107
.iter()
107108
.next()
108-
.and_then(|it| it.last().map(|it| !it.is_unsized()))
109+
.and_then(|it| it.iter().last().map(|it| !it.is_unsized()))
109110
.unwrap_or(true),
110111
)
111112
.ok_or(LayoutError::SizeOverflow)?

crates/hir/src/lib.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use hir_ty::{
6464
consteval::{try_const_usize, unknown_const_as_generic, ConstEvalError, ConstExt},
6565
diagnostics::BodyValidationDiagnostic,
6666
known_const_to_ast,
67-
layout::{Layout as TyLayout, RustcEnumVariantIdx, TagEncoding},
67+
layout::{Layout as TyLayout, RustcEnumVariantIdx, RustcFieldIdx, TagEncoding},
6868
method_resolution::{self, TyFingerprint},
6969
mir::{self, interpret_mir},
7070
primitive::UintTy,
@@ -4526,15 +4526,31 @@ impl Layout {
45264526
Some(self.0.largest_niche?.available(&*self.1))
45274527
}
45284528

4529-
pub fn field_offset(&self, idx: usize) -> Option<u64> {
4529+
pub fn field_offset(&self, field: Field) -> Option<u64> {
45304530
match self.0.fields {
45314531
layout::FieldsShape::Primitive => None,
45324532
layout::FieldsShape::Union(_) => Some(0),
45334533
layout::FieldsShape::Array { stride, count } => {
4534-
let i = u64::try_from(idx).ok()?;
4534+
let i = u64::try_from(field.index()).ok()?;
45354535
(i < count).then_some((stride * i).bytes())
45364536
}
4537-
layout::FieldsShape::Arbitrary { ref offsets, .. } => Some(offsets.get(idx)?.bytes()),
4537+
layout::FieldsShape::Arbitrary { ref offsets, .. } => {
4538+
Some(offsets.get(RustcFieldIdx(field.id))?.bytes())
4539+
}
4540+
}
4541+
}
4542+
4543+
pub fn tuple_field_offset(&self, field: usize) -> Option<u64> {
4544+
match self.0.fields {
4545+
layout::FieldsShape::Primitive => None,
4546+
layout::FieldsShape::Union(_) => Some(0),
4547+
layout::FieldsShape::Array { stride, count } => {
4548+
let i = u64::try_from(field).ok()?;
4549+
(i < count).then_some((stride * i).bytes())
4550+
}
4551+
layout::FieldsShape::Arbitrary { ref offsets, .. } => {
4552+
Some(offsets.get(RustcFieldIdx::new(field))?.bytes())
4553+
}
45384554
}
45394555
}
45404556

crates/ide/src/hover/render.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,9 @@ pub(super) fn definition(
402402
|&it| it.layout(db),
403403
|_| {
404404
let var_def = it.parent_def(db);
405-
let id = it.index();
406405
match var_def {
407406
hir::VariantDef::Struct(s) => {
408-
Adt::from(s).layout(db).ok().and_then(|layout| layout.field_offset(id))
407+
Adt::from(s).layout(db).ok().and_then(|layout| layout.field_offset(it))
409408
}
410409
_ => None,
411410
}

crates/ide/src/view_memory_layout.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ impl fmt::Display for RecursiveMemoryLayout {
5555
}
5656
}
5757

58+
#[derive(Copy, Clone)]
5859
enum FieldOrTupleIdx {
5960
Field(Field),
6061
TupleIdx(usize),
@@ -71,13 +72,6 @@ impl FieldOrTupleIdx {
7172
FieldOrTupleIdx::TupleIdx(i) => format!(".{i}").to_owned(),
7273
}
7374
}
74-
75-
fn index(&self) -> usize {
76-
match *self {
77-
FieldOrTupleIdx::Field(f) => f.index(),
78-
FieldOrTupleIdx::TupleIdx(i) => i,
79-
}
80-
}
8175
}
8276

8377
// Feature: View Memory Layout
@@ -138,7 +132,10 @@ pub(crate) fn view_memory_layout(
138132
return;
139133
}
140134

141-
fields.sort_by_key(|(f, _)| layout.field_offset(f.index()).unwrap());
135+
fields.sort_by_key(|&(f, _)| match f {
136+
FieldOrTupleIdx::Field(f) => layout.field_offset(f).unwrap_or(0),
137+
FieldOrTupleIdx::TupleIdx(f) => layout.tuple_field_offset(f).unwrap_or(0),
138+
});
142139

143140
let children_start = nodes.len();
144141
nodes[parent_idx].children_start = children_start as i64;
@@ -151,7 +148,10 @@ pub(crate) fn view_memory_layout(
151148
typename: child_ty.display(db).to_string(),
152149
size: child_layout.size(),
153150
alignment: child_layout.align(),
154-
offset: layout.field_offset(field.index()).unwrap_or(0),
151+
offset: match *field {
152+
FieldOrTupleIdx::Field(f) => layout.field_offset(f).unwrap_or(0),
153+
FieldOrTupleIdx::TupleIdx(f) => layout.tuple_field_offset(f).unwrap_or(0),
154+
},
155155
parent_idx: parent_idx as i64,
156156
children_start: -1,
157157
children_len: 0,

crates/rustc-dependencies/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ ra-ap-rustc_lexer = { version = "0.10.0" }
1313
ra-ap-rustc_parse_format = { version = "0.10.0", default-features = false }
1414

1515
# Upstream broke this for us so we can't update it
16-
hkalbasi-rustc-ap-rustc_abi = { version = "0.0.20221221", default-features = false }
17-
hkalbasi-rustc-ap-rustc_index = { version = "0.0.20221221", default-features = false }
16+
# hkalbasi-rustc-ap-rustc_abi = { version = "0.0.20221221", default-features = false }
17+
# hkalbasi-rustc-ap-rustc_index = { version = "0.0.20221221", default-features = false }
18+
rustc_abi = { path = "C:\\workspace\\rust\\rust\\compiler\\rustc_abi", default-features = false }
19+
rustc_index = { path = "C:\\workspace\\rust\\rust\\compiler\\rustc_index", default-features = false }
1820

1921
[features]
2022
in-rust-tree = []

crates/rustc-dependencies/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ pub mod parse_format {
3131

3232
// Upstream broke this for us so we can't update it
3333
pub mod abi {
34-
pub use ::hkalbasi_rustc_ap_rustc_abi::*;
34+
pub use ::rustc_abi::*;
3535
}
3636

3737
pub mod index {
38-
pub use ::hkalbasi_rustc_ap_rustc_index::*;
38+
pub use ::rustc_index::*;
3939
}

0 commit comments

Comments
 (0)