From b0e55a83a82bae26851f442859acace2b94f5028 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Tue, 23 Aug 2016 03:56:52 +0300 Subject: Such large. Very 128. Much bits. This commit introduces 128-bit integers. Stage 2 builds and produces a working compiler which understands and supports 128-bit integers throughout. The general strategy used is to have rustc_i128 module which provides aliases for iu128, equal to iu64 in stage9 and iu128 later. Since nowhere in rustc we rely on large numbers being supported, this strategy is good enough to get past the first bootstrap stages to end up with a fully working 128-bit capable compiler. In order for this strategy to work, number of locations had to be changed to use associated max_value/min_value instead of MAX/MIN constants as well as the min_value (or was it max_value?) had to be changed to use xor instead of shift so both 64-bit and 128-bit based consteval works (former not necessarily producing the right results in stage1). This commit includes manual merge conflict resolution changes from a rebase by @est31. --- src/libsyntax_ext/deriving/generic/mod.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/libsyntax_ext') diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 7f187d8d1c1..114bf437cfd 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -782,12 +782,13 @@ fn find_repr_type_name(diagnostic: &Handler, type_attrs: &[ast::Attribute]) -> & attr::ReprInt(attr::SignedInt(ast::IntTy::I16)) => "i16", attr::ReprInt(attr::SignedInt(ast::IntTy::I32)) => "i32", attr::ReprInt(attr::SignedInt(ast::IntTy::I64)) => "i64", + attr::ReprInt(attr::SignedInt(ast::IntTy::I128)) => "i128", attr::ReprInt(attr::UnsignedInt(ast::UintTy::Us)) => "usize", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U8)) => "u8", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U16)) => "u16", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U32)) => "u32", - attr::ReprInt(attr::UnsignedInt(ast::UintTy::U64)) => "u64", + attr::ReprInt(attr::UnsignedInt(ast::UintTy::U128)) => "u128", } } } -- cgit 1.4.1-3-g733a5 From 7a3704c50044a0e9d611a264daeabbf47d398474 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Tue, 27 Sep 2016 19:06:44 +0300 Subject: Fix rebase fallout This commit includes manual merge conflict resolution changes from a rebase by @est31. --- src/libproc_macro/Cargo.toml | 1 - src/librustc/ty/layout.rs | 4 ++++ src/librustc_metadata/decoder.rs | 2 +- src/librustc_metadata/encoder.rs | 12 ++++++++---- src/librustc_metadata/lib.rs | 3 --- src/librustc_metadata/schema.rs | 4 +++- src/librustc_resolve/lib.rs | 4 ++-- src/librustc_trans/type_.rs | 1 + src/librustc_typeck/check/mod.rs | 2 +- src/libsyntax_ext/deriving/generic/mod.rs | 1 + src/rustllvm/RustWrapper.cpp | 1 + src/test/run-pass/i128.rs | 3 +++ src/test/run-pass/u128.rs | 3 +++ 13 files changed, 28 insertions(+), 13 deletions(-) (limited to 'src/libsyntax_ext') diff --git a/src/libproc_macro/Cargo.toml b/src/libproc_macro/Cargo.toml index ca26ddbe5a0..7ce65d0fe4d 100644 --- a/src/libproc_macro/Cargo.toml +++ b/src/libproc_macro/Cargo.toml @@ -9,4 +9,3 @@ crate-type = ["dylib"] [dependencies] syntax = { path = "../libsyntax" } -rustc_i128 = { path = "../librustc_i128" } diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index d930d5d2246..ed2aa5e51b9 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -350,6 +350,7 @@ impl Integer { I16 => Size::from_bytes(2), I32 => Size::from_bytes(4), I64 => Size::from_bytes(8), + I128 => Size::from_bytes(16), } } @@ -360,6 +361,7 @@ impl Integer { I16 => dl.i16_align, I32 => dl.i32_align, I64 => dl.i64_align, + I128 => dl.i128_align, } } @@ -371,11 +373,13 @@ impl Integer { (I16, false) => tcx.types.u16, (I32, false) => tcx.types.u32, (I64, false) => tcx.types.u64, + (I128, false) => tcx.types.u128, (I1, true) => tcx.types.i8, (I8, true) => tcx.types.i8, (I16, true) => tcx.types.i16, (I32, true) => tcx.types.i32, (I64, true) => tcx.types.i64, + (I128, true) => tcx.types.i128, } } diff --git a/src/librustc_metadata/decoder.rs b/src/librustc_metadata/decoder.rs index 3e3553dd1f2..cfc4dfb9075 100644 --- a/src/librustc_metadata/decoder.rs +++ b/src/librustc_metadata/decoder.rs @@ -44,7 +44,7 @@ use syntax::ast::{self, NodeId}; use syntax::codemap; use syntax_pos::{self, Span, BytePos, Pos, DUMMY_SP}; use syntax_pos::{self, Span, BytePos, Pos}; -use rustc_i128::u128; +use rustc_i128::{u128, i128}; pub struct DecodeContext<'a, 'tcx: 'a> { opaque: opaque::Decoder<'a>, diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 72dcb4ba9a3..c3bcdf42d4e 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -43,6 +43,8 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::intravisit::{Visitor, NestedVisitorMap}; use rustc::hir::intravisit; +use rustc_i128::{u128, i128}; + use super::index_builder::{FromId, IndexBuilder, Untracked}; pub struct EncodeContext<'a, 'tcx: 'a> { @@ -75,12 +77,14 @@ impl<'a, 'tcx> Encoder for EncodeContext<'a, 'tcx> { encoder_methods! { emit_usize(usize); + emit_u128(u128); emit_u64(u64); emit_u32(u32); emit_u16(u16); emit_u8(u8); emit_isize(isize); + emit_i128(i128); emit_i64(i64); emit_i32(i32); emit_i16(i16); @@ -259,7 +263,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let data = VariantData { ctor_kind: variant.ctor_kind, - disr: variant.disr_val.to_u64_unchecked(), + disr: variant.disr_val.to_u128_unchecked(), struct_ctor: None, }; @@ -386,7 +390,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { let data = VariantData { ctor_kind: variant.ctor_kind, - disr: variant.disr_val.to_u64_unchecked(), + disr: variant.disr_val.to_u128_unchecked(), struct_ctor: Some(def_id.index), }; @@ -648,7 +652,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { }; EntryKind::Struct(self.lazy(&VariantData { ctor_kind: variant.ctor_kind, - disr: variant.disr_val.to_u64_unchecked(), + disr: variant.disr_val.to_u128_unchecked(), struct_ctor: struct_ctor, })) } @@ -657,7 +661,7 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { EntryKind::Union(self.lazy(&VariantData { ctor_kind: variant.ctor_kind, - disr: variant.disr_val.to_u64_unchecked(), + disr: variant.disr_val.to_u128_unchecked(), struct_ctor: None, })) } diff --git a/src/librustc_metadata/lib.rs b/src/librustc_metadata/lib.rs index 8ba3e7d82f2..f4ccc01544a 100644 --- a/src/librustc_metadata/lib.rs +++ b/src/librustc_metadata/lib.rs @@ -51,9 +51,6 @@ mod diagnostics; pub use rustc::middle; -#[macro_use] -mod macros; - mod astencode; mod index_builder; mod index; diff --git a/src/librustc_metadata/schema.rs b/src/librustc_metadata/schema.rs index 2bd5a9ea59d..74825a5c6e3 100644 --- a/src/librustc_metadata/schema.rs +++ b/src/librustc_metadata/schema.rs @@ -27,6 +27,8 @@ use syntax_pos::{self, Span}; use std::marker::PhantomData; +use rustc_i128::u128; + pub fn rustc_version() -> String { format!("rustc {}", option_env!("CFG_VERSION").unwrap_or("unknown version")) @@ -264,7 +266,7 @@ pub struct FnData { #[derive(RustcEncodable, RustcDecodable)] pub struct VariantData { pub ctor_kind: CtorKind, - pub disr: u64, + pub disr: u128, /// If this is a struct's only variant, this /// is the index of the "struct ctor" item. diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index f27a5c80b9c..b7908f0c0ed 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -2313,8 +2313,8 @@ impl<'a> Resolver<'a> { let prim = self.primitive_type_table.primitive_types[&path[0].name]; match prim { TyUint(UintTy::U128) | TyInt(IntTy::I128) => { - if !this.session.features.borrow().i128_type { - emit_feature_err(&this.session.parse_sess.span_diagnostic, + if !self.session.features.borrow().i128_type { + emit_feature_err(&self.session.parse_sess, "i128_type", span, GateIssue::Language, "128-bit type is unstable"); diff --git a/src/librustc_trans/type_.rs b/src/librustc_trans/type_.rs index 5e4fe015d76..f68acab9113 100644 --- a/src/librustc_trans/type_.rs +++ b/src/librustc_trans/type_.rs @@ -313,6 +313,7 @@ impl Type { I16 => Type::i16(cx), I32 => Type::i32(cx), I64 => Type::i64(cx), + I128 => Type::i128(cx), } } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 051a4200235..26dd53fecb2 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -1332,7 +1332,7 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>, let repr_type_ty = ccx.tcx.enum_repr_type(Some(&hint)).to_ty(ccx.tcx); if repr_type_ty == ccx.tcx.types.i128 || repr_type_ty == ccx.tcx.types.u128 { if !ccx.tcx.sess.features.borrow().i128_type { - emit_feature_err(&ccx.tcx.sess.parse_sess.span_diagnostic, + emit_feature_err(&ccx.tcx.sess.parse_sess, "i128_type", sp, GateIssue::Language, "128-bit type is unstable"); } } diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 114bf437cfd..0d2f4eaaffd 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -788,6 +788,7 @@ fn find_repr_type_name(diagnostic: &Handler, type_attrs: &[ast::Attribute]) -> & attr::ReprInt(attr::UnsignedInt(ast::UintTy::U8)) => "u8", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U16)) => "u16", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U32)) => "u32", + attr::ReprInt(attr::UnsignedInt(ast::UintTy::U64)) => "u64", attr::ReprInt(attr::UnsignedInt(ast::UintTy::U128)) => "u128", } } diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 81093249318..46ba68f0724 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -1456,6 +1456,7 @@ extern "C" LLVMRustLinkage LLVMRustGetLinkage(LLVMValueRef V) { extern "C" void LLVMRustSetLinkage(LLVMValueRef V, LLVMRustLinkage RustLinkage) { LLVMSetLinkage(V, from_rust(RustLinkage)); +} // Returns true if both high and low were successfully set. Fails in case constant wasn’t any of // the common sizes (1, 8, 16, 32, 64, 128 bits) diff --git a/src/test/run-pass/i128.rs b/src/test/run-pass/i128.rs index 57ef6e55935..2279a84ca5c 100644 --- a/src/test/run-pass/i128.rs +++ b/src/test/run-pass/i128.rs @@ -7,6 +7,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. + +// ignore-stage0 +// ignore-stage1 #![feature(i128_type)] fn main() { diff --git a/src/test/run-pass/u128.rs b/src/test/run-pass/u128.rs index 4c6ae7b0e78..9c87a5a8ee6 100644 --- a/src/test/run-pass/u128.rs +++ b/src/test/run-pass/u128.rs @@ -7,6 +7,9 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. + +// ignore-stage0 +// ignore-stage1 #![feature(i128_type)] fn main() { -- cgit 1.4.1-3-g733a5