-
Notifications
You must be signed in to change notification settings - Fork 45
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
Should sub-protocols (for i.e. MTLAllocation
) turn on the parent feature?
#663
Comments
An unrelated side-issue to this is our "workaround" in Traverse-Research/gpu-allocator@6a2f521 (and we later pushed a different workaround: Traverse-Research/gpu-allocator@95b79c6). We have a codebase that uses
|
Actually, As a bit of a contrived example, Similar logic applies to protocols, if we auto-enabled the features for sub-protocols, other items defined in the same files would require those features as well even though they don't need them.
Yeah, I get that that must have been confusing. It is noted in the changelog, but probably not prominently enough, I understand that it is long and perhaps overly verbose. I think it may be mitigated once v0.3 is actually released? Since then the online docs would state fairly prominently "Available on crate features
Don't know much about that, Cargo's crate and feature unification is weird. |
In hindsight, let's not call this "auto-enabling" but rather a regular dependency chain. If I request I had never expected this to be filename-based which makes things extra complicated, when there appears to be a mostly 1:1 mapping between filenames and the main type that it defines.
Is this debunked by stating that the type is only used in functions on If We previously discussed that this "parent trait" relation is purely for the type system and only matters when calling a function on the available protocol - which is a requirement for retroactively introducing a "parent protocol" in the hierarchy in newer versions. This means that old code without any notion of the extern_protocol!(
#[cfg(feature = "MTLAllocation")]
pub unsafe trait MTLResource: MTLAllocation { But if we have something like the following (perhaps with extern_protocol!(
pub unsafe trait MTLResource:
#[cfg(feature = "MTLAllocation")] MTLAllocation
{ |
I agree that it's kinda confusing (though documented here, open to input on how to make it clearer), but the only consistent choices were basically between file-based or one-feature-per-item. And given that these feature flags are intended for compilation performance optimization, I found that one-feature-per-item just doesn't make sense, since a lot of time is spent just parsing the files and expanding macros.
Yes, which is why I said "contrived" ;) A more realistic case might be (My confidence level here is low, I'm not sure which choice is the correct one here)
It's not a bad idea, and would be workable in Metal (where you rarely want to implement these protocols), but I think it would interfere with implementing the protocols yourself; e.g. if a library implementer does |
I expected and am glad to see a counter-example. You're right that
Yikes, that would be very annoying and I don't have a solution around this. |
Hi!
We recently patched our
objc2-metal
crate to the latest version in this repository. In 6442cbe the newMTLAllocation
protocol and feature flag were added. The effect is that, when we merely turn on features likeMTLHeap
andMTLResource
, the code now compiles with "imports not found" for the respective types, because they're guarded behindMTLHeap
andMTLAllocation
.While this is fixed by also turning on the
MTLAllocation
feature, doesn't it make more sense to haveMTLHeap = ["MTLAllocation"]
so that the feature is automatically enabled, for user convenience? Or if not, is there a thought-out reason why this should not be done?Specifically, it took some digging through the new source code to understand all the places where these protocols were guarded, before realizing that it was now hidden by the new
MTLAllocation
feature.The text was updated successfully, but these errors were encountered: