Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
6ba494b
Point to let when modifying field of immutable variable
estebank Mar 11, 2017
38b5b29
Change label to "consider changing this to `mut f`"
estebank Mar 12, 2017
197e529
Initial attempt at implementing optimization fuel and re-enabling str…
ahicks92 Mar 8, 2017
8f36057
Make a comment better.
ahicks92 Mar 9, 2017
c2d14fc
Tests for -Z fuel=foo=n
ahicks92 Mar 10, 2017
3fb94b7
UI test for -Z print-fuel=foo
ahicks92 Mar 10, 2017
9ac628d
Add label to primary span for mutable access of immutable struct error
estebank Mar 13, 2017
460bf55
Cleanup.
jseyfried Mar 6, 2017
68c1cc6
Refactor `Attribute` to use `Path` and `TokenStream` instead of `Meta…
jseyfried Mar 3, 2017
839c286
Liberalize attributes.
jseyfried Mar 8, 2017
85e02bd
Add tests.
jseyfried Mar 8, 2017
b43c744
Add feature toggle for rvalue-static-promotion RFC
tbg Mar 11, 2017
20c0f32
Use `&&` instead of `&`
tbg Mar 12, 2017
f06b049
Improve the documentation for `rvalue_static_promotion`
tbg Mar 12, 2017
9741c9d
add test for nested macro def (#31946)
durka Mar 14, 2017
cc23d17
make shift builtins panic-free with new unchecked_sh* intrinsics
TimNN Mar 14, 2017
ff63866
Change how the `0` flag works in format!
Sawyer47 Mar 3, 2017
8065486
Change how the 0 flag works in format! for floats
Sawyer47 Mar 4, 2017
ce616a7
Improve the `TokenStream` quoter.
jseyfried Mar 14, 2017
9b89274
Fix const not displayed in rustdoc
GuillaumeGomez Mar 16, 2017
8c16c45
Check for conflicts between macros 1.0 exports (`#[macro_export]`, `#…
jseyfried Mar 14, 2017
910532e
Add a test for issue 34571
topecongiro Mar 16, 2017
449219a
isolate llvm 4.0 code path
TimNN Mar 16, 2017
222ca3c
clang-format
TimNN Mar 16, 2017
95bd7f2
add missing global metadata
TimNN Mar 16, 2017
50cede0
documented order of conversion between u32 an ipv4addr
Mar 17, 2017
0b9d83c
Represent function pointers in mir-constants as a Value instead of Item
oli-obk Mar 7, 2017
187a922
Remove zst hacks
oli-obk Mar 17, 2017
963d4df
minor wording tweak to slice::{as_ptr, as_mut_ptr}
QuietMisdreavus Mar 17, 2017
ec8ecf4
Fix typo in mutex.rs docs
ScottAbbey Mar 17, 2017
33a5665
Stabilize move_cell feature, closes #39264
aturon Mar 15, 2017
65b7c4e
Stabilize expect_err feature, closes #39041
aturon Mar 15, 2017
d38ea8b
Stabilize ptr_unaligned feature, closes #37955
aturon Mar 15, 2017
9511fe6
Stabilize process_abort feature, closes #37838
aturon Mar 15, 2017
10510ae
Stabilize ptr_eq feature, closes #36497
aturon Mar 15, 2017
37b38a2
Stabilize btree_range, closes #27787
aturon Mar 15, 2017
48890d4
Stabilize ordering_chaining, closes #37053
aturon Mar 15, 2017
a8f4a1b
Stabilize rc_raw feature, closes #37197
aturon Mar 15, 2017
1241a88
Minor fixups to fix tidy errors
alexcrichton Mar 15, 2017
27fcdb8
Specialize Vec::from_elem<u8> to use calloc or memset
mbrubeck Mar 10, 2017
ae630ca
Specialize Vec::from_elem for other integer types
mbrubeck Mar 10, 2017
cb96ade
Fix regression when `include!()`ing a `macro_rules!` containing a `$c…
jseyfried Mar 16, 2017
2976ddb
Fix a spelling error in HashMap documentation, and slightly reword it…
jswalden Mar 18, 2017
8eaac08
Parse 0e+10 as a valid floating-point literal
topecongiro Mar 17, 2017
e16d286
add inline attributes to stage 0 methods
TimNN Mar 18, 2017
251f8a8
Rollup merge of #40241 - Sawyer47:fix-39997, r=alexcrichton
Mar 19, 2017
e9c1c0c
Rollup merge of #40346 - jseyfried:path_and_tokenstream_attr, r=nrc
Mar 19, 2017
3a128fc
Rollup merge of #40377 - camlorn:optimization_fuel, r=arielb1
Mar 19, 2017
d242407
Rollup merge of #40409 - mbrubeck:calloc, r=sfackler
Mar 19, 2017
17e0c8b
Rollup merge of #40441 - tschottdorf:promotable-rfc, r=eddyb
Mar 19, 2017
99ade10
Rollup merge of #40445 - estebank:issue-18150, r=jonathandturner
Mar 19, 2017
65e697b
Rollup merge of #40509 - jseyfried:duplicate_check_macro_exports, r=nrc
Mar 19, 2017
e3cd41a
Rollup merge of #40521 - TimNN:panic-free-shift, r=alexcrichton
Mar 19, 2017
c9b7a9e
Rollup merge of #40523 - durka:patch-38, r=petrochenkov
Mar 19, 2017
584f1b6
Rollup merge of #40532 - jseyfried:improve_tokenstream_quoter, r=nrc
Mar 19, 2017
eef8130
Rollup merge of #40538 - aturon:stab-1.17, r=alexcrichton
Mar 19, 2017
c3e8ca1
Rollup merge of #40564 - GuillaumeGomez:rustdoc-const, r=frewsxcv
Mar 19, 2017
878b9b5
Rollup merge of #40581 - TimNN:di-global-40, r=alexcrichton
Mar 19, 2017
9e36496
Rollup merge of #40583 - jseyfried:fix_include_macro_regression, r=nrc
Mar 19, 2017
5ffec58
Rollup merge of #40588 - topecongiro:add-missing-tests, r=alexcrichton
Mar 19, 2017
d3e5a45
Rollup merge of #40589 - topecongiro:floating-point-literal, r=nagisa
Mar 19, 2017
c1a864d
Rollup merge of #40590 - z1mvader:master, r=steveklabnik
Mar 19, 2017
0d904ce
Rollup merge of #40602 - oli-obk:fn_const, r=eddyb
Mar 19, 2017
9fa91f4
Rollup merge of #40603 - QuietMisdreavus:slice-ptr-docs, r=GuillaumeG…
Mar 19, 2017
37b9514
Rollup merge of #40611 - ScottAbbey:patch-1, r=GuillaumeGomez
Mar 19, 2017
f2d0a1d
Rollup merge of #40621 - jswalden:dependant-spelling-fix, r=sfackler
Mar 19, 2017
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
18 changes: 9 additions & 9 deletions src/libcompiler_builtins/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub mod reimpls {
macro_rules! ashl {
($a:expr, $b:expr, $ty:ty) => {{
let (a, b) = ($a, $b);
let bits = (::core::mem::size_of::<$ty>() * 8) as $ty;
let half_bits = bits >> 1;
let bits = ::core::mem::size_of::<$ty>().wrapping_mul(8) as $ty;
let half_bits = bits.wrapping_shr(1);
if b & half_bits != 0 {
<$ty>::from_parts(0, a.low().wrapping_shl(
b.wrapping_sub(half_bits) as u32))
Expand All @@ -58,8 +58,8 @@ pub mod reimpls {
macro_rules! ashr {
($a: expr, $b: expr, $ty:ty) => {{
let (a, b) = ($a, $b);
let bits = (::core::mem::size_of::<$ty>() * 8) as $ty;
let half_bits = bits >> 1;
let bits = ::core::mem::size_of::<$ty>().wrapping_mul(8) as $ty;
let half_bits = bits.wrapping_shr(1);
if b & half_bits != 0 {
<$ty>::from_parts(a.high().wrapping_shr(b.wrapping_sub(half_bits) as u32)
as <$ty as LargeInt>::LowHalf,
Expand All @@ -83,8 +83,8 @@ pub mod reimpls {
macro_rules! lshr {
($a: expr, $b: expr, $ty:ty) => {{
let (a, b) = ($a, $b);
let bits = (::core::mem::size_of::<$ty>() * 8) as $ty;
let half_bits = bits >> 1;
let bits = ::core::mem::size_of::<$ty>().wrapping_mul(8) as $ty;
let half_bits = bits.wrapping_shr(1);
if b & half_bits != 0 {
<$ty>::from_parts(a.high().wrapping_shr(b.wrapping_sub(half_bits) as u32), 0)
} else if b == 0 {
Expand Down Expand Up @@ -370,7 +370,7 @@ pub mod reimpls {
macro_rules! mul {
($a:expr, $b:expr, $ty: ty, $tyh: ty) => {{
let (a, b) = ($a, $b);
let half_bits = ((::core::mem::size_of::<$tyh>() * 8) / 2) as u32;
let half_bits = ::core::mem::size_of::<$tyh>().wrapping_mul(4) as u32;
let lower_mask = (!0u64).wrapping_shr(half_bits);
let mut low = (a.low() & lower_mask).wrapping_mul(b.low() & lower_mask);
let mut t = low.wrapping_shr(half_bits);
Expand Down Expand Up @@ -478,7 +478,7 @@ pub mod reimpls {
let mantissa_fraction = repr & <$fromty as FloatStuff>::MANTISSA_MASK;
let mantissa = mantissa_fraction | <$fromty as FloatStuff>::MANTISSA_LEAD_BIT;
if sign == -1.0 || exponent < 0 { return 0 as u128; }
if exponent > ::core::mem::size_of::<$outty>() as i32 * 8 {
if exponent > ::core::mem::size_of::<$outty>().wrapping_mul(8) as i32 {
return !(0 as u128);
}
(if exponent < (<$fromty as FloatStuff>::MANTISSA_BITS) as i32 {
Expand All @@ -503,7 +503,7 @@ pub mod reimpls {
let mantissa = mantissa_fraction | <$fromty as FloatStuff>::MANTISSA_LEAD_BIT;

if exponent < 0 { return 0 as i128; }
if exponent > ::core::mem::size_of::<$outty>() as i32 * 8 {
if exponent > ::core::mem::size_of::<$outty>().wrapping_mul(8) as i32 {
let ret = if sign > 0.0 { <$outty>::max_value() } else { <$outty>::min_value() };
return ret
}
Expand Down
9 changes: 9 additions & 0 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,15 @@ extern "rust-intrinsic" {
/// undefined behavior where y = 0 or x = `T::min_value()` and y = -1
pub fn unchecked_rem<T>(x: T, y: T) -> T;

/// Performs an unchecked left shift, resulting in undefined behavior when
/// y < 0 or y >= N, where N is the width of T in bits.
#[cfg(not(stage0))]
pub fn unchecked_shl<T>(x: T, y: T) -> T;
/// Performs an unchecked right shift, resulting in undefined behavior when
/// y < 0 or y >= N, where N is the width of T in bits.
#[cfg(not(stage0))]
pub fn unchecked_shr<T>(x: T, y: T) -> T;

/// Returns (a + b) mod 2^N, where N is the width of T in bits.
/// The stabilized versions of this intrinsic are available on the integer
/// primitives via the `wrapping_add` method. For example,
Expand Down
117 changes: 99 additions & 18 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ macro_rules! checked_op {

// `Int` + `SignedInt` implemented for signed integers
macro_rules! int_impl {
($ActualT:ident, $UnsignedT:ty, $BITS:expr,
($SelfT:ty, $ActualT:ident, $UnsignedT:ty, $BITS:expr,
$add_with_overflow:path,
$sub_with_overflow:path,
$mul_with_overflow:path) => {
Expand Down Expand Up @@ -850,6 +850,17 @@ macro_rules! int_impl {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(not(stage0))]
pub fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
}
}

/// Stage 0
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(stage0)]
pub fn wrapping_shl(self, rhs: u32) -> Self {
self.overflowing_shl(rhs).0
}
Expand All @@ -875,6 +886,17 @@ macro_rules! int_impl {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(not(stage0))]
pub fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
}
}

/// Stage 0
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(stage0)]
pub fn wrapping_shr(self, rhs: u32) -> Self {
self.overflowing_shr(rhs).0
}
Expand Down Expand Up @@ -1089,6 +1111,15 @@ macro_rules! int_impl {
/// ```
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(not(stage0))]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
}

/// Stage 0
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(stage0)]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self << (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
Expand All @@ -1111,6 +1142,15 @@ macro_rules! int_impl {
/// ```
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(not(stage0))]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))
}

/// Stage 0
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(stage0)]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
Expand Down Expand Up @@ -1268,39 +1308,39 @@ macro_rules! int_impl {

#[lang = "i8"]
impl i8 {
int_impl! { i8, u8, 8,
int_impl! { i8, i8, u8, 8,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
}

#[lang = "i16"]
impl i16 {
int_impl! { i16, u16, 16,
int_impl! { i16, i16, u16, 16,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
}

#[lang = "i32"]
impl i32 {
int_impl! { i32, u32, 32,
int_impl! { i32, i32, u32, 32,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
}

#[lang = "i64"]
impl i64 {
int_impl! { i64, u64, 64,
int_impl! { i64, i64, u64, 64,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
}

#[lang = "i128"]
impl i128 {
int_impl! { i128, u128, 128,
int_impl! { i128, i128, u128, 128,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
Expand All @@ -1309,7 +1349,7 @@ impl i128 {
#[cfg(target_pointer_width = "16")]
#[lang = "isize"]
impl isize {
int_impl! { i16, u16, 16,
int_impl! { isize, i16, u16, 16,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
Expand All @@ -1318,7 +1358,7 @@ impl isize {
#[cfg(target_pointer_width = "32")]
#[lang = "isize"]
impl isize {
int_impl! { i32, u32, 32,
int_impl! { isize, i32, u32, 32,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
Expand All @@ -1327,15 +1367,15 @@ impl isize {
#[cfg(target_pointer_width = "64")]
#[lang = "isize"]
impl isize {
int_impl! { i64, u64, 64,
int_impl! { isize, i64, u64, 64,
intrinsics::add_with_overflow,
intrinsics::sub_with_overflow,
intrinsics::mul_with_overflow }
}

// `Int` + `UnsignedInt` implemented for unsigned integers
macro_rules! uint_impl {
($ActualT:ty, $BITS:expr,
($SelfT:ty, $ActualT:ty, $BITS:expr,
$ctpop:path,
$ctlz:path,
$cttz:path,
Expand Down Expand Up @@ -1978,6 +2018,17 @@ macro_rules! uint_impl {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(not(stage0))]
pub fn wrapping_shl(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shl(self, (rhs & ($BITS - 1)) as $SelfT)
}
}

/// Stage 0
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(stage0)]
pub fn wrapping_shl(self, rhs: u32) -> Self {
self.overflowing_shl(rhs).0
}
Expand All @@ -2003,6 +2054,17 @@ macro_rules! uint_impl {
/// ```
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(not(stage0))]
pub fn wrapping_shr(self, rhs: u32) -> Self {
unsafe {
intrinsics::unchecked_shr(self, (rhs & ($BITS - 1)) as $SelfT)
}
}

/// Stage 0
#[stable(feature = "num_wrapping", since = "1.2.0")]
#[inline(always)]
#[cfg(stage0)]
pub fn wrapping_shr(self, rhs: u32) -> Self {
self.overflowing_shr(rhs).0
}
Expand Down Expand Up @@ -2170,6 +2232,15 @@ macro_rules! uint_impl {
/// ```
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(not(stage0))]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shl(rhs), (rhs > ($BITS - 1)))
}

/// Stage 0
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(stage0)]
pub fn overflowing_shl(self, rhs: u32) -> (Self, bool) {
(self << (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
Expand All @@ -2192,6 +2263,16 @@ macro_rules! uint_impl {
/// ```
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(not(stage0))]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self.wrapping_shr(rhs), (rhs > ($BITS - 1)))

}

/// Stage 0
#[inline]
#[stable(feature = "wrapping", since = "1.7.0")]
#[cfg(stage0)]
pub fn overflowing_shr(self, rhs: u32) -> (Self, bool) {
(self >> (rhs & ($BITS - 1)), (rhs > ($BITS - 1)))
}
Expand Down Expand Up @@ -2292,7 +2373,7 @@ macro_rules! uint_impl {

#[lang = "u8"]
impl u8 {
uint_impl! { u8, 8,
uint_impl! { u8, u8, 8,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2304,7 +2385,7 @@ impl u8 {

#[lang = "u16"]
impl u16 {
uint_impl! { u16, 16,
uint_impl! { u16, u16, 16,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2316,7 +2397,7 @@ impl u16 {

#[lang = "u32"]
impl u32 {
uint_impl! { u32, 32,
uint_impl! { u32, u32, 32,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2328,7 +2409,7 @@ impl u32 {

#[lang = "u64"]
impl u64 {
uint_impl! { u64, 64,
uint_impl! { u64, u64, 64,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2340,7 +2421,7 @@ impl u64 {

#[lang = "u128"]
impl u128 {
uint_impl! { u128, 128,
uint_impl! { u128, u128, 128,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2353,7 +2434,7 @@ impl u128 {
#[cfg(target_pointer_width = "16")]
#[lang = "usize"]
impl usize {
uint_impl! { u16, 16,
uint_impl! { usize, u16, 16,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2365,7 +2446,7 @@ impl usize {
#[cfg(target_pointer_width = "32")]
#[lang = "usize"]
impl usize {
uint_impl! { u32, 32,
uint_impl! { usize, u32, 32,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand All @@ -2378,7 +2459,7 @@ impl usize {
#[cfg(target_pointer_width = "64")]
#[lang = "usize"]
impl usize {
uint_impl! { u64, 64,
uint_impl! { usize, u64, 64,
intrinsics::ctpop,
intrinsics::ctlz,
intrinsics::cttz,
Expand Down
9 changes: 8 additions & 1 deletion src/librustc_trans/intrinsic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
"ctlz" | "cttz" | "ctpop" | "bswap" |
"add_with_overflow" | "sub_with_overflow" | "mul_with_overflow" |
"overflowing_add" | "overflowing_sub" | "overflowing_mul" |
"unchecked_div" | "unchecked_rem" => {
"unchecked_div" | "unchecked_rem" | "unchecked_shl" | "unchecked_shr" => {
let sty = &arg_tys[0].sty;
match int_type_width_signed(sty, ccx) {
Some((width, signed)) =>
Expand Down Expand Up @@ -311,6 +311,13 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
} else {
bcx.urem(llargs[0], llargs[1])
},
"unchecked_shl" => bcx.shl(llargs[0], llargs[1]),
"unchecked_shr" =>
if signed {
bcx.ashr(llargs[0], llargs[1])
} else {
bcx.lshr(llargs[0], llargs[1])
},
_ => bug!(),
},
None => {
Expand Down
Loading