Skip to content

Commit 270d3ec

Browse files
authored
Merge pull request #3975 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3b1ad80 + 2ab97ed commit 270d3ec

File tree

188 files changed

+3102
-1186
lines changed

Some content is hidden

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

188 files changed

+3102
-1186
lines changed

include/swift/ABI/Executor.h

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ template <class AsyncSignature>
149149
class AsyncFunctionPointer;
150150
template <class AsyncSignature>
151151
struct AsyncFunctionTypeImpl;
152+
template <class AsyncSignature>
153+
struct AsyncContinuationTypeImpl;
152154

153155
/// The abstract signature for an asynchronous function.
154156
template <class Sig, bool HasErrorResult>
@@ -163,6 +165,7 @@ struct AsyncSignature<DirectResultTy(ArgTys...), HasErrorResult> {
163165

164166
using FunctionPointer = AsyncFunctionPointer<AsyncSignature>;
165167
using FunctionType = typename AsyncFunctionTypeImpl<AsyncSignature>::type;
168+
using ContinuationType = typename AsyncContinuationTypeImpl<AsyncSignature>::type;
166169
};
167170

168171
/// A signature for a thin async function that takes no arguments
@@ -175,30 +178,58 @@ using ThinNullaryAsyncSignature =
175178
using ThickNullaryAsyncSignature =
176179
AsyncSignature<void(HeapObject*), false>;
177180

