Skip to content

Commit 4d9feea

Browse files
author
Paul Kernfeld
committed
Use build.rs instead of feature flag, fix len()
1 parent c31d24c commit 4d9feea

File tree

7 files changed

+62
-38
lines changed

7 files changed

+62
-38
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,13 @@ matrix:
7373

7474

7575
script:
76+
- cargo build
7677
- |
7778
if [ $TRAVIS_RUST_VERSION == nightly ]; then
78-
cargo build --features range128 &&
79-
cargo test -p rayon --features range128 &&
79+
cargo test -p rayon &&
8080
cargo test -p rayon-core &&
8181
cargo test -p rayon-demo &&
8282
./ci/highlander.sh
83-
else
84-
cargo build
8583
fi
8684
- |
8785
if [ -n "$RUSTFLAGS" ]; then

Cargo.toml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ categories = ["concurrency"]
1616
members = ["rayon-demo", "rayon-core", "rayon-futures"]
1717
exclude = ["ci"]
1818

19-
[features]
20-
default = []
21-
22-
range128 = []
23-
2419
[dependencies]
2520
rayon-core = { version = "1.4", path = "rayon-core" }
2621

appveyor.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,11 @@ matrix:
5151
build: false
5252

5353
test_script:
54+
- cargo build
5455
- if [%CHANNEL%]==[nightly] (
55-
cargo build --features range128 &&
56-
cargo test -p rayon --features range128 &&
56+
cargo test -p rayon &&
5757
cargo test -p rayon-core &&
5858
cargo test -p rayon-demo
59-
) else (
60-
cargo build
6159
)
6260
- if not "%RUSTFLAGS%"=="%^RUSTFLAGS%" (
6361
cargo clean &&

build.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::env;
2+
use std::io::Write;
3+
use std::process::{Command, Stdio};
4+
5+
fn main() {
6+
if probe("fn main() { 0i128; }") {
7+
println!("cargo:rustc-cfg=has_i128");
8+
}
9+
}
10+
11+
/// Test if a code snippet can be compiled
12+
fn probe(code: &str) -> bool {
13+
let rustc = env::var_os("RUSTC").unwrap_or_else(|| "rustc".into());
14+
let out_dir = env::var_os("OUT_DIR").expect("environment variable OUT_DIR");
15+
16+
let mut child = Command::new(rustc)
17+
.arg("--out-dir")
18+
.arg(out_dir)
19+
.arg("--emit=obj")
20+
.arg("-")
21+
.stdin(Stdio::piped())
22+
.spawn()
23+
.expect("rustc probe");
24+
25+
child
26+
.stdin
27+
.as_mut()
28+
.expect("rustc stdin")
29+
.write_all(code.as_bytes())
30+
.expect("write rustc stdin");
31+
32+
child.wait().expect("rustc probe").success()
33+
}

src/iter/find_first_last/test.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,15 @@ fn find_last_folder_yields_last_match() {
101101
assert_eq!(f.complete(), Some(2_i32));
102102
}
103103

104-
105104
/// Produce a parallel iterator for 0u128..10²⁷
105+
#[cfg(has_i128)]
106106
fn octillion() -> impl ParallelIterator<Item = u128> {
107+
(0u128..1_000_000_000_000_000_000_000_000_000).into_par_iter()
108+
}
109+
110+
/// Produce a parallel iterator for 0u128..10²⁷
111+
#[cfg(not(has_i128))]
112+
fn octillion() -> impl ParallelIterator<Item = u128>{
107113
(0u32..1_000_000_000)
108114
.into_par_iter()
109115
.with_max_len(1_000)
@@ -127,19 +133,6 @@ fn octillion() -> impl ParallelIterator<Item = u128> {
127133
)
128134
}
129135

130-
#[cfg(feature = "range128")]
131-
fn octillion_range128() -> impl ParallelIterator<Item = u128> {
132-
(0u128..1_000_000_000_000_000_000_000_000_000).into_par_iter()
133-
}
134-
135-
#[cfg(feature = "range128")]
136-
#[test]
137-
fn find_first_octillion() {
138-
let x = octillion_range128().find_first(|_| true);
139-
assert_eq!(x, Some(0));
140-
}
141-
142-
#[cfg(not(feature = "range128"))]
143136
#[test]
144137
fn find_first_octillion() {
145138
let x = octillion().find_first(|_| true);

src/iter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ impl<T: ParallelIterator> IntoParallelIterator for T {
14361436
/// that you can split it at arbitrary indices and draw data from
14371437
/// those points.
14381438
///
1439-
/// **Note:** Not implemented for `u64` and `i64` ranges
1439+
/// **Note:** Not implemented for `u64`, `i64`, `u128`, or `i128` ranges
14401440
pub trait IndexedParallelIterator: ParallelIterator {
14411441
/// Collects the results of the iterator into the specified
14421442
/// vector. The vector is always truncated before execution

src/range.rs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ use std::ops::Range;
2323
/// Parallel iterator over a range, implemented for all integer types.
2424
///
2525
/// **Note:** The `zip` operation requires `IndexedParallelIterator`
26-
/// which is not implemented for `u64` or `i64`.
26+
/// which is not implemented for `u64`, `i64`, `u128`, or `i128`.
2727
///
2828
/// ```
2929
/// use rayon::prelude::*;
@@ -128,12 +128,12 @@ macro_rules! indexed_range_impl {
128128
}
129129

130130
macro_rules! unindexed_range_impl {
131-
( $t:ty ) => {
131+
( $t:ty, $len_t:ty ) => {
132132
impl IterProducer<$t> {
133-
fn len(&self) -> u64 {
133+
fn len(&self) -> $len_t {
134134
let Range { start, end } = self.range;
135135
if end > start {
136-
end.wrapping_sub(start) as u64
136+
end.wrapping_sub(start) as $len_t
137137
} else {
138138
0
139139
}
@@ -185,12 +185,10 @@ indexed_range_impl!{i32}
185185
indexed_range_impl!{isize}
186186

187187
// other Range<T> with just Iterator
188-
unindexed_range_impl!{u64}
189-
unindexed_range_impl!{i64}
190-
191-
// 128-bit support uses a feature to permit rustc < 1.26
192-
#[cfg(feature = "range128")] unindexed_range_impl !{u128}
193-
#[cfg(feature = "range128")] unindexed_range_impl !{i128}
188+
unindexed_range_impl!{u64, u64}
189+
unindexed_range_impl!{i64, u64}
190+
#[cfg(has_i128)] unindexed_range_impl !{u128, u128}
191+
#[cfg(has_i128)] unindexed_range_impl !{i128, u128}
194192

195193
#[test]
196194
pub fn check_range_split_at_overflow() {
@@ -201,3 +199,12 @@ pub fn check_range_split_at_overflow() {
201199
let r2: i32 = right.range.map(|i| i as i32).sum();
202200
assert_eq!(r1 + r2, -100);
203201
}
202+
203+
#[cfg(has_i128)]
204+
#[test]
205+
pub fn test_i128_len_doesnt_overflow() {
206+
let octillion = 1_000_000_000_000_000_000_000_000_000i128;
207+
let producer = IterProducer { range: 0..octillion };
208+
209+
assert_eq!(octillion as u128, producer.len());
210+
}

0 commit comments

Comments
 (0)