Skip to content

sqlparser regression: normalizes-to impl-where clauses are nonproductive #176

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

Closed
compiler-errors opened this issue Apr 11, 2025 · 4 comments · Fixed by rust-lang/rust#139900
Assignees
Labels
A-winnowing from-crater A regression found via a crater run, not part of our test suite

Comments

@compiler-errors
Copy link
Member

compiler-errors commented Apr 11, 2025

https://crater-reports.s3.amazonaws.com/pr-133502-1/try%23fa8e241660363f48d64b66b05eea58c93ab828fb/reg/sqlparser-0.55.0/log.txt

Minimized:

fn test<T>()
where
    <Vec<T> as IntoIterator>::IntoIter: Iterator,
{
}
@compiler-errors
Copy link
Member Author

Something iffy going on with alias-relate 💀

@compiler-errors
Copy link
Member Author

compiler-errors commented Apr 11, 2025

As far as I can tell, this is the root cause:

Normalizing <Vec<T> as IntoIterator>::IntoIter assembles two candidates:

  1. The one we expect, via the impl IntoIterator for Vec<T> in libstd.
  2. The one via the blanket impl IntoIterator for T where T: Iterator. This requires proving Vec<T>: Iterator, which requires alias-relating Vec<T> and <Vec<T> as IntoIterator>::IntoIter. Doing that requires normalizing <Vec<T> as IntoIterator>::IntoIter, which is a cycle, leading to ambiguity.

@compiler-errors
Copy link
Member Author

There may be an additional layer of shenanigans going on with NestedNormalizationGoals.

@lcnr lcnr added A-winnowing from-crater A regression found via a crater run, not part of our test suite labels Apr 14, 2025
@lcnr
Copy link
Contributor

lcnr commented Apr 14, 2025

changing the root goal so that it's easier to think about:

  • Vec<T>: Iterator
    • via env <Vec<T> as IntoIterator>::IntoIter: Iterator
      • Vec<T> eq <Vec<T> as IntoIterator>::IntoIter
        • normalize <Vec<T> as IntoIterator>::IntoIter
          • via impl<I: Iterator> IntoIterator for I
            • prove where-bound Vec<T>: Iterator cycle
          • via impl<T> IntoIterator for Vec<T> ~> trivial

Clearly Vec<T>: Iterator should not hold in an empty environment and proving <Vec<T> as IntoIterator>::IntoIter: Iterator should succeed. If we were to treat this cycle as productive, and dealt with the resulting ambiguity in some way, Vec<T>: Iterator could hold. So this cycle has to be unproductive and should result in an error.

I would need to actually lower this the dictionary passing style to fully understand what's going on, but my understanding is that even though we enter the impl<I: Iterator> IntoIterator for I by normalizing to its associated item, we exit the "impl constructor" again, so this cycle is not productive.

How to actually implement this in rustc is interesting and needs some further thought :> I am done for today

@lcnr lcnr moved this from unknown to in progress in -Znext-solver=globally Apr 16, 2025
@lcnr lcnr self-assigned this Apr 16, 2025
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 16, 2025
…productive, r=compiler-errors

stepping into impls for normalization is unproductive

See the inline comment. This builds on the reasoning from rust-lang#136824 (https://gist.github.com/lcnr/c49d887bbd34f5d05c36d1cf7a1bf5a5). Fixes rust-lang/trait-system-refactor-initiative#176.

Looking at the end of the gist:
> The only ways to project out of a constructor are the following:
> - accessing an associated item, either its type or its item bounds
> - accessing super predicates

Detecting cases where we accessing the type of an associated item is easy, it's simply when we normalize. I don't yet know how to detect whether we step out of an impl by accessing item bounds. Once we also detect these cases we should be able to soundly support arbitrary coinductive traits. Luckily this does not matter for this PR :>

r? `@compiler-errors` cc `@nikomatsakis`
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 17, 2025
Rollup merge of rust-lang#139900 - lcnr:normalizes-to-where-bounds-unproductive, r=compiler-errors

stepping into impls for normalization is unproductive

See the inline comment. This builds on the reasoning from rust-lang#136824 (https://gist.github.com/lcnr/c49d887bbd34f5d05c36d1cf7a1bf5a5). Fixes rust-lang/trait-system-refactor-initiative#176.

Looking at the end of the gist:
> The only ways to project out of a constructor are the following:
> - accessing an associated item, either its type or its item bounds
> - accessing super predicates

Detecting cases where we accessing the type of an associated item is easy, it's simply when we normalize. I don't yet know how to detect whether we step out of an impl by accessing item bounds. Once we also detect these cases we should be able to soundly support arbitrary coinductive traits. Luckily this does not matter for this PR :>

r? `@compiler-errors` cc `@nikomatsakis`
@lcnr lcnr moved this from in progress to done in -Znext-solver=globally Apr 17, 2025
@lcnr lcnr closed this as completed by moving to done in -Znext-solver=globally Apr 17, 2025
@lcnr lcnr changed the title sqlparser regression sqlparser regression: normalizes-to impl-where clauses are nonproductive Apr 17, 2025
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this issue Apr 19, 2025
…e, r=compiler-errors

stepping into impls for normalization is unproductive

See the inline comment. This builds on the reasoning from #136824 (https://gist.github.com/lcnr/c49d887bbd34f5d05c36d1cf7a1bf5a5). Fixes rust-lang/trait-system-refactor-initiative#176.

Looking at the end of the gist:
> The only ways to project out of a constructor are the following:
> - accessing an associated item, either its type or its item bounds
> - accessing super predicates

Detecting cases where we accessing the type of an associated item is easy, it's simply when we normalize. I don't yet know how to detect whether we step out of an impl by accessing item bounds. Once we also detect these cases we should be able to soundly support arbitrary coinductive traits. Luckily this does not matter for this PR :>

r? `@compiler-errors` cc `@nikomatsakis`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-winnowing from-crater A regression found via a crater run, not part of our test suite
Projects
Development

Successfully merging a pull request may close this issue.

2 participants