Add unique typo corrections to the main diagnostic with a fix-it.

Continue to emit notes for the candidates, but use different text.
Note that we can emit a typo correction fix-it even if there are
multiple candidates with the same name.

Also, disable typo correction in the migrator, since the operation
is quite expensive, the notes are never presented to the user, and
the fix-its can interfere with the migrator's own edits.

Our general guidance is that fix-its should be added on the main
diagnostic only when the fix-it is highly likely to be correct.
The exact threshold is debateable.  Typo correction is certainly
capable of making mistakes, but most of its edits are right, and
when it's wrong it's usually obviously wrong.  On balance, I think
this is the right thing to do.  For what it's worth, it's also
what we do in Clang.
This commit is contained in:
John McCall
2018-04-06 16:32:07 -04:00
parent 478d846e36
commit 7815892a76
27 changed files with 425 additions and 196 deletions

View File

@@ -920,12 +920,11 @@ static std::string getScriptFileName(StringRef name, bool isSwiftVersion3) {
return (Twine(name) + langVer + ".json").str();
}
bool ParseMigratorArgs(MigratorOptions &Opts,
const FrontendOptions &FrontendOpts,
const llvm::Triple &Triple,
const bool isSwiftVersion3,
StringRef ResourcePath, const ArgList &Args,
DiagnosticEngine &Diags) {
static bool ParseMigratorArgs(MigratorOptions &Opts,
LangOptions &LangOpts,
const FrontendOptions &FrontendOpts,
StringRef ResourcePath, const ArgList &Args,
DiagnosticEngine &Diags) {
using namespace options;
Opts.KeepObjcVisibility |= Args.hasArg(OPT_migrate_keep_objc_visibility);
@@ -950,9 +949,13 @@ bool ParseMigratorArgs(MigratorOptions &Opts,
if (auto DataPath = Args.getLastArg(OPT_api_diff_data_file)) {
Opts.APIDigesterDataStorePaths.push_back(DataPath->getValue());
} else {
auto &Triple = LangOpts.Target;
bool isSwiftVersion3 = LangOpts.isSwiftVersion3();
bool Supported = true;
llvm::SmallString<128> dataPath(ResourcePath);
llvm::sys::path::append(dataPath, "migrator");
if (Triple.isMacOSX())
llvm::sys::path::append(dataPath,
getScriptFileName("macos", isSwiftVersion3));
@@ -991,6 +994,9 @@ bool ParseMigratorArgs(MigratorOptions &Opts,
// supplementary output for the whole compilation instead of one per input,
// so it's probably not worth it.
FrontendOpts.InputsAndOutputs.assertMustNotBeMoreThanOnePrimaryInput();
// Always disable typo-correction in the migrator.
LangOpts.TypoCorrectionLimit = 0;
}
return false;
@@ -1061,8 +1067,7 @@ bool CompilerInvocation::parseArgs(
return true;
}
if (ParseMigratorArgs(MigratorOpts, FrontendOpts, LangOpts.Target,
LangOpts.isSwiftVersion3(),
if (ParseMigratorArgs(MigratorOpts, LangOpts, FrontendOpts,
SearchPathOpts.RuntimeResourcePath, ParsedArgs, Diags)) {
return true;
}