Skip to content

Commit 4873245

Browse files
Merge pull request #5170 from swiftwasm/katei/merge-main-2023-01-11
Merge main 2023-01-11
2 parents 49f10c2 + 397c18b commit 4873245

14 files changed

+264
-71
lines changed

lib/SIL/Utils/FieldSensitivePrunedLiveness.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
781781
LLVM_DEBUG(llvm::dbgs() << "Has multiple defs!\n");
782782

783783
// Handle a live-out or live-within block with potentially multiple defs
784-
// unsigned prevCount = boundary.getNumLastUsersAndDeadDefs(bitNo);
784+
unsigned prevCount = boundary.getNumLastUsersAndDeadDefs(bitNo);
785785
bool isLive = isLiveOut;
786786
for (auto &inst : llvm::reverse(*block)) {
787787
LLVM_DEBUG(llvm::dbgs() << "Visiting: " << inst);
@@ -861,6 +861,7 @@ void FieldSensitiveMultiDefPrunedLiveRange::findBoundariesInBlock(
861861
<< " Live at beginning of block! No dead args!\n");
862862
}
863863

864-
// assert(prevCount < boundary.getNumLastUsersAndDeadDefs(bitNo) &&
865-
// "findBoundariesInBlock must be called on a live block");
864+
assert((isLiveOut ||
865+
prevCount < boundary.getNumLastUsersAndDeadDefs(bitNo)) &&
866+
"findBoundariesInBlock must be called on a live block");
866867
}

