This repository has been archived by the owner on Nov 21, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from Marwes/issue-32062
Add a test for #32062
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// This tests rustc performance when a large amount variables are created which all have equality | ||
// relations between them. With #32062 merged there should no longer be an exponentationl time | ||
// complexity for this test. | ||
|
||
fn main() { | ||
let _ = test(Some(0).into_iter()); | ||
} | ||
|
||
trait Parser { | ||
type Input: Iterator; | ||
type Output; | ||
fn parse(self, input: Self::Input) -> Result<(Self::Output, Self::Input), ()>; | ||
fn chain<P>(self, p: P) -> Chain<Self, P> where Self: Sized { | ||
Chain(self, p) | ||
} | ||
} | ||
|
||
struct Token<T>(T::Item) where T: Iterator; | ||
|
||
impl<T> Parser for Token<T> where T: Iterator { | ||
type Input = T; | ||
type Output = T::Item; | ||
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> { | ||
Err(()) | ||
} | ||
} | ||
|
||
struct Chain<L, R>(L, R); | ||
|
||
impl<L, R> Parser for Chain<L, R> where L: Parser, R: Parser<Input = L::Input> { | ||
type Input = L::Input; | ||
type Output = (L::Output, R::Output); | ||
fn parse(self, _input: Self::Input) -> Result<(Self::Output, Self::Input), ()> { | ||
Err(()) | ||
} | ||
} | ||
|
||
fn test<I>(i: I) -> Result<((), I), ()> where I: Iterator<Item = i32> { | ||
Chain(Token(0), Token(1)) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.chain(Chain(Token(0), Token(1))) | ||
.parse(i) | ||
.map(|(_, i)| ((), i)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
all: | ||
$(RUSTC) issue-32062.rs -Ztime-passes -Zinput-stats | ||
touch: | ||
rm hello | ||
clean: | ||
rm hello |