178-
/// A class which can be used to statically query whether a type
179-
/// is a specialization of AsyncSignature.
180-
template <class T>
181-
struct IsAsyncSignature {
182-
static const bool value = false;
183-
};
181+
template <class Signature>
182+
struct AsyncFunctionTypeImpl;
183+
184184
template <class DirectResultTy, class... ArgTys, bool HasErrorResult>
185-
struct IsAsyncSignature<AsyncSignature<DirectResultTy(ArgTys...),
186-
HasErrorResult>> {
187-
static const bool value = true;
185+
struct AsyncFunctionTypeImpl<
186+
AsyncSignature<DirectResultTy(ArgTys...), HasErrorResult>> {
187+
188+
using type = SWIFT_CC(swiftasync) void(SWIFT_ASYNC_CONTEXT AsyncContext *,
189+
ArgTys...);
188190
};
189191

190192
template <class Signature>
191-
struct AsyncFunctionTypeImpl {
192-
static_assert(IsAsyncSignature<Signature>::value,
193-
"template argument is not an AsyncSignature");
193+
struct AsyncContinuationTypeImpl;
194+
195+
template <class DirectResultTy, class... ArgTys>
196+
struct AsyncContinuationTypeImpl<
197+
AsyncSignature<DirectResultTy(ArgTys...), /*throws=*/true>> {
198+
199+
using type = SWIFT_CC(swiftasync) void(SWIFT_ASYNC_CONTEXT AsyncContext *,
200+
DirectResultTy,
201+
SWIFT_CONTEXT void *);
202+
};
194203

195-
// TODO: expand and include the arguments in the parameters.
196-
using type = TaskContinuationFunction;
204+
template <class DirectResultTy, class... ArgTys>
205+
struct AsyncContinuationTypeImpl<
206+
AsyncSignature<DirectResultTy(ArgTys...), /*throws=*/false>> {
207+
208+
using type = SWIFT_CC(swiftasync) void(SWIFT_ASYNC_CONTEXT AsyncContext *,
209+
DirectResultTy);
210+
};
211+
212+
template <class... ArgTys>
213+
struct AsyncContinuationTypeImpl<
214+
AsyncSignature<void(ArgTys...), /*throws=*/true>> {
215+
216+
using type = SWIFT_CC(swiftasync) void(SWIFT_ASYNC_CONTEXT AsyncContext *,
217+
SWIFT_CONTEXT void *);
218+
};
219+
220+
template <class... ArgTys>
221+
struct AsyncContinuationTypeImpl<
222+
AsyncSignature<void(ArgTys...), /*throws=*/false>> {
223+
224+
using type = SWIFT_CC(swiftasync) void(SWIFT_ASYNC_CONTEXT AsyncContext *);
197225
};
198226

199227
template <class Fn>
200228
using AsyncFunctionType = typename AsyncFunctionTypeImpl<Fn>::type;
201229

230+
template <class Fn>
231+
using AsyncContinuationType = typename AsyncContinuationTypeImpl<Fn>::type;
232+
202233
/// A "function pointer" for an async function.
203234
///
204235
/// Eventually, this will always be signed with the data key

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,9 @@ class ASTContext final {
620620
ConcreteDeclRef getBuiltinInitDecl(NominalTypeDecl *decl,
621621
KnownProtocolKind builtinProtocol,
622622
llvm::function_ref<DeclName (ASTContext &ctx)> initName) const;
623+
624+
/// Retrieve _StringProcessing.Regex.init(_regexString: String).
625+
ConcreteDeclRef getRegexInitDecl(Type regexType) const;
623626

624627
/// Retrieve the declaration of Swift.<(Int, Int) -> Bool.
625628
FuncDecl *getLessThanIntDecl() const;

include/swift/AST/CaptureInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ namespace swift {
3636
class ValueDecl;
3737
class FuncDecl;
3838
class OpaqueValueExpr;
39+
class VarDecl;
3940

4041
/// CapturedValue includes both the declaration being captured, along with flags
4142
/// that indicate how it is captured.
@@ -219,6 +220,11 @@ class CaptureInfo {
219220
return StorageAndFlags.getPointer()->getOpaqueValue();
220221
}
221222

223+
/// Retrieve the variable corresponding to an isolated parameter that has
224+
/// been captured, if there is one. This might be a capture variable
225+
/// that was initialized with an isolated parameter.
226+
VarDecl *getIsolatedParamCapture() const;
227+
222228
SWIFT_DEBUG_DUMP;
223229
void print(raw_ostream &OS) const;
224230
};

include/swift/AST/Decl.h

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
520520
IsComputingSemanticMembers : 1
521521
);
522522

523-
SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+1+1+8+16,
523+
SWIFT_INLINE_BITFIELD_FULL(ProtocolDecl, NominalTypeDecl, 1+1+1+1+1+1+1+1+1+1+1+8+16,
524524
/// Whether the \c RequiresClass bit is valid.
525525
RequiresClassValid : 1,
526526

@@ -533,6 +533,12 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
533533
/// Whether the existential of this protocol conforms to itself.
534534
ExistentialConformsToSelf : 1,
535535

536+
/// Whether the \c ExistentialRequiresAny bit is valid.
537+
ExistentialRequiresAnyValid : 1,
538+
539+
/// Whether the existential of this protocol must be spelled with \c any.
540+
ExistentialRequiresAny : 1,
541+
536542
/// True if the protocol has requirements that cannot be satisfied (e.g.
537543
/// because they could not be imported from Objective-C).
538544
HasMissingRequirements : 1,
@@ -4244,6 +4250,21 @@ class ProtocolDecl final : public NominalTypeDecl {
42444250
Bits.ProtocolDecl.ExistentialConformsToSelf = result;
42454251
}
42464252

4253+
/// Returns the cached result of \c existentialRequiresAny or \c None if it
4254+
/// hasn't yet been computed.
4255+
Optional<bool> getCachedExistentialRequiresAny() {
4256+
if (Bits.ProtocolDecl.ExistentialRequiresAnyValid)
4257+
return Bits.ProtocolDecl.ExistentialRequiresAny;
4258+
4259+
return None;
4260+
}
4261+
4262+
/// Caches the result of \c existentialRequiresAny
4263+
void setCachedExistentialRequiresAny(bool requiresAny) {
4264+
Bits.ProtocolDecl.ExistentialRequiresAnyValid = true;
4265+
Bits.ProtocolDecl.ExistentialRequiresAny = requiresAny;
4266+
}
4267+
42474268
bool hasLazyRequirementSignature() const {
42484269
return Bits.ProtocolDecl.HasLazyRequirementSignature;
42494270
}
@@ -4257,6 +4278,7 @@ class ProtocolDecl final : public NominalTypeDecl {
42574278
friend class RequirementSignatureRequestRQM;
42584279
friend class ProtocolRequiresClassRequest;
42594280
friend class ExistentialConformsToSelfRequest;
4281+
friend class ExistentialRequiresAnyRequest;
42604282
friend class InheritedProtocolsRequest;
42614283

42624284
public:
@@ -4345,6 +4367,11 @@ class ProtocolDecl final : public NominalTypeDecl {
43454367
/// contain 'Self' in 'parameter' or 'other' position.
43464368
bool isAvailableInExistential(const ValueDecl *decl) const;
43474369

4370+
/// Determine whether an existential type must be explicitly prefixed
4371+
/// with \c any. \c any is required if any of the members contain
4372+
/// an associated type, or if \c Self appears in non-covariant position.
4373+
bool existentialRequiresAny() const;
4374+
43484375
/// Returns a list of protocol requirements that must be assessed to
43494376
/// determine a concrete's conformance effect polymorphism kind.
43504377
PolymorphicEffectRequirementList getPolymorphicEffectRequirements(
@@ -5155,6 +5182,9 @@ class VarDecl : public AbstractStorageDecl {
51555182
Bits.VarDecl.IsSelfParamCapture = IsSelfParamCapture;
51565183
}
51575184

5185+
/// Check whether this capture of the self param is actor-isolated.
5186+
bool isSelfParamCaptureIsolated() const;
5187+
51585188
/// Determines if this var has an initializer expression that should be
51595189
/// exposed to clients.
51605190
///

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ ERROR(error_unknown_arg,none,
8080
"unknown argument: '%0'", (StringRef))
8181
ERROR(error_invalid_arg_value,none,
8282
"invalid value '%1' in '%0'", (StringRef, StringRef))
83+
ERROR(error_invalid_arg_combination,none,
84+
"unsupported argument combination: '%0' and '%1'", (StringRef, StringRef))
8385
WARNING(warning_invalid_locale_code,none,
8486
"unsupported locale code; supported locale codes are: '%0'", (StringRef))
8587
WARNING(warning_locale_path_not_found,none,
@@ -145,6 +147,8 @@ WARNING(emit_reference_dependencies_without_primary_file,none,
145147

146148
WARNING(warn_implicit_concurrency_import_failed,none,
147149
"unable to perform implicit import of \"_Concurrency\" module: no such module found", ())
150+
WARNING(warn_implicit_string_processing_import_failed,none,
151+
"unable to perform implicit import of \"_StringProcessing\" module: no such module found", ())
148152

149153
ERROR(error_module_name_required,none, "-module-name is required", ())
150154
ERROR(error_bad_module_name,none,

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,8 @@ ERROR(sil_function_subs_without_generics,none,
873873

874874
// Opaque types
875875
ERROR(opaque_mid_composition,none,
876-
"'some' should appear at the beginning of a composition", ())
876+
"'%0' should appear at the beginning of a composition",
877+
(StringRef))
877878

878879
//------------------------------------------------------------------------------
879880
// MARK: Layout constraint diagnostics

include/swift/AST/DiagnosticsSema.def

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,6 +2533,11 @@ WARNING(associated_type_override_typealias,none,
25332533
"associated type %0 is redundant with type %0 declared in inherited "
25342534
"%1 %2", (Identifier, DescriptiveDeclKind, Type))
25352535

2536+
ERROR(requirement_machine_completion_failed,none,
2537+
"cannot build rewrite system for %select{generic signature|protocol}0; "
2538+
"%select{step|depth}1 limit exceeded",
2539+
(unsigned, unsigned))
2540+
25362541
ERROR(associated_type_objc,none,
25372542
"associated type %0 cannot be declared inside '@objc' protocol %1",
25382543
(Identifier, Identifier))
@@ -3668,9 +3673,6 @@ ERROR(builtin_string_literal_broken_proto,none,
36683673
ERROR(string_literal_broken_proto,none,
36693674
"protocol 'ExpressibleByStringLiteral' is broken", ())
36703675

3671-
ERROR(regex_decl_broken,none,
3672-
"cannot find 'Regex' type in scope", ())
3673-
36743676
// Array literals
36753677
ERROR(should_use_dictionary_literal,none,
36763678
"dictionary of type %0 cannot be %select{used|initialized}1 "
@@ -4618,6 +4620,19 @@ ERROR(unchecked_not_inheritance_clause,none,
46184620
ERROR(unchecked_not_existential,none,
46194621
"'unchecked' attribute cannot apply to non-protocol type %0", (Type))
46204622

4623+
WARNING(unnecessary_any,none,
4624+
"'any' is redundant on type %0", (Type))
4625+
ERROR(any_not_existential,none,
4626+
"'any' has no effect on %select{concrete type|type parameter}0 %1",
4627+
(bool, Type))
4628+
ERROR(existential_requires_any,none,
4629+
"protocol %0 as a type must be explicitly marked as 'any'",
4630+
(Identifier))
4631+
ERROR(explicit_existential_not_supported,none,
4632+
"explicit 'any' not supported; use frontend flag "
4633+
"-enable-explicit-existential-types to enable this feature",
4634+
())
4635+
46214636
ERROR(nonisolated_let,none,
46224637
"'nonisolated' is meaningless on 'let' declarations because "
46234638
"they are immutable",
@@ -4722,6 +4737,14 @@ ERROR(async_unavailable_decl,none,
47224737
"%0 %1 is unavailable from asynchronous contexts%select{|; %3}2",
47234738
(DescriptiveDeclKind, DeclBaseName, bool, StringRef))
47244739

4740+
//------------------------------------------------------------------------------
4741+
// MARK: String Processing
4742+
//------------------------------------------------------------------------------
4743+
4744+
ERROR(string_processing_lib_missing,none,
4745+
"missing '%0' declaration, probably because the '_StringProcessing' "
4746+
"module was not imported properly", (StringRef))
4747+
47254748
//------------------------------------------------------------------------------
47264749
// MARK: Type Check Types
47274750
//------------------------------------------------------------------------------

include/swift/AST/Expr.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -966,26 +966,18 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
966966
class RegexLiteralExpr : public LiteralExpr {
967967
SourceLoc Loc;
968968
StringRef RegexText;
969-
Expr *SemanticExpr;
970969

971-
RegexLiteralExpr(SourceLoc loc, StringRef regexText, Expr *semanticExpr,
972-
bool isImplicit)
970+
RegexLiteralExpr(SourceLoc loc, StringRef regexText, bool isImplicit)
973971
: LiteralExpr(ExprKind::RegexLiteral, isImplicit), Loc(loc),
974-
RegexText(regexText), SemanticExpr(semanticExpr) {}
972+
RegexText(regexText) {}
975973

976974
public:
977975
static RegexLiteralExpr *createParsed(ASTContext &ctx, SourceLoc loc,
978-
StringRef regexText,
979-
Expr *semanticExpr);
976+
StringRef regexText);
980977

981978
/// Retrieve the raw regex text.
982979
StringRef getRegexText() const { return RegexText; }
983980

984-
/// Retrieve the semantic expression that the regex will be type-checked and
985-
/// emitted as.
986-
Expr *getSemanticExpr() const { return SemanticExpr; }
987-
void setSemanticExpr(Expr *expr) { SemanticExpr = expr; }
988-
989981
SourceRange getSourceRange() const { return Loc; }
990982

991983
static bool classof(const Expr *E) {

include/swift/AST/GenericSignature.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,12 @@ class GenericSignature {
217217

218218
/// Check invariants.
219219
void verify() const;
220+
221+
/// Check invariants for a list of requirements that are understood to
222+
/// be valid in the given signature; used to verify a protocol's
223+
/// requirement signature against the protocol generic signature
224+
/// <Self where Self : P>.
225+
void verify(ArrayRef<Requirement> reqts) const;
220226
};
221227

222228
/// A reference to a canonical generic signature.

include/swift/AST/KnownIdentifiers.def

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,10 @@ IDENTIFIER(pullback)
250250
IDENTIFIER(TangentVector)
251251
IDENTIFIER(zero)
252252

253-
// Regex literals
253+
// String processing
254254
IDENTIFIER(Regex)
255-
IDENTIFIER(_regexString)
255+
IDENTIFIER_(regexString)
256+
IDENTIFIER_(StringProcessing)
256257

257258
// Distributed actors
258259
IDENTIFIER(transport)

include/swift/AST/KnownSDKTypes.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ KNOWN_SDK_TYPE_DECL(Distributed, DistributedActor, ProtocolDecl, 0)
4848
KNOWN_SDK_TYPE_DECL(Distributed, ActorIdentity, ProtocolDecl, 0)
4949
KNOWN_SDK_TYPE_DECL(Distributed, AnyActorIdentity, StructDecl, 0)
5050

51+
// String processing
52+
KNOWN_SDK_TYPE_DECL(StringProcessing, Regex, StructDecl, 1)
53+
KNOWN_SDK_TYPE_DECL(StringProcessing, DynamicCaptures, EnumDecl, 0)
54+
5155
#undef KNOWN_SDK_TYPE_DECL

include/swift/AST/TypeCheckRequests.h

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,32 @@ class ExistentialConformsToSelfRequest :
287287
void cacheResult(bool value) const;
288288
};
289289

290+
/// Determine whether an existential type conforming to this protocol
291+
/// requires the \c any syntax.
292+
class ExistentialRequiresAnyRequest :
293+
public SimpleRequest<ExistentialRequiresAnyRequest,
294+
bool(ProtocolDecl *),
295+
RequestFlags::SeparatelyCached> {
296+
public:
297+
using SimpleRequest::SimpleRequest;
298+
299+
private:
300+
friend SimpleRequest;
301+
302+
// Evaluation.
303+
bool evaluate(Evaluator &evaluator, ProtocolDecl *decl) const;
304+
305+
public:
306+
// Cycle handling.
307+
void diagnoseCycle(DiagnosticEngine &diags) const;
308+
void noteCycleStep(DiagnosticEngine &diags) const;
309+
310+
// Separate caching.
311+
bool isCached() const { return true; }
312+
Optional<bool> getCachedResult() const;
313+
void cacheResult(bool value) const;
314+
};
315+
290316
class PolymorphicEffectRequirementsRequest :
291317
public SimpleRequest<PolymorphicEffectRequirementsRequest,
292318
PolymorphicEffectRequirementList(EffectKind, ProtocolDecl *),
@@ -3095,15 +3121,15 @@ class SynthesizeMainFunctionRequest
30953121
/// the Sendable protocol.
30963122
class GetImplicitSendableRequest :
30973123
public SimpleRequest<GetImplicitSendableRequest,
3098-
NormalProtocolConformance *(NominalTypeDecl *),
3124+
ProtocolConformance *(NominalTypeDecl *),
30993125
RequestFlags::Cached> {
31003126
public:
31013127
using SimpleRequest::SimpleRequest;
31023128

31033129
private:
31043130
friend SimpleRequest;
31053131

3106-
NormalProtocolConformance *evaluate(
3132+
ProtocolConformance *evaluate(
31073133
Evaluator &evaluator, NominalTypeDecl *nominal) const;
31083134

31093135
public:

0 commit comments

Comments
 (0)