Skip to content

Commit

Permalink
Add a test for #32062
Browse files Browse the repository at this point in the history
Add a test on @nikomatsakis suggestion for the improvement for equality relations implemented in rust-lang/rust#32062
  • Loading branch information
Marwes committed Mar 21, 2016
1 parent 30ea35b commit b16f0e8
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
60 changes: 60 additions & 0 deletions issue-32062-equality-relations-complexity/issue-32062.rs
@@ -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))
}
6 changes: 6 additions & 0 deletions issue-32062-equality-relations-complexity/makefile
@@ -0,0 +1,6 @@
all:
$(RUSTC) issue-32062.rs -Ztime-passes -Zinput-stats
touch:
rm hello
clean:
rm hello

0 comments on commit b16f0e8

Please sign in to comment.