Drop uses of Optional::cache.

In preparation for the switch to llvm::Optional, which doesn't have a 'cache'
method. Given how long we spent bikeshedding over the name and how few places
we ended up using it, I didn't feel like trying to push it through on the
LLVM side.

Swift SVN r22471
This commit is contained in:
Jordan Rose
2014-10-02 18:51:36 +00:00
parent d3a9e58133
commit 2a76f18e4b
5 changed files with 49 additions and 44 deletions

View File

@@ -2465,16 +2465,16 @@ public:
GenericParamList *getGenericParamListAtDepth(unsigned depth) {
assert(Options.ContextGenericParams);
auto &paramLists = UnwrappedGenericParams.cache([&]{
if (!UnwrappedGenericParams) {
std::vector<GenericParamList *> paramLists;
for (auto *params = Options.ContextGenericParams;
params;
params = params->getOuterParameters()) {
paramLists.push_back(params);
}
return paramLists;
});
return paramLists.rbegin()[depth];
UnwrappedGenericParams = std::move(paramLists);
}
return UnwrappedGenericParams->rbegin()[depth];
}
void visitGenericTypeParamType(GenericTypeParamType *T) {

View File

@@ -4631,13 +4631,12 @@ static void setAlignmentBits(llvm::BitVector &v, Alignment align) {
const llvm::BitVector &
IRGenModule::getHeapObjectSpareBits() const {
return HeapPointerSpareBits.cache([&]{
if (!HeapPointerSpareBits) {
// Start with the spare bit mask for all pointers.
llvm::BitVector r = TargetInfo.PointerSpareBits;
HeapPointerSpareBits = TargetInfo.PointerSpareBits;
// Low bits are made available by heap object alignment.
setAlignmentBits(r, TargetInfo.HeapObjectAlignment);
return r;
});
setAlignmentBits(*HeapPointerSpareBits, TargetInfo.HeapObjectAlignment);
}
return *HeapPointerSpareBits;
}

View File

@@ -85,18 +85,21 @@ static bool hasSingletonMetatype(CanType instanceType) {
static CanType getKnownType(Optional<CanType> &cacheSlot, ASTContext &C,
StringRef moduleName, StringRef typeName) {
CanType t = cacheSlot.cache([&] {
Optional<UnqualifiedLookup> lookup
= UnqualifiedLookup::forModuleAndName(C, moduleName, typeName);
if (!lookup)
if (!cacheSlot) {
cacheSlot = ([&] {
Optional<UnqualifiedLookup> lookup
= UnqualifiedLookup::forModuleAndName(C, moduleName, typeName);
if (!lookup)
return CanType();
if (TypeDecl *typeDecl = lookup->getSingleTypeResult()) {
assert(typeDecl->getDeclaredType() &&
"bridged type must be type-checked");
return typeDecl->getDeclaredType()->getCanonicalType();
}
return CanType();
if (TypeDecl *typeDecl = lookup->getSingleTypeResult()) {
assert(typeDecl->getDeclaredType() &&
"bridged type must be type-checked");
return typeDecl->getDeclaredType()->getCanonicalType();
}
return CanType();
});
})();
}
CanType t = *cacheSlot;
// It is possible that we won't find a briding type (e.g. String) when we're
// parsing the stdlib itself.

View File

@@ -75,7 +75,7 @@ static SILDeclRef getBridgingFn(Optional<SILDeclRef> &cacheSlot,
// are hacks for cases where coming up with those types is complicated, i.e.,
// when dealing with generic bridging functions.
SILDeclRef fn = cacheSlot.cache([&] {
if (!cacheSlot) {
Optional<UnqualifiedLookup> lookup
= UnqualifiedLookup::forModuleAndName(SGM.M.getASTContext(),
moduleName,
@@ -138,15 +138,15 @@ static SILDeclRef getBridgingFn(Optional<SILDeclRef> &cacheSlot,
llvm::report_fatal_error("unable to set up the ObjC bridge!");
}
return c;
});
cacheSlot = c;
}
DEBUG(llvm::dbgs() << "bridging function "
<< moduleName << '.' << functionName
<< " mapped to ";
fn.print(llvm::dbgs()));
cacheSlot->print(llvm::dbgs()));
return fn;
return *cacheSlot;
}
static SILType getStringTy(SILGenModule &SGM) {

View File

@@ -170,24 +170,27 @@ Module *TypeChecker::getStdlibModule(const DeclContext *dc) {
}
Type TypeChecker::lookupBoolType(const DeclContext *dc) {
return boolType.cache([&]{
UnqualifiedLookup boolLookup(Context.getIdentifier("Bool"),
getStdlibModule(dc), nullptr,
SourceLoc(),
/*IsTypeLookup=*/true);
if (!boolLookup.isSuccess()) {
diagnose(SourceLoc(), diag::bool_type_broken);
return Type();
}
TypeDecl *tyDecl = boolLookup.getSingleTypeResult();
if (!tyDecl) {
diagnose(SourceLoc(), diag::bool_type_broken);
return Type();
}
return tyDecl->getDeclaredType();
});
if (!boolType) {
boolType = ([&] {
UnqualifiedLookup boolLookup(Context.getIdentifier("Bool"),
getStdlibModule(dc), nullptr,
SourceLoc(),
/*IsTypeLookup=*/true);
if (!boolLookup.isSuccess()) {
diagnose(SourceLoc(), diag::bool_type_broken);
return Type();
}
TypeDecl *tyDecl = boolLookup.getSingleTypeResult();
if (!tyDecl) {
diagnose(SourceLoc(), diag::bool_type_broken);
return Type();
}
return tyDecl->getDeclaredType();
})();
}
return *boolType;
}
static void bindExtensionDecl(ExtensionDecl *ED, TypeChecker &TC) {