Skip to content

Commit 6b5e554

Browse files
committed
wip
1 parent a496d3f commit 6b5e554

File tree

9 files changed

+32
-39
lines changed

9 files changed

+32
-39
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ namespace swift {
7474
class ClangModuleLoader;
7575
class ClangNode;
7676
class ClangTypeConverter;
77-
class CompilerPlugin;
7877
class ConcreteDeclRef;
7978
class ConstructorDecl;
8079
class Decl;

include/swift/AST/PluginRegistry.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ class CompilerPlugin {
6565

6666
virtual ~CompilerPlugin();
6767

68-
// Launch the plugin if it's not already running, or it's stale. Return an
69-
// error if it's fails to execute it.
68+
/// Launch the plugin if it's not already running, or it's stale. Return an
69+
/// error if it's fails to execute it.
7070
virtual llvm::Error spawnIfNeeded() = 0;
7171

7272
/// Send a message to the plugin.
@@ -83,13 +83,16 @@ class InProcessPlugins : public CompilerPlugin {
8383
/// PluginServer
8484
llvm::sys::DynamicLibrary server;
8585

86+
/// Entry point in the in-process plugin server. It received the request
87+
/// string and populate the response string. deallocating the populated
88+
/// `repsonseDataPtr` is caller's responsibility.
8689
using HandleMessageFunction = bool (*)(const char *requestData,
8790
size_t requestLength,
8891
const char **repsonseDataPtr,
8992
size_t *responseDataLengthPtr);
9093
HandleMessageFunction handleMessageFn;
9194

92-
/// Temporary strorage to store the response data from 'handleMessageFn'.
95+
/// Temporary storage for the response data from 'handleMessageFn'.
9396
std::string receivedResponse;
9497

9598
InProcessPlugins(llvm::StringRef serverPath, llvm::sys::DynamicLibrary server,
@@ -98,10 +101,10 @@ class InProcessPlugins : public CompilerPlugin {
98101
handleMessageFn(handleMessageFn) {}
99102

100103
public:
104+
/// Create and instance by loading the in-process plugin server at
105+
/// 'serverPath' and return it.
101106
static llvm::Expected<InProcessPlugins *> create(const char *serverPath);
102107

103-
llvm::StringRef getServerPath() const { return getPath(); }
104-
105108
/// Send a message to the plugin.
106109
llvm::Error sendMessage(llvm::StringRef message) override;
107110

@@ -113,7 +116,11 @@ class InProcessPlugins : public CompilerPlugin {
113116
return llvm::Error::success();
114117
}
115118

116-
void addOnReconnect(std::function<void(void)> *fn) override;
119+
void addOnReconnect(std::function<void(void)> *fn) override {
120+
// In-Process plugins is always connected. So "on reconnect" callbacks are
121+
// useless.
122+
delete fn;
123+
}
117124
};
118125

119126
/// Represent a "resolved" executable plugin.
@@ -195,6 +202,7 @@ class LoadedExecutablePlugin : public CompilerPlugin {
195202
};
196203

197204
class PluginRegistry {
205+
/// The in-process plugin server.
198206
std::unique_ptr<InProcessPlugins> inProcessPlugins;
199207

200208
/// Record of loaded plugin executables.
@@ -209,7 +217,10 @@ class PluginRegistry {
209217
public:
210218
PluginRegistry();
211219

212-
/// Get a in-process plugin server.
220+
/// Get the in-process plugin server.
221+
/// If it's loaded, returned the cached object. If the loaded instance is
222+
/// from a different 'serverPath', returns an error as we don't support
223+
/// multiple in-process plugin server in a host process.
213224
llvm::Expected<CompilerPlugin *>
214225
getInProcessPlugins(llvm::StringRef serverPath);
215226

lib/AST/PluginRegistry.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ llvm::Error InProcessPlugins::sendMessage(llvm::StringRef message) {
9191

9292
// Store the response and wait for 'waitForNextMessage()' call.
9393
receivedResponse = std::string(responseData, responseLength);
94+
95+
if (shouldDumpMessaging()) {
96+
llvm::dbgs() << "<-(plugin:0) " << receivedResponse << "\n";
97+
}
98+
9499
assert(!receivedResponse.empty() && "received empty response()");
95100
return llvm::Error::success();
96101
}
@@ -99,19 +104,10 @@ llvm::Expected<std::string> InProcessPlugins::waitForNextMessage() {
99104
assert(!receivedResponse.empty() &&
100105
"waitForNextMessage() called without response data.");
101106
auto message = receivedResponse;
102-
if (shouldDumpMessaging()) {
103-
llvm::dbgs() << "<-(plugin:0) " << message << "\n";
104-
}
105107
receivedResponse = "";
106108
return message;
107109
}
108110

109-
void InProcessPlugins::addOnReconnect(std::function<void()> *fn) {
110-
// In-Process plugins is always connected. So "on reconnect" callbacks are
111-
// useless.
112-
delete fn;
113-
}
114-
115111
llvm::Expected<CompilerPlugin *>
116112
PluginRegistry::getInProcessPlugins(llvm::StringRef serverPath) {
117113
std::lock_guard<std::mutex> lock(mtx);
@@ -127,10 +123,10 @@ PluginRegistry::getInProcessPlugins(llvm::StringRef serverPath) {
127123
});
128124
}
129125
inProcessPlugins = std::unique_ptr<InProcessPlugins>(server.get());
130-
} else if (inProcessPlugins->getServerPath() != serverPath) {
126+
} else if (inProcessPlugins->getPath() != serverPath) {
131127
return llvm::createStringError(
132128
llvm::inconvertibleErrorCode(),
133-
"loading multiple in-process servers are not supported: '%s' and '%s'", inProcessPlugins->getServerPath().str().c_str(), serverPath.str().c_str());
129+
"loading multiple in-process servers are not supported: '%s' and '%s'", inProcessPlugins->getPath().data(), serverPath.str().c_str());
134130
}
135131
inProcessPlugins->setDumpMessaging(dumpMessaging);
136132

lib/CompilerSwiftSyntax/CMakeLists.txt

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,9 @@ macro(target_link_libraries_whole_archive target)
3838
set_property(TARGET ${target} APPEND PROPERTY
3939
INTERFACE_INCLUDE_DIRECTORIES "$<TARGET_PROPERTY:${lib},INTERFACE_INCLUDE_DIRECTORIES>"
4040
)
41+
force_add_dependencies(${target} ${lib})
4142

4243
endforeach()
43-
# if(WIN32)
44-
# foreach(lib ${ARGN})
45-
# target_link_options(${target} PRIVATE "/WHOLEARCHIVE:${lib}")
46-
# endforeach()
47-
#elseif (APPLE)
48-
# target_link_libraries(${target} PRIVATE ${ARGN})
49-
# target_link_options(${target} PRIVATE "SHELL:-Xlinker -all_load")
50-
#else ()
51-
# target_link_libraries(${target} PRIVATE ${ARGN})
52-
# target_link_options(${target} PRIVATE "SHELL:-Xlinker --whole-archive")
53-
#endif ()
5444
endmacro()
5545

5646
target_link_libraries_whole_archive(swiftSyntaxUnified

lib/CompilerSwiftSyntax/dummy.c

Whitespace-only changes.

lib/CompilerSwiftSyntax/dummy.swift

Whitespace-only changes.

lib/Driver/ToolChains.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -391,12 +391,9 @@ void ToolChain::addCommonFrontendArgs(const OutputInfo &OI,
391391
inputArgs.AddAllArgs(arguments, options::OPT_file_compilation_dir);
392392
}
393393

394-
inputArgs.AddAllArgs(arguments, options::OPT_plugin_search_Group);
395-
396-
397-
398394
// Specify default plugin search path options after explicitly specified
399395
// options.
396+
inputArgs.AddAllArgs(arguments, options::OPT_plugin_search_Group);
400397
addPlatformSpecificPluginFrontendArgs(OI, output, inputArgs, arguments);
401398

402399
addPluginArguments(inputArgs, arguments);

test/Macros/macro_plugin_broken_shlib.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
// RUN: c-index-test -read-diagnostics %t/macro_expand_inproc.dia 2>&1 | %FileCheck -check-prefix INPROC %s
3535

3636
// INPROC-NOT: {{error|warning}}
37-
// INPROC: test.swift:1:33: warning: external macro implementation type 'TestPlugin.FooMacro' could not be found for macro 'fooMacro'; compiler plugin 'BUILD_DIR/{{.*}}/libTestPlugin.dylib' could not be loaded; dlopen(BUILD_DIR/{{.*}}/libTestPlugin.dylib, 0x0005): tried: 'BUILD_DIR/{{.*}}/libTestPlugin.dylib'
38-
// INPROC: test.swift:4:7: error: external macro implementation type 'TestPlugin.FooMacro' could not be found for macro 'fooMacro'; compiler plugin 'BUILD_DIR/{{.*}}/libTestPlugin.dylib' could not be loaded; dlopen(BUILD_DIR/{{.*}}/libTestPlugin.dylib, 0x0005): tried: 'BUILD_DIR/{{.*}}/libTestPlugin.dylib'
37+
// INPROC: test.swift:1:33: warning: external macro implementation type 'TestPlugin.FooMacro' could not be found for macro 'fooMacro'; failed to load library plugin 'BUILD_DIR/{{.*}}/libTestPlugin.dylib' in plugin server 'BUILD_DIR/{{.*}}/libSwiftInProcPluginServer.dylib'; loader error: dlopen(BUILD_DIR/{{.*}}/libTestPlugin.dylib, 0x0005): tried: 'BUILD_DIR/{{.*}}/libTestPlugin.dylib'
38+
// INPROC: test.swift:4:7: error: external macro implementation type 'TestPlugin.FooMacro' could not be found for macro 'fooMacro'; failed to load library plugin 'BUILD_DIR/{{.*}}/libTestPlugin.dylib' in plugin server 'BUILD_DIR/{{.*}}/libSwiftInProcPluginServer.dylib'; loader error: dlopen(BUILD_DIR/{{.*}}/libTestPlugin.dylib, 0x0005): tried: 'BUILD_DIR/{{.*}}/libTestPlugin.dylib'
3939
// INPROC: test.swift:1:33: note: 'fooMacro' declared here
4040
// INPROC-NOT: {{error|warning}}
4141

tools/driver/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
3232
swiftDriverTool
3333
swiftCompilerStub)
3434

35-
#add_swift_parser_link_libraries(swift-frontend-bootstrapping0)
35+
add_swift_parser_link_libraries(swift-frontend-bootstrapping0)
3636

3737
swift_create_post_build_symlink(swift-frontend-bootstrapping0
3838
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
@@ -53,7 +53,7 @@ if(BOOTSTRAPPING_MODE MATCHES "BOOTSTRAPPING.*")
5353
swiftDriverTool
5454
swiftCompilerModules-bootstrapping1)
5555

56-
#add_swift_parser_link_libraries(swift-frontend-bootstrapping1)
56+
add_swift_parser_link_libraries(swift-frontend-bootstrapping1)
5757

5858
swift_create_post_build_symlink(swift-frontend-bootstrapping1
5959
SOURCE "swift-frontend${CMAKE_EXECUTABLE_SUFFIX}"
@@ -71,7 +71,7 @@ target_link_libraries(swift-frontend
7171
swiftDriverTool
7272
swiftCompilerModules)
7373

74-
#add_swift_parser_link_libraries(swift-frontend)
74+
add_swift_parser_link_libraries(swift-frontend)
7575

7676
# Create a `swift-driver` executable adjacent to the `swift-frontend` executable
7777
# to ensure that `swiftc` forwards to the standalone driver when invoked.

0 commit comments

Comments
 (0)