Skip to content

Commit 25f078a

Browse files
authored
Merge branch 'main' into lazy-immediate
2 parents 831cfb5 + 88c4141 commit 25f078a

File tree

185 files changed

+3406
-4467
lines changed

Some content is hidden

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

185 files changed

+3406
-4467
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,24 @@ private struct CollectedEffects {
142142
handleApply(pa)
143143
checkedIfDeinitBarrier = true
144144
}
145+
// In addition to the effects of the apply, also consider the
146+
// effects of the capture, which reads the captured value in
147+
// order to move it into the context. This only applies to
148+
// addressible values, because capturing does not dereference
149+
// any class objects.
150+
//
151+
// Ignore captures for on-stack partial applies. They only
152+
// bitwise-move or capture by address, so the call to
153+
// handleApply above is sufficient. And, if they are not applied
154+
// in this function, then they are never applied.
155+
if !pa.isOnStack {
156+
// the callee and its arguments are all captured...
157+
for operand in pa.operands {
158+
if operand.value.type.isAddress {
159+
addEffects(.read, to: operand.value)
160+
}
161+
}
162+
}
145163

146164
case let fl as FixLifetimeInst:
147165
// A fix_lifetime instruction acts like a read on the operand to prevent

docs/ABI/Mangling.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ Globals
150150
#endif
151151
global ::= protocol-conformance 'Hc' // protocol conformance runtime record
152152
global ::= global 'HF' // accessible function runtime record
153-
global ::= global 'Ha' // runtime discoverable attribute record
154153

155154
global ::= nominal-type 'Mo' // class metadata immediate member base offset
156155

