Skip to content

Commit

Permalink
emit from(ignore) on duplicate enum variants for derive_more 0.99
Browse files Browse the repository at this point in the history
  • Loading branch information
MarijnS95 committed Jan 12, 2021
1 parent 4e06b60 commit 73c986e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
16 changes: 15 additions & 1 deletion autogen/src/dr.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::collections::HashSet;

use crate::structs;
use crate::utils::*;

Expand Down Expand Up @@ -240,7 +242,19 @@ pub fn gen_dr_operand_kinds(grammar: &[structs::OperandKind]) -> TokenStream {
};

let kind_enum = {
let kinds = kind_and_ty.iter().map(|(kind, ty)| quote! {#kind(#ty)});
let mut types_seen = HashSet::new();

// To prevent ambiguity we don't want to generate an implementation for `Word` at all:
types_seen.insert(quote!(spirv::Word).to_string());

let kinds = kind_and_ty.iter().map(|(kind, ty)| {
let v = quote!(#kind(#ty));
if types_seen.insert(ty.to_string()) {
v
} else {
quote!(#[from(ignore)] #v)
}
});
quote! {
#[doc = "Data representation of a SPIR-V operand."]
#[derive(Clone, Debug, PartialEq, From)]
Expand Down
3 changes: 1 addition & 2 deletions autogen/src/sr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,10 @@ pub fn gen_sr_code_from_operand_kind_grammar(
})
.collect();
let tokens = quote! {
use derive_more::From;
use spirv;

/// SPIR-V decorations.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Decoration {
#( #enumerants ),*
}
Expand Down
4 changes: 4 additions & 0 deletions rspirv/dr/autogen_operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ pub enum Operand {
RayQueryIntersection(spirv::RayQueryIntersection),
RayQueryCommittedIntersectionType(spirv::RayQueryCommittedIntersectionType),
RayQueryCandidateIntersectionType(spirv::RayQueryCandidateIntersectionType),
#[from(ignore)]
IdMemorySemantics(spirv::Word),
#[from(ignore)]
IdScope(spirv::Word),
#[from(ignore)]
IdRef(spirv::Word),
LiteralInt32(u32),
LiteralInt64(u64),
LiteralFloat32(f32),
LiteralFloat64(f64),
#[from(ignore)]
LiteralExtInstInteger(u32),
LiteralSpecConstantOpInteger(spirv::Op),
LiteralString(String),
Expand Down
3 changes: 1 addition & 2 deletions rspirv/sr/autogen_decoration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
// external/spirv.core.grammar.json.
// DO NOT MODIFY!

use derive_more::From;
use spirv;
#[doc = r" SPIR-V decorations."]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, From)]
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Decoration {
RelaxedPrecision,
SpecId(u32),
Expand Down

0 comments on commit 73c986e

Please sign in to comment.