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 all trivial const paths as ConstArgKind::Path #135186

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

Conversation

camelid
Copy link
Member

@camelid camelid commented Jan 7, 2025

This PR:

  • Lower all trivial const paths (i.e. no nested anon consts) 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

@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 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 Jan 23, 2025
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 27, 2025
@camelid camelid changed the title Lower multi-segment const paths as ConstArgKind::Path Lower all trivial const paths as ConstArgKind::Path Jan 27, 2025
@bors
Copy link
Contributor

bors commented Jan 27, 2025

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

@BoxyUwU BoxyUwU 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 Jan 28, 2025
@bors
Copy link
Contributor

bors commented Feb 17, 2025

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

@rustbot
Copy link
Collaborator

rustbot commented Feb 19, 2025

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann

@rustbot rustbot added the A-attributes Area: Attributes (`#[…]`, `#![…]`) label Feb 19, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

camelid and others added 4 commits February 19, 2025 18:52
A bit tricky to support this special case now, so might as well save it
for once we're ready to handle the general case. See
rust-lang#135186 (comment).

Co-authored-by: BoxyUwU <[email protected]>
Comment on lines +1119 to +1120
// FIXME: should this only allow single-segment paths?
&& path.is_potential_trivial_const_arg(self.tcx.features().min_generic_const_args())
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?
&& path.is_potential_trivial_const_arg(self.tcx.features().min_generic_const_args())
&& path.is_potential_trivial_const_arg(false)

Yes I think this should only work for mcg paths rn. Generally this needs to be kept in sync with the logic in name resolution that attempts to resolve type args in both valuens and typens and that currently uses false.

@@ -1200,7 +1200,7 @@ impl<'ra: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'r
if let TyKind::Path(None, ref path) = ty.kind
// We cannot disambiguate multi-segment paths right now as that requires type
// checking.
&& path.is_potential_trivial_const_arg()
&& path.is_potential_trivial_const_arg(false)
Copy link
Member

Choose a reason for hiding this comment

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

this.

I think making this use self.features().min_generic_const_args() is spooky 🤔 We would need to update logic furthur down to call methods that can actually resolve multi-seg paths and idk if such methods exist.

So yeah, tl;dr we just make both of these false and handle it down the road when we support unbraced const arguments of more complex paths (probably under a different feature gate)

const ASSOC: usize;
}

// FIXME(min_generic_const_args): implement support for this, behind the feature gate
// FIXME(min_generic_const_args): add suggestion for mgca to this error
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(min_generic_const_args): add suggestion for mgca to this error
// FIXME(mgca): add suggestion for mgca to this error

Comment on lines 1150 to 1179
let assoc = tcx.associated_item(def_id);
let ty = if matches!(assoc, ty::AssocItem {
container: ty::AssocItemContainer::Impl,
trait_item_def_id: None,
..
}) {
Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new_from_args(tcx, def_id, args))
} else {
Ty::new_projection_from_args(tcx, def_id, args)
};
Ok((ty, DefKind::AssocTy, def_id))
Copy link
Member

Choose a reason for hiding this comment

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

Hmm yeah you're right I don't think we care about any of the other kinds of aliases here... It's just more concise then I guess 😅 My understanding is that type Foo = impl Trait; is a projection/iat that normalizes to an opaque, rather than T::Foo itself referring to an opaque so doesnt matter here

/// that the path resolves to a const param, the caller should check this.
pub fn is_potential_trivial_const_arg(&self) -> bool {
matches!(self.segments[..], [PathSegment { args: None, .. }])
// FIXME: add docs
Copy link
Member

Choose a reason for hiding this comment

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

:3

@@ -1177,22 +1178,26 @@ pub struct Expr {
}

impl Expr {
// FIXME: update docs
Copy link
Member

Choose a reason for hiding this comment

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

:3

@BoxyUwU
Copy link
Member

BoxyUwU commented Feb 22, 2025

I think this is basically good to go now (once minor nits are resolved). I'm really happy to see this feature at the point its at :3 thx for doing this

@bors
Copy link
Contributor

bors commented Feb 25, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) 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