diff options
| author | bors <bors@rust-lang.org> | 2016-03-21 16:00:08 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-03-21 16:00:08 -0700 |
| commit | 21922e1f48b263b39498cfeec79c1ca3f5886efe (patch) | |
| tree | 091cf922ad764cc1bc19a2910b16d0abd82691e5 /src/test | |
| parent | 0168dc7c5904701983c280cb4fa0fb0c0fa692c5 (diff) | |
| parent | e00cdd73456a3258e317bf68f8fa3a26c9922deb (diff) | |
| download | rust-21922e1f48b263b39498cfeec79c1ca3f5886efe.tar.gz rust-21922e1f48b263b39498cfeec79c1ca3f5886efe.zip | |
Auto merge of #32062 - Marwes:unification_table_for_eq_relations, r=nikomatsakis
Improve time complexity of equality relations This PR adds a `UnificationTable` to the `TypeVariableTable` type which is used store information about variable equality instead of just storing them in a vector for later processing. By using a `UnificationTable` equality relations can be resolved in O(n) (for all realistic values of n) rather than O(n!) which can give massive speedups in certain cases (see combine as an example). Link to combine: https://github.com/Marwes/combine
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/run-pass/bench/issue-32062.rs | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/test/run-pass/bench/issue-32062.rs b/src/test/run-pass/bench/issue-32062.rs new file mode 100644 index 00000000000..8f6457d820a --- /dev/null +++ b/src/test/run-pass/bench/issue-32062.rs @@ -0,0 +1,58 @@ +// 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. + +// pretty-expanded FIXME #23616 + +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)) +} |
