Skip to content
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

Make sure generic parameters can be unordered internally #61334

Closed
varkor opened this issue May 29, 2019 · 2 comments
Closed

Make sure generic parameters can be unordered internally #61334

varkor opened this issue May 29, 2019 · 2 comments
Labels
C-bug Category: This is a bug. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@varkor
Copy link
Member

varkor commented May 29, 2019

Although we currently require generic parameters to be ordered — lifetimes, types, consts — internally there should be no such restriction (other than the error message). However, currently we also require generic parameters to be ordered this way internally. This has caused issues in the past, for example:

// FIXME(const_generics): we shouldn't have to abort here at all, but we currently get ICEs
// if we don't. Const parameters and type parameters can currently conflict if they
// are out-of-order.
if !out_of_order.is_empty() && found_type && found_const {
FatalError.raise();
}

and #61333. Requiring ordering causes pain points like these, without making anything easier to deal with.

The compiler has got better at handling these now that all parameters are stored in a single vector, but they still need to be ordered in some locations. To fix this, it's probably simplest to add a feature gate unordered_generic_params which disables the order check and trace exactly what requires the parameters to be sorted, removing those restrictions. The feature flag will allow us to add regression tests.

@varkor varkor added the C-cleanup Category: PRs that clean code up or issues documenting cleanup. label May 29, 2019
@Centril Centril added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels May 30, 2019
@petrochenkov
Copy link
Contributor

There are some language implications with lifetimes.

Lifetime arguments in foo<'a, 'b, T, U> can be elided and inferred independently from type arguments - foo<T, U>, so with unordered generics it would technically look like an "expected a lifetime argument, found a type argument" error.
This needs to continue working somehow.

@varkor
Copy link
Member Author

varkor commented Feb 10, 2021

I believe the compiler supports generic parameters in any order now, though the restriction is still enforced for now.

@varkor varkor closed this as completed Feb 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants