Skip to content

Commit c6387a5

Browse files
committed
[Macros] Small changes for review
1 parent c5a737f commit c6387a5

File tree

6 files changed

+13
-15
lines changed

6 files changed

+13
-15
lines changed

include/swift/Basic/Program.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct ChildProcessInfo {
5858
/// \param program Path of the program to be executed
5959
/// \param args An array of strings that are passed to the program. The first
6060
/// element should be the name of the program.
61-
/// \param env An optional array of strings to use for the program's
61+
/// \param env An optional array of 'key=value 'strings to use for the program's
6262
/// environment.
6363
llvm::ErrorOr<swift::ChildProcessInfo> ExecuteWithPipe(
6464
llvm::StringRef program, llvm::ArrayRef<llvm::StringRef> args,

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ struct ASTContext::Implementation {
531531
llvm::StringMap<void *> LoadedSymbols;
532532

533533
/// Map a module name to an executable plugin path that provides the module.
534-
llvm::DenseMap<Identifier, std::string> ExecutablePluginPaths;
534+
llvm::DenseMap<Identifier, StringRef> ExecutablePluginPaths;
535535

536536
/// The permanent arena.
537537
Arena Permanent;
@@ -6256,9 +6256,9 @@ void ASTContext::loadCompilerPlugins() {
62566256
// TODO: Error messsage.
62576257
Diags.diagnose(SourceLoc(), diag::compiler_plugin_not_loaded, arg, "");
62586258
}
6259-
auto pathstr = std::string(path);
6259+
auto pathStr = AllocateCopy(path);
62606260
for (auto moduleName : modules) {
6261-
getImpl().ExecutablePluginPaths[getIdentifier(moduleName)] = pathstr;
6261+
getImpl().ExecutablePluginPaths[getIdentifier(moduleName)] = pathStr;
62626262
}
62636263
}
62646264
}
@@ -6327,7 +6327,7 @@ ASTContext::lookupExecutablePluginByModuleName(Identifier moduleName) {
63276327
if (found == execPluginPaths.end())
63286328
return nullptr;
63296329

6330-
// Resolve the realpath.
6330+
// Let the VFS to map the path.
63316331
auto &path = found->second;
63326332
SmallString<128> resolvedPath;
63336333
auto fs = this->SourceMgr.getFileSystem();

lib/ASTGen/Sources/ASTGen/Macros.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,13 @@ public func resolveExecutableMacro(
109109
moduleNameLength: Int,
110110
typeName: UnsafePointer<UInt8>,
111111
typeNameLength: Int,
112-
pluginOpaqueHanle: UnsafeMutableRawPointer
112+
pluginOpaqueHandle: UnsafeMutableRawPointer
113113
) -> UnsafeRawPointer {
114114
let exportedPtr = UnsafeMutablePointer<ExportedExecutableMacro>.allocate(capacity: 1)
115115
exportedPtr.initialize(to: .init(
116116
moduleName: String(bufferStart: moduleName, count: moduleNameLength),
117117
typeName: String(bufferStart: typeName, count: typeNameLength),
118-
plugin: CompilerPlugin(opaqueHandle: pluginOpaqueHanle)))
118+
plugin: CompilerPlugin(opaqueHandle: pluginOpaqueHandle)))
119119
return UnsafeRawPointer(exportedPtr)
120120
}
121121

lib/Basic/Program.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ toNullTerminatedCStringArray(ArrayRef<StringRef> array,
5959
llvm::BumpPtrAllocator &Alloc) {
6060
size_t size = array.size();
6161
const char **result = Alloc.Allocate<const char *>(size + 1);
62-
const char **ptr = result;
6362
for (size_t i = 0; i < size; ++i) {
6463
result[i] = NullTerminatedStringRef(array[i], Alloc).data();
6564
}
@@ -155,8 +154,7 @@ swift::ExecuteWithPipe(llvm::StringRef program,
155154
dup2(p2.write, STDOUT_FILENO);
156155

157156
// Execute the program.
158-
if (env.has_value()) {
159-
const char **envp = toNullTerminatedCStringArray(*env, Alloc);
157+
if (envp) {
160158
execve(progCStr, const_cast<char **>(argv), const_cast<char **>(envp));
161159
} else {
162160
execv(progCStr, const_cast<char **>(argv));

lib/Sema/TypeCheckMacros.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ resolveInProcessMacro(
356356
}
357357

358358
static Optional<ExternalMacroDefinition>
359-
resolvExecutableMacro(ASTContext &ctx, Identifier moduleName,
359+
resolveExecutableMacro(ASTContext &ctx, Identifier moduleName,
360360
Identifier typeName) {
361361
#if SWIFT_SWIFT_PARSER
362362
// Find macros in exectuable plugins.
@@ -374,7 +374,7 @@ resolvExecutableMacro(ASTContext &ctx, Identifier moduleName,
374374
});
375375
}
376376

377-
if (auto execMacro = swift_ASTGen_resolveExecutableMacro(
377+
if (auto *execMacro = swift_ASTGen_resolveExecutableMacro(
378378
moduleName.str().data(), moduleName.str().size(),
379379
typeName.str().data(), typeName.str().size(), executablePlugin)) {
380380
// Make sure we clean up after the macro.
@@ -408,7 +408,7 @@ ExternalMacroDefinitionRequest::evaluate(Evaluator &evaluator, ASTContext *ctx,
408408

409409
// Try executable plugins.
410410
if (auto executableMacro =
411-
resolvExecutableMacro(*ctx, moduleName, typeName)) {
411+
resolveExecutableMacro(*ctx, moduleName, typeName)) {
412412
return executableMacro;
413413
}
414414

utils/mock_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
#
2424
# where 'TEST_SPEC' is a list of pairs of an expected request and the result to
2525
# respond. For example:
26-
# {'expected': {'testRequest': {'params': []}},
26+
# {'expect': {'testRequest': {'params': []}},
2727
# 'response': {'testRequestResult': [1,2,"foo"]}}
28-
# this spec matches a request that is an object with 'testRequst' key with an
28+
# this spec matches a request that is an object with 'testRequest' key with an
2929
# object with 'params' key with an empty array. When the host system sends a
3030
# request matching, this mock plugin replies to it with the 'response' object.
3131
# ===-----------------------------------------------------------------------===#

0 commit comments

Comments
 (0)