Skip to content

Commit 3a089cc

Browse files
committed
Merge branch 'master' into slazarus/allow-access-through-existential-metatype
2 parents aaf7f23 + 2d7fedd commit 3a089cc

File tree

228 files changed

+281191
-265782
lines changed

Some content is hidden

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

228 files changed

+281191
-265782
lines changed

CMakeLists.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -477,12 +477,6 @@ if(NOT SWIFT_LIPO)
477477
find_toolchain_tool(SWIFT_LIPO "${SWIFT_DARWIN_XCRUN_TOOLCHAIN}" lipo)
478478
endif()
479479

480-
if("${SWIFT_NATIVE_LLVM_TOOLS_PATH}" STREQUAL "")
481-
set(SWIFT_CROSS_COMPILING FALSE)
482-
else()
483-
set(SWIFT_CROSS_COMPILING TRUE)
484-
endif()
485-
486480
# Reset CMAKE_SYSTEM_PROCESSOR if not cross-compiling.
487481
# CMake refuses to use `uname -m` on OS X
488482
# http://public.kitware.com/Bug/view.php?id=10326
@@ -578,6 +572,8 @@ else()
578572
set(SWIFT_HOST_VARIANT_SDK_default "WINDOWS")
579573
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
580574
set(SWIFT_HOST_VARIANT_SDK_default "HAIKU")
575+
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Android")
576+
set(SWIFT_HOST_VARIANT_SDK_default "ANDROID")
581577
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin")
582578
set(SWIFT_HOST_VARIANT_SDK_default "OSX")
583579
else()
@@ -702,6 +698,15 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "HAIKU")
702698
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
703699
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
704700

701+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
702+
703+
set(SWIFT_HOST_VARIANT "android" CACHE STRING
704+
"Deployment OS for Swift host tools (the compiler) [android].")
705+
706+
configure_sdk_unix("Android" "${SWIFT_HOST_VARIANT_ARCH}")
707+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
708+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
709+
705710
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*)")
706711

707712
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING
@@ -746,7 +751,10 @@ endif()
746751

