Skip to content

migrator: run try? migration pass only when migrating from swift<5. #21387

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 1 commit into from
Dec 18, 2018
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
7 changes: 6 additions & 1 deletion include/swift/Migrator/Migrator.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ namespace migrator {
bool updateCodeAndEmitRemapIfNeeded(CompilerInstance *Instance,
const CompilerInvocation &Invocation);

/// Specify options when running syntactic migration pass.
struct SyntacticPassOptions {
bool RunOptionalTryMigration = false;
};

struct Migrator {
CompilerInstance *StartInstance;
const CompilerInvocation &StartInvocation;
Expand Down Expand Up @@ -69,7 +74,7 @@ struct Migrator {
/// Returns true if failed:
/// - Setting up the Swift CompilerInstance failed.
/// - performSema emitted fatal errors along the way.
bool performSyntacticPasses();
bool performSyntacticPasses(SyntacticPassOptions Opts);

/// Emit a replacement map from the very start state's output text to the
/// final state's output text to the StartInvocation's output file.
Expand Down
14 changes: 10 additions & 4 deletions lib/Migrator/Migrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
// Phase 2: Syntactic Transformations
// Don't run these passes if we're already in newest Swift version.
if (EffectiveVersion != CurrentVersion) {
auto FailedSyntacticPasses = M.performSyntacticPasses();
SyntacticPassOptions Opts;

// Type of optional try changes since Swift 5.
Opts.RunOptionalTryMigration = !EffectiveVersion.isVersionAtLeast(5);
auto FailedSyntacticPasses = M.performSyntacticPasses(Opts);
if (FailedSyntacticPasses) {
return true;
}
Expand Down Expand Up @@ -173,7 +177,7 @@ Migrator::performAFixItMigration(version::Version SwiftLanguageVersion) {
return Instance;
}

bool Migrator::performSyntacticPasses() {
bool Migrator::performSyntacticPasses(SyntacticPassOptions Opts) {
clang::FileSystemOptions ClangFileSystemOptions;
clang::FileManager ClangFileManager { ClangFileSystemOptions };

Expand All @@ -197,8 +201,10 @@ bool Migrator::performSyntacticPasses() {

runAPIDiffMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
getMigratorOptions());
runOptionalTryMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
getMigratorOptions());
if (Opts.RunOptionalTryMigration) {
runOptionalTryMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
getMigratorOptions());
}

Edits.commit(Editor.getEdits());

Expand Down