Skip to content

Commit 3c5ea2e

Browse files
authored
Merge branch 'main' into es-pkg-err
2 parents ecc2042 + 77527c9 commit 3c5ea2e

File tree

249 files changed

+4764
-1079
lines changed

Some content is hidden

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

249 files changed

+4764
-1079
lines changed

SwiftCompilerSources/Sources/_RegexParser/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
file(GLOB_RECURSE _LIBSWIFT_REGEX_PARSER_SOURCES
10-
"${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}/Sources/_RegexParser/*.swift")
10+
"${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}/Sources/_RegexParser/*.swift")
1111
set(LIBSWIFT_REGEX_PARSER_SOURCES)
1212
foreach(source ${_LIBSWIFT_REGEX_PARSER_SOURCES})
1313
file(TO_CMAKE_PATH "${source}" source)
1414
list(APPEND LIBSWIFT_REGEX_PARSER_SOURCES ${source})
1515
endforeach()
16-
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${EXPERIMENTAL_STRING_PROCESSING_SOURCE_DIR}).")
16+
message(STATUS "Using Experimental String Processing library for libswift _RegexParser (${SWIFT_PATH_TO_STRING_PROCESSING_SOURCE}).")
1717

1818
add_swift_compiler_module(_CompilerRegexParser
1919
SOURCES

docs/ABI/Mangling.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ Globals
149149
#endif
150150
global ::= protocol-conformance 'Hc' // protocol conformance runtime record
151151
global ::= global 'HF' // accessible function runtime record
152+
global ::= global 'Ha' // runtime discoverable attribute record
152153

153154
global ::= nominal-type 'Mo' // class metadata immediate member base offset
154155

@@ -346,6 +347,7 @@ Entities
346347
entity-spec ::= type 'fU' INDEX // explicit anonymous closure expression
347348
entity-spec ::= type 'fu' INDEX // implicit anonymous closure
348349
entity-spec ::= 'fA' INDEX // default argument N+1 generator
350+
entity-spec ::= 'fa' // runtime discoverable attribute generator
349351
entity-spec ::= 'fi' // non-local variable initializer
350352
entity-spec ::= 'fP' // property wrapper backing initializer
351353
entity-spec ::= 'fW' // property wrapper init from projected value
@@ -653,6 +655,7 @@ Types
653655
type ::= assoc-type-name 'Qz' // shortcut for 'Qyz'
654656
type ::= assoc-type-list 'QY' GENERIC-PARAM-INDEX // associated type at depth
655657
type ::= assoc-type-list 'QZ' // shortcut for 'QYz'
658+
type ::= opaque-type-decl-name bound-generic-args 'Qo' INDEX // opaque type
656659
657660
type ::= pattern-type count-type 'Qp' // pack expansion type
658661
type ::= pack-element-list 'QP' // pack type

include/swift/ABI/Metadata.h

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,9 @@ struct TargetClassMetadataBounds : TargetMetadataBounds<Runtime> {
648648
/// Return the basic bounds of all Swift class metadata.
649649
/// The immediate members offset will not be meaningful.
650650
static constexpr TargetClassMetadataBounds<Runtime> forSwiftRootClass() {
651-
using Metadata = FullMetadata<TargetClassMetadataType<Runtime>>;
652-
return forAddressPointAndSize(sizeof(typename Metadata::HeaderType),
653-
sizeof(Metadata));
651+
using MetadataTy = FullMetadata<TargetClassMetadataType<Runtime>>;
652+
return forAddressPointAndSize(sizeof(typename MetadataTy::HeaderType),
653+
sizeof(MetadataTy));
654654
}
655655

656656
/// Return the bounds of a Swift class metadata with the given address
@@ -4736,6 +4736,45 @@ struct TargetAccessibleFunctionRecord final {
47364736

47374737
using AccessibleFunctionRecord = TargetAccessibleFunctionRecord<InProcess>;
47384738

4739+
/// A single entry in an runtine discoverable attribute record
4740+
/// that relates a type attribute is attached to a generator function.
4741+
template <typename Runtime>
4742+
struct TargetRuntimeDiscoverableAttributeEntry {
4743+
ConstTargetMetadataPointer<Runtime, TargetMetadata> Type;
4744+
RelativeDirectPointer<TargetAccessibleFunctionRecord<Runtime>> Generator;
4745+
};
4746+
4747+
/// A record that relates a runtime discoverable attribute to all of the
4748+
/// types (i.e. a nominal type, method, property etc.) it's attached to.
4749+
template <typename Runtime>
4750+
class RuntimeDiscoverableAttributeRecord
4751+
: private swift::ABI::TrailingObjects<
4752+
RuntimeDiscoverableAttributeRecord<Runtime>,
4753+
TargetRuntimeDiscoverableAttributeEntry<Runtime>> {
4754+
using TrailingObjects = swift::ABI::TrailingObjects<
4755+
RuntimeDiscoverableAttributeRecord<Runtime>,
4756+
ConstTargetMetadataPointer<Runtime, TargetMetadata>>;
4757+
friend TrailingObjects;
4758+
4759+
uint32_t flags;
4760+
4761+
/// The nominal type that describes the attribute.
4762+
TargetSignedContextPointer<Runtime, TargetTypeContextDescriptor> Attribute;
4763+
4764+
/// The number of types this attribute is associated with.
4765+
uint32_t numEntries;
4766+
4767+
public:
4768+
uint32_t getFlags() { return flags; }
4769+
4770+
llvm::ArrayRef<TargetRuntimeDiscoverableAttributeEntry<Runtime>>
4771+
getEntries() const {
4772+
return {this->template getTrailingObjects<
4773+
TargetRuntimeDiscoverableAttributeEntry<Runtime>>(),
4774+
numEntries};
4775+
}
4776+
};
4777+
47394778
} // end namespace swift
47404779

47414780
#pragma clang diagnostic pop

include/swift/AST/ASTContext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace swift {
8787
class LazyContextData;
8888
class LazyIterableDeclContextData;
8989
class LazyMemberLoader;
90-
class ModuleDependencies;
90+
class ModuleDependencyInfo;
9191
class PatternBindingDecl;
9292
class PatternBindingInitializer;
9393
class SourceFile;
@@ -993,16 +993,16 @@ class ASTContext final {
993993
///
994994
/// \param isUnderlyingClangModule When true, only look for a Clang module
995995
/// with the given name, ignoring any Swift modules.
996-
Optional<ModuleDependencies> getModuleDependencies(
996+
Optional<ModuleDependencyInfo> getModuleDependencies(
997997
StringRef moduleName,
998998
bool isUnderlyingClangModule,
999999
ModuleDependenciesCache &cache,
10001000
InterfaceSubContextDelegate &delegate,
10011001
bool cacheOnly = false,
1002-
llvm::Optional<std::pair<std::string, swift::ModuleDependenciesKind>> dependencyOf = None);
1002+
llvm::Optional<std::pair<std::string, swift::ModuleDependencyKind>> dependencyOf = None);
10031003

10041004
/// Retrieve the module dependencies for the Swift module with the given name.
1005-
Optional<ModuleDependencies> getSwiftModuleDependencies(
1005+
Optional<ModuleDependencyInfo> getSwiftModuleDependencies(
10061006
StringRef moduleName,
10071007
ModuleDependenciesCache &cache,
10081008
InterfaceSubContextDelegate &delegate);

include/swift/AST/ASTMangler.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class ASTMangler : public Mangler {
158158
BackDeploymentThunk,
159159
BackDeploymentFallback,
160160
HasSymbolQuery,
161+
RuntimeDiscoverableAttributeRecord,
161162
};
162163

163164
/// lldb overrides the defaulted argument to 'true'.
@@ -360,6 +361,10 @@ class ASTMangler : public Mangler {
360361

361362
std::string mangleHasSymbolQuery(const ValueDecl *decl);
362363

364+
std::string
365+
mangleRuntimeAttributeGeneratorEntity(const ValueDecl *decl, CustomAttr *attr,
366+
SymbolKind SKind = SymbolKind::Default);
367+
363368
enum SpecialContext {
364369
ObjCContext,
365370
ClangImporterContext,
@@ -584,6 +589,9 @@ class ASTMangler : public Mangler {
584589

585590
void appendConstrainedExistential(Type base, GenericSignature sig,
586591
const ValueDecl *forDecl);
592+
593+
void appendRuntimeAttributeGeneratorEntity(const ValueDecl *decl,
594+
CustomAttr *attr);
587595
};
588596

589597
} // end namespace Mangle

include/swift/AST/Decl.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,22 @@ class ValueDecl : public Decl {
27942794
/// 'func foo(Int) -> () -> Self?'.
27952795
GenericParameterReferenceInfo findExistentialSelfReferences(
27962796
Type baseTy, bool treatNonResultCovariantSelfAsInvariant) const;
2797+
2798+
/// Retrieve runtime discoverable attributes (if any) associated
2799+
/// with this declaration.
2800+
ArrayRef<CustomAttr *> getRuntimeDiscoverableAttrs() const;
2801+
/// Retrieve a nominal type declaration backing given runtime discoverable
2802+
/// attribute.
2803+
///
2804+
/// FIXME: This should be a more general facility but its unclear where
2805+
/// to place it for maximum impact.
2806+
NominalTypeDecl *getRuntimeDiscoverableAttrTypeDecl(CustomAttr *attr) const;
2807+
2808+
/// Given a runtime discoverable attribute, return a generator
2809+
/// which could be used to instantiate it for this declaration
2810+
/// together with its result type.
2811+
std::pair<BraceStmt *, Type>
2812+
getRuntimeDiscoverableAttributeGenerator(CustomAttr *) const;
27972813
};
27982814

27992815
/// This is a common base class for declarations which declare a type.

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2014,9 +2014,9 @@ ERROR(macro_expansion_decl_expected_macro_identifier,none,
20142014
"expected a macro identifier for a pound literal declaration", ())
20152015

20162016
ERROR(parser_round_trip_error,none,
2017-
"source file did not round-trip through the Swift Swift parser", ())
2017+
"source file did not round-trip through the new Swift parser", ())
20182018
ERROR(parser_new_parser_errors,none,
2019-
"Swift Swift parser generated errors for code that C++ parser accepted",
2019+
"new Swift parser generated errors for code that C++ parser accepted",
20202020
())
20212021

20222022
#define UNDEFINE_DIAGNOSTIC_MACROS

include/swift/AST/DiagnosticsSema.def

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5164,6 +5164,9 @@ ERROR(multiple_ellipsis_in_tuple,none,
51645164
ERROR(expansion_not_same_shape,none,
51655165
"variadic expansion %0 requires that %1 and %2 have the same shape",
51665166
(Type, Type, Type))
5167+
ERROR(expansion_expr_not_same_shape,none,
5168+
"pack expansion requires that %0 and %1 have the same shape",
5169+
(Type, Type))
51675170

51685171
ERROR(enum_element_ellipsis,none,
51695172
"variadic enum cases are not supported", ())
@@ -6803,6 +6806,28 @@ ERROR(moveonly_cannot_conform_to_protocol_with_name, none,
68036806
ERROR(runtime_discoverable_attrs_are_experimental,none,
68046807
"runtime discoverable attributes are an experimental feature", ())
68056808

6809+
ERROR(invalid_decl_for_runtime_discoverable_attr,none,
6810+
"@%0 can only be applied to non-generic types, methods, "
6811+
"instance properties, and global functions", (StringRef))
6812+
6813+
ERROR(duplicate_runtime_discoverable_attr,none,
6814+
"duplicate runtime discoverable attribute", ())
6815+
6816+
ERROR(runtime_attribute_requires_init,none,
6817+
"runtime attribute type %0 does not contain a required initializer"
6818+
" - init(attachedTo:)",
6819+
(DeclName))
6820+
6821+
ERROR(runtime_attribute_type_failable_init,none,
6822+
"runtime attribute type initializer %0 cannot be failable", (DeclName))
6823+
6824+
ERROR(runtime_attribute_type_requirement_not_accessible,none,
6825+
"%select{private|fileprivate|internal|public|open}0 %1 %2 cannot have "
6826+
"more restrictive access than its enclosing runtime attribute type %3 "
6827+
"(which is %select{private|fileprivate|internal|public|open}4)",
6828+
(AccessLevel, DescriptiveDeclKind, DeclName, Type, AccessLevel))
6829+
6830+
68066831
#define UNDEFINE_DIAGNOSTIC_MACROS
68076832
#include "DefineDiagnosticMacros.h"
68086833

include/swift/AST/Expr.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3584,10 +3584,6 @@ class PackExpansionExpr final : public Expr,
35843584
: Expr(ExprKind::PackExpansion, implicit, type),
35853585
PatternExpr(patternExpr), DotsLoc(dotsLoc), Environment(environment) {
35863586
Bits.PackExpansionExpr.NumBindings = packElements.size();
3587-
3588-
assert(Bits.PackExpansionExpr.NumBindings > 0 &&
3589-
"PackExpansionExpr must have pack references");
3590-
35913587
std::uninitialized_copy(packElements.begin(), packElements.end(),
35923588
getTrailingObjects<PackElementExpr *>());
35933589
}
@@ -3623,9 +3619,7 @@ class PackExpansionExpr final : public Expr,
36233619
return {getTrailingObjects<PackElementExpr *>(), getNumBindings()};
36243620
}
36253621

3626-
void setBinding(unsigned i, PackElementExpr *e) {
3627-
getMutableBindings()[i] = e;
3628-
}
3622+
void getExpandedPacks(SmallVectorImpl<ASTNode> &packs);
36293623

36303624
GenericEnvironment *getGenericEnvironment() {
36313625
return Environment;
@@ -3791,11 +3785,11 @@ class AbstractClosureExpr : public DeclContext, public Expr {
37913785

37923786
public:
37933787
AbstractClosureExpr(ExprKind Kind, Type FnType, bool Implicit,
3794-
unsigned Discriminator, DeclContext *Parent)
3788+
DeclContext *Parent)
37953789
: DeclContext(DeclContextKind::AbstractClosureExpr, Parent),
37963790
Expr(Kind, Implicit, FnType),
37973791
parameterList(nullptr) {
3798-
Bits.AbstractClosureExpr.Discriminator = Discriminator;
3792+
Bits.AbstractClosureExpr.Discriminator = InvalidDiscriminator;
37993793
}
38003794

38013795
CaptureInfo getCaptureInfo() const { return Captures; }
@@ -3824,11 +3818,18 @@ class AbstractClosureExpr : public DeclContext, public Expr {
38243818
/// optimization and therefore make it into e.g. stack traces.
38253819
/// Having their symbol names be stable across minor code changes is
38263820
/// therefore pretty useful for debugging.)
3827-
unsigned getDiscriminator() const {
3821+
unsigned getDiscriminator() const;
3822+
3823+
/// Retrieve the raw discriminator, which may not have been computed yet.
3824+
///
3825+
/// Only use this for queries that are checking for (e.g.) reentrancy or
3826+
/// intentionally do not want to initiate verification.
3827+
unsigned getRawDiscriminator() const {
38283828
return Bits.AbstractClosureExpr.Discriminator;
38293829
}
3830+
38303831
void setDiscriminator(unsigned discriminator) {
3831-
assert(getDiscriminator() == InvalidDiscriminator);
3832+
assert(getRawDiscriminator() == InvalidDiscriminator);
38323833
assert(discriminator != InvalidDiscriminator);
38333834
Bits.AbstractClosureExpr.Discriminator = discriminator;
38343835
}
@@ -3987,9 +3988,9 @@ class ClosureExpr : public AbstractClosureExpr {
39873988
SourceRange bracketRange, VarDecl *capturedSelfDecl,
39883989
ParameterList *params, SourceLoc asyncLoc, SourceLoc throwsLoc,
39893990
SourceLoc arrowLoc, SourceLoc inLoc, TypeExpr *explicitResultType,
3990-
unsigned discriminator, DeclContext *parent)
3991+
DeclContext *parent)
39913992
: AbstractClosureExpr(ExprKind::Closure, Type(), /*Implicit=*/false,
3992-
discriminator, parent),
3993+
parent),
39933994
Attributes(attributes), BracketRange(bracketRange),
39943995
CapturedSelfDecl(capturedSelfDecl),
39953996
AsyncLoc(asyncLoc), ThrowsLoc(throwsLoc), ArrowLoc(arrowLoc),
@@ -4185,10 +4186,9 @@ class AutoClosureExpr : public AbstractClosureExpr {
41854186
AsyncLet = 3,
41864187
};
41874188

4188-
AutoClosureExpr(Expr *Body, Type ResultTy, unsigned Discriminator,
4189-
DeclContext *Parent)
4189+
AutoClosureExpr(Expr *Body, Type ResultTy, DeclContext *Parent)
41904190
: AbstractClosureExpr(ExprKind::AutoClosure, ResultTy, /*Implicit=*/true,
4191-
Discriminator, Parent) {
4191+
Parent) {
41924192
if (Body != nullptr)
41934193
setBody(Body);
41944194

include/swift/AST/Initializer.h

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ enum class InitializerKind : uint8_t {
3636

3737
/// A property wrapper initialization expression.
3838
PropertyWrapper,
39+
40+
/// A runtime discoverable attribute initialization expression.
41+
RuntimeAttribute,
3942
};
4043

4144
/// An Initializer is a kind of DeclContext used for expressions that
@@ -232,7 +235,36 @@ class PropertyWrapperInitializer : public Initializer {
232235
return I->getInitializerKind() == InitializerKind::PropertyWrapper;
233236
}
234237
};
235-
238+
239+
/// A runtime discoverable attribute initialization expression context.
240+
///
241+
/// The parent context is context of the file/module this generator is
242+
/// synthesized in.
243+
class RuntimeAttributeInitializer : public Initializer {
244+
CustomAttr *Attr;
245+
ValueDecl *AttachedTo;
246+
247+
public:
248+
explicit RuntimeAttributeInitializer(CustomAttr *attr, ValueDecl *attachedTo)
249+
: Initializer(InitializerKind::RuntimeAttribute,
250+
attachedTo->getDeclContext()->getModuleScopeContext()),
251+
Attr(attr), AttachedTo(attachedTo) {}
252+
253+
CustomAttr *getAttr() const { return Attr; }
254+
255+
ValueDecl *getAttachedToDecl() const { return AttachedTo; }
256+
257+
static bool classof(const DeclContext *DC) {
258+
if (auto init = dyn_cast<Initializer>(DC))
259+
return classof(init);
260+
return false;
261+
}
262+
263+
static bool classof(const Initializer *I) {
264+
return I->getInitializerKind() == InitializerKind::RuntimeAttribute;
265+
}
266+
};
267+
236268
} // end namespace swift
237269

238270
#endif

include/swift/AST/KnownIdentifiers.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,9 @@ IDENTIFIER(unsafe)
333333
// The singleton instance of TupleTypeDecl in the Builtin module
334334
IDENTIFIER(TheTupleType)
335335

336+
// Runtime attributes
337+
IDENTIFIER(attachedTo)
338+
336339
#undef IDENTIFIER
337340
#undef IDENTIFIER_
338341
#undef IDENTIFIER_WITH_NAME

include/swift/AST/Module.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@ class ModuleDecl
173173
/// The ABI name of the module, if it differs from the module name.
174174
mutable Identifier ModuleABIName;
175175

176+
/// The name of the package this module belongs to
177+
mutable Identifier PackageName;
176178
public:
177179
/// Produces the components of a given module's full name in reverse order.
178180
///
@@ -400,6 +402,14 @@ class ModuleDecl
400402
ModuleABIName = name;
401403
}
402404

405+
/// Get the package name of the module
406+
Identifier getPackageName() const { return PackageName; }
407+
408+
/// Set the name of the package this module belongs to
409+
void setPackageName(Identifier name) {
410+
PackageName = name;
411+
}
412+
403413
/// Retrieve the actual module name of an alias used for this module (if any).
404414
///
405415
/// For example, if '-module-alias Foo=Bar' is passed in when building the main module,

0 commit comments

Comments
 (0)