747752
# Should we cross-compile the standard library for Android?
748753
is_sdk_requested(ANDROID swift_build_android)
749-
if(swift_build_android AND NOT "${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
754+
if(swift_build_android AND NOT "${SWIFT_HOST_VARIANT_SDK}" STREQUAL "ANDROID")
755+
if ("${SWIFT_ANDROID_NDK_PATH}" STREQUAL "")
756+
message(FATAL_ERROR "You must set SWIFT_ANDROID_NDK_PATH to cross-compile the Swift runtime for Android")
757+
endif()
750758
if (NOT ("${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_HOST_SYSTEM_NAME}" STREQUAL "Linux"))
751759
message(FATAL_ERROR "A Darwin or Linux host is required to build the Swift runtime for Android")
752760
endif()

cmake/modules/AddSwift.cmake

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,12 +467,14 @@ function(_add_variant_link_flags)
467467
endif()
468468

469469
if(NOT "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_UC}" STREQUAL "")
470-
get_filename_component(SWIFT_${sdk}_${arch}_ICU_UC_LIBDIR "${SWIFT_${sdk}_${arch}_ICU_UC}" DIRECTORY)
471-
list(APPEND library_search_directories "${SWIFT_${sdk}_${arch}_ICU_UC_LIBDIR}")
470+
get_filename_component(SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_UC_LIBDIR
471+
"${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_UC}" DIRECTORY)
472+
list(APPEND library_search_directories "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_UC_LIBDIR}")
472473
endif()
473474
if(NOT "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N}" STREQUAL "")
474-
get_filename_component(SWIFT_${sdk}_${arch}_ICU_I18N_LIBDIR "${SWIFT_${sdk}_${arch}_ICU_I18N}" DIRECTORY)
475-
list(APPEND library_search_directories "${SWIFT_${sdk}_${arch}_ICU_I18N_LIBDIR}")
475+
get_filename_component(SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N_LIBDIR
476+
"${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N}" DIRECTORY)
477+
list(APPEND library_search_directories "${SWIFT_${LFLAGS_SDK}_${LFLAGS_ARCH}_ICU_I18N_LIBDIR}")
476478
endif()
477479

478480
if(NOT SWIFT_COMPILER_IS_MSVC_LIKE)
@@ -1029,6 +1031,10 @@ function(_add_swift_library_single target name)
10291031
if(SWIFTLIB_SINGLE_SDK IN_LIST SWIFT_APPLE_PLATFORMS)
10301032
set(install_name_dir "@rpath")
10311033

1034+
if(SWIFTLIB_SINGLE_IS_STDLIB)
1035+
set(install_name_dir "${SWIFT_DARWIN_STDLIB_INSTALL_NAME_DIR}")
1036+
endif()
1037+
10321038
# Always use @rpath for XCTest
10331039
if(module_name STREQUAL "XCTest")
10341040
set(install_name_dir "@rpath")

include/swift/AST/ASTWalker.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ class ASTWalker {
211211
/// However, ASTWalker does not walk into LazyInitializerExprs on its own.
212212
virtual bool shouldWalkIntoLazyInitializers() { return true; }
213213

214+
/// This method configures whether the walker should visit the body of a
215+
/// non-single expression closure.
216+
///
217+
/// For work that is performed for every top-level expression, this should
218+
/// be overridden to return false, to avoid duplicating work or visiting
219+
/// bodies of closures that have not yet been type checked.
220+
virtual bool shouldWalkIntoNonSingleExpressionClosure() { return true; }
221+
214222
/// walkToParameterListPre - This method is called when first visiting a
215223
/// ParameterList, before walking into its parameters. If it returns false,
216224
/// the subtree is skipped.

include/swift/AST/Decl.h

Lines changed: 70 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include "swift/Basic/ArrayRefView.h"
3737
#include "swift/Basic/Compiler.h"
3838
#include "swift/Basic/InlineBitfield.h"
39+
#include "swift/Basic/NullablePtr.h"
3940
#include "swift/Basic/OptionalEnum.h"
4041
#include "swift/Basic/Range.h"
4142
#include "llvm/ADT/DenseMap.h"
@@ -334,7 +335,7 @@ class alignas(1 << DeclAlignInBits) Decl {
334335
IsUserAccessible : 1
335336
);
336337

337-
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1+1+1+1+2+1+1,
338+
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1+1+1+1+2+1+1+1,
338339
/// Whether the getter is mutating.
339340
IsGetterMutating : 1,
340341

@@ -353,14 +354,14 @@ class alignas(1 << DeclAlignInBits) Decl {
353354
/// Whether a keypath component can directly reference this storage,
354355
/// or if it must use the overridden declaration instead.
355356
HasComputedValidKeyPathComponent : 1,
356-
ValidKeyPathComponent : 1
357-
);
358-
359-
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1+1,
357+
ValidKeyPathComponent : 1,
358+
360359
/// Whether this property is a type property (currently unfortunately
361360
/// called 'static').
362-
IsStatic : 1,
361+
IsStatic : 1
362+
);
363363

364+
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 4+1+1+1+1,
364365
/// The specifier associated with this variable or parameter. This
365366
/// determines the storage semantics of the value e.g. mutability.
366367
Specifier : 4,
@@ -394,11 +395,10 @@ class alignas(1 << DeclAlignInBits) Decl {
394395
defaultArgumentKind : NumDefaultArgumentKindBits
395396
);
396397

397-
SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 1,
398-
/// The ResilienceExpansion to use for default arguments.
399-
DefaultArgumentResilienceExpansion : 1
398+
SWIFT_INLINE_BITFIELD(SubscriptDecl, VarDecl, 2,
399+
StaticSpelling : 2
400400
);
401-
401+
402402
SWIFT_INLINE_BITFIELD(AbstractFunctionDecl, ValueDecl, 3+8+1+1+1+1+1+1+1,
403403
/// \see AbstractFunctionDecl::BodyKind
404404
BodyKind : 3,
@@ -421,9 +421,6 @@ class alignas(1 << DeclAlignInBits) Decl {
421421
/// Whether NeedsNewVTableEntry is valid.
422422
HasComputedNeedsNewVTableEntry : 1,
423423

424-
/// The ResilienceExpansion to use for default arguments.
425-
DefaultArgumentResilienceExpansion : 1,
426-
427424
/// Whether this member was synthesized as part of a derived
428425
/// protocol conformance.
429426
Synthesized : 1
@@ -4283,15 +4280,17 @@ class AbstractStorageDecl : public ValueDecl {
42834280
}
42844281

42854282
protected:
4286-
AbstractStorageDecl(DeclKind Kind, DeclContext *DC, DeclName Name,
4287-
SourceLoc NameLoc, StorageIsMutable_t supportsMutation)
4283+
AbstractStorageDecl(DeclKind Kind, bool IsStatic, DeclContext *DC,
4284+
DeclName Name, SourceLoc NameLoc,
4285+
StorageIsMutable_t supportsMutation)
42884286
: ValueDecl(Kind, DC, Name, NameLoc) {
42894287
Bits.AbstractStorageDecl.HasStorage = true;
42904288
Bits.AbstractStorageDecl.SupportsMutation = supportsMutation;
42914289
Bits.AbstractStorageDecl.IsGetterMutating = false;
42924290
Bits.AbstractStorageDecl.IsSetterMutating = true;
42934291
Bits.AbstractStorageDecl.OpaqueReadOwnership =
42944292
unsigned(OpaqueReadOwnership::Owned);
4293+
Bits.AbstractStorageDecl.IsStatic = IsStatic;
42954294
}
42964295

42974296
void setSupportsMutationIfStillStored(StorageIsMutable_t supportsMutation) {
@@ -4312,9 +4311,16 @@ class AbstractStorageDecl : public ValueDecl {
43124311
/// attribute.
43134312
bool isTransparent() const;
43144313

4315-
/// Determine whether this storage is a static member, if it
4316-
/// is a member. Currently only variables can be static.
4317-
inline bool isStatic() const; // defined in this header
4314+
/// Is this a type ('static') variable?
4315+
bool isStatic() const {
4316+
return Bits.AbstractStorageDecl.IsStatic;
4317+
}
4318+
void setStatic(bool IsStatic) {
4319+
Bits.AbstractStorageDecl.IsStatic = IsStatic;
4320+
}
4321+
4322+
/// \returns the way 'static'/'class' should be spelled for this declaration.
4323+
StaticSpellingKind getCorrectStaticSpelling() const;
43184324

43194325
/// Return the interface type of the stored value.
43204326
Type getValueInterfaceType() const;
@@ -4612,10 +4618,9 @@ class VarDecl : public AbstractStorageDecl {
46124618

46134619
VarDecl(DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
46144620
SourceLoc NameLoc, Identifier Name, DeclContext *DC)
4615-
: AbstractStorageDecl(Kind, DC, Name, NameLoc,
4621+
: AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
46164622
StorageIsMutable_t(!isImmutableSpecifier(Sp)))
46174623
{
4618-
Bits.VarDecl.IsStatic = IsStatic;
46194624
Bits.VarDecl.Specifier = static_cast<unsigned>(Sp);
46204625
Bits.VarDecl.IsCaptureList = IsCaptureList;
46214626
Bits.VarDecl.IsDebuggerVar = false;
@@ -4743,8 +4748,32 @@ class VarDecl : public AbstractStorageDecl {
47434748
/// return this. Otherwise, this VarDecl must belong to a CaseStmt's
47444749
/// CaseLabelItem. In that case, return the first case label item of the first
47454750
/// case stmt in a sequence of case stmts that fallthrough into each other.
4751+
///
4752+
/// NOTE: During type checking, we emit an error if we have a single case
4753+
/// label item with a pattern that has multiple var decls of the same
4754+
/// name. This means that during type checking and before type checking, we
4755+
/// may have a _malformed_ switch stmt var decl linked list since var decls in
4756+
/// the same case label item that have the same name will point at the same
4757+
/// canonical var decl, namely the first var decl with the name in the
4758+
/// canonical case label item's var decl list. This is ok, since we are going
4759+
/// to emit the error, but it requires us to be more careful/cautious before
4760+
/// type checking has been complete when relying on canonical var decls
4761+
/// matching up.
47464762
VarDecl *getCanonicalVarDecl() const;
47474763

4764+
/// If this is a case stmt var decl, return the var decl that corresponds to
4765+
/// this var decl in the first case label item of the case stmt. Returns
4766+
/// nullptr if this isn't a VarDecl that is part of a case stmt.
4767+
NullablePtr<VarDecl> getCorrespondingFirstCaseLabelItemVarDecl() const;
4768+
4769+
/// If this is a case stmt var decl, return the case body var decl that this
4770+
/// var decl maps to.
4771+
NullablePtr<VarDecl> getCorrespondingCaseBodyVariable() const;
4772+
4773+
/// Return true if this var decl is an implicit var decl belonging to a case
4774+
/// stmt's body.
4775+
bool isCaseBodyVariable() const;
4776+
47484777
/// True if the global stored property requires lazy initialization.
47494778
bool isLazilyInitializedGlobal() const;
47504779

@@ -4794,14 +4823,6 @@ class VarDecl : public AbstractStorageDecl {
47944823
return getSpecifier() == Specifier::InOut;
47954824
}
47964825

4797-
4798-
/// Is this a type ('static') variable?
4799-
bool isStatic() const { return Bits.VarDecl.IsStatic; }
4800-
void setStatic(bool IsStatic) { Bits.VarDecl.IsStatic = IsStatic; }
4801-
4802-
/// \returns the way 'static'/'class' should be spelled for this declaration.
4803-
StaticSpellingKind getCorrectStaticSpelling() const;
4804-
48054826
bool isImmutable() const {
48064827
return isImmutableSpecifier(getSpecifier());
48074828
}
@@ -5110,24 +5131,40 @@ enum class ObjCSubscriptKind {
51105131
/// signatures (indices and element type) are distinct.
51115132
///
51125133
class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
5134+
SourceLoc StaticLoc;
51135135
SourceLoc ArrowLoc;
51145136
ParameterList *Indices;
51155137
TypeLoc ElementTy;
51165138

51175139
public:
5118-
SubscriptDecl(DeclName Name, SourceLoc SubscriptLoc, ParameterList *Indices,
5140+
SubscriptDecl(DeclName Name,
5141+
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5142+
SourceLoc SubscriptLoc, ParameterList *Indices,
51195143
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
51205144
GenericParamList *GenericParams)
51215145
: GenericContext(DeclContextKind::SubscriptDecl, Parent),
5122-
AbstractStorageDecl(DeclKind::Subscript, Parent, Name, SubscriptLoc,
5146+
AbstractStorageDecl(DeclKind::Subscript,
5147+
StaticSpelling != StaticSpellingKind::None,
5148+
Parent, Name, SubscriptLoc,
51235149
/*will be overwritten*/ StorageIsNotMutable),
5124-
ArrowLoc(ArrowLoc), Indices(nullptr), ElementTy(ElementTy) {
5150+
StaticLoc(StaticLoc), ArrowLoc(ArrowLoc),
5151+
Indices(nullptr), ElementTy(ElementTy) {
5152+
Bits.SubscriptDecl.StaticSpelling = static_cast<unsigned>(StaticSpelling);
51255153
setIndices(Indices);
51265154
setGenericParams(GenericParams);
51275155
}
51285156

5157+
/// \returns the way 'static'/'class' was spelled in the source.
5158+
StaticSpellingKind getStaticSpelling() const {
5159+
return static_cast<StaticSpellingKind>(Bits.SubscriptDecl.StaticSpelling);
5160+
}
5161+
5162+
SourceLoc getStaticLoc() const { return StaticLoc; }
51295163
SourceLoc getSubscriptLoc() const { return getNameLoc(); }
5130-
SourceLoc getStartLoc() const { return getSubscriptLoc(); }
5164+
5165+
SourceLoc getStartLoc() const {
5166+
return getStaticLoc().isValid() ? getStaticLoc() : getSubscriptLoc();
5167+
}
51315168
SourceRange getSourceRange() const;
51325169
SourceRange getSignatureSourceRange() const;
51335170

@@ -5287,8 +5324,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
52875324
Bits.AbstractFunctionDecl.Throws = Throws;
52885325
Bits.AbstractFunctionDecl.NeedsNewVTableEntry = false;
52895326
Bits.AbstractFunctionDecl.HasComputedNeedsNewVTableEntry = false;
5290-
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion =
5291-
unsigned(ResilienceExpansion::Maximal);
52925327
Bits.AbstractFunctionDecl.Synthesized = false;
52935328
}
52945329

@@ -5536,21 +5571,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
55365571
/// Resolved during type checking
55375572
void setIsOverridden() { Bits.AbstractFunctionDecl.Overridden = true; }
55385573

5539-
/// The ResilienceExpansion for default arguments.
5540-
///
5541-
/// In Swift 4 mode, default argument expressions are serialized, and must
5542-
/// obey the restrictions imposed upon inlinable function bodies.
5543-
ResilienceExpansion getDefaultArgumentResilienceExpansion() const {
5544-
return ResilienceExpansion(
5545-
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion);
5546-
}
5547-
5548-
/// Set the ResilienceExpansion for default arguments.
5549-
void setDefaultArgumentResilienceExpansion(ResilienceExpansion expansion) {
5550-
Bits.AbstractFunctionDecl.DefaultArgumentResilienceExpansion =
5551-
unsigned(expansion);
5552-
}
5553-
55545574
/// Set information about the foreign error convention used by this
55555575
/// declaration.
55565576
void setForeignErrorConvention(const ForeignErrorConvention &convention);
@@ -6005,10 +6025,7 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
60056025
Params(Params),
60066026
EqualsLoc(EqualsLoc),
60076027
RawValueExpr(RawValueExpr)
6008-
{
6009-
Bits.EnumElementDecl.DefaultArgumentResilienceExpansion =
6010-
static_cast<unsigned>(ResilienceExpansion::Maximal);
6011-
}
6028+
{}
60126029

60136030
Identifier getName() const { return getFullName().getBaseIdentifier(); }
60146031

@@ -6037,21 +6054,6 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
60376054
TypeCheckedRawValueExpr = e;
60386055
}
60396056

6040-
/// The ResilienceExpansion for default arguments.
6041-
///
6042-
/// In Swift 4 mode, default argument expressions are serialized, and must
6043-
/// obey the restrictions imposed upon inlinable function bodies.
6044-
ResilienceExpansion getDefaultArgumentResilienceExpansion() const {
6045-
return ResilienceExpansion(
6046-
Bits.EnumElementDecl.DefaultArgumentResilienceExpansion);
6047-
}
6048-
6049-
/// Set the ResilienceExpansion for default arguments.
6050-
void setDefaultArgumentResilienceExpansion(ResilienceExpansion expansion) {
6051-
Bits.EnumElementDecl.DefaultArgumentResilienceExpansion =
6052-
unsigned(expansion);
6053-
}
6054-
60556057
/// Return the containing EnumDecl.
60566058
EnumDecl *getParentEnum() const {
60576059
return cast<EnumDecl>(getDeclContext());
@@ -6825,15 +6827,6 @@ AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
68256827
mutableAddressor->overwriteAccess(accessLevel);
68266828
}
68276829

6828-
inline bool AbstractStorageDecl::isStatic() const {
6829-
if (auto var = dyn_cast<VarDecl>(this)) {
6830-
return var->isStatic();
6831-
}
6832-
6833-
// Currently, subscripts are never static.
6834-
return false;
6835-
}
6836-
68376830
/// Constructors and destructors always have a 'self' parameter,
68386831
/// which is stored in an instance member. Functions only have a
68396832
/// 'self' if they are declared inside of a nominal type or extension,

include/swift/AST/DiagnosticsModuleDiffer.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ ERROR(param_ownership_change,none,"%0 has %1 changing from %2 to %3", (StringRef
9292

9393
ERROR(type_witness_change,none,"%0 has type witness type for %1 changing from %2 to %3", (StringRef, StringRef, StringRef, StringRef))
9494

95+
ERROR(decl_new_witness_table_entry,none,"%0 now requires %select{|no}1 new witness table entry", (StringRef, bool))
96+
9597
#ifndef DIAG_NO_UNDEF
9698
# if defined(DIAG)
9799
# undef DIAG

0 commit comments

Comments
 (0)