Skip to content

Commit 9bbe441

Browse files
authored
Merge pull request #3619 from swiftwasm/release/5.5
[pull] swiftwasm-release/5.5 from release/5.5
2 parents 11347a0 + 83913d6 commit 9bbe441

File tree

14 files changed

+102
-53
lines changed

14 files changed

+102
-53
lines changed

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ swiftscan_clang_detail_get_context_hash(swiftscan_module_details_t details);
203203
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
204204
swiftscan_clang_detail_get_command_line(swiftscan_module_details_t details);
205205

206+
SWIFTSCAN_PUBLIC swiftscan_string_set_t *
207+
swiftscan_clang_detail_get_captured_pcm_args(swiftscan_module_details_t details);
208+
206209
//=== Batch Scan Input Functions ------------------------------------------===//
207210

208211
/// Create an \c swiftscan_batch_scan_input_t instance.

include/swift/AST/ModuleDependencies.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,16 +247,22 @@ class ClangModuleDependenciesStorage : public ModuleDependenciesStorageBase {
247247
/// The file dependencies
248248
const std::vector<std::string> fileDependencies;
249249

250+
/// The swift-specific PCM arguments captured by this dependencies object
251+
/// as found by the scanning action that discovered it
252+
const std::vector<std::string> capturedPCMArgs;
253+
250254
ClangModuleDependenciesStorage(
251255
const std::string &moduleMapFile,
252256
const std::string &contextHash,
253257
const std::vector<std::string> &nonPathCommandLine,
254-
const std::vector<std::string> &fileDependencies
258+
const std::vector<std::string> &fileDependencies,
259+
const std::vector<std::string> &capturedPCMArgs
255260
) : ModuleDependenciesStorageBase(ModuleDependenciesKind::Clang),
256261
moduleMapFile(moduleMapFile),
257262
contextHash(contextHash),
258263
nonPathCommandLine(nonPathCommandLine),
259-
fileDependencies(fileDependencies) { }
264+
fileDependencies(fileDependencies),
265+
capturedPCMArgs(capturedPCMArgs) {}
260266

261267
ModuleDependenciesStorageBase *clone() const override {
262268
return new ClangModuleDependenciesStorage(*this);
@@ -361,10 +367,12 @@ class ModuleDependencies {
361367
const std::string &moduleMapFile,
362368
const std::string &contextHash,
363369
const std::vector<std::string> &nonPathCommandLine,
364-
const std::vector<std::string> &fileDependencies) {
370+
const std::vector<std::string> &fileDependencies,
371+
const std::vector<std::string> &capturedPCMArgs) {
365372
return ModuleDependencies(
366373
std::make_unique<ClangModuleDependenciesStorage>(
367-
moduleMapFile, contextHash, nonPathCommandLine, fileDependencies));
374+
moduleMapFile, contextHash, nonPathCommandLine,
375+
fileDependencies, capturedPCMArgs));
368376
}
369377

370378
/// Describe a placeholder dependency swift module.

include/swift/DependencyScan/DependencyScanImpl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ typedef struct {
129129

130130
/// Options to the compile command required to build this clang modulemap
131131
swiftscan_string_set_t *command_line;
132+
133+
/// The swift-specific PCM arguments captured by this dependencies object
134+
swiftscan_string_set_t *captured_pcm_args;
132135
} swiftscan_clang_details_t;
133136

