Skip to content

Commit f237fba

Browse files
authored
Merge pull request #62878 from DougGregor/serialized-diag-pretty-printed-buffers
2 parents e1ac29c + 514a052 commit f237fba

File tree

8 files changed

+42
-8
lines changed

8 files changed

+42
-8
lines changed

include/swift/Basic/SourceManager.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@ class GeneratedSourceInfo {
3636

3737
/// A new function body that is replacing an existing function body.
3838
ReplacedFunctionBody,
39-
} kind;
4039

41-
/// The buffer ID for the enclosing buffer, in which originalSourceRange
42-
/// resides.
43-
unsigned originalBufferID;
40+
/// Pretty-printed declarations that have no source location.
41+
PrettyPrinted,
42+
} kind;
4443

4544
/// The source range in the enclosing buffer where this source was generated.
4645
///

lib/AST/DiagnosticEngine.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1142,6 +1142,7 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
11421142
SmallVector<std::pair<const Decl *, uint64_t>, 8> entries;
11431143
llvm::SmallString<128> buffer;
11441144
llvm::SmallString<128> bufferName;
1145+
const Decl *ppDecl = decl;
11451146
{
11461147
// The access level of the buffer we want to print. Declarations below
11471148
// this access level will be omitted from the buffer; declarations
@@ -1152,7 +1153,6 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
11521153

11531154
// Figure out which declaration to print. It's the top-most
11541155
// declaration (not a module).
1155-
const Decl *ppDecl = decl;
11561156
auto dc = decl->getDeclContext();
11571157

11581158
// FIXME: Horrible, horrible hackaround. We're not getting a
@@ -1237,6 +1237,20 @@ DiagnosticEngine::diagnosticInfoForDiagnostic(const Diagnostic &diagnostic) {
12371237
auto bufferID = SourceMgr.addMemBufferCopy(buffer, bufferName);
12381238
auto memBufferStartLoc = SourceMgr.getLocForBufferStart(bufferID);
12391239

1240+
SourceMgr.setGeneratedSourceInfo(
1241+
bufferID,
1242+
GeneratedSourceInfo{
1243+
GeneratedSourceInfo::PrettyPrinted,
1244+
SourceRange(),
1245+
SourceRange(
1246+
memBufferStartLoc,
1247+
memBufferStartLoc.getAdvancedLoc(buffer.size())
1248+
),
1249+
ASTNode(const_cast<Decl *>(ppDecl)).getOpaqueValue(),
1250+
nullptr
1251+
}
1252+
);
1253+
12401254
// Go through all of the pretty-printed entries and record their
12411255
// locations.
12421256
for (auto entry : entries) {
@@ -1318,12 +1332,18 @@ std::vector<Diagnostic> DiagnosticEngine::getGeneratedSourceBufferNotes(
13181332
break;
13191333
}
13201334

1335+
case GeneratedSourceInfo::PrettyPrinted:
1336+
break;
1337+
13211338
case GeneratedSourceInfo::ReplacedFunctionBody:
13221339
return childNotes;
13231340
}
13241341

13251342
// Walk up the stack.
13261343
currentLoc = expansionNode.getStartLoc();
1344+
if (currentLoc.isInvalid())
1345+
return childNotes;
1346+
13271347
currentBufferID = SourceMgr.findBufferContainingLoc(currentLoc);
13281348
} while (true);
13291349
}

lib/Basic/SourceLoc.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ void SourceManager::setGeneratedSourceInfo(
260260

261261
switch (info.kind) {
262262
case GeneratedSourceInfo::MacroExpansion:
263+
case GeneratedSourceInfo::PrettyPrinted:
263264
break;
264265

265266
case GeneratedSourceInfo::ReplacedFunctionBody:

lib/IDETool/CompileInstance.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ void retypeCheckFunctionBody(AbstractFunctionDecl *func,
193193
sliceBufferID,
194194
GeneratedSourceInfo{
195195
GeneratedSourceInfo::ReplacedFunctionBody,
196-
*func->getParentSourceFile()->getBufferID(),
197196
func->getOriginalBodySourceRange(),
198197
newRange,
199198
func,

lib/IDETool/IDEInspectionInstance.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,6 @@ bool IDEInspectionInstance::performCachedOperationIfPossible(
346346
newBufferID,
347347
GeneratedSourceInfo{
348348
GeneratedSourceInfo::ReplacedFunctionBody,
349-
*AFD->getParentSourceFile()->getBufferID(),
350349
AFD->getOriginalBodySourceRange(),
351350
newBodyRange,
352351
AFD,

lib/Sema/TypeCheckMacros.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,6 @@ Expr *swift::expandMacroExpr(
448448
auto macroBufferRange = sourceMgr.getRangeForBuffer(macroBufferID);
449449
GeneratedSourceInfo sourceInfo{
450450
GeneratedSourceInfo::MacroExpansion,
451-
*sourceFile->getBufferID(),
452451
expr->getSourceRange(),
453452
SourceRange(macroBufferRange.getStart(), macroBufferRange.getEnd()),
454453
ASTNode(expr).getOpaqueValue(),

test/ImportResolution/import-specific-fixits.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ import struct ambiguous.funcOrVar // expected-error{{ambiguous name 'funcOrVar'
5555
// CHECK-NEXT: Number FIXITs = 0
5656
// CHECK-NEXT: note: found this candidate
5757
// CHECK-NEXT: Number FIXITs = 0
58+
// CHECK-NEXT: CONTENTS OF FILE ambiguous_right.funcOrVar:
59+
// CHECK: public var funcOrVar: Int
60+
// CHECK: END CONTENTS OF FILE
5861
// CHECK-NEXT: note: found this candidate
5962

6063
import func ambiguous.someVar // expected-error{{ambiguous name 'someVar' in module 'ambiguous'}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: rm -f %t.*
2+
3+
// Test swift executable
4+
// RUN: %target-swift-frontend -typecheck -serialize-diagnostics-path %t.dia %s -verify
5+
// RUN: c-index-test -read-diagnostics %t.dia > %t.deserialized_diagnostics.txt 2>&1
6+
// RUN: %FileCheck --input-file=%t.deserialized_diagnostics.txt %s
7+
8+
var x = String.init // expected-error{{ambiguous use of 'init'}}
9+
// CHECK: {{.*[/\\]}}serialized-diagnostics-prettyprint.swift:[[@LINE-1]]:9: error: ambiguous use of 'init'
10+
11+
// CHECK: Swift.String:2:23: note: found this candidate
12+
// CHECK: CONTENTS OF FILE Swift.String:
13+
// CHECK: extension String {
14+
// CHECK: public init(_ content: Substring.UnicodeScalarView)

0 commit comments

Comments
 (0)