Skip to content

Commit 07e7655

Browse files
authored
Merge pull request #2891 from swiftwasm/main
[pull] swiftwasm from main
2 parents 3ded3e6 + a72070e commit 07e7655

File tree

123 files changed

+3275
-1614
lines changed

Some content is hidden

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

123 files changed

+3275
-1614
lines changed

include/swift/AST/ActorIsolation.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class ActorIsolation {
4040
/// The actor isolation has not been specified. It is assumed to be
4141
/// unsafe to interact with this declaration from any actor.
4242
Unspecified = 0,
43-
/// The declaration is isolated to the instance of an actor class.
43+
/// The declaration is isolated to the instance of an actor.
4444
/// For example, a mutable stored property or synchronous function within
4545
/// the actor is isolated to the instance of that actor.
4646
ActorInstance,

include/swift/AST/DiagnosticEngine.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -814,15 +814,15 @@ namespace swift {
814814
if (llvm::sys::fs::exists(filePath)) {
815815
if (auto file = llvm::MemoryBuffer::getFile(filePath)) {
816816
localization = std::make_unique<diag::SerializedLocalizationProducer>(
817-
std::move(file.get()));
817+
std::move(file.get()), getPrintDiagnosticNames());
818818
}
819819
} else {
820820
llvm::sys::path::replace_extension(filePath, ".yaml");
821821
// In case of missing localization files, we should fallback to messages
822822
// from `.def` files.
823823
if (llvm::sys::fs::exists(filePath)) {
824-
localization =
825-
std::make_unique<diag::YAMLLocalizationProducer>(filePath.str());
824+
localization = std::make_unique<diag::YAMLLocalizationProducer>(
825+
filePath.str(), getPrintDiagnosticNames());
826826
}
827827
}
828828
}
@@ -1049,7 +1049,7 @@ namespace swift {
10491049

10501050
public:
10511051
llvm::StringRef diagnosticStringFor(const DiagID id,
1052-
bool printDiagnosticName);
1052+
bool printDiagnosticNames);
10531053

10541054
/// If there is no clear .dia file for a diagnostic, put it in the one
10551055
/// corresponding to the SourceLoc given here.

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,7 +4323,7 @@ ERROR(async_objc_dynamic_self,none,
43234323
"asynchronous method returning 'Self' cannot be '@objc'", ())
43244324

43254325
ERROR(actor_with_nonactor_superclass,none,
4326-
"actor class cannot inherit from non-actor class %0", (DeclName))
4326+
"actor cannot inherit from non-actor class %0", (DeclName))
43274327

43284328
ERROR(actor_isolated_non_self_reference,none,
43294329
"actor-isolated %0 %1 can only be %select{referenced|mutated|used 'inout'}3 "
@@ -4500,7 +4500,7 @@ ERROR(multiple_global_actors,none,
45004500
ERROR(global_actor_disallowed,none,
45014501
"%0 cannot have a global actor", (DescriptiveDeclKind))
45024502
ERROR(global_actor_on_actor_class,none,
4503-
"actor class %0 cannot have a global actor", (Identifier))
4503+
"actor %0 cannot have a global actor", (Identifier))
45044504
ERROR(global_actor_on_local_variable,none,
45054505
"local variable %0 cannot have a global actor", (DeclName))
45064506
ERROR(global_actor_non_unsafe_init,none,
@@ -5581,16 +5581,16 @@ ERROR(property_wrapper_param_not_supported,none,
55815581
(DescriptiveDeclKind))
55825582
NOTE(property_wrapper_declared_here,none,
55835583
"property wrapper type %0 declared here", (Identifier))
5584-
ERROR(property_wrapper_param_no_projection,none,
5585-
"cannot use property wrapper projection parameter; "
5586-
"wrapper %0 does not have a 'projectedValue'", (Type))
5587-
ERROR(property_wrapper_param_no_wrapper,none,
5588-
"cannot use property wrapper projection argument; "
5589-
"parameter does not have an attached property wrapper",
5590-
())
5591-
ERROR(property_wrapper_param_projection_invalid,none,
5592-
"cannot use property wrapper projection argument; "
5593-
"pass wrapped value type %0 instead", (Type))
5584+
ERROR(invalid_projection_argument,none,
5585+
"cannot use property wrapper projection %select{argument|parameter}0",
5586+
(bool))
5587+
NOTE(property_wrapper_param_no_wrapper,none,
5588+
"parameter %0 does not have an attached property wrapper", (Identifier))
5589+
NOTE(property_wrapper_param_attr_arg,none,
5590+
"property wrapper has arguments in the wrapper attribute", ())
5591+
NOTE(property_wrapper_no_init_projected_value,none,
5592+
"property wrapper type %0 does not support initialization from a "
5593+
"projected value", (Type))
55945594
ERROR(property_wrapper_param_mutating,none,
55955595
"property wrapper applied to parameter must have a nonmutating "
55965596
"'wrappedValue' getter", ())

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,7 +3329,7 @@ END_CAN_TYPE_WRAPPER(FunctionType, AnyFunctionType)
33293329
struct ParameterListInfo {
33303330
SmallBitVector defaultArguments;
33313331
SmallBitVector acceptsUnlabeledTrailingClosures;
3332-
SmallVector<const ParamDecl *, 4> propertyWrappers;
3332+
SmallBitVector propertyWrappers;
33333333

33343334
public:
33353335
ParameterListInfo() { }
@@ -3346,7 +3346,7 @@ struct ParameterListInfo {
33463346

33473347
/// The ParamDecl at the given index if the parameter has an applied
33483348
/// property wrapper.
3349-
const ParamDecl *getPropertyWrapperParam(unsigned paramIdx) const;
3349+
bool hasExternalPropertyWrapper(unsigned paramIdx) const;
33503350

33513351
/// Retrieve the number of non-defaulted parameters.
33523352
unsigned numNonDefaultedParameters() const {

include/swift/IDE/Utils.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ struct ResolvedCursorInfo {
164164
Type ContainerType;
165165
Stmt *TrailingStmt = nullptr;
166166
Expr *TrailingExpr = nullptr;
167+
/// If this is a call, whether it is "dynamic", see ide::isDynamicCall.
168+
bool IsDynamic = false;
169+
/// If this is a call, the types of the base (multiple in the case of
170+
/// protocol composition).
171+
SmallVector<NominalTypeDecl *, 1> ReceiverTypes;
167172

168173
ResolvedCursorInfo() = default;
169174
ResolvedCursorInfo(SourceFile *SF) : SF(SF) {}
@@ -174,12 +179,9 @@ struct ResolvedCursorInfo {
174179
lhs.Loc.getOpaquePointerValue() == rhs.Loc.getOpaquePointerValue();
175180
}
176181

177-
void setValueRef(ValueDecl *ValueD,
178-
TypeDecl *CtorTyRef,
179-
ExtensionDecl *ExtTyRef,
180-
bool IsRef,
181-
Type Ty,
182-
Type ContainerType) {
182+
void setValueRef(ValueDecl *ValueD, TypeDecl *CtorTyRef,
183+
ExtensionDecl *ExtTyRef, bool IsRef,
184+
Type Ty, Type ContainerType) {
183185
Kind = CursorInfoKind::ValueRef;
184186
this->ValueD = ValueD;
185187
this->CtorTyRef = CtorTyRef;
@@ -621,6 +623,23 @@ ClangNode extensionGetClangNode(const ExtensionDecl *ext);
621623
/// or a curry thunk, etc.
622624
std::pair<Type, ConcreteDeclRef> getReferencedDecl(Expr *expr);
623625

626+
/// Whether the last expression in \p ExprStack is being called.
627+
bool isBeingCalled(ArrayRef<Expr*> ExprStack);
628+
629+
/// The base of the last expression in \p ExprStack (which may look up the
630+
/// stack in eg. the case of a `DotSyntaxCallExpr`).
631+
Expr *getBase(ArrayRef<Expr *> ExprStack);
632+
633+
/// Assuming that we have a call, returns whether or not it is "dynamic" based
634+
/// on its base expression and decl of the callee. Note that this is not
635+
/// Swift's "dynamic" modifier (`ValueDecl::isDynamic`), but rathar "can call a
636+
/// function in a conformance/subclass".
637+
bool isDynamicCall(Expr *Base, ValueDecl *D);
638+
639+
/// Adds the resolved nominal types of \p Base to \p Types.
640+
void getReceiverType(Expr *Base,
641+
SmallVectorImpl<NominalTypeDecl *> &Types);
642+
624643
} // namespace ide
625644
} // namespace swift
626645

include/swift/Localization/LocalizationFormat.h

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Support/EndianStream.h"
2727
#include "llvm/Support/MemoryBuffer.h"
2828
#include "llvm/Support/OnDiskHashTable.h"
29+
#include "llvm/Support/StringSaver.h"
2930
#include "llvm/Support/YAMLParser.h"
3031
#include "llvm/Support/YAMLTraits.h"
3132
#include "llvm/Support/raw_ostream.h"
@@ -154,14 +155,23 @@ class SerializedLocalizationWriter {
154155
};
155156

156157
class LocalizationProducer {
158+
/// This allocator will retain localized diagnostic strings containing the
159+
/// diagnostic's message and identifier as `message [id]` for the duration of
160+
/// compiler invocation. This will be used when the frontend flag
161+
/// `-debug-diagnostic-names` is used.
162+
llvm::BumpPtrAllocator localizationAllocator;
163+
llvm::StringSaver localizationSaver;
164+
bool printDiagnosticNames;
165+
157166
public:
167+
LocalizationProducer(bool printDiagnosticNames = false)
168+
: localizationSaver(localizationAllocator),
169+
printDiagnosticNames(printDiagnosticNames) {}
170+
158171
/// If the message isn't available/localized in current context
159172
/// return the fallback default message.
160173
virtual llvm::StringRef getMessageOr(swift::DiagID id,
161-
llvm::StringRef defaultMessage) const {
162-
auto message = getMessage(id);
163-
return message.empty() ? defaultMessage : message;
164-
}
174+
llvm::StringRef defaultMessage);
165175

166176
virtual ~LocalizationProducer() {}
167177

@@ -177,7 +187,8 @@ class YAMLLocalizationProducer final : public LocalizationProducer {
177187
public:
178188
/// The diagnostics IDs that are no longer available in `.def`
179189
std::vector<std::string> unknownIDs;
180-
explicit YAMLLocalizationProducer(llvm::StringRef filePath);
190+
explicit YAMLLocalizationProducer(llvm::StringRef filePath,
191+
bool printDiagnosticNames = false);
181192

182193
/// Iterate over all of the available (non-empty) translations
183194
/// maintained by this producer, callback gets each translation
@@ -198,7 +209,8 @@ class SerializedLocalizationProducer final : public LocalizationProducer {
198209

199210
public:
200211
explicit SerializedLocalizationProducer(
201-
std::unique_ptr<llvm::MemoryBuffer> buffer);
212+
std::unique_ptr<llvm::MemoryBuffer> buffer,
213+
bool printDiagnosticNames = false);
202214

203215
protected:
204216
llvm::StringRef getMessage(swift::DiagID id) const override;

include/swift/Runtime/Concurrency.h

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,25 @@ SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
479479
void swift_MainActor_register(HeapObject *actor);
480480

481481
/// A hook to take over global enqueuing.
482-
/// TODO: figure out a better abstraction plan than this.
483-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
484-
void (*swift_task_enqueueGlobal_hook)(Job *job);
482+
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobal_original)(Job *job);
483+
SWIFT_EXPORT_FROM(swift_Concurrency)
484+
SWIFT_CC(swift) void (*swift_task_enqueueGlobal_hook)(
485+
Job *job, swift_task_enqueueGlobal_original original);
485486

486487
/// A hook to take over global enqueuing with delay.
487-
/// TODO: figure out a better abstraction plan than this.
488-
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
489-
void (*swift_task_enqueueGlobalWithDelay_hook)(unsigned long long delay, Job *job);
488+
typedef SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_original)(
489+
unsigned long long delay, Job *job);
490+
SWIFT_EXPORT_FROM(swift_Concurrency)
491+
SWIFT_CC(swift) void (*swift_task_enqueueGlobalWithDelay_hook)(
492+
unsigned long long delay, Job *job,
493+
swift_task_enqueueGlobalWithDelay_original original);
494+
495+
/// A hook to take over main executor enqueueing.
496+
typedef SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_original)(
497+
Job *job);
498+
SWIFT_EXPORT_FROM(swift_Concurrency)
499+
SWIFT_CC(swift) void (*swift_task_enqueueMainExecutor_hook)(
500+
Job *job, swift_task_enqueueMainExecutor_original original);
490501

491502
/// Initialize the runtime storage for a default actor.
492503
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
@@ -537,7 +548,7 @@ void swift_continuation_logFailedCheck(const char *message);
537548
/// If the binary links CoreFoundation, uses CFRunLoopRun
538549
/// Otherwise it uses dispatchMain.
539550
SWIFT_EXPORT_FROM(swift_Concurrency) SWIFT_CC(swift)
540-
void swift_task_asyncMainDrainQueue();
551+
void swift_task_asyncMainDrainQueue [[noreturn]]();
541552

542553
/// Establish that the current thread is running as the given
543554
/// executor, then run a job.

include/swift/Sema/CSFix.h

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ enum class FixKind : uint8_t {
122122
/// the storage or property wrapper.
123123
UseWrappedValue,
124124

125-
/// Add 'var projectedValue' to the property wrapper type to allow passing
126-
/// a projection argument.
127-
AddProjectedValue,
125+
/// Allow a type that is not a property wrapper to be used as a property
126+
/// wrapper.
127+
AllowInvalidPropertyWrapperType,
128128

129-
/// Add '@propertyWrapper' to a nominal type declaration.
130-
AddPropertyWrapperAttribute,
129+
/// Remove the '$' prefix from an argument label or parameter name.
130+
RemoveProjectedValueArgument,
131131

132132
/// Instead of spelling out `subscript` directly, use subscript operator.
133133
UseSubscriptOperator,
@@ -984,37 +984,40 @@ class UseWrappedValue final : public ConstraintFix {
984984
ConstraintLocator *locator);
985985
};
986986

987-
class AddProjectedValue final : public ConstraintFix {
987+
class AllowInvalidPropertyWrapperType final : public ConstraintFix {
988988
Type wrapperType;
989989

990-
AddProjectedValue(ConstraintSystem &cs, Type wrapper,
991-
ConstraintLocator *locator)
992-
: ConstraintFix(cs, FixKind::AddProjectedValue, locator), wrapperType(wrapper) {}
990+
AllowInvalidPropertyWrapperType(ConstraintSystem &cs, Type wrapperType,
991+
ConstraintLocator *locator)
992+
: ConstraintFix(cs, FixKind::AllowInvalidPropertyWrapperType, locator),
993+
wrapperType(wrapperType) {}
993994

994995
public:
995-
static AddProjectedValue *create(ConstraintSystem &cs, Type wrapper,
996-
ConstraintLocator *locator);
996+
static AllowInvalidPropertyWrapperType *create(ConstraintSystem &cs, Type wrapperType,
997+
ConstraintLocator *locator);
997998

998999
std::string getName() const override {
999-
return "add 'var projectedValue' to pass a projection argument";
1000+
return "allow invalid property wrapper type";
10001001
}
10011002

10021003
bool diagnose(const Solution &solution, bool asNote = false) const override;
10031004
};
10041005

1005-
class AddPropertyWrapperAttribute final : public ConstraintFix {
1006+
class RemoveProjectedValueArgument final : public ConstraintFix {
10061007
Type wrapperType;
1008+
ParamDecl *param;
10071009

1008-
AddPropertyWrapperAttribute(ConstraintSystem &cs, Type wrapper,
1009-
ConstraintLocator *locator)
1010-
: ConstraintFix(cs, FixKind::AddPropertyWrapperAttribute, locator), wrapperType(wrapper) {}
1010+
RemoveProjectedValueArgument(ConstraintSystem &cs, Type wrapper,
1011+
ParamDecl *param, ConstraintLocator *locator)
1012+
: ConstraintFix(cs, FixKind::RemoveProjectedValueArgument, locator),
1013+
wrapperType(wrapper), param(param) {}
10111014

10121015
public:
1013-
static AddPropertyWrapperAttribute *create(ConstraintSystem &cs, Type wrapper,
1014-
ConstraintLocator *locator);
1016+
static RemoveProjectedValueArgument *create(ConstraintSystem &cs, Type wrapper,
1017+
ParamDecl *param, ConstraintLocator *locator);
10151018

10161019
std::string getName() const override {
1017-
return "add '@propertyWrapper'";
1020+
return "remove '$' from argument label";
10181021
}
10191022

10201023
bool diagnose(const Solution &solution, bool asNote = false) const override;

include/swift/Sema/Constraint.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ enum class ConstraintKind : char {
187187
/// - If base is a protocol metatype, this constraint becomes a conformance
188188
/// check instead of an equality.
189189
UnresolvedMemberChainBase,
190+
/// The first type is a property wrapper with a wrapped-value type
191+
/// equal to the second type.
192+
PropertyWrapper,
190193
};
191194

192195
/// Classification of the different kinds of constraints.
@@ -586,6 +589,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
586589
case ConstraintKind::ValueMember:
587590
case ConstraintKind::UnresolvedValueMember:
588591
case ConstraintKind::ValueWitness:
592+
case ConstraintKind::PropertyWrapper:
589593
return ConstraintClassification::Member;
590594

591595
case ConstraintKind::DynamicTypeOf:

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4595,6 +4595,11 @@ class ConstraintSystem {
45954595
ArrayRef<TypeVariableType *> referencedOuterParameters,
45964596
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
45974597

4598+
/// Attempt to simplify a property wrapper constraint.
4599+
SolutionKind simplifyPropertyWrapperConstraint(Type wrapperType, Type wrappedValueType,
4600+
TypeMatchOptions flags,
4601+
ConstraintLocatorBuilder locator);
4602+
45984603
/// Attempt to simplify a one-way constraint.
45994604
SolutionKind simplifyOneWayConstraint(ConstraintKind kind,
46004605
Type first, Type second,

lib/AST/ASTPrinter.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5158,7 +5158,11 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
51585158
->castTo<GenericTypeParamType>()
51595159
->getIndex();
51605160

5161-
Printer << u8") \U0001F9B8";
5161+
// The identifier after the closing parenthesis is irrelevant and can be
5162+
// anything. It just needs to be there for the @_opaqueReturnTypeOf
5163+
// attribute to apply to, but the attribute alone references the opaque
5164+
// type.
5165+
Printer << ") __";
51625166
printGenericArgs(T->getSubstitutions().getReplacementTypes());
51635167
return;
51645168
}

lib/AST/Attr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
10201020
type.print(Printer, Options);
10211021
else
10221022
attr->getTypeRepr()->print(Printer, Options);
1023-
if (attr->isArgUnsafe())
1023+
if (attr->isArgUnsafe() && Options.IsForSwiftInterface)
10241024
Printer << "(unsafe)";
10251025
Printer.printNamePost(PrintNameContext::Attribute);
10261026
break;

lib/AST/DiagnosticEngine.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,12 +1115,10 @@ void DiagnosticEngine::emitDiagnostic(const Diagnostic &diagnostic) {
11151115

11161116
llvm::StringRef
11171117
DiagnosticEngine::diagnosticStringFor(const DiagID id,
1118-
bool printDiagnosticName) {
1119-
// TODO: Print diagnostic names from `localization`.
1120-
if (printDiagnosticName) {
1121-
return debugDiagnosticStrings[(unsigned)id];
1122-
}
1123-
auto defaultMessage = diagnosticStrings[(unsigned)id];
1118+
bool printDiagnosticNames) {
1119+
auto defaultMessage = printDiagnosticNames
1120+
? debugDiagnosticStrings[(unsigned)id]
1121+
: diagnosticStrings[(unsigned)id];
11241122
if (localization) {
11251123
auto localizedMessage =
11261124
localization.get()->getMessageOr(id, defaultMessage);

lib/AST/Module.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,7 @@ bool ModuleDecl::isBuiltinModule() const {
14191419
}
14201420

14211421
bool SourceFile::registerMainDecl(Decl *mainDecl, SourceLoc diagLoc) {
1422+
assert(mainDecl);
14221423
if (mainDecl == MainDecl)
14231424
return false;
14241425

0 commit comments

Comments
 (0)