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

Implement Clone for Module #2013

Merged
merged 2 commits into from
Aug 16, 2022
Merged

Implement Clone for Module #2013

merged 2 commits into from
Aug 16, 2022

Conversation

daxpedda
Copy link
Contributor

Allows Module to be cloned.

@teoxoy
Copy link
Member

teoxoy commented Jul 21, 2022

I think we should implement this via a feature flag that's on by default (and run CI with default features off) since @kvark previously mentioned that having these Clone implementations makes it too easy for the contributors of the project to clone potentially expensive structures unnecessarily.

@daxpedda
Copy link
Contributor Author

I used cfg(dev) instead, I hope that's appropriate.

@teoxoy
Copy link
Member

teoxoy commented Jul 21, 2022

Oh, I think that's even better!

Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but let's wait for one more review

@JCapucho
Copy link
Collaborator

JCapucho commented Aug 6, 2022

I think we should do the opposite and add a feature flag to enable it that's not the default, because I think most people that would want to dabble in naga will try to run

$ cargo run

And this will cause them to be able to Clone even though they shouldn't and then later when they try to open a PR it will fail on CI and debugging it would be a little bit counter intuitive.

But either way we should document this feature flag

@daxpedda
Copy link
Contributor Author

daxpedda commented Aug 7, 2022

I don't particularly understand the problem, calling clone() is explicit, why are we afraid of people misusing it or not be able to catch it in code review? I mean Vecs and HashMaps are also cloneable and they can be pretty large too, any clone() call should be paid attention to.

I think we should do the opposite and add a feature flag to enable it that's not the default, ...

This PR is specifically made for gfx-rs/wgpu#2903, so not having it on by default doesn't really work.

Alternatively, instead of Clone, I could also implement ToOwned, this should stand out even more.

Otherwise I could change gfx-rs/wgpu#2903 to not use Cow, but some custom type not requiring ToOwned or Clone.

But either way we should document this feature flag

I could add a note under README#development-workflow?

@JCapucho
Copy link
Collaborator

JCapucho commented Aug 7, 2022

I don't particularly understand the problem, calling clone() is explicit, why are we afraid of people misusing it or not be able to catch it in code review? I mean Vecs and HashMaps are also cloneable and they can be pretty large too, any clone() call should be paid attention to.

While Clones are explicit they are a tool that people can easily reach to and will do so, and naga doesn't clone IR internally for memory and performance considerations.

And while we can review them, doing so in every PR and pointing it out every time is an added task to the reviewer and some are voluntary so easing their work is always better and it's also unexpected to the contributor because they saw nowhere that the codebase doesn't accept it and suddenly are being told to not do it.

This PR is specifically made for gfx-rs/wgpu#2903, so not having it on by default doesn't really work.

Alternatively, instead of Clone, I could also implement ToOwned, this should stand out even more.

Otherwise I could change gfx-rs/wgpu#2903 to not use Cow, but some custom type not requiring ToOwned or Clone.

I don't understand the problem. wgpu is a user of naga so it can add to it's Cargo.toml the feature explicitly and I assume it already does so for other features.

No need to implement other traits.

But either way we should document this feature flag

I could add a note under README#development-workflow?

If we do end up following the negative feature flag then yes this would be the preferred place

@daxpedda
Copy link
Contributor Author

daxpedda commented Aug 7, 2022

I don't understand the problem. wgpu is a user of naga so it can add to it's Cargo.toml the feature explicitly and I assume it already does so for other features.

Yeah, I don't know what I was thinking, will do that.

@daxpedda
Copy link
Contributor Author

daxpedda commented Aug 7, 2022

Alright, I changed it to a non-default crate feature and documented it in the crate documentation!

Copy link
Collaborator

@JCapucho JCapucho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll just wait for @teoxoy to re-review since he originally approved it but otherwise it seems good to me, thanks for your contribution.

@JCapucho JCapucho requested a review from teoxoy August 8, 2022 10:09
@daxpedda daxpedda requested a review from JCapucho August 8, 2022 10:10
@daxpedda

This comment was marked as resolved.

Copy link
Member

@teoxoy teoxoy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; I think the previous cfg(dev) could have clashed with downstream users possibly setting the cmd line flag --cfg dev themselves.

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

Successfully merging this pull request may close these issues.

3 participants