Skip to content

Commit fbad889

Browse files
committed
[Migrator] Use Version::getCurrentLanguageVersion() as latest version
1 parent 3753207 commit fbad889

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

Diff for: lib/Migrator/Migrator.cpp

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,15 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
3737
llvm::sys::fs::remove(Invocation.getMigratorOptions().EmitRemapFilePath);
3838

3939
Migrator M { Instance, Invocation }; // Provide inputs and configuration
40+
auto EffectiveVersion = Invocation.getLangOptions().EffectiveLanguageVersion;
41+
auto CurrentVersion = version::Version::getCurrentLanguageVersion();
4042

4143
// Phase 1: Pre Fix-it passes
4244
// These uses the initial frontend invocation to apply any obvious fix-its
4345
// to see if we can get an error-free AST to get to Phase 2.
4446
std::unique_ptr<swift::CompilerInstance> PreFixItInstance;
4547
if (Instance->getASTContext().hadError()) {
46-
PreFixItInstance = M.repeatFixitMigrations(2,
47-
Invocation.getLangOptions().EffectiveLanguageVersion);
48+
PreFixItInstance = M.repeatFixitMigrations(2, EffectiveVersion);
4849

4950
// If we still couldn't fix all of the errors, give up.
5051
if (PreFixItInstance == nullptr ||
@@ -56,10 +57,8 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
5657
}
5758

5859
// Phase 2: Syntactic Transformations
59-
// Don't run these passes if we're already in Swift 4.2
60-
auto Opts = Invocation.getLangOptions().EffectiveLanguageVersion;
61-
bool isFourTwo = Opts.size() == 2 && Opts[0] == 4 && Opts[1] == 2;
62-
if (!isFourTwo) {
60+
// Don't run these passes if we're already in newest Swift version.
61+
if (EffectiveVersion != CurrentVersion) {
6362
auto FailedSyntacticPasses = M.performSyntacticPasses();
6463
if (FailedSyntacticPasses) {
6564
return true;
@@ -75,7 +74,7 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
7574

7675
if (M.getMigratorOptions().EnableMigratorFixits) {
7776
M.repeatFixitMigrations(Migrator::MaxCompilerFixitPassIterations,
78-
{4, 0, 0});
77+
CurrentVersion);
7978
}
8079

8180
// OK, we have a final resulting text. Now we compare against the input

0 commit comments

Comments
 (0)