Skip to content

Commit 64d808f

Browse files
authored
Merge pull request #16294 from nkcsgexi/cherry-mig-change-04-30-2018
[swift-4.2-branch-04-30-2018] migrator: ignore migration scripts with underscored new names. rdar://39877447
2 parents 6d743ad + ec72b54 commit 64d808f

File tree

7 files changed

+34
-8
lines changed

7 files changed

+34
-8
lines changed

include/swift/IDE/APIDigesterData.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,15 @@ struct CommonDiffItem: public APIDiffItem {
147147
APIDiffItemKind getKind() const override {
148148
return APIDiffItemKind::ADK_CommonDiffItem;
149149
}
150+
151+
bool rightCommentUnderscored() const {
152+
DeclNameViewer Viewer(RightComment);
153+
auto HasUnderScore =
154+
[](StringRef S) { return S.find('_') != StringRef::npos; };
155+
auto Args = Viewer.args();
156+
return HasUnderScore(Viewer.base()) ||
157+
std::any_of(Args.begin(), Args.end(), HasUnderScore);
158+
}
150159
};
151160

152161

lib/IDE/APIDigesterData.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,15 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
482482
private:
483483
llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> AllBuffer;
484484
llvm::BumpPtrAllocator Allocator;
485+
486+
static bool shouldInclude(APIDiffItem *Item) {
487+
if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
488+
if (CI->rightCommentUnderscored())
489+
return false;
490+
}
491+
return true;
492+
}
493+
485494
public:
486495
llvm::StringMap<std::vector<APIDiffItem*>> Data;
487496
bool PrintUsr;
@@ -507,14 +516,13 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
507516
APIDiffItem *Item = serializeDiffItem(Allocator,
508517
cast<llvm::yaml::MappingNode>(&*It));
509518
auto &Bag = Data[Item->getKey()];
510-
if (std::find_if(Bag.begin(), Bag.end(),
519+
if (shouldInclude(Item) && std::find_if(Bag.begin(), Bag.end(),
511520
[&](APIDiffItem* I) { return *Item == *I; }) == Bag.end()) {
512521
Bag.push_back(Item);
513522
AllItems.push_back(Item);
514523
}
515524
}
516525
}
517-
518526
}
519527
};
520528

test/Migrator/Inputs/API.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@
1717
"RightComment": "theSimpleNewName",
1818
"ModuleName": "SomeModule"
1919
},
20+
{
21+
"DiffItemKind": "CommonDiffItem",
22+
"NodeKind": "Var",
23+
"NodeAnnotation": "Rename",
24+
"ChildIndex": "0",
25+
"LeftUsr": "c:@SA@SomeItemSet@FI@theSimpleOldNameNotToRename",
26+
"LeftComment": "theSimpleOldNameNotToRename",
27+
"RightUsr": "",
28+
"RightComment": "__theSimpleNewName",
29+
"ModuleName": "SomeModule"
30+
},
2031
{
2132
"DiffItemKind": "CommonDiffItem",
2233
"NodeKind": "Function",

test/Migrator/member.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import Bar
66

77
func foo(_ b: BarForwardDeclaredClass, _ s: SomeItemSet) -> Int32 {
88
let _ = s.theSimpleOldName
9+
let _ = s.theSimpleOldNameNotToRename
910
return barGlobalVariable
1011
}

test/Migrator/member.swift.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ import Bar
66

77
func foo(_ b: BarForwardDeclaredClass, _ s: SomeItemSet) -> Int32 {
88
let _ = s.theSimpleNewName
9+
let _ = s.theSimpleOldNameNotToRename
910
return bar.memberVariable
1011
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ enum BarForwardDeclaredEnum {
3636
typedef struct {
3737
int count;
3838
int theSimpleOldName;
39+
int theSimpleOldNameNotToRename;
3940
} SomeItemSet;
4041

4142
typedef SomeItemSet SomeEnvironment;

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,12 +3979,7 @@ static int deserializeNameCorrection(APIDiffItemStore &Store,
39793979
if (CI->DiffKind == NodeAnnotation::Rename) {
39803980
auto NewName = CI->getNewName();
39813981
auto Module = CI->ModuleName;
3982-
DeclNameViewer Viewer(NewName);
3983-
auto HasUnderScore =
3984-
[](StringRef S) { return S.find('_') != StringRef::npos; };
3985-
auto Args = Viewer.args();
3986-
if (HasUnderScore(Viewer.base()) ||
3987-
std::any_of(Args.begin(), Args.end(), HasUnderScore)) {
3982+
if (CI->rightCommentUnderscored()) {
39883983
Result.insert(NameCorrectionInfo(NewName, NewName, Module));
39893984
}
39903985
}

0 commit comments

Comments
 (0)