File tree 4 files changed +11
-12
lines changed
tools/SourceKit/lib/SwiftLang
4 files changed +11
-12
lines changed Original file line number Diff line number Diff line change @@ -122,7 +122,9 @@ class DiagnosticConsumer {
122
122
// / Invoked whenever the frontend emits a diagnostic.
123
123
// /
124
124
// / \param SM The source manager associated with the source locations in
125
- // / this diagnostic.
125
+ // / this diagnostic. NOTE: Do not persist either the SourceManager, or the
126
+ // / buffer names from the SourceManager, since it may not outlive the
127
+ // / DiagnosticConsumer (this is the case when building module interfaces).
126
128
// /
127
129
// / \param Info Information describing the diagnostic.
128
130
virtual void handleDiagnostic (SourceManager &SM,
Original file line number Diff line number Diff line change @@ -228,11 +228,12 @@ namespace serialized_diagnostics {
228
228
unsigned SerializedDiagnosticConsumer::getEmitFile (
229
229
SourceManager &SM, StringRef Filename, unsigned bufferID
230
230
) {
231
- // NOTE: Using Filename.data() here relies on SourceMgr using
232
- // const char* as buffer identifiers. This is fast, but may
233
- // be brittle. We can always switch over to using a StringMap.
234
- // Note that the logic in EditorDiagConsumer::getBufferInfo
235
- // will also need changing.
231
+ // FIXME: Using Filename.data() here is wrong, since the provided
232
+ // SourceManager may not live as long as this consumer (which is
233
+ // the case if it's a diagnostic produced from building a module
234
+ // interface). We ought to switch over to using a StringMap once
235
+ // buffer names are unique (currently not the case for
236
+ // pretty-printed decl buffers).
236
237
unsigned &existingEntry = State->Files [Filename.data ()];
237
238
if (existingEntry)
238
239
return existingEntry;
Original file line number Diff line number Diff line change @@ -91,10 +91,6 @@ BufferInfoSharedPtr
91
91
EditorDiagConsumer::getBufferInfo (StringRef FileName,
92
92
llvm::Optional<unsigned > BufferID,
93
93
swift::SourceManager &SM) {
94
- // NOTE: Using StringRef as a key here relies on SourceMgr using const char*
95
- // as buffer identifiers. This is fast, but may be brittle. We can always
96
- // switch over to using a StringMap. Note that the logic in
97
- // SerializedDiagnosticConsumer::getEmitFile will also need changing.
98
94
auto Result = BufferInfos.find (FileName);
99
95
if (Result != BufferInfos.end ())
100
96
return Result->second ;
Original file line number Diff line number Diff line change 16
16
#include " SourceKit/Core/LangSupport.h"
17
17
#include " swift/AST/DiagnosticConsumer.h"
18
18
#include " llvm/ADT/DenseMap.h"
19
- #include " llvm/ADT/MapVector .h"
19
+ #include " llvm/ADT/StringMap .h"
20
20
21
21
namespace SourceKit {
22
22
@@ -27,7 +27,7 @@ class EditorDiagConsumer : public swift::DiagnosticConsumer {
27
27
llvm::DenseMap<unsigned , DiagnosticsTy> BufferDiagnostics;
28
28
DiagnosticsTy InvalidLocDiagnostics;
29
29
30
- llvm::MapVector<StringRef, BufferInfoSharedPtr> BufferInfos;
30
+ llvm::StringMap< BufferInfoSharedPtr> BufferInfos;
31
31
32
32
int LastDiagBufferID = -1 ;
33
33
unsigned LastDiagIndex = 0 ;
You can’t perform that action at this time.
0 commit comments