-
Notifications
You must be signed in to change notification settings - Fork 57
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
Remove num-derive crate dependency #97
Conversation
Wow, managing 2.5K more LOC is not something taken lightly. Is there a way to reduce this? |
Ok, I think I know of a better way. fn from_primitive(num: u32) -> Self {
if num < $num_variants {
unsafe { mem::transmute(num) }
} else {
panic!("Unexpected value")
}
} |
Depends on where you want to go with this tbh, this generates identical code to what the Personally I'd be totally find just doing a transmute, but some of the enums have gaps in them (see |
Would it be possible to detect if there are gaps and fall back to a match for those cases? |
I've switched them to |
@Jasper-Bekkers wouldn't it actually make the run-time faster if we do a |
The rust compiler already takes care of doing range checks: https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=f569354c173b1e1aeb06ebd11f7ecd9d |
@Jasper-Bekkers thank you for addressing my concerns! |
From a quick glance, it looks like only a handful of small enums actually have that property. The gaps exist because of the vulkan extension model so it's likely that all/most of these end up with gaps in them in the long run. Besides you'd add a bunch of unsafe code for cases where the compiler already does something good & clever. |
Ideally what I'd want to have is: match value {
0 .. LAST_CORE_VALUE => Some(unsafe { mem::transmute(value) }),
EXT_VALUE_1 => Some(Value::Ext1),
EXT_VALUE_2 => Some(Value::Ext2),
_ => None,
} This would be concise, future-proof, and easy to read. |
I don't have a strong preference here given this is generated code. So I'm fine to land this and then revise later. :) |
Is there anything else that needs to be done before merging this in? |
This looks fine to me, the only other thing is could you remove the num dependency from spirv_headers now? It isn't used anywhere. You could also change the num dependency in rspirv to num-traits. These two together shave over a quarter off my clean compile times, so it seems worth it. |
Turns out |
You can replace the num dependency with num-traits and change one line in the autogen, but don't worry too much I'll do it as a separate PR if you leave this one as is. |
Cool then feel free to merge this I guess :-) |
This PR removes the
num-derive
dependency and instead opts to auto-generate the implementation fornum_traits::FromPrimitive
manually during theautogen
stage. This should save downstream dependencies from compiling a copy ofsyn
that's dragged in throughnum-derive
.For some reason this also causes a whitespace diff in
rspirv/dr/autogen_operand.rs
. I've left it in the commit for now.