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

Lower multi-segment const paths as ConstArgKind::Path #135186

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

camelid
Copy link
Member

@camelid camelid commented Jan 7, 2025

This PR:

  • Lower all const paths in arg position to hir::ConstArgKind::Path
  • Then lower assoc const paths to ty::ConstKind::Unevaluated
  • (incomplete) Introduce #[type_const] attribute for trait assoc consts that are allowed as const args

Next steps:

  • Implement code to check that assoc const definitions satisfy #[type_const] if present (basically is it a const path or monomorphic anon const)

r? @BoxyUwU

@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. labels Jan 7, 2025
@rust-log-analyzer

This comment has been minimized.

@camelid camelid changed the title Start lowering multi-segment const paths as ConstArgKind::Path Lower multi-segment const paths as ConstArgKind::Path Jan 7, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@camelid camelid marked this pull request as ready for review January 11, 2025 02:51
@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 2025

Some changes occurred in const_evaluatable.rs

cc @BoxyUwU

HIR ty lowering was modified

cc @fmease

@camelid camelid changed the title Lower multi-segment const paths as ConstArgKind::Path Lower multi-segment const paths as ConstArgKind::Path Jan 11, 2025
Copy link
Member

@BoxyUwU BoxyUwU left a comment

Choose a reason for hiding this comment

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

thx for working on this :3

@@ -1100,7 +1100,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
.and_then(|partial_res| partial_res.full_res())
{
if !res.matches_ns(Namespace::TypeNS)
&& path.is_potential_trivial_const_arg()
// FIXME: should this only allow single-segment paths?
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// FIXME: should this only allow single-segment paths?
// FIXME(mgca): should this only allow single-segment paths?

unannotated FIXME will just get lost tbh, no way of tracking them down lol

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah yeah, I meant it as a FIXME to deal with before merging this PR -- which is why I didn't label it. But since all of this is experimental anyway, we could deal with it later.

Copy link
Member

Choose a reason for hiding this comment

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

Oh in that case using // TODO will fail tidy and ensure the PR can't be merged until its resolved which ensures noone can forget about it before r+

compiler/rustc_ast/src/ast.rs Outdated Show resolved Hide resolved
/// Literals and const generic parameters are eagerly converted to a constant, everything else
/// becomes `Unevaluated`.
#[instrument(level = "debug", skip(self), ret)]
pub fn lower_const_assoc_path(
Copy link
Member

Choose a reason for hiding this comment

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

We should definitely consolidate this and lower_assoc_path into one method that handles 99% of the logic since the only real behavioural differences are the AssocKind arguments we hard code and that we construct a Ty or Const at the very end depending on which method it is

match &candidates[..] {
[] => {}
&[(impl_, assoc)] => {
// FIXME(mgca): adapted from temporary inherent assoc ty code that may be incorrect
Copy link
Member

Choose a reason for hiding this comment

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

same here we should just make probe_inherent_assoc_ty be able to be reused for consts somehow

@@ -549,6 +549,95 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
}
}

fn lower_assoc_const(
Copy link
Member

Choose a reason for hiding this comment

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

this would probably also be good to unify with lower_assoc_ty somehow, at the very least it would be good to not duplicate almost 100 lines of diagnostics logic :3

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. These two could now be on the dyn HirTyLowerer impl instead, with just the new lower_assoc_shared left as a trait method. I didn't do that though in case future impl-specific behavior was needed. Thoughts?

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 23, 2025

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

@BoxyUwU BoxyUwU removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 23, 2025
@BoxyUwU BoxyUwU added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants