-
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
make default anon const substs optional #83086
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this actually used anywhere here? Or are you doing that in a followup PR? I'm just curious if there's a better way. But I think this makes sense and should be fine.
/// Supplies the `tcx` for an unevaluated anonymous constant in case its default substs | ||
/// are not yet supplied. | ||
/// | ||
/// Visitors which do not look into these substs may leave this unimplemented, so be | ||
/// careful when calling this method elsewhere. | ||
fn tcx_for_anon_const_substs<'a>(&'a self) -> TyCtxt<'tcx>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a significant downside to just making this tcx(&self)
and always requiring it? Is there any place we have a TypeVisitor
but no tcx?
I also think that it's perhaps a bit nice to just have this be tcx
and return an Option<TyCtxt<'tcx>>
, then were it's used, we can just expect
. But given the option, I think it's better to just always require a TyCtxt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the reason I went for tcx_for_anon_const_substs
is that I don't want to modify all the type flags stuff, because that would be a far bigger change.
Using Option<TyCtxt<'tcx>>
seems ok though I would probably still keep the long name 🤔
Using None
incorrectly would cause some fairly bad issues in the future
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would you have to modify the type flags stuff to just add a function? Also, where are you expecting to use this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i want to use this function to get the default anon const substs once these are lazily computed.
making tcx
obligatory means that we have to modify stuff like needs_subst
to take a TyCtxt
, which is a more invasive change and shouldn't be needed.
i now think that merging this PR as is isn't really helpful, going to mark as a draft again and keep pushing the const substs changes to this PR as well 🤔 |
tcx
for TypeVisitor
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #82936) made this pull request unmergeable. Please resolve the merge conflicts. |
don't have the capacity to work on this rn |
…r=nikomatsakis lazily "compute" anon const default substs Continuing the work of rust-lang#83086, this implements the discussed solution for the [unused substs problem](https://github.com/rust-lang/project-const-generics/blob/master/design-docs/anon-const-substs.md#unused-substs). As of now, anonymous constants inherit all of their parents generics, even if they do not use them, e.g. in `fn foo<T, const N: usize>() -> [T; N + 1]`, the array length has `T` as a generic parameter even though it doesn't use it. These *unused substs* cause some backwards incompatible, and imo incorrect behavior, e.g. rust-lang#78369. --- We do not actually filter any generic parameters here and the `default_anon_const_substs` query still a dummy which only checks that - we now prevent the previously existing query cycles and are able to call `predicates_of(parent)` when computing the substs of anonymous constants - the default anon consts substs only include the typeflags we assume it does. Implementing that filtering will be left as future work. --- The idea of this PR is to delay the creation of the anon const substs until after we've computed `predicates_of` for the parent of the anon const. As the predicates of the parent can however contain the anon const we still have to create a `ty::Const` for it. We do this by changing the substs field of `ty::Unevaluated` to an option and modifying accesses to instead call the method `unevaluated.substs(tcx)` which returns the substs as before. If the substs - now `substs_` - of `ty::Unevaluated` are `None`, it means that the anon const currently has its default substs, i.e. the substs it has when first constructed, which are the generic parameters it has available. To be able to call `unevaluated.substs(tcx)` in a `TypeVisitor`, we add the non-defaulted method `fn tcx_for_anon_const_substs(&self) -> Option<TyCtxt<'tcx>>`. In case `tcx_for_anon_const_substs` returns `None`, unknown anon const default substs are skipped entirely. Even when `substs_` is `None` we still have to treat the constant as if it has its default substs. To do this, `TypeFlags` are modified so that it is clear whether they can still change when *exposing* any anon const default substs. A new flag, `HAS_UNKNOWN_DEFAULT_CONST_SUBSTS`, is added in case some default flags are missing. The rest of this PR are some smaller changes to either not cause cycles by trying to access the default anon const substs too early or to be able to access the `tcx` in previously unused locations. cc `@rust-lang/project-const-generics` r? `@nikomatsakis`
this description is currently outdated
This is the least invasive way I could think of to get a
tcx
into thesuper_visit_with
impl for consts.Needed to deal with unused substs for anonymous constants. Note that
tcx_for_anon_const_substs
isn't actually used anywhere yet. Not sure whether it makes sense to merge this PR without actually implementing the optional const substs 😅More info can be found in the meeting notes and on zulip
r? @nikomatsakis cc @oli-obk