Skip to content

Commit 324e36f

Browse files
committed
Sema: Remove useObjectiveCBridgeableConformances()
THere is no longer any reason to complete ClangImporter-synthesized _ObjectiveCBridgeable conformances in Sema. SILGen will determine the ones that it needs and will trigger conformance checking as needed automatically.
1 parent 33b548f commit 324e36f

File tree

5 files changed

+0
-122
lines changed

5 files changed

+0
-122
lines changed

lib/Sema/CSApply.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4736,11 +4736,6 @@ namespace {
47364736
Expr *walkToExprPost(Expr *expr) {
47374737
Expr *result = visit(expr);
47384738

4739-
// Mark any _ObjectiveCBridgeable conformances as 'used'.
4740-
if (result) {
4741-
useObjectiveCBridgeableConformances(cs.DC, cs.getType(result));
4742-
}
4743-
47444739
assert(expr == ExprStack.back());
47454740
ExprStack.pop_back();
47464741

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,14 +1632,6 @@ void markAsObjC(ValueDecl *D, ObjCReason reason,
16321632
ctx.getLazyResolver()->resolveDeclSignature(D);
16331633
}
16341634

1635-
if (!isa<TypeDecl>(D) && !isa<AccessorDecl>(D) && !isa<EnumElementDecl>(D)) {
1636-
if (ctx.getLazyResolver()) {
1637-
// Only record conformances when we have a lazy resolver.
1638-
useObjectiveCBridgeableConformances(D->getInnermostDeclContext(),
1639-
D->getInterfaceType());
1640-
}
1641-
}
1642-
16431635
if (auto method = dyn_cast<AbstractFunctionDecl>(D)) {
16441636
// Determine the foreign error convention.
16451637
if (auto baseMethod = method->getOverriddenDecl()) {

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -4309,92 +4309,6 @@ TypeChecker::LookUpConformance::operator()(
43094309
ConformanceCheckFlags::SkipConditionalRequirements));
43104310
}
43114311

4312-
/// Mark any _ObjectiveCBridgeable conformances in the given type as "used".
4313-
///
4314-
/// These conformances might not appear in any substitution lists produced
4315-
/// by Sema, since bridging is done at the SILGen level, so we have to
4316-
/// force them here to ensure SILGen can find them.
4317-
void swift::useObjectiveCBridgeableConformances(DeclContext *dc, Type type) {
4318-
class Walker : public TypeWalker {
4319-
ASTContext &Ctx;
4320-
DeclContext *DC;
4321-
ProtocolDecl *Proto;
4322-
4323-
public:
4324-
Walker(DeclContext *dc, ProtocolDecl *proto)
4325-
: Ctx(dc->getASTContext()), DC(dc), Proto(proto) { }
4326-
4327-
Action walkToTypePre(Type ty) override {
4328-
ConformanceCheckOptions options =
4329-
(ConformanceCheckFlags::InExpression |
4330-
ConformanceCheckFlags::Used |
4331-
ConformanceCheckFlags::SuppressDependencyTracking);
4332-
4333-
// If we have a nominal type, "use" its conformance to
4334-
// _ObjectiveCBridgeable if it has one.
4335-
if (auto *nominalDecl = ty->getAnyNominal()) {
4336-
if (isa<ClassDecl>(nominalDecl) || isa<ProtocolDecl>(nominalDecl))
4337-
return Action::Continue;
4338-
4339-
auto lazyResolver = Ctx.getLazyResolver();
4340-
assert(lazyResolver &&
4341-
"Cannot do conforms-to-protocol check without a type checker");
4342-
TypeChecker &tc = *static_cast<TypeChecker *>(lazyResolver);
4343-
(void)tc.conformsToProtocol(ty, Proto, DC, options,
4344-
/*ComplainLoc=*/SourceLoc());
4345-
4346-
// Set and Dictionary bridging also requires the conformance
4347-
// of the key type to Hashable.
4348-
if (nominalDecl == Ctx.getSetDecl() ||
4349-
nominalDecl == Ctx.getDictionaryDecl()) {
4350-
if (auto boundGeneric = ty->getAs<BoundGenericType>()) {
4351-
auto args = boundGeneric->getGenericArgs();
4352-
if (!args.empty()) {
4353-
auto keyType = args[0];
4354-
auto *hashableProto =
4355-
Ctx.getProtocol(KnownProtocolKind::Hashable);
4356-
if (!hashableProto)
4357-
return Action::Stop;
4358-
4359-
(void)tc.conformsToProtocol(
4360-
keyType, hashableProto, DC, options,
4361-
/*ComplainLoc=*/SourceLoc());
4362-
}
4363-
}
4364-
}
4365-
}
4366-
4367-
return Action::Continue;
4368-
}
4369-
};
4370-
4371-
auto proto =
4372-
dc->getASTContext().getProtocol(KnownProtocolKind::ObjectiveCBridgeable);
4373-
if (!proto) return;
4374-
4375-
Walker walker(dc, proto);
4376-
type.walk(walker);
4377-
}
4378-
4379-
void swift::useObjectiveCBridgeableConformancesOfArgs(
4380-
DeclContext *dc, BoundGenericType *bound) {
4381-
ASTContext &ctx = dc->getASTContext();
4382-
auto proto = ctx.getProtocol(KnownProtocolKind::ObjectiveCBridgeable);
4383-
if (!proto) return;
4384-
4385-
// Check whether the bound generic type itself is bridged to
4386-
// Objective-C.
4387-
ConformanceCheckOptions options =
4388-
(ConformanceCheckFlags::InExpression |
4389-
ConformanceCheckFlags::SuppressDependencyTracking);
4390-
auto lazyResolver = ctx.getLazyResolver();
4391-
assert(lazyResolver && "Need a type checker to check conforms-to-protocol");
4392-
auto &tc = *static_cast<TypeChecker *>(lazyResolver);
4393-
(void)tc.conformsToProtocol(
4394-
bound->getDecl()->getDeclaredType(), proto, dc,
4395-
options, /*ComplainLoc=*/SourceLoc());
4396-
}
4397-
43984312
void TypeChecker::useBridgedNSErrorConformances(DeclContext *dc, Type type) {
43994313
auto errorProto = Context.getProtocol(KnownProtocolKind::Error);
44004314
auto bridgedStoredNSError = Context.getProtocol(

lib/Sema/TypeCheckProtocol.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -937,16 +937,6 @@ llvm::TinyPtrVector<ValueDecl *> findWitnessedObjCRequirements(
937937
const ValueDecl *witness,
938938
bool anySingleRequirement = false);
939939

940-
/// Mark any _ObjectiveCBridgeable conformances in the given type as "used".
941-
void useObjectiveCBridgeableConformances(
942-
DeclContext *dc, Type type);
943-
944-
/// If this bound-generic type is bridged, mark any
945-
/// _ObjectiveCBridgeable conformances in the generic arguments of
946-
/// the given type as "used".
947-
void useObjectiveCBridgeableConformancesOfArgs(
948-
DeclContext *dc, BoundGenericType *bound);
949-
950940
}
951941

952942
#endif // SWIFT_SEMA_PROTOCOL_H

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -881,11 +881,6 @@ Type TypeChecker::applyUnboundGenericArguments(
881881
subMap, resultType);
882882
}
883883

884-
if (isa<NominalTypeDecl>(decl) && resultType) {
885-
(void)useObjectiveCBridgeableConformancesOfArgs(
886-
dc, resultType->castTo<BoundGenericType>());
887-
}
888-
889884
return resultType;
890885
}
891886

@@ -3012,9 +3007,6 @@ Type TypeResolver::resolveArrayType(ArrayTypeRepr *repr,
30123007
if (!sliceTy)
30133008
return ErrorType::get(Context);
30143009

3015-
// Check for _ObjectiveCBridgeable conformances in the element type.
3016-
useObjectiveCBridgeableConformances(DC, baseTy);
3017-
30183010
return sliceTy;
30193011
}
30203012

@@ -3045,11 +3037,6 @@ Type TypeResolver::resolveDictionaryType(DictionaryTypeRepr *repr,
30453037
return nullptr;
30463038
}
30473039

3048-
// Check for _ObjectiveCBridgeable conformances in the key and value
3049-
// types.
3050-
useObjectiveCBridgeableConformances(DC, keyTy);
3051-
useObjectiveCBridgeableConformances(DC, valueTy);
3052-
30533040
return dictTy;
30543041
}
30553042

0 commit comments

Comments
 (0)