include/swift/ABI/Metadata.h

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,48 +4907,6 @@ struct TargetAccessibleFunctionRecord final {
49074907

49084908
using AccessibleFunctionRecord = TargetAccessibleFunctionRecord<InProcess>;
49094909

4910-
/// A single entry in an runtine discoverable attribute record
4911-
/// that relates a type attribute is attached to a generator function.
4912-
template <typename Runtime>
4913-
struct TargetRuntimeDiscoverableAttributeEntry {
4914-
RelativeDirectPointer<const char, /*nullable*/ false> Type;
4915-
RelativeDirectPointer<TargetAccessibleFunctionRecord<Runtime>> Generator;
4916-
};
4917-
4918-
/// A record that relates a runtime discoverable attribute to all of the
4919-
/// types (i.e. a nominal type, method, property etc.) it's attached to.
4920-
template <typename Runtime>
4921-
class RuntimeDiscoverableAttributeRecord
4922-
: private swift::ABI::TrailingObjects<
4923-
RuntimeDiscoverableAttributeRecord<Runtime>,
4924-
TargetRuntimeDiscoverableAttributeEntry<Runtime>> {
4925-
using TrailingObjects = swift::ABI::TrailingObjects<
4926-
RuntimeDiscoverableAttributeRecord<Runtime>,
4927-
ConstTargetMetadataPointer<Runtime, TargetMetadata>>;
4928-
friend TrailingObjects;
4929-
4930-
uint32_t flags;
4931-
4932-
/// The nominal type that describes the attribute.
4933-
TargetRelativeIndirectablePointer<Runtime,
4934-
TargetTypeContextDescriptor<Runtime>,
4935-
/*nullable*/ false>
4936-
Attribute;
4937-
4938-
/// The number of types this attribute is associated with.
4939-
uint32_t numEntries;
4940-
4941-
public:
4942-
uint32_t getFlags() { return flags; }
4943-
4944-
llvm::ArrayRef<TargetRuntimeDiscoverableAttributeEntry<Runtime>>
4945-
getEntries() const {
4946-
return {this->template getTrailingObjects<
4947-
TargetRuntimeDiscoverableAttributeEntry<Runtime>>(),
4948-
numEntries};
4949-
}
4950-
};
4951-
49524910
enum class PackLifetime : uint8_t {
49534911
OnStack = 0,
49544912
OnHeap = 1

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ class ASTContext final {
941941
/// descriptors.
942942
AvailabilityContext getSignedDescriptorAvailability();
943943

944+
/// Get the runtime availability of the swift_initRawStructMetadata entrypoint
945+
/// that fixes up the value witness table of @_rawLayout dependent types.
946+
AvailabilityContext getInitRawStructMetadataAvailability();
947+
944948
/// Get the runtime availability of features introduced in the Swift 5.2
945949
/// compiler for the target platform.
946950
AvailabilityContext getSwift52Availability();

include/swift/AST/ASTMangler.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ class ASTMangler : public Mangler {
161161
BackDeploymentThunk,
162162
BackDeploymentFallback,
163163
HasSymbolQuery,
164-
RuntimeDiscoverableAttributeRecord,
165164
};
166165

167166
/// lldb overrides the defaulted argument to 'true'.
@@ -363,10 +362,6 @@ class ASTMangler : public Mangler {
363362

364363
std::string mangleHasSymbolQuery(const ValueDecl *decl);
365364

366-
std::string
367-
mangleRuntimeAttributeGeneratorEntity(const ValueDecl *decl, CustomAttr *attr,
368-
SymbolKind SKind = SymbolKind::Default);
369-
370365
std::string mangleMacroExpansion(const FreestandingMacroExpansion *expansion);
371366
std::string mangleAttachedMacroExpansion(
372367
const Decl *decl, CustomAttr *attr, MacroRole role);
@@ -603,9 +598,6 @@ class ASTMangler : public Mangler {
603598

604599
void appendConstrainedExistential(Type base, GenericSignature sig,
605600
const ValueDecl *forDecl);
606-
607-
void appendRuntimeAttributeGeneratorEntity(const ValueDecl *decl,
608-
CustomAttr *attr);
609601
};
610602

611603
} // end namespace Mangle

include/swift/AST/Attr.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -416,9 +416,6 @@ DECL_ATTR(_documentation, Documentation,
416416
SIMPLE_DECL_ATTR(_noMetadata, NoMetadata,
417417
OnGenericTypeParam | UserInaccessible | NotSerialized | ABIStableToAdd | ABIBreakingToRemove | APIStableToAdd | APIStableToRemove,
418418
138)
419-
SIMPLE_DECL_ATTR(runtimeMetadata, RuntimeMetadata,
420-
OnStruct | OnClass | OnEnum | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
421-
139)
422419
SIMPLE_DECL_ATTR(_used, Used,
423420
OnAbstractFunction | OnVar | UserInaccessible | ABIBreakingToAdd | ABIBreakingToRemove | APIBreakingToAdd | APIBreakingToRemove,
424421
143)

include/swift/AST/ConstTypeInfo.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,18 @@ struct ConstValueTypePropertyInfo {
233233
swift::VarDecl *VarDecl;
234234
std::shared_ptr<CompileTimeValue> Value;
235235
llvm::Optional<AttrValueVector> PropertyWrappers;
236-
llvm::Optional<AttrValueVector> RuntimeMetadataAttributes;
237236

238237
ConstValueTypePropertyInfo(
239238
swift::VarDecl *VarDecl, std::shared_ptr<CompileTimeValue> Value,
240-
llvm::Optional<AttrValueVector> PropertyWrappers,
241-
llvm::Optional<AttrValueVector> RuntimeMetadataAttributes)
242-
: VarDecl(VarDecl), Value(Value), PropertyWrappers(PropertyWrappers),
243-
RuntimeMetadataAttributes(RuntimeMetadataAttributes) {}
239+
llvm::Optional<AttrValueVector> PropertyWrappers)
240+
: VarDecl(VarDecl), Value(Value), PropertyWrappers(PropertyWrappers)
241+
{}
244242

245243
ConstValueTypePropertyInfo(swift::VarDecl *VarDecl,
246244
std::shared_ptr<CompileTimeValue> Value)
247245
: VarDecl(VarDecl), Value(Value),
248-
PropertyWrappers(llvm::Optional<AttrValueVector>()),
249-
RuntimeMetadataAttributes(llvm::Optional<AttrValueVector>()) {}
246+
PropertyWrappers(llvm::Optional<AttrValueVector>())
247+
{}
250248
};
251249

252250
struct ConstValueTypeInfo {

include/swift/AST/Decl.h

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -650,13 +650,16 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
650650
/// address diversified ptrauth qualified field.
651651
IsNonTrivialPtrAuth : 1);
652652

653-
SWIFT_INLINE_BITFIELD(EnumDecl, NominalTypeDecl, 2+1,
653+
SWIFT_INLINE_BITFIELD(EnumDecl, NominalTypeDecl, 2+1+1,
654654
/// True if the enum has cases and at least one case has associated values.
655655
HasAssociatedValues : 2,
656656
/// True if the enum has at least one case that has some availability
657657
/// attribute. A single bit because it's lazily computed along with the
658658
/// HasAssociatedValues bit.
659-
HasAnyUnavailableValues : 1
659+
HasAnyUnavailableValues : 1,
660+
/// True if \c isAvailableDuringLowering() is false for any cases. Lazily
661+
/// computed along with HasAssociatedValues.
662+
HasAnyUnavailableDuringLoweringValues : 1
660663
);
661664

662665
SWIFT_INLINE_BITFIELD(ModuleDecl, TypeDecl, 1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1,
@@ -895,10 +898,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
895898
return Attrs;
896899
}
897900

898-
/// Retrieve runtime discoverable attributes (if any) associated
899-
/// with this declaration.
900-
ArrayRef<CustomAttr *> getRuntimeDiscoverableAttrs() const;
901-
902901
/// Returns the attributes that were directly attached to this declaration
903902
/// as written in source, ie. does not include attributes generated by macro
904903
/// expansions.
@@ -1237,7 +1236,10 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
12371236
/// Returns true if this declaration should be considered available during
12381237
/// SIL/IR lowering. A declaration would not be available during lowering if,
12391238
/// for example, it is annotated as unavailable with `@available` and
1240-
/// optimization settings require that it be omitted.
1239+
/// optimization settings require that it be omitted. Canonical SIL must not
1240+
/// contain any references to declarations that are unavailable during
1241+
/// lowering because the resulting IR could reference non-existent symbols
1242+
/// and fail to link.
12411243
bool isAvailableDuringLowering() const;
12421244

12431245
/// Returns true if ABI compatibility stubs must be emitted for the given
@@ -2980,19 +2982,6 @@ class ValueDecl : public Decl {
29802982
/// 'func foo(Int) -> () -> Self?'.
29812983
GenericParameterReferenceInfo findExistentialSelfReferences(
29822984
Type baseTy, bool treatNonResultCovariantSelfAsInvariant) const;
2983-
2984-
/// Retrieve a nominal type declaration backing given runtime discoverable
2985-
/// attribute.
2986-
///
2987-
/// FIXME: This should be a more general facility but its unclear where
2988-
/// to place it for maximum impact.
2989-
NominalTypeDecl *getRuntimeDiscoverableAttrTypeDecl(CustomAttr *attr) const;
2990-
2991-
/// Given a runtime discoverable attribute, return a generator
2992-
/// which could be used to instantiate it for this declaration
2993-
/// together with its result type.
2994-
std::pair<BraceStmt *, Type>
2995-
getRuntimeDiscoverableAttributeGenerator(CustomAttr *) const;
29962985
};
29972986

29982987
/// This is a common base class for declarations which declare a type.
@@ -4204,6 +4193,11 @@ class EnumDecl final : public NominalTypeDecl {
42044193
/// A range for iterating the elements of an enum.
42054194
using ElementRange = DowncastFilterRange<EnumElementDecl, DeclRange>;
42064195

4196+
/// A range for iterating the elements of an enum that are available during
4197+
/// lowering.
4198+
using ElementRangeForLowering = OptionalTransformRange<
4199+
ElementRange, AvailableDuringLoweringDeclFilter<EnumElementDecl>>;
4200+
42074201
/// A range for iterating the cases of an enum.
42084202
using CaseRange = DowncastFilterRange<EnumCaseDecl, DeclRange>;
42094203

@@ -4217,6 +4211,13 @@ class EnumDecl final : public NominalTypeDecl {
42174211
return std::distance(eltRange.begin(), eltRange.end());
42184212
}
42194213

4214+
/// Returns a range that iterates over all the elements of an enum for which
4215+
/// \c isAvailableDuringLowering() is true.
4216+
ElementRangeForLowering getAllElementsForLowering() const {
4217+
return ElementRangeForLowering(
4218+
getAllElements(), AvailableDuringLoweringDeclFilter<EnumElementDecl>());
4219+
}
4220+
42204221
/// If this enum has a unique element, return it. A unique element can
42214222
/// either hold a value or not, and the existence of one unique element does
42224223
/// not imply the existence or non-existence of the opposite unique element.
@@ -4279,6 +4280,11 @@ class EnumDecl final : public NominalTypeDecl {
42794280
/// Note that this is false for enums with absolutely no cases.
42804281
bool hasPotentiallyUnavailableCaseValue() const;
42814282

4283+
/// True if \c isAvailableDuringLowering() is false for any cases.
4284+
///
4285+
/// Note that this is false for enums with absolutely no cases.
4286+
bool hasCasesUnavailableDuringLowering() const;
4287+
42824288
/// True if the enum has cases.
42834289
bool hasCases() const {
42844290
return !getAllElements().empty();
@@ -5973,9 +5979,6 @@ class VarDecl : public AbstractStorageDecl {
59735979
/// that has an external effect on the function.
59745980
bool hasExternalPropertyWrapper() const;
59755981

5976-
/// Whether this property has any attached runtime metadata attributes.
5977-
bool hasRuntimeMetadataAttributes() const;
5978-
59795982
/// Whether all of the attached property wrappers have an init(wrappedValue:)
59805983
/// initializer.
59815984
bool allAttachedPropertyWrappersHaveWrappedValueInit() const;

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,10 +1104,6 @@ ERROR(expected_expr_throw,PointsToFirstBadToken,
11041104
// Discard Statement
11051105
ERROR(expected_expr_discard,PointsToFirstBadToken,
11061106
"expected expression in 'discard' statement", ())
1107-
WARNING(forget_is_deprecated,PointsToFirstBadToken,
1108-
"'_forget' keyword is deprecated and will be removed soon; "
1109-
"use 'discard' instead",
1110-
())
11111107

11121108
// Await/Async
11131109
ERROR(expected_await_not_async,none,

include/swift/AST/DiagnosticsSema.def

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,6 +1800,11 @@ NOTE(objc_implementation_one_matched_requirement,none,
18001800
"'@objc(%3)' to use it}2",
18011801
(ValueDecl *, ObjCSelector, bool, StringRef))
18021802

1803+
WARNING(wrap_objc_implementation_will_become_error,none,
1804+
"%0; this will become an error before '@_objcImplementation' is "
1805+
"stabilized",
1806+
(DiagnosticInfo *))
1807+
18031808
ERROR(cdecl_not_at_top_level,none,
18041809
"@_cdecl can only be applied to global functions", ())
18051810
ERROR(cdecl_empty_name,none,
@@ -6687,7 +6692,7 @@ WARNING(hashvalue_implementation,Deprecation,
66876692
"conform type %0 to 'Hashable' by implementing 'hash(into:)' instead",
66886693
(Type))
66896694

6690-
WARNING(executor_enqueue_unowned_implementation,Deprecation,
6695+
WARNING(executor_enqueue_deprecated_unowned_implementation,Deprecation,
66916696
"'Executor.enqueue(UnownedJob)' is deprecated as a protocol requirement; "
66926697
"conform type %0 to 'Executor' by implementing 'func enqueue(ExecutorJob)' instead",
66936698
(Type))
@@ -7082,7 +7087,7 @@ ERROR(attr_incompatible_with_back_deploy,none,
70827087
"'%0' cannot be applied to a back deployed %1",
70837088
(DeclAttribute, DescriptiveDeclKind))
70847089

7085-
ERROR(backdeployed_opaque_result_not_supported,none,
7090+
WARNING(backdeployed_opaque_result_not_supported,none,
70867091
"'%0' is unsupported on a %1 with a 'some' return type",
70877092
(DeclAttribute, DescriptiveDeclKind))
70887093

@@ -7154,9 +7159,7 @@ ERROR(macro_undefined,PointsToFirstBadToken,
71547159
"no macro named %0", (Identifier))
71557160
ERROR(external_macro_not_found,none,
71567161
"external macro implementation type '%0.%1' could not be found for "
7157-
"macro %2; the type must be public and provided by a macro target in a "
7158-
"Swift package, or via '-plugin-path' or '-load-plugin-library'",
7159-
(StringRef, StringRef, DeclName))
7162+
"macro %2", (StringRef, StringRef, DeclName))
71607163
ERROR(macro_must_be_defined,none,
71617164
"macro %0 requires a definition", (DeclName))
71627165
ERROR(external_macro_outside_macro_definition,none,
@@ -7374,62 +7377,6 @@ ERROR(noncopyable_cannot_have_read_set_accessor,none,
73747377
"noncopyable %select{variable|subscript}0 cannot provide a read and set accessor",
73757378
(unsigned))
73767379

7377-
//------------------------------------------------------------------------------
7378-
// MARK: Runtime discoverable attributes (@runtimeMetadata)
7379-
//------------------------------------------------------------------------------
7380-
7381-
ERROR(runtime_discoverable_attrs_are_experimental,none,
7382-
"runtime discoverable attributes are an experimental feature", ())
7383-
7384-
ERROR(invalid_decl_for_runtime_discoverable_attr,none,
7385-
"@%0 can only be applied to non-generic types, methods, "
7386-
"instance properties, and global functions", (StringRef))
7387-
7388-
ERROR(invalid_decl_for_runtime_discoverable_attr_in_extension,none,
7389-
"@%0 can only be applied to unavailable extensions in the same module"
7390-
" as %1", (StringRef, DeclName))
7391-
7392-
ERROR(invalid_attr_redeclaration_in_extension,none,
7393-
"@%0 is already applied to type %1; did you want to remove it?",
7394-
(StringRef, DeclName))
7395-
7396-
ERROR(duplicate_runtime_discoverable_attr,none,
7397-
"duplicate runtime discoverable attribute", ())
7398-
7399-
ERROR(runtime_attribute_requires_init,none,
7400-
"runtime attribute type %0 does not contain a required initializer"
7401-
" - init(attachedTo:)",
7402-
(DeclName))
7403-
7404-
ERROR(runtime_attribute_type_failable_init,none,
7405-
"runtime attribute type initializer %0 cannot be failable", (DeclName))
7406-
7407-
ERROR(runtime_attribute_type_requirement_not_accessible,none,
7408-
"%select{private|fileprivate|internal|package|public|open}0 %kind1 cannot have "
7409-
"more restrictive access than its enclosing runtime attribute type %2 "
7410-
"(which is %select{private|fileprivate|internal|package|public|open}3)",
7411-
(AccessLevel, const ValueDecl *, Type, AccessLevel))
7412-
7413-
ERROR(cannot_use_attr_with_custom_arguments_on_protocol,none,
7414-
"reflection metadata attributes applied to protocols cannot have"
7415-
" additional attribute arguments; attribute arguments must be"
7416-
" explicitly written on the conforming type",
7417-
())
7418-
7419-
NOTE(missing_reflection_metadata_attribute_on_type,none,
7420-
"protocol %0 requires reflection metadata attribute @%1",
7421-
(DeclName, StringRef))
7422-
7423-
ERROR(missing_reflection_metadata_attribute_on_subclass,none,
7424-
"superclass %0 requires reflection metadata attribute @%1",
7425-
(DeclName, StringRef))
7426-
NOTE(add_missing_reflection_metadata_attr,none,
7427-
"add missing reflection metadata attribute @%0", (StringRef))
7428-
NOTE(opt_out_from_missing_reflection_metadata_attr,none,
7429-
"opt-out of reflection metadata attribute @%0 using"
7430-
" unavailable extension",
7431-
(StringRef))
7432-
74337380
//------------------------------------------------------------------------------
74347381
// MARK: Init accessors
74357382
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)