Skip to content

Commit cb1fa84

Browse files
committed
[migrator] Handle renaming from explicit argument label to empty argument label at call sites. rdar://32241559 (#9873)
1 parent 2f3434c commit cb1fa84

File tree

5 files changed

+31
-1
lines changed

5 files changed

+31
-1
lines changed

lib/Migrator/APIDiffMigratorPass.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
325325
unsigned Idx = 0;
326326
auto Ranges = getCallArgLabelRanges(SM, Arg,
327327
LabelRangeEndAt::LabelNameOnly);
328+
llvm::SmallVector<uint8_t, 2> ToRemoveIndices;
328329
for (unsigned I = 0; I < Ranges.size(); I ++) {
329330
if (std::any_of(IgnoreArgIndex.begin(), IgnoreArgIndex.end(),
330331
[I](unsigned Ig) { return Ig == I; }))
@@ -333,15 +334,24 @@ struct APIDiffMigratorPass : public ASTMigratorPass, public SourceEntityWalker {
333334
if (Idx < NewName.argSize()) {
334335
auto Label = NewName.args()[Idx++];
335336

336-
// FIXME: We update only when args are consistently valid.
337337
if (Label != "_") {
338338
if (LR.getByteLength())
339339
Editor.replace(LR, Label);
340340
else
341341
Editor.insert(LR.getStart(), (llvm::Twine(Label) + ": ").str());
342+
} else if (LR.getByteLength()){
343+
// New label is "_" however the old label is explicit.
344+
ToRemoveIndices.push_back(I);
342345
}
343346
}
344347
}
348+
if (!ToRemoveIndices.empty()) {
349+
auto Ranges = getCallArgLabelRanges(SM, Arg,
350+
LabelRangeEndAt::BeforeElemStart);
351+
for (auto I : ToRemoveIndices) {
352+
Editor.remove(Ranges[I]);
353+
}
354+
}
345355
}
346356

347357
void handleFuncRename(ValueDecl *FD, Expr* FuncRefContainer, Expr *Arg) {

test/Migrator/API.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
"RightComment": "barNewInstanceFunc1(newlabel1:newlabel2:newlabel3:newlabel4:)",
4040
"ModuleName": "bar"
4141
},
42+
{
43+
"DiffItemKind": "CommonDiffItem",
44+
"NodeKind": "Function",
45+
"NodeAnnotation": "Rename",
46+
"ChildIndex": "0",
47+
"LeftUsr": "c:objc(cs)BarForwardDeclaredClass(im)barInstanceFunc2:toRemove:toRemove1:toRemove2:",
48+
"LeftComment": "",
49+
"RightUsr": "",
50+
"RightComment": "barNewInstanceFunc2(_:_:NotToRemove1:_:)",
51+
"ModuleName": "bar"
52+
},
4253
{
4354
"DiffItemKind": "CommonDiffItem",
4455
"NodeKind": "Constructor",

test/Migrator/mock-sdk/Bar.framework/Headers/Bar.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int barGlobalFuncOldName(int a);
1414
- (id)initWithOldLabel0:(int)frame;
1515
- (void) barInstanceFunc0;
1616
- (void) barInstanceFunc1:(int)info anotherValue:(int)info1 anotherValue1:(int)info2 anotherValue2:(int)info3;
17+
- (void) barInstanceFunc2:(int)info toRemove:(int)info1 toRemove1:(int)info2 toRemove2:(int)info3;
1718
@end
1819

1920
enum BarForwardDeclaredEnum {

test/Migrator/rename.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ func foo(_ b: BarForwardDeclaredClass) {
1717
barGlobalFuncOldName(2)
1818
_ = barGlobalVariableOldEnumElement
1919
}
20+
21+
func foo1(_ b: BarForwardDeclaredClass) {
22+
b.barInstanceFunc2(0,toRemove:1,toRemove1:2,toRemove2:3)
23+
}

test/Migrator/rename.swift.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ func foo(_ b: BarForwardDeclaredClass) {
1717
barGlobalFuncNewName(newlabel: 2)
1818
_ = NewEnum.enumElement
1919
}
20+
21+
func foo1(_ b: BarForwardDeclaredClass) {
22+
b.barNewInstanceFunc2(0,1,NotToRemove1:2,3)
23+
}

0 commit comments

Comments
 (0)