Skip to content

Commit 33ed207

Browse files
committed
Cache _MaxBuiltinFloatType
period
1 parent b3d6214 commit 33ed207

File tree

3 files changed

+34
-18
lines changed

3 files changed

+34
-18
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,9 @@ class ASTContext final {
530530

531531
// Retrieve the declaration of Swift._stdlib_isOSVersionAtLeast.
532532
FuncDecl *getIsOSVersionAtLeastDecl() const;
533+
534+
// Retrieve the declaration of Swift._MaxBuiltinFloatType.
535+
TypeAliasDecl *getMaxBuiltinFloatTypeDecl() const;
533536

534537
/// Look for the declaration with the given name within the
535538
/// Swift module.

lib/AST/ASTContext.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
206206
// -> Builtin.Int1
207207
FuncDecl *IsOSVersionAtLeastDecl = nullptr;
208208

209+
/// typealias Swift._MaxBuiltinFloatType
210+
TypeAliasDecl *MaxBuiltinFloatTypeDecl = nullptr;
211+
209212
/// The set of known protocols, lazily populated as needed.
210213
ProtocolDecl *KnownProtocols[NumKnownProtocols] = { };
211214

@@ -1177,6 +1180,25 @@ FuncDecl *ASTContext::getIsOSVersionAtLeastDecl() const {
11771180
return decl;
11781181
}
11791182

1183+
TypeAliasDecl *ASTContext::getMaxBuiltinFloatTypeDecl() const {
1184+
if (getImpl().MaxBuiltinFloatTypeDecl)
1185+
return getImpl().MaxBuiltinFloatTypeDecl;
1186+
1187+
// Go find '_MaxBuiltinFloatType' in the Swift module.
1188+
SmallVector<ValueDecl *, 1> results;
1189+
lookupInSwiftModule("_MaxBuiltinFloatType", results);
1190+
1191+
if (results.size() != 1)
1192+
return nullptr;
1193+
1194+
if (auto typeAlias = dyn_cast<TypeAliasDecl>(results.front())) {
1195+
getImpl().MaxBuiltinFloatTypeDecl = typeAlias;
1196+
return typeAlias;
1197+
}
1198+
1199+
return nullptr;
1200+
}
1201+
11801202
static bool isHigherPrecedenceThan(PrecedenceGroupDecl *a,
11811203
PrecedenceGroupDecl *b) {
11821204
assert(a != b && "exact match should already have been filtered");

lib/Sema/CSApply.cpp

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,8 +1834,6 @@ namespace {
18341834
Expr *forceBridgeFromObjectiveC(Expr *object, Type valueType) {
18351835
return bridgeFromObjectiveC(object, valueType, false);
18361836
}
1837-
1838-
TypeAliasDecl *MaxFloatTypeDecl = nullptr;
18391837

18401838
public:
18411839
ExprRewriter(ConstraintSystem &cs, const Solution &solution,
@@ -2002,25 +2000,18 @@ namespace {
20022000
type = defaultType;
20032001
}
20042002

2005-
// Find the maximum-sized builtin float type.
2006-
// FIXME: Cache name lookup.
2007-
if (!MaxFloatTypeDecl) {
2008-
SmallVector<ValueDecl *, 1> lookupResults;
2009-
tc.getStdlibModule(dc)->lookupValue(/*AccessPath=*/{},
2010-
tc.Context.Id_MaxBuiltinFloatType,
2011-
NLKind::QualifiedLookup,
2012-
lookupResults);
2013-
if (lookupResults.size() == 1)
2014-
MaxFloatTypeDecl = dyn_cast<TypeAliasDecl>(lookupResults.front());
2015-
}
2016-
if (!MaxFloatTypeDecl ||
2017-
!MaxFloatTypeDecl->hasInterfaceType() ||
2018-
!MaxFloatTypeDecl->getDeclaredInterfaceType()->is<BuiltinFloatType>()) {
2003+
// Get the _MaxBuiltinFloatType decl, or look for it if it's not cached.
2004+
auto maxFloatTypeDecl = tc.Context.getMaxBuiltinFloatTypeDecl();
2005+
2006+
if (!maxFloatTypeDecl ||
2007+
!maxFloatTypeDecl->hasInterfaceType() ||
2008+
!maxFloatTypeDecl->getDeclaredInterfaceType()->is<BuiltinFloatType>()) {
20192009
tc.diagnose(expr->getLoc(), diag::no_MaxBuiltinFloatType_found);
20202010
return nullptr;
20212011
}
2022-
tc.validateDecl(MaxFloatTypeDecl);
2023-
auto maxType = MaxFloatTypeDecl->getUnderlyingTypeLoc().getType();
2012+
2013+
tc.validateDecl(maxFloatTypeDecl);
2014+
auto maxType = maxFloatTypeDecl->getUnderlyingTypeLoc().getType();
20242015

20252016
DeclName initName(tc.Context, DeclBaseName::createConstructor(),
20262017
{ tc.Context.Id_floatLiteral });

0 commit comments

Comments
 (0)