Skip to content

Commit 1b4b739

Browse files
committed
[Type checker] Remove some pointless cached state from the type checker.
We can retrieve these standard library declarations from the ASTContext easily enough, and the interface type is already cached, so do that.
1 parent b529953 commit 1b4b739

File tree

2 files changed

+25
-33
lines changed

2 files changed

+25
-33
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -420,46 +420,47 @@ Type TypeChecker::getUnsafeMutablePointerType(SourceLoc loc, Type pointeeType) {
420420
return getPointerType(*this, loc, pointeeType, PTK_UnsafeMutablePointer);
421421
}
422422

423-
static Type getStdlibType(TypeChecker &TC, Type &cached, DeclContext *dc,
424-
StringRef name) {
425-
if (cached.isNull()) {
426-
ModuleDecl *stdlib = TC.Context.getStdlibModule();
427-
LookupTypeResult lookup = TC.lookupMemberType(dc, ModuleType::get(stdlib),
428-
TC.Context.getIdentifier(
429-
name));
430-
if (lookup)
431-
cached = lookup.back().MemberType;
432-
}
433-
return cached;
434-
}
435-
436423
Type TypeChecker::getStringType(DeclContext *dc) {
437-
return ::getStdlibType(*this, StringType, dc, "String");
424+
if (auto typeDecl = Context.getStringDecl())
425+
return typeDecl->getDeclaredInterfaceType();
426+
427+
return Type();
438428
}
429+
439430
Type TypeChecker::getSubstringType(DeclContext *dc) {
440-
return ::getStdlibType(*this, SubstringType, dc, "Substring");
431+
if (auto typeDecl = Context.getSubstringDecl())
432+
return typeDecl->getDeclaredInterfaceType();
433+
434+
return Type();
441435
}
436+
442437
Type TypeChecker::getIntType(DeclContext *dc) {
443-
return ::getStdlibType(*this, IntType, dc, "Int");
438+
if (auto typeDecl = Context.getIntDecl())
439+
return typeDecl->getDeclaredInterfaceType();
440+
441+
return Type();
444442
}
443+
445444
Type TypeChecker::getInt8Type(DeclContext *dc) {
446-
return ::getStdlibType(*this, Int8Type, dc, "Int8");
445+
if (auto typeDecl = Context.getInt8Decl())
446+
return typeDecl->getDeclaredInterfaceType();
447+
448+
return Type();
447449
}
450+
448451
Type TypeChecker::getUInt8Type(DeclContext *dc) {
449-
return ::getStdlibType(*this, UInt8Type, dc, "UInt8");
452+
if (auto typeDecl = Context.getUInt8Decl())
453+
return typeDecl->getDeclaredInterfaceType();
454+
455+
return Type();
450456
}
451457

452458
/// Find the standard type of exceptions.
453459
///
454460
/// We call this the "exception type" to try to avoid confusion with
455461
/// the AST's ErrorType node.
456462
Type TypeChecker::getExceptionType(DeclContext *dc, SourceLoc loc) {
457-
if (NominalTypeDecl *decl = Context.getErrorDecl())
458-
return decl->getDeclaredType();
459-
460-
// Not really sugar, but the actual diagnostic text is fine.
461-
diagnose(loc, diag::sugar_type_not_found, 4);
462-
return Type();
463+
return Context.getErrorDecl()->getDeclaredType();
463464
}
464465

465466
Type

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -663,19 +663,10 @@ class TypeChecker final : public LazyResolver {
663663

664664
private:
665665
Type MaxIntegerType;
666-
Type StringType;
667-
Type SubstringType;
668-
Type IntType;
669-
Type Int8Type;
670-
Type UInt8Type;
671666
Type NSObjectType;
672667
Type NSNumberType;
673668
Type NSValueType;
674669
Type ObjCSelectorType;
675-
Type ExceptionType;
676-
677-
/// The \c Swift.UnsafeMutablePointer<T> declaration.
678-
Optional<NominalTypeDecl *> ArrayDecl;
679670

680671
/// The set of expressions currently being analyzed for failures.
681672
llvm::DenseMap<Expr*, Expr*> DiagnosedExprs;

0 commit comments

Comments
 (0)