134137
struct swiftscan_module_details_s {

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ const unsigned MODULE_DEPENDENCY_CACHE_FORMAT_VERSION_MINOR = 0;
4646
using IdentifierIDField = BCVBR<13>;
4747
using FileIDField = IdentifierIDField;
4848
using ModuleIDField = IdentifierIDField;
49-
using CompilerFlagField = IdentifierIDField;
5049
using ContextHashField = IdentifierIDField;
5150

5251
/// A bit that indicates whether or not a module is a framework
@@ -166,7 +165,8 @@ using ClangModuleDetailsLayout =
166165
FileIDField, // moduleMapPath
167166
ContextHashField, // contextHash
168167
FlagIDArrayIDField, // commandLine
169-
FileIDArrayIDField // fileDependencies
168+
FileIDArrayIDField, // fileDependencies
169+
FlagIDArrayIDField // capturedPCMArgs
170170
>;
171171
} // namespace graph_block
172172

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,16 @@ static ClangModuleDependenciesCacheImpl *getOrCreateClangImpl(
193193
void ClangImporter::recordModuleDependencies(
194194
ModuleDependenciesCache &cache,
195195
const FullDependenciesResult &clangDependencies) {
196-
struct ModuleInfo {
197-
std::string PCMPath;
198-
std::string ModuleMapPath;
199-
};
200196
auto &ctx = Impl.SwiftContext;
201197
auto currentSwiftSearchPathSet = ctx.getAllModuleSearchPathsSet();
202198

199+
// This scanner invocation's already-captured APINotes version
200+
std::vector<std::string> capturedPCMArgs = {
201+
"-Xcc",
202+
("-fapinotes-swift-version=" +
203+
ctx.LangOpts.EffectiveLanguageVersion.asAPINotesVersionString())
204+
};
205+
203206
for (const auto &clangModuleDep : clangDependencies.DiscoveredModules) {
204207
// If we've already cached this information, we're done.
205208
if (cache.hasDependencies(
@@ -293,7 +296,8 @@ void ClangImporter::recordModuleDependencies(
293296
clangModuleDep.ClangModuleMapFile,
294297
clangModuleDep.ContextHash,
295298
swiftArgs,
296-
fileDeps);
299+
fileDeps,
300+
capturedPCMArgs);
297301
for (const auto &moduleName : clangModuleDep.ClangModuleDeps) {
298302
dependencies.addModuleDependency(moduleName.ModuleName, &alreadyAddedModules);
299303
}

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,10 +447,11 @@ bool Deserializer::readGraph(GlobalModuleDependenciesCache &cache) {
447447
llvm::report_fatal_error("Unexpected CLANG_MODULE_DETAILS_NODE record");
448448
cache.configureForTriple(getTriple());
449449
unsigned moduleMapPathID, contextHashID, commandLineArrayID,
450-
fileDependenciesArrayID;
450+
fileDependenciesArrayID, capturedPCMArgsArrayID;
451451
ClangModuleDetailsLayout::readRecord(Scratch, moduleMapPathID,
452452
contextHashID, commandLineArrayID,
453-
fileDependenciesArrayID);
453+
fileDependenciesArrayID,
454+
capturedPCMArgsArrayID);
454455
auto moduleMapPath = getIdentifier(moduleMapPathID);
455456
if (!moduleMapPath)
456457
llvm::report_fatal_error("Bad module map path");
@@ -463,10 +464,15 @@ bool Deserializer::readGraph(GlobalModuleDependenciesCache &cache) {
463464
auto fileDependencies = getArray(fileDependenciesArrayID);
464465
if (!fileDependencies)
465466
llvm::report_fatal_error("Bad file dependencies");
467+
auto capturedPCMArgs = getArray(capturedPCMArgsArrayID);
468+
if (!capturedPCMArgs)
469+
llvm::report_fatal_error("Bad captured PCM Args");
466470

467471
// Form the dependencies storage object
468472
auto moduleDep = ModuleDependencies::forClangModule(
469-
*moduleMapPath, *contextHash, *commandLineArgs, *fileDependencies);
473+
*moduleMapPath, *contextHash, *commandLineArgs, *fileDependencies,
474+
*capturedPCMArgs);
475+
470476
// Add dependencies of this module
471477
for (const auto &moduleName : *currentModuleDependencies)
472478
moduleDep.addModuleDependency(moduleName);
@@ -572,6 +578,7 @@ enum ModuleIdentifierArrayKind : uint8_t {
572578
BridgingModuleDependencies,
573579
NonPathCommandLine,
574580
FileDependencies,
581+
CapturedPCMArgs,
575582
LastArrayKind
576583
};
577584

@@ -846,7 +853,8 @@ void Serializer::writeModuleInfo(ModuleDependencyID moduleID,
846853
getIdentifier(clangDeps->moduleMapFile),
847854
getIdentifier(clangDeps->contextHash),
848855
getArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine),
849-
getArray(moduleID, ModuleIdentifierArrayKind::FileDependencies));
856+
getArray(moduleID, ModuleIdentifierArrayKind::FileDependencies),
857+
getArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs));
850858

851859
break;
852860
}
@@ -1015,6 +1023,8 @@ void Serializer::collectStringsAndArrays(
10151023
clangDeps->nonPathCommandLine);
10161024
addArray(moduleID, ModuleIdentifierArrayKind::FileDependencies,
10171025
clangDeps->fileDependencies);
1026+
addArray(moduleID, ModuleIdentifierArrayKind::CapturedPCMArgs,
1027+
clangDeps->capturedPCMArgs);
10181028
break;
10191029
}
10201030
default:

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,10 @@ static void writeJSON(llvm::raw_ostream &out,
716716

717717
// Command line.
718718
writeJSONSingleField(out, "commandLine", clangDeps->command_line, 5,
719+
/*trailingComma=*/true);
720+
721+
// Captured PCM arguments.
722+
writeJSONSingleField(out, "capturedPCMArgs", clangDeps->captured_pcm_args, 5,
719723
/*trailingComma=*/false);
720724
}
721725

