Skip to content

[AST] Consolidate Obj-C types on ASTContext #28128

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Use getXXXType over getXXXDecl in a bunch of places
  • Loading branch information
hamishknight committed Nov 7, 2019
commit cb0c9adc46da932d0d8536795b596e51f6385417
8 changes: 4 additions & 4 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4265,12 +4265,12 @@ Type ASTContext::getBridgedToObjC(const DeclContext *dc, Type type,
// Check whether the type is an existential that contains
// Error. If so, it's bridged to NSError.
if (type->isExistentialWithError()) {
if (auto nsErrorDecl = getNSErrorDecl()) {
if (auto nsErrorTy = getNSErrorType()) {
// The corresponding value type is Error.
if (bridgedValueType)
*bridgedValueType = getErrorDecl()->getDeclaredInterfaceType();

return nsErrorDecl->getDeclaredInterfaceType();
return nsErrorTy;
}
}

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

// Bridge to NSError.
if (auto nsErrorDecl = getNSErrorDecl())
return nsErrorDecl->getDeclaredInterfaceType();
if (auto nsErrorTy = getNSErrorType())
return nsErrorTy;
}

// No special bridging to Objective-C, but this can become an 'Any'.
Expand Down
2 changes: 1 addition & 1 deletion lib/ClangImporter/ImportType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2082,7 +2082,7 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
bool paramIsIUO;
if (kind == SpecialMethodKind::NSDictionarySubscriptGetter &&
paramTy->isObjCIdType()) {
swiftParamTy = SwiftContext.getNSCopyingDecl()->getDeclaredType();
swiftParamTy = SwiftContext.getNSCopyingType();
if (optionalityOfParam != OTK_None)
swiftParamTy = OptionalType::get(swiftParamTy);

Expand Down
4 changes: 2 additions & 2 deletions lib/PrintAsObjC/DeclAndTypePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1396,8 +1396,8 @@ class DeclAndTypePrinter::Implementation
// upper-bounded keys.
else if (swiftNominal == ctx.getDictionaryDecl() &&
isNSObjectOrAnyHashable(ctx, typeArgs[0])) {
if (auto proto = ctx.getNSCopyingDecl()) {
rewrittenArgsBuf[0] = proto->getDeclaredInterfaceType();
if (auto protoTy = ctx.getNSCopyingType()) {
rewrittenArgsBuf[0] = protoTy;
rewrittenArgsBuf[1] = typeArgs[1];
typeArgs = rewrittenArgsBuf;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/SIL/Bridging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ Type TypeConverter::getLoweredCBridgedType(AbstractionPattern pattern,
}

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

Expand Down
8 changes: 3 additions & 5 deletions lib/SIL/SILType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,10 @@ static bool isBridgedErrorClass(ASTContext &ctx, Type t) {
t = archetypeType->getSuperclass();

// NSError (TODO: and CFError) can be bridged.
auto nsErrorType = ctx.getNSErrorDecl();
if (t && nsErrorType &&
nsErrorType->getDeclaredType()->isExactSuperclassOf(t)) {
auto nsErrorType = ctx.getNSErrorType();
if (t && nsErrorType && nsErrorType->isExactSuperclassOf(t))
return true;
}


return false;
}

Expand Down
7 changes: 3 additions & 4 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
return *NSErrorConformanceToError;

auto &ctx = getASTContext();
auto nsError = ctx.getNSErrorDecl();
if (!nsError) {
auto nsErrorTy = ctx.getNSErrorType();
if (!nsErrorTy) {
NSErrorConformanceToError = nullptr;
return nullptr;
}
Expand All @@ -349,8 +349,7 @@ ProtocolConformance *SILGenModule::getNSErrorConformanceToError() {
}

auto conformance =
SwiftModule->lookupConformance(nsError->getDeclaredInterfaceType(),
cast<ProtocolDecl>(error));
SwiftModule->lookupConformance(nsErrorTy, cast<ProtocolDecl>(error));

if (conformance.isConcrete())
NSErrorConformanceToError = conformance.getConcrete();
Expand Down
4 changes: 1 addition & 3 deletions lib/SILGen/SILGenConvert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,11 +625,9 @@ ManagedValue SILGenFunction::emitExistentialErasure(
if (ctx.LangOpts.EnableObjCInterop && conformances.size() == 1 &&
conformances[0].getRequirement() == ctx.getErrorDecl() &&
ctx.getNSErrorDecl()) {
auto nsErrorDecl = ctx.getNSErrorDecl();

// If the concrete type is NSError or a subclass thereof, just erase it
// directly.
auto nsErrorType = nsErrorDecl->getDeclaredType()->getCanonicalType();
auto nsErrorType = ctx.getNSErrorType()->getCanonicalType();
if (nsErrorType->isExactSuperclassOf(concreteFormalType)) {
ManagedValue nsError = F(SGFContext());
if (nsErrorType != concreteFormalType) {
Expand Down
5 changes: 2 additions & 3 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,9 +1670,8 @@ namespace {
Expr *bridgeErrorToObjectiveC(Expr *value) {
auto &ctx = cs.getASTContext();

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

auto result = new (ctx) BridgeToObjCExpr(value, nsErrorType);
return cs.cacheType(result);
Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4097,9 +4097,7 @@ static OmissionTypeName getTypeNameForOmission(Type type) {
Type boolType;
if (auto boolDecl = ctx.getBoolDecl())
boolType = boolDecl->getDeclaredInterfaceType();
Type objcBoolType;
if (auto objcBoolDecl = ctx.getObjCBoolDecl())
objcBoolType = objcBoolDecl->getDeclaredInterfaceType();
auto objcBoolType = ctx.getObjCBoolType();

/// Determine the options associated with the given type.
auto getOptions = [&](Type type) {
Expand Down
7 changes: 3 additions & 4 deletions lib/Sema/TypeCheckConstraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4427,10 +4427,9 @@ CheckedCastKind TypeChecker::typeCheckCheckedCast(Type fromType,
if (!conformsToProtocol(toType, errorTypeProto, dc,
ConformanceCheckFlags::InExpression)
.isInvalid()) {
auto nsError = Context.getNSErrorDecl();
if (nsError) {
Type NSErrorTy = nsError->getDeclaredInterfaceType();
if (isSubtypeOf(fromType, NSErrorTy, dc)
auto nsErrorTy = Context.getNSErrorType();
if (nsErrorTy) {
if (isSubtypeOf(fromType, nsErrorTy, dc)
// Don't mask "always true" warnings if NSError is cast to
// Error itself.
&& !isSubtypeOf(fromType, toType, dc))
Expand Down
7 changes: 3 additions & 4 deletions lib/Sema/TypeCheckDeclObjC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -680,11 +680,10 @@ bool swift::isRepresentableInObjC(
}

// The error type is always 'AutoreleasingUnsafeMutablePointer<NSError?>?'.
auto nsError = ctx.getNSErrorDecl();
auto nsErrorTy = ctx.getNSErrorType();
Type errorParameterType;
if (nsError) {
errorParameterType = nsError->getDeclaredInterfaceType();
errorParameterType = OptionalType::get(errorParameterType);
if (nsErrorTy) {
errorParameterType = OptionalType::get(nsErrorTy);
errorParameterType
= BoundGenericType::get(
ctx.getAutoreleasingUnsafeMutablePointerDecl(),
Expand Down