Skip to content

Commit cb0c9ad

Browse files
committed
Use getXXXType over getXXXDecl in a bunch of places
1 parent 18088b0 commit cb0c9ad

File tree

11 files changed

+26
-36
lines changed

11 files changed

+26
-36
lines changed

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4265,12 +4265,12 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
42654265
// Check whether the type is an existential that contains
42664266
// Error. If so, it's bridged to NSError.
42674267
if (type->isExistentialWithError()) {
4268-
if (auto nsErrorDecl = getNSErrorDecl()) {
4268+
if (auto nsErrorTy = getNSErrorType()) {
42694269
// The corresponding value type is Error.
42704270
if (bridgedValueType)
42714271
*bridgedValueType = getErrorDecl()->getDeclaredInterfaceType();
42724272

4273-
return nsErrorDecl->getDeclaredInterfaceType();
4273+
return nsErrorTy;
42744274
}
42754275
}
42764276

@@ -4308,8 +4308,8 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
43084308
*bridgedValueType = getErrorDecl()->getDeclaredInterfaceType();
43094309

43104310
// Bridge to NSError.
4311-
if (auto nsErrorDecl = getNSErrorDecl())
4312-
return nsErrorDecl->getDeclaredInterfaceType();
4311+
if (auto nsErrorTy = getNSErrorType())
4312+
return nsErrorTy;
43134313
}
43144314

43154315
// No special bridging to Objective-C, but this can become an 'Any'.

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2082,7 +2082,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
20822082
bool paramIsIUO;
20832083
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
20842084
paramTy->isObjCIdType()) {
2085-
swiftParamTy = SwiftContext.getNSCopyingDecl()->getDeclaredType();
2085+
swiftParamTy = SwiftContext.getNSCopyingType();
20862086
if (optionalityOfParam != OTK_None)
20872087
swiftParamTy = OptionalType::get(swiftParamTy);
20882088

lib/PrintAsObjC/DeclAndTypePrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,8 +1396,8 @@ class DeclAndTypePrinter::Implementation
13961396
// upper-bounded keys.
13971397
else if (swiftNominal == ctx.getDictionaryDecl() &&
13981398
isNSObjectOrAnyHashable(ctx, typeArgs[0])) {
1399-
if (auto proto = ctx.getNSCopyingDecl()) {
1400-
rewrittenArgsBuf[0] = proto->getDeclaredInterfaceType();
1399+
if (auto protoTy = ctx.getNSCopyingType()) {
1400+
rewrittenArgsBuf[0] = protoTy;
14011401
rewrittenArgsBuf[1] = typeArgs[1];
14021402
typeArgs = rewrittenArgsBuf;
14031403
}

lib/SIL/Bridging.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
232232
}
233233

234234
case ForeignRepresentableKind::BridgedError: {
235-
auto nsErrorDecl = M.getASTContext().getNSErrorDecl();
236-
assert(nsErrorDecl && "Cannot bridge when NSError isn't available");
237-
return nsErrorDecl->getDeclaredInterfaceType();
235+
auto nsErrorTy = M.getASTContext().getNSErrorType();
236+
assert(nsErrorTy && "Cannot bridge when NSError isn't available");
237+
return nsErrorTy;
238238
}
239239
}
240240

lib/SIL/SILType.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,10 @@ static bool isBridgedErrorClass(ASTContext &ctx, Type t) {
304304
t = archetypeType->getSuperclass();
305305

306306
// NSError (TODO: and CFError) can be bridged.
307-
auto nsErrorType = ctx.getNSErrorDecl();
308-
if (t && nsErrorType &&
309-
nsErrorType->getDeclaredType()->isExactSuperclassOf(t)) {
307+
auto nsErrorType = ctx.getNSErrorType();
308+
if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t))
310309
return true;
311-
}
312-
310+
313311
return false;
314312
}
315313

lib/SILGen/SILGen.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
336336
return *NSErrorConformanceToError;
337337

338338
auto &ctx = getASTContext();
339-
auto nsError = ctx.getNSErrorDecl();
340-
if (!nsError) {
339+
auto nsErrorTy = ctx.getNSErrorType();
340+
if (!nsErrorTy) {
341341
NSErrorConformanceToError = nullptr;
342342
return nullptr;
343343
}
@@ -349,8 +349,7 @@ ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
349349
}
350350

