Skip to content

migrator: add a flag to print incoming usrs to the API diff data store to facilitate test generation. NFC #8969

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
Apr 24, 2017
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
1 change: 1 addition & 0 deletions include/swift/IDE/APIDigesterData.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ struct APIDiffItemStore {
~APIDiffItemStore();
ArrayRef<APIDiffItem*> getDiffItems(StringRef Key) const;
ArrayRef<APIDiffItem*> getAllDiffItems() const;
void printIncomingUsr(bool print = true);

/// Add a path of a JSON file dumped from swift-api-digester that contains
/// API changes we care about. Calling this can be heavy since the procedure
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Migrator/MigratorOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct MigratorOptions {
/// compiler and applies them. This is generally for debugging.
bool EnableMigratorFixits = true;

/// Whether to print each USR we query the api change data store about.
bool DumpUsr = false;

/// If non-empty, print the last MigrationState's output text to the given
/// file path.
std::string EmitMigratedFilePath = "";
Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,9 @@ def api_diff_data_file: Separate<["-"], "api-diff-data-file">,
HelpText<"API migration data is from <path>">,
MetaVarName<"<path>">;

def dump_usr: Flag<["-"], "dump-usr">,
Flags<[FrontendOption, NoInteractiveOption]>,
HelpText<"Dump USR for each declaration reference">;
// File types

def parse_as_library : Flag<["-"], "parse-as-library">,
Expand Down
3 changes: 3 additions & 0 deletions lib/Driver/ToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,9 @@ ToolChain::constructInvocation(const CompileJobAction &job,
Arguments.push_back("-api-diff-data-file");
Arguments.push_back(DataPath->getValue());
}
if (context.Args.hasArg(options::OPT_dump_usr)) {
Arguments.push_back("-dump-usr");
}
}
}
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1592,6 +1592,7 @@ bool ParseMigratorArgs(MigratorOptions &Opts, llvm::Triple &Triple,
using namespace options;

Opts.AddObjC |= Args.hasArg(OPT_warn_swift3_objc_inference);
Opts.DumpUsr = Args.hasArg(OPT_dump_usr);

if (Args.hasArg(OPT_disable_migrator_fixits)) {
Opts.EnableMigratorFixits = false;
Expand Down
11 changes: 10 additions & 1 deletion lib/IDE/APIDigesterData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
llvm::BumpPtrAllocator Allocator;
public:
llvm::StringMap<std::vector<APIDiffItem*>> Data;
bool PrintUsr;
std::vector<APIDiffItem*> AllItems;
void addStorePath(StringRef FileName) {
llvm::MemoryBuffer *pMemBuffer = nullptr;
Expand Down Expand Up @@ -400,7 +401,11 @@ struct swift::ide::api::APIDiffItemStore::Implementation {
};

ArrayRef<APIDiffItem*> swift::ide::api::APIDiffItemStore::
getDiffItems(StringRef Key) const { return Impl.Data[Key]; }
getDiffItems(StringRef Key) const {
if (Impl.PrintUsr)
llvm::outs() << Key;
return Impl.Data[Key];
}

ArrayRef<APIDiffItem*> swift::ide::api::APIDiffItemStore::
getAllDiffItems() const { return Impl.AllItems; }
Expand All @@ -413,3 +418,7 @@ swift::ide::api::APIDiffItemStore::~APIDiffItemStore() { delete &Impl; }
void swift::ide::api::APIDiffItemStore::addStorePath(StringRef Path) {
Impl.addStorePath(Path);
}

void swift::ide::api::APIDiffItemStore::printIncomingUsr(bool print) {
Impl.PrintUsr = print;
}
1 change: 1 addition & 0 deletions lib/Migrator/SyntacticMigratorPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct SyntacticMigratorPass::Implementation : public SourceEntityWalker {
if (Opts.APIDigesterDataStorePath.empty())
return;
DiffStore.addStorePath(Opts.APIDigesterDataStorePath);
DiffStore.printIncomingUsr(Opts.DumpUsr);
walk(SF);
}

Expand Down
10 changes: 10 additions & 0 deletions test/migrator/dump_usr.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// REQUIRES: objc_interop
// RUN: rm -rf %t && mkdir -p %t && %swift -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/API.json -o %t/member.swift.remap -dump-usr | %FileCheck %s -check-prefix=USR

import Bar

func foo(_ b: BarForwardDeclaredClass) -> Int32 {
return barGlobalVariable
}

// USR: c:objc(cs)BarForwardDeclaredClasss:s5Int32Vc:@barGlobalVariable