Rollup merge of #66719 - Mark-Simulacrum:int-normalization, r=Centril
Store pointer width as u32 on Config This removes the dependency on IntTy, UintTy from Session. It's not obviously a win, but it seems a bit odd to store the AST IntTy/UintTy in Session, rather we store the pointer width as an integer and add normalization methods to IntTy and UintTy.
This commit is contained in:
commit
f178d35ae7
5 changed files with 37 additions and 24 deletions
|
@ -12,7 +12,7 @@ use rustc_target::spec::{LinkerFlavor, MergeFunctions, PanicStrategy, RelroLevel
|
||||||
use rustc_target::spec::{Target, TargetTriple};
|
use rustc_target::spec::{Target, TargetTriple};
|
||||||
|
|
||||||
use syntax;
|
use syntax;
|
||||||
use syntax::ast::{self, IntTy, UintTy};
|
use syntax::ast;
|
||||||
use syntax::source_map::{FileName, FilePathMapping};
|
use syntax::source_map::{FileName, FilePathMapping};
|
||||||
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
|
use syntax::edition::{Edition, EDITION_NAME_LIST, DEFAULT_EDITION};
|
||||||
use syntax::symbol::{sym, Symbol};
|
use syntax::symbol::{sym, Symbol};
|
||||||
|
@ -36,8 +36,7 @@ use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub target: Target,
|
pub target: Target,
|
||||||
pub isize_ty: IntTy,
|
pub ptr_width: u32,
|
||||||
pub usize_ty: UintTy,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
@ -1621,10 +1620,10 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
||||||
FatalError.raise();
|
FatalError.raise();
|
||||||
});
|
});
|
||||||
|
|
||||||
let (isize_ty, usize_ty) = match &target.target_pointer_width[..] {
|
let ptr_width = match &target.target_pointer_width[..] {
|
||||||
"16" => (ast::IntTy::I16, ast::UintTy::U16),
|
"16" => 16,
|
||||||
"32" => (ast::IntTy::I32, ast::UintTy::U32),
|
"32" => 32,
|
||||||
"64" => (ast::IntTy::I64, ast::UintTy::U64),
|
"64" => 64,
|
||||||
w => sp.fatal(&format!(
|
w => sp.fatal(&format!(
|
||||||
"target specification was invalid: \
|
"target specification was invalid: \
|
||||||
unrecognized target-pointer-width {}",
|
unrecognized target-pointer-width {}",
|
||||||
|
@ -1634,8 +1633,7 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
|
||||||
|
|
||||||
Config {
|
Config {
|
||||||
target,
|
target,
|
||||||
isize_ty,
|
ptr_width,
|
||||||
usize_ty,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -325,8 +325,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||||
use rustc::ty::{Int, Uint};
|
use rustc::ty::{Int, Uint};
|
||||||
|
|
||||||
let new_kind = match ty.kind {
|
let new_kind = match ty.kind {
|
||||||
Int(Isize) => Int(self.tcx.sess.target.isize_ty),
|
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
|
||||||
Uint(Usize) => Uint(self.tcx.sess.target.usize_ty),
|
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
|
||||||
ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
|
ref t @ Uint(_) | ref t @ Int(_) => t.clone(),
|
||||||
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
|
_ => panic!("tried to get overflow intrinsic for op applied to non-int type")
|
||||||
};
|
};
|
||||||
|
|
|
@ -1926,7 +1926,7 @@ unsupported {} from `{}` with element `{}` of size `{}` to `{}`"#,
|
||||||
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
|
fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, bool)> {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
ty::Int(t) => Some((match t {
|
ty::Int(t) => Some((match t {
|
||||||
ast::IntTy::Isize => cx.tcx.sess.target.isize_ty.bit_width().unwrap() as u64,
|
ast::IntTy::Isize => cx.tcx.sess.target.ptr_width as u64,
|
||||||
ast::IntTy::I8 => 8,
|
ast::IntTy::I8 => 8,
|
||||||
ast::IntTy::I16 => 16,
|
ast::IntTy::I16 => 16,
|
||||||
ast::IntTy::I32 => 32,
|
ast::IntTy::I32 => 32,
|
||||||
|
@ -1934,7 +1934,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
|
||||||
ast::IntTy::I128 => 128,
|
ast::IntTy::I128 => 128,
|
||||||
}, true)),
|
}, true)),
|
||||||
ty::Uint(t) => Some((match t {
|
ty::Uint(t) => Some((match t {
|
||||||
ast::UintTy::Usize => cx.tcx.sess.target.usize_ty.bit_width().unwrap() as u64,
|
ast::UintTy::Usize => cx.tcx.sess.target.ptr_width as u64,
|
||||||
ast::UintTy::U8 => 8,
|
ast::UintTy::U8 => 8,
|
||||||
ast::UintTy::U16 => 16,
|
ast::UintTy::U16 => 16,
|
||||||
ast::UintTy::U32 => 32,
|
ast::UintTy::U32 => 32,
|
||||||
|
|
|
@ -252,12 +252,7 @@ fn lint_int_literal<'a, 'tcx>(
|
||||||
t: ast::IntTy,
|
t: ast::IntTy,
|
||||||
v: u128,
|
v: u128,
|
||||||
) {
|
) {
|
||||||
let int_type = if let ast::IntTy::Isize = t {
|
let int_type = t.normalize(cx.sess().target.ptr_width);
|
||||||
cx.sess().target.isize_ty
|
|
||||||
} else {
|
|
||||||
t
|
|
||||||
};
|
|
||||||
|
|
||||||
let (_, max) = int_ty_range(int_type);
|
let (_, max) = int_ty_range(int_type);
|
||||||
let max = max as u128;
|
let max = max as u128;
|
||||||
let negative = type_limits.negated_expr_id == e.hir_id;
|
let negative = type_limits.negated_expr_id == e.hir_id;
|
||||||
|
@ -303,11 +298,7 @@ fn lint_uint_literal<'a, 'tcx>(
|
||||||
lit: &hir::Lit,
|
lit: &hir::Lit,
|
||||||
t: ast::UintTy,
|
t: ast::UintTy,
|
||||||
) {
|
) {
|
||||||
let uint_type = if let ast::UintTy::Usize = t {
|
let uint_type = t.normalize(cx.sess().target.ptr_width);
|
||||||
cx.sess().target.usize_ty
|
|
||||||
} else {
|
|
||||||
t
|
|
||||||
};
|
|
||||||
let (min, max) = uint_ty_range(uint_type);
|
let (min, max) = uint_ty_range(uint_type);
|
||||||
let lit_val: u128 = match lit.node {
|
let lit_val: u128 = match lit.node {
|
||||||
// _v is u8, within range by definition
|
// _v is u8, within range by definition
|
||||||
|
|
|
@ -1718,6 +1718,18 @@ impl IntTy {
|
||||||
IntTy::I128 => 128,
|
IntTy::I128 => 128,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn normalize(&self, target_width: u32) -> Self {
|
||||||
|
match self {
|
||||||
|
IntTy::Isize => match target_width {
|
||||||
|
16 => IntTy::I16,
|
||||||
|
32 => IntTy::I32,
|
||||||
|
64 => IntTy::I64,
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
_ => *self,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic,
|
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, HashStable_Generic,
|
||||||
|
@ -1768,6 +1780,18 @@ impl UintTy {
|
||||||
UintTy::U128 => 128,
|
UintTy::U128 => 128,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn normalize(&self, target_width: u32) -> Self {
|
||||||
|
match self {
|
||||||
|
UintTy::Usize => match target_width {
|
||||||
|
16 => UintTy::U16,
|
||||||
|
32 => UintTy::U32,
|
||||||
|
64 => UintTy::U64,
|
||||||
|
_ => unreachable!(),
|
||||||
|
},
|
||||||
|
_ => *self,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
|
/// A constraint on an associated type (e.g., `A = Bar` in `Foo<A = Bar>` or
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue