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

erasable const-ness on types and TypeId #14

Open
lcnr opened this issue Oct 29, 2024 · 2 comments
Open

erasable const-ness on types and TypeId #14

lcnr opened this issue Oct 29, 2024 · 2 comments

Comments

@lcnr
Copy link

lcnr commented Oct 29, 2024

I have personally wanted for const fn(u32) and fn(u32) to be the same types at codegen once/if we ever add them. This requires const-ness of types to not influence selection.

It also requires TypeId::of::<const fn(u32)>() to error, as you can otherwise cast from fn(u32) to const fn(u32) which would be broken. Doing this would likely require a new bound on TypeId which only works by introducing a new default trait bound. Doing so is very questionable and means we're pretty much forced to treat them as different types.

by @BoxyUwU:

because then you could call a runtime only fn at compile time and thats (?)
well I mean we could error on it when you actually do it [during CTFE] but that feels like we failed in the type system xd

@programmerjake
Copy link
Member

I want to treat const fn() as a different type anyway, because it lets you distinguish between f and g's generic's types:

fn f<const F: const fn(u8) -> u8>() -> ([u8; F(1)], [u8; F(2)]) {
    todo!()
}

fn g<const F: fn(u8) -> u8>() -> [u8; 2] {
    [F(0), F(1)]
}

@lcnr
Copy link
Author

lcnr commented Oct 29, 2024

I have personally wanted for const fn(u32) and fn(u32) to be the same types at codegen once/if we ever add them.

as in: I want their TypeId to be the same and whether something is a const-fn to never impact trait selection. I would very much expect these to be different types during analysis, and e.g. prevent assigning an fn() to a const fn(). The same way fn(&'static u32) and fn(&'not_higher_ranked u32) are different types but are treated as equal outside of analysis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants