Skip to content

Lower const parameters #7434

@Veykril

Description

@Veykril
Member

Currently const params are not lowered at all:
https://github.com/rust-analyzer/rust-analyzer/blob/aa91a0268bae6deda964a9fdfcbdbd2d8ca5802f/crates/hir_def/src/path/lower.rs#L177-L178

These kind of define bodies, so they come with all the goodies(and problems like local items) that other items like functions, statics and consts come with, and just like those they should ideally be lowered lazily.

See corresponding zulip discussion https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/ConstArg.20lowering

Activity

added
C-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )
S-unactionableIssue requires feedback, design decisions or is blocked on other work
on Jan 25, 2021
dickytamara

dickytamara commented on Jan 27, 2021

@dickytamara
added a commit that references this issue on Mar 4, 2022
added a commit that references this issue on Mar 14, 2022
HKalbasi

HKalbasi commented on Mar 17, 2022

@HKalbasi
Member

If each constant needs a body for its own, locating them/allocating id for them will be hard. My suggestion is generalizing body to an expression store, and include expressions of constants in generics in the related definition's body. So for example:

fn foo<const N: usize = {2 + 2}>(x: Const<{2 + 2}>, y: Const<N>) -> Const<{2 + 2}> {
  let x: Const<{2 + 2}> = Const::<{2 + 2}>;
  x
}

all of 2 + 2 would get ExprId from function's body. Similarly, expressions inside const and static type annotations will be included inside of their bodies. And in this way, type alias will become a DefWithBody so it can lower and evaluate expressions. Body of a type alias has no meaningful root, so we may want to split Body into two abstractions, one with body_expr and params and one with the rest of fields (the expression allocator part).

Comments?

flodiebold

flodiebold commented on Mar 17, 2022

@flodiebold
Member

I think having a common expression store for all constants probably makes sense, but maybe not making that the body? How about we introduce something like an ExpressionStore and have Body contain one of those (basically what you're suggesting in the last sentence). So TypeAlias wouldn't be a DefWithBody.

31 remaining items

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-ArchitectureBig architectural things which we need to figure up-front (or suggestions for rewrites :0) )C-featureCategory: feature requestE-hardS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @flodiebold@jplatte@Veykril@dickytamara@HKalbasi

        Issue actions

          Lower const parameters · Issue #7434 · rust-lang/rust-analyzer