Skip to content

i128 and u128 support #37900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0d3cac9
Such large. Very 128. Much bits.
nagisa Aug 23, 2016
331432d
Tests for the 128 bit integers
nagisa Aug 23, 2016
002f9a1
Feature gate the 128 bit types
nagisa Aug 23, 2016
660c12c
Cleanup FIXMEs
nagisa Aug 23, 2016
2f0457d
Fix LEB128 to work with the stage1
nagisa Aug 24, 2016
1e203f5
Tidy
nagisa Aug 24, 2016
3a31265
Makefiles support for rustc_i128 crate
nagisa Aug 24, 2016
c6b5c91
Wrapping<i128> and attempt at LLVM 3.7 compat
nagisa Aug 24, 2016
275b4d5
Fix parse-fail and compile-fail tests
nagisa Aug 24, 2016
ad743e0
impl Step for iu128
nagisa Aug 24, 2016
aa5adb7
Add a way to retrieve constant value in 128 bits
nagisa Aug 25, 2016
eb44eb3
Implement emit_iu128 for json serialiser
nagisa Aug 27, 2016
af9fe30
Fix i128 alignment calculation
nagisa Sep 27, 2016
792fecf
Fix rebase fallout
nagisa Sep 27, 2016
ac942a2
WIP intrinsics
nagisa Oct 2, 2016
236da89
Fix rebase fallout
est31 Nov 20, 2016
231485f
Use LLVMRustConstInt128Get on stage1 too
est31 Nov 20, 2016
36269e3
Compilation fixes
est31 Nov 20, 2016
42b6518
Make rustdoc aware of the primitive i128 type
est31 Nov 21, 2016
231cf20
Fix intrinsics and expand tests
est31 Nov 24, 2016
a8fb346
intrinsics : uabs and iabs
est31 Nov 25, 2016
f609586
Fix warning on 64 bit
est31 Nov 26, 2016
e08e34b
Move from RUSTC_CRATES to TARGET_CRATES
est31 Nov 27, 2016
bcf7f93
40 -> 39, as ceil(log10(2^128)) == 39
est31 Nov 28, 2016
73e142e
UGLY hack around an ICE bc of stage0
est31 Dec 1, 2016
249f7b6
Always use Rust based intrinsics on Windows
est31 Dec 4, 2016
1f2ed68
Try to fix some things
est31 Dec 5, 2016
1edc590
libcompiler_builtins: don't codegen dead code call to eh_personality
est31 Dec 7, 2016
8958e7c
Remove unimplemented() function
est31 Dec 7, 2016
c004f88
Port to wrapping_* and unchecked_* operations
est31 Dec 8, 2016
93c3584
Tidy
est31 Dec 8, 2016
2175095
Windows x64 ABI requires i128 params to be passed as reference
est31 Dec 10, 2016
93ee9f5
intrinsics: try to return everything via {u,i}128ret to match LLVM
est31 Dec 12, 2016
dc57f52
Fix another windows ABI mistake
est31 Dec 14, 2016
a66b8b0
Tidy
est31 Dec 14, 2016
53925c4
Fix rebase fallout
est31 Dec 14, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Feature gate the 128 bit types
Dangling a carrot in front of a donkey.

This commit includes manual merge conflict resolution changes from a rebase by @est31.
  • Loading branch information
nagisa authored and est31 committed Dec 15, 2016

Unverified

This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
commit 002f9a1ff13e1ca7f634ecc99e3e640279d1e282
1 change: 1 addition & 0 deletions src/libcore/lib.rs
Original file line number Diff line number Diff line change
@@ -90,6 +90,7 @@
#![feature(staged_api)]
#![feature(unboxed_closures)]
#![feature(never_type)]
#![cfg_attr(not(stage0), feature(i128_type))]
#![feature(prelude_import)]

#[prelude_import]
1 change: 1 addition & 0 deletions src/librustc_i128/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(non_camel_case_types)]
#![feature(i128_type)]

#[cfg(stage0)]
pub type i128 = i64;
15 changes: 14 additions & 1 deletion src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
@@ -64,6 +64,7 @@ use syntax::ast::{FnDecl, ForeignItem, ForeignItemKind, Generics};
use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind};
use syntax::ast::{Local, Mutability, Pat, PatKind, Path};
use syntax::ast::{PathSegment, PathParameters, QSelf, TraitItemKind, TraitRef, Ty, TyKind};
use syntax::feature_gate::{emit_feature_err, GateIssue};

