Skip to content

[swift-4.2-branch-04-30-2018] migrator: ignore migration scripts with underscored new names. rdar://39877447 #16294

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 2, 2018
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions include/swift/IDE/APIDigesterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,15 @@ struct CommonDiffItem: public APIDiffItem {
APIDiffItemKind getKind() const override {
return APIDiffItemKind::ADK_CommonDiffItem;
}

bool rightCommentUnderscored() const {
DeclNameViewer Viewer(RightComment);
auto HasUnderScore =
[](StringRef S) { return S.find('_') != StringRef::npos; };
auto Args = Viewer.args();
return HasUnderScore(Viewer.base()) ||
std::any_of(Args.begin(), Args.end(), HasUnderScore);
}
};


Expand Down
12 changes: 10 additions & 2 deletions lib/IDE/APIDigesterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
private:
llvm::SmallVector<std::unique_ptr<llvm::MemoryBuffer>, 2> AllBuffer;
llvm::BumpPtrAllocator Allocator;

static bool shouldInclude(APIDiffItem *Item) {
if (auto *CI = dyn_cast<CommonDiffItem>(Item)) {
if (CI->rightCommentUnderscored())
return false;
}
return true;
}

public:
llvm::StringMap<std::vector<APIDiffItem*>> Data;
bool PrintUsr;
Expand All @@ -507,14 +516,13 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
APIDiffItem *Item = serializeDiffItem(Allocator,
cast<llvm::yaml::MappingNode>(&*It));
auto &Bag = Data[Item->getKey()];
if (std::find_if(Bag.begin(), Bag.end(),
if (shouldInclude(Item) && std::find_if(Bag.begin(), Bag.end(),
[&](APIDiffItem* I) { return *Item == *I; }) == Bag.end()) {
Bag.push_back(Item);
AllItems.push_back(Item);
}
}
}

}
};

Expand Down
11 changes: 11 additions & 0 deletions test/Migrator/Inputs/API.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
"RightComment": "theSimpleNewName",
"ModuleName": "SomeModule"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Var",
"NodeAnnotation": "Rename",
"ChildIndex": "0",
"LeftUsr": "c:@SA@SomeItemSet@FI@theSimpleOldNameNotToRename",
"LeftComment": "theSimpleOldNameNotToRename",
"RightUsr": "",
"RightComment": "__theSimpleNewName",
"ModuleName": "SomeModule"
},
{
"DiffItemKind": "CommonDiffItem",
"NodeKind": "Function",
Expand Down
1 change: 1 addition & 0 deletions test/Migrator/member.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import Bar

func foo(_ b: BarForwardDeclaredClass, _ s: SomeItemSet) -> Int32 {
let _ = s.theSimpleOldName
let _ = s.theSimpleOldNameNotToRename
return barGlobalVariable
}
1 change: 1 addition & 0 deletions test/Migrator/member.swift.expected
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import Bar

func foo(_ b: BarForwardDeclaredClass, _ s: SomeItemSet) -> Int32 {
let _ = s.theSimpleNewName
let _ = s.theSimpleOldNameNotToRename
return bar.memberVariable
}
1 change: 1 addition & 0 deletions test/Migrator/mock-sdk/Bar.framework/Headers/Bar.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum BarForwardDeclaredEnum {
typedef struct {
int count;
int theSimpleOldName;
int theSimpleOldNameNotToRename;
} SomeItemSet;

typedef SomeItemSet SomeEnvironment;
Expand Down
7 changes: 1 addition & 6 deletions tools/swift-api-digester/swift-api-digester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3979,12 +3979,7 @@ static int deserializeNameCorrection(APIDiffItemStore &Store,
if (CI->DiffKind == NodeAnnotation::Rename) {
auto NewName = CI->getNewName();
auto Module = CI->ModuleName;
DeclNameViewer Viewer(NewName);
auto HasUnderScore =
[](StringRef S) { return S.find('_') != StringRef::npos; };
auto Args = Viewer.args();
if (HasUnderScore(Viewer.base()) ||
std::any_of(Args.begin(), Args.end(), HasUnderScore)) {
if (CI->rightCommentUnderscored()) {
Result.insert(NameCorrectionInfo(NewName, NewName, Module));
}
}
Expand Down