Skip to content

[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

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

camelid
Copy link
Member

@camelid camelid commented Apr 8, 2025

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Apr 8, 2025
@camelid camelid added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 8, 2025
@rust-log-analyzer

This comment has been minimized.

@camelid camelid force-pushed the mgca-const-items branch from fa42f86 to 6054bd5 Compare April 9, 2025 16:14
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

let ty = this
.lower_ty(ty, ImplTraitContext::Disallowed(ImplTraitPosition::ConstTy));
let body =
this.lower_const_item(span, body_id.unwrap(), expr.as_deref().unwrap());
Copy link
Member Author

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.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid force-pushed the mgca-const-items branch from 4f6c9ab to a46aa4c Compare May 15, 2025 12:37
@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label May 15, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid added A-const-generics Area: const generics (parameters and arguments) F-min_generic_const_args `#![feature(min_generic_const_args)]` labels May 17, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Collaborator

bors commented May 21, 2025

☔ The latest upstream changes (presumably #141343) made this pull request unmergeable. Please resolve the merge conflicts.

Comment on lines 177 to 180
// HACK(mgca): see lower_const_item in ast_lowering
ItemKind::Const(box ConstItem { body_id: Some(body_id), .. }) => {
this.create_def(body_id, None, DefKind::AnonConst, i.span);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't need to be changing def collector, it should just handle anon consts in the AST correctly already. Just need to change ast::ConstItem to store an AnonConst instead of NodeId/Expr as separate fields. This should also fix some of the ICEs you've been encountering

Comment on lines -217 to -222
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));
}
Copy link
Member

@BoxyUwU BoxyUwU May 22, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-generics Area: const generics (parameters and arguments) F-min_generic_const_args `#![feature(min_generic_const_args)]` S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants