Skip to content

Commit 33e6c0f

Browse files
committed
[AST] Also cache protocol kind in getBuiltinInitDecl
Make sure we don't return the wrong witness if you query with 2 different builtin protocol kinds.
1 parent 92e5e7b commit 33e6c0f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/AST/ASTContext.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,9 @@ struct ASTContext::Implementation {
525525

526526
/// The builtin initializer witness for a literal. Used when building
527527
/// LiteralExprs in fully-checked AST.
528-
llvm::DenseMap<const NominalTypeDecl *, ConcreteDeclRef> BuiltinInitWitness;
528+
llvm::DenseMap<std::pair<const NominalTypeDecl *, KnownProtocolKind>,
529+
ConcreteDeclRef>
530+
BuiltinInitWitness;
529531

530532
/// Mapping from the function decl to its original body's source range. This
531533
/// is populated if the body is reparsed from other source buffers.
@@ -1686,11 +1688,12 @@ ASTContext::getStringBuiltinInitDecl(NominalTypeDecl *stringDecl) const {
16861688
return getBuiltinInitDecl(stringDecl, builtinProtocolKind, fn);
16871689
}
16881690

1689-
ConcreteDeclRef
1690-
ASTContext::getBuiltinInitDecl(NominalTypeDecl *decl,
1691-
KnownProtocolKind builtinProtocolKind,
1692-
llvm::function_ref<DeclName (ASTContext &ctx)> initName) const {
1693-
auto &witness = getImpl().BuiltinInitWitness[decl];
1691+
ConcreteDeclRef ASTContext::getBuiltinInitDecl(
1692+
NominalTypeDecl *decl, KnownProtocolKind builtinProtocolKind,
1693+
llvm::function_ref<DeclName(ASTContext &ctx)> initName) const {
1694+
// Note the initializer name is expected to be unique for each protocol kind
1695+
// so we don't need it to be part of the key.
1696+
auto &witness = getImpl().BuiltinInitWitness[{decl, builtinProtocolKind}];
16941697
if (witness)
16951698
return witness;
16961699

0 commit comments

Comments
 (0)