Skip to content

Commit 34d69b0

Browse files
authored
Merge pull request #10528 from kubamracek/4.0-runtime-reporting-improve-objc-inference
[4.0] Improve reporting of @objc inference issues from the Swift runtime
2 parents 29bd6c3 + 5cc1fc6 commit 34d69b0

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

include/swift/Runtime/Debug.h

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,9 @@ void printCurrentBacktrace(unsigned framesToSkip = 1);
139139
/// non-fatal warning, which should be logged as a runtime issue. Please keep
140140
/// all integer values pointer-sized.
141141
struct RuntimeErrorDetails {
142-
// ABI version, needs to be "1" currently.
142+
static const uintptr_t currentVersion = 2;
143+
144+
// ABI version, needs to be set to "currentVersion".
143145
uintptr_t version;
144146

145147
// A short hyphenated string describing the type of the issue, e.g.
@@ -169,6 +171,33 @@ struct RuntimeErrorDetails {
169171
// and the pointer to the array of extra threads.
170172
uintptr_t numExtraThreads;
171173
Thread *threads;
174+
175+
// Describes a suggested fix-it. Text in [startLine:startColumn,
176+
// endLine:endColumn) is to be replaced with replacementText.
177+
struct FixIt {
178+
const char *filename;
179+
uintptr_t startLine;
180+
uintptr_t startColumn;
181+
uintptr_t endLine;
182+
uintptr_t endColumn;
183+
const char *replacementText;
184+
};
185+
186+
// Describes some extra information, possible with fix-its, about the current
187+
// runtime issue.
188+
struct Note {
189+
const char *description;
190+
uintptr_t numFixIts;
191+
FixIt *fixIts;
192+
};
193+
194+
// Number of suggested fix-its, and the pointer to the array of them.
195+
uintptr_t numFixIts;
196+
FixIt *fixIts;
197+
198+
// Number of related notes, and the pointer to the array of them.
199+
uintptr_t numNotes;
200+
Note *notes;
172201
};
173202

174203
enum: uintptr_t {

stdlib/public/runtime/Exclusivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static void reportExclusivityConflict(ExclusivityFlags oldAction, void *oldPC,
113113
.frames = &oldPC
114114
};
115115
RuntimeErrorDetails details = {
116-
.version = 1,
116+
.version = RuntimeErrorDetails::currentVersion,
117117
.errorType = "exclusivity-violation",
118118
.currentStackDescription = newAccess,
119119
.framesToSkip = framesToSkip,

stdlib/public/runtime/SwiftObject.mm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,10 +1435,25 @@ void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
14351435
sel_getName(selector));
14361436
asprintf(&nullTerminatedFilename, "%*s", (int)filenameLength, filename);
14371437

1438+
RuntimeErrorDetails::FixIt fixit = {
1439+
.filename = nullTerminatedFilename,
1440+
.startLine = line,
1441+
.endLine = line,
1442+
.startColumn = column,
1443+
.endColumn = column,
1444+
.replacementText = "@objc "
1445+
};
1446+
RuntimeErrorDetails::Note note = {
1447+
.description = "add '@objc' to expose this Swift declaration to Objective-C",
1448+
.numFixIts = 1,
1449+
.fixIts = &fixit
1450+
};
14381451
RuntimeErrorDetails details = {
1439-
.version = 1,
1452+
.version = RuntimeErrorDetails::currentVersion,
14401453
.errorType = "implicit-objc-entrypoint",
1441-
.framesToSkip = 1
1454+
.framesToSkip = 1,
1455+
.numNotes = 1,
1456+
.notes = &note
14421457
};
14431458
uintptr_t runtime_error_flags = RuntimeErrorFlagNone;
14441459
if (reporter == swift::fatalError)

0 commit comments

Comments
 (0)