Skip to content

Commit 74ef5eb

Browse files
committed
migrator: run try? migration pass only when migrating from swift<5.
This migration pass is version specific, so we should add an option controlling whether we should perform it.
1 parent e94abbc commit 74ef5eb

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

Diff for: include/swift/Migrator/Migrator.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ namespace migrator {
3131
bool updateCodeAndEmitRemapIfNeeded(CompilerInstance *Instance,
3232
const CompilerInvocation &Invocation);
3333

34+
/// Specify options when running syntactic migration pass.
35+
struct SyntacticPassOptions {
36+
bool RunOptionalTryMigration = false;
37+
};
38+
3439
struct Migrator {
3540
CompilerInstance *StartInstance;
3641
const CompilerInvocation &StartInvocation;
@@ -69,7 +74,7 @@ struct Migrator {
6974
/// Returns true if failed:
7075
/// - Setting up the Swift CompilerInstance failed.
7176
/// - performSema emitted fatal errors along the way.
72-
bool performSyntacticPasses();
77+
bool performSyntacticPasses(SyntacticPassOptions Opts);
7378

7479
/// Emit a replacement map from the very start state's output text to the
7580
/// final state's output text to the StartInvocation's output file.

Diff for: lib/Migrator/Migrator.cpp

+10-4
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
5959
// Phase 2: Syntactic Transformations
6060
// Don't run these passes if we're already in newest Swift version.
6161
if (EffectiveVersion != CurrentVersion) {
62-
auto FailedSyntacticPasses = M.performSyntacticPasses();
62+
SyntacticPassOptions Opts;
63+
64+
// Type of optional try changes since Swift 5.
65+
Opts.RunOptionalTryMigration = !EffectiveVersion.isVersionAtLeast(5);
66+
auto FailedSyntacticPasses = M.performSyntacticPasses(Opts);
6367
if (FailedSyntacticPasses) {
6468
return true;
6569
}
@@ -173,7 +177,7 @@ Migrator::performAFixItMigration(version::Version SwiftLanguageVersion) {
173177
return Instance;
174178
}
175179

176-
bool Migrator::performSyntacticPasses() {
180+
bool Migrator::performSyntacticPasses(SyntacticPassOptions Opts) {
177181
clang::FileSystemOptions ClangFileSystemOptions;
178182
clang::FileManager ClangFileManager { ClangFileSystemOptions };
179183

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

198202
runAPIDiffMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
199203
getMigratorOptions());
200-
runOptionalTryMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
201-
getMigratorOptions());
204+
if (Opts.RunOptionalTryMigration) {
205+
runOptionalTryMigratorPass(Editor, StartInstance->getPrimarySourceFile(),
206+
getMigratorOptions());
207+
}
202208

203209
Edits.commit(Editor.getEdits());
204210

0 commit comments

Comments
 (0)