|
| 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 | +} |
0 commit comments