Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit 283b068

Browse files
committed
Merge pull request #4 from Marwes/issue-32062
Add a test for #32062
2 parents 30ea35b + b16f0e8 commit 283b068

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This tests rustc performance when a large amount variables are created which all have equality
12+
// relations between them. With #32062 merged there should no longer be an exponentationl time
13+
// complexity for this test.
14+
15+
fn main() {
16+
let _ = test(Some(0).into_iter());
17+
}
18+
19+
trait Parser {
20+
type Input: Iterator;
21+
type Output;
22+
fn parse(self, input: Self::Input) -> Result<(Self::Output, Self::Input), ()>;
23+
fn chain<P>(self, p: P) -> Chain<Self, P> where Self: Sized {
24+
Chain(self, p)
25+
}
26+
}
27+
28+
struct Token<T>(T::Item) where T: Iterator;
29+
30+
impl<T> Parser for Token<T> where T: Iterator {
31+
type Input = T;
32+
type Output = T::Item;
33+
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> {
34+
Err(())
35+
}
36+
}
37+
38+
struct Chain<L, R>(L, R);
39+
40+
impl<L, R> Parser for Chain<L, R> where L: Parser, R: Parser<Input = L::Input> {
41+
type Input = L::Input;
42+
type Output = (L::Output, R::Output);
43+
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> {
44+
Err(())
45+
}
46+
}
47+
48+
fn test<I>(i: I) -> Result<((), I), ()> where I: Iterator<Item = i32> {
49+
Chain(Token(0), Token(1))
50+
.chain(Chain(Token(0), Token(1)))
51+
.chain(Chain(Token(0), Token(1)))
52+
.chain(Chain(Token(0), Token(1)))
53+
.chain(Chain(Token(0), Token(1)))
54+
.chain(Chain(Token(0), Token(1)))
55+
.chain(Chain(Token(0), Token(1)))
56+
.chain(Chain(Token(0), Token(1)))
57+
.chain(Chain(Token(0), Token(1)))
58+
.parse(i)
59+
.map(|(_, i)| ((), i))
60+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
all:
2+
$(RUSTC) issue-32062.rs -Ztime-passes -Zinput-stats
3+
touch:
4+
rm hello
5+
clean:
6+
rm hello

0 commit comments

Comments
 (0)