Skip to content

Commit 55f76cd

Browse files
committed
syntax: use distinct FloatTy from rustc_target.
We also sever syntax's dependency on rustc_target as a result. This should slightly improve pipe-lining. Moreover, some cleanup is done in related code.
1 parent bffc3d8 commit 55f76cd

File tree

19 files changed

+123
-158
lines changed

19 files changed

+123
-158
lines changed

Cargo.lock

-3
Original file line numberDiff line numberDiff line change
@@ -3762,7 +3762,6 @@ dependencies = [
37623762
"rustc",
37633763
"rustc_codegen_utils",
37643764
"rustc_data_structures",
3765-
"rustc_target",
37663765
"serde_json",
37673766
"syntax",
37683767
"syntax_pos",
@@ -4362,7 +4361,6 @@ dependencies = [
43624361
"rustc_errors",
43634362
"rustc_index",
43644363
"rustc_lexer",
4365-
"rustc_target",
43664364
"scoped-tls",
43674365
"serialize",
43684366
"smallvec 1.0.0",
@@ -4380,7 +4378,6 @@ dependencies = [
43804378
"rustc_errors",
43814379
"rustc_index",
43824380
"rustc_lexer",
4383-
"rustc_target",
43844381
"scoped-tls",
43854382
"serialize",
43864383
"smallvec 1.0.0",

src/librustc/ich/impls_syntax.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,6 @@ for ::syntax::attr::StabilityLevel {
124124

125125
impl_stable_hash_for!(struct ::syntax::attr::RustcDeprecation { since, reason, suggestion });
126126

127-
128127
impl_stable_hash_for!(enum ::syntax::attr::IntType {
129128
SignedInt(int_ty),
130129
UnsignedInt(uint_ty)
@@ -136,6 +135,11 @@ impl_stable_hash_for!(enum ::syntax::ast::LitIntType {
136135
Unsuffixed
137136
});
138137

138+
impl_stable_hash_for!(enum ::syntax::ast::LitFloatType {
139+
Suffixed(float_ty),
140+
Unsuffixed
141+
});
142+
139143
impl_stable_hash_for!(struct ::syntax::ast::Lit {
140144
kind,
141145
token,
@@ -148,8 +152,7 @@ impl_stable_hash_for!(enum ::syntax::ast::LitKind {
148152
Byte(value),
149153
Char(value),
150154
Int(value, lit_int_type),
151-
Float(value, float_ty),
152-
FloatUnsuffixed(value),
155+
Float(value, lit_float_type),
153156
Bool(value),
154157
Err(value)
155158
});
@@ -159,6 +162,7 @@ impl_stable_hash_for_spanned!(::syntax::ast::LitKind);
159162
impl_stable_hash_for!(enum ::syntax::ast::IntTy { Isize, I8, I16, I32, I64, I128 });
160163
impl_stable_hash_for!(enum ::syntax::ast::UintTy { Usize, U8, U16, U32, U64, U128 });
161164
impl_stable_hash_for!(enum ::syntax::ast::FloatTy { F32, F64 });
165+
impl_stable_hash_for!(enum ::rustc_target::abi::FloatTy { F32, F64 });
162166
impl_stable_hash_for!(enum ::syntax::ast::Unsafety { Unsafe, Normal });
163167
impl_stable_hash_for!(enum ::syntax::ast::Constness { Const, NotConst });
164168
impl_stable_hash_for!(enum ::syntax::ast::Defaultness { Default, Final });

src/librustc/ty/layout.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,10 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
538538
ty::Uint(ity) => {
539539
scalar(Int(Integer::from_attr(dl, attr::UnsignedInt(ity)), false))
540540
}
541-
ty::Float(fty) => scalar(Float(fty)),
541+
ty::Float(fty) => scalar(Float(match fty {
542+
ast::FloatTy::F32 => FloatTy::F32,
543+
ast::FloatTy::F64 => FloatTy::F64,
544+
})),
542545
ty::FnPtr(_) => {
543546
let mut ptr = scalar_unit(Pointer);
544547
ptr.valid_range = 1..=*ptr.valid_range.end();

src/librustc/ty/print/obsolete.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use rustc::ty::{self, Const, Instance, Ty, TyCtxt};
1212
use rustc::{bug, hir};
1313
use std::fmt::Write;
1414
use std::iter;
15-
use syntax::ast;
1615

1716
/// Same as `unique_type_name()` but with the result pushed onto the given
1817
/// `output` parameter.
@@ -39,20 +38,9 @@ impl DefPathBasedNames<'tcx> {
3938
ty::Char => output.push_str("char"),
4039
ty::Str => output.push_str("str"),
4140
ty::Never => output.push_str("!"),
42-
ty::Int(ast::IntTy::Isize) => output.push_str("isize"),
43-
ty::Int(ast::IntTy::I8) => output.push_str("i8"),
44-
ty::Int(ast::IntTy::I16) => output.push_str("i16"),
45-
ty::Int(ast::IntTy::I32) => output.push_str("i32"),
46-
ty::Int(ast::IntTy::I64) => output.push_str("i64"),
47-
ty::Int(ast::IntTy::I128) => output.push_str("i128"),
48-
ty::Uint(ast::UintTy::Usize) => output.push_str("usize"),
49-
ty::Uint(ast::UintTy::U8) => output.push_str("u8"),
50-
ty::Uint(ast::UintTy::U16) => output.push_str("u16"),
51-
ty::Uint(ast::UintTy::U32) => output.push_str("u32"),
52-
ty::Uint(ast::UintTy::U64) => output.push_str("u64"),
53-
ty::Uint(ast::UintTy::U128) => output.push_str("u128"),
54-
ty::Float(ast::FloatTy::F32) => output.push_str("f32"),
55-
ty::Float(ast::FloatTy::F64) => output.push_str("f64"),
41+
ty::Int(ty) => output.push_str(ty.name_str()),
42+
ty::Uint(ty) => output.push_str(ty.name_str()),
43+
ty::Float(ty) => output.push_str(ty.name_str()),
5644
ty::Adt(adt_def, substs) => {
5745
self.push_def_path(adt_def.did, output);
5846
self.push_generic_params(substs, iter::empty(), output, debug);

src/librustc/ty/print/pretty.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -466,9 +466,9 @@ pub trait PrettyPrinter<'tcx>:
466466
match ty.kind {
467467
ty::Bool => p!(write("bool")),
468468
ty::Char => p!(write("char")),
469-
ty::Int(t) => p!(write("{}", t.ty_to_string())),
470-
ty::Uint(t) => p!(write("{}", t.ty_to_string())),
471-
ty::Float(t) => p!(write("{}", t.ty_to_string())),
469+
ty::Int(t) => p!(write("{}", t.name_str())),
470+
ty::Uint(t) => p!(write("{}", t.name_str())),
471+
ty::Float(t) => p!(write("{}", t.name_str())),
472472
ty::RawPtr(ref tm) => {
473473
p!(write("*{} ", match tm.mutbl {
474474
hir::MutMutable => "mut",
@@ -895,10 +895,11 @@ pub trait PrettyPrinter<'tcx>:
895895
let bit_size = Integer::from_attr(&self.tcx(), UnsignedInt(*ui)).size();
896896
let max = truncate(u128::max_value(), bit_size);
897897

898+
let ui_str = ui.name_str();
898899
if data == max {
899-
p!(write("std::{}::MAX", ui))
900+
p!(write("std::{}::MAX", ui_str))
900901
} else {
901-
p!(write("{}{}", data, ui))
902+
p!(write("{}{}", data, ui_str))
902903
};
903904
},
904905
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Int(i)) => {
@@ -911,10 +912,11 @@ pub trait PrettyPrinter<'tcx>:
911912
let size = self.tcx().layout_of(ty::ParamEnv::empty().and(ty))
912913
.unwrap()
913914
.size;
915+
let i_str = i.name_str();
914916
match data {
915-
d if d == min => p!(write("std::{}::MIN", i)),
916-
d if d == max => p!(write("std::{}::MAX", i)),
917-
_ => p!(write("{}{}", sign_extend(data, size) as i128, i))
917+
d if d == min => p!(write("std::{}::MIN", i_str)),
918+
d if d == max => p!(write("std::{}::MAX", i_str)),
919+
_ => p!(write("{}{}", sign_extend(data, size) as i128, i_str))
918920
}
919921
},
920922
(ConstValue::Scalar(Scalar::Raw { data, .. }), ty::Char) =>

src/librustc_codegen_llvm/debuginfo/metadata.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -843,13 +843,13 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
843843
ty::Bool => ("bool", DW_ATE_boolean),
844844
ty::Char => ("char", DW_ATE_unsigned_char),
845845
ty::Int(int_ty) => {
846-
(int_ty.ty_to_string(), DW_ATE_signed)
846+
(int_ty.name_str(), DW_ATE_signed)
847847
},
848848
ty::Uint(uint_ty) => {
849-
(uint_ty.ty_to_string(), DW_ATE_unsigned)
849+
(uint_ty.name_str(), DW_ATE_unsigned)
850850
},
851851
ty::Float(float_ty) => {
852-
(float_ty.ty_to_string(), DW_ATE_float)
852+
(float_ty.name_str(), DW_ATE_float)
853853
},
854854
_ => bug!("debuginfo::basic_type_metadata - t is invalid type")
855855
};

src/librustc_codegen_llvm/intrinsic.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use rustc::ty::layout::{self, LayoutOf, HasTyCtxt, Primitive};
1818
use rustc::mir::interpret::GlobalId;
1919
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
2020
use rustc::hir;
21-
use syntax::ast::{self, FloatTy};
22-
use rustc_target::abi::HasDataLayout;
21+
use rustc_target::abi::{FloatTy, HasDataLayout};
22+
use syntax::ast;
2323

2424
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
2525
use rustc_codegen_ssa::traits::*;
@@ -1335,7 +1335,7 @@ fn generic_simd_intrinsic(
13351335
},
13361336
ty::Float(f) => {
13371337
return_error!("unsupported element type `{}` of floating-point vector `{}`",
1338-
f, in_ty);
1338+
f.name_str(), in_ty);
13391339
},
13401340
_ => {
13411341
return_error!("`{}` is not a floating-point type", in_ty);

src/librustc_codegen_ssa/debuginfo/type_names.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ pub fn push_debuginfo_type_name<'tcx>(
3737
ty::Char => output.push_str("char"),
3838
ty::Str => output.push_str("str"),
3939
ty::Never => output.push_str("!"),
40-
ty::Int(int_ty) => output.push_str(int_ty.ty_to_string()),
41-
ty::Uint(uint_ty) => output.push_str(uint_ty.ty_to_string()),
42-
ty::Float(float_ty) => output.push_str(float_ty.ty_to_string()),
40+
ty::Int(int_ty) => output.push_str(int_ty.name_str()),
41+
ty::Uint(uint_ty) => output.push_str(uint_ty.name_str()),
42+
ty::Float(float_ty) => output.push_str(float_ty.name_str()),
4343
ty::Foreign(def_id) => push_item_name(tcx, def_id, qualified, output),
4444
ty::Adt(def, substs) => {
4545
push_item_name(tcx, def.did, qualified, output);

src/librustc_interface/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ rustc_codegen_utils = { path = "../librustc_codegen_utils" }
2727
rustc_metadata = { path = "../librustc_metadata" }
2828
rustc_mir = { path = "../librustc_mir" }
2929
rustc_passes = { path = "../librustc_passes" }
30-
rustc_target = { path = "../librustc_target" }
3130
rustc_typeck = { path = "../librustc_typeck" }
3231
rustc_lint = { path = "../librustc_lint" }
3332
rustc_errors = { path = "../librustc_errors" }
@@ -36,3 +35,6 @@ rustc_privacy = { path = "../librustc_privacy" }
3635
rustc_resolve = { path = "../librustc_resolve" }
3736
tempfile = "3.0.5"
3837
once_cell = "1"
38+
39+
[dev-dependencies]
40+
rustc_target = { path = "../librustc_target" }

src/librustc_lint/types.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
6868
max: u128,
6969
expr: &'tcx hir::Expr,
7070
parent_expr: &'tcx hir::Expr,
71-
ty: impl std::fmt::Debug,
71+
ty: &str,
7272
) -> bool {
7373
// We only want to handle exclusive (`..`) ranges,
7474
// which are represented as `ExprKind::Struct`.
@@ -83,15 +83,15 @@ fn lint_overflowing_range_endpoint<'a, 'tcx>(
8383
let mut err = cx.struct_span_lint(
8484
OVERFLOWING_LITERALS,
8585
parent_expr.span,
86-
&format!("range endpoint is out of range for `{:?}`", ty),
86+
&format!("range endpoint is out of range for `{}`", ty),
8787
);
8888
if let Ok(start) = cx.sess().source_map().span_to_snippet(eps[0].span) {
8989
use ast::{LitKind, LitIntType};
9090
// We need to preserve the literal's suffix,
9191
// as it may determine typing information.
9292
let suffix = match lit.node {
93-
LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s),
94-
LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s),
93+
LitKind::Int(_, LitIntType::Signed(s)) => format!("{}", s.name_str()),
94+
LitKind::Int(_, LitIntType::Unsigned(s)) => format!("{}", s.name_str()),
9595
LitKind::Int(_, LitIntType::Unsuffixed) => "".to_owned(),
9696
_ => bug!(),
9797
};
@@ -161,11 +161,11 @@ fn report_bin_hex_error(
161161
let (t, actually) = match ty {
162162
attr::IntType::SignedInt(t) => {
163163
let actually = sign_extend(val, size) as i128;
164-
(format!("{:?}", t), actually.to_string())
164+
(t.name_str(), actually.to_string())
165165
}
166166
attr::IntType::UnsignedInt(t) => {
167167
let actually = truncate(val, size);
168-
(format!("{:?}", t), actually.to_string())
168+
(t.name_str(), actually.to_string())
169169
}
170170
};
171171
let mut err = cx.struct_span_lint(
@@ -204,7 +204,7 @@ fn report_bin_hex_error(
204204
// - `uX` => `uY`
205205
//
206206
// No suggestion for: `isize`, `usize`.
207-
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
207+
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static str> {
208208
use syntax::ast::IntTy::*;
209209
use syntax::ast::UintTy::*;
210210
macro_rules! find_fit {
@@ -215,10 +215,10 @@ fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<String> {
215215
match $ty {
216216
$($type => {
217217
$(if !negative && val <= uint_ty_range($utypes).1 {
218-
return Some(format!("{:?}", $utypes))
218+
return Some($utypes.name_str())
219219
})*
220220
$(if val <= int_ty_range($itypes).1 as u128 + _neg {
221-
return Some(format!("{:?}", $itypes))
221+
return Some($itypes.name_str())
222222
})*
223223
None
224224
},)+
@@ -281,7 +281,7 @@ fn lint_int_literal<'a, 'tcx>(
281281
if let Node::Expr(par_e) = cx.tcx.hir().get(par_id) {
282282
if let hir::ExprKind::Struct(..) = par_e.kind {
283283
if is_range_literal(cx.sess(), par_e)
284-
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t)
284+
&& lint_overflowing_range_endpoint(cx, lit, v, max, e, par_e, t.name_str())
285285
{
286286
// The overflowing literal lint was overridden.
287287
return;
@@ -292,7 +292,7 @@ fn lint_int_literal<'a, 'tcx>(
292292
cx.span_lint(
293293
OVERFLOWING_LITERALS,
294294
e.span,
295-
&format!("literal out of range for `{:?}`", t),
295+
&format!("literal out of range for `{}`", t.name_str()),
296296
);
297297
}
298298
}
@@ -338,6 +338,7 @@ fn lint_uint_literal<'a, 'tcx>(
338338
}
339339
hir::ExprKind::Struct(..)
340340
if is_range_literal(cx.sess(), par_e) => {
341+
let t = t.name_str();
341342
if lint_overflowing_range_endpoint(cx, lit, lit_val, max, e, par_e, t) {
342343
// The overflowing literal lint was overridden.
343344
return;
@@ -353,7 +354,7 @@ fn lint_uint_literal<'a, 'tcx>(
353354
cx.span_lint(
354355
OVERFLOWING_LITERALS,
355356
e.span,
356-
&format!("literal out of range for `{:?}`", t),
357+
&format!("literal out of range for `{}`", t.name_str()),
357358
);
358359
}
359360
}
@@ -379,8 +380,7 @@ fn lint_literal<'a, 'tcx>(
379380
}
380381
ty::Float(t) => {
381382
let is_infinite = match lit.node {
382-
ast::LitKind::Float(v, _) |
383-
ast::LitKind::FloatUnsuffixed(v) => {
383+
ast::LitKind::Float(v, _) => {
384384
match t {
385385
ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
386386
ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
@@ -389,9 +389,11 @@ fn lint_literal<'a, 'tcx>(
389389
_ => bug!(),
390390
};
391391
if is_infinite == Ok(true) {
392-
cx.span_lint(OVERFLOWING_LITERALS,
393-
e.span,
394-
&format!("literal out of range for `{:?}`", t));
392+
cx.span_lint(
393+
OVERFLOWING_LITERALS,
394+
e.span,
395+
&format!("literal out of range for `{}`", t.name_str()),
396+
);
395397
}
396398
}
397399
_ => {}

src/librustc_mir/hair/constant.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ crate fn lit_to_const<'tcx>(
4545
trunc(n as u128)?
4646
},
4747
LitKind::Int(n, _) => trunc(n)?,
48-
LitKind::Float(n, fty) => {
49-
parse_float(n, fty, neg).map_err(|_| LitToConstError::UnparseableFloat)?
50-
}
51-
LitKind::FloatUnsuffixed(n) => {
48+
LitKind::Float(n, _) => {
5249
let fty = match ty.kind {
5350
ty::Float(fty) => fty,
5451
_ => bug!()

src/librustc_save_analysis/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ log = "0.4"
1313
rustc = { path = "../librustc" }
1414
rustc_data_structures = { path = "../librustc_data_structures" }
1515
rustc_codegen_utils = { path = "../librustc_codegen_utils" }
16-
rustc_target = { path = "../librustc_target" }
1716
serde_json = "1"
1817
syntax = { path = "../libsyntax" }
1918
syntax_pos = { path = "../libsyntax_pos" }

0 commit comments

Comments
 (0)