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

Add a test for #32062 #4

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
60 changes: 60 additions & 0 deletions issue-32062-equality-relations-complexity/issue-32062.rs
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))
}
6 changes: 6 additions & 0 deletions issue-32062-equality-relations-complexity/makefile
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