Skip to content

Commit 979f882

Browse files
Merge pull request #4931 from swiftwasm/main
[pull] swiftwasm from main
2 parents ad6f530 + d015505 commit 979f882

File tree

78 files changed

+1370
-539
lines changed

Some content is hidden

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

78 files changed

+1370
-539
lines changed

include/swift/AST/Decl.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2822,7 +2822,7 @@ class GenericTypeDecl : public GenericContext, public TypeDecl {
28222822
/// (opaque archetype 1))`.
28232823
class OpaqueTypeDecl final :
28242824
public GenericTypeDecl,
2825-
private llvm::TrailingObjects<OpaqueTypeDecl, OpaqueReturnTypeRepr *> {
2825+
private llvm::TrailingObjects<OpaqueTypeDecl, TypeRepr *> {
28262826
friend TrailingObjects;
28272827

28282828
public:
@@ -2866,7 +2866,7 @@ class OpaqueTypeDecl final :
28662866
OpaqueTypeDecl(ValueDecl *NamingDecl, GenericParamList *GenericParams,
28672867
DeclContext *DC,
28682868
GenericSignature OpaqueInterfaceGenericSignature,
2869-
ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs);
2869+
ArrayRef<TypeRepr *> OpaqueReturnTypeReprs);
28702870

28712871
unsigned getNumOpaqueReturnTypeReprs() const {
28722872
return NamingDeclAndHasOpaqueReturnTypeRepr.getInt()
@@ -2883,7 +2883,7 @@ class OpaqueTypeDecl final :
28832883
ValueDecl *NamingDecl, GenericParamList *GenericParams,
28842884
DeclContext *DC,
28852885
GenericSignature OpaqueInterfaceGenericSignature,
2886-
ArrayRef<OpaqueReturnTypeRepr *> OpaqueReturnTypeReprs);
2886+
ArrayRef<TypeRepr *> OpaqueReturnTypeReprs);
28872887

28882888
ValueDecl *getNamingDecl() const {
28892889
return NamingDeclAndHasOpaqueReturnTypeRepr.getPointer();
@@ -2904,7 +2904,7 @@ class OpaqueTypeDecl final :
29042904
/// repr `repr`, as introduce implicitly by an occurrence of "some" in return
29052905
/// position e.g. `func f() -> some P`. Returns -1 if `repr` is not found.
29062906
Optional<unsigned> getAnonymousOpaqueParamOrdinal(
2907-
OpaqueReturnTypeRepr *repr) const;
2907+
TypeRepr *repr) const;
29082908

29092909
GenericSignature getOpaqueInterfaceGenericSignature() const {
29102910
return OpaqueInterfaceGenericSignature;
@@ -2928,9 +2928,9 @@ class OpaqueTypeDecl final :
29282928

29292929
/// Retrieve the buffer containing the opaque return type
29302930
/// representations that correspond to the opaque generic parameters.
2931-
ArrayRef<OpaqueReturnTypeRepr *> getOpaqueReturnTypeReprs() const {
2931+
ArrayRef<TypeRepr *> getOpaqueReturnTypeReprs() const {
29322932
return {
2933-
getTrailingObjects<OpaqueReturnTypeRepr *>(),
2933+
getTrailingObjects<TypeRepr *>(),
29342934
getNumOpaqueReturnTypeReprs()
29352935
};
29362936
}
@@ -3163,7 +3163,7 @@ class AbstractTypeParamDecl : public TypeDecl {
31633163
/// \endcode
31643164
class GenericTypeParamDecl final :
31653165
public AbstractTypeParamDecl,
3166-
private llvm::TrailingObjects<GenericTypeParamDecl, OpaqueReturnTypeRepr *>{
3166+
private llvm::TrailingObjects<GenericTypeParamDecl, TypeRepr *>{
31673167
friend TrailingObjects;
31683168

31693169
size_t numTrailingObjects(OverloadToken<OpaqueReturnTypeRepr *>) const {
@@ -3180,7 +3180,7 @@ class GenericTypeParamDecl final :
31803180
/// \param nameLoc The location of the name.
31813181
GenericTypeParamDecl(DeclContext *dc, Identifier name, SourceLoc nameLoc,
31823182
bool isTypeSequence, unsigned depth, unsigned index,
3183-
bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
3183+
bool isOpaqueType, TypeRepr *typeRepr);
31843184

31853185
public:
31863186
/// Construct a new generic type parameter.
@@ -3201,7 +3201,7 @@ class GenericTypeParamDecl final :
32013201
static GenericTypeParamDecl *
32023202
create(DeclContext *dc, Identifier name, SourceLoc nameLoc,
32033203
bool isTypeSequence, unsigned depth, unsigned index,
3204-
bool isOpaqueType, OpaqueReturnTypeRepr *opaqueTypeRepr);
3204+
bool isOpaqueType, TypeRepr *typeRepr);
32053205

32063206
/// The depth of this generic type parameter, i.e., the number of outer
32073207
/// levels of generic parameter lists that enclose this type parameter.
@@ -3249,11 +3249,11 @@ class GenericTypeParamDecl final :
32493249
/// extension, meaning that it was specified explicitly
32503250
/// - the enclosing declaration was deserialized, in which case it lost
32513251
/// the source location information and has no type representation.
3252-
OpaqueReturnTypeRepr *getOpaqueTypeRepr() const {
3252+
TypeRepr *getOpaqueTypeRepr() const {
32533253
if (!isOpaqueType())
32543254
return nullptr;
32553255

3256-
return *getTrailingObjects<OpaqueReturnTypeRepr *>();
3256+
return *getTrailingObjects<TypeRepr *>();
32573257
}
32583258

32593259
/// The index of this generic type parameter within its generic parameter

include/swift/AST/DiagnosticsParse.def

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1513,7 +1513,10 @@ ERROR(attr_availability_multiple_kinds ,none,
15131513
WARNING(attr_availability_invalid_duplicate,none,
15141514
"'%0' argument has already been specified", (StringRef))
15151515
WARNING(attr_availability_unknown_platform,none,
1516-
"unknown platform '%0' for attribute '%1'", (StringRef, StringRef))
1516+
"unknown platform '%0' for attribute '%1'", (StringRef, StringRef))
1517+
WARNING(attr_availability_suggest_platform,none,
1518+
"unknown platform '%0' for attribute '%1'; did you mean '%2'?",
1519+
(StringRef, StringRef, StringRef))
15171520
ERROR(attr_availability_expected_platform,none,
15181521
"expected platform in '%0' attribute", (StringRef))
15191522
ERROR(attr_availability_invalid_renamed,none,
@@ -1897,6 +1900,10 @@ ERROR(avail_query_expected_rparen,PointsToFirstBadToken,
18971900

18981901
WARNING(avail_query_unrecognized_platform_name,
18991902
PointsToFirstBadToken, "unrecognized platform name %0", (Identifier))
1903+
WARNING(avail_query_suggest_platform_name,
1904+
PointsToFirstBadToken, "unrecognized platform name %0;"
1905+
" did you mean '%1'?",
1906+
(Identifier, StringRef))
19001907

19011908
ERROR(avail_query_disallowed_operator, PointsToFirstBadToken,
19021909
"'%0' cannot be used in an availability condition", (StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5696,14 +5696,22 @@ ERROR(availability_decl_more_than_enclosing, none,
56965696
"%0 cannot be more available than enclosing scope",
56975697
(DescriptiveDeclKind))
56985698

5699+
WARNING(availability_decl_more_than_unavailable_enclosing, none,
5700+
"%0 cannot be more available than unavailable enclosing scope",
5701+
(DescriptiveDeclKind))
5702+
56995703
NOTE(availability_implicit_decl_here, none,
57005704
"%0 implicitly declared here with availability of %1 %2 or newer",
57015705
(DescriptiveDeclKind, StringRef, llvm::VersionTuple))
57025706

5703-
NOTE(availability_decl_more_than_enclosing_enclosing_here, none,
5707+
NOTE(availability_decl_more_than_enclosing_here, none,
57045708
"enclosing scope requires availability of %0 %1 or newer",
57055709
(StringRef, llvm::VersionTuple))
57065710

5711+
NOTE(availability_decl_more_than_unavailable_enclosing_here, none,
5712+
"enclosing scope has been explicitly marked unavailable here",
5713+
())
5714+
57075715
ERROR(availability_decl_only_version_newer, none,
57085716
"%0 is only available in %1 %2 or newer",
57095717
(DeclName, StringRef, llvm::VersionTuple))

include/swift/AST/Expr.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4047,14 +4047,6 @@ class ClosureExpr : public AbstractClosureExpr {
40474047
/// func f(x : @autoclosure () -> Int)
40484048
/// f(42) // AutoclosureExpr convert from Int to ()->Int
40494049
/// \endcode
4050-
///
4051-
/// They are also created when key path expressions are converted to function
4052-
/// type, in which case, a pair of nested implicit closures are formed:
4053-
/// \code
4054-
/// { $kp$ in { $0[keyPath: $kp$] } }( \(E) )
4055-
/// \endcode
4056-
/// This is to ensure side effects of the key path expression (mainly indices in
4057-
/// subscripts) are only evaluated once.
40584050
class AutoClosureExpr : public AbstractClosureExpr {
40594051
BraceStmt *Body;
40604052

@@ -5397,6 +5389,10 @@ class KeyPathExpr : public Expr {
53975389
/// a contextual root type.
53985390
bool HasLeadingDot = false;
53995391

5392+
/// When we parse a key path literal, we claim a closure discriminator for it, since it may be used as
5393+
/// a closure value in function type context.
5394+
unsigned ClosureDiscriminator;
5395+
54005396
public:
54015397
/// A single stored component, which will be one of:
54025398
/// - an unresolved DeclNameRef, which has to be type-checked
@@ -5728,11 +5724,12 @@ class KeyPathExpr : public Expr {
57285724

57295725
KeyPathExpr(SourceLoc startLoc, Expr *parsedRoot, Expr *parsedPath,
57305726
SourceLoc endLoc, bool hasLeadingDot, bool isObjC,
5731-
bool isImplicit);
5727+
bool isImplicit, unsigned closureDiscriminator);
57325728

57335729
/// Create a key path with unresolved root and path expressions.
57345730
KeyPathExpr(SourceLoc backslashLoc, Expr *parsedRoot, Expr *parsedPath,
5735-
bool hasLeadingDot, bool isImplicit);
5731+
bool hasLeadingDot, bool isImplicit,
5732+
unsigned closureDiscriminator);
57365733

57375734
/// Create a key path with components.
57385735
KeyPathExpr(ASTContext &ctx, SourceLoc startLoc,
@@ -5742,8 +5739,9 @@ class KeyPathExpr : public Expr {
57425739
public:
57435740
/// Create a new parsed Swift key path expression.
57445741
static KeyPathExpr *createParsed(ASTContext &ctx, SourceLoc backslashLoc,
5745-
Expr *parsedRoot, Expr *parsedPath,
5746-
bool hasLeadingDot);
5742+
Expr *parsedRoot, Expr *parsedPath,
5743+
bool hasLeadingDot,
5744+
unsigned closureDiscriminator = AbstractClosureExpr::InvalidDiscriminator);
57475745

57485746
/// Create a new parsed #keyPath expression.
57495747
static KeyPathExpr *createParsedPoundKeyPath(ASTContext &ctx,
@@ -5838,6 +5836,9 @@ class KeyPathExpr : public Expr {
58385836
/// True if this key path expression has a leading dot.
58395837
bool expectsContextualRoot() const { return HasLeadingDot; }
58405838

5839+
/// Return the discriminator to use if this key path becomes a closure.
5840+
unsigned getClosureDiscriminator() const { return ClosureDiscriminator; }
5841+
58415842
static bool classof(const Expr *E) {
58425843
return E->getKind() == ExprKind::KeyPath;
58435844
}

include/swift/AST/NameLookup.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "swift/Basic/SourceLoc.h"
2828
#include "swift/Basic/SourceManager.h"
2929
#include "llvm/ADT/SmallVector.h"
30+
#include "swift/AST/TypeRepr.h"
3031

3132
namespace swift {
3233
class ASTContext;
@@ -36,12 +37,15 @@ class TypeDecl;
3637
class ValueDecl;
3738
struct SelfBounds;
3839
class NominalTypeDecl;
39-
4040
namespace ast_scope {
4141
class ASTSourceFileScope;
4242
class ASTScopeImpl;
4343
} // namespace ast_scope
4444

45+
/// Walk the type representation recursively, collecting any
46+
/// `OpaqueReturnTypeRepr`s, `CompositionTypeRepr`s or `IdentTypeRepr`s.
47+
CollectedOpaqueReprs collectOpaqueReturnTypeReprs(TypeRepr *, ASTContext &ctx, DeclContext *dc);
48+
4549
/// LookupResultEntry - One result of unqualified lookup.
4650
struct LookupResultEntry {
4751
private:
@@ -637,8 +641,8 @@ class FindLocalVal : public StmtVisitor<FindLocalVal> {
637641
void visitDoCatchStmt(DoCatchStmt *S);
638642

639643
};
640-
641-
644+
645+
642646
/// The bridge between the legacy UnqualifiedLookupFactory and the new ASTScope
643647
/// lookup system
644648
class AbstractASTScopeDeclConsumer {

include/swift/AST/PlatformKind.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ StringRef platformString(PlatformKind platform);
4141
/// or None if such a platform kind does not exist.
4242
Optional<PlatformKind> platformFromString(StringRef Name);
4343

44+
/// Returns a valid platform string if the candidate string would be a valid
45+
/// platform string if its case were adjusted (e.g. "macos" -> "macOS").
46+
Optional<StringRef> caseCorrectedPlatformString(StringRef candidate);
47+
4448
/// Returns a human-readable version of the platform name as a string, suitable
4549
/// for emission in diagnostics (e.g., "macOS").
4650
StringRef prettyPlatformString(PlatformKind platform);

include/swift/AST/TypeRepr.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "llvm/Support/TrailingObjects.h"
3434

3535
namespace swift {
36+
class ASTContext;
3637
class ASTWalker;
3738
class DeclContext;
3839
class IdentTypeRepr;
@@ -48,7 +49,7 @@ enum : unsigned { NumTypeReprKindBits =
4849
countBitsUsed(static_cast<unsigned>(TypeReprKind::Last_TypeRepr)) };
4950

5051
class OpaqueReturnTypeRepr;
51-
using CollectedOpaqueReprs = SmallVector<OpaqueReturnTypeRepr *, 2>;
52+
using CollectedOpaqueReprs = SmallVector<TypeRepr *, 2>;
5253

5354
/// Representation of a type as written in source.
5455
class alignas(1 << TypeReprAlignInBits) TypeRepr
@@ -118,6 +119,9 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
118119
return static_cast<TypeReprKind>(Bits.TypeRepr.Kind);
119120
}
120121

122+
/// Is this type representation a protocol?
123+
bool isProtocol(DeclContext *dc);
124+
121125
/// Is this type representation known to be invalid?
122126
bool isInvalid() const { return Bits.TypeRepr.Invalid; }
123127

@@ -165,10 +169,6 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
165169
/// opaque return type reprs.
166170
bool hasOpaque();
167171

168-
/// Walk the type representation recursively, collecting any
169-
/// `OpaqueReturnTypeRepr`s.
170-
CollectedOpaqueReprs collectOpaqueReturnTypeReprs();
171-
172172
/// Retrieve the type repr without any parentheses around it.
173173
///
174174
/// The use of this function must be restricted to contexts where
@@ -866,6 +866,12 @@ class CompositionTypeRepr final : public TypeRepr,
866866
SourceLoc getSourceLoc() const { return FirstTypeLoc; }
867867
SourceRange getCompositionRange() const { return CompositionRange; }
868868

869+
/// 'Any' is understood as CompositionTypeRepr by the compiler but its type array will be empty
870+
/// becasue it is a nonspecific type
871+
bool isTypeReprAny() {
872+
return getTypes().size() == 0 ? true : false;
873+
}
874+
869875
static CompositionTypeRepr *create(const ASTContext &C,
870876
ArrayRef<TypeRepr*> Protocols,
871877
SourceLoc FirstTypeLoc,

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ EXPERIMENTAL_FEATURE(ParserValidation)
138138
/// Swift Swift parser.
139139
EXPERIMENTAL_FEATURE(ParserSequenceFolding)
140140

141+
/// Enables implicit some while also enabling existential `any`
142+
EXPERIMENTAL_FEATURE(ImplicitSome)
143+
141144
#undef EXPERIMENTAL_FEATURE
142145
#undef UPCOMING_FEATURE
143146
#undef SUPPRESSIBLE_LANGUAGE_FEATURE

include/swift/Concurrency/Actor.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ enum : uint32_t {
5252
/// The actor is ready for deallocation once it stops running
5353
Zombie_ReadyForDeallocation = 0x3,
5454

55-
// Bit 3
56-
DistributedRemote = 0x8,
55+
// Bit 3 is free
56+
5757
// Bit 4
5858
IsPriorityEscalated = 0x10,
5959

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,10 @@ def enable_experimental_associated_type_inference :
579579
Flag<["-"], "enable-experimental-associated-type-inference">,
580580
HelpText<"Enable experimental associated type inference via type witness systems">;
581581

582+
def enable_experimental_implicit_some :
583+
Flag<["-"], "enable-experimental-implicit-some">,
584+
HelpText<"Enable experimental implicit some">;
585+
582586
def disable_availability_checking : Flag<["-"],
583587
"disable-availability-checking">,
584588
HelpText<"Disable checking for potentially unavailable APIs">;

include/swift/Reflection/ReflectionContext.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ class ReflectionContext
203203
StoredPointer FirstJob;
204204

205205
uint8_t State;
206-
bool IsDistributedRemote;
207206
bool IsPriorityEscalated;
207+
bool IsDistributedRemote;
208208
uint8_t MaxPriority;
209209

210210
bool HasThreadPort;
@@ -1737,13 +1737,12 @@ class ReflectionContext
17371737

17381738
uint32_t Flags = ActorObj->Status.Flags[0];
17391739
Info.State = Flags & concurrency::ActorFlagConstants::ActorStateMask;
1740-
Info.IsDistributedRemote =
1741-
Flags & concurrency::ActorFlagConstants::DistributedRemote;
17421740
Info.IsPriorityEscalated =
17431741
Flags & concurrency::ActorFlagConstants::IsPriorityEscalated;
17441742
Info.MaxPriority =
17451743
(Flags & concurrency::ActorFlagConstants::PriorityMask) >>
17461744
concurrency::ActorFlagConstants::PriorityShift;
1745+
Info.IsDistributedRemote = ActorObj->IsDistributedRemote;
17471746

17481747
// Don't read FirstJob when idle.
17491748
if (Info.State != concurrency::ActorFlagConstants::Idle) {

include/swift/Reflection/RuntimeInternals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ struct DefaultActorImpl {
176176
HeapObject<Runtime> HeapObject;
177177
Job<Runtime> JobStorage;
178178
ActiveActorStatus Status;
179+
bool IsDistributedRemote;
179180
};
180181

181182
template <typename Runtime>

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,10 @@ static bool usesFeatureExistentialAny(Decl *decl) {
30453045
return false;
30463046
}
30473047

3048+
static bool usesFeatureImplicitSome(Decl *decl) {
3049+
return false;
3050+
}
3051+
30483052
static bool usesFeatureForwardTrailingClosures(Decl *decl) {
30493053
return false;
30503054
}

lib/AST/ASTScopeLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,10 @@ NullablePtr<const GenericParamList> ASTScopeImpl::genericParams() const {
166166
}
167167
NullablePtr<const GenericParamList>
168168
AbstractFunctionDeclScope::genericParams() const {
169-
return decl->getGenericParams();
169+
return decl->getParsedGenericParams();
170170
}
171171
NullablePtr<const GenericParamList> SubscriptDeclScope::genericParams() const {
172-
return decl->getGenericParams();
172+
return decl->getParsedGenericParams();
173173
}
174174
NullablePtr<const GenericParamList> GenericTypeScope::genericParams() const {
175175
// For Decls:

0 commit comments

Comments
 (0)