Skip to content

[Type checker] Remove some pointless cached state from the type checker. #22342

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 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
49 changes: 25 additions & 24 deletions lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,46 +420,47 @@ Type TypeChecker::getUnsafeMutablePointerType(SourceLoc loc, Type pointeeType) {
return getPointerType(*this, loc, pointeeType, PTK_UnsafeMutablePointer);
}

static Type getStdlibType(TypeChecker &TC, Type &cached, DeclContext *dc,
StringRef name) {
if (cached.isNull()) {
ModuleDecl *stdlib = TC.Context.getStdlibModule();
LookupTypeResult lookup = TC.lookupMemberType(dc, ModuleType::get(stdlib),
TC.Context.getIdentifier(
name));
if (lookup)
cached = lookup.back().MemberType;
}
return cached;
}

Type TypeChecker::getStringType(DeclContext *dc) {
return ::getStdlibType(*this, StringType, dc, "String");
if (auto typeDecl = Context.getStringDecl())
return typeDecl->getDeclaredInterfaceType();

return Type();
}

Type TypeChecker::getSubstringType(DeclContext *dc) {
return ::getStdlibType(*this, SubstringType, dc, "Substring");
if (auto typeDecl = Context.getSubstringDecl())
return typeDecl->getDeclaredInterfaceType();

return Type();
}

Type TypeChecker::getIntType(DeclContext *dc) {
return ::getStdlibType(*this, IntType, dc, "Int");
if (auto typeDecl = Context.getIntDecl())
return typeDecl->getDeclaredInterfaceType();

return Type();
}

Type TypeChecker::getInt8Type(DeclContext *dc) {
return ::getStdlibType(*this, Int8Type, dc, "Int8");
if (auto typeDecl = Context.getInt8Decl())
return typeDecl->getDeclaredInterfaceType();

return Type();
}

Type TypeChecker::getUInt8Type(DeclContext *dc) {
return ::getStdlibType(*this, UInt8Type, dc, "UInt8");
if (auto typeDecl = Context.getUInt8Decl())
return typeDecl->getDeclaredInterfaceType();

return Type();
}

/// Find the standard type of exceptions.
///
/// We call this the "exception type" to try to avoid confusion with
/// the AST's ErrorType node.
Type TypeChecker::getExceptionType(DeclContext *dc, SourceLoc loc) {
if (NominalTypeDecl *decl = Context.getErrorDecl())
return decl->getDeclaredType();

// Not really sugar, but the actual diagnostic text is fine.
diagnose(loc, diag::sugar_type_not_found, 4);
return Type();
return Context.getErrorDecl()->getDeclaredType();
}

Type
Expand Down
9 changes: 0 additions & 9 deletions lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -663,19 +663,10 @@ class TypeChecker final : public LazyResolver {

private:
Type MaxIntegerType;
Type StringType;
Type SubstringType;
Type IntType;
Type Int8Type;
Type UInt8Type;
Type NSObjectType;
Type NSNumberType;
Type NSValueType;
Type ObjCSelectorType;
Type ExceptionType;

/// The \c Swift.UnsafeMutablePointer<T> declaration.
Optional<NominalTypeDecl *> ArrayDecl;

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