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

[SR-6922] [SE-0143] [release mode] type ... does not conform to protocol ... #49471

Closed
swift-ci opened this issue Feb 4, 2018 · 12 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Feb 4, 2018

Previous ID SR-6922
Radar rdar://problem/37290900
Original Reporter tannernelson (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

macOS 10.13.2
Xcode 9.2
Swift 2018-02-01

Additional Detail from JIRA
Votes 13
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: 5583323ce1401d66f0c4828686300777

is duplicated by:

  • SR-7227 Conditional conformance error in iOS Release builds only

relates to:

  • SR-6914 Extensions don't add conformance to inherited protocols
  • SR-6474 Conditional conformance to refined protocol inappropriately fails

Issue Description:

Code using conditional conformance that compiles in debug mode is not compiling in release mode.

To recreate, compile this code in release mode (in Xcode, CLI not tested)
vapor/core@28ee900

/Users/tanner/dev/vapor/core/Sources/CodableKit/Key/KeyStringDecodable.swift:80:1: Type 'Array<Element>' does not conform to protocol 'AnyKeyStringDecodable'
/Users/tanner/dev/vapor/core/Sources/CodableKit/Key/KeyStringDecodable.swift:9:17: Type 'Array<Element>' does not conform to inherited protocol 'AnyKeyStringDecodable'
/Users/tanner/dev/vapor/core/Sources/CodableKit/Key/KeyStringDecodable.swift:86:1: Type 'Dictionary<Key, Value>' does not conform to protocol 'AnyKeyStringDecodable'
/Users/tanner/dev/vapor/core/Sources/CodableKit/Key/KeyStringDecodable.swift:9:17: Type 'Dictionary<Key, Value>' does not conform to inherited protocol 'AnyKeyStringDecodable'
/Users/tanner/dev/vapor/core/Sources/CodableKit/Key/KeyStringDecodable.swift:91:1: Type 'Optional<Wrapped>' does not conform to protocol 'AnyKeyStringDecodable'
@belkadan
Copy link
Contributor

belkadan commented Feb 5, 2018

Probably related to WMO vs. single-file compilation.

@swift-ci create

@swift-ci
Copy link
Collaborator Author

Comment by tanner0101 (JIRA)

I tried creating a smaller repro case for this to make things easier for you guys but couldn't get it to happen. Even with a similar setup in an SPM project (two modules, release mode).

I've tagged the core repo at least, so you should be able to easily recreate this:

~/Desktop$ swiftenv version
4.1-DEVELOPMENT-SNAPSHOT-2018-02-14-a (set by /Users/tanner/.swiftenv/version)
~/Desktop$ swift --version
Apple Swift version 4.1-dev (LLVM 1c8b50929b, Clang 8be462d5b8, Swift 54ea599d66)
Target: x86_64-apple-darwin16.7.0
~/Desktop$ git clone git@github.com:vapor/core.git
Cloning into 'core'...
remote: Counting objects: 18176, done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 18176 (delta 10), reused 22 (delta 7), pack-reused 18144
Receiving objects: 100% (18176/18176), 8.82 MiB | 2.40 MiB/s, done.
Resolving deltas: 100% (11520/11520), done.
~/Desktop$ cd core/
~/Desktop/core master$ git checkout SR-6922
Note: checking out 'SR-6922'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 06ff4d12... dependencies update
~/Desktop/core (HEAD detached at SR-6922)$ swift build
Fetching https://github.com/vapor/async.git
Cloning https://github.com/vapor/async.git
Resolving https://github.com/vapor/async.git at 1.0.0-beta.1.1
Compile Swift Module 'Bits' (5 sources)
Compile Swift Module 'Debugging' (6 sources)
Compile Swift Module 'COperatingSystem' (1 sources)
Compile Swift Module 'Async' (45 sources)
Compile Swift Module 'CodableKit' (24 sources)
~/Desktop/core (HEAD detached at SR-6922)$ swift build -c release
Compile Swift Module 'Debugging' (6 sources)
Compile Swift Module 'COperatingSystem' (1 sources)
Compile Swift Module 'Bits' (5 sources)
Compile Swift Module 'Async' (45 sources)
Compile Swift Module 'CodableKit' (24 sources)
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:80:1: error: type 'Array<Element>' does not conform to protocol 'AnyKeyStringDecodable'
extension Array: KeyStringDecodable where Element: KeyStringDecodable {
^
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:9:17: note: type 'Array<Element>' does not conform to inherited protocol 'AnyKeyStringDecodable'
public protocol KeyStringDecodable: AnyKeyStringDecodable {
                ^
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:86:1: error: type 'Dictionary<Key, Value>' does not conform to protocol 'AnyKeyStringDecodable'
extension Dictionary: KeyStringDecodable where Value: KeyStringDecodable, Key == String {
^
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:9:17: note: type 'Dictionary<Key, Value>' does not conform to inherited protocol 'AnyKeyStringDecodable'
public protocol KeyStringDecodable: AnyKeyStringDecodable {
                ^
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:91:1: error: type 'Optional<Wrapped>' does not conform to protocol 'AnyKeyStringDecodable'
extension Optional: KeyStringDecodable where Wrapped: KeyStringDecodable {
^
/Users/tanner/Desktop/core/Sources/CodableKit/Key/KeyStringDecodable.swift:9:17: note: type 'Optional<Wrapped>' does not conform to inherited protocol 'AnyKeyStringDecodable'
public protocol KeyStringDecodable: AnyKeyStringDecodable {
                ^
error: terminated(1): /Library/Developer/Toolchains/swift-4.1-DEVELOPMENT-SNAPSHOT-2018-02-14-a.xctoolchain/usr/bin/swift-build-tool -f /Users/tanner/Desktop/core/.build/release.yaml main output:
    

~/Desktop/core (HEAD detached at SR-6922)$ 

@swift-ci
Copy link
Collaborator Author

Comment by tanner0101 (JIRA)

https://github.com/vapor/core/releases/tag/SR-6922

@swift-ci
Copy link
Collaborator Author

Comment by tanner0101 (JIRA)

Any updates on this? I'm worried this is going to make it into Swift 4.1.0 release.

@0xTim
Copy link

0xTim commented Feb 21, 2018

Any news on this?

@belkadan
Copy link
Contributor

I think it's unlikely we'll have time to address this in Swift 4.1. It's not great to ship a feature with known bugs, especially when we don't understand the root cause yet, but at least it's a new feature, which means it's not breaking existing code.

It's possible that a non-WMO build would succeed, but I don't know if there's any way to turn that off from SwiftPM.

@swift-ci
Copy link
Collaborator Author

Comment by tanner0101 (JIRA)

This change fixes the problem.

diff --git a/Sources/CodableKit/Key/KeyStringDecodable.swift b/Sources/CodableKit/Key/KeyStringDecodable.swift
index f04d7015..386c3375 100644
--- a/Sources/CodableKit/Key/KeyStringDecodable.swift
+++ b/Sources/CodableKit/Key/KeyStringDecodable.swift
@@ -77,18 +77,18 @@ extension Date: KeyStringDecodable {
     public static var keyStringFalse: Date { return Date(timeIntervalSince1970: 0) }
 }
 
-extension Array: KeyStringDecodable where Element: KeyStringDecodable {
+extension Array: KeyStringDecodable, AnyKeyStringDecodable where Element: KeyStringDecodable {
     public static func keyStringIsTrue(_ item: Array<Element>) -> Bool { return Element.keyStringIsTrue(item[0]) }
     public static var keyStringTrue: Array<Element> { return [Element.keyStringTrue] }
     public static var keyStringFalse: Array<Element> { return [Element.keyStringFalse] }
 }
 
-extension Dictionary: KeyStringDecodable where Value: KeyStringDecodable, Key == String {
+extension Dictionary: KeyStringDecodable, AnyKeyStringDecodable where Value: KeyStringDecodable, Key == String {
     public static func keyStringIsTrue(_ item: Dictionary<String, Value>) -> Bool { return Value.keyStringIsTrue(item[""]!) }
     public static var keyStringTrue: Dictionary<Key, Value> { return ["": Value.keyStringTrue] }
     public static var keyStringFalse: Dictionary<Key, Value> { return ["": Value.keyStringFalse] }
 }
-extension Optional: KeyStringDecodable where Wrapped: KeyStringDecodable {
+extension Optional: KeyStringDecodable, AnyKeyStringDecodable where Wrapped: KeyStringDecodable {
     public static func keyStringIsTrue(_ item: Optional<Wrapped>) -> Bool {
         guard let item = item else {
             return false

@swift-ci
Copy link
Collaborator Author

Comment by tanner0101 (JIRA)

Where you have:

protocol X: Y { }
extension Array: X where Element: X { 

}

It seems the problem is that the `extension Array: X` is not properly implying conformance to `Y`

@huonw
Copy link
Mannequin

huonw mannequin commented Apr 5, 2018

That was almost certainly the problem. The compiler didn't accept implicit conditional conformance in a broken way, leading to inconsistencies and brokenness like this. As of apple/swift-evolution#809 and #15268 (available in the 2018-04-04 snapshot), the compiler prompts for the explicit conformance (and offers help to write it via a few different fixits that are slightly syntactically wrong in that snapshot but should be fixed in the next one), and so this doesn't crash any more.

Thanks for filing!

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Jul 26, 2018

tannernelson (JIRA User), Could you verify if the problem is fixed and if so move the JIRA to "Closed"?
Thanks!
Anna

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Sep 13, 2018

tannernelson (JIRA User), Could you verify if the problem is fixed and/or move the JIRA to "Closed"?
Thanks!
Anna

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Oct 24, 2018

Closing the bug. Feel free to reopen if the issue is not resolved.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants