Skip to content

Commit 81e6039

Browse files
authored
Merge pull request #1203 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents 4492fee + 30491e6 commit 81e6039

File tree

84 files changed

+1292
-219
lines changed

Some content is hidden

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

84 files changed

+1292
-219
lines changed

include/swift/AST/Decl.h

+32
Original file line numberDiff line numberDiff line change
@@ -2711,6 +2711,7 @@ class ValueDecl : public Decl {
27112711
/// Is this declaration marked with 'dynamic'?
27122712
bool isDynamic() const;
27132713

2714+
private:
27142715
bool isObjCDynamic() const {
27152716
return isObjC() && isDynamic();
27162717
}
@@ -2719,6 +2720,37 @@ class ValueDecl : public Decl {
27192720
return !isObjC() && isDynamic();
27202721
}
27212722

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

include/swift/AST/DiagnosticsSema.def

+2-2
Original file line numberDiff line numberDiff line change
@@ -5054,8 +5054,8 @@ ERROR(function_builder_infer_ambig, none,
50545054
NOTE(function_builder_infer_add_return, none,
50555055
"add an explicit 'return' statement to not use a function builder", ())
50565056
NOTE(function_builder_infer_pick_specific, none,
5057-
"apply function builder %0 (inferred from protocol %1)",
5058-
(Type, DeclName))
5057+
"apply function builder %0 (inferred from %select{protocol|dynamic replacement of}1 %2)",
5058+
(Type, unsigned, DeclName))
50595059

50605060
//------------------------------------------------------------------------------
50615061
// MARK: Tuple Shuffle Diagnostics

include/swift/AST/Expr.h

+14-4
Original file line numberDiff line numberDiff line change
@@ -597,13 +597,23 @@ class ErrorExpr : public Expr {
597597
/// CodeCompletionExpr - Represents the code completion token in the AST, this
598598
/// can help us preserve the context of the code completion position.
599599
class CodeCompletionExpr : public Expr {
600-
SourceRange Range;
600+
Expr *Base;
601+
SourceLoc Loc;
601602

602603
public:
603-
CodeCompletionExpr(SourceRange Range, Type Ty = Type())
604-
: Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Ty), Range(Range) {}
604+
CodeCompletionExpr(Expr *Base, SourceLoc Loc)
605+
: Expr(ExprKind::CodeCompletion, /*Implicit=*/true, Type()),
606+
Base(Base), Loc(Loc) {}
605607

606-
SourceRange getSourceRange() const { return Range; }
608+
CodeCompletionExpr(SourceLoc Loc)
609+
: CodeCompletionExpr(/*Base=*/nullptr, Loc) {}
610+
611+
Expr *getBase() const { return Base; }
612+
void setBase(Expr *E) { Base = E; }
613+
614+
SourceLoc getLoc() const { return Loc; }
615+
SourceLoc getStartLoc() const { return Base ? Base->getStartLoc() : Loc; }
616+
SourceLoc getEndLoc() const { return Loc; }
607617

608618
static bool classof(const Expr *E) {
609619
return E->getKind() == ExprKind::CodeCompletion;

include/swift/Basic/LangOptions.h

+6-3
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,13 @@ namespace swift {
316316

317317
/// Emit the newer, finer-grained swiftdeps file. Eventually will support
318318
/// faster rebuilds.
319-
bool EnableFineGrainedDependencies = true;
319+
bool EnableFineGrainedDependencies = false;
320320

321321
/// Instead of hashing tokens inside of NominalType and ExtensionBodies into
322322
/// the interface hash, hash them into per-iterable-decl-context
323323
/// fingerprints. Fine-grained dependency types won't dirty every provides
324324
/// in a file when the user adds a member to, e.g., a struct.
325-
bool EnableTypeFingerprints = true;
325+
bool EnableTypeFingerprints = false;
326326

327327
/// When using fine-grained dependencies, emit dot files for every swiftdeps
328328
/// file.
@@ -540,7 +540,10 @@ namespace swift {
540540
/// Enable constraint solver support for experimental
541541
/// operator protocol designator feature.
542542
bool SolverEnableOperatorDesignatedTypes = false;
543-
543+
544+
/// Enable experimental support for one-way constraints for the
545+
/// parameters of closures.
546+
bool EnableOneWayClosureParameters = false;
544547
};
545548
} // end namespace swift
546549

include/swift/Option/FrontendOptions.td

+4
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,10 @@ def experimental_print_full_convention :
632632
HelpText<"When emitting a module interface, emit additional @convention "
633633
"arguments, regardless of whether they were written in the source">;
634634

635+
def experimental_one_way_closure_params :
636+
Flag<["-"], "experimental-one-way-closure-params">,
637+
HelpText<"Enable experimental support for one-way closure parameters">;
638+
635639
def prebuilt_module_cache_path :
636640
Separate<["-"], "prebuilt-module-cache-path">,
637641
HelpText<"Directory of prebuilt modules for loading module interfaces">;

include/swift/Parse/CodeCompletionCallbacks.h

+4
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,10 @@ class CodeCompletionCallbacks {
198198

199199
virtual void completeCallArg(CodeCompletionExpr *E, bool isFirst) {};
200200

201+
virtual bool canPerformCompleteLabeledTrailingClosure() const {
202+
return false;
203+
}
204+
201205
virtual void completeLabeledTrailingClosure(CodeCompletionExpr *E,
202206
bool isAtStartOfLine) {};
203207

include/swift/Serialization/Validation.h

+5
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class ExtendedValidationInfo {
9898
unsigned IsSIB : 1;
9999
unsigned IsTestable : 1;
100100
unsigned ResilienceStrategy : 2;
101+
unsigned IsImplicitDynamicEnabled: 1;
101102
} Bits;
102103
public:
103104
ExtendedValidationInfo() : Bits() {}
@@ -123,6 +124,10 @@ class ExtendedValidationInfo {
123124
void setPrivateImportsEnabled(bool enabled) {
124125
Bits.ArePrivateImportsEnabled = enabled;
125126
}
127+
bool isImplicitDynamicEnabled() { return Bits.IsImplicitDynamicEnabled; }
128+
void setImplicitDynamicEnabled(bool val) {
129+
Bits.IsImplicitDynamicEnabled = val;
130+
}
126131
bool isTestable() const { return Bits.IsTestable; }
127132
void setIsTestable(bool val) {
128133
Bits.IsTestable = val;

lib/AST/ASTVerifier.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -3111,12 +3111,12 @@ class Verifier : public ASTWalker {
31113111
storageDecl->getWriteImpl() ==
31123112
WriteImplKind::StoredWithObservers ||
31133113
storageDecl->getWriteImpl() == WriteImplKind::MutableAddress) &&
3114-
storageDecl->isNativeDynamic()) &&
3114+
storageDecl->shouldUseNativeDynamicDispatch()) &&
31153115
// We allow a non dynamic getter if there is a dynamic read.
31163116
!(FD->isGetter() &&
31173117
(storageDecl->getReadImpl() == ReadImplKind::Read ||
31183118
storageDecl->getReadImpl() == ReadImplKind::Address) &&
3119-
storageDecl->isNativeDynamic())) {
3119+
storageDecl->shouldUseNativeDynamicDispatch())) {
31203120
Out << "Property and accessor do not match for 'dynamic'\n";
31213121
abort();
31223122
}

lib/AST/ASTWalker.cpp

+9-1
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,15 @@ class Traversal : public ASTVisitor<Traversal, Expr*, Stmt*,
476476
} while (false)
477477

478478
Expr *visitErrorExpr(ErrorExpr *E) { return E; }
479-
Expr *visitCodeCompletionExpr(CodeCompletionExpr *E) { return E; }
479+
Expr *visitCodeCompletionExpr(CodeCompletionExpr *E) {
480+
if (Expr *baseExpr = E->getBase()) {
481+
Expr *newBaseExpr = doIt(baseExpr);
482+
if (!newBaseExpr)
483+
return nullptr;
484+
E->setBase(newBaseExpr);
485+
}
486+
return E;
487+
}
480488
Expr *visitLiteralExpr(LiteralExpr *E) { return E; }
481489
Expr *visitDiscardAssignmentExpr(DiscardAssignmentExpr *E) { return E; }
482490
Expr *visitTypeExpr(TypeExpr *E) {

lib/AST/Decl.cpp

+57-4
Original file line numberDiff line numberDiff line change
@@ -1950,7 +1950,7 @@ SourceRange IfConfigDecl::getSourceRange() const {
19501950
}
19511951

19521952
static bool isPolymorphic(const AbstractStorageDecl *storage) {
1953-
if (storage->isObjCDynamic())
1953+
if (storage->shouldUseObjCDispatch())
19541954
return true;
19551955

19561956

@@ -2083,7 +2083,7 @@ getDirectReadWriteAccessStrategy(const AbstractStorageDecl *storage) {
20832083
return AccessStrategy::getStorage();
20842084
case ReadWriteImplKind::Stored: {
20852085
// If the storage isDynamic (and not @objc) use the accessors.
2086-
if (storage->isNativeDynamic())
2086+
if (storage->shouldUseNativeDynamicDispatch())
20872087
return AccessStrategy::getMaterializeToTemporary(
20882088
getOpaqueReadAccessStrategy(storage, false),
20892089
getOpaqueWriteAccessStrategy(storage, false));
@@ -2168,7 +2168,7 @@ AbstractStorageDecl::getAccessStrategy(AccessSemantics semantics,
21682168
if (isPolymorphic(this))
21692169
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ true);
21702170

2171-
if (isNativeDynamic())
2171+
if (shouldUseNativeDynamicDispatch())
21722172
return getOpaqueAccessStrategy(this, accessKind, /*dispatch*/ false);
21732173

21742174
// If the storage is resilient from the given module and resilience
@@ -2926,6 +2926,59 @@ bool ValueDecl::isDynamic() const {
29262926
getAttrs().hasAttribute<DynamicAttr>());
29272927
}
29282928

2929+
bool ValueDecl::isObjCDynamicInGenericClass() const {
2930+
if (!isObjCDynamic())
2931+
return false;
2932+
2933+
auto *DC = this->getDeclContext();
2934+
auto *classDecl = DC->getSelfClassDecl();
2935+
if (!classDecl)
2936+
return false;
2937+
2938+
return classDecl->isGenericContext() && !classDecl->usesObjCGenericsModel();
2939+
}
2940+
2941+
bool ValueDecl::shouldUseObjCMethodReplacement() const {
2942+
if (isNativeDynamic())
2943+
return false;
2944+
2945+
if (getModuleContext()->isImplicitDynamicEnabled() &&
2946+
isObjCDynamicInGenericClass())
2947+
return false;
2948+
2949+
return isObjCDynamic();
2950+
}
2951+
2952+
bool ValueDecl::shouldUseNativeMethodReplacement() const {
2953+
if (isNativeDynamic())
2954+
return true;
2955+
2956+
if (!isObjCDynamicInGenericClass())
2957+
return false;
2958+
2959+
auto *replacedDecl = getDynamicallyReplacedDecl();
2960+
if (replacedDecl)
2961+
return false;
2962+
2963+
return getModuleContext()->isImplicitDynamicEnabled();
2964+
}
2965+
2966+
bool ValueDecl::isNativeMethodReplacement() const {
2967+
// Is this a @_dynamicReplacement(for:) that use the native dynamic function
2968+
// replacement mechanism.
2969+
auto *replacedDecl = getDynamicallyReplacedDecl();
2970+
if (!replacedDecl)
2971+
return false;
2972+
2973+
if (isNativeDynamic())
2974+
return true;
2975+
2976+
if (isObjCDynamicInGenericClass())
2977+
return replacedDecl->getModuleContext()->isImplicitDynamicEnabled();
2978+
2979+
return false;
2980+
}
2981+
29292982
void ValueDecl::setIsDynamic(bool value) {
29302983
assert(!LazySemanticInfo.isDynamicComputed ||
29312984
LazySemanticInfo.isDynamic == value);
@@ -5143,7 +5196,7 @@ bool AbstractStorageDecl::hasDidSetOrWillSetDynamicReplacement() const {
51435196

51445197
bool AbstractStorageDecl::hasAnyNativeDynamicAccessors() const {
51455198
for (auto accessor : getAllAccessors()) {
5146-
if (accessor->isNativeDynamic())
5199+
if (accessor->shouldUseNativeDynamicDispatch())
51475200
return true;
51485201
}
51495202
return false;

lib/Frontend/CompilerInvocation.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,8 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
677677

678678
Opts.SolverEnableOperatorDesignatedTypes |=
679679
Args.hasArg(OPT_solver_enable_operator_designated_types);
680+
Opts.EnableOneWayClosureParameters |=
681+
Args.hasArg(OPT_experimental_one_way_closure_params);
680682

681683
Opts.DebugConstraintSolver |= Args.hasArg(OPT_debug_constraints);
682684
Opts.DebugGenericSignatures |= Args.hasArg(OPT_debug_generic_signatures);

0 commit comments

Comments
 (0)