Skip to content

Commit dec7091

Browse files
committed
---
yaml --- r: 343607 b: refs/heads/master-rebranch c: 9da2e86 h: refs/heads/master i: 343605: 1a940b0 343603: 736d226 343599: 24eb3f8
1 parent f2afad1 commit dec7091

File tree

4 files changed

+39
-71
lines changed

4 files changed

+39
-71
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: eb79f3e528185b866f178c3a9692938fe82017d4
1458+
refs/heads/master-rebranch: 9da2e864d00b38a862c02a7b72cb66ae7a5ba7df
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

branches/master-rebranch/include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -507,20 +507,6 @@ class DefaultTypeRequest
507507
bool isCached() const { return true; }
508508
Optional<Type> getCachedResult() const;
509509
void cacheResult(Type value) const;
510-
511-
private:
512-
KnownProtocolKind getKnownProtocolKind() const {
513-
return std::get<0>(getStorage());
514-
}
515-
const DeclContext *getDeclContext() const {
516-
return std::get<1>(getStorage());
517-
}
518-
519-
static const char *getTypeName(KnownProtocolKind);
520-
static bool getPerformLocalLookup(KnownProtocolKind);
521-
TypeChecker &getTypeChecker() const;
522-
SourceFile *getSourceFile() const;
523-
Type &getCache() const;
524510
};
525511

526512
/// Retrieve information about a property wrapper type.

branches/master-rebranch/lib/AST/TypeCheckRequests.cpp

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -508,49 +508,20 @@ void swift::simple_display(llvm::raw_ostream &out,
508508
// DefaultTypeRequest caching.
509509
//----------------------------------------------------------------------------//
510510

511-
SourceFile *DefaultTypeRequest::getSourceFile() const {
512-
return getDeclContext()->getParentSourceFile();
513-
}
514-
515-
Type &DefaultTypeRequest::getCache() const {
516-
return getDeclContext()->getASTContext().getDefaultTypeRequestCache(
517-
getSourceFile(), getKnownProtocolKind());
518-
}
519-
520511
Optional<Type> DefaultTypeRequest::getCachedResult() const {
521-
auto const &cachedType = getCache();
512+
auto *DC = std::get<1>(getStorage());
513+
auto knownProtocolKind = std::get<0>(getStorage());
514+
const auto &cachedType = DC->getASTContext().getDefaultTypeRequestCache(
515+
DC->getParentSourceFile(), knownProtocolKind);
522516
return cachedType ? Optional<Type>(cachedType) : None;
523517
}
524518

525-
void DefaultTypeRequest::cacheResult(Type value) const { getCache() = value; }
526-
527-
const char *
528-
DefaultTypeRequest::getTypeName(const KnownProtocolKind knownProtocolKind) {
529-
switch (knownProtocolKind) {
530-
531-
// clang-format off
532-
# define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, Name, typeName, performLocalLookup) \
533-
case KnownProtocolKind::Id: return typeName;
534-
# include "swift/AST/KnownProtocols.def"
535-
# undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
536-
//clang-format on
537-
538-
default: return nullptr;
539-
}
540-
}
541-
542-
bool DefaultTypeRequest::getPerformLocalLookup(const KnownProtocolKind knownProtocolKind) {
543-
switch (knownProtocolKind) {
544-
545-
// clang-format off
546-
# define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, Name, typeName, performLocalLookup) \
547-
case KnownProtocolKind::Id: return performLocalLookup;
548-
# include "swift/AST/KnownProtocols.def"
549-
# undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
550-
//clang-format on
551-
552-
default: return false;
553-
}
519+
void DefaultTypeRequest::cacheResult(Type value) const {
520+
auto *DC = std::get<1>(getStorage());
521+
auto knownProtocolKind = std::get<0>(getStorage());
522+
auto &cacheEntry = DC->getASTContext().getDefaultTypeRequestCache(
523+
DC->getParentSourceFile(), knownProtocolKind);
524+
cacheEntry = value;
554525
}
555526

556527
bool PropertyWrapperTypeInfoRequest::isCached() const {

branches/master-rebranch/lib/Sema/TypeCheckExpr.cpp

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -663,39 +663,54 @@ static Optional<KnownProtocolKind>
663663
getKnownProtocolKindIfAny(const ProtocolDecl *protocol) {
664664
TypeChecker &tc = TypeChecker::createForContext(protocol->getASTContext());
665665

666-
// clang-format off
667-
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, _, __, ___) \
668-
if (protocol == tc.getProtocol(SourceLoc(), KnownProtocolKind::Id)) \
669-
return KnownProtocolKind::Id;
670-
#include "swift/AST/KnownProtocols.def"
671-
#undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
672-
// clang-format on
666+
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, _, __, ___) \
667+
if (protocol == tc.getProtocol(SourceLoc(), KnownProtocolKind::Id)) \
668+
return KnownProtocolKind::Id;
669+
#include "swift/AST/KnownProtocols.def"
670+
#undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
673671

674672
return None;
675673
}
676674

677675
Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) {
678676
if (auto knownProtocolKindIfAny = getKnownProtocolKindIfAny(protocol)) {
679-
Type t = evaluateOrDefault(
677+
return evaluateOrDefault(
680678
Context.evaluator,
681679
DefaultTypeRequest{knownProtocolKindIfAny.getValue(), dc}, nullptr);
682-
return t;
683680
}
684-
return nullptr;
681+
return Type();
682+
}
683+
684+
static std::pair<const char *, bool> lookupDefaultTypeInfoForKnownProtocol(
685+
const KnownProtocolKind knownProtocolKind) {
686+
switch (knownProtocolKind) {
687+
#define EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME(Id, Name, typeName, \
688+
performLocalLookup) \
689+
case KnownProtocolKind::Id: \
690+
return {typeName, performLocalLookup};
691+
#include "swift/AST/KnownProtocols.def"
692+
#undef EXPRESSIBLE_BY_LITERAL_PROTOCOL_WITH_NAME
693+
default:
694+
return {nullptr, false};
695+
}
685696
}
686697

687698
llvm::Expected<Type>
688699
swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
689700
KnownProtocolKind knownProtocolKind,
690701
const DeclContext *dc) const {
691-
const char *const name = getTypeName(knownProtocolKind);
702+
const char *name;
703+
bool performLocalLookup;
704+
std::tie(name, performLocalLookup) =
705+
lookupDefaultTypeInfoForKnownProtocol(knownProtocolKind);
692706
if (!name)
693707
return nullptr;
694708

695-
TypeChecker &tc = getTypeChecker();
709+
// FIXME: Creating a whole type checker just to do lookup is unnecessary.
710+
TypeChecker &tc = TypeChecker::createForContext(dc->getASTContext());
696711

697712
Type type;
698-
if (getPerformLocalLookup(knownProtocolKind))
713+
if (performLocalLookup)
699714
type = lookupDefaultLiteralType(tc, dc, name);
700715

701716
if (!type)
@@ -710,10 +725,6 @@ swift::DefaultTypeRequest::evaluate(Evaluator &evaluator,
710725
return type;
711726
}
712727

713-
TypeChecker &DefaultTypeRequest::getTypeChecker() const {
714-
return TypeChecker::createForContext(getDeclContext()->getASTContext());
715-
}
716-
717728
Expr *TypeChecker::foldSequence(SequenceExpr *expr, DeclContext *dc) {
718729
ArrayRef<Expr*> Elts = expr->getElements();
719730
assert(Elts.size() > 1 && "inadequate number of elements in sequence");

0 commit comments

Comments
 (0)