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

Leaking implementation details during unification #30

Open
lcnr opened this issue Mar 23, 2022 · 0 comments
Open

Leaking implementation details during unification #30

lcnr opened this issue Mar 23, 2022 · 0 comments
Labels
A-generic-exprs Generic const expressions A-unification Unifying constants in the type system C-design-docs Category: This is part of our design documentation K-impl Document Kind: regarding implementation P-necessary Priority: will be needed at some point S-active

Comments

@lcnr
Copy link
Contributor

lcnr commented Mar 23, 2022

What is this

This is a design document for const generics. Any discussions about its content should be on zulip. The conclusions of these discussions should then be edited back into this issue. Please do not post any comments directly in this issue.

Content

When unifying generic constants, we have to avoid accidentally stabilizing
parts of our lowering.

fn foo<const B: bool>() -> [u8; if B { 3 } else { 7 }] {
    [0; match B {
        true => 3,
        false => 7,
    }]
}

If we allow foo to compile, we have to guarantee that we will continue supporting it
in the future. While this is fine if we intentionally allow it, it could also be allowed
by accident if we we use the same representation for if and match in the abstract representation for
generic constants.

Another issue here is the removal of noops, like redundant as-casts. This was an issue with a
previous implementation which relied on the MIR of generic constants for unification.

fn multiple_casts<const N: u8>() -> [u8; N as usize as usize] {
    [0; N as usize]
}

In general, the unification of generic constants has to add a new representation for expressions which can
be used in types. If we end up stabilizing feature(generic_const_exprs) with a suboptimal lifting from expressions
to that new representation, this will probably be quite difficult to fix while maintaining backwards compatability.

@lcnr lcnr added C-design-docs Category: This is part of our design documentation K-impl Document Kind: regarding implementation P-necessary Priority: will be needed at some point S-active A-generic-exprs Generic const expressions A-unification Unifying constants in the type system labels Mar 23, 2022
@rust-lang rust-lang locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-generic-exprs Generic const expressions A-unification Unifying constants in the type system C-design-docs Category: This is part of our design documentation K-impl Document Kind: regarding implementation P-necessary Priority: will be needed at some point S-active
Projects
None yet
Development

No branches or pull requests

1 participant