Skip to content

Commit 1dabc67

Browse files
committed
[Sema] TypeCheckProtocolInference: using trailingWhereClause to get self bounds in source file.
1 parent ad00118 commit 1dabc67

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,9 +983,6 @@ SelfBounds swift::getSelfBoundsFromWhereClause(
983983
SelfBounds SelfBoundsFromGenericSignatureRequest::evaluate(
984984
Evaluator &evaluator, const ExtensionDecl *extDecl) const {
985985
SelfBounds result;
986-
if (!extDecl->hasComputedGenericSignature())
987-
return result;
988-
989986
ASTContext &ctx = extDecl->getASTContext();
990987
auto selfType = extDecl->getSelfInterfaceType();
991988
for (const auto &req : extDecl->getGenericRequirements()) {

lib/Sema/TypeCheckProtocolInference.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,16 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitnesses(
220220
if (!checkConformance(proto))
221221
return false;
222222

223-
// Now check any additional bounds on 'Self' from the generic signature.
224-
auto bounds = getSelfBoundsFromGenericSignature(extension);
223+
// Source file and module file have different ways to get self bounds.
224+
// Source file extension will have trailing where clause which can avoid
225+
// computing a generic signature. Module file will not have
226+
// trailing where clause, so it will compute generic signature to get
227+
// self bounds which might result in slow performance.
228+
SelfBounds bounds;
229+
if (extension->getParentSourceFile() != nullptr)
230+
bounds = getSelfBoundsFromWhereClause(extension);
231+
else
232+
bounds = getSelfBoundsFromGenericSignature(extension);
225233
for (auto *decl : bounds.decls) {
226234
if (auto *proto = dyn_cast<ProtocolDecl>(decl)) {
227235
if (!checkConformance(proto))

test/Sema/sr15807.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend -emit-module -o %t/ModuleA.swiftmodule %S/Inputs/where_clause_across_module_boundaries_module.swift
3+
// RUN: %target-swift-frontend -I %t -emit-sil -verify %s
4+
5+
// SR-15807:
6+
// Associated Type Inference fails across module boundaries
7+
// Self bounds from where clause cannot be accessed across modules.
8+
// This test is intended to test whether it can use generic signature to get self bounds.
9+
import Foundation
10+
import ModuleA
11+
12+
struct ModuleBFoo: Codable, DefaultsSerializable {
13+
}
14+
15+
enum ModuleBBar: Int, Codable, DefaultsSerializable { // expected-error {{type 'ModuleBBar' does not conform to protocol 'DefaultsSerializable'}}
16+
case foo, bar
17+
}

0 commit comments

Comments
 (0)