@@ -8194,39 +8194,38 @@ bool importer::hasSameUnderlyingType(const clang::Type *a,
81948194 return a == b->getTypeForDecl ();
81958195}
81968196
8197- unsigned ClangImporter::Implementation::getClangSwiftAttrSourceBuffer (
8198- StringRef attributeText) {
8199- auto known = ClangSwiftAttrSourceBuffers. find ( attributeText);
8200- if (known != ClangSwiftAttrSourceBuffers. end ())
8201- return known-> second ;
8197+ SourceFile & ClangImporter::Implementation::getClangSwiftAttrSourceFile (
8198+ ModuleDecl & module ,
8199+ StringRef attributeText
8200+ ) {
8201+ auto &sourceFiles = ClangSwiftAttrSourceFiles[attributeText] ;
82028202
8203- // Create a new buffer with a copy of the attribute text, so we don't need to
8204- // rely on Clang keeping it around.
8203+ // Check whether we've already created a source file.
8204+ for (auto sourceFile : sourceFiles) {
8205+ if (sourceFile->getParentModule () == &module )
8206+ return *sourceFile;
8207+ }
8208+
8209+ // Create a new buffer with a copy of the attribute text,
8210+ // so we don't need to rely on Clang keeping it around.
82058211 auto &sourceMgr = SwiftContext.SourceMgr ;
82068212 auto bufferID = sourceMgr.addMemBufferCopy (attributeText);
8207- ClangSwiftAttrSourceBuffers.insert ({attributeText, bufferID});
82088213
82098214 // Note that this is for an attribute.
82108215 sourceMgr.setGeneratedSourceInfo (
82118216 bufferID,
82128217 {
82138218 GeneratedSourceInfo::Attribute,
82148219 CharSourceRange (),
8215- sourceMgr.getRangeForBuffer (bufferID)
8220+ sourceMgr.getRangeForBuffer (bufferID),
8221+ &module
82168222 }
82178223 );
8218- return bufferID;
8219- }
8220-
8221- SourceFile &ClangImporter::Implementation::getClangSwiftAttrSourceFile (
8222- ModuleDecl &module , unsigned bufferID) {
8223- auto known = ClangSwiftAttrSourceFiles.find (&module );
8224- if (known != ClangSwiftAttrSourceFiles.end ())
8225- return *known->second ;
82268224
8225+ // Create the source file.
82278226 auto sourceFile = new (SwiftContext)
82288227 SourceFile (module , SourceFileKind::Library, bufferID);
8229- ClangSwiftAttrSourceFiles. insert ({& module , sourceFile} );
8228+ sourceFiles. push_back ( sourceFile);
82308229
82318230 return *sourceFile;
82328231}
@@ -8402,17 +8401,15 @@ ClangImporter::Implementation::importSwiftAttrAttributes(Decl *MappedDecl) {
84028401 continue ;
84038402 }
84048403
8405- // Dig out a buffer with the attribute text.
8406- unsigned bufferID = getClangSwiftAttrSourceBuffer (
8407- swiftAttr->getAttribute ());
8408-
84098404 // Dig out a source file we can use for parsing.
84108405 auto &sourceFile = getClangSwiftAttrSourceFile (
8411- *MappedDecl->getDeclContext ()->getParentModule (), bufferID);
8406+ *MappedDecl->getDeclContext ()->getParentModule (),
8407+ swiftAttr->getAttribute ());
84128408
84138409 // Spin up a parser.
84148410 swift::Parser parser (
8415- bufferID, sourceFile, &SwiftContext.Diags , nullptr , nullptr );
8411+ sourceFile.getBufferID (), sourceFile, &SwiftContext.Diags ,
8412+ nullptr , nullptr );
84168413 // Prime the lexer.
84178414 parser.consumeTokenWithoutFeedingReceiver ();
84188415
0 commit comments