Skip to content

Commit 73f1b10

Browse files
committed
Sema: Remove useBridgedNSErrorConformances()
The walker in SILGenLazyConformance.cpp should be sufficient to catch any conformances needed at runtime, and after all the recent changes SILGen is now able to trigger lazy conformance checking and synthesis of fully-checked function bodies for accessors, which is enough to remove the explicit conformance checks from Sema in this case.
1 parent e0bba70 commit 73f1b10

File tree

4 files changed

+1
-77
lines changed

4 files changed

+1
-77
lines changed

lib/Sema/CSApply.cpp

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -285,18 +285,6 @@ namespace {
285285
const Solution &solution;
286286
bool SuppressDiagnostics;
287287

288-
/// Recognize used conformances from an imported type when we must emit
289-
/// the witness table.
290-
///
291-
/// This arises in _BridgedStoredNSError, where we wouldn't
292-
/// otherwise pull in the witness table, causing dynamic casts to
293-
/// perform incorrectly, and _ErrorCodeProtocol, where we need to
294-
/// check for _BridgedStoredNSError conformances on the
295-
/// corresponding ErrorType.
296-
void checkForImportedUsedConformances(Type toType) {
297-
cs.getTypeChecker().useBridgedNSErrorConformances(dc, toType);
298-
}
299-
300288
/// Coerce the given tuple to another tuple type.
301289
///
302290
/// \param expr The expression we're converting.
@@ -3189,7 +3177,6 @@ namespace {
31893177
auto toType = simplifyType(cs.getType(expr->getCastTypeLoc()));
31903178
auto sub = cs.coerceToRValue(expr->getSubExpr());
31913179

3192-
checkForImportedUsedConformances(toType);
31933180
expr->setSubExpr(sub);
31943181

31953182
// Set the type we checked against.
@@ -3557,7 +3544,6 @@ namespace {
35573544
// Simplify the type we're casting to.
35583545
auto toType = simplifyType(cs.getType(expr->getCastTypeLoc()));
35593546
expr->getCastTypeLoc().setType(toType);
3560-
checkForImportedUsedConformances(toType);
35613547

35623548
auto &tc = cs.getTypeChecker();
35633549

@@ -3650,7 +3636,6 @@ namespace {
36503636
toType = toType->getOptionalObjectType();
36513637

36523638
expr->getCastTypeLoc().setType(toType);
3653-
checkForImportedUsedConformances(toType);
36543639

36553640
// The subexpression is always an rvalue.
36563641
auto &tc = cs.getTypeChecker();
@@ -3729,7 +3714,6 @@ namespace {
37293714
bool isInsideIsExpr = false) {
37303715
// Simplify the type we're casting to.
37313716
auto toType = simplifyType(cs.getType(expr->getCastTypeLoc()));
3732-
checkForImportedUsedConformances(toType);
37333717
expr->getCastTypeLoc().setType(toType);
37343718

37353719
// The subexpression is always an rvalue.
@@ -7449,11 +7433,7 @@ namespace {
74497433
}
74507434

74517435
Expr *walkToExprPost(Expr *expr) override {
7452-
Expr *result = Rewriter.walkToExprPost(expr);
7453-
auto &cs = Rewriter.getConstraintSystem();
7454-
if (result && cs.hasType(result))
7455-
Rewriter.checkForImportedUsedConformances(cs.getType(result));
7456-
return result;
7436+
return Rewriter.walkToExprPost(expr);
74577437
}
74587438

74597439
/// Ignore statements.

lib/Sema/TypeCheckPattern.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,9 +1292,6 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
12921292

12931293
auto castType = IP->getCastTypeLoc().getType();
12941294

1295-
// Make sure we use any bridged NSError-related conformances.
1296-
useBridgedNSErrorConformances(dc, castType);
1297-
12981295
// Determine whether we have an imbalance in the number of optionals.
12991296
SmallVector<Type, 2> inputTypeOptionals;
13001297
type->lookThroughAllOptionalTypes(inputTypeOptionals);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,55 +4299,6 @@ TypeChecker::LookUpConformance::operator()(
42994299
ConformanceCheckFlags::SkipConditionalRequirements));
43004300
}
43014301

4302-
void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
4303-
auto errorProto = Context.getProtocol(KnownProtocolKind::Error);
4304-
auto bridgedStoredNSError = Context.getProtocol(
4305-
KnownProtocolKind::BridgedStoredNSError);
4306-
auto errorCodeProto = Context.getProtocol(
4307-
KnownProtocolKind::ErrorCodeProtocol);
4308-
auto rawProto = Context.getProtocol(
4309-
KnownProtocolKind::RawRepresentable);
4310-
4311-
if (!errorProto || !bridgedStoredNSError || !errorCodeProto || !rawProto)
4312-
return;
4313-
4314-
// The NSError: Error conformance.
4315-
if (auto nsError = Context.getNSErrorDecl()) {
4316-
validateDecl(nsError);
4317-
(void)conformsToProtocol(nsError->TypeDecl::getDeclaredInterfaceType(),
4318-
errorProto, dc, ConformanceCheckFlags::Used);
4319-
}
4320-
4321-
// _BridgedStoredNSError.
4322-
auto conformance = conformsToProtocol(type, bridgedStoredNSError, dc,
4323-
ConformanceCheckFlags::Used);
4324-
if (conformance && conformance->isConcrete()) {
4325-
// Hack: If we've used a conformance to the _BridgedStoredNSError
4326-
// protocol, also use the RawRepresentable and _ErrorCodeProtocol
4327-
// conformances on the Code associated type witness.
4328-
if (auto codeType = conformance->getTypeWitnessByName(
4329-
type, Context.Id_Code)) {
4330-
(void)conformsToProtocol(codeType, errorCodeProto, dc,
4331-
ConformanceCheckFlags::Used);
4332-
(void)conformsToProtocol(codeType, rawProto, dc,
4333-
ConformanceCheckFlags::Used);
4334-
}
4335-
}
4336-
4337-
// _ErrorCodeProtocol.
4338-
conformance =
4339-
conformsToProtocol(type, errorCodeProto, dc,
4340-
(ConformanceCheckFlags::SuppressDependencyTracking|
4341-
ConformanceCheckFlags::Used));
4342-
if (conformance && conformance->isConcrete()) {
4343-
if (Type errorType = conformance->getTypeWitnessByName(
4344-
type, Context.Id_ErrorType)) {
4345-
(void)conformsToProtocol(errorType, bridgedStoredNSError, dc,
4346-
ConformanceCheckFlags::Used);
4347-
}
4348-
}
4349-
}
4350-
43514302
void TypeChecker::checkConformance(NormalProtocolConformance *conformance) {
43524303
MultiConformanceChecker checker(*this);
43534304
checker.addConformance(conformance);

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,10 +1690,6 @@ class TypeChecker final : public LazyResolver {
16901690
/// Check that the type of the given property conforms to NSCopying.
16911691
Optional<ProtocolConformanceRef> checkConformanceToNSCopying(VarDecl *var);
16921692

1693-
/// Mark any _BridgedNSError/_BridgedStoredNSError/related
1694-
/// conformances in the given type as "used".
1695-
void useBridgedNSErrorConformances(DeclContext *dc, Type type);
1696-
16971693
/// Derive an implicit declaration to satisfy a requirement of a derived
16981694
/// protocol conformance.
16991695
///

0 commit comments

Comments
 (0)