-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[WIP] mgca: Add ConstArg representation for const items #139558
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
fa42f86
to
6054bd5
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ac73a4a
to
4f6c9ab
Compare
let ty = this | ||
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy)); | ||
let body = | ||
this.lower_const_item(span, body_id.unwrap(), expr.as_deref().unwrap()); |
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.
These new unwraps should be correct in theory since an error should've already been emitted, but they might ICE if the compiler didn't stop earlier. It might be a good idea to add ConstArgKind::Err and use delayed_span_bug.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
☔ The latest upstream changes (presumably #141343) made this pull request unmergeable. Please resolve the merge conflicts. |
DefKind::Const if tcx.generics_of(item_def_id).is_empty() => { | ||
let instance = ty::Instance::new_raw(item_def_id.into(), ty::GenericArgs::empty()); | ||
let cid = GlobalId { instance, promoted: None }; | ||
let typing_env = ty::TypingEnv::fully_monomorphized(); | ||
tcx.ensure_ok().eval_to_const_value_raw(typing_env.as_query_input(cid)); | ||
} |
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.
We should properly handle this before landing 🤔 don't need to care too much rn while everything is still ICEing. I expect we'll just want to update fn check_associated_item
and fn check_item
in wfcheck.rs
to handle const aliases like we do type aliases and then get rid of this codepath
/// Returns the const of the RHS of a const item. | ||
query const_of_item(def_id: DefId) -> ty::EarlyBinder<'tcx, ty::Const<'tcx>> { | ||
desc { |tcx| "computing the value for `{}`", tcx.def_path_str(def_id) } | ||
cache_on_disk_if { def_id.is_local() } | ||
separate_provide_extern | ||
} |
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.
You'll need to do some more stuff to get this separate_provide_extern to actually work. You'll probably start getting ICEs in cross crate scenarios once you're past building core. See this commit for an example of adding a separate_provide_extern query: 996a185
if let Ok(Some(Instance { def: ty::InstanceKind::Item(def_id), args })) = result | ||
&& matches!(tcx.def_kind(def_id), DefKind::Const | DefKind::AssocConst) | ||
{ |
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.
So it turns out that not all CTFE entry points actually call try_resolve
, some of them just manually construct an instance for a const item. Not sure what to do about that long term 🤔
For now though you can go through all the entry points in rustc_middle/src/mir/interpret/queries
and update everything to use Instance::expect_resolve
instead of Instance::new_raw
which should atleast solve any ICEs in the short term until we figure out how to properly handle this
@oli-obk I've assigned you to this PR alongside me because I'd definitely want you to review it before it lands since its so CTFE involved 🤔 I don't think it needs reviewing rn though, things are so up in the air and we're not bootstrapping yet :3 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
ty::AnonConstKind::MCG | ||
if matches!(parent_def_kind, DefKind::Const | DefKind::AssocConst) => | ||
{ | ||
Some(parent_did) | ||
} |
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.
This will probably make the anon const in const FOO: [u8; ...]
have generics too which is not desirable 🤔 Should look at the HIR instead to see if the parent hir node of the ConstArg
node is a const item or not. Not sure whether it makes sense to add a new variant to ty::AnonConstKind
or not, I guess it depends on whether we wind up special casing them elsewhere (e.g. HIR ty lowering).
Actually that reminds me- we should have a test about const ASSOC: usize = (N);
. It's possible that will get lowered to an anon const instead of a path (expected) and then ICE in ty lowering due to being a bare usage of a generic parameter not lowered to a path. Properly fixing this might just require changing ty lowering to not do anything fancy for anon consts used as the rhs of const items, which probably motivates adding a ty::AnonConstKind::ConstBody
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
The job Click to see the possible cause of the failure (guessed by this bot)
|
☔ The latest upstream changes (presumably #141605) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @BoxyUwU