Support DefKind::InlineConst in ConstKind::Unevaluated#158375
Conversation
|
HIR ty lowering was modified cc @fmease Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
| @@ -508,11 +490,9 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> { | |||
There was a problem hiding this comment.
all of this can be yeeten i think. this was all just to avoid the with_const_arg call below
There was a problem hiding this comment.
big yeeten! I also refactored this a bit to clean it up now that we don't need to do with_const_arg crimes (probably easier to read the new version in standalone mode, rather than looking at the diff)
| .create_def(constant.id, None, DefKind::InlineConst, constant.value.span) | ||
| .def_id(); | ||
| self.with_parent(def, |this| visit::walk_anon_const(this, constant)); | ||
| return; |
There was a problem hiding this comment.
| return; | |
| self | |
| .create_def(constant.id, None, DefKind::InlineConst, constant.value.span) | |
| .def_id() |
now that we're not doing a manual with_const_arg call should just be able to let this fall through to the catch all logic at the end of the function
| ) -> V::Result { | ||
| let kind = tcx.def_kind(item); | ||
| trace!(?kind); | ||
| let mut visit_alias = || { |
There was a problem hiding this comment.
| let mut visit_alias = || { | |
| let mut visit_anon_const = || { |
There was a problem hiding this comment.
hmm? this is called by TyAlias, AssocTy, Static, Const, AssocConst, AnonConst, and InlineConst, not just AnonConst and InlineConst. (heck if I know a good name for that category of things, though)
There was a problem hiding this comment.
oh nvm then, yeah I didn't see the other bits because of github diff hiding 😅
This comment has been minimized.
This comment has been minimized.
a238c1d to
013f793
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Looked through them all! Went through them all again just now to be sure. Here's a list of things that might be notable for you (to double check my looking-through-them-all):
@rustbot ready (except you didn't do rustbot author :P) |
013f793 to
4a41270
Compare
|
Updated with the stuff I was unsure of in the previous comment. Also moved a comment that was wonkily placed IMO (due to #158360 ) |
There was a problem hiding this comment.
I had a question about the expected invariant here. Does this mean that if we have an InlineConst which is not a type-system inline const, its typeck root is expected to always be an AnonConst?
I was wondering about a nested case where an InlineConst appears inside another InlineConst, and the outer InlineConst is directly under a ConstArg. For example, with the changes here, something like Struct<{ (some, stuff, const { const { hi } }) }> seems like it would be represented roughly as Tuple(some, stuff, InlineConst(InlineConst(hi))).
My understanding is that the outer InlineConst would be the type-system const argument, because it is directly under ConstArg, while the inner InlineConst would not be type-system and would just be an inline const expression inside the outer const body. Now, if we walk from inner to outer, we would stop at the outer inline node, as its the typeck root, but here we would return None which would mean we are not in context arg context I guess? or should nested children of a type-system inline const still be considered to be under the const-arg context? Newbie question, I might be misunderstandIng something.
There was a problem hiding this comment.
Oh. Yes. You're almost certainly correct this PR is incorrect, but, uuuh, hmm, this currently ICEs on main:
#![feature(min_generic_const_args)]
struct S<const N: usize>;
fn foo<const N: usize>(_: S<{ const { const { N } } }>) {}There was a problem hiding this comment.
ok, got a repro that doesn't ICE on main, that fails with the code in this PR before a fix (due to the issue you pointed out), that succeeds after my latest push. Added that repro as a test in my latest push as well. Thanks for pointing this out!
I think the ICE on main is totally unrelated, will look into it later.
4a41270 to
f31f522
Compare
fixes rust-lang/project-const-generics#101
required for rust-lang/project-const-generics#108
consider:
Struct<{ (some, stuff, const { hi }) }>. The following is very pseudocode-y, the important parts are whether it says AnonConst or InlineConst, not the Tuple stuffAnonConst(Tuple(some, stuff, InlineConst(hi)))Tuple(some, stuff, AnonConst(hi)). The inner InlineConst got intercepted in the def_collector with hacks (ConstArgContext) and converted into an AnonConst, even though it has inline const syntax.It would be nice to keep it as an InlineConst under mGCA, i.e.
Tuple(some, stuff, InlineConst(hi)), and have the type system support passing around InlineConsts inConstKind::Unevaluated(soon to be renamedConstKind::Alias). This would allow the def collector to not need to know if we are in a "direct" or "regular/anon" context, which it turns out is extremely useful for implementing rust-lang/project-const-generics#108. Supporting InlineConsts in the type system are also useful for other things, for example, mentioned in rust-lang/project-const-generics#101 is arg position const generics experiments.This PR does two things:
ConstKind::Unevaluated)r? @BoxyUwU