lib/SIL/Utils/PrunedLiveness.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,8 +578,15 @@ void MultiDefPrunedLiveness::findBoundariesInBlock(
578578
boundary.deadDefs.push_back(deadArg);
579579
}
580580
}
581+
if (auto *predBB = block->getSinglePredecessorBlock()) {
582+
if (getBlockLiveness(predBB) == PrunedLiveBlocks::LiveOut) {
583+
boundary.boundaryEdges.push_back(block);
584+
}
585+
}
581586
}
582-
assert(prevCount < boundary.deadDefs.size() + boundary.lastUsers.size()
587+
// All live-within blocks must contain a boundary.
588+
assert(isLiveOut
589+
|| (prevCount < boundary.deadDefs.size() + boundary.lastUsers.size())
583590
&& "findBoundariesInBlock must be called on a live block");
584591
}
585592

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,34 +3586,6 @@ bool ExprAvailabilityWalker::diagnoseDeclRefAvailability(
35863586
static bool
35873587
diagnoseDeclAsyncAvailability(const ValueDecl *D, SourceRange R,
35883588
const Expr *call, const ExportContext &Where) {
3589-
// FIXME: I don't think this is right, but I don't understand the issue well
3590-
// enough to fix it properly. If the decl context is an abstract
3591-
// closure, we need it to have a type assigned to it before we can
3592-
// determine whether it is an asynchronous context. It will crash
3593-
// when we go to check without one. In TypeChecker::typeCheckExpression
3594-
// (TypeCheckConstraints.cpp:403), we apply a solution before calling
3595-
// `performSyntacticDiagnosticsForTarget`, which eventually calls
3596-
// down to this function. Under most circumstances, the context that
3597-
// we're in is typechecked at that point and has a type assigned.
3598-
// When working with specific result builders, the solution applied
3599-
// results in an expression with an unset type. In these cases, the
3600-
// application makes its way into `ConstraintSystem::applySolution` for
3601-
// closures (CSClosure.cpp:1356). The type is computed, but is
3602-
// squirreled away in the constrain system to be applied once the
3603-
// checks (including this one) approve of the decls within the decl
3604-
// context before applying the type to the expression. It might be
3605-
// possible to drive the constraint solver through the availability
3606-
// checker and into us so that we can ask for it, but that feels wrong
3607-
// too.
3608-
// This behavior is demonstrated by the first use of the `tuplify`
3609-
// function in `testExistingPatternsInCaseStatements` in
3610-
// `test/Constraints/result_builder.swift`.
3611-
const AbstractClosureExpr *declCtxAsExpr =
3612-
dyn_cast<AbstractClosureExpr>(Where.getDeclContext());
3613-
if (declCtxAsExpr && !declCtxAsExpr->getType()) {
3614-
return false;
3615-
}
3616-
36173589
// If we are in a synchronous context, don't check it
36183590
if (!Where.getDeclContext()->isAsyncContext())
36193591
return false;

lib/Sema/TypeCheckRuntimeMetadataAttr.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,20 +283,25 @@ Expr *SynthesizeRuntimeMetadataAttrGenerator::evaluate(
283283
initArgument = keyPath;
284284
}
285285

286-
auto reprRange = SourceRange();
287-
if (auto *repr = attr->getTypeRepr())
288-
reprRange = repr->getSourceRange();
286+
SourceRange sourceRange;
287+
if (auto *repr = attr->getTypeRepr()) {
288+
sourceRange = repr->getSourceRange();
289+
} else {
290+
sourceRange = SourceRange(
291+
attachedTo->getAttributeInsertionLoc(/*forModifier=*/false));
292+
}
289293

290-
auto typeExpr = TypeExpr::createImplicitHack(reprRange.Start, attrType, ctx);
294+
auto typeExpr =
295+
TypeExpr::createImplicitHack(sourceRange.Start, attrType, ctx);
291296

292297
// Add the initializer argument at the front of the argument list
293298
SmallVector<Argument, 4> newArgs;
294299
newArgs.push_back({/*loc=*/SourceLoc(), ctx.Id_attachedTo, initArgument});
295300
if (auto *attrArgs = attr->getArgs())
296301
newArgs.append(attrArgs->begin(), attrArgs->end());
297302

298-
ArgumentList *argList = ArgumentList::createImplicit(ctx, reprRange.Start,
299-
newArgs, reprRange.End);
303+
ArgumentList *argList = ArgumentList::createImplicit(
304+
ctx, sourceRange.Start, newArgs, sourceRange.End);
300305
Expr *init = CallExpr::createImplicit(ctx, typeExpr, argList);
301306

302307
// result of generator is an optional always.

stdlib/public/BackDeployConcurrency/TaskCancellation.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ public func withTaskCancellationHandler<T>(
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
defer { _taskRemoveCancellationHandler(record: record) }
50-
51-
return try await operation()
49+
do {
50+
let result = try await operation()
51+
_taskRemoveCancellationHandler(record: record)
52+
return result
53+
} catch {
54+
_taskRemoveCancellationHandler(record: record)
55+
throw error
56+
}
5257
}
5358

5459
@available(SwiftStdlib 5.1, *)

stdlib/public/BackDeployConcurrency/TaskLocal.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
145145
_checkIllegalTaskLocalBindingWithinWithTaskGroup(file: file, line: line)
146146

147147
_taskLocalValuePush(key: key, value: valueDuringOperation)
148-
defer { _taskLocalValuePop() }
149-
150-
return try await operation()
148+
do {
149+
let result = try await operation()
150+
_taskLocalValuePop()
151+
return result
152+
} catch {
153+
_taskLocalValuePop()
154+
throw error
155+
}
151156
}
152157

153158
/// Binds the task-local to the specific value for the duration of the

stdlib/public/Concurrency/TaskCancellation.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,14 @@ public func withTaskCancellationHandler<T>(
4646
// unconditionally add the cancellation record to the task.
4747
// if the task was already cancelled, it will be executed right away.
4848
let record = _taskAddCancellationHandler(handler: handler)
49-
defer { _taskRemoveCancellationHandler(record: record) }
50-
51-
return try await operation()
49+
do {
50+
let result = try await operation()
51+
_taskRemoveCancellationHandler(record: record)
52+
return result
53+
} catch {
54+
_taskRemoveCancellationHandler(record: record)
55+
throw error
56+
}
5257
}
5358

5459
@available(SwiftStdlib 5.1, *)

stdlib/public/Concurrency/TaskLocal.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,14 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
145145
_checkIllegalTaskLocalBindingWithinWithTaskGroup(file: file, line: line)
146146

147147
_taskLocalValuePush(key: key, value: valueDuringOperation)
148-
defer { _taskLocalValuePop() }
149-
150-
return try await operation()
148+
do {
149+
let result = try await operation()
150+
_taskLocalValuePop()
151+
return result
152+
} catch {
153+
_taskLocalValuePop()
154+
throw error
155+
}
151156
}
152157

153158
/// Binds the task-local to the specific value for the duration of the

stdlib/public/core/Macros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
#if hasAttribute(expression)
13+
#if compiler(>=5.8) && hasAttribute(expression)
1414
/// Specifies the module and type name for an externally-defined macro, which
1515
/// must conform to the appropriate set of `Macro` protocols.
1616
///
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@runtimeMetadata
2+
public struct Ignore {
3+
public init<T>(attachedTo: T,
4+
fileID: String = #fileID,
5+
line: Int = #line,
6+
column: Int = #column) {}
7+
}
8+
9+
@Ignore
10+
public protocol Ignorable {}

0 commit comments

Comments
 (0)