Skip to content

Commit 807142c

Browse files
authored
Merge pull request #13364 from slavapestov/fix-default-witness-checking
Fix default witness checking
2 parents eddfe11 + fc3cf28 commit 807142c

File tree

11 files changed

+30
-48
lines changed

11 files changed

+30
-48
lines changed

include/swift/Subsystems.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ namespace swift {
184184
unsigned WarnLongExpressionTypeChecking = 0,
185185
unsigned ExpressionTimeoutThreshold = 0);
186186

187-
/// Once type checking is complete, this walks protocol requirements
188-
/// to resolve default witnesses.
189-
void finishTypeCheckingFile(SourceFile &SF);
190-
191187
/// Now that we have type-checked an entire module, perform any type
192188
/// checking that requires the full module, e.g., Objective-C method
193189
/// override checking.

lib/Frontend/Frontend.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ void CompilerInstance::finishTypeChecking(
651651
performWholeModuleTypeChecking(SF);
652652
});
653653
}
654-
forEachFileToTypeCheck([&](SourceFile &SF) { finishTypeCheckingFile(SF); });
655654
}
656655

657656
void CompilerInstance::performParseOnly(bool EvaluateConditionals) {

lib/SILGen/SILGenType.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,8 @@ class SILGenType : public TypeMemberVisitor<SILGenType> {
827827

828828
// Build a default witness table if this is a protocol.
829829
if (auto protocol = dyn_cast<ProtocolDecl>(theType)) {
830-
if (!protocol->isObjC())
830+
if (!protocol->isObjC() &&
831+
!protocol->hasFixedLayout())
831832
SGM.emitDefaultWitnessTable(protocol);
832833
return;
833834
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3969,6 +3969,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
39693969
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
39703970
TC.checkDeclCircularity(nominal);
39713971
}
3972+
if (auto protocol = dyn_cast<ProtocolDecl>(decl)) {
3973+
if (!protocol->hasFixedLayout())
3974+
TC.inferDefaultWitnesses(protocol);
3975+
}
39723976
}
39733977
}
39743978

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ struct swift::RequirementMatch {
384384
/// The set of optional adjustments performed on the witness.
385385
SmallVector<OptionalAdjustment, 2> OptionalAdjustments;
386386

387+
/// Substitutions mapping the type of the witness to the requirement
388+
/// environment.
389+
SmallVector<Substitution, 2> WitnessSubstitutions;
390+
387391
/// \brief Determine whether this match is viable.
388392
bool isViable() const {
389393
switch(Kind) {
@@ -438,8 +442,6 @@ struct swift::RequirementMatch {
438442
llvm_unreachable("Unhandled MatchKind in switch.");
439443
}
440444

441-
SmallVector<Substitution, 2> WitnessSubstitutions;
442-
443445
swift::Witness getWitness(ASTContext &ctx) const {
444446
SmallVector<Substitution, 2> syntheticSubs;
445447
auto syntheticEnv = ReqEnv->getSyntheticEnvironment();

lib/Sema/TypeChecker.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -672,15 +672,6 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
672672
}
673673
}
674674

675-
void swift::finishTypeCheckingFile(SourceFile &SF) {
676-
auto &Ctx = SF.getASTContext();
677-
TypeChecker TC(Ctx);
678-
679-
for (auto D : SF.Decls)
680-
if (auto PD = dyn_cast<ProtocolDecl>(D))
681-
TC.inferDefaultWitnesses(PD);
682-
}
683-
684675
void swift::performWholeModuleTypeChecking(SourceFile &SF) {
685676
SharedTimer("performWholeModuleTypeChecking");
686677
auto &Ctx = SF.getASTContext();

test/SILGen/protocol_resilience.swift

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -254,19 +254,6 @@ func inoutResilientProtocol(_ x: inout OtherConformingType) {
254254
inoutFunc(&OtherConformingType.staticPropertyInExtension)
255255
}
256256

257-
// Protocol is not public -- make sure default witnesses have the right linkage
258-
protocol InternalProtocol {
259-
func noDefaultF()
260-
func defaultG()
261-
}
262-
263-
extension InternalProtocol {
264-
265-
// CHECK-LABEL: sil private [transparent] [thunk] @_T019protocol_resilience16InternalProtocolP8defaultGyyF
266-
// CHECK: return
267-
func defaultG() {}
268-
}
269-
270257
// CHECK-LABEL: sil_default_witness_table P {
271258
// CHECK-NEXT: }
272259

@@ -328,8 +315,3 @@ extension InternalProtocol {
328315
// CHECK-NEXT: method #ReabstractSelfRefined.callback!setter.1: {{.*}} : @_T019protocol_resilience21ReabstractSelfRefinedP8callbackxxcvs
329316
// CHECK-NEXT: method #ReabstractSelfRefined.callback!materializeForSet.1: {{.*}} : @_T019protocol_resilience21ReabstractSelfRefinedP8callbackxxcvm
330317
// CHECK-NEXT: }
331-
332-
// CHECK-LABEL: sil_default_witness_table hidden InternalProtocol {
333-
// CHECK-NEXT: no_default
334-
// CHECK-NEXT: method #InternalProtocol.defaultG!1: {{.*}} : @_T019protocol_resilience16InternalProtocolP8defaultGyyF
335-
// CHECK-NEXT: }

test/SILGen/witness_accessibility.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ extension R {
2020

2121
public struct S : R {}
2222

23-
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}AE18privateRequirementyyF
2423
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}E17publicRequirementyyF
2524
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}E19internalRequirementyyF
25+
// CHECK-LABEL: sil private @_T021witness_accessibility1R{{.*}}AE18privateRequirementyyF
2626

2727
// CHECK-LABEL: sil private [transparent] [thunk] @_T021witness_accessibility1SVAA1R{{.*}}dELLP18privateRequirementyyFTW
2828
// CHECK-LABEL: sil private [transparent] [thunk] @_T021witness_accessibility1SVAA1QA2aDP19internalRequirementyyFTW

test/SILOptimizer/dead_function_elimination.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,3 @@ internal func donotEliminate() {
216216

217217
// CHECK-TESTING-LABEL: sil_witness_table [serialized] Adopt: Prot
218218
// CHECK-TESTING: DeadWitness{{.*}}: @{{.*}}DeadWitness
219-
220-
// CHECK-LABEL: sil_default_witness_table hidden Prot
221-
// CHECK: no_default
222-
// CHECK: no_default
223-
// CHECK: method #Prot.aliveDefaultWitness!1: {{.*}} : @{{.*}}aliveDefaultWitness
224-
// CHECK: no_default
225-
226-
// CHECK-TESTING-LABEL: sil_default_witness_table Prot
227-
// CHECK-TESTING: no_default
228-
// CHECK-TESTING: no_default
229-
// CHECK-TESTING: method #Prot.aliveDefaultWitness!1: {{.*}} : @{{.*}}aliveDefaultWitness
230-
// CHECK-TESTING: method #Prot.DeadDefaultWitness!1: {{.*}} : @{{.*}}DeadDefaultWitness
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public protocol Node: Source { }
2+
3+
public protocol Source {
4+
associatedtype Output
5+
}
6+
7+
public final class GraphNode<U>: Node {
8+
public typealias Output = U
9+
}

test/multifile/default-witness.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend -typecheck %S/Inputs/default-witness.swift -primary-file %s -enable-resilience
2+
3+
public protocol GraphType {
4+
func insert<U>(_: GraphNode<U>, _: GraphNode<U>)
5+
}
6+
7+
public extension GraphType {
8+
func insert<N: Node>(_: N, _: GraphNode<N.Output>) {}
9+
}
10+

0 commit comments

Comments
 (0)