Skip to content

Commit d194d7c

Browse files
rustc_abi::Abi to IrForm in mir_transform and rustc_lint
1 parent 540fa03 commit d194d7c

File tree

10 files changed

+32
-26
lines changed

10 files changed

+32
-26
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3906,6 +3906,7 @@ dependencies = [
39063906
name = "rustc_lint"
39073907
version = "0.0.0"
39083908
dependencies = [
3909+
"rustc_abi",
39093910
"rustc_ast",
39103911
"rustc_ast_pretty",
39113912
"rustc_attr",
@@ -4095,6 +4096,7 @@ version = "0.0.0"
40954096
dependencies = [
40964097
"either",
40974098
"itertools",
4099+
"rustc_abi",
40984100
"rustc_arena",
40994101
"rustc_ast",
41004102
"rustc_attr",

compiler/rustc_lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ edition = "2021"
55

66
[dependencies]
77
# tidy-alphabetical-start
8+
rustc_abi = { path = "../rustc_abi" }
89
rustc_ast = { path = "../rustc_ast" }
910
rustc_ast_pretty = { path = "../rustc_ast_pretty" }
1011
rustc_attr = { path = "../rustc_attr" }

compiler/rustc_lint/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use std::fmt::Write;
2424

2525
use ast::token::TokenKind;
26+
use rustc_abi::IrForm;
2627
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2728
use rustc_ast::visit::{FnCtxt, FnKind};
2829
use rustc_ast::{self as ast, *};
@@ -47,7 +48,6 @@ use rustc_span::edition::Edition;
4748
use rustc_span::source_map::Spanned;
4849
use rustc_span::symbol::{Ident, Symbol, kw, sym};
4950
use rustc_span::{BytePos, InnerSpan, Span};
50-
use rustc_target::abi::Abi;
5151
use rustc_target::asm::InlineAsmArch;
5252
use rustc_trait_selection::infer::{InferCtxtExt, TyCtxtInferExt};
5353
use rustc_trait_selection::traits::misc::type_allowed_to_implement_copy;
@@ -2473,7 +2473,7 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24732473

24742474
// Check if this ADT has a constrained layout (like `NonNull` and friends).
24752475
if let Ok(layout) = cx.tcx.layout_of(cx.param_env.and(ty)) {
2476-
if let Abi::Scalar(scalar) | Abi::ScalarPair(scalar, _) = &layout.abi {
2476+
if let IrForm::Scalar(scalar) | IrForm::ScalarPair(scalar, _) = &layout.ir_form {
24772477
let range = scalar.valid_range(cx);
24782478
let msg = if !range.contains(0) {
24792479
"must be non-null"

compiler/rustc_lint/src/foreign_modules.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ fn structurally_same_type<'tcx>(
217217
// `extern` blocks cannot be generic, so we'll always get a layout here.
218218
let a_layout = tcx.layout_of(param_env.and(a)).unwrap();
219219
let b_layout = tcx.layout_of(param_env.and(b)).unwrap();
220-
assert_eq!(a_layout.abi, b_layout.abi);
220+
assert_eq!(a_layout.ir_form, b_layout.ir_form);
221221
assert_eq!(a_layout.size, b_layout.size);
222222
assert_eq!(a_layout.align, b_layout.align);
223223
}

compiler/rustc_lint/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::iter;
22
use std::ops::ControlFlow;
33

4+
use rustc_abi::{IrForm, TagEncoding, Variants, WrappingRange};
45
use rustc_data_structures::fx::FxHashSet;
56
use rustc_errors::DiagMessage;
67
use rustc_hir::{Expr, ExprKind};
@@ -13,7 +14,6 @@ use rustc_session::{declare_lint, declare_lint_pass, impl_lint_pass};
1314
use rustc_span::def_id::LocalDefId;
1415
use rustc_span::symbol::sym;
1516
use rustc_span::{Span, Symbol, source_map};
16-
use rustc_target::abi::{Abi, TagEncoding, Variants, WrappingRange};
1717
use rustc_target::spec::abi::Abi as SpecAbi;
1818
use tracing::debug;
1919
use {rustc_ast as ast, rustc_hir as hir};
@@ -776,8 +776,8 @@ pub(crate) fn repr_nullable_ptr<'tcx>(
776776
bug!("should be able to compute the layout of non-polymorphic type");
777777
}
778778

779-
let field_ty_abi = &field_ty_layout.ok()?.abi;
780-
if let Abi::Scalar(field_ty_scalar) = field_ty_abi {
779+
let field_ty_abi = &field_ty_layout.ok()?.ir_form;
780+
if let IrForm::Scalar(field_ty_scalar) = field_ty_abi {
781781
match field_ty_scalar.valid_range(&tcx) {
782782
WrappingRange { start: 0, end }
783783
if end == field_ty_scalar.size(&tcx).unsigned_int_max() - 1 =>

compiler/rustc_mir_transform/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ edition = "2021"
77
# tidy-alphabetical-start
88
either = "1"
99
itertools = "0.12"
10+
11+
rustc_abi = { path = "../rustc_abi" }
1012
rustc_arena = { path = "../rustc_arena" }
1113
rustc_ast = { path = "../rustc_ast" }
1214
rustc_attr = { path = "../rustc_attr" }
@@ -26,6 +28,7 @@ rustc_span = { path = "../rustc_span" }
2628
rustc_target = { path = "../rustc_target" }
2729
rustc_trait_selection = { path = "../rustc_trait_selection" }
2830
rustc_type_ir = { path = "../rustc_type_ir" }
31+
2932
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
3033
tracing = "0.1"
3134
# tidy-alphabetical-end

compiler/rustc_mir_transform/src/dataflow_const_prop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//!
33
//! Currently, this pass only propagates scalar values.
44
5+
use rustc_abi::{FIRST_VARIANT, FieldIdx, IrForm, Size, VariantIdx};
56
use rustc_const_eval::const_eval::{DummyMachine, throw_machine_stop_str};
67
use rustc_const_eval::interpret::{
78
ImmTy, Immediate, InterpCx, OpTy, PlaceTy, Projectable, interp_ok,
@@ -20,7 +21,6 @@ use rustc_mir_dataflow::value_analysis::{
2021
};
2122
use rustc_mir_dataflow::{Analysis, Results, ResultsVisitor};
2223
use rustc_span::DUMMY_SP;
23-
use rustc_target::abi::{Abi, FIRST_VARIANT, FieldIdx, Size, VariantIdx};
2424
use tracing::{debug, debug_span, instrument};
2525

2626
// These constants are somewhat random guesses and have not been optimized.
@@ -457,7 +457,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
457457
// a pair and sometimes not. But as a hack we always return a pair
458458
// and just make the 2nd component `Bottom` when it does not exist.
459459
Some(val) => {
460-
if matches!(val.layout.abi, Abi::ScalarPair(..)) {
460+
if matches!(val.layout.ir_form, IrForm::ScalarPair(..)) {
461461
let (val, overflow) = val.to_scalar_pair();
462462
(FlatSet::Elem(val), FlatSet::Elem(overflow))
463463
} else {
@@ -470,7 +470,7 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> {
470470
// Exactly one side is known, attempt some algebraic simplifications.
471471
(FlatSet::Elem(const_arg), _) | (_, FlatSet::Elem(const_arg)) => {
472472
let layout = const_arg.layout;
473-
if !matches!(layout.abi, rustc_target::abi::Abi::Scalar(..)) {
473+
if !matches!(layout.ir_form, rustc_target::abi::IrForm::Scalar(..)) {
474474
return (FlatSet::Top, FlatSet::Top);
475475
}
476476

@@ -589,13 +589,13 @@ impl<'a, 'tcx> Collector<'a, 'tcx> {
589589
}
590590

591591
let place = map.find(place.as_ref())?;
592-
if layout.abi.is_scalar()
592+
if layout.ir_form.is_scalar()
593593
&& let Some(value) = propagatable_scalar(place, state, map)
594594
{
595595
return Some(Const::Val(ConstValue::Scalar(value), ty));
596596
}
597597

598-
if matches!(layout.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
598+
if matches!(layout.ir_form, IrForm::Scalar(..) | IrForm::ScalarPair(..)) {
599599
let alloc_id = ecx
600600
.intern_with_temp_alloc(layout, |ecx, dest| {
601601
try_write_constant(ecx, dest, place, ty, state, map)
@@ -641,7 +641,7 @@ fn try_write_constant<'tcx>(
641641
}
642642

643643
// Fast path for scalars.
644-
if layout.abi.is_scalar()
644+
if layout.ir_form.is_scalar()
645645
&& let Some(value) = propagatable_scalar(place, state, map)
646646
{
647647
return ecx.write_immediate(Immediate::Scalar(value), dest);

compiler/rustc_mir_transform/src/gvn.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
use std::borrow::Cow;
8686

8787
use either::Either;
88+
use rustc_abi::{self as abi, FIRST_VARIANT, FieldIdx, IrForm, Primitive, Size, VariantIdx};
8889
use rustc_const_eval::const_eval::DummyMachine;
8990
use rustc_const_eval::interpret::{
9091
ImmTy, Immediate, InterpCx, MemPlaceMeta, MemoryKind, OpTy, Projectable, Scalar,
@@ -103,7 +104,6 @@ use rustc_middle::ty::layout::{HasParamEnv, LayoutOf};
103104
use rustc_middle::ty::{self, Ty, TyCtxt};
104105
use rustc_span::DUMMY_SP;
105106
use rustc_span::def_id::DefId;
106-
use rustc_target::abi::{self, Abi, FIRST_VARIANT, FieldIdx, Primitive, Size, VariantIdx};
107107
use smallvec::SmallVec;
108108
use tracing::{debug, instrument, trace};
109109

@@ -427,7 +427,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
427427
};
428428
let ptr_imm = Immediate::new_pointer_with_meta(data, meta, &self.ecx);
429429
ImmTy::from_immediate(ptr_imm, ty).into()
430-
} else if matches!(ty.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
430+
} else if matches!(ty.ir_form, IrForm::Scalar(..) | IrForm::ScalarPair(..)) {
431431
let dest = self.ecx.allocate(ty, MemoryKind::Stack).discard_err()?;
432432
let variant_dest = if let Some(variant) = variant {
433433
self.ecx.project_downcast(&dest, variant).discard_err()?
@@ -573,12 +573,12 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
573573
// limited transmutes: it only works between types with the same layout, and
574574
// cannot transmute pointers to integers.
575575
if value.as_mplace_or_imm().is_right() {
576-
let can_transmute = match (value.layout.abi, to.abi) {
577-
(Abi::Scalar(s1), Abi::Scalar(s2)) => {
576+
let can_transmute = match (value.layout.ir_form, to.ir_form) {
577+
(IrForm::Scalar(s1), IrForm::Scalar(s2)) => {
578578
s1.size(&self.ecx) == s2.size(&self.ecx)
579579
&& !matches!(s1.primitive(), Primitive::Pointer(..))
580580
}
581-
(Abi::ScalarPair(a1, b1), Abi::ScalarPair(a2, b2)) => {
581+
(IrForm::ScalarPair(a1, b1), IrForm::ScalarPair(a2, b2)) => {
582582
a1.size(&self.ecx) == a2.size(&self.ecx) &&
583583
b1.size(&self.ecx) == b2.size(&self.ecx) &&
584584
// The alignment of the second component determines its offset, so that also needs to match.
@@ -1241,7 +1241,7 @@ impl<'body, 'tcx> VnState<'body, 'tcx> {
12411241

12421242
let as_bits = |value| {
12431243
let constant = self.evaluated[value].as_ref()?;
1244-
if layout.abi.is_scalar() {
1244+
if layout.ir_form.is_scalar() {
12451245
let scalar = self.ecx.read_scalar(constant).discard_err()?;
12461246
scalar.to_bits(constant.layout.size).discard_err()
12471247
} else {
@@ -1497,12 +1497,12 @@ fn op_to_prop_const<'tcx>(
14971497

14981498
// Do not synthetize too large constants. Codegen will just memcpy them, which we'd like to
14991499
// avoid.
1500-
if !matches!(op.layout.abi, Abi::Scalar(..) | Abi::ScalarPair(..)) {
1500+
if !matches!(op.layout.ir_form, IrForm::Scalar(..) | IrForm::ScalarPair(..)) {
15011501
return None;
15021502
}
15031503

15041504
// If this constant has scalar ABI, return it as a `ConstValue::Scalar`.
1505-
if let Abi::Scalar(abi::Scalar::Initialized { .. }) = op.layout.abi
1505+
if let IrForm::Scalar(abi::Scalar::Initialized { .. }) = op.layout.ir_form
15061506
&& let Some(scalar) = ecx.read_scalar(op).discard_err()
15071507
{
15081508
if !scalar.try_to_scalar_int().is_ok() {

compiler/rustc_mir_transform/src/known_panics_lint.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
use std::fmt::Debug;
66

7+
use rustc_abi::{FieldIdx, HasDataLayout, IrForm, Size, TargetDataLayout, VariantIdx};
78
use rustc_const_eval::const_eval::DummyMachine;
89
use rustc_const_eval::interpret::{
910
ImmTy, InterpCx, InterpResult, Projectable, Scalar, format_interp_error, interp_ok,
@@ -19,7 +20,6 @@ use rustc_middle::mir::*;
1920
use rustc_middle::ty::layout::{LayoutError, LayoutOf, LayoutOfHelpers, TyAndLayout};
2021
use rustc_middle::ty::{self, ConstInt, ParamEnv, ScalarInt, Ty, TyCtxt, TypeVisitableExt};
2122
use rustc_span::Span;
22-
use rustc_target::abi::{Abi, FieldIdx, HasDataLayout, Size, TargetDataLayout, VariantIdx};
2323
use tracing::{debug, instrument, trace};
2424

2525
use crate::errors::{AssertLint, AssertLintKind};
@@ -557,7 +557,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
557557
let right = self.use_ecx(|this| this.ecx.read_immediate(&right))?;
558558

559559
let val = self.use_ecx(|this| this.ecx.binary_op(bin_op, &left, &right))?;
560-
if matches!(val.layout.abi, Abi::ScalarPair(..)) {
560+
if matches!(val.layout.ir_form, IrForm::ScalarPair(..)) {
561561
// FIXME `Value` should properly support pairs in `Immediate`... but currently
562562
// it does not.
563563
let (val, overflow) = val.to_pair(&self.ecx);
@@ -651,9 +651,9 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
651651
let to = self.ecx.layout_of(to).ok()?;
652652
// `offset` for immediates only supports scalar/scalar-pair ABIs,
653653
// so bail out if the target is not one.
654-
match (value.layout.abi, to.abi) {
655-
(Abi::Scalar(..), Abi::Scalar(..)) => {}
656-
(Abi::ScalarPair(..), Abi::ScalarPair(..)) => {}
654+
match (value.layout.ir_form, to.ir_form) {
655+
(IrForm::Scalar(..), IrForm::Scalar(..)) => {}
656+
(IrForm::ScalarPair(..), IrForm::ScalarPair(..)) => {}
657657
_ => return None,
658658
}
659659

compiler/rustc_mir_transform/src/unreachable_enum_branching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! A pass that eliminates branches on uninhabited or unreachable enum variants.
22
3+
use rustc_abi::Variants;
34
use rustc_data_structures::fx::FxHashSet;
45
use rustc_middle::bug;
56
use rustc_middle::mir::patch::MirPatch;
@@ -9,7 +10,6 @@ use rustc_middle::mir::{
910
};
1011
use rustc_middle::ty::layout::TyAndLayout;
1112
use rustc_middle::ty::{Ty, TyCtxt};
12-
use rustc_target::abi::{Abi, Variants};
1313
use tracing::trace;
1414

1515
pub(super) struct UnreachableEnumBranching;

0 commit comments

Comments
 (0)