Skip to content

Followup work from making ValTree recurse through ty::Const #150624

Description

@BoxyUwU

After #149114 ValTree's Branches variant stores a list of ty::Const instead of a list of ValTrees. See the PR description and associated zulip thread (#project-const-generics > Valtrees that can contain generic params) for a motivation for this.

This has left us with two problems:

  1. The name Value is kinda confusing :) These are in some sense not full values. It may be desirable to rename ConstKind::Value, ty::Value, ty::ValTree and ty::ValTreeKind to something different now that they don't represent full values.
  2. There are now a bunch of extra Ty in a fully evaluate ValTree. This is likely bad for performance. Though more importantly it means that when CTFE evaluates something to a ValTree it has to pick types for all the nested nodes in a ValTree. This is effectively impossible for CTFE to do correctly as it doesn't have lifetime information so we wind up with a bunch of erased lifetimes entering the type system.

The second point can be observed by looking at debug logs for this code example:

#![feature(adt_const_params, unsized_const_params)]
#![expect(incomplete_features)]
#![crate_type = "lib"]

struct Foo<'a> {
    r: &'a u32,
}

fn bar<const N: Foo<'static>>() { }

fn qux() {
    bar::<{ Foo { r: &1 } }>();
}

0ms DEBUG rustc_trait_selection::traits ct=UnevaluatedConst { def: DefId(0:9 ~ foo[cae9]::qux::{constant#0}), args: [] }
0ms DEBUG rustc_trait_selection::traits return=Ok(ValTree(Branch([ValTree(Leaf(0x00000001): &'{erased} u32)]): Foo::<'static>))

Assigning myself as I'm partially through fixing this second point.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)E-needs-designThis issue needs exploration and design to see how and if we can fix/implement itF-gca_min_const_items`#![feature(gca_min_const_items)]` (previously: `min_generic_const_args`)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions