Skip to content

Commit afec259

Browse files
committed
[squash later] ad-hoc fields for default_address_space_info
1 parent 3f8b20b commit afec259

File tree

4 files changed

+45
-52
lines changed

4 files changed

+45
-52
lines changed

compiler/rustc_abi/src/lib.rs

Lines changed: 45 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ pub struct TargetDataLayout {
253253
pub vector_align: Vec<(Size, AbiAlign)>,
254254

255255
pub default_address_space: AddressSpace,
256+
pub default_address_space_info: AddressSpaceInfo,
256257

257258
/// The address space informations relative to all the known address spaces.
258259
///
259260
/// # Note
260-
/// The first item (`address_space_info[0]`) in the vector should always be the informations
261-
/// related to the default address space.
261+
///
262+
/// This vector does not contain the [`AddressSpaceInfo`] relative to the default address space,
263+
/// which instead lives in [`Self::default_address_space_info`].
262264
address_space_info: Vec<(AddressSpace, AddressSpaceInfo)>,
263265

264266
pub instruction_address_space: AddressSpace,
@@ -291,14 +293,12 @@ impl Default for TargetDataLayout {
291293
(Size::from_bits(128), AbiAlign::new(align(128))),
292294
],
293295
default_address_space: AddressSpace::ZERO,
294-
address_space_info: vec![(
295-
AddressSpace::ZERO,
296-
AddressSpaceInfo {
297-
pointer_size: Size::from_bits(64),
298-
pointer_align: AbiAlign::new(align(64)),
299-
pointer_index: Size::from_bits(64),
300-
},
301-
)],
296+
default_address_space_info: AddressSpaceInfo {
297+
pointer_size: Size::from_bits(64),
298+
pointer_align: AbiAlign::new(align(64)),
299+
pointer_index: Size::from_bits(64),
300+
},
301+
address_space_info: vec![],
302302
instruction_address_space: AddressSpace::ZERO,
303303
c_enum_min_size: Integer::I32,
304304
}
@@ -313,7 +313,6 @@ pub enum TargetDataLayoutErrors<'a> {
313313
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
314314
InconsistentTargetPointerWidth { pointer_size: u64, target: u32 },
315315
InvalidBitsSize { err: String },
316-
MissingAddressSpaceInfo { addr_space: AddressSpace },
317316
}
318317

