-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exponential trait selection when compiling a crate using combine 4 #68666
Comments
The |
This is btw the same function as in #67454, just that with combine 3 this works fine again now while with combine 4 it exposes the same behaviour |
I tagged it |
Minimized, add more use std::marker::PhantomData;
pub trait Parser<Input> {
type Output;
fn or<P2>(self, p: P2) -> Or<Self, P2>
where
Self: Sized,
P2: Parser<Input, Output = Self::Output>,
{
Or(self, p)
}
}
#[macro_export]
macro_rules! choice {
($first : expr) => {
$first
};
($first : expr, $($rest : expr),+) => {
$first.or(choice!($($rest),+))
}
}
pub struct Or<P1, P2>(P1, P2);
impl<Input, P1, P2> Parser<Input> for Or<P1, P2>
where
P1: Parser<Input, Output = P2::Output>,
P2: Parser<Input>,
{
type Output = P2::Output;
}
pub struct P<I, O>(PhantomData<fn(I) -> O>);
impl<Input, O> Parser<Input> for P<Input, O> {
type Output = O;
}
pub fn token<I>(_: u8) -> impl Parser<I, Output = u8> {
P(PhantomData)
}
fn mcc_payload_item<I>() -> impl Parser<I, Output = u8> {
choice!(
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G'),
token(b'G')
)
}
fn main() {} |
No, this isn't fixed by #67471 . This is a separate issue (even if the reproductions are really similar). |
Ok, sorry for the confusion. Just to clarify: there is no rustc regression involved here, right? |
No, i looked back a few versions and it was always slow. |
I increased the size of the benchmark from 16 tokens to 19 and did some profiling.
The length of Worst of all, the length of at least one
I.e. the length of this I printed out the predicates being added, there are a lot (786k) of these ones:
I don't really understand the predicate stuff, but maybe @nikomatsakis has some thoughts about this? |
@nnethercote Got a big PR in the works which rewrites most of |
Seeing what looks like this issue in futures heavy code as well (in two different projects). Root issue is that there are just too many obligations generated, nothing can be done to |
Originally reported in Marwes/combine#284 . It appears that the changes made between version 3 and 4 in https://github.com/Marwes/combine . Made trait selection exponential in some cases. The main change that I would suspect causing this is that combine-3 had
Input
as an associated type whereas combine-4 uses a type parameter.The following minimized repo reproduces the slowdown, removing a few arguments from the
choice!
macro makes it compile quickly https://github.com/Marwes/combine-slow-compile . The commit beforemaster
contains a version with combine-3 which compiles instantaneously (after dependencies are compiled). (diff Marwes/combine-slow-compile@21cf38a)The text was updated successfully, but these errors were encountered: