diff --git a/issue-32062-equality-relations-complexity/issue-32062.rs b/issue-32062-equality-relations-complexity/issue-32062.rs new file mode 100644 index 000000000..fbd685864 --- /dev/null +++ b/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 or the MIT license +// , 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

(self, p: P) -> Chain where Self: Sized { + Chain(self, p) + } +} + +struct Token(T::Item) where T: Iterator; + +impl Parser for Token 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); + +impl Parser for Chain where L: Parser, R: Parser { + 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) -> Result<((), I), ()> where I: Iterator { + 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)) +} diff --git a/issue-32062-equality-relations-complexity/makefile b/issue-32062-equality-relations-complexity/makefile new file mode 100644 index 000000000..605c7061d --- /dev/null +++ b/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