@@ -841,7 +845,6 @@ generateFullDependencyGraph(CompilerInstance &instance,
841845
// TODO: Once the clients are taught about the new dependency kind,
842846
// switch to using a bespoke kind here.
843847
details->kind = SWIFTSCAN_DEPENDENCY_INFO_SWIFT_TEXTUAL;
844-
845848
details->swift_textual_details = {
846849
moduleInterfacePath,
847850
create_empty_set(),
@@ -870,7 +873,9 @@ generateFullDependencyGraph(CompilerInstance &instance,
870873
details->clang_details = {
871874
create_clone(clangDeps->moduleMapFile.c_str()),
872875
create_clone(clangDeps->contextHash.c_str()),
873-
create_set(clangDeps->nonPathCommandLine)};
876+
create_set(clangDeps->nonPathCommandLine),
877+
create_set(clangDeps->capturedPCMArgs)
878+
};
874879
}
875880
return details;
876881
};

lib/IRGen/GenReflection.cpp

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,19 @@ class PrintMetadataSource
173173
};
174174

175175
Optional<llvm::VersionTuple>
176-
swift::irgen::getRuntimeVersionThatSupportsDemanglingType(CanType type) {
176+
getRuntimeVersionThatSupportsDemanglingType(CanType type) {
177+
// The Swift 5.5 runtime is the first version able to demangle types
178+
// related to concurrency.
179+
bool needsConcurrency = type.findIf([](CanType t) -> bool {
180+
if (auto fn = dyn_cast<AnyFunctionType>(t)) {
181+
return fn->isAsync() || fn->isSendable() || fn->hasGlobalActor();
182+
}
183+
return false;
184+
});
185+
if (needsConcurrency) {
186+
return llvm::VersionTuple(5, 5);
187+
}
188+
177189
// Associated types of opaque types weren't mangled in a usable form by the
178190
// Swift 5.1 runtime, so we needed to add a new mangling in 5.2.
179191
if (type->hasOpaqueArchetype()) {
@@ -192,16 +204,6 @@ swift::irgen::getRuntimeVersionThatSupportsDemanglingType(CanType type) {
192204
// involving them.
193205
}
194206

195-
bool needsConcurrency = type.findIf([](CanType t) -> bool {
196-
if (auto fn = dyn_cast<AnyFunctionType>(t)) {
197-
return fn->isAsync() || fn->isSendable() || fn->hasGlobalActor();
198-
}
199-
return false;
200-
});
201-
if (needsConcurrency) {
202-
return llvm::VersionTuple(5, 5);
203-
}
204-
205207
return None;
206208
}
207209

@@ -281,6 +283,20 @@ getTypeRefByFunction(IRGenModule &IGM,
281283
return {constant, 6};
282284
}
283285

286+
bool swift::irgen::mangledNameIsUnknownToDeployTarget(IRGenModule &IGM,
287+
CanType type) {
288+
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget(
289+
IGM.Context.LangOpts.Target)) {
290+
if (auto minimumSupportedRuntimeVersion =
291+
getRuntimeVersionThatSupportsDemanglingType(type)) {
292+
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
293+
return true;
294+
}
295+
}
296+
}
297+
return false;
298+
}
299+
284300
static std::pair<llvm::Constant *, unsigned>
285301
getTypeRefImpl(IRGenModule &IGM,
286302
CanType type,
@@ -297,16 +313,10 @@ getTypeRefImpl(IRGenModule &IGM,
297313
// If the minimum deployment target's runtime demangler wouldn't understand
298314
// this mangled name, then fall back to generating a "mangled name" with a
299315
// symbolic reference with a callback function.
300-
if (auto runtimeCompatVersion = getSwiftRuntimeCompatibilityVersionForTarget
301-
(IGM.Context.LangOpts.Target)) {
302-
if (auto minimumSupportedRuntimeVersion =
303-
getRuntimeVersionThatSupportsDemanglingType(type)) {
304-
if (*runtimeCompatVersion < *minimumSupportedRuntimeVersion) {
305-
return getTypeRefByFunction(IGM, sig, type);
306-
}
307-
}
316+
if (mangledNameIsUnknownToDeployTarget(IGM, type)) {
317+
return getTypeRefByFunction(IGM, sig, type);
308318
}
309-
319+
310320
break;
311321

312322
case MangledTypeRefRole::Reflection:

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,10 +641,10 @@ class IRGenMangler : public Mangle::ASTMangler {
641641
}
642642
};
643643

644-
/// Does this type require a special minimum Swift runtime version which
645-
/// supports demangling it?
646-
Optional<llvm::VersionTuple>
647-
getRuntimeVersionThatSupportsDemanglingType(CanType type);
644+
/// Determines if the minimum deployment target's runtime demangler will not
645+
/// understand the mangled name for the given type.
646+
/// \returns true iff the target's runtime does not understand the mangled name.
647+
bool mangledNameIsUnknownToDeployTarget(IRGenModule &IGM, CanType type);
648648

649649
} // end namespace irgen
650650
} // end namespace swift

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2477,7 +2477,11 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
24772477
// Never access by mangled name if we've been asked not to.
24782478
if (IGM.getOptions().DisableConcreteTypeMetadataMangledNameAccessors)
24792479
return false;
2480-
2480+
2481+
// Do not access by mangled name if the runtime won't understand it.
2482+
if (mangledNameIsUnknownToDeployTarget(IGM, type))
2483+
return false;
2484+
24812485
// A nongeneric nominal type with nontrivial metadata has an accessor
24822486
// already we can just call.
24832487
if (auto nom = dyn_cast<NominalType>(type)) {
@@ -2487,14 +2491,7 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
24872491
return false;
24882492
}
24892493
}
2490-
2491-
// The Swift 5.1 runtime fails to demangle associated types of opaque types.
2492-
if (auto minimumSwiftVersion =
2493-
getRuntimeVersionThatSupportsDemanglingType(type)) {
2494-
return IGM.getAvailabilityContext().isContainedIn(
2495-
IGM.Context.getSwift5PlusAvailability(*minimumSwiftVersion));
2496-
}
2497-
2494+
24982495
return true;
24992496

25002497
// The visitor below can be used to fine-tune a heuristic to decide whether

0 commit comments

Comments
 (0)