Skip to content

Commit bd5adeb

Browse files
authored
Merge pull request #16779 from nkcsgexi/mig-05-22
[4.2] Cherry-pick migrator changes.
2 parents 8e5ab3c + 8d3a728 commit bd5adeb

File tree

7 files changed

+87
-280
lines changed

7 files changed

+87
-280
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -260,21 +260,6 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
260260
SF->getASTContext().SourceMgr, Range).str() == "nil";
261261
}
262262

263-
bool isDotMember(CharSourceRange Range) {
264-
auto S = Range.str();
265-
return S.startswith(".") && S.substr(1).find(".") == StringRef::npos;
266-
}
267-
268-
bool isDotMember(SourceRange Range) {
269-
return isDotMember(Lexer::getCharSourceRangeFromSourceRange(
270-
SF->getASTContext().SourceMgr, Range));
271-
}
272-
273-
bool isDotMember(Expr *E) {
274-
auto Range = E->getSourceRange();
275-
return Range.isValid() && isDotMember(Range);
276-
}
277-
278263
std::vector<APIDiffItem*> getRelatedDiffItems(ValueDecl *VD) {
279264
std::vector<APIDiffItem*> results;
280265
auto addDiffItems = [&](ValueDecl *VD) {
@@ -323,11 +308,11 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
323308
}
324309

325310

326-
bool isSimpleReplacement(APIDiffItem *Item, bool isDotMember, std::string &Text) {
311+
bool isSimpleReplacement(APIDiffItem *Item, std::string &Text) {
327312
if (auto *MD = dyn_cast<TypeMemberDiffItem>(Item)) {
328313
if (MD->Subkind == TypeMemberDiffItemSubKind::SimpleReplacement) {
329-
Text = (llvm::Twine(isDotMember ? "" : MD->newTypeName) + "." +
330-
MD->getNewName().base()).str();
314+
Text = (llvm::Twine(MD->newTypeName) + "." + MD->getNewName().base()).
315+
str();
331316
return true;
332317
}
333318
}
@@ -390,7 +375,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
390375
Type T, ReferenceMetaData Data) override {
391376
for (auto *Item: getRelatedDiffItems(CtorTyRef ? CtorTyRef: D)) {
392377
std::string RepText;
393-
if (isSimpleReplacement(Item, isDotMember(Range), RepText)) {
378+
if (isSimpleReplacement(Item, RepText)) {
394379
Editor.replace(Range, RepText);
395380
return true;
396381
}
@@ -465,9 +450,8 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
465450
for (auto *I: getRelatedDiffItems(VD)) {
466451
if (auto *Item = dyn_cast<TypeMemberDiffItem>(I)) {
467452
if (Item->Subkind == TypeMemberDiffItemSubKind::QualifiedReplacement) {
468-
Editor.replace(ToReplace,
469-
(llvm::Twine(isDotMember(ToReplace) ? "" : Item->newTypeName) + "." +
470-
Item->getNewName().base()).str());
453+
Editor.replace(ToReplace, (llvm::Twine(Item->newTypeName) + "." +
454+
Item->getNewName().base()).str());
471455
return true;
472456
}
473457
}
@@ -741,7 +725,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
741725
StringRef LeftComment;
742726
StringRef RightComment;
743727
for (auto *Item: getRelatedDiffItems(RD)) {
744-
if (isSimpleReplacement(Item, isDotMember(Reference), Rename)) {
728+
if (isSimpleReplacement(Item, Rename)) {
745729
} else if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
746730
if (CI->isStringRepresentableChange() &&
747731
CI->NodeKind == SDKNodeKind::DeclVar) {

test/Migrator/qualified-replacement.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ func foo() {
1414
_ = Cities.CityKind.Town
1515
_ = ToplevelType()
1616
_ = ToplevelType(recordName: "")
17-
bar(.orderedSame)
1817
}
1918

2019
func foo(_: ToplevelType) {}
21-
func bar(_ : FooComparisonResult) {}

test/Migrator/qualified-replacement.swift.expected

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ func foo() {
1010
_ = NewPropertyUserInterface.newFieldPlus
1111
NewPropertyUserInterface.newMethodPlus(1)
1212
_ = NewFooComparisonResult.NewFooOrderedSame
13-
let _ : FooComparisonResult = .NewFooOrderedSame
13+
let _ : FooComparisonResult = NewFooComparisonResult.NewFooOrderedSame
1414
_ = NewCityKind.NewTown
1515
_ = ToplevelWrapper.internalType()
1616
_ = ToplevelWrapper.internalType(recordName: "")
17-
bar(.NewFooOrderedSame)
1817
}
1918

2019
func foo(_: ToplevelWrapper.internalType) {}
21-
func bar(_ : FooComparisonResult) {}

test/api-digester/Outputs/apinotes-migrator-gen-revert.json

Lines changed: 13 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,9 @@
22
{
33
"DiffItemKind": "CommonDiffItem",
44
"NodeKind": "Function",
5-
"NodeAnnotation": "TypeRewritten",
6-
"ChildIndex": "1:0",
7-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
8-
"LeftComment": "AnimalAttributeName",
9-
"RightUsr": "",
10-
"RightComment": "String",
11-
"ModuleName": "APINotesTest"
12-
},
13-
{
14-
"DiffItemKind": "CommonDiffItem",
15-
"NodeKind": "Function",
16-
"NodeAnnotation": "RevertDictionaryKeyUpdate",
5+
"NodeAnnotation": "RevertSimpleStringRepresentableUpdate",
176
"ChildIndex": "1",
18-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
7+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleAttribute:",
198
"LeftComment": "",
209
"RightUsr": "",
2110
"RightComment": "",
@@ -25,30 +14,8 @@
2514
"DiffItemKind": "CommonDiffItem",
2615
"NodeKind": "Function",
2716
"NodeAnnotation": "TypeRewritten",
28-
"ChildIndex": "1:0",
29-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
30-
"LeftComment": "AnimalAttributeName",
31-
"RightUsr": "",
32-
"RightComment": "String",
33-
"ModuleName": "APINotesTest"
34-
},
35-
{
36-
"DiffItemKind": "CommonDiffItem",
37-
"NodeKind": "Function",
38-
"NodeAnnotation": "RevertDictionaryKeyUpdate",
3917
"ChildIndex": "1",
40-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
41-
"LeftComment": "",
42-
"RightUsr": "",
43-
"RightComment": "",
44-
"ModuleName": "APINotesTest"
45-
},
46-
{
47-
"DiffItemKind": "CommonDiffItem",
48-
"NodeKind": "Function",
49-
"NodeAnnotation": "TypeRewritten",
50-
"ChildIndex": "1:0:0",
51-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
18+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleAttribute:",
5219
"LeftComment": "AnimalAttributeName",
5320
"RightUsr": "",
5421
"RightComment": "String",
@@ -57,9 +24,9 @@
5724
{
5825
"DiffItemKind": "CommonDiffItem",
5926
"NodeKind": "Function",
60-
"NodeAnnotation": "RevertOptionalDictionaryKeyUpdate",
27+
"NodeAnnotation": "RevertSimpleOptionalStringRepresentableUpdate",
6128
"ChildIndex": "1",
62-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
29+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
6330
"LeftComment": "",
6431
"RightUsr": "",
6532
"RightComment": "",
@@ -69,8 +36,8 @@
6936
"DiffItemKind": "CommonDiffItem",
7037
"NodeKind": "Function",
7138
"NodeAnnotation": "TypeRewritten",
72-
"ChildIndex": "1:0:0",
73-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
39+
"ChildIndex": "1:0",
40+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
7441
"LeftComment": "AnimalAttributeName",
7542
"RightUsr": "",
7643
"RightComment": "String",
@@ -79,9 +46,9 @@
7946
{
8047
"DiffItemKind": "CommonDiffItem",
8148
"NodeKind": "Function",
82-
"NodeAnnotation": "RevertOptionalDictionaryKeyUpdate",
49+
"NodeAnnotation": "RevertDictionaryKeyUpdate",
8350
"ChildIndex": "1",
84-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
51+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
8552
"LeftComment": "",
8653
"RightUsr": "",
8754
"RightComment": "",
@@ -92,7 +59,7 @@
9259
"NodeKind": "Function",
9360
"NodeAnnotation": "TypeRewritten",
9461
"ChildIndex": "1:0",
95-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
62+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributes:",
9663
"LeftComment": "AnimalAttributeName",
9764
"RightUsr": "",
9865
"RightComment": "String",
@@ -123,9 +90,9 @@
12390
{
12491
"DiffItemKind": "CommonDiffItem",
12592
"NodeKind": "Function",
126-
"NodeAnnotation": "RevertArrayMemberUpdate",
93+
"NodeAnnotation": "RevertOptionalDictionaryKeyUpdate",
12794
"ChildIndex": "1",
128-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingAttributesArray:",
95+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
12996
"LeftComment": "",
13097
"RightUsr": "",
13198
"RightComment": "",
@@ -136,7 +103,7 @@
136103
"NodeKind": "Function",
137104
"NodeAnnotation": "TypeRewritten",
138105
"ChildIndex": "1:0:0",
139-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
106+
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributes:",
140107
"LeftComment": "AnimalAttributeName",
141108
"RightUsr": "",
142109
"RightComment": "String",
@@ -164,61 +131,6 @@
164131
"RightComment": "String",
165132
"ModuleName": "APINotesTest"
166133
},
167-
{
168-
"DiffItemKind": "CommonDiffItem",
169-
"NodeKind": "Function",
170-
"NodeAnnotation": "RevertOptionalArrayMemberUpdate",
171-
"ChildIndex": "1",
172-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(im)animalStatusDescriptorByAddingOptionalAttributesArray:",
173-
"LeftComment": "",
174-
"RightUsr": "",
175-
"RightComment": "",
176-
"ModuleName": "APINotesTest"
177-
},
178-
{
179-
"DiffItemKind": "CommonDiffItem",
180-
"NodeKind": "Function",
181-
"NodeAnnotation": "TypeRewritten",
182-
"ChildIndex": "1:0",
183-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
184-
"LeftComment": "AnimalAttributeName",
185-
"RightUsr": "",
186-
"RightComment": "String",
187-
"ModuleName": "APINotesTest"
188-
},
189-
{
190-
"DiffItemKind": "CommonDiffItem",
191-
"NodeKind": "Function",
192-
"NodeAnnotation": "RevertSimpleOptionalStringRepresentableUpdate",
193-
"ChildIndex": "1",
194-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleOptionalAttribute:",
195-
"LeftComment": "",
196-
"RightUsr": "",
197-
"RightComment": "",
198-
"ModuleName": "APINotesTest"
199-
},
200-
{
201-
"DiffItemKind": "CommonDiffItem",
202-
"NodeKind": "Function",
203-
"NodeAnnotation": "RevertSimpleStringRepresentableUpdate",
204-
"ChildIndex": "1",
205-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleAttribute:",
206-
"LeftComment": "",
207-
"RightUsr": "",
208-
"RightComment": "",
209-
"ModuleName": "APINotesTest"
210-
},
211-
{
212-
"DiffItemKind": "CommonDiffItem",
213-
"NodeKind": "Function",
214-
"NodeAnnotation": "TypeRewritten",
215-
"ChildIndex": "1",
216-
"LeftUsr": "c:objc(cs)AnimalStatusDescriptor(cm)animalStatusSingleAttribute:",
217-
"LeftComment": "AnimalAttributeName",
218-
"RightUsr": "",
219-
"RightComment": "String",
220-
"ModuleName": "APINotesTest"
221-
},
222134
{
223135
"DiffItemKind": "CommonDiffItem",
224136
"NodeKind": "TypeDecl",

0 commit comments

Comments
 (0)