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

emit from(ignore) on duplicate enum variants for derive_more 0.99 #181

Merged
merged 4 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
184 changes: 37 additions & 147 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 1 addition & 1 deletion rspirv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ travis-ci = { repository = "gfx-rs/rspirv" }

[dependencies]
clippy = { version = "0.0", optional = true }
derive_more = "0.15"
derive_more = "0.99"
fxhash = "0.2"
num-traits = "0.2"

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
Loading