Skip to content

Commit 5b9d68b

Browse files
committed
Merge branch 'main' into observation_peer_macros
2 parents c5fbb42 + 67e919f commit 5b9d68b

File tree

190 files changed

+6397
-3368
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+6397
-3368
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/StackPromotion.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,14 +289,13 @@ private extension BasicBlockRange {
289289
/// Returns true if there is a direct edge connecting this range with the `otherRange`.
290290
func hasControlFlowEdge(to otherRange: BasicBlockRange) -> Bool {
291291
func isOnlyInOtherRange(_ block: BasicBlock) -> Bool {
292-
return !inclusiveRangeContains(block) &&
293-
otherRange.inclusiveRangeContains(block) && block != otherRange.begin
292+
return !inclusiveRangeContains(block) && otherRange.inclusiveRangeContains(block)
294293
}
295294

296295
for lifeBlock in inclusiveRange {
297296
assert(otherRange.inclusiveRangeContains(lifeBlock), "range must be a subset of other range")
298297
for succ in lifeBlock.successors {
299-
if isOnlyInOtherRange(succ) {
298+
if isOnlyInOtherRange(succ) && succ != otherRange.begin {
300299
return true
301300
}
302301
// The entry of the begin-block is conceptually not part of the range. We can check if

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyInitEnumDataAddr.swift

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ extension InitEnumDataAddrInst : OnoneSimplifyable {
1818
// Optimize the sequence
1919
// ```
2020
// %1 = init_enum_data_addr %enum_addr, #someCaseWithPayload
21+
// ...
2122
// store %payload to %1
2223
// inject_enum_addr %enum_addr, #someCaseWithPayload
2324
// ```
@@ -26,18 +27,16 @@ extension InitEnumDataAddrInst : OnoneSimplifyable {
2627
// %1 = enum $E, #someCaseWithPayload, %payload
2728
// store %1 to %enum_addr
2829
// ```
29-
// This sequence of three instructions must appear in consecutive order.
30+
// This store and inject instructions must appear in consecutive order.
3031
// But usually this is the case, because it's generated this way by SILGen.
32+
// We also check that between the init and the store, no instruction writes to memory.
3133
//
32-
if let nextInst = self.next,
33-
let store = nextInst as? StoreInst,
34+
if let store = self.uses.singleUse?.instruction as? StoreInst,
3435
store.destination == self,
35-
let singleUse = self.uses.singleUse,
36-
singleUse.instruction == store,
37-
let nextAfterStore = store.next,
38-
let inject = nextAfterStore as? InjectEnumAddrInst,
36+
let inject = store.next as? InjectEnumAddrInst,
3937
inject.enum == self.enum,
40-
inject.enum.type.isLoadable(in: parentFunction) {
38+
inject.enum.type.isLoadable(in: parentFunction),
39+
!anyInstructionMayWriteToMemory(between: self, and: store) {
4140

4241
assert(self.caseIndex == inject.caseIndex, "mismatching case indices when creating an enum")
4342

@@ -51,3 +50,19 @@ extension InitEnumDataAddrInst : OnoneSimplifyable {
5150
}
5251
}
5352
}
53+
54+
// Returns false if `first` and `last` are in the same basic block and no instructions between them write to memory. True otherwise.
55+
private func anyInstructionMayWriteToMemory(between first: Instruction, and last: Instruction) -> Bool {
56+
var nextInstruction = first.next
57+
while let i = nextInstruction {
58+
if i == last {
59+
return false
60+
}
61+
if i.mayWriteToMemory {
62+
return true
63+
}
64+
nextInstruction = i.next
65+
}
66+
// End of basic block, and we did not find `last`
67+
return true
68+
}

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ extension Instruction {
8282
return type.isBuiltinInteger || type.isBuiltinFloat
8383
case .PtrToInt:
8484
return bi.operands[0].value is StringLiteralInst
85+
case .IntToPtr:
86+
return bi.operands[0].value is IntegerLiteralInst
8587
case .StringObjectOr:
8688
// The first operand can be a string literal (i.e. a pointer), but the
8789
// second operand must be a constant. This enables creating a

include/swift-c/DependencyScan/DependencyScan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ typedef enum {
440440
SWIFTSCAN_OUTPUT_TYPE_OBJECT = 0,
441441
SWIFTSCAN_OUTPUT_TYPE_SWIFTMODULE = 1,
442442
SWIFTSCAN_OUTPUT_TYPE_SWIFTINTERFACE = 2,
443-
SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIAVEINTERFACE = 3,
443+
SWIFTSCAN_OUTPUT_TYPE_SWIFTPRIVATEINTERFACE = 3,
444444
SWIFTSCAN_OUTPUT_TYPE_CLANG_MODULE = 4,
445445
SWIFTSCAN_OUTPUT_TYPE_CLANG_PCH = 5
446446
} swiftscan_output_kind_t;

include/swift/AST/Attr.def.gyb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ TYPE_ATTR(objc_metatype)
8686
TYPE_ATTR(opened)
8787
TYPE_ATTR(pack_element)
8888
TYPE_ATTR(pseudogeneric)
89+
TYPE_ATTR(unimplementable)
8990
TYPE_ATTR(yields)
9091
TYPE_ATTR(yield_once)
9192
TYPE_ATTR(yield_many)

include/swift/AST/CASTBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(closed) BridgedTypeAttrKind : long {
190190
BridgedTypeAttrKind_opened,
191191
BridgedTypeAttrKind_pack_element,
192192
BridgedTypeAttrKind_pseudogeneric,
193+
BridgedTypeAttrKind_unimplementable,
193194
BridgedTypeAttrKind_yields,
194195
BridgedTypeAttrKind_yield_once,
195196
BridgedTypeAttrKind_yield_many,

include/swift/AST/DiagnosticsSIL.def

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ ERROR(c_function_pointer_from_function_with_context,none,
115115
ERROR(objc_selector_malformed,none,"the type ObjectiveC.Selector is malformed",
116116
())
117117

118+
ERROR(unsupported_variadic_function_abstraction,none,
119+
"cannot fully abstract a value of variadic function type %0 because "
120+
"different contexts will not be able to reliably agree on a calling "
121+
"convention; try wrapping it in a struct",
122+
(Type))
123+
118124
// Capture before declaration diagnostics.
119125
ERROR(capture_before_declaration,none,
120126
"closure captures %0 before it is declared", (Identifier))
@@ -859,9 +865,13 @@ NOTE(sil_referencebinding_inout_binding_here, none,
859865
// Warnings arising from the flow-sensitive checking of Sendability of
860866
// non-Sendable values
861867
WARNING(consumed_value_used, none,
862-
"Non-Sendable value consumed, then used at this site; could yield race with another thread", ())
868+
"non-Sendable value consumed, then used at this site; could yield race with another thread", ())
863869
WARNING(arg_region_consumed, none,
864-
"This application could pass `self` or a Non-Sendable argument of this function to another thread, potentially yielding a race with the caller", ())
870+
"this application could pass `self` or a Non-Sendable argument of this function to another thread, potentially yielding a race with the caller", ())
871+
WARNING(consumption_yields_race, none,
872+
"non-Sendable value sent across isolation domains here, but could be accessed later in this function (%0 access site%select{|s}1 displayed%select{|, %3 more hidden}2)", (unsigned, bool, bool, unsigned))
873+
NOTE(possible_racy_access_site, none,
874+
"access here could race with non-Sendable value send above", ())
865875

866876
#define UNDEFINE_DIAGNOSTIC_MACROS
867877
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3370,7 +3370,8 @@ ERROR(decl_from_hidden_module,none,
33703370
"it is an SPI imported from %3|"
33713371
"it is SPI|"
33723372
"%3 was imported for SPI only|"
3373-
"%3 was not imported by this file}4",
3373+
"%3 was not imported by this file|"
3374+
"C++ types from imported module %3 do not support library evolution}4",
33743375
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
33753376
WARNING(decl_from_hidden_module_warn,none,
33763377
"cannot use %0 %1 %select{here|as property wrapper here|"
@@ -3391,7 +3392,8 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
33913392
"it is an SPI imported from %4|"
33923393
"<<ERROR>>|"
33933394
"%4 was imported for SPI only|"
3394-
"%4 was not imported by this file}5",
3395+
"%4 was not imported by this file|"
3396+
"C++ types from imported module %4 do not support library evolution}5",
33953397
(DeclName, StringRef, StringRef, unsigned, Identifier, unsigned))
33963398
ERROR(conformance_from_implementation_only_module,none,
33973399
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
@@ -3402,7 +3404,8 @@ ERROR(conformance_from_implementation_only_module,none,
34023404
"the conformance is declared as SPI in %3|"
34033405
"the conformance is declared as SPI|"
34043406
"%3 was imported for SPI only|"
3405-
"%3 was not imported by this file}4",
3407+
"%3 was not imported by this file|"
3408+
"C++ types from imported module %3 do not support library evolution}4",
34063409
(Type, Identifier, unsigned, Identifier, unsigned))
34073410
NOTE(assoc_conformance_from_implementation_only_module,none,
34083411
"in associated type %0 (inferred as %1)", (Type, Type))
@@ -6513,7 +6516,8 @@ ERROR(inlinable_decl_ref_from_hidden_module,
65136516
"it is an SPI imported from %3|"
65146517
"it is SPI|"
65156518
"%3 was imported for SPI only|"
6516-
"%3 was not imported by this file}4",
6519+
"%3 was not imported by this file|"
6520+
"C++ APIs from imported module %3 do not support library evolution}4",
65176521
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
65186522

65196523
WARNING(inlinable_decl_ref_from_hidden_module_warn,
@@ -6529,7 +6533,8 @@ ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,
65296533
"it is an SPI imported from %4|"
65306534
"<<ERROR>>|"
65316535
"%4 was imported for SPI only|"
6532-
"%4 was not imported by this file}5",
6536+
"%4 was not imported by this file|"
6537+
"C++ types from imported module %4 do not support library evolution}5",
65336538
(DeclName, StringRef, StringRef, unsigned, Identifier, unsigned))
65346539

65356540
NOTE(missing_import_inserted,
@@ -7249,6 +7254,9 @@ ERROR(literal_type_in_macro_expansion,none,
72497254
ERROR(invalid_macro_introduced_name,none,
72507255
"declaration name %0 is not covered by macro %1",
72517256
(DeclName, DeclName))
7257+
ERROR(undocumented_conformance_in_expansion,none,
7258+
"conformance to %0 is not covered by macro %1",
7259+
(Type, DeclName))
72527260
ERROR(invalid_macro_role_for_macro_syntax,none,
72537261
"invalid macro role for %{a freestanding|an attached}0 macro",
72547262
(unsigned))
@@ -7271,6 +7279,9 @@ ERROR(local_extension_macro,none,
72717279
ERROR(extension_macro_invalid_conformance,none,
72727280
"invalid protocol conformance %0 in extension macro",
72737281
(Type))
7282+
ERROR(macro_attached_to_invalid_decl,none,
7283+
"'%0' macro cannot be attached to %1",
7284+
(StringRef, DescriptiveDeclKind))
72747285

72757286
ERROR(macro_resolve_circular_reference, none,
72767287
"circular reference resolving %select{freestanding|attached}0 macro %1",

include/swift/AST/ExtInfo.h

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,8 +651,10 @@ class SILExtInfoBuilder {
651651
// If bits are added or removed, then TypeBase::SILFunctionTypeBits
652652
// and NumMaskBits must be updated, and they must match.
653653

654-
// |representation|pseudogeneric| noescape | concurrent | async |differentiability|
655-
// | 0 .. 3 | 4 | 5 | 6 | 7 | 8 .. 10 |
654+
// |representation|pseudogeneric| noescape | concurrent | async
655+
// | 0 .. 3 | 4 | 5 | 6 | 7
656+
// |differentiability|unimplementable|
657+
// | 8 .. 10 | 11 |
656658
//
657659
enum : unsigned {
658660
RepresentationMask = 0xF << 0,
@@ -662,7 +664,8 @@ class SILExtInfoBuilder {
662664
AsyncMask = 1 << 7,
663665
DifferentiabilityMaskOffset = 8,
664666
DifferentiabilityMask = 0x7 << DifferentiabilityMaskOffset,
665-
NumMaskBits = 11
667+
UnimplementableMask = 1 << 11,
668+
NumMaskBits = 12
666669
};
667670

668671
unsigned bits; // Naturally sized for speed.
@@ -677,12 +680,13 @@ class SILExtInfoBuilder {
677680

678681
static constexpr unsigned makeBits(Representation rep, bool isPseudogeneric,
679682
bool isNoEscape, bool isSendable,
680-
bool isAsync,
683+
bool isAsync, bool isUnimplementable,
681684
DifferentiabilityKind diffKind) {
682685
return ((unsigned)rep) | (isPseudogeneric ? PseudogenericMask : 0) |
683686
(isNoEscape ? NoEscapeMask : 0) |
684687
(isSendable ? SendableMask : 0) |
685688
(isAsync ? AsyncMask : 0) |
689+
(isUnimplementable ? UnimplementableMask : 0) |
686690
(((unsigned)diffKind << DifferentiabilityMaskOffset) &
687691
DifferentiabilityMask);
688692
}
@@ -692,22 +696,23 @@ class SILExtInfoBuilder {
692696
/// non-pseudogeneric, non-differentiable.
693697
SILExtInfoBuilder()
694698
: SILExtInfoBuilder(makeBits(SILFunctionTypeRepresentation::Thick, false,
695-
false, false, false,
699+
false, false, false, false,
696700
DifferentiabilityKind::NonDifferentiable),
697701
ClangTypeInfo(nullptr)) {}
698702

699703
SILExtInfoBuilder(Representation rep, bool isPseudogeneric, bool isNoEscape,
700-
bool isSendable, bool isAsync,
704+
bool isSendable, bool isAsync, bool isUnimplementable,
701705
DifferentiabilityKind diffKind, const clang::Type *type)
702706
: SILExtInfoBuilder(makeBits(rep, isPseudogeneric, isNoEscape,
703-
isSendable, isAsync, diffKind),
707+
isSendable, isAsync, isUnimplementable,
708+
diffKind),
704709
ClangTypeInfo(type)) {}
705710

706711
// Constructor for polymorphic type.
707712
SILExtInfoBuilder(ASTExtInfoBuilder info, bool isPseudogeneric)
708713
: SILExtInfoBuilder(makeBits(info.getSILRepresentation(), isPseudogeneric,
709714
info.isNoEscape(), info.isSendable(),
710-
info.isAsync(),
715+
info.isAsync(), /*unimplementable*/ false,
711716
info.getDifferentiabilityKind()),
712717
info.getClangTypeInfo()) {}
713718

@@ -746,6 +751,10 @@ class SILExtInfoBuilder {
746751
DifferentiabilityKind::NonDifferentiable;
747752
}
748753

754+
constexpr bool isUnimplementable() const {
755+
return bits & UnimplementableMask;
756+
}
757+
749758
/// Get the underlying ClangTypeInfo value.
750759
ClangTypeInfo getClangTypeInfo() const { return clangTypeInfo; }
751760

@@ -816,6 +825,12 @@ class SILExtInfoBuilder {
816825
clangTypeInfo);
817826
}
818827
[[nodiscard]]
828+
SILExtInfoBuilder withUnimplementable(bool isUnimplementable = true) const {
829+
return SILExtInfoBuilder(isUnimplementable ? (bits | UnimplementableMask)
830+
: (bits & ~UnimplementableMask),
831+
clangTypeInfo);
832+
}
833+
[[nodiscard]]
819834
SILExtInfoBuilder
820835
withDifferentiabilityKind(DifferentiabilityKind differentiability) const {
821836
return SILExtInfoBuilder(
@@ -828,6 +843,7 @@ class SILExtInfoBuilder {
828843
return SILExtInfoBuilder(bits, ClangTypeInfo(type).getCanonical());
829844
}
830845

846+
831847
bool isEqualTo(SILExtInfoBuilder other, bool useClangTypes) const {
832848
return bits == other.bits &&
833849
(useClangTypes ? (clangTypeInfo == other.clangTypeInfo) : true);
@@ -873,7 +889,7 @@ class SILExtInfo {
873889
/// A default ExtInfo but with a Thin convention.
874890
static SILExtInfo getThin() {
875891
return SILExtInfoBuilder(SILExtInfoBuilder::Representation::Thin, false,
876-
false, false, false,
892+
false, false, false, false,
877893
DifferentiabilityKind::NonDifferentiable, nullptr)
878894
.build();
879895
}
@@ -901,6 +917,10 @@ class SILExtInfo {
901917

902918
constexpr bool isAsync() const { return builder.isAsync(); }
903919

920+
constexpr bool isUnimplementable() const {
921+
return builder.isUnimplementable();
922+
}
923+
904924
constexpr DifferentiabilityKind getDifferentiabilityKind() const {
905925
return builder.getDifferentiabilityKind();
906926
}
@@ -935,6 +955,10 @@ class SILExtInfo {
935955
return builder.withAsync(isAsync).build();
936956
}
937957

958+
SILExtInfo withUnimplementable(bool isUnimplementable = true) const {
959+
return builder.withUnimplementable(isUnimplementable).build();
960+
}
961+
938962
bool isEqualTo(SILExtInfo other, bool useClangTypes) const {
939963
return builder.isEqualTo(other.builder, useClangTypes);
940964
}

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ IDENTIFIER(size)
325325
IDENTIFIER(speed)
326326
IDENTIFIER(unchecked)
327327
IDENTIFIER(unsafe)
328-
IDENTIFIER(element)
329328

330329
// The singleton instance of TupleTypeDecl in the Builtin module
331330
IDENTIFIER(TheTupleType)

include/swift/AST/ModuleDependencies.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,13 @@ class ModuleDependencyInfoStorageBase {
110110
ModuleDependencyInfoStorageBase(ModuleDependencyKind dependencyKind,
111111
StringRef moduleCacheKey = "")
112112
: dependencyKind(dependencyKind), moduleCacheKey(moduleCacheKey.str()),
113-
resolved(false) { }
113+
resolved(false), finalized(false) {}
114114

115115
ModuleDependencyInfoStorageBase(ModuleDependencyKind dependencyKind,
116116
const std::vector<std::string> &moduleImports,
117117
StringRef moduleCacheKey = "")
118118
: dependencyKind(dependencyKind), moduleImports(moduleImports),
119-
moduleCacheKey(moduleCacheKey.str()), resolved(false) {}
119+
moduleCacheKey(moduleCacheKey.str()), resolved(false), finalized(false) {}
120120

121121
virtual ModuleDependencyInfoStorageBase *clone() const = 0;
122122

@@ -137,7 +137,11 @@ class ModuleDependencyInfoStorageBase {
137137
/// The cache key for the produced module.
138138
std::string moduleCacheKey;
139139

140+
/// The direct dependency of the module is resolved by scanner.
140141
bool resolved;
142+
/// ModuleDependencyInfo is finalized (with all transitive dependencies
143+
/// and inputs).
144+
bool finalized;
141145
};
142146

143147
struct CommonSwiftTextualModuleDependencyDetails {
@@ -604,6 +608,13 @@ class ModuleDependencyInfo {
604608
storage->resolved = isResolved;
605609
}
606610

611+
bool isFinalized() const {
612+
return storage->finalized;
613+
}
614+
void setIsFinalized(bool isFinalized) {
615+
storage->finalized = isFinalized;
616+
}
617+
607618
/// For a Source dependency, register a `Testable` import
608619
void addTestableImport(ImportPath::Module module);
609620

include/swift/AST/TypeMemberVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class TypeMemberVisitor : public DeclVisitor<ImplClass, RetTy> {
7171
///
7272
/// \seealso IterableDeclContext::getImplementationContext()
7373
void visitImplementationMembers(NominalTypeDecl *D) {
74-
for (Decl *member : D->getImplementationContext()->getMembers()) {
74+
for (Decl *member : D->getImplementationContext()->getAllMembers()) {
7575
asImpl().visit(member);
7676
}
7777

0 commit comments

Comments
 (0)