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

Add wrapper type for safety #32

Closed
wants to merge 1 commit into from
Closed

Conversation

jstarry
Copy link

@jstarry jstarry commented Feb 23, 2022

Problem

Summary of Changes

Fixes #

// The following trait bounds ensure that the above unsafe trait implementations
// won't allow undefined behavior to be introduced.
#[cfg(debug_assertions)]
trait AutoSendSync: Send + Sync {}
Copy link
Owner

Choose a reason for hiding this comment

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

Sorry how does this work? My understanding of how marker traits are handled is that they just tell the auto-trait resolver, "stop digging, you've struck gold." There's no compiler side verification of Send-iness of Sync-iness, which is why they're unsafe.

Copy link
Author

Choose a reason for hiding this comment

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

A type can't implement AutoSendSync unless it satisfies the Send + Sync trait requirements as well

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah I understand that, but it doesn't prevent UB. I can still implement AutoSendSync on a type that I've screwed up Send and/or Sync implementations on. So I guess the comment confused me at best. I'm not sure I understand the value add here other than maybe to mark any other types we may hit this bug on before Rust 1.60.0?

To be clear, the issue the original PR is fixing is not UB, it's bypassing a bug in the auto-trait resolver

Copy link
Author

Choose a reason for hiding this comment

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

You can't implement AutoSendSync unless a type already implements Send + Sync. So if you break the type, the AutoSendSync will cause a compiler error. Without it, your unsafe impl could allow new UB to be undetected

Copy link
Owner

Choose a reason for hiding this comment

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

Ok I get it after some offline brain bashing. Didn't realize that the trait resolver would check field types on explicitly declared marker traits.

I'm cool with this. Going to move it to sdk and mark it deprecated under the assumption we'll need it again

@t-nelson
Copy link
Owner

Closing in favor of solana-labs#23321

@t-nelson t-nelson closed this Feb 24, 2022
@jstarry jstarry deleted the add-wrapper branch February 24, 2022 03:00
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.

2 participants