Skip to content

Commit b855062

Browse files
authored
Merge pull request #4334 from swiftwasm/main
2 parents 33012c3 + aed6c62 commit b855062

File tree

72 files changed

+1367
-673
lines changed

Some content is hidden

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

72 files changed

+1367
-673
lines changed

include/swift-c/StaticMirror/BinaryScan.h

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
/// SWIFTSTATICMIRROR_VERSION_MINOR should increase when there are API additions.
2626
/// SWIFTSTATICMIRROR_VERSION_MAJOR is intended for "major" source/ABI breaking changes.
2727
#define SWIFTSTATICMIRROR_VERSION_MAJOR 0
28-
#define SWIFTSTATICMIRROR_VERSION_MINOR 1
28+
#define SWIFTSTATICMIRROR_VERSION_MINOR 2 // Added associated-type gather
2929

3030
SWIFTSTATICMIRROR_BEGIN_DECLS
3131

@@ -42,11 +42,33 @@ typedef void *swift_static_mirror_t;
4242
typedef struct swift_static_mirror_conformance_info_s
4343
*swift_static_mirror_conformance_info_t;
4444

45+
/// Opaque container to details of an associated type specification.
46+
typedef struct swift_static_mirror_type_alias_s
47+
*swift_static_mirror_type_alias_t;
48+
49+
/// Opaque container to an associated type (typealias) info of a given type.
50+
typedef struct swift_static_mirror_associated_type_info_s
51+
*swift_static_mirror_associated_type_info_t;
52+
53+
typedef struct {
54+
swift_static_mirror_type_alias_t *type_aliases;
55+
size_t count;
56+
} swift_static_mirror_type_alias_set_t;
57+
58+
59+
typedef struct {
60+
swift_static_mirror_associated_type_info_t *associated_type_infos;
61+
size_t count;
62+
} swift_static_mirror_associated_type_info_set_t;
63+
4564
typedef struct {
4665
swift_static_mirror_conformance_info_t *conformances;
4766
size_t count;
4867
} swift_static_mirror_conformances_set_t;
4968

69+
70+
// swift_static_mirror_conformance_info query methods
71+
5072
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
5173
swift_static_mirror_conformance_info_get_type_name(
5274
swift_static_mirror_conformance_info_t);
@@ -63,6 +85,25 @@ SWIFTSTATICMIRROR_PUBLIC void
6385
swift_static_mirror_conformance_info_dispose(
6486
swift_static_mirror_conformance_info_t);
6587

88+
// swift_static_mirror_associated_type query methods
89+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
90+
swift_static_mirror_type_alias_get_type_alias_name(
91+
swift_static_mirror_type_alias_t);
92+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
93+
swift_static_mirror_type_alias_get_substituted_type_name(
94+
swift_static_mirror_type_alias_t);
95+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
96+
swift_static_mirror_type_alias_get_substituted_type_mangled_name(
97+
swift_static_mirror_type_alias_t);
98+
99+
// swift_static_mirror_associated_type_info query methods
100+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_string_ref_t
101+
swift_static_mirror_associated_type_info_get_mangled_type_name(
102+
swift_static_mirror_associated_type_info_t);
103+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_type_alias_set_t*
104+
swift_static_mirror_associated_type_info_get_type_alias_set(
105+
swift_static_mirror_associated_type_info_t);
106+
66107
/// Create an \c swift_static_mirror_t instance.
67108
/// The returned \c swift_static_mirror_t is owned by the caller and must be
68109
/// disposed of using \c swift_static_mirror_dispose .
@@ -81,6 +122,19 @@ swift_static_mirror_conformances_set_create(
81122
SWIFTSTATICMIRROR_PUBLIC void swift_static_mirror_conformances_set_dispose(
82123
swift_static_mirror_conformances_set_t *);
83124

125+
/// Identify and collect all associated types of a given input type (by mangled name)
126+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_associated_type_info_set_t *
127+
swift_static_mirror_associated_type_info_set_create(
128+
swift_static_mirror_t, const char *);
129+
130+
/// Identify and collect associated types of all discovered types.
131+
SWIFTSTATICMIRROR_PUBLIC swift_static_mirror_associated_type_info_set_t *
132+
swift_static_mirror_all_associated_type_info_set_create(
133+
swift_static_mirror_t);
134+
135+
SWIFTSTATICMIRROR_PUBLIC void swift_static_mirror_associated_type_info_set_dispose(
136+
swift_static_mirror_associated_type_info_set_t *);
137+
84138
SWIFTSTATICMIRROR_END_DECLS
85139

86140
#endif // SWIFT_C_BINARY_SCAN_H

include/swift/AST/Attr.def

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,7 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
661661
APIBreakingToAdd | APIBreakingToRemove,
662662
118)
663663

664-
SIMPLE_DECL_ATTR(_primaryAssociatedType,
665-
PrimaryAssociatedType, OnAssociatedType | UserInaccessible |
666-
APIStableToAdd | ABIStableToAdd | APIBreakingToRemove | ABIStableToRemove,
667-
119)
664+
// 119 is unused
668665

669666
SIMPLE_DECL_ATTR(_assemblyVision, EmitAssemblyVisionRemarks,
670667
OnFunc | UserInaccessible | NotSerialized | OnNominalType |

include/swift/AST/ClangModuleLoader.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ class Type;
3131

3232
namespace swift {
3333

34+
class ConcreteDeclRef;
3435
class Decl;
3536
class DeclContext;
3637
class EffectiveClangContext;
3738
class SwiftLookupTable;
39+
class ValueDecl;
3840
class VisibleDeclConsumer;
3941

4042
/// Represents the different namespaces for types in C.
@@ -201,6 +203,10 @@ class ClangModuleLoader : public ModuleLoader {
201203
instantiateCXXClassTemplate(clang::ClassTemplateDecl *decl,
202204
ArrayRef<clang::TemplateArgument> arguments) = 0;
203205

206+
virtual ConcreteDeclRef
207+
getCXXFunctionTemplateSpecialization(SubstitutionMap subst,
208+
ValueDecl *decl) = 0;
209+
204210
/// Try to parse the string as a Clang function type.
205211
///
206212
/// Returns null if there was a parsing failure.

include/swift/AST/Decl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,11 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
505505
IsOpaqueType : 1
506506
);
507507

508+
SWIFT_INLINE_BITFIELD_FULL(AssociatedTypeDecl, AbstractTypeParamDecl, 1,
509+
/// Whether this is a primary associated type.
510+
IsPrimary : 1
511+
);
512+
508513
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);
509514

510515
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
@@ -3206,6 +3211,14 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
32063211
LazyMemberLoader *definitionResolver,
32073212
uint64_t resolverData);
32083213

3214+
bool isPrimary() const {
3215+
return Bits.AssociatedTypeDecl.IsPrimary;
3216+
}
3217+
3218+
void setPrimary() {
3219+
Bits.AssociatedTypeDecl.IsPrimary = true;
3220+
}
3221+
32093222
/// Get the protocol in which this associated type is declared.
32103223
ProtocolDecl *getProtocol() const {
32113224
return cast<ProtocolDecl>(getDeclContext());

include/swift/AST/DiagnosticsParse.def

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,8 +1797,14 @@ ERROR(redundant_class_requirement,none,
17971797
ERROR(late_class_requirement,none,
17981798
"'class' must come first in the requirement list", ())
17991799
ERROR(where_inside_brackets,none,
1800-
"'where' clause next to generic parameters is obsolete, "
1801-
"must be written following the declaration's type", ())
1800+
"'where' clause next to generic parameters is obsolete, "
1801+
"must be written following the declaration's type", ())
1802+
1803+
1804+
ERROR(expected_rangle_primary_associated_type_list,PointsToFirstBadToken,
1805+
"expected '>' to complete primary associated type list", ())
1806+
ERROR(expected_primary_associated_type_name,PointsToFirstBadToken,
1807+
"expected an identifier to name primary associated type", ())
18021808

18031809
//------------------------------------------------------------------------------
18041810
// MARK: Conditional compilation parsing diagnostics

include/swift/AST/PrintOptions.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,12 @@ struct PrintOptions {
511511
QualifyNestedDeclarations ShouldQualifyNestedDeclarations =
512512
QualifyNestedDeclarations::Never;
513513

514+
/// If true, we print a protocol's primary associated types using the
515+
/// primary associated type syntax: protocol Foo<Type1, ...>.
516+
///
517+
/// If false, we print them as ordinary associated types.
518+
bool PrintPrimaryAssociatedTypes = true;
519+
514520
/// If this is not \c nullptr then function bodies (including accessors
515521
/// and constructors) will be printed by this function.
516522
std::function<void(const ValueDecl *, ASTPrinter &)> FunctionBody;

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,6 @@ LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
7474
SUPPRESSIBLE_LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
7575
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
7676
SUPPRESSIBLE_LANGUAGE_FEATURE(UnsafeInheritExecutor, 0, "@_unsafeInheritExecutor", true)
77-
77+
SUPPRESSIBLE_LANGUAGE_FEATURE(PrimaryAssociatedTypes, 0, "Primary associated types", true)
7878
#undef SUPPRESSIBLE_LANGUAGE_FEATURE
7979
#undef LANGUAGE_FEATURE

include/swift/ClangImporter/ClangImporter.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,20 @@ class CompilerInvocation;
6161
class ClangImporterOptions;
6262
class ClangModuleUnit;
6363
class ClangNode;
64+
class ConcreteDeclRef;
6465
class Decl;
6566
class DeclContext;
6667
class EffectiveClangContext;
6768
class EnumDecl;
69+
class FuncDecl;
6870
class ImportDecl;
6971
class IRGenOptions;
7072
class ModuleDecl;
7173
class NominalTypeDecl;
7274
class StructDecl;
7375
class SwiftLookupTable;
7476
class TypeDecl;
77+
class ValueDecl;
7578
class VisibleDeclConsumer;
7679
enum class SelectorSplitKind;
7780

@@ -261,6 +264,9 @@ class ClangImporter final : public ClangModuleLoader {
261264
instantiateCXXClassTemplate(clang::ClassTemplateDecl *decl,
262265
ArrayRef<clang::TemplateArgument> arguments) override;
263266

267+
ConcreteDeclRef getCXXFunctionTemplateSpecialization(
268+
SubstitutionMap subst, ValueDecl *decl) override;
269+
264270
/// Just like Decl::getClangNode() except we look through to the 'Code'
265271
/// enum of an error wrapper struct.
266272
ClangNode getEffectiveClangNode(const Decl *decl) const;

include/swift/Parse/Parser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,6 +1199,9 @@ class Parser {
11991199
void parseAbstractFunctionBody(AbstractFunctionDecl *AFD);
12001200
BodyAndFingerprint
12011201
parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD);
1202+
1203+
ParserStatus parsePrimaryAssociatedTypes(
1204+
SmallVectorImpl<AssociatedTypeDecl *> &AssocTypes);
12021205
ParserResult<ProtocolDecl> parseDeclProtocol(ParseDeclOptions Flags,
12031206
DeclAttributes &Attributes);
12041207

include/swift/Reflection/TypeRefBuilder.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,26 @@ struct ConformanceCollectionResult {
297297
std::vector<std::string> Errors;
298298
};
299299

300+
struct AssociatedType {
301+
std::string TypeAliasName;
302+
std::string SubstitutedTypeMangledName;
303+
std::string SubstitutedTypeFullyQualifiedName;
304+
std::string SubstitutedTypeDiagnosticPrintName;
305+
};
306+
307+
/// Info about a given type's associated type, as read out from an Image
308+
struct AssociatedTypeInfo {
309+
std::string MangledTypeName;
310+
std::string FullyQualifiedName;
311+
std::string ProtocolFullyQualifiedName;
312+
std::vector<AssociatedType> AssociatedTypes;
313+
};
314+
315+
struct AssociatedTypeCollectionResult {
316+
std::vector<AssociatedTypeInfo> AssociatedTypeInfos;
317+
std::vector<std::string> Errors;
318+
};
319+
300320
/// An implementation of MetadataReader's BuilderType concept for
301321
/// building TypeRefs, and parsing field metadata from any images
302322
/// it has been made aware of.
@@ -880,6 +900,7 @@ class TypeRefBuilder {
880900
void dumpTypeRef(RemoteRef<char> MangledName, std::ostream &stream,
881901
bool printTypeName = false);
882902
void dumpFieldSection(std::ostream &stream);
903+
AssociatedTypeCollectionResult collectAssociatedTypes(llvm::Optional<std::string> forMangledTypeName);
883904
void dumpAssociatedTypeSection(std::ostream &stream);
884905
void dumpBuiltinTypeSection(std::ostream &stream);
885906
void dumpCaptureSection(std::ostream &stream);

0 commit comments

Comments
 (0)