Skip to content

Commit 9c80702

Browse files
committed
Merge branch 'master' of github.com:swiftwasm/swift into maxd/master-merge
2 parents 265111f + ca72891 commit 9c80702

File tree

400 files changed

+6124
-2090
lines changed

Some content is hidden

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

400 files changed

+6124
-2090
lines changed

include/swift/AST/ASTNode.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ namespace swift {
3030
class Stmt;
3131
class Decl;
3232
class Pattern;
33-
class TypeLoc;
33+
class TypeRepr;
3434
class DeclContext;
3535
class SourceLoc;
3636
class SourceRange;
@@ -41,7 +41,7 @@ namespace swift {
4141
enum class StmtKind;
4242

4343
struct ASTNode : public llvm::PointerUnion<Expr *, Stmt *, Decl *, Pattern *,
44-
TypeLoc *> {
44+
TypeRepr *> {
4545
// Inherit the constructors from PointerUnion.
4646
using PointerUnion::PointerUnion;
4747

include/swift/AST/AutoDiff.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,8 @@ IndexSubset *getLoweredParameterIndices(IndexSubset *astParameterIndices,
521521
///
522522
/// Returns the "constrained" derivative/transpose generic signature given:
523523
/// - An original SIL function type.
524-
/// - Differentiability parameter indices.
525-
/// - A possibly "unconstrained" derivative generic signature.
524+
/// - Differentiability/linearity parameter indices.
525+
/// - A possibly "unconstrained" derivative/transpose generic signature.
526526
GenericSignature getConstrainedDerivativeGenericSignature(
527527
SILFunctionType *originalFnTy, IndexSubset *diffParamIndices,
528528
GenericSignature derivativeGenSig, LookupConformanceFn lookupConformance,

include/swift/AST/Decl.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,7 @@ class ValueDecl : public Decl {
27152715
/// Is this declaration marked with 'dynamic'?
27162716
bool isDynamic() const;
27172717

2718+
private:
27182719
bool isObjCDynamic() const {
27192720
return isObjC() && isDynamic();
27202721
}
@@ -2723,6 +2724,37 @@ class ValueDecl : public Decl {
27232724
return !isObjC() && isDynamic();
27242725
}
27252726

2727+
bool isObjCDynamicInGenericClass() const;
2728+
2729+
public:
2730+
/// Should we use Objective-C method dispatch for this decl.
2731+
bool shouldUseObjCDispatch() const {
2732+
return isObjCDynamic();
2733+
}
2734+
2735+
/// Should we use native dynamic function replacement dispatch for this decl.
2736+
bool shouldUseNativeDynamicDispatch() const {
2737+
return isNativeDynamic();
2738+
}
2739+
2740+
/// Should we use Objective-C category based function replacement for this
2741+
/// decl.
2742+
/// This is all `@objc dynamic` methods except for such methods in native
2743+
/// generic classes. We can't use a category for generic classes so we use
2744+
/// native replacement instead (this behavior is only enabled with
2745+
/// -enable-implicit-dynamic).
2746+
bool shouldUseObjCMethodReplacement() const;
2747+
2748+
/// Should we use native dynamic function replacement mechanism for this decl.
2749+
/// This is all native dynamic methods except for `@objc dynamic` methods in
2750+
/// generic classes (see above).
2751+
bool shouldUseNativeMethodReplacement() const;
2752+
2753+
/// Is this a native dynamic function replacement based replacement.
2754+
/// This is all @_dynamicReplacement(for:) of native functions and @objc
2755+
/// dynamic methods on generic classes (see above).
2756+
bool isNativeMethodReplacement() const;
2757+
27262758
bool isEffectiveLinkageMoreVisibleThan(ValueDecl *other) const {
27272759
return (std::min(getEffectiveAccess(), AccessLevel::Public) >
27282760
std::min(other->getEffectiveAccess(), AccessLevel::Public));

include/swift/AST/DiagnosticsCommon.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,11 @@ NOTE(circular_type_resolution_note,none,
159159
// MARK: Cross-import overlay loading diagnostics
160160
//------------------------------------------------------------------------------
161161
ERROR(cannot_load_swiftoverlay_file, none,
162-
"cannot load cross-import overlay for %0 and %1: %2 (declared by '%3')",
163-
(Identifier, Identifier, StringRef, StringRef))
162+
"cannot load cross-import overlay for '%0' and '%1': %2 (declared by '%3')",
163+
(StringRef, StringRef, StringRef, StringRef))
164164
ERROR(cannot_list_swiftcrossimport_dir, none,
165-
"cannot list cross-import overlays for %0: %1 (declared in '%2')",
166-
(Identifier, StringRef, StringRef))
165+
"cannot list cross-import overlays for '%0': %1 (declared in '%2')",
166+
(StringRef, StringRef, StringRef))
167167
WARNING(cross_imported_by_both_modules, none,
168168
"modules %0 and %1 both declare module %2 as a cross-import overlay, "
169169
"which may cause paradoxical behavior when looking up names in them; "

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ ERROR(could_not_find_enum_case,none,
9494

9595
NOTE(did_you_mean_raw_type,none,
9696
"did you mean to specify a raw type on the enum declaration?", ())
97+
98+
NOTE(did_you_mean_generic_param_as_conformance,none,
99+
"did you mean to declare %0 as a protocol conformance for %1?", (DeclName, Type))
97100

98101
NOTE(any_as_anyobject_fixit, none,
99102
"cast 'Any' to 'AnyObject' or use 'as!' to force downcast to a more specific type to access members", ())
@@ -5075,8 +5078,8 @@ ERROR(function_builder_infer_ambig, none,
50755078
NOTE(function_builder_infer_add_return, none,
50765079
"add an explicit 'return' statement to not use a function builder", ())
50775080
NOTE(function_builder_infer_pick_specific, none,
5078-
"apply function builder %0 (inferred from protocol %1)",
5079-
(Type, DeclName))
5081+
"apply function builder %0 (inferred from %select{protocol|dynamic replacement of}1 %2)",
5082+
(Type, unsigned, DeclName))
50805083

50815084
//------------------------------------------------------------------------------
50825085
// MARK: Tuple Shuffle Diagnostics

include/swift/AST/EvaluatorDependencies.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,17 +237,19 @@ struct DependencyRecorder {
237237
friend DependencyCollector;
238238

239239
enum class Mode {
240-
// Enables the current "status quo" behavior of the dependency collector.
241-
//
242-
// By default, the dependency collector moves to register dependencies in
243-
// the referenced name trackers at the top of the active dependency stack.
244-
StatusQuo,
245-
// Enables an experimental mode to only register private dependencies.
240+
// Enables the status quo of recording direct dependencies.
246241
//
247242
// This mode restricts the dependency collector to ignore changes of
248243
// scope. This has practical effect of charging all unqualified lookups to
249244
// the primary file being acted upon instead of to the destination file.
250-
ExperimentalPrivateDependencies,
245+
DirectDependencies,
246+
// Enables a legacy mode of dependency tracking that makes a distinction
247+
// between private and cascading edges, and does not directly capture
248+
// transitive dependencies.
249+
//
250+
// By default, the dependency collector moves to register dependencies in
251+
// the referenced name trackers at the top of the active dependency stack.
252+
LegacyCascadingDependencies,
251253
};
252254

253255
private:
@@ -305,9 +307,9 @@ struct DependencyRecorder {
305307
if (dependencySources.empty())
306308
return nullptr;
307309
switch (mode) {
308-
case Mode::StatusQuo:
310+
case Mode::LegacyCascadingDependencies:
309311
return dependencySources.back().getPointer();
310-
case Mode::ExperimentalPrivateDependencies:
312+
case Mode::DirectDependencies:
311313
return dependencySources.front().getPointer();
312314
}
313315
}
@@ -347,9 +349,9 @@ struct DependencyRecorder {
347349
/// If there is no active scope, the result always cascades.
348350
bool isActiveSourceCascading() const {
349351
switch (mode) {
350-
case Mode::StatusQuo:
352+
case Mode::LegacyCascadingDependencies:
351353
return getActiveSourceScope() == evaluator::DependencyScope::Cascading;
352-
case Mode::ExperimentalPrivateDependencies:
354+
case Mode::DirectDependencies:
353355
return false;
354356
}
355357
llvm_unreachable("invalid mode");

include/swift/AST/Expr.h

Lines changed: 57 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
#include "swift/AST/ProtocolConformanceRef.h"
2626
#include "swift/AST/TrailingCallArguments.h"
2727
#include "swift/AST/TypeAlignments.h"
28-
#include "swift/AST/TypeLoc.h"
2928
#include "swift/AST/Availability.h"
3029
#include "swift/Basic/Debug.h"
3130
#include "swift/Basic/InlineBitfield.h"
@@ -555,7 +554,7 @@ class alignas(8) Expr {
555554
SWIFT_DEBUG_DUMP;
556555
void dump(raw_ostream &OS, unsigned Indent = 0) const;
557556
void dump(raw_ostream &OS, llvm::function_ref<Type(Expr *)> getType,
558-
llvm::function_ref<Type(TypeLoc &)> getTypeOfTypeLoc,
557+
llvm::function_ref<Type(TypeRepr *)> getTypeOfTypeRepr,
559558
llvm::function_ref<Type(KeyPathExpr *E, unsigned index)>
560559
getTypeOfKeyPathComponent,
561560
unsigned Indent = 0) const;
@@ -4587,23 +4586,22 @@ class DotSyntaxBaseIgnoredExpr : public Expr {
45874586
class ExplicitCastExpr : public Expr {
45884587
Expr *SubExpr;
45894588
SourceLoc AsLoc;
4590-
TypeLoc CastTy;
4589+
TypeExpr *const CastTy;
45914590

45924591
protected:
4593-
ExplicitCastExpr(ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeLoc castTy)
4594-
: Expr(kind, /*Implicit=*/false), SubExpr(sub), AsLoc(AsLoc), CastTy(castTy)
4595-
{}
4592+
ExplicitCastExpr(ExprKind kind, Expr *sub, SourceLoc AsLoc, TypeExpr *castTy)
4593+
: Expr(kind, /*Implicit=*/false), SubExpr(sub), AsLoc(AsLoc),
4594+
CastTy(castTy) {}
45964595

45974596
public:
45984597
Expr *getSubExpr() const { return SubExpr; }
4599-
4600-
/// Get the type syntactically spelled in the cast. For some forms of checked
4601-
/// cast this is different from the result type of the expression.
4602-
TypeLoc &getCastTypeLoc() { return CastTy; }
46034598

46044599
/// Get the type syntactically spelled in the cast. For some forms of checked
46054600
/// cast this is different from the result type of the expression.
4606-
TypeLoc getCastTypeLoc() const { return CastTy; }
4601+
Type getCastType() const { return CastTy->getInstanceType(); }
4602+
void setCastType(Type type);
4603+
4604+
TypeRepr *getCastTypeRepr() const { return CastTy->getTypeRepr(); }
46074605

46084606
void setSubExpr(Expr *E) { SubExpr = E; }
46094607

@@ -4619,7 +4617,7 @@ class ExplicitCastExpr : public Expr {
46194617
}
46204618

46214619
SourceRange getSourceRange() const {
4622-
SourceRange castTyRange = CastTy.getSourceRange();
4620+
const SourceRange castTyRange = CastTy->getSourceRange();
46234621
if (castTyRange.isInvalid())
46244622
return SubExpr->getSourceRange();
46254623

@@ -4644,14 +4642,13 @@ StringRef getCheckedCastKindName(CheckedCastKind kind);
46444642
/// Abstract base class for checked casts 'as' and 'is'. These represent
46454643
/// casts that can dynamically fail.
46464644
class CheckedCastExpr : public ExplicitCastExpr {
4647-
public:
4648-
CheckedCastExpr(ExprKind kind,
4649-
Expr *sub, SourceLoc asLoc, TypeLoc castTy)
4650-
: ExplicitCastExpr(kind, sub, asLoc, castTy)
4651-
{
4645+
protected:
4646+
CheckedCastExpr(ExprKind kind, Expr *sub, SourceLoc asLoc, TypeExpr *castTy)
4647+
: ExplicitCastExpr(kind, sub, asLoc, castTy) {
46524648
Bits.CheckedCastExpr.CastKind = unsigned(CheckedCastKind::Unresolved);
46534649
}
4654-
4650+
4651+
public:
46554652
/// Return the semantic kind of cast performed.
46564653
CheckedCastKind getCastKind() const {
46574654
return CheckedCastKind(Bits.CheckedCastExpr.CastKind);
@@ -4675,22 +4672,20 @@ class CheckedCastExpr : public ExplicitCastExpr {
46754672
/// from a value of some type to some specified subtype and fails dynamically
46764673
/// if the value does not have that type.
46774674
/// Spelled 'a as! T' and produces a value of type 'T'.
4678-
class ForcedCheckedCastExpr : public CheckedCastExpr {
4675+
class ForcedCheckedCastExpr final : public CheckedCastExpr {
46794676
SourceLoc ExclaimLoc;
46804677

4681-
public:
46824678
ForcedCheckedCastExpr(Expr *sub, SourceLoc asLoc, SourceLoc exclaimLoc,
4683-
TypeLoc type)
4684-
: CheckedCastExpr(ExprKind::ForcedCheckedCast,
4685-
sub, asLoc, type),
4686-
ExclaimLoc(exclaimLoc)
4687-
{
4688-
}
4679+
TypeExpr *type)
4680+
: CheckedCastExpr(ExprKind::ForcedCheckedCast, sub, asLoc, type),
4681+
ExclaimLoc(exclaimLoc) {}
46894682

4690-
ForcedCheckedCastExpr(SourceLoc asLoc, SourceLoc exclaimLoc, TypeLoc type)
4691-
: ForcedCheckedCastExpr(nullptr, asLoc, exclaimLoc, type)
4692-
{
4693-
}
4683+
public:
4684+
static ForcedCheckedCastExpr *create(ASTContext &ctx, SourceLoc asLoc,
4685+
SourceLoc exclaimLoc, TypeRepr *tyRepr);
4686+
4687+
static ForcedCheckedCastExpr *createImplicit(ASTContext &ctx, Expr *sub,
4688+
Type castTy);
46944689

46954690
/// Retrieve the location of the '!' that follows 'as'.
46964691
SourceLoc getExclaimLoc() const { return ExclaimLoc; }
@@ -4704,21 +4699,24 @@ class ForcedCheckedCastExpr : public CheckedCastExpr {
47044699
/// from a type to some subtype and produces an Optional value, which will be
47054700
/// .Some(x) if the cast succeeds, or .None if the cast fails.
47064701
/// Spelled 'a as? T' and produces a value of type 'T?'.
4707-
class ConditionalCheckedCastExpr : public CheckedCastExpr {
4702+
class ConditionalCheckedCastExpr final : public CheckedCastExpr {
47084703
SourceLoc QuestionLoc;
47094704

4710-
public:
47114705
ConditionalCheckedCastExpr(Expr *sub, SourceLoc asLoc, SourceLoc questionLoc,
4712-
TypeLoc type)
4713-
: CheckedCastExpr(ExprKind::ConditionalCheckedCast,
4714-
sub, asLoc, type),
4715-
QuestionLoc(questionLoc)
4716-
{ }
4717-
4718-
ConditionalCheckedCastExpr(SourceLoc asLoc, SourceLoc questionLoc,
4719-
TypeLoc type)
4720-
: ConditionalCheckedCastExpr(nullptr, asLoc, questionLoc, type)
4721-
{}
4706+
TypeExpr *type)
4707+
: CheckedCastExpr(ExprKind::ConditionalCheckedCast, sub, asLoc, type),
4708+
QuestionLoc(questionLoc) {}
4709+
4710+
public:
4711+
static ConditionalCheckedCastExpr *create(ASTContext &ctx, SourceLoc asLoc,
4712+
SourceLoc questionLoc,
4713+
TypeRepr *tyRepr);
4714+
4715+
static ConditionalCheckedCastExpr *createImplicit(ASTContext &ctx, Expr *sub,
4716+
Type castTy);
4717+
4718+
static ConditionalCheckedCastExpr *
4719+
createImplicit(ASTContext &ctx, Expr *sub, TypeRepr *tyRepr, Type castTy);
47224720

47234721
/// Retrieve the location of the '?' that follows 'as'.
47244722
SourceLoc getQuestionLoc() const { return QuestionLoc; }
@@ -4733,16 +4731,13 @@ class ConditionalCheckedCastExpr : public CheckedCastExpr {
47334731
/// of the type and 'a as T' would succeed, false otherwise.
47344732
///
47354733
/// FIXME: We should support type queries with a runtime metatype value too.
4736-
class IsExpr : public CheckedCastExpr {
4734+
class IsExpr final : public CheckedCastExpr {
4735+
IsExpr(Expr *sub, SourceLoc isLoc, TypeExpr *type)
4736+
: CheckedCastExpr(ExprKind::Is, sub, isLoc, type) {}
4737+
47374738
public:
4738-
IsExpr(Expr *sub, SourceLoc isLoc, TypeLoc type)
4739-
: CheckedCastExpr(ExprKind::Is, sub, isLoc, type)
4740-
{}
4741-
4742-
IsExpr(SourceLoc isLoc, TypeLoc type)
4743-
: IsExpr(nullptr, isLoc, type)
4744-
{}
4745-
4739+
static IsExpr *create(ASTContext &ctx, SourceLoc isLoc, TypeRepr *tyRepr);
4740+
47464741
static bool classof(const Expr *E) {
47474742
return E->getKind() == ExprKind::Is;
47484743
}
@@ -4751,35 +4746,29 @@ class IsExpr : public CheckedCastExpr {
47514746
/// Represents an explicit coercion from a value to a specific type.
47524747
///
47534748
/// Spelled 'a as T' and produces a value of type 'T'.
4754-
class CoerceExpr : public ExplicitCastExpr {
4749+
class CoerceExpr final : public ExplicitCastExpr {
47554750
/// Since there is already `asLoc` location,
47564751
/// we use it to store `start` of the initializer
47574752
/// call source range to save some storage.
47584753
SourceLoc InitRangeEnd;
47594754

4760-
public:
4761-
CoerceExpr(Expr *sub, SourceLoc asLoc, TypeLoc type)
4762-
: ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type)
4763-
{ }
4755+
CoerceExpr(Expr *sub, SourceLoc asLoc, TypeExpr *type)
4756+
: ExplicitCastExpr(ExprKind::Coerce, sub, asLoc, type) {}
47644757

4765-
CoerceExpr(SourceLoc asLoc, TypeLoc type)
4766-
: CoerceExpr(nullptr, asLoc, type)
4767-
{ }
4768-
4769-
private:
4770-
CoerceExpr(SourceRange initRange, Expr *literal, TypeLoc type)
4771-
: ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start,
4772-
type), InitRangeEnd(initRange.End)
4773-
{ setImplicit(); }
4758+
CoerceExpr(SourceRange initRange, Expr *literal, TypeExpr *type)
4759+
: ExplicitCastExpr(ExprKind::Coerce, literal, initRange.Start, type),
4760+
InitRangeEnd(initRange.End) {}
47744761

47754762
public:
4763+
static CoerceExpr *create(ASTContext &ctx, SourceLoc asLoc, TypeRepr *tyRepr);
4764+
4765+
static CoerceExpr *createImplicit(ASTContext &ctx, Expr *sub, Type castTy);
4766+
47764767
/// Create an implicit coercion expression for literal initialization
47774768
/// preserving original source information, this way original call
47784769
/// could be recreated if needed.
47794770
static CoerceExpr *forLiteralInit(ASTContext &ctx, Expr *literal,
4780-
SourceRange range, TypeLoc literalType) {
4781-
return new (ctx) CoerceExpr(range, literal, literalType);
4782-
}
4771+
SourceRange range, TypeRepr *literalTyRepr);
47834772

47844773
bool isLiteralInit() const { return InitRangeEnd.isValid(); }
47854774

include/swift/AST/KnownDecls.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ FUNC_DECL(AllocateUninitializedArray,
4444
"_allocateUninitializedArray")
4545
FUNC_DECL(DeallocateUninitializedArray,
4646
"_deallocateUninitializedArray")
47+
FUNC_DECL(FinalizeUninitializedArray,
48+
"_finalizeUninitializedArray")
4749

4850
FUNC_DECL(ForceBridgeFromObjectiveC,
4951
"_forceBridgeFromObjectiveC")

0 commit comments

Comments
 (0)