Skip to content

[4.2-04-30][Migrator] Use Version::getCurrentLanguageVersion() as latest version #16359

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
May 4, 2018
Merged
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
13 changes: 6 additions & 7 deletions lib/Migrator/Migrator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ bool migrator::updateCodeAndEmitRemapIfNeeded(
llvm::sys::fs::remove(Invocation.getMigratorOptions().EmitRemapFilePath);

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

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

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

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

if (M.getMigratorOptions().EnableMigratorFixits) {
M.repeatFixitMigrations(Migrator::MaxCompilerFixitPassIterations,
{4, 0, 0});
CurrentVersion);
}

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