use syntax_pos::{Span, DUMMY_SP};
use errors::DiagnosticBuilder;
@@ -2296,8 +2297,20 @@ impl<'a> Resolver<'a> {
PathResult::Module(..) | PathResult::Failed(..)
if scope == PathScope::Lexical && (ns == TypeNS || path.len() > 1) &&
self.primitive_type_table.primitive_types.contains_key(&path[0].name) => {
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,
"i128_type", span, GateIssue::Language,
"128-bit type is unstable");

}
}
_ => {}
}
PathResolution {
base_def: Def::PrimTy(self.primitive_type_table.primitive_types[&path[0].name]),
base_def: Def::PrimTy(prim),
depth: segments.len() - 1,
}
}
7 changes: 7 additions & 0 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
@@ -1347,6 +1347,13 @@ 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,
"i128_type", sp, GateIssue::Language, "128-bit type is unstable");
}
}

for v in vs {
if let Some(ref e) = v.node.disr_expr {
check_const_with_type(ccx, e, repr_type_ty, e.id);
15 changes: 15 additions & 0 deletions src/libsyntax/feature_gate.rs
Original file line number Diff line number Diff line change
@@ -314,6 +314,9 @@ declare_features! (

// Allows #[target_feature(...)]
(active, target_feature, "1.15.0", None),

// The `i128` type
(active, i128_type, "1.15.0", Some(35118)),
);

declare_features! (
@@ -1196,6 +1199,18 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, loop_break_value, e.span,
"`break` with a value is experimental");
}
ast::ExprKind::Lit(ref lit) => {
if let ast::LitKind::Int(_, ref ty) = lit.node {
match *ty {
ast::LitIntType::Signed(ast::IntTy::I128) |
ast::LitIntType::Unsigned(ast::UintTy::U128) => {
gate_feature_post!(&self, i128_type, e.span,
"128-bit integers are not stable");
}
_ => {}
}
}
}
_ => {}
}
visit::walk_expr(self, e);
20 changes: 20 additions & 0 deletions src/test/compile-fail/i128-feature-2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
fn test1() -> i128 { //~ ERROR 128-bit type is unstable
0
}

fn test1_2() -> u128 { //~ ERROR 128-bit type is unstable
0
}

fn test3() {
let x: i128 = 0; //~ ERROR 128-bit type is unstable
}

fn test3_2() {
let x: u128 = 0; //~ ERROR 128-bit type is unstable
}

#[repr(u128)]
enum A { //~ ERROR 128-bit type is unstable
A(u64)
}
8 changes: 8 additions & 0 deletions src/test/compile-fail/i128-feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fn test2() {
0i128; //~ ERROR 128-bit integers are not stable
}

fn test2_2() {
0u128; //~ ERROR 128-bit integers are not stable
}

2 changes: 2 additions & 0 deletions src/test/run-pass/i128.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(i128_type)]

fn main() {
let x: i128 = -1;
assert_eq!(0, !x);
9 changes: 9 additions & 0 deletions src/test/run-pass/u128.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#![feature(i128_type)]

fn main() {
let x: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFF;
assert_eq!(0, !x);
assert_eq!(0, !x);
let y: u128 = 0xFFFF_FFFF_FFFF_FFFF__FFFF_FFFF_FFFF_FFFE;
assert_eq!(!1, y);
assert_eq!(x, y | 1);
assert_eq!(0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFE,
y &
0xFAFF_0000_FF8F_0000__FFFF_0000_FFFF_FFFF);
let z: u128 = 0xABCD_EF;
assert_eq!(z * z * z * z, 0x33EE_0E2A_54E2_59DA_A0E7_8E41);
assert_eq!(z + z + z + z, 0x2AF3_7BC);
@@ -13,6 +20,8 @@ fn main() {
assert_eq!(0x1000_0000_0000_0000_0000_0000_0000_000,
k - 0x234_5678_9ABC_DEFF_EDCB_A987_6543_210);
assert_eq!(0x6EF5_DE4C_D3BC_2AAA_3BB4_CC5D_D6EE_8, k / 42);
assert_eq!(0, k % 42);
assert_eq!(15, z % 42);
assert_eq!(0x91A2_B3C4_D5E6_F7, k >> 65);
assert_eq!(0xFDB9_7530_ECA8_6420_0000_0000_0000_0000, k << 65);
assert!(k > z);