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 9 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+

/// Could this expr be either `N`, or `{ N }`, where `N` is a const parameter.
///
/// If this is not the case, name resolution does not resolve `N` when using
/// `min_const_generics` as more complex expressions are not supported.
///
/// Does not ensure that the path resolves to a const param, the caller should check this.
/// This also does not consider macros, so it's only correct after macro-expansion.
pub fn is_potential_trivial_const_arg(&self) -> bool {
pub fn is_potential_trivial_const_arg(&self, allow_multi_segment: bool) -> bool {
Copy link
Member

Choose a reason for hiding this comment

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

It's not that just we should support multi seg paths we should also support generic arguments on paths too, and also support qualified paths. e.g. this path which has segments with args and also a self ty: <T as Trait<u32>>::ASSOC

/// 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

@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-18 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#21 exporting to docker image format
#21 sending tarball 28.4s done
#21 DONE 34.3s
##[endgroup]
Setting extra environment values for docker:  --env ENABLE_GCC_CODEGEN=1 --env GCC_EXEC_PREFIX=/usr/lib/gcc/
[CI_JOB_NAME=x86_64-gnu-llvm-18]
debug: `DISABLE_CI_RUSTC_IF_INCOMPATIBLE` configured.
---
sccache: Starting the server...
##[group]Configure the build
configure: processing command line
configure: 
configure: build.configure-args := ['--build=x86_64-unknown-linux-gnu', '--llvm-root=/usr/lib/llvm-18', '--enable-llvm-link-shared', '--set', 'rust.randomize-layout=true', '--set', 'rust.thin-lto-import-instr-limit=10', '--enable-verbose-configure', '--enable-sccache', '--disable-manage-submodules', '--enable-locked-deps', '--enable-cargo-native-static', '--set', 'rust.codegen-units-std=1', '--set', 'dist.compression-profile=balanced', '--dist-compression-formats=xz', '--set', 'rust.lld=false', '--disable-dist-src', '--release-channel=nightly', '--enable-debug-assertions', '--enable-overflow-checks', '--enable-llvm-assertions', '--set', 'rust.verify-llvm-ir', '--set', 'rust.codegen-backends=llvm,cranelift,gcc', '--set', 'llvm.static-libstdcpp', '--enable-new-symbol-mangling']
configure: target.x86_64-unknown-linux-gnu.llvm-config := /usr/lib/llvm-18/bin/llvm-config
configure: llvm.link-shared     := True
configure: rust.randomize-layout := True
configure: rust.thin-lto-import-instr-limit := 10
---
##[group]Testing stage2 compiletest suite=ui mode=ui (x86_64-unknown-linux-gnu)

running 18301 tests
10%  --  1831/18301,  1786 passed, 0 failed, 45 ignored
   [ui] tests/ui/const-generics/mgca/assoc-const.rs ... FAILED
30%  --  5491/18301,  5429 passed, 1 failed, 61 ignored
40%  --  7321/18301,  7250 passed, 1 failed, 70 ignored
50%  --  9151/18301,  9068 passed, 1 failed, 82 ignored
60%  -- 10981/18301, 10870 passed, 1 failed, 110 ignored
---


failures:

---- [ui] tests/ui/const-generics/mgca/assoc-const.rs stdout ----
error: test compilation failed although it shouldn't!
status: exit status: 1
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/mgca/assoc-const.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2" "--target=x86_64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/const-generics/mgca/assoc-const" "-A" "unused" "-A" "internal_features" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers"
--- stderr -------------------------------
error[E0277]: the trait bound `T: Tr<bool>` is not satisfied
error[E0277]: the trait bound `T: Tr<bool>` is not satisfied
##[error]  --> /checkout/tests/ui/const-generics/mgca/assoc-const.rs:11:42
   |
LL | fn mk_array<T: Tr<bool>>(_x: T) -> [(); <T as Tr<bool>>::SIZE] {
   |                                          ^ the trait `Tr<bool>` is not implemented for `T`
error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0277`.
------------------------------------------
------------------------------------------



failures:
    [ui] tests/ui/const-generics/mgca/assoc-const.rs
test result: FAILED. 18119 passed; 1 failed; 181 ignored; 0 measured; 0 filtered out; finished in 177.77s

Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Build completed unsuccessfully in 0:17:56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants