Skip to content

[CSRanking] Swift 4.1 compatibility hack for favouring properties on concrete types over protocols #18952

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

Merged
merged 3 commits into from
Sep 5, 2018

Conversation

hamishknight
Copy link
Contributor

(This is the Swift 4 mode portion of #18927)

Changes in shadowing behaviour by #15412 caused a property on a concrete type to no longer shadow a protocol property member, which created unintentional ambiguities in 4.2. This PR ensures we at least keep these cases unambiguous in Swift 5 under Swift 4 compatibility mode. This is intentionally narrow in order to best preserve source compatibility under Swift 4 mode by ensuring we don't introduce any new ambiguities.

Resolves SR-7425.

…concrete types over protocols

Changes in shadowing behaviour by swiftlang#15412 caused a property on a concrete type to no longer shadow a protocol property member, which created unintentional ambiguities in 4.2. This commit ensures we at least keep these cases unambiguous in Swift 5 under Swift 4 compatibility mode. This is intentionally narrow in order to best preserve source compatibility under Swift 4 mode by ensuring we don't introduce any new ambiguities.

Resolves SR-7425, SR-7940 & SR-8343.
@hamishknight hamishknight force-pushed the concrete-is-better-swift4 branch from fc74954 to 9268fcd Compare August 24, 2018 16:10
@rudkx
Copy link
Contributor

rudkx commented Aug 25, 2018

@swift-ci Please smoke test

@rudkx
Copy link
Contributor

rudkx commented Aug 28, 2018

@swift-ci Please test source compatibility

@rudkx rudkx self-assigned this Aug 28, 2018
auto *nominal2 = dc2->getSelfNominalTypeDecl();
if (nominal1 && nominal2 && nominal1 != nominal2) {
isSwift4ConcreteOverProtocolVar1 = isa<ProtocolDecl>(nominal2);
isSwift4ConcreteOverProtocolVar2 = isa<ProtocolDecl>(nominal1);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like these two lines would be a little clearer if they were actually looking at the decl associated with each variable rather than the other one, e.g.:

isSwift4ConcreteOverProtocolVar1 = !isa<ProtocolDecl>(nominal1);
isSwift4ConcreteOverProtocolVar2 = !isa<ProtocolDecl>(nominal2);

Copy link
Contributor

Choose a reason for hiding this comment

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

And perhaps rename the LHS of each. I mention this because at first I thought I was looking at typos in the name on the RHS.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rudkx That's actually how I originally wrote it, but wasn't sure the extra visual noise was worth it – I'll swap it back :). Any suggestions for the naming of the LHS? I can't immediately think of a better alternative.

Copy link
Contributor

Choose a reason for hiding this comment

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

@hamishknight Perhaps drop isVarAndNotProtocol{1,2}?

I don't think keeping Swift4 in the name adds a lot of meaning and it's pretty clear that it's only set under -swift-version 4 so I don't think there's going to be a lot of confusion over what it's for.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rudkx I agree that's better, thanks! I've gone ahead and made that change.

@rudkx
Copy link
Contributor

rudkx commented Aug 28, 2018

@swift-ci Please smoke test

@rudkx
Copy link
Contributor

rudkx commented Aug 28, 2018

@swift-ci Please test source compatibility

@hamishknight
Copy link
Contributor Author

Source compat suite failed to clone again – shouldn't it automatically restart in cases like this?

@rudkx
Copy link
Contributor

rudkx commented Aug 29, 2018

@swift-ci Please smoke test OS X platform

@rudkx
Copy link
Contributor

rudkx commented Aug 29, 2018

@swift-ci Please test source compatibility

@rudkx
Copy link
Contributor

rudkx commented Aug 29, 2018

@hamishknight I'm not sure how much sense it makes to automatically retry, even on what appear to be spurious infrastructure failures, since you may hit the same failure again immediately and you wouldn't want to just spin and retry if you have many jobs hitting the same issue.

@hamishknight
Copy link
Contributor Author

@rudkx Sure, you'd want to have a maximum number of retries (even if that was just 1). I only mention it because I know we already automatically restart jobs that grab the wrong commit SHA (though I'm not actually sure what causes those failures; perhaps restarting those cannot immediately lead to the same failure).

@rudkx
Copy link
Contributor

rudkx commented Aug 29, 2018

@hamishknight I think those are typically caused by triggering another run either while one is in progress or after one has been triggered but not started.

@shahmishal Mishal, any thoughts on automatically retrying jobs when we can determine that the cause was related to infrastructure/networking/etc. as opposed to something inherent in the changes we're attempting to build and test?

@hamishknight
Copy link
Contributor Author

Debug compat suite failure appears to be unrelated – the bot is consistently failing for:

FAIL: Chatto, 4.0.3, 3e4b1a, ChattoApp, generic/platform=iOS
FAIL: Chatto, 4.0.3, 3e4b1a, ChattoAdditions, generic/platform=iOS
FAIL: CoreStore, 4.0, 83e608, CoreStoreDemo, generic/platform=iOS

@rudkx
Copy link
Contributor

rudkx commented Sep 4, 2018

Yeah those are unrelated and are hitting with other PRs as well.

@rudkx
Copy link
Contributor

rudkx commented Sep 4, 2018

@swift-ci Please smoke test and merge

1 similar comment
@rudkx
Copy link
Contributor

rudkx commented Sep 4, 2018

@swift-ci Please smoke test and merge

@swift-ci swift-ci merged commit 638272d into swiftlang:master Sep 5, 2018
@hamishknight hamishknight deleted the concrete-is-better-swift4 branch September 5, 2018 10:27
@hamishknight
Copy link
Contributor Author

@rudkx Do you think this would be worth cherry picking to the 4.2 branch now that it's taking changes for a potential 4.2.1 release? IMO the risk should be minimal considering how narrow it is.

@hamishknight
Copy link
Contributor Author

Opened a 4.2 PR just in case: #19288

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