319318
impl TargetDataLayout {
@@ -395,12 +394,12 @@ impl TargetDataLayout {
395394
pointer_size,
396395
pointer_align: parse_align(a, p)?,
397396
};
398-
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
399-
Some(e) => e.1 = info,
400-
None => {
401-
if addr_space == default_address_space {
402-
dl.address_space_info.insert(0, (addr_space, info));
403-
} else {
397+
if addr_space == default_address_space {
398+
dl.default_address_space_info = info;
399+
} else {
400+
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
401+
Some(e) => e.1 = info,
402+
None => {
404403
dl.address_space_info.push((addr_space, info));
405404
}
406405
}
@@ -423,12 +422,12 @@ impl TargetDataLayout {
423422
pointer_index: parse_size(i, p)?,
424423
};
425424

426-
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
427-
Some(e) => e.1 = info,
428-
None => {
429-
if addr_space == default_address_space {
430-
dl.address_space_info.insert(0, (addr_space, info));
431-
} else {
425+
if addr_space == default_address_space {
426+
dl.default_address_space_info = info;
427+
} else {
428+
match dl.address_space_info.iter_mut().find(|(a, _)| *a == addr_space) {
429+
Some(e) => e.1 = info,
430+
None => {
432431
dl.address_space_info.push((addr_space, info));
433432
}
434433
}
@@ -470,26 +469,17 @@ impl TargetDataLayout {
470469
}
471470
}
472471

473-
if dl.address_space_info.iter().find(|(a, _)| *a == default_address_space).is_none() {
474-
return Err(TargetDataLayoutErrors::MissingAddressSpaceInfo {
475-
addr_space: default_address_space,
476-
});
477-
}
478-
479472
// Inherit, if not given, address space informations for specific LLVM elements from the
480473
// default data address space.
481-
482-
if dl.address_space_info.iter().find(|(a, _)| *a == dl.instruction_address_space).is_none()
474+
if (dl.instruction_address_space != dl.default_address_space)
475+
&& dl
476+
.address_space_info
477+
.iter()
478+
.find(|(a, _)| *a == dl.instruction_address_space)
479+
.is_none()
483480
{
484-
dl.address_space_info.push((
485-
dl.instruction_address_space,
486-
dl.address_space_info
487-
.iter()
488-
.find(|(a, _)| *a == default_address_space)
489-
.unwrap()
490-
.1
491-
.clone(),
492-
));
481+
dl.address_space_info
482+
.push((dl.instruction_address_space, dl.default_address_space_info.clone()));
493483
}
494484

495485
Ok(dl)
@@ -576,12 +566,16 @@ impl TargetDataLayout {
576566
/// Get the pointer size in the default data address space.
577567
#[inline]
578568
pub fn pointer_size(&self) -> Size {
579-
self.address_space_info[0].1.pointer_size
569+
self.default_address_space_info.pointer_size
580570
}
581571

582572
/// Get the pointer size in a specific address space.
583573
#[inline]
584574
pub fn pointer_size_in(&self, c: AddressSpace) -> Size {
575+
if c == self.default_address_space {
576+
return self.default_address_space_info.pointer_size;
577+
}
578+
585579
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
586580
e.1.pointer_size
587581
} else {
@@ -592,12 +586,16 @@ impl TargetDataLayout {
592586
/// Get the pointer index in the default data address space.
593587
#[inline]
594588
pub fn pointer_index(&self) -> Size {
595-
self.address_space_info[0].1.pointer_index
589+
self.default_address_space_info.pointer_index
596590
}
597591

598592
/// Get the pointer index in a specific address space.
599593
#[inline]
600594
pub fn pointer_index_in(&self, c: AddressSpace) -> Size {
595+
if c == self.default_address_space {
596+
return self.default_address_space_info.pointer_index;
597+
}
598+
601599
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
602600
e.1.pointer_index
603601
} else {
@@ -608,12 +606,16 @@ impl TargetDataLayout {
608606
/// Get the pointer alignment in the default data address space.
609607
#[inline]
610608
pub fn pointer_align(&self) -> AbiAlign {
611-
self.address_space_info[0].1.pointer_align
609+
self.default_address_space_info.pointer_align
612610
}
613611

614612
/// Get the pointer alignment in a specific address space.
615613
#[inline]
616614
pub fn pointer_align_in(&self, c: AddressSpace) -> AbiAlign {
615+
if c == self.default_address_space {
616+
return self.default_address_space_info.pointer_align;
617+
}
618+
617619
if let Some(e) = self.address_space_info.iter().find(|(a, _)| a == &c) {
618620
e.1.pointer_align
619621
} else {

compiler/rustc_errors/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,5 @@ errors_target_invalid_bits =
4141
4242
errors_target_invalid_bits_size = {$err}
4343
44-
errors_target_missing_addr_space_info =
45-
missing address space info for address space `{$addr_space}` in "data-layout"
46-
4744
errors_target_missing_alignment =
4845
missing alignment for `{$cause}` in "data-layout"

compiler/rustc_errors/src/diagnostic_impls.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,6 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for TargetDataLayoutErrors<'_> {
374374
TargetDataLayoutErrors::InvalidBitsSize { err } => {
375375
Diag::new(dcx, level, fluent::errors_target_invalid_bits_size).with_arg("err", err)
376376
}
377-
TargetDataLayoutErrors::MissingAddressSpaceInfo { addr_space } => {
378-
Diag::new(dcx, level, fluent::errors_target_missing_addr_space_info)
379-
.with_arg("addr_space", addr_space.0)
380-
}
381377
}
382378
}
383379
}

src/tools/rust-analyzer/crates/hir-ty/src/layout/target.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ pub fn target_data_layout_query(
3939
target,
4040
} => format!(r#"inconsistent target specification: "data-layout" claims pointers are {pointer_size}-bit, while "target-pointer-width" is `{target}`"#),
4141
TargetDataLayoutErrors::InvalidBitsSize { err } => err,
42-
TargetDataLayoutErrors::MissingAddressSpaceInfo { addr_space } =>
43-
format!(r#"missing address space info for address space {addr_space:?}` in "data-layout""#)
4442
}.into())
4543
}
4644
},

0 commit comments

Comments
 (0)