351351
auto conformance =
352-
SwiftModule->lookupConformance(nsError->getDeclaredInterfaceType(),
353-
cast<ProtocolDecl>(error));
352+
SwiftModule->lookupConformance(nsErrorTy, cast<ProtocolDecl>(error));
354353

355354
if (conformance.isConcrete())
356355
NSErrorConformanceToError = conformance.getConcrete();

lib/SILGen/SILGenConvert.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -625,11 +625,9 @@ ManagedValue SILGenFunction::emitExistentialErasure(
625625
if (ctx.LangOpts.EnableObjCInterop && conformances.size() == 1 &&
626626
conformances[0].getRequirement() == ctx.getErrorDecl() &&
627627
ctx.getNSErrorDecl()) {
628-
auto nsErrorDecl = ctx.getNSErrorDecl();
629-
630628
// If the concrete type is NSError or a subclass thereof, just erase it
631629
// directly.
632-
auto nsErrorType = nsErrorDecl->getDeclaredType()->getCanonicalType();
630+
auto nsErrorType = ctx.getNSErrorType()->getCanonicalType();
633631
if (nsErrorType->isExactSuperclassOf(concreteFormalType)) {
634632
ManagedValue nsError = F(SGFContext());
635633
if (nsErrorType != concreteFormalType) {

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,9 +1670,8 @@ namespace {
16701670
Expr *bridgeErrorToObjectiveC(Expr *value) {
16711671
auto &ctx = cs.getASTContext();
16721672

1673-
auto nsErrorDecl = ctx.getNSErrorDecl();
1674-
assert(nsErrorDecl && "Missing NSError?");
1675-
Type nsErrorType = nsErrorDecl->getDeclaredInterfaceType();
1673+
auto nsErrorType = ctx.getNSErrorType();
1674+
assert(nsErrorType && "Missing NSError?");
16761675

16771676
auto result = new (ctx) BridgeToObjCExpr(value, nsErrorType);
16781677
return cs.cacheType(result);

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,9 +4097,7 @@ static OmissionTypeName getTypeNameForOmission(Type type) {
40974097
Type boolType;
40984098
if (auto boolDecl = ctx.getBoolDecl())
40994099
boolType = boolDecl->getDeclaredInterfaceType();
4100-
Type objcBoolType;
4101-
if (auto objcBoolDecl = ctx.getObjCBoolDecl())
4102-
objcBoolType = objcBoolDecl->getDeclaredInterfaceType();
4100+
auto objcBoolType = ctx.getObjCBoolType();
41034101

41044102
/// Determine the options associated with the given type.
41054103
auto getOptions = [&](Type type) {

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4427,10 +4427,9 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
44274427
if (!conformsToProtocol(toType, errorTypeProto, dc,
44284428
ConformanceCheckFlags::InExpression)
44294429
.isInvalid()) {
4430-
auto nsError = Context.getNSErrorDecl();
4431-
if (nsError) {
4432-
Type NSErrorTy = nsError->getDeclaredInterfaceType();
4433-
if (isSubtypeOf(fromType, NSErrorTy, dc)
4430+
auto nsErrorTy = Context.getNSErrorType();
4431+
if (nsErrorTy) {
4432+
if (isSubtypeOf(fromType, nsErrorTy, dc)
44344433
// Don't mask "always true" warnings if NSError is cast to
44354434
// Error itself.
44364435
&& !isSubtypeOf(fromType, toType, dc))

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,11 +680,10 @@ bool swift::isRepresentableInObjC(
680680
}
681681

682682
// The error type is always 'AutoreleasingUnsafeMutablePointer<NSError?>?'.
683-
auto nsError = ctx.getNSErrorDecl();
683+
auto nsErrorTy = ctx.getNSErrorType();
684684
Type errorParameterType;
685-
if (nsError) {
686-
errorParameterType = nsError->getDeclaredInterfaceType();
687-
errorParameterType = OptionalType::get(errorParameterType);
685+
if (nsErrorTy) {
686+
errorParameterType = OptionalType::get(nsErrorTy);
688687
errorParameterType
689688
= BoundGenericType::get(
690689
ctx.getAutoreleasingUnsafeMutablePointerDecl(),

0 commit comments

Comments
 (0)