Skip to content

Improve reporting of @objc inference issues from the Swift runtime #10406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion include/swift/Runtime/Debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ void printCurrentBacktrace(unsigned framesToSkip = 1);
/// non-fatal warning, which should be logged as a runtime issue. Please keep
/// all integer values pointer-sized.
struct RuntimeErrorDetails {
// ABI version, needs to be "1" currently.
static const uintptr_t currentVersion = 2;

// ABI version, needs to be set to "currentVersion".
uintptr_t version;

// A short hyphenated string describing the type of the issue, e.g.
Expand Down Expand Up @@ -169,6 +171,33 @@ struct RuntimeErrorDetails {
// and the pointer to the array of extra threads.
uintptr_t numExtraThreads;
Thread *threads;

// Describes a suggested fix-it. Text in [startLine:startColumn,
// endLine:endColumn) is to be replaced with replacementText.
struct FixIt {
const char *filename;
uintptr_t startLine;
uintptr_t startColumn;
uintptr_t endLine;
uintptr_t endColumn;
const char *replacementText;
};

// Describes some extra information, possible with fix-its, about the current
// runtime issue.
struct Note {
const char *description;
uintptr_t numFixIts;
FixIt *fixIts;
};

// Number of suggested fix-its, and the pointer to the array of them.
uintptr_t numFixIts;
FixIt *fixIts;

// Number of related notes, and the pointer to the array of them.
uintptr_t numNotes;
Note *notes;
};

/// Debugger hook. Calling this stops the debugger with a message and details
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/runtime/Exclusivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static void reportExclusivityConflict(ExclusivityFlags oldAction, void *oldPC,
.frames = &oldPC
};
RuntimeErrorDetails details = {
.version = 1,
.version = RuntimeErrorDetails::currentVersion,
.errorType = "exclusivity-violation",
.currentStackDescription = newAccess,
.framesToSkip = framesToSkip,
Expand Down
19 changes: 17 additions & 2 deletions stdlib/public/runtime/SwiftObject.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1435,10 +1435,25 @@ void swift_objc_swift3ImplicitObjCEntrypoint(id self, SEL selector,
sel_getName(selector));
asprintf(&nullTerminatedFilename, "%*s", (int)filenameLength, filename);

RuntimeErrorDetails::FixIt fixit = {
.filename = nullTerminatedFilename,
.startLine = line,
.endLine = line,
.startColumn = column,
.endColumn = column,
.replacementText = "@objc "
};
RuntimeErrorDetails::Note note = {
.description = "add '@objc' to expose this Swift declaration to Objective-C",
.numFixIts = 1,
.fixIts = &fixit
};
RuntimeErrorDetails details = {
.version = 1,
.version = RuntimeErrorDetails::currentVersion,
.errorType = "implicit-objc-entrypoint",
.framesToSkip = 1
.framesToSkip = 1,
.numNotes = 1,
.notes = &note
};
bool isFatal = reporter == swift::fatalError;
reportToDebugger(isFatal, message, &details);
Expand Down