-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
languageLanguage specification related issuesLanguage specification related issues
Description
The language currently does not define any strict rules about as casts. This should be dedicated so that it can be:
- formally implemented in the IR and lowered
- supported by whichever backend (if it involves runtime conversions)
Cast kinds
Some clear requirements from casts are:
- Numeric casts:
- integer type to another integer type cast (for example
8u8 as u64) - integer to float cast
- float to integer cast
- integer type to another integer type cast (for example
- pointer casts
- what are the valid pointer casts?
- array to pointer?
- decide on how different pointer kinds interact with one another
Ref<T>to&T?- function pointer casts?
- what are the valid pointer casts?
We should also consider the following
- c-kind casts
enums to integer casts - so long as the enum is compatible with ac-like enumboolorcharto integer type castu8to `char cast
Numeric cast semantics
We should define some clear semantics on numeric casting, what is valid, what isn't, if there is a runtime cost, etc.
- casting between an integer kind of the same size is a no-op
- downcasting between integers results in truncation
- upcasting integers will result:
- zero-extend if the source integer type is unsigned
- sign-extend if the source integer type is signed
- casting between a float to an integer will...?
- casting between an integer to a float will...?
- upcasting floats is a perfect and lossless operation.
- downcasting floats tries to get the nearest approximation of float value (how?)
- should we follow a formal specification?
Enum cast
Cast from an enum value to its discriminant value, and then uses a numeric cast.
c-kind casts
Boolean to integer cast adheres to the following rules (basically an enum cast):
falsecasts to0truecasts to1
u8 to char cast converts the value into the corresponding char code point.
pointer casts
An area for discussion!
What are the rules for pointer casts... can pointers be cast into an integral type, how do different reference types interact with one another when it comes to casting, etc?
Metadata
Metadata
Assignees
Labels
languageLanguage specification related issuesLanguage specification related issues