-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] SR-15807: Associated Type Inference fails across module boundaries #42293
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
Changes from all commits
ad00118
1dabc67
7edbf67
1e5519c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -220,8 +220,16 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses( | |
if (!checkConformance(proto)) | ||
return false; | ||
|
||
// Now check any additional bounds on 'Self' from the where clause. | ||
auto bounds = getSelfBoundsFromWhereClause(extension); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the extension came from a source file, then it might still have a trailing where clause, so we still want to prefer to do it the old way since it avoids computing a generic signature and therefore it is faster. You can check if 'extension->getParentSourceFile() != nullptr' to determine which method to use. |
||
// Source file and module file have different ways to get self bounds. | ||
// Source file extension will have trailing where clause which can avoid | ||
// computing a generic signature. Module file will not have | ||
// trailing where clause, so it will compute generic signature to get | ||
// self bounds which might result in slow performance. | ||
SelfBounds bounds; | ||
if (extension->getParentSourceFile() != nullptr) | ||
bounds = getSelfBoundsFromWhereClause(extension); | ||
else | ||
bounds = getSelfBoundsFromGenericSignature(extension); | ||
for (auto *decl : bounds.decls) { | ||
if (auto *proto = dyn_cast<ProtocolDecl>(decl)) { | ||
if (!checkConformance(proto)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
public protocol DefaultsBridge { | ||
associatedtype T | ||
} | ||
|
||
public struct BridgeStructSerializable<T: Codable>: DefaultsBridge { | ||
} | ||
|
||
public struct BridgeStructRawRepresentable<T: RawRepresentable>: DefaultsBridge { | ||
} | ||
|
||
public protocol DefaultsSerializable { | ||
associatedtype Bridge: DefaultsBridge | ||
static var _defaults: Bridge { get } | ||
} | ||
|
||
public extension DefaultsSerializable where Self: Codable { | ||
static var _defaults: BridgeStructSerializable<Self> { return BridgeStructSerializable() } | ||
} | ||
|
||
public extension DefaultsSerializable where Self: RawRepresentable { | ||
static var _defaults: BridgeStructRawRepresentable<Self> { return BridgeStructRawRepresentable() } | ||
} | ||
|
||
public struct ModuleAFoo: Codable, DefaultsSerializable { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module -o %t/ModuleA.swiftmodule %S/Inputs/where_clause_across_module_boundaries_module.swift | ||
// RUN: %target-typecheck-verify-swift -I %t | ||
|
||
// SR-15807: | ||
// Associated Type Inference fails across module boundaries | ||
// Self bounds from where clause cannot be accessed across modules. | ||
// This test is intended to test whether it can use generic signature to get self bounds. | ||
import ModuleA | ||
|
||
struct ModuleBFoo: Codable, DefaultsSerializable { | ||
} | ||
|
||
enum ModuleBBar: Int, Codable, DefaultsSerializable { // expected-error {{type 'ModuleBBar' does not conform to protocol 'DefaultsSerializable'}} | ||
case foo, bar | ||
} |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try making this request and SelfBoundsFromWhereClauseRequest Cached? (In a separate PR, if you like)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is my pleasure! I will do it!