Skip to content

Commit 6586930

Browse files
Merge pull request #4420 from swiftwasm/katei/merge-main-2022-04-05
Merge main 2022-04-05
2 parents 23aa047 + ed7d40b commit 6586930

File tree

109 files changed

+1816
-1124
lines changed

Some content is hidden

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

109 files changed

+1816
-1124
lines changed

SwiftCompilerSources/Package.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@ let package = Package(
2828
.target(
2929
name: "_RegexParser",
3030
dependencies: [],
31-
swiftSettings: [SwiftSetting.unsafeFlags([
31+
swiftSettings: [
32+
.unsafeFlags([
3233
"-I", "../include/swift",
33-
"-cross-module-optimization"
34+
"-cross-module-optimization",
35+
]),
36+
// Workaround until `_RegexParser` is imported as implementation-only
37+
// by `_StringProcessing`.
38+
.unsafeFlags([
39+
"-Xfrontend",
40+
"-disable-implicit-string-processing-module-import"
3441
])]),
3542
.target(
3643
name: "Optimizer",

docs/RequirementMachine/RequirementMachine.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3053,7 +3053,7 @@ \chapter{The Requirement Machine}\label{requirementmachine}
30533053

30543054
\section{Generic Parameters}\label{genericparamsym}
30553055
\index{generic parameter symbol}
3056-
So far, I've only shown you how to build rewrite rules from requirements in the requirement signature of some protocol $\proto{P}$. When lowering a type parameter, the protocol $\genericparam{Self}$ type lowers to the protocol symbol $\protosym{P}$. Once such a rewrite system is built, queries can be performed against the protocol generic signature $\gensig{\genericparam{Self}}{\genericparam{Self}\colon\proto{P}}$. When lowering parameters and requirements in an arbitary generic signature, generic parameter types instead become generic parameter symbols.
3056+
So far, I've only shown you how to build rewrite rules from requirements in the requirement signature of some protocol $\proto{P}$. When lowering a type parameter, the protocol $\genericparam{Self}$ type lowers to the protocol symbol $\protosym{P}$. Once such a rewrite system is built, queries can be performed against the protocol generic signature $\gensig{\genericparam{Self}}{\genericparam{Self}\colon\proto{P}}$. When lowering parameters and requirements in an arbitrary generic signature, generic parameter types instead become generic parameter symbols.
30573057

30583058
Generic parameter symbols should only ever appear as the initial symbol in a term. While the rewrite system would have no trouble with terms where generic parameter symbols appear elsewhere in the abstract, they don't actually make sense semantically, since they do not correspond to valid Swift type parameter types.
30593059

include/swift/AST/Decl.h

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

509-
SWIFT_INLINE_BITFIELD_FULL(AssociatedTypeDecl, AbstractTypeParamDecl, 1,
510-
/// Whether this is a primary associated type.
511-
IsPrimary : 1
512-
);
513-
514509
SWIFT_INLINE_BITFIELD_EMPTY(GenericTypeDecl, TypeDecl);
515510

516511
SWIFT_INLINE_BITFIELD(TypeAliasDecl, GenericTypeDecl, 1+1,
@@ -3272,14 +3267,6 @@ class AssociatedTypeDecl : public AbstractTypeParamDecl {
32723267
LazyMemberLoader *definitionResolver,
32733268
uint64_t resolverData);
32743269

3275-
bool isPrimary() const {
3276-
return Bits.AssociatedTypeDecl.IsPrimary;
3277-
}
3278-
3279-
void setPrimary() {
3280-
Bits.AssociatedTypeDecl.IsPrimary = true;
3281-
}
3282-
32833270
/// Get the protocol in which this associated type is declared.
32843271
ProtocolDecl *getProtocol() const {
32853272
return cast<ProtocolDecl>(getDeclContext());
@@ -4358,11 +4345,14 @@ enum class KnownDerivableProtocolKind : uint8_t {
43584345
Decodable,
43594346
AdditiveArithmetic,
43604347
Differentiable,
4348+
Identifiable,
43614349
Actor,
43624350
DistributedActor,
43634351
DistributedActorSystem,
43644352
};
43654353

4354+
using PrimaryAssociatedTypeName = std::pair<Identifier, SourceLoc>;
4355+
43664356
/// ProtocolDecl - A declaration of a protocol, for example:
43674357
///
43684358
/// protocol Drawable {
@@ -4379,6 +4369,7 @@ enum class KnownDerivableProtocolKind : uint8_t {
43794369
class ProtocolDecl final : public NominalTypeDecl {
43804370
SourceLoc ProtocolLoc;
43814371

4372+
ArrayRef<PrimaryAssociatedTypeName> PrimaryAssociatedTypeNames;
43824373
ArrayRef<ProtocolDecl *> InheritedProtocols;
43834374
ArrayRef<AssociatedTypeDecl *> AssociatedTypes;
43844375

@@ -4460,7 +4451,9 @@ class ProtocolDecl final : public NominalTypeDecl {
44604451

44614452
public:
44624453
ProtocolDecl(DeclContext *DC, SourceLoc ProtocolLoc, SourceLoc NameLoc,
4463-
Identifier Name, ArrayRef<InheritedEntry> Inherited,
4454+
Identifier Name,
4455+
ArrayRef<PrimaryAssociatedTypeName> PrimaryAssociatedTypeNames,
4456+
ArrayRef<InheritedEntry> Inherited,
44644457
TrailingWhereClause *TrailingWhere);
44654458

44664459
using Decl::getASTContext;
@@ -4486,6 +4479,13 @@ class ProtocolDecl final : public NominalTypeDecl {
44864479
/// a protocol having nested types (ObjC protocols).
44874480
ArrayRef<AssociatedTypeDecl *> getAssociatedTypeMembers() const;
44884481

4482+
/// Returns the list of primary associated type names. These are the associated
4483+
/// types that is parametrized with same-type requirements in a
4484+
/// parametrized protocol type of the form SomeProtocol<Arg1, Arg2...>.
4485+
ArrayRef<PrimaryAssociatedTypeName> getPrimaryAssociatedTypeNames() const {
4486+
return PrimaryAssociatedTypeNames;
4487+
}
4488+
44894489
/// Returns the list of primary associated types. These are the associated
44904490
/// types that is parametrized with same-type requirements in a
44914491
/// parametrized protocol type of the form SomeProtocol<Arg1, Arg2...>.

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3770,14 +3770,19 @@ ERROR(not_a_generic_definition,none,
37703770
"cannot specialize a non-generic definition", ())
37713771
ERROR(not_a_generic_type,none,
37723772
"cannot specialize non-generic type %0", (Type))
3773+
ERROR(protocol_declares_unknown_primary_assoc_type,none,
3774+
"an associated type named %0 must be declared in the protocol %1 or a protocol it inherits",
3775+
(Identifier, Type))
3776+
ERROR(protocol_declares_duplicate_primary_assoc_type,none,
3777+
"duplicate primary associated type name %0", (Identifier))
37733778
ERROR(parameterized_protocol_not_supported,none,
3774-
"protocol type with generic arguments can only be used as a generic constraint", ())
3779+
"protocol type with type arguments can only be used as a generic constraint", ())
37753780
ERROR(protocol_does_not_have_primary_assoc_type,none,
37763781
"cannot specialize protocol type %0", (Type))
3777-
ERROR(parameterized_protocol_too_many_type_arguments,none,
3778-
"protocol type %0 can specialized with too many type parameters "
3779-
"(got %1, but expected at most %2)",
3780-
(Type, unsigned, unsigned))
3782+
ERROR(parameterized_protocol_type_argument_count_mismatch,none,
3783+
"protocol type %0 specialized with %select{too many|too few}3 type arguments "
3784+
"(got %1, but expected %2)",
3785+
(Type, unsigned, unsigned, unsigned))
37813786
ERROR(cannot_specialize_self,none,
37823787
"cannot specialize 'Self'", ())
37833788
NOTE(specialize_explicit_type_instead,none,
@@ -6128,9 +6133,6 @@ WARNING(result_builder_missing_limited_availability, none,
61286133
"result builder %0 does not implement 'buildLimitedAvailability'; "
61296134
"this code may crash on earlier versions of the OS",
61306135
(Type))
6131-
ERROR(result_builder_static_buildblock, none,
6132-
"result builder must provide at least one static 'buildBlock' "
6133-
"method", ())
61346136
ERROR(result_builder_static_buildblock_or_buildpartialblock, none,
61356137
"result builder must provide at least one static 'buildBlock' "
61366138
"method, or both 'buildPartialBlock(first:)' and "

include/swift/AST/EducationalNotes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ EDUCATIONAL_NOTES(type_cannot_conform, "protocol-type-non-conformance.md")
7373
EDUCATIONAL_NOTES(unlabeled_trailing_closure_deprecated,
7474
"trailing-closure-matching.md")
7575

76-
EDUCATIONAL_NOTES(result_builder_static_buildblock,
76+
EDUCATIONAL_NOTES(result_builder_static_buildblock_or_buildpartialblock,
7777
"result-builder-methods.md")
7878
EDUCATIONAL_NOTES(result_builder_missing_limited_availability,
7979
"result-builder-methods.md")

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060

6161
PROTOCOL(Actor)
6262
PROTOCOL(Sequence)
63+
PROTOCOL(Identifiable)
6364
PROTOCOL(IteratorProtocol)
6465
PROTOCOL(RawRepresentable)
6566
PROTOCOL(Equatable)

include/swift/Basic/LangOptions.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ namespace swift {
209209
/// Emit a remark after loading a module.
210210
bool EnableModuleLoadingRemarks = false;
211211

212+
/// Resolve main function as though it were called from an async context
213+
bool EnableAsyncMainResolution = false;
214+
212215
///
213216
/// Support for alternate usage modes
214217
///
@@ -346,9 +349,6 @@ namespace swift {
346349
/// Enable experimental 'move only' features.
347350
bool EnableExperimentalMoveOnly = false;
348351

349-
/// Enable experimental pairwise `buildBlock` for result builders.
350-
bool EnableExperimentalPairwiseBuildBlock = false;
351-
352352
/// Enable variadic generics.
353353
bool EnableExperimentalVariadicGenerics = false;
354354

@@ -360,6 +360,9 @@ namespace swift {
360360
bool DisableImplicitConcurrencyModuleImport =
361361
!SWIFT_IMPLICIT_CONCURRENCY_IMPORT;
362362

363+
/// Disable the implicit import of the _StringProcessing module.
364+
bool DisableImplicitStringProcessingModuleImport = false;
365+
363366
/// Should we check the target OSs of serialized modules to see that they're
364367
/// new enough?
365368
bool EnableTargetOSChecking = true;

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,10 @@ def disable_implicit_distributed_module_import : Flag<["-"],
422422
"disable-implicit-distributed-module-import">,
423423
HelpText<"Disable the implicit import of the Distributed module.">;
424424

425+
def disable_implicit_string_processing_module_import : Flag<["-"],
426+
"disable-implicit-string-processing-module-import">,
427+
HelpText<"Disable the implicit import of the _StringProcessing module.">;
428+
425429
def disable_arc_opts : Flag<["-"], "disable-arc-opts">,
426430
HelpText<"Don't run SIL ARC optimization passes.">;
427431
def disable_ossa_opts : Flag<["-"], "disable-ossa-opts">,

include/swift/Option/Options.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ def pch_output_dir: Separate<["-"], "pch-output-dir">,
270270
Flags<[FrontendOption, HelpHidden, ArgumentIsPath]>,
271271
HelpText<"Directory to persist automatically created precompiled bridging headers">;
272272

273+
def async_main: Flag<["-"], "async-main">,
274+
Flags<[FrontendOption]>,
275+
HelpText<"Resolve main function as if it were called from an asynchronous context">;
276+
273277
// FIXME: Unhide this once it doesn't depend on an output file map.
274278
def incremental : Flag<["-"], "incremental">,
275279
Flags<[NoInteractiveOption, HelpHidden, DoesNotAffectIncrementalBuild]>,

include/swift/Parse/Parser.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,9 +1213,9 @@ class Parser {
12131213
parseAbstractFunctionBodyDelayed(AbstractFunctionDecl *AFD);
12141214

12151215
ParserStatus parsePrimaryAssociatedTypes(
1216-
SmallVectorImpl<AssociatedTypeDecl *> &AssocTypes);
1216+
SmallVectorImpl<PrimaryAssociatedTypeName> &AssocTypeNames);
12171217
ParserStatus parsePrimaryAssociatedTypeList(
1218-
SmallVectorImpl<AssociatedTypeDecl *> &AssocTypes);
1218+
SmallVectorImpl<PrimaryAssociatedTypeName> &AssocTypeNames);
12191219
ParserResult<ProtocolDecl> parseDeclProtocol(ParseDeclOptions Flags,
12201220
DeclAttributes &Attributes);
12211221

0 commit comments

Comments
 (0)