Skip to content

Commit e62a5b0

Browse files
authored
Merge pull request #41499 from slavapestov/rqm-fixes-for-abstract-signatures
Fix a couple of issues while testing with -requirement-machine-abstract-signatures=verify
2 parents e706c4e + 522273e commit e62a5b0

File tree

7 files changed

+40
-19
lines changed

7 files changed

+40
-19
lines changed

include/swift/AST/TypeMatcher.h

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,27 @@ class TypeMatcher {
229229
}
230230

231231
TRIVIAL_CASE(ModuleType)
232-
TRIVIAL_CASE(DynamicSelfType)
233232
TRIVIAL_CASE(ArchetypeType)
234233

234+
bool visitDynamicSelfType(CanDynamicSelfType firstDynamicSelf,
235+
Type secondType,
236+
Type sugaredFirstType) {
237+
if (auto secondDynamicSelf = secondType->getAs<DynamicSelfType>()) {
238+
auto firstBase = firstDynamicSelf->getSelfType();
239+
auto secondBase = secondDynamicSelf->getSelfType();
240+
auto firstSugaredBase = sugaredFirstType->getAs<DynamicSelfType>()
241+
->getSelfType();
242+
243+
if (!this->visit(CanType(firstBase), secondBase, firstSugaredBase))
244+
return false;
245+
246+
return true;
247+
}
248+
249+
return mismatch(firstDynamicSelf.getPointer(), secondType,
250+
sugaredFirstType);
251+
}
252+
235253
bool visitDependentMemberType(CanDependentMemberType firstType,
236254
Type secondType,
237255
Type sugaredFirstType) {

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,17 +226,20 @@ OpaqueResultTypeRequest::evaluate(Evaluator &evaluator,
226226
if (constraintType->hasError())
227227
return nullptr;
228228

229-
// Error out if the constraint type isn't a class or existential type.
230-
if (!constraintType->isConstraintType() &&
231-
!constraintType->getClassOrBoundGenericClass()) {
229+
RequirementKind kind;
230+
if (constraintType->isConstraintType())
231+
kind = RequirementKind::Conformance;
232+
else if (constraintType->getClassOrBoundGenericClass())
233+
kind = RequirementKind::Superclass;
234+
else {
235+
// Error out if the constraint type isn't a class or existential type.
232236
ctx.Diags.diagnose(currentRepr->getLoc(),
233237
diag::opaque_type_invalid_constraint);
234238
return nullptr;
235239
}
236240

237241
assert(!constraintType->hasArchetype());
238-
requirements.emplace_back(RequirementKind::Conformance, paramType,
239-
constraintType);
242+
requirements.emplace_back(kind, paramType, constraintType);
240243
}
241244

242245
interfaceSignature = buildGenericSignature(ctx, outerGenericSignature,

test/IRGen/dynamic_replaceable_opaque_return_type_parameter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -disable-availability-checking -enable-implicit-dynamic -enable-private-imports %S/Inputs/opaque_return_type_parameter.swift -module-name Repo -emit-module -emit-module-path %t/Repo.swiftmodule
3-
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -emit-ir | %FileCheck %s
4-
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -c -o %t/tmp.o
2+
// RUN: %target-swift-frontend -disable-availability-checking -enable-implicit-dynamic -enable-private-imports %S/Inputs/opaque_return_type_parameter.swift -module-name Repo -emit-module -emit-module-path %t/Repo.swiftmodule -requirement-machine-abstract-signatures=verify
3+
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -emit-ir -requirement-machine-abstract-signatures=verify | %FileCheck %s
4+
// RUN: %target-swift-frontend -disable-availability-checking -I %t -module-name A -swift-version 5 -primary-file %s -c -o %t/tmp.o -requirement-machine-abstract-signatures=verify
55
@_private(sourceFile: "opaque_return_type_parameter.swift") import Repo
66

77
// Make sure we are not emitting a replacement for the opaque result type used as parameter (Assoc).

test/SILGen/dynamic_self.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// RUN: %target-swift-emit-silgen -swift-version 4 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s
2-
// RUN: %target-swift-emit-sil -swift-version 4 -O %s -disable-objc-attr-requires-foundation-module -enable-objc-interop
3-
// RUN: %target-swift-emit-ir -swift-version 4 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop
1+
// RUN: %target-swift-emit-silgen -swift-version 4 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify | %FileCheck %s
2+
// RUN: %target-swift-emit-sil -swift-version 4 -O %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify
3+
// RUN: %target-swift-emit-ir -swift-version 4 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify
44

5-
// RUN: %target-swift-emit-silgen -swift-version 5 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop | %FileCheck %s
6-
// RUN: %target-swift-emit-sil -swift-version 5 -O %s -disable-objc-attr-requires-foundation-module -enable-objc-interop
7-
// RUN: %target-swift-emit-ir -swift-version 5 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop
5+
// RUN: %target-swift-emit-silgen -swift-version 5 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify | %FileCheck %s
6+
// RUN: %target-swift-emit-sil -swift-version 5 -O %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify
7+
// RUN: %target-swift-emit-ir -swift-version 5 %s -disable-objc-attr-requires-foundation-module -enable-objc-interop -requirement-machine-abstract-signatures=verify
88

99
protocol P {
1010
func f() -> Self

test/SILGen/opaque_result_type.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift
3-
// RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s | %FileCheck %s
2+
// RUN: %target-swift-frontend -emit-module -enable-library-evolution -emit-module-path=%t/resilient_struct.swiftmodule -module-name=resilient_struct %S/../Inputs/resilient_struct.swift -requirement-machine-abstract-signatures=verify
3+
// RUN: %target-swift-frontend -I %t -disable-availability-checking -emit-silgen %s -requirement-machine-abstract-signatures=verify | %FileCheck %s
44

55
import resilient_struct
66

test/type/opaque.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -typecheck -verify -requirement-machine-abstract-signatures=verify %s
22

33
protocol P {
44
func paul()

test/type/opaque_generic_superclass_constraint.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -verify %s
1+
// RUN: %target-swift-frontend -disable-availability-checking -emit-ir -verify -requirement-machine-abstract-signatures=verify %s
22

33
// rdar://problem/53318811
44

0 commit comments

Comments
 (0)