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

Use mapSignatureFunctionType on SubscriptDecls #23457

Merged
merged 3 commits into from Mar 31, 2019

Conversation

Jumhyn
Copy link
Collaborator

@Jumhyn Jumhyn commented Mar 21, 2019

When we call getOverloadSignatureType() on a SubscriptDecl, use mapSignatureFunctionType to perform the same transform that we use for other function types. This makes the allowed overloading behavior consistent between AbstractFunctionDecl and SubscriptDecl.

Resolves SR-10088.

@@ -2311,7 +2320,12 @@ CanType ValueDecl::getOverloadSignatureType() const {
if (isa<VarDecl>(this)) {
defaultSignatureType = TupleType::getEmpty(getASTContext());
} else {
defaultSignatureType = getInterfaceType()->getCanonicalType();
defaultSignatureType = mapSignatureFunctionType(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Does it matter whether we map the type before or after we add the curried self param? It means that we won't strip inout from the self param but it wasn't clear to me whether addCurriedSelfType already deals with that.

Copy link
Member

Choose a reason for hiding this comment

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

addCurriedSelfType() does not mark the self parameter as inout even if the storage is mutating. So I guess it doesn't matter if you add it before or after.

lib/AST/Decl.cpp Outdated
@@ -2221,6 +2221,15 @@ static Type mapSignatureFunctionType(ASTContext &ctx, Type type,
bool isMethod,
bool isInitializer,
unsigned curryLevels) {
if (auto errorType = type->getAs<ErrorType>()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can you explain why this part was necessary?

Copy link
Collaborator Author

@Jumhyn Jumhyn Mar 21, 2019

Choose a reason for hiding this comment

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

In test/IDE/complete_where_clause.swift, the subscript on line 106 results in an ErrorType (even though the underlying original type seems to be correct—I'm not entirely sure what that signifies). When we tried to cast to AnyFunctionType on line 2244 below the compiler crashed. Should this be added as a comment and/or tracked as a bug?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should this method assume that type->castTo<AnyFunctionType>() will always succeed and leave any error checking to the caller instead?

Copy link
Member

Choose a reason for hiding this comment

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

I see, I think is coming from checkRedeclaration(). Instead of destructuring the error type, how about just returning in this case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, sounds good.

@Jumhyn
Copy link
Collaborator Author

Jumhyn commented Mar 25, 2019

@slavapestov Does this need more work in order to be mergeable?

@slavapestov slavapestov self-assigned this Mar 27, 2019
@slavapestov
Copy link
Member

@Jumhyn Sorry for the late responses.

@slavapestov
Copy link
Member

@swift-ci Please smoke test

@slavapestov
Copy link
Member

@swift-ci Please test source compatibility

@Jumhyn
Copy link
Collaborator Author

Jumhyn commented Mar 27, 2019

@slavapestov No worries! Thanks for the feedback. Will update the PR with your suggestion this evening.

@Jumhyn Jumhyn force-pushed the subscript-escaping-overload branch from a809d26 to 427bdc5 Compare March 28, 2019 01:44
@Jumhyn
Copy link
Collaborator Author

Jumhyn commented Mar 28, 2019

@slavapestov Updated.

@slavapestov
Copy link
Member

@swift-ci Please smoke test

@slavapestov
Copy link
Member

@swift-ci Please test source compatibility

@Jumhyn
Copy link
Collaborator Author

Jumhyn commented Mar 28, 2019

@slavapestov Any chance you could shed some light on the failure here? Looks like there's a UPASS, but it seems unrelated to these changes...

@jrose-apple
Copy link
Contributor

Is this going to be source-breaking? That is, were there any programs that compiled previously that now will not compile? cc @hamishknight

@hamishknight
Copy link
Collaborator

This is technically a source breaking change, though in the discussion of SR-10088 it was felt that it's fairly unlikely that anyone's relying on overloading a subscript function-typed parameter by escaping-ness.

@jrose-apple
Copy link
Contributor

:-/ I agree, but a core team member should weigh in. @jckarter, @DougGregor?

@jckarter
Copy link
Member

I agree it seems unlikely. The only source compatibility suite failure looks like an UPASS:

01:01:39   UPASS: https://bugs.swift.org/browse/SR-8234, Lark, 4.0, 7604f9, Swift Package

@jrose-apple
Copy link
Contributor

jrose-apple commented Mar 28, 2019

"it seems unlikely" = "this is acceptable source breakage without going through the full evolution review process"?

@jckarter
Copy link
Member

Sorry, yeah, that's my opinion.

@jrose-apple
Copy link
Contributor

I think Harlan just un-XFAILed Lark, so I think it's okay to ignore the UPASS. If Slava's good with this then I guess it's good to go. :-)

@Jumhyn
Copy link
Collaborator Author

Jumhyn commented Mar 29, 2019

@slavapestov Given the above, can this be merged?

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.

None yet

5 participants