Skip to content

Commit b3c2db9

Browse files
committed
lookupDefaultLiteralType doesn't need a TypeChecler
1 parent be23ecc commit b3c2db9

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

lib/Sema/TypeCheckExpr.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,15 +638,16 @@ Expr *TypeChecker::buildAutoClosureExpr(DeclContext *DC, Expr *expr,
638638
return closure;
639639
}
640640

641-
static Type lookupDefaultLiteralType(TypeChecker &TC, const DeclContext *dc,
641+
static Type lookupDefaultLiteralType(const DeclContext *dc,
642642
StringRef name) {
643+
auto &ctx = dc->getASTContext();
643644
auto lookupOptions = defaultUnqualifiedLookupOptions;
644645
if (isa<AbstractFunctionDecl>(dc))
645646
lookupOptions |= NameLookupFlags::KnownPrivate;
646-
auto lookup = TC.lookupUnqualified(dc->getModuleScopeContext(),
647-
TC.Context.getIdentifier(name),
648-
SourceLoc(),
649-
lookupOptions);
647+
auto lookup = TypeChecker::lookupUnqualified(dc->getModuleScopeContext(),
648+
ctx.getIdentifier(name),
649+
SourceLoc(),
650+
lookupOptions);
650651
TypeDecl *TD = lookup.getSingleTypeResult();
651652
if (!TD)
652653
return Type();
@@ -709,15 +710,12 @@ swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
709710
if (!name)
710711
return nullptr;
711712

712-
// FIXME: Creating a whole type checker just to do lookup is unnecessary.
713-
TypeChecker &tc = TypeChecker::createForContext(dc->getASTContext());
714-
715713
Type type;
716714
if (performLocalLookup)
717-
type = lookupDefaultLiteralType(tc, dc, name);
715+
type = lookupDefaultLiteralType(dc, name);
718716

719717
if (!type)
720-
type = lookupDefaultLiteralType(tc, tc.getStdlibModule(dc), name);
718+
type = lookupDefaultLiteralType(TypeChecker::getStdlibModule(dc), name);
721719

722720
// Strip off one level of sugar; we don't actually want to print
723721
// the name of the typealias itself anywhere.

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ Type TypeChecker::getObjectLiteralParameterType(ObjectLiteralExpr *expr,
209209
}
210210

211211
ModuleDecl *TypeChecker::getStdlibModule(const DeclContext *dc) {
212-
if (auto *stdlib = Context.getStdlibModule()) {
212+
if (auto *stdlib = dc->getASTContext().getStdlibModule()) {
213213
return stdlib;
214214
}
215215

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ class TypeChecker final : public LazyResolver {
17021702
///
17031703
/// This is "Swift", if that module is imported, or the current module if
17041704
/// we're parsing the standard library.
1705-
ModuleDecl *getStdlibModule(const DeclContext *dc);
1705+
static ModuleDecl *getStdlibModule(const DeclContext *dc);
17061706

17071707
/// \name Lazy resolution.
17081708
///

0 commit comments

Comments
 (0)