mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.
The basic pipeline in the frontend is:
- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
set to 7 based on prior migrator seasons. Right now, this is just set
to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
file that Xcode knows how to understand.
Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.
- Add -emit-remap frontend option
This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
Useful for debugging, this skips the phase in the Migrator that
automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
This is used for testing/debugging scenarios. This takes the final
migration state's output text and writes it to the file specified
by this option.
- Add -dump-migration-states-dir
This dumps all of the migration states encountered during a migration
run for a file to the given directory. For example, the compiler
fix-it migration pass dumps the input file, the output file, and the
remap file between the two.
State output has the following naming convention:
${Index}-${MigrationPassName}-${What}.${extension}, such as:
1-FixitMigrationState-Input.swift
rdar://problem/30926261
This commit is contained in:
@@ -323,6 +323,8 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
Action = FrontendOptions::REPL;
|
||||
} else if (Opt.matches(OPT_interpret)) {
|
||||
Action = FrontendOptions::Immediate;
|
||||
} else if(Opt.matches(OPT_update_code)) {
|
||||
Action = FrontendOptions::UpdateCode;
|
||||
} else {
|
||||
llvm_unreachable("Unhandled mode option");
|
||||
}
|
||||
@@ -560,6 +562,10 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
Suffix = "importedmodules";
|
||||
break;
|
||||
|
||||
case FrontendOptions::UpdateCode:
|
||||
Suffix = REMAP_EXTENSION;
|
||||
break;
|
||||
|
||||
case FrontendOptions::EmitTBD:
|
||||
if (Opts.OutputFilenames.empty())
|
||||
Opts.setSingleOutputFilename("-");
|
||||
@@ -706,6 +712,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
case FrontendOptions::DumpTypeRefinementContexts:
|
||||
case FrontendOptions::Immediate:
|
||||
case FrontendOptions::REPL:
|
||||
case FrontendOptions::UpdateCode:
|
||||
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_dependencies);
|
||||
return true;
|
||||
case FrontendOptions::Parse:
|
||||
@@ -738,6 +745,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
case FrontendOptions::DumpTypeRefinementContexts:
|
||||
case FrontendOptions::Immediate:
|
||||
case FrontendOptions::REPL:
|
||||
case FrontendOptions::UpdateCode:
|
||||
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_header);
|
||||
return true;
|
||||
case FrontendOptions::Parse:
|
||||
@@ -773,6 +781,7 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
|
||||
case FrontendOptions::EmitSILGen:
|
||||
case FrontendOptions::Immediate:
|
||||
case FrontendOptions::REPL:
|
||||
case FrontendOptions::UpdateCode:
|
||||
if (!Opts.ModuleOutputPath.empty())
|
||||
Diags.diagnose(SourceLoc(), diag::error_mode_cannot_emit_module);
|
||||
else
|
||||
@@ -1535,6 +1544,27 @@ static bool ParseIRGenArgs(IRGenOptions &Opts, ArgList &Args,
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ParseMigratorArgs(MigratorOptions &Opts, ArgList &Args,
|
||||
DiagnosticEngine &Diags) {
|
||||
using namespace options;
|
||||
|
||||
Opts.AddObjC |= Args.hasArg(OPT_warn_swift3_objc_inference);
|
||||
|
||||
if (Args.hasArg(OPT_disable_migrator_fixits)) {
|
||||
Opts.EnableMigratorFixits = false;
|
||||
}
|
||||
|
||||
if (auto MigratedFilePath = Args.getLastArg(OPT_emit_migrated_file_path)) {
|
||||
Opts.EmitMigratedFilePath = MigratedFilePath->getValue();
|
||||
}
|
||||
|
||||
if (auto Dumpster = Args.getLastArg(OPT_dump_migration_states_dir)) {
|
||||
Opts.DumpMigrationStatesDir = Dumpster->getValue();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
|
||||
DiagnosticEngine &Diags,
|
||||
StringRef workingDirectory) {
|
||||
@@ -1597,6 +1627,10 @@ bool CompilerInvocation::parseArgs(ArrayRef<const char *> Args,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (ParseMigratorArgs(MigratorOpts, ParsedArgs, Diags)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
updateRuntimeLibraryPath(SearchPathOpts, LangOpts.Target);
|
||||
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user