Skip to content

Commit 96d61d3

Browse files
committed
Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6
2 parents a19021d + d4c54af commit 96d61d3

40 files changed

+988
-392
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5558,8 +5558,6 @@ ERROR(isolated_attr_global_actor_type,none,
55585558
ERROR(isolated_attr_bad_convention,none,
55595559
"'@isolated(%0)' function type cannot have %1 convention",
55605560
(StringRef, StringRef))
5561-
ERROR(isolation_macro_experimental,none,
5562-
"#isolation macro is experimental", ())
55635561

55645562
NOTE(in_derived_conformance, none,
55655563
"in derived conformance to %0",

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros")
122122
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive")
123123
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)")
124124
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
125+
LANGUAGE_FEATURE(OptionalIsolatedParameters, 420, "Optional isolated parameters")
125126
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
126127
LANGUAGE_FEATURE(ExpressionMacroDefaultArguments, 422, "Expression macro as caller-side default argument")
127128

@@ -261,9 +262,6 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
261262
/// lifetime-dependent results.
262263
EXPERIMENTAL_FEATURE(NonescapableTypes, true)
263264

264-
// Allow optional isolated parameters.
265-
EXPERIMENTAL_FEATURE(OptionalIsolatedParameters, true)
266-
267265
/// Enable the `@_staticExclusiveOnly` attribute.
268266
EXPERIMENTAL_FEATURE(StaticExclusiveOnly, true)
269267

include/swift/Runtime/GenericMetadataBuilder.h

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,11 @@ class GenericMetadataBuilder {
296296
patternPointers->resolvePointer(&patternPointers->ptr[i]);
297297
if (!patternPointer)
298298
return *patternPointer.getError();
299-
data.writePointer(
299+
auto writeResult = data.writePointer(
300300
&metadataExtraData[i + extraDataPattern->OffsetInWords],
301301
patternPointer->template cast<const StoredPointer>());
302+
if (!writeResult)
303+
return *writeResult.getError();
302304
}
303305
}
304306

@@ -310,7 +312,10 @@ class GenericMetadataBuilder {
310312
if (!valueWitnesses)
311313
return *valueWitnesses.getError();
312314
METADATA_BUILDER_LOG("Setting initial value witnesses");
313-
data.writePointer(&fullMetadata->ValueWitnesses, *valueWitnesses);
315+
auto writeResult =
316+
data.writePointer(&fullMetadata->ValueWitnesses, *valueWitnesses);
317+
if (!writeResult)
318+
return *writeResult.getError();
314319

315320
// Set the metadata kind.
316321
METADATA_BUILDER_LOG("Setting metadata kind %#x",
@@ -319,7 +324,9 @@ class GenericMetadataBuilder {
319324

320325
// Set the type descriptor.
321326
METADATA_BUILDER_LOG("Setting descriptor");
322-
data.writePointer(&metadata->Description, descriptionBuffer);
327+
writeResult = data.writePointer(&metadata->Description, descriptionBuffer);
328+
if (!writeResult)
329+
return *writeResult.getError();
323330

324331
return {{}};
325332
}
@@ -353,8 +360,11 @@ class GenericMetadataBuilder {
353360
header.NumKeyArguments,
354361
getGenericArgumentOffset(
355362
descriptionBuffer.template cast<const TypeContextDescriptor>()));
356-
for (unsigned i = 0; i < header.NumKeyArguments; i++)
357-
data.writePointer(&dst[i], arguments[i]);
363+
for (unsigned i = 0; i < header.NumKeyArguments; i++) {
364+
auto writeResult = data.writePointer(&dst[i], arguments[i]);
365+
if (!writeResult)
366+
return *writeResult.getError();
367+
}
358368

359369
// TODO: parameter pack support.
360370

@@ -495,7 +505,11 @@ class GenericMetadataBuilder {
495505
auto LOWER_ID##_Buffer = from.resolveFunctionPointer(&from.ptr->LOWER_ID); \
496506
if (!LOWER_ID##_Buffer) \
497507
return *LOWER_ID##_Buffer.getError(); \
498-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->LOWER_ID, *LOWER_ID##_Buffer);
508+
if (auto *error = vwtBuffer \
509+
.writeFunctionPointer(&vwtBuffer.ptr->LOWER_ID, \
510+
*LOWER_ID##_Buffer) \
511+
.getError()) \
512+
return *error;
499513
#define DATA_VALUE_WITNESS(LOWER_ID, UPPER_ID, TYPE)
500514
#include "swift/ABI/ValueWitness.def"
501515

@@ -520,40 +534,56 @@ class GenericMetadataBuilder {
520534
(size_t)flags.getAlignmentMask());
521535
switch (sizeWithAlignmentMask(layout.size, flags.getAlignmentMask(),
522536
hasExtraInhabitants)) {
523-
default:
537+
default: {
524538
// For uncommon layouts, use value witnesses that work with an arbitrary
525539
// size and alignment.
526540
METADATA_BUILDER_LOG("Uncommon layout case, flags.isInlineStorage=%s",
527541
flags.isInlineStorage() ? "true" : "false");
528542
if (flags.isInlineStorage()) {
529543
if (!pod_direct_initializeBufferWithCopyOfBuffer)
530544
return *pod_direct_initializeBufferWithCopyOfBuffer.getError();
531-
vwtBuffer.writeFunctionPointer(
545+
auto writeResult = vwtBuffer.writeFunctionPointer(
532546
&vwtBuffer.ptr->initializeBufferWithCopyOfBuffer,
533547
*pod_direct_initializeBufferWithCopyOfBuffer);
548+
if (!writeResult)
549+
return *writeResult.getError();
534550
} else {
535551
if (!pod_indirect_initializeBufferWithCopyOfBuffer)
536552
return *pod_indirect_initializeBufferWithCopyOfBuffer.getError();
537-
vwtBuffer.writeFunctionPointer(
553+
auto writeResult = vwtBuffer.writeFunctionPointer(
538554
&vwtBuffer.ptr->initializeBufferWithCopyOfBuffer,
539555
*pod_indirect_initializeBufferWithCopyOfBuffer);
556+
if (!writeResult)
557+
return *writeResult.getError();
540558
}
541559
if (!pod_destroy)
542560
return *pod_destroy.getError();
543561
if (!pod_copy)
544562
return *pod_copy.getError();
545-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->destroy, *pod_destroy);
546-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->initializeWithCopy,
547-
*pod_copy);
548-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->initializeWithTake,
549-
*pod_copy);
550-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->assignWithCopy,
551-
*pod_copy);
552-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->assignWithTake,
553-
*pod_copy);
563+
auto writeResult = vwtBuffer.writeFunctionPointer(
564+
&vwtBuffer.ptr->destroy, *pod_destroy);
565+
if (!writeResult)
566+
return *writeResult.getError();
567+
writeResult = vwtBuffer.writeFunctionPointer(
568+
&vwtBuffer.ptr->initializeWithCopy, *pod_copy);
569+
if (!writeResult)
570+
return *writeResult.getError();
571+
writeResult = vwtBuffer.writeFunctionPointer(
572+
&vwtBuffer.ptr->initializeWithTake, *pod_copy);
573+
if (!writeResult)
574+
return *writeResult.getError();
575+
writeResult = vwtBuffer.writeFunctionPointer(
576+
&vwtBuffer.ptr->assignWithCopy, *pod_copy);
577+
if (!writeResult)
578+
return *writeResult.getError();
579+
writeResult = vwtBuffer.writeFunctionPointer(
580+
&vwtBuffer.ptr->assignWithTake, *pod_copy);
581+
if (!writeResult)
582+
return *writeResult.getError();
554583
// getEnumTagSinglePayload and storeEnumTagSinglePayload are not
555584
// interestingly optimizable based on POD-ness.
556585
return {{}};
586+
}
557587

558588
case sizeWithAlignmentMask(1, 0, 0): {
559589
METADATA_BUILDER_LOG("case sizeWithAlignmentMask(1, 0, 0)");
@@ -629,8 +659,10 @@ class GenericMetadataBuilder {
629659
// Use POD value witnesses for operations that do an initializeWithTake.
630660
if (!pod_copy)
631661
return *pod_copy.getError();
632-
vwtBuffer.writeFunctionPointer(&vwtBuffer.ptr->initializeWithTake,
633-
*pod_copy);
662+
auto writeResult = vwtBuffer.writeFunctionPointer(
663+
&vwtBuffer.ptr->initializeWithTake, *pod_copy);
664+
if (!writeResult)
665+
return *writeResult.getError();
634666
}
635667
return {{}};
636668
}
@@ -761,7 +793,10 @@ class GenericMetadataBuilder {
761793
auto fptr = oldVWTBuffer->resolveFunctionPointer(&oldVWT->LOWER_ID); \
762794
if (!fptr) \
763795
return *fptr.getError(); \
764-
newVWTData.writeFunctionPointer(&newVWT->LOWER_ID, *fptr); \
796+
if (auto *error = \
797+
newVWTData.writeFunctionPointer(&newVWT->LOWER_ID, *fptr) \
798+
.getError()) \
799+
return *error; \
765800
}
766801
#include "swift/ABI/ValueWitness.def"
767802

@@ -774,9 +809,11 @@ class GenericMetadataBuilder {
774809
newVWT->extraInhabitantCount = layout.extraInhabitantCount;
775810
newVWT->flags = layout.flags;
776811

777-
metadataBuffer.writePointer(
812+
auto writeResult = metadataBuffer.writePointer(
778813
&metadataBuffer.ptr->ValueWitnesses,
779814
newVWTData.template cast<const ValueWitnessTable>());
815+
if (!writeResult)
816+
return *writeResult.getError();
780817
return {{}}; // success
781818
}
782819

lib/Basic/LangOptions.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ DiagnosticBehavior LangOptions::getAccessNoteFailureLimit() const {
697697
}
698698

699699
namespace {
700-
static constexpr std::array<std::string_view, 16> knownSearchPathPrefiexes =
700+
constexpr std::array<std::string_view, 16> knownSearchPathPrefiexes =
701701
{"-I",
702702
"-F",
703703
"-fmodule-map-file=",
@@ -714,6 +714,23 @@ namespace {
714714
"-ivfsoverlay",
715715
"-working-directory=",
716716
"-working-directory"};
717+
718+
constexpr std::array<std::string_view, 15> knownClangDependencyIgnorablePrefiexes =
719+
{"-I",
720+
"-F",
721+
"-fmodule-map-file=",
722+
"-iquote",
723+
"-idirafter",
724+
"-iframeworkwithsysroot",
725+
"-iframework",
726+
"-iprefix",
727+
"-iwithprefixbefore",
728+
"-iwithprefix",
729+
"-isystemafter",
730+
"-isystem",
731+
"-isysroot",
732+
"-working-directory=",
733+
"-working-directory"};
717734
}
718735

719736
std::vector<std::string> ClangImporterOptions::getRemappedExtraArgs(
@@ -756,7 +773,7 @@ std::vector<std::string> ClangImporterOptions::getRemappedExtraArgs(
756773
std::vector<std::string>
757774
ClangImporterOptions::getReducedExtraArgsForSwiftModuleDependency() const {
758775
auto matchIncludeOption = [](StringRef &arg) {
759-
for (const auto &option : knownSearchPathPrefiexes)
776+
for (const auto &option : knownClangDependencyIgnorablePrefiexes)
760777
if (arg.consume_front(option))
761778
return true;
762779
return false;

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,97 @@ static llvm::Error resolveExplicitModuleInputs(
415415
return llvm::Error::success();
416416
}
417417

418+
static llvm::Error pruneUnusedVFSOverlays(
419+
ModuleDependencyID moduleID, const ModuleDependencyInfo &resolvingDepInfo,
420+
const std::set<ModuleDependencyID> &dependencies,
421+
ModuleDependenciesCache &cache, CompilerInstance &instance) {
422+
auto isVFSOverlayFlag = [](StringRef arg) {
423+
return arg == "-ivfsoverlay" || arg == "-vfsoverlay";
424+
};
425+
auto isXCCArg = [](StringRef arg) {
426+
return arg == "-Xcc";
427+
};
428+
429+
// Pruning of unused VFS overlay options for Clang dependencies
430+
// is performed by the Clang dependency scanner.
431+
if (!resolvingDepInfo.isSwiftModule())
432+
return llvm::Error::success();
433+
434+
// If this Swift dependency contains any VFS overlay paths,
435+
// then attempt to prune the ones not used by any of the Clang dependencies.
436+
if (!llvm::any_of(resolvingDepInfo.getCommandline(),
437+
[&isVFSOverlayFlag](const std::string &arg) {
438+
return isVFSOverlayFlag(arg);
439+
}))
440+
return llvm::Error::success();
441+
442+
// 1. For each Clang dependency, gather its ivfsoverlay path arguments
443+
// to keep track of which overlays are actually used and were not
444+
// pruned by the Clang dependency scanner.
445+
llvm::StringSet<> usedVFSOverlayPaths;
446+
for (const auto &depModuleID : dependencies) {
447+
const auto optionalDepInfo = cache.findDependency(depModuleID);
448+
assert(optionalDepInfo.has_value());
449+
const auto depInfo = optionalDepInfo.value();
450+
if (auto clangDepDetails = depInfo->getAsClangModule()) {
451+
const auto &depCommandLine = clangDepDetails->buildCommandLine;
452+
// true if the previous argument was the dash-option of an option pair
453+
bool getNext = false;
454+
for (const auto &A : depCommandLine) {
455+
StringRef arg(A);
456+
if (isXCCArg(arg))
457+
continue;
458+
if (getNext) {
459+
getNext = false;
460+
usedVFSOverlayPaths.insert(arg);
461+
} else if (isVFSOverlayFlag(arg))
462+
getNext = true;
463+
}
464+
}
465+
}
466+
467+
// 2. Each -Xcc VFS overlay path on the resolving command-line which is not used by
468+
// any of the Clang dependencies can be removed from the command-line.
469+
const std::vector<std::string> &currentCommandLine =
470+
resolvingDepInfo.getCommandline();
471+
std::vector<std::string> resolvedCommandLine;
472+
size_t skip = 0;
473+
for (auto it = currentCommandLine.begin(), end = currentCommandLine.end();
474+
it != end; it++) {
475+
if (skip) {
476+
skip--;
477+
continue;
478+
}
479+
// If this VFS overlay was not used across any of the dependencies, skip it.
480+
if ((it+1) != end && isXCCArg(*it) && isVFSOverlayFlag(*(it + 1))) {
481+
assert(it + 2 != end); // Extra -Xcc
482+
assert(it + 3 != end); // Actual VFS overlay path argument
483+
if (!usedVFSOverlayPaths.contains(*(it + 3))) {
484+
skip = 3;
485+
continue;
486+
}
487+
}
488+
resolvedCommandLine.push_back(*it);
489+
}
490+
491+
// 3. Update the dependency in the cache if the command-line has been modified.
492+
if (currentCommandLine.size() != resolvedCommandLine.size()) {
493+
auto dependencyInfoCopy = resolvingDepInfo;
494+
dependencyInfoCopy.updateCommandLine(resolvedCommandLine);
495+
496+
// Update the CAS cache key for the new command-line
497+
if (instance.getInvocation().getCASOptions().EnableCaching) {
498+
auto &CAS = cache.getScanService().getSharedCachingFS().getCAS();
499+
auto Key = updateModuleCacheKey(dependencyInfoCopy, cache, CAS);
500+
if (!Key)
501+
return Key.takeError();
502+
}
503+
cache.updateDependency(moduleID, dependencyInfoCopy);
504+
}
505+
506+
return llvm::Error::success();
507+
}
508+
418509
namespace {
419510
std::string quote(StringRef unquoted) {
420511
llvm::SmallString<128> buffer;
@@ -1658,7 +1749,7 @@ swift::dependencies::createEncodedModuleKindAndName(ModuleDependencyID id) {
16581749
}
16591750
}
16601751

1661-
static void resolveDependencyInputCommandLineArguments(
1752+
static void resolveDependencyCommandLineArguments(
16621753
CompilerInstance &instance, ModuleDependenciesCache &cache,
16631754
const std::vector<ModuleDependencyID> &topoSortedModuleList) {
16641755
auto moduleTransitiveClosures =
@@ -1676,6 +1767,11 @@ static void resolveDependencyInputCommandLineArguments(
16761767
cache, instance))
16771768
instance.getDiags().diagnose(SourceLoc(), diag::error_cas,
16781769
toString(std::move(E)));
1770+
1771+
if (auto E = pruneUnusedVFSOverlays(modID, *deps, dependencyClosure,
1772+
cache, instance))
1773+
instance.getDiags().diagnose(SourceLoc(), diag::error_cas,
1774+
toString(std::move(E)));
16791775
}
16801776
}
16811777

@@ -1756,8 +1852,8 @@ swift::dependencies::performModuleScan(CompilerInstance &instance,
17561852

17571853
auto topologicallySortedModuleList =
17581854
computeTopologicalSortOfExplicitDependencies(allModules, cache);
1759-
resolveDependencyInputCommandLineArguments(instance, cache,
1760-
topologicallySortedModuleList);
1855+
resolveDependencyCommandLineArguments(instance, cache,
1856+
topologicallySortedModuleList);
17611857

17621858
updateDependencyTracker(instance, cache, allModules);
17631859
return generateFullDependencyGraph(instance, cache,

0 commit comments

Comments
 (0)