Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
14f5c6f
5.6: Fix SR-15785 by adding a cached reference to the last linked lis…
Catfish-Man Feb 3, 2022
f3401cc
[SE-0338] Contexts with the same actor isolation never execute concur…
DougGregor Mar 5, 2022
04d62c5
Fixup for the 5.6 branch
DougGregor Mar 22, 2022
882dc9e
Ensure that we print @Sendable when printing TypeReprs.
DougGregor Mar 10, 2022
dd1d29a
Ensure that we don't emit references to marker protocols in existenti…
DougGregor Mar 4, 2022
026a7a0
[test] Disable marker_protocol_backdeploy.swift on arm
hamishknight Mar 8, 2022
3c4e0d3
Ensure that emit unnamed isolated parameters
DougGregor Mar 10, 2022
403ec1b
[Concurrency] Have StackAllocator gracefully fail when passed a small…
mikeash Mar 18, 2022
5c37bff
backtrack on part of SE-327 dealing with default-value exprs
kavon Mar 19, 2022
58a549f
GSB: Try to avoid calling Type::subst() from expandConformanceRequire…
slavapestov Dec 14, 2021
99b445a
RequirementMachine: Narrow fix for concrete type requirements with op…
slavapestov Mar 23, 2022
f1224fd
Merge pull request #41972 from slavapestov/fix-rdar90665615-5.6
slavapestov Mar 23, 2022
ce8ad52
Merge pull request #41968 from slavapestov/fix-rdar90666408-5.6
slavapestov Mar 23, 2022
b2a2a76
Merge pull request #41955 from DougGregor/fix-async-let-stackallocato…
DougGregor Mar 23, 2022
4b7e5e5
Merge pull request #41951 from DougGregor/unnamed-isolated-params-5.6
DougGregor Mar 23, 2022
0128989
Merge pull request #41950 from DougGregor/existential-marker-protocol…
DougGregor Mar 23, 2022
b9f6709
Merge pull request #41949 from DougGregor/print-sendable-typerepr-5.6
DougGregor Mar 23, 2022
ef7e22c
Merge pull request #41923 from DougGregor/isolated-match-may-not-exec…
DougGregor Mar 23, 2022
fa6b731
[MiscDiagnostics] Produce warnings about confusable `self` iff its ex…
xedin Mar 23, 2022
7c5b1aa
Merge pull request #41967 from kavon/5.6-backtrack-defaultvalue-warning
DougGregor Mar 23, 2022
5420863
Merge pull request #41192 from Catfish-Man/linked-lost-5.6
DougGregor Mar 23, 2022
08de3f7
Merge pull request #41980 from xedin/rdar-90666315-5.6
xedin Mar 24, 2022
14d1b96
[NFC] Cherry-pick a test fix for new SDK on CI system
cachemeifyoucan Mar 3, 2022
4e118a1
Merge pull request #42027 from cachemeifyoucan/eng/PR-90821341
cachemeifyoucan Mar 26, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions include/swift/ABI/TaskStatus.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,14 +164,21 @@ class ChildTaskStatusRecord : public TaskStatusRecord {
/// and are only tracked by their respective `TaskGroupTaskStatusRecord`.
class TaskGroupTaskStatusRecord : public TaskStatusRecord {
AsyncTask *FirstChild;
AsyncTask *LastChild;

public:
TaskGroupTaskStatusRecord()
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(nullptr) {
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
FirstChild(nullptr),
LastChild(nullptr) {
}

TaskGroupTaskStatusRecord(AsyncTask *child)
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup), FirstChild(child) {}
: TaskStatusRecord(TaskStatusRecordKind::TaskGroup),
FirstChild(child),
LastChild(child) {
assert(!LastChild || !LastChild->childFragment()->getNextChild());
}

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

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

auto oldLastChild = LastChild;
LastChild = child;

if (!FirstChild) {
// This is the first child we ever attach, so store it as FirstChild.
FirstChild = child;
return;
}

// We need to traverse the siblings to find the last one and add the child
// there.
// FIXME: just set prepend to the current head, no need to traverse.

auto cur = FirstChild;
while (cur) {
// no need to check hasChildFragment, all tasks we store here have them.
auto fragment = cur->childFragment();
if (auto next = fragment->getNextChild()) {
cur = next;
} else {
// we're done searching and `cur` is the last
break;
}
}

cur->childFragment()->setNextChild(child);
oldLastChild->childFragment()->setNextChild(child);
}

void detachChild(AsyncTask *child) {
assert(child && "cannot remove a null child from group");
if (FirstChild == child) {
FirstChild = getNextChildTask(child);
if (FirstChild == nullptr) {
LastChild = nullptr;
}
return;
}

AsyncTask *prev = FirstChild;
// Remove the child from the linked list, i.e.:
// prev -> afterPrev -> afterChild
Expand All @@ -230,6 +227,9 @@ class TaskGroupTaskStatusRecord : public TaskStatusRecord {
if (afterPrev == child) {
auto afterChild = getNextChildTask(child);
prev->childFragment()->setNextChild(afterChild);
if (child == LastChild) {
LastChild = prev;
}
return;
}

Expand Down
14 changes: 14 additions & 0 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ class ActorIsolation {

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

bool isActorIsolated() const {
switch (getKind()) {
case ActorInstance:
case DistributedActorInstance:
case GlobalActor:
case GlobalActorUnsafe:
return true;

case Unspecified:
case Independent:
return false;
}
}

NominalTypeDecl *getActor() const {
assert(getKind() == ActorInstance || getKind() == DistributedActorInstance);
return actor;
Expand Down
4 changes: 0 additions & 4 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -4475,10 +4475,6 @@ ERROR(global_actor_from_nonactor_context,none,
"%0 %1 isolated to global actor %2 can not be %select{referenced|mutated|used 'inout'}4"
" from %select{this|a non-isolated}3%select{| synchronous}5 context",
(DescriptiveDeclKind, DeclName, Type, bool, unsigned, bool))
ERROR(global_actor_from_initializing_expr,none,
"expression requiring global actor %0 cannot appear in "
"default-value expression of %1 %2",
(Type, DescriptiveDeclKind, DeclName))
ERROR(actor_isolated_call,none,
"call to %0 function in a synchronous %1 context",
(ActorIsolation, ActorIsolation))
Expand Down
19 changes: 2 additions & 17 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8667,24 +8667,9 @@ ActorIsolation swift::getActorIsolationOfContext(DeclContext *dc) {
if (auto *vd = dyn_cast_or_null<ValueDecl>(dc->getAsDecl()))
return getActorIsolation(vd);

// In the context of the initializing or default-value expression of a
// stored property, the isolation varies between global and type members:
// - For a static stored property, the isolation matches the VarDecl.
// - For a field of a nominal type, the expression is not isolated.
// Without this distinction, a nominal can have non-async initializers
// with various kinds of isolation, so an impossible constraint can be
// created. See SE-0327 for details.
if (auto *var = dc->getNonLocalVarDecl()) {

// Isolation officially changes, as described above, in Swift 6+
if (dc->getASTContext().isSwiftVersionAtLeast(6) &&
var->isInstanceMember() &&
!var->getAttrs().hasAttribute<LazyAttr>()) {
return ActorIsolation::forUnspecified();
}

if (auto *var = dc->getNonLocalVarDecl())
return getActorIsolation(var);
}


if (auto *closure = dyn_cast<AbstractClosureExpr>(dc)) {
switch (auto isolation = closure->getActorIsolation()) {
Expand Down
48 changes: 25 additions & 23 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3988,8 +3988,16 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
ProtocolDecl *proto,
const RequirementSource *source,
bool onlySameTypeConstraints) {
auto protocolSubMap = SubstitutionMap::getProtocolSubstitutions(
proto, selfType.getDependentType(*this), ProtocolConformanceRef(proto));
auto selfTy = selfType.getDependentType(*this);

auto subst = [&](Requirement req) -> Optional<Requirement> {
return req.subst(
[&](SubstitutableType *t) -> Type {
assert(isa<GenericTypeParamType>(t));
return selfTy;
},
MakeAbstractConformanceForGenericType());
};

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

auto substReq = req.subst(protocolSubMap);
auto substReq = subst(req);
auto reqResult = substReq
? addRequirement(*substReq, innerSource, nullptr)
: ConstraintResult::Conflicting;
Expand Down Expand Up @@ -4032,8 +4040,9 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(

auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
source, proto, reqRepr->getSeparatorLoc(), /*inferred=*/false);
addRequirement(req, reqRepr, innerSource,
&protocolSubMap, nullptr);

if (auto substReq = subst(req))
addRequirement(*substReq, reqRepr, innerSource, nullptr);
return false;
});

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

auto rawReq = Requirement(RequirementKind::SameType, firstType, secondType);
if (auto req = rawReq.subst(protocolSubMap))
if (auto req = subst(rawReq))
addRequirement(*req, inferredSameTypeSource, proto->getParentModule());
};

Expand Down Expand Up @@ -4174,8 +4183,10 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(

auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
source, proto, reqRepr->getSeparatorLoc(), /*inferred=*/false);
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
/*inferForModule=*/nullptr);
if (auto substReq = subst(req)) {
addRequirement(*substReq, reqRepr, innerSource,
/*inferForModule=*/nullptr);
}
return false;
});

Expand Down Expand Up @@ -5160,28 +5171,19 @@ ConstraintResult
GenericSignatureBuilder::addRequirement(const Requirement &req,
FloatingRequirementSource source,
ModuleDecl *inferForModule) {
return addRequirement(req, nullptr, source, nullptr, inferForModule);
return addRequirement(req, nullptr, source, inferForModule);
}

ConstraintResult
GenericSignatureBuilder::addRequirement(const Requirement &req,
const RequirementRepr *reqRepr,
FloatingRequirementSource source,
const SubstitutionMap *subMap,
ModuleDecl *inferForModule) {
// Local substitution for types in the requirement.
auto subst = [&](Type t) {
if (subMap)
return t.subst(*subMap);

return t;
};

auto firstType = subst(req.getFirstType());
auto firstType = req.getFirstType();
switch (req.getKind()) {
case RequirementKind::Superclass:
case RequirementKind::Conformance: {
auto secondType = subst(req.getSecondType());
auto secondType = req.getSecondType();

if (inferForModule) {
inferRequirements(*inferForModule, firstType,
Expand Down Expand Up @@ -5209,7 +5211,7 @@ GenericSignatureBuilder::addRequirement(const Requirement &req,
}

case RequirementKind::SameType: {
auto secondType = subst(req.getSecondType());
auto secondType = req.getSecondType();

if (inferForModule) {
inferRequirements(*inferForModule, firstType,
Expand Down Expand Up @@ -8697,8 +8699,8 @@ InferredGenericSignatureRequest::evaluate(
}
}

builder.addRequirement(req, reqRepr, source, nullptr,
lookupDC->getParentModule());
builder.addRequirement(req, reqRepr, source,
lookupDC->getParentModule());
return false;
};

Expand Down
1 change: 0 additions & 1 deletion lib/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ class GenericSignatureBuilder {
ConstraintResult addRequirement(const Requirement &req,
const RequirementRepr *reqRepr,
FloatingRequirementSource source,
const SubstitutionMap *subMap,
ModuleDecl *inferForModule);

/// Add all of a generic signature's parameters and requirements.
Expand Down
6 changes: 3 additions & 3 deletions lib/AST/RequirementMachine/PropertyUnification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,9 +491,9 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
continue;
}

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

auto *concrete = conformance.getConcrete();

Expand Down
2 changes: 2 additions & 0 deletions lib/AST/TypeRepr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,8 @@ void AttributedTypeRepr::printAttrs(ASTPrinter &Printer,
Printer.printSimpleAttr("@autoclosure") << " ";
if (hasAttr(TAK_escaping))
Printer.printSimpleAttr("@escaping") << " ";
if (hasAttr(TAK_Sendable))
Printer.printSimpleAttr("@Sendable") << " ";
if (hasAttr(TAK_noDerivative))
Printer.printSimpleAttr("@noDerivative") << " ";

Expand Down
8 changes: 6 additions & 2 deletions lib/IRGen/MetadataRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,8 +1670,12 @@ namespace {
}

auto layout = type.getExistentialLayout();

auto protocols = layout.getProtocols();

SmallVector<ProtocolType *, 4> protocols;
for (auto proto : layout.getProtocols()) {
if (!proto->getDecl()->isMarkerProtocol())
protocols.push_back(proto);
}

// Collect references to the protocol descriptors.
auto descriptorArrayTy
Expand Down
2 changes: 1 addition & 1 deletion lib/SILGen/SILGenProlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ struct ArgumentInitHelper {
assert(type->isMaterializable());

++ArgNo;
if (PD->hasName()) {
if (PD->hasName() || PD->isIsolated()) {
makeArgumentIntoBinding(type, &*f.begin(), PD);
return;
}
Expand Down
58 changes: 35 additions & 23 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4717,31 +4717,43 @@ static void diagUnqualifiedAccessToMethodNamedSelf(const Expr *E,
if (!E || isa<ErrorExpr>(E) || !E->getType())
return {false, E};

if (auto *declRefExpr = dyn_cast<DeclRefExpr>(E)) {
if (declRefExpr->getDecl()->getBaseName() == Ctx.Id_self &&
declRefExpr->getType()->is<AnyFunctionType>()) {
if (auto typeContext = DC->getInnermostTypeContext()) {
// self() is not easily confusable
if (!isa<CallExpr>(Parent.getAsExpr())) {
auto baseType = typeContext->getDeclaredInterfaceType();
if (!baseType->getEnumOrBoundGenericEnum()) {
auto baseTypeString = baseType.getString();

Ctx.Diags.diagnose(E->getLoc(), diag::self_refers_to_method,
baseTypeString);

Ctx.Diags
.diagnose(E->getLoc(),
diag::fix_unqualified_access_member_named_self,
baseTypeString)
.fixItInsert(E->getLoc(), diag::insert_type_qualification,
baseType);
}
}
}
}
auto *DRE = dyn_cast<DeclRefExpr>(E);
// If this is not an explicit 'self' reference, let's keep searching.
if (!DRE || DRE->isImplicit())
return {true, E};

// If this not 'self' or it's not a function reference, it's unrelated.
if (!(DRE->getDecl()->getBaseName() == Ctx.Id_self &&
DRE->getType()->is<AnyFunctionType>()))
return {true, E};

auto typeContext = DC->getInnermostTypeContext();
// Use of 'self' in enums is not confusable.
if (!typeContext || typeContext->getSelfEnumDecl())
return {true, E};

// self(...) is not easily confusable.
if (auto *parentExpr = Parent.getAsExpr()) {
if (isa<CallExpr>(parentExpr))
return {true, E};

// Explicit call to a static method 'self' of some type is not
// confusable.
if (isa<DotSyntaxCallExpr>(parentExpr) && !parentExpr->isImplicit())
return {true, E};
}

auto baseType = typeContext->getDeclaredInterfaceType();
auto baseTypeString = baseType.getString();

Ctx.Diags.diagnose(E->getLoc(), diag::self_refers_to_method,
baseTypeString);

Ctx.Diags
.diagnose(E->getLoc(), diag::fix_unqualified_access_member_named_self,
baseTypeString)
.fixItInsert(E->getLoc(), diag::insert_type_qualification, baseType);

return {true, E};
}
};
Expand Down
Loading