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

[docs] Tidy and document permissible conversions based on calling conventions #35457

Merged

Conversation

varungandhi-apple
Copy link
Contributor

Fixes https://bugs.swift.org/browse/SR-14051 and matching rdar://73250604.

Also, I filed https://bugs.swift.org/browse/SR-14058 recently for the difference between the compiler and the runtime, so I figured it is worth updating DynamicCasting.md to reflect this.

The existing polarity is sufficiently confusing that it has an
explanatory comment at a return statement.
@varungandhi-apple varungandhi-apple changed the title Tidy and document permissible conversions based on calling conventions [docs] Tidy and document permissible conversions based on calling conventions Jan 16, 2021
@varungandhi-apple varungandhi-apple requested review from tbkka, slavapestov and xedin and removed request for slavapestov January 16, 2021 09:25
@@ -1590,6 +1590,10 @@ ManagedValue emitCFunctionPointer(SILGenFunction &SGF,
// C function pointers cannot capture anything from their context.
auto captures = SGF.SGM.Types.getLoweredLocalCaptures(constant);

// Catch cases like:
// func g(_ : @convention(c) () -> ()) {}
Copy link
Contributor

Choose a reason for hiding this comment

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

I just want to say. Thank you so much for putting stuff like this in here! Very useful! = ).

/// The subtype relationship is defined as:
/// 1. any representation R is a sub-type of itself.
/// 2. a thin representation is a subtype of any other representation.
/// 3. a thick representation is a subtype of any other representation.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this true? Because thick-to-thin subtype is not allowed ... sorry, maybe I'm just a bit confused :)

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are correct, at least that is how it was handled before, even examples still have passing a swift closure to @conversion(c) parameter as an error.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, made a mistake there, it should be "a thick representation is a subtype of any other thick representation"

Copy link
Contributor

Choose a reason for hiding this comment

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

Sounds good!

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah makes sense :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Question, do you think would be informational note sub-type relation and variance here? As in (@convetion(c) () -> Void) -> Void sub (@convention(block) () -> Void) -> Void? I'm just wondering if this could be helpful in someway

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Function subtyping has multiple aspects: (1) representation/convention (2) variance (3) throws (4) @escaping. At the moment, this PR only documents (1), because that's the trickiest part.

The example you're describing falls out as a composition of (1) + (2). Are you suggesting that I document both (1) and (2) separately? Or is the suggestion that I specifically document that "(1) + (2) can be combined in such a way"?

Copy link
Contributor

Choose a reason for hiding this comment

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

this PR only documents (1), because that's the trickiest part

Ah sure, better thinking about I agree it makes sense to only focus on (1) here
I just mentioned because (1) + (2) combined used to get me confused =]

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

/// The subtype relationship is defined as:
/// 1. any representation R is a sub-type of itself.
/// 2. a thin representation is a subtype of any other representation.
/// 3. a thick representation is a subtype of any other representation.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you are correct, at least that is how it was handled before, even examples still have passing a swift closure to @conversion(c) parameter as an error.

@varungandhi-apple
Copy link
Contributor Author

@swift-ci smoke test

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.

4 participants