Skip to content

Commit f45c1a4

Browse files
authored
Merge pull request #4394 from swiftwasm/release/5.6
[pull] swiftwasm-release/5.6 from release/5.6
2 parents 9548ba6 + 4e118a1 commit f45c1a4

28 files changed

+345
-174
lines changed

include/swift/ABI/TaskStatus.h

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,21 @@ class ChildTaskStatusRecord : public TaskStatusRecord {
164164
/// and are only tracked by their respective `TaskGroupTaskStatusRecord`.
165165
class TaskGroupTaskStatusRecord : public TaskStatusRecord {
166166
AsyncTask *FirstChild;
167+
AsyncTask *LastChild;
167168

168169
public:
169170
TaskGroupTaskStatusRecord()
170-
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(nullptr) {
171+
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
172+
FirstChild(nullptr),
173+
LastChild(nullptr) {
171174
}
172175

173176
TaskGroupTaskStatusRecord(AsyncTask *child)
174-
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(child) {}
177+
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
178+
FirstChild(child),
179+
LastChild(child) {
180+
assert(!LastChild || !LastChild->childFragment()->getNextChild());
181+
}
175182

176183
TaskGroup *getGroup() { return reinterpret_cast<TaskGroup *>(this); }
177184

@@ -185,38 +192,28 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
185192
assert(child->hasGroupChildFragment());
186193
assert(child->groupChildFragment()->getGroup() == getGroup());
187194

195+
auto oldLastChild = LastChild;
196+
LastChild = child;
197+
188198
if (!FirstChild) {
189199
// This is the first child we ever attach, so store it as FirstChild.
190200
FirstChild = child;
191201
return;
192202
}
193203

194-
// We need to traverse the siblings to find the last one and add the child
195-
// there.
196-
// FIXME: just set prepend to the current head, no need to traverse.
197-
198-
auto cur = FirstChild;
199-
while (cur) {
200-
// no need to check hasChildFragment, all tasks we store here have them.
201-
auto fragment = cur->childFragment();
202-
if (auto next = fragment->getNextChild()) {
203-
cur = next;
204-
} else {
205-
// we're done searching and `cur` is the last
206-
break;
207-
}
208-
}
209-
210-
cur->childFragment()->setNextChild(child);
204+
oldLastChild->childFragment()->setNextChild(child);
211205
}
212206

213207
void detachChild(AsyncTask *child) {
214208
assert(child && "cannot remove a null child from group");
215209
if (FirstChild == child) {
216210
FirstChild = getNextChildTask(child);
211+
if (FirstChild == nullptr) {
212+
LastChild = nullptr;
213+
}
217214
return;
218215
}
219-
216+
220217
AsyncTask *prev = FirstChild;
221218
// Remove the child from the linked list, i.e.:
222219
// prev -> afterPrev -> afterChild
@@ -230,6 +227,9 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
230227
if (afterPrev == child) {
231228
auto afterChild = getNextChildTask(child);
232229
prev->childFragment()->setNextChild(afterChild);
230+
if (child == LastChild) {
231+
LastChild = prev;
232+
}
233233
return;
234234
}
235235

include/swift/AST/ActorIsolation.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,20 @@ class ActorIsolation {
109109

110110
bool isIndependent() const { return kind == Independent; }
111111

112+
bool isActorIsolated() const {
113+
switch (getKind()) {
114+
case ActorInstance:
115+
case DistributedActorInstance:
116+
case GlobalActor:
117+
case GlobalActorUnsafe:
118+
return true;
119+
120+
case Unspecified:
121+
case Independent:
122+
return false;
123+
}
124+
}
125+
112126
NominalTypeDecl *getActor() const {
113127
assert(getKind() == ActorInstance || getKind() == DistributedActorInstance);
114128
return actor;

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4475,10 +4475,6 @@ ERROR(global_actor_from_nonactor_context,none,
44754475
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
44764476
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
44774477
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
4478-
ERROR(global_actor_from_initializing_expr,none,
4479-
"expression requiring global actor %0 cannot appear in "
4480-
"default-value expression of %1 %2",
4481-
(Type, DescriptiveDeclKind, DeclName))
44824478
ERROR(actor_isolated_call,none,
44834479
"call to %0 function in a synchronous %1 context",
44844480
(ActorIsolation, ActorIsolation))

lib/AST/Decl.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8667,24 +8667,9 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
86678667
if (auto *vd = dyn_cast_or_null<ValueDecl>(dc->getAsDecl()))
86688668
return getActorIsolation(vd);
86698669

8670-
// In the context of the initializing or default-value expression of a
8671-
// stored property, the isolation varies between global and type members:
8672-
// - For a static stored property, the isolation matches the VarDecl.
8673-
// - For a field of a nominal type, the expression is not isolated.
8674-
// Without this distinction, a nominal can have non-async initializers
8675-
// with various kinds of isolation, so an impossible constraint can be
8676-
// created. See SE-0327 for details.
8677-
if (auto *var = dc->getNonLocalVarDecl()) {
8678-
8679-
// Isolation officially changes, as described above, in Swift 6+
8680-
if (dc->getASTContext().isSwiftVersionAtLeast(6) &&
8681-
var->isInstanceMember() &&
8682-
!var->getAttrs().hasAttribute<LazyAttr>()) {
8683-
return ActorIsolation::forUnspecified();
8684-
}
8685-
8670+
if (auto *var = dc->getNonLocalVarDecl())
86868671
return getActorIsolation(var);
8687-
}
8672+
86888673

86898674
if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
86908675
switch (auto isolation = closure->getActorIsolation()) {

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,8 +3988,16 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
39883988
ProtocolDecl *proto,
39893989
const RequirementSource *source,
39903990
bool onlySameTypeConstraints) {
3991-
auto protocolSubMap = SubstitutionMap::getProtocolSubstitutions(
3992-
proto, selfType.getDependentType(*this), ProtocolConformanceRef(proto));
3991+
auto selfTy = selfType.getDependentType(*this);
3992+
3993+
auto subst = [&](Requirement req) -> Optional<Requirement> {
3994+
return req.subst(
3995+
[&](SubstitutableType *t) -> Type {
3996+
assert(isa<GenericTypeParamType>(t));
3997+
return selfTy;
3998+
},
3999+
MakeAbstractConformanceForGenericType());
4000+
};
39934001

39944002
// Use the requirement signature to avoid rewalking the entire protocol. This
39954003
// cannot compute the requirement signature directly, because that may be
@@ -4003,7 +4011,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
40034011
if (onlySameTypeConstraints && req.getKind() != RequirementKind::SameType)
40044012
continue;
40054013

4006-
auto substReq = req.subst(protocolSubMap);
4014+
auto substReq = subst(req);
40074015
auto reqResult = substReq
40084016
? addRequirement(*substReq, innerSource, nullptr)
40094017
: ConstraintResult::Conflicting;
@@ -4032,8 +4040,9 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
40324040

40334041
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
40344042
source, proto, reqRepr->getSeparatorLoc(), /*inferred=*/false);
4035-
addRequirement(req, reqRepr, innerSource,
4036-
&protocolSubMap, nullptr);
4043+
4044+
if (auto substReq = subst(req))
4045+
addRequirement(*substReq, reqRepr, innerSource, nullptr);
40374046
return false;
40384047
});
40394048

@@ -4146,7 +4155,7 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
41464155
source, proto, SourceLoc(), /*inferred=*/true);
41474156

41484157
auto rawReq = Requirement(RequirementKind::SameType, firstType, secondType);
4149-
if (auto req = rawReq.subst(protocolSubMap))
4158+
if (auto req = subst(rawReq))
41504159
addRequirement(*req, inferredSameTypeSource, proto->getParentModule());
41514160
};
41524161

@@ -4174,8 +4183,10 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
41744183

41754184
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
41764185
source, proto, reqRepr->getSeparatorLoc(), /*inferred=*/false);
4177-
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
4178-
/*inferForModule=*/nullptr);
4186+
if (auto substReq = subst(req)) {
4187+
addRequirement(*substReq, reqRepr, innerSource,
4188+
/*inferForModule=*/nullptr);
4189+
}
41794190
return false;
41804191
});
41814192

@@ -5160,28 +5171,19 @@ ConstraintResult
51605171
GenericSignatureBuilder::addRequirement(const Requirement &req,
51615172
FloatingRequirementSource source,
51625173
ModuleDecl *inferForModule) {
5163-
return addRequirement(req, nullptr, source, nullptr, inferForModule);
5174+
return addRequirement(req, nullptr, source, inferForModule);
51645175
}
51655176

51665177
ConstraintResult
51675178
GenericSignatureBuilder::addRequirement(const Requirement &req,
51685179
const RequirementRepr *reqRepr,
51695180
FloatingRequirementSource source,
5170-
const SubstitutionMap *subMap,
51715181
ModuleDecl *inferForModule) {
5172-
// Local substitution for types in the requirement.
5173-
auto subst = [&](Type t) {
5174-
if (subMap)
5175-
return t.subst(*subMap);
5176-
5177-
return t;
5178-
};
5179-
5180-
auto firstType = subst(req.getFirstType());
5182+
auto firstType = req.getFirstType();
51815183
switch (req.getKind()) {
51825184
case RequirementKind::Superclass:
51835185
case RequirementKind::Conformance: {
5184-
auto secondType = subst(req.getSecondType());
5186+
auto secondType = req.getSecondType();
51855187

51865188
if (inferForModule) {
51875189
inferRequirements(*inferForModule, firstType,
@@ -5209,7 +5211,7 @@ GenericSignatureBuilder::addRequirement(const Requirement &req,
52095211
}
52105212

52115213
case RequirementKind::SameType: {
5212-
auto secondType = subst(req.getSecondType());
5214+
auto secondType = req.getSecondType();
52135215

52145216
if (inferForModule) {
52155217
inferRequirements(*inferForModule, firstType,
@@ -8697,8 +8699,8 @@ InferredGenericSignatureRequest::evaluate(
86978699
}
86988700
}
86998701

8700-
builder.addRequirement(req, reqRepr, source, nullptr,
8701-
lookupDC->getParentModule());
8702+
builder.addRequirement(req, reqRepr, source,
8703+
lookupDC->getParentModule());
87028704
return false;
87038705
};
87048706

lib/AST/GenericSignatureBuilder.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,6 @@ class GenericSignatureBuilder {
570570
ConstraintResult addRequirement(const Requirement &req,
571571
const RequirementRepr *reqRepr,
572572
FloatingRequirementSource source,
573-
const SubstitutionMap *subMap,
574573
ModuleDecl *inferForModule);
575574

576575
/// Add all of a generic signature's parameters and requirements.

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -491,9 +491,9 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
491491
continue;
492492
}
493493

494-
// FIXME: Maybe this can happen if the concrete type is an
495-
// opaque result type?
496-
assert(!conformance.isAbstract());
494+
// This can happen if the concrete type is an opaque result type.
495+
if (conformance.isAbstract())
496+
continue;
497497

498498
auto *concrete = conformance.getConcrete();
499499

lib/AST/TypeRepr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,8 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
183183
Printer.printSimpleAttr("@autoclosure") << " ";
184184
if (hasAttr(TAK_escaping))
185185
Printer.printSimpleAttr("@escaping") << " ";
186+
if (hasAttr(TAK_Sendable))
187+
Printer.printSimpleAttr("@Sendable") << " ";
186188
if (hasAttr(TAK_noDerivative))
187189
Printer.printSimpleAttr("@noDerivative") << " ";
188190

lib/IRGen/MetadataRequest.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1670,8 +1670,12 @@ namespace {
16701670
}
16711671

16721672
auto layout = type.getExistentialLayout();
1673-
1674-
auto protocols = layout.getProtocols();
1673+
1674+
SmallVector<ProtocolType *, 4> protocols;
1675+
for (auto proto : layout.getProtocols()) {
1676+
if (!proto->getDecl()->isMarkerProtocol())
1677+
protocols.push_back(proto);
1678+
}
16751679

16761680
// Collect references to the protocol descriptors.
16771681
auto descriptorArrayTy

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ struct ArgumentInitHelper {
314314
assert(type->isMaterializable());
315315

316316
++ArgNo;
317-
if (PD->hasName()) {
317+
if (PD->hasName() || PD->isIsolated()) {
318318
makeArgumentIntoBinding(type, &*f.begin(), PD);
319319
return;
320320
}

0 commit comments

Comments
 (0)