Skip to content
This repository has been archived by the owner on Oct 22, 2020. It is now read-only.

Implement intrinsic types through traits #50

Open
MaikKlein opened this issue Jun 13, 2018 · 0 comments
Open

Implement intrinsic types through traits #50

MaikKlein opened this issue Jun 13, 2018 · 0 comments

Comments

@MaikKlein
Copy link
Owner

pub trait SpirvVector {
    type Intrinsic: Intrinsic;
}

unsafe trait Intrinsic {}

// This type has the metainformation
#[spirv(Vector3)]
struct SpirvVec3;

unsafe impl Intrinsic for SpirvVec3{}

impl SpirvVector for SomeExternalMathVec3 {
    type Intrinsic = SpirvVec3;
}

// Check if a given type implements SpirvVector, if it does then access the Intrinsic type which
// has the metainformation to generate a specific OpVector type.

// Some pseudo code

let trait_impl: Option<TraitImpl> = tcx.get_impl_of_trait(ty, def_id);
let associated_ty: Option<Ty> = trait_impl.and_then(|trait_impl| trait_impl.associated_types_iter().first());

fn type_moves_by_default should be enough to figure out how trait system works in rustc

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

No branches or pull requests

1 participant