Skip to content

Commit 12ff379

Browse files
committed
[Migrator] Don't run AST passes when in Swift 4 or later
AST passes assume that you are migrating from a version earlier than Swift 4, where declaration references and type names may be unconditionally renamed if their USRs match. For example, this can happen for TypeMemberDiffItem entries where the Objective-C USR is the same in Swift 3 and Swift 4, but the type is spelled differently in Swift 4. A concrete example of this is: `NSDocumentTypeDocumentAttribute` (Swift 3) -> `NSAttributedString.DocumentAttributeKey` (Swift 4). Although this declaration is imported differently in Swift 4, its Objective-C USR is `c:@NSDocumentTypeDocumentAttribute` for both. rdar://problem/32604558
1 parent ce8c0eb commit 12ff379

File tree

5 files changed

+31
-4
lines changed

5 files changed

+31
-4
lines changed

Diff for: lib/Migrator/Migrator.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ bool migrator::updateCodeAndEmitRemap(CompilerInstance *Instance,
5353
}
5454

5555
// Phase 2: Syntactic Transformations
56-
auto FailedSyntacticPasses = M.performSyntacticPasses();
57-
if (FailedSyntacticPasses) {
58-
return true;
56+
if (Invocation.getLangOptions().EffectiveLanguageVersion[0] < 4) {
57+
auto FailedSyntacticPasses = M.performSyntacticPasses();
58+
if (FailedSyntacticPasses) {
59+
return true;
60+
}
5961
}
6062

6163
// Phase 3: Post Fix-it Passes

Diff for: lib/Migrator/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Here are the passes:
4848
2. AST Passes
4949

5050
If the Pre-fix-it Pass was successful, or skipped because it was unnecessary, the
51-
*AST Passes* run. These include:
51+
*AST Passes* run if you are migrating *from before Swift 4*. These include:
5252

5353
- API Diff Pass
5454

Diff for: test/Migrator/DoubleEditAPI.json

+7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
[
2+
{
3+
"DiffItemKind": "TypeMemberDiffItem",
4+
"Usr": "c:@E@FooComparisonResult@FooOrderedAscending",
5+
"OldPrintedName": "FooOrderedAscending",
6+
"NewPrintedName": "orderedAscending",
7+
"NewTypeName": "FooComparisonResult"
8+
},
29
{
310
"DiffItemKind": "TypeMemberDiffItem",
411
"Usr": "c:@SA@SomeItemSet",

Diff for: test/Migrator/no_ast_passes_after_swift4.swift

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4
3+
// RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
4+
// RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result
5+
6+
import Bar
7+
func foo() -> FooComparisonResult {
8+
return FooComparisonResult.orderedAscending
9+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// REQUIRES: objc_interop
2+
// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4
3+
// RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
4+
// RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result
5+
6+
import Bar
7+
func foo() -> FooComparisonResult {
8+
return FooComparisonResult.orderedAscending
9+
}

0 commit comments

Comments
 (0)