msiglreith / inspirv-rust

Rust (MIR) → SPIR-V (Shader) compiler
Other
57 stars 1 forks source link

Improve enum type support #4

Open msiglreith opened 7 years ago

msiglreith commented 7 years ago

Currently only support C-like enums or consisting of unit types. SPIR-V (shader) doesn't support union types (afaik), so we probably will use a simple struct layout for emulating it:

enum Foo {
    A(u32),
    B(f32),
    C,
}

would be translated to

struct FooA(u32);
struct FooB(u32);
enum FooTy { A, B, C };

struct Foo {
   ty: FooTy,
   a: FooA,
   b: FooB,
}

This will need alot more memory than an corresponding enum, so complex enum types should be avoided.

Alternative

Keep the current state and disallow complex enum types, but add special handling for Option<T>.

msiglreith commented 7 years ago

Partially supported now (type construction and tag field assignment) Requires struct construction