-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Frontend: when emitting loaded module trace file, also emit a JSON file tracking Objc method calls issued from the source code #77217
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
Conversation
…le tracking Objc method calls issued from the source code.
@swift-ci please smoke test |
ASTContext &ctxt = mainModule->getASTContext(); | ||
assert(!ctxt.hadError() && | ||
"We should've already exited earlier if there was an error."); | ||
class ObjcMethodRefereceCollector: public SourceEntityWalker { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd pull out of this function personally
assert(!ctxt.hadError() && | ||
"We should've already exited earlier if there was an error."); | ||
class ObjcMethodRefereceCollector: public SourceEntityWalker { | ||
std::set<const clang::ObjCMethodDecl*> results; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DenseSet
/SmallPtrSet
?
} | ||
OS << "\t{\n"; | ||
OS << "\t\t\"method_name\": \"" << clangD->getNameAsString() << "\",\n"; | ||
OS << "\t\t\"location\": \"" << Loc.printToString(SM) << "\"\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure exactly what you're after here, but note this will be both the spelling + expansion + line + column. If you only need offset, you could make this a fair bit simpler.
return false; | ||
llvm::SmallString<128> tracePath {loadedModuleTracePath}; | ||
llvm::sys::path::remove_filename(tracePath); | ||
llvm::sys::path::append(tracePath, "SWIFT_OBJC_MESSAGE_TRACE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Caps is a little weird but module trace does the same so 🤷. Maybe .SWIFT_OBJC_MESSAGE_TRACE
then though?
} | ||
// Write the contents of the buffer. | ||
llvm::raw_fd_ostream out(tmpFD, /*shouldClose=*/true); | ||
ObjcMethodRefereceCollector collector; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ObjcMethodRefereceCollector
-> ObjcMethodReferenceCollector
collector.walk(*SF); | ||
} | ||
} | ||
collector.dump(out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I see dump
I think of debugging. serializeAsJson
or something similar?
|
||
// REQUIRES: objc_interop | ||
|
||
// EXPECTED OUTPUT STARTS BELOW THIS LINE. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't really the output 🤔. Also does this test really belong under IDE
?
continue; | ||
} | ||
OS << "\t{\n"; | ||
OS << "\t\t\"method_name\": \"" << clangD->getNameAsString() << "\",\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is just the method name really all that's needed? Is the expectation that the location will unique them?
// RUN: %empty-directory(%t) | ||
|
||
// RUN: %target-swift-frontend -I %t/lib/swift -typecheck %s -module-name main -swift-version 5 -F %S/Inputs/mock-sdk -emit-loaded-module-trace-path %t/.MODULE_TRACE | ||
// RUN: %{python} %S/Inputs/print_first_file_under_directory.py %t/SWIFT_OBJC_MESSAGE_TRACE | %FileCheck %s |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just RUN: cat %t/SWIFT_OBJC_MESSAGE_TRACE/*
?
|
||
#include "clang/Basic/Module.h" | ||
#include "clang/AST/DeclObjC.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format?
Thank you for the comments, Ben! Will address via a follow-up PR. Regarding the exact content/details of this tracing file, we are still discussing with clients to settle the details. |
if (!Loc.isValid()) { | ||
continue; | ||
} | ||
OS << "\t{\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For small JSON output like this, it would be nice to use llvm::json::OStream
. e.g. how ConstExtract.cpp
's writeValue
does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Will update.
No description provided.