Skip to content

Require @usableFromInline on witnesses for non-type requirements too #20485

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 1 commit into from
Nov 16, 2018

Conversation

jrose-apple
Copy link
Contributor

Follow-up to #20384 for non-type requirements. We use non-type witnesses for optimization purposes, so if we didn't enforce this we might end up with something silently performing worse with parseable interfaces than it would with swiftmodules. There's also a tricky case where the client of the interface infers a different implementation:

public protocol Foo {
  func foo()
}
extension Foo {
  public func foo() { print("default") }
}
@usableFromInline struct FooImpl: Foo {
  internal func foo() { print("actual") } // not printed
}

There might be another solution to this in the future, but for now this is the simplest answer. Like #20384, it'll be a warning in Swift 4 mode and an error in Swift 5 mode.

rdar://problem/43824161

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

@swift-ci
Copy link
Contributor

swift-ci commented Nov 9, 2018

Build failed
Swift Test Linux Platform
Git Sha - 916ee8f85012edc8bb6bccd87e21df8e9886ca93

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 916ee8f85012edc8bb6bccd87e21df8e9886ca93

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 916ee8f85012edc8bb6bccd87e21df8e9886ca93

Copy link
Member

@lorentey lorentey left a comment

Choose a reason for hiding this comment

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

Nice! 👍

The stdlib changes highlight that we have some issues with the visibility of some of our internal protocols; we should address these in a followup.

@@ -118,7 +118,7 @@ internal class _EmptyDictionarySingleton: _RawDictionaryStorage {
}

#if _runtime(_ObjC)
@objc
@objc @usableFromInline
Copy link
Member

Choose a reason for hiding this comment

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

Oh - these are correct but unfortunate: these are Objective-C entry points and they aren’t supposed to be visible (or used) as Swift methods.

We currently have _NSDictionaryCore and the other shadow protocols as public. I think we should make them internal and remove these usableFromInlines in a followup PR. Cc @airspeedswift, @Catfish-Man

Copy link
Contributor Author

@jrose-apple jrose-apple Nov 12, 2018

Choose a reason for hiding this comment

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

I tried but couldn't find an obvious way to do so. See the summary in the commit message for 1d437ca581e28601340bb63903bd5469af62646f.

@@ -654,7 +654,7 @@ protocol _Unwrappable {
}

extension Optional: _Unwrappable {
func unwrap() -> Any? {
@usableFromInline func unwrap() -> Any? {
Copy link
Member

Choose a reason for hiding this comment

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

TIL _Unwrappable is a thing. I think we should remove it.

@jrose-apple
Copy link
Contributor Author

(Waiting for Karoy to land his changes, then I'll rebase.)

Follow-up to f33bf67 for non-type requirements. We use non-type
witnesses for optimization purposes, so if we didn't enforce this we
might end up with something silently performing worse with parseable
interfaces than it would with swiftmodules. There's also a tricky case
where the client of the interface infers a different implementation:

    public protocol Foo {
      func foo()
    }
    extension Foo {
      public func foo() { print("default") }
    }
    @usableFromInline struct FooImpl: Foo {
      internal func foo() { print("actual") }
    }

There might be another solution to this in the future, but for now
this is the simplest answer. Like f33bf67, it'll be a warning in
Swift 4 mode and an error in Swift 5 mode.

rdar://problem/43824161
@jrose-apple
Copy link
Contributor Author

@swift-ci Please 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.

5 participants