Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit b669583

Browse files
committed
Merge branch 'main' of github.com:apple/swift into tensorflow-stage
* 'main' of github.com:apple/swift: [test] Mark two SILOptimizer tests requiring asserts [test] Disable IRGen/unmanaged_objc_throw_func.swift with non-optimized stdlib [NFC] Move Migrated SDK Target List into StdlibDeploymentTarget [stdlib] Unbreak unified builds after swiftlang#34859 Update a comment in EscapeAnalysis. [concurrency] IRGen: update task/executor/context on every suspend point [auto-diff] Fix a bunch of places in the *Cloners where we were not closing borrow scopes. [test] Adjusting stdlib ocurrences where class syntax is used for protocol inheritance [test] Adding specific tests for the warning for protocol inheritance class keyword syntax deprecation [test] Adjusting test files where class syntax is used for protocol inheritance [Sema] Adding deprecation warning for protocol inheritance class keyword syntax [stdlib] Simplify buffer pointer initialization. [cxx-interop] Bail on functions that use unimportable types. Sema: Remove a dead param on TypeChecker::conformsToProtocol [CSBinding] Attempt to join any existing and viable bindings with new binding [cmake] Semi-parametrize manpage location.
2 parents f8d4829 + 820b2c6 commit b669583

Some content is hidden

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

46 files changed

+265
-136
lines changed

cmake/modules/SwiftManpage.cmake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,12 @@ function(manpage)
3939
ALL)
4040

4141
add_dependencies(${MP_INSTALL_IN_COMPONENT} ${manpage_target})
42+
set(MANPAGE_DEST "share/")
43+
if("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "OPENBSD")
44+
set(MANPAGE_DEST "")
45+
endif()
4246
swift_install_in_component(FILES "${output_file_name}"
43-
DESTINATION "share/man/man${MP_MAN_SECTION}"
47+
DESTINATION "${MANPAGE_DEST}man/man${MP_MAN_SECTION}"
4448
COMPONENT "${MP_INSTALL_IN_COMPONENT}")
4549
endfunction()
4650

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2616,6 +2616,9 @@ WARNING(duplicate_anyobject_class_inheritance,none,
26162616
"redundant inheritance from 'AnyObject' and Swift 3 'class' keyword", ())
26172617
ERROR(inheritance_from_protocol_with_superclass,none,
26182618
"inheritance from class-constrained protocol composition type %0", (Type))
2619+
WARNING(anyobject_class_inheritance_deprecated,none,
2620+
"using 'class' keyword for protocol inheritance is deprecated; "
2621+
"use 'AnyObject' instead", ())
26192622
ERROR(multiple_inheritance,none,
26202623
"multiple inheritance from classes %0 and %1", (Type, Type))
26212624
ERROR(inheritance_from_non_protocol_or_class,none,

include/swift/Sema/ConstraintSystem.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4706,6 +4706,11 @@ class ConstraintSystem {
47064706
return {type, kind, BindingSource};
47074707
}
47084708

4709+
/// Determine whether this binding could be a viable candidate
4710+
/// to be "joined" with some other binding. It has to be at least
4711+
/// a non-default r-value supertype binding with no type variables.
4712+
bool isViableForJoin() const;
4713+
47094714
static PotentialBinding forHole(TypeVariableType *typeVar,
47104715
ConstraintLocator *locator) {
47114716
return {HoleType::get(typeVar->getASTContext(), typeVar),
@@ -4745,9 +4750,6 @@ class ConstraintSystem {
47454750
/// Whether this type variable has literal bindings.
47464751
LiteralBindingKind LiteralBinding = LiteralBindingKind::None;
47474752

4748-
/// Tracks the position of the last known supertype in the group.
4749-
Optional<unsigned> lastSupertypeIndex;
4750-
47514753
/// A set of all not-yet-resolved type variables this type variable
47524754
/// is a subtype of, supertype of or is equivalent to. This is used
47534755
/// to determine ordering inside of a chain of subtypes to help infer

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3896,6 +3896,10 @@ namespace {
38963896
bodyParams =
38973897
getNonSelfParamList(dc, decl, selfIdx, name.getArgumentNames(),
38983898
allowNSUIntegerAsInt, !name, templateParams);
3899+
// If we can't import a param for some reason (ex. it's a dependent
3900+
// type), bail.
3901+
if (!bodyParams)
3902+
return nullptr;
38993903

39003904
importedType =
39013905
Impl.importFunctionReturnType(dc, decl, allowNSUIntegerAsInt);

lib/IRGen/GenCall.cpp

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -331,25 +331,60 @@ static Alignment getAsyncContextAlignment(IRGenModule &IGM) {
331331
return IGM.getPointerAlignment();
332332
}
333333

334+
void IRGenFunction::setupAsync() {
335+
llvm::Value *t = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Task);
336+
asyncTaskLocation = createAlloca(t->getType(), IGM.getPointerAlignment());
337+
Builder.CreateStore(t, asyncTaskLocation);
338+
339+
llvm::Value *e = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Executor);
340+
asyncExecutorLocation = createAlloca(e->getType(), IGM.getPointerAlignment());
341+
Builder.CreateStore(e, asyncExecutorLocation);
342+
343+
llvm::Value *c = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Context);
344+
asyncContextLocation = createAlloca(c->getType(), IGM.getPointerAlignment());
345+
Builder.CreateStore(c, asyncContextLocation);
346+
}
347+
334348
llvm::Value *IRGenFunction::getAsyncTask() {
335349
assert(isAsync());
336-
auto *value = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Task);
337-
assert(value->getType() == IGM.SwiftTaskPtrTy);
338-
return value;
350+
return Builder.CreateLoad(asyncTaskLocation);
339351
}
340352

341353
llvm::Value *IRGenFunction::getAsyncExecutor() {
342354
assert(isAsync());
343-
auto *value = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Executor);
344-
assert(value->getType() == IGM.SwiftExecutorPtrTy);
345-
return value;
355+
return Builder.CreateLoad(asyncExecutorLocation);
346356
}
347357

348358
llvm::Value *IRGenFunction::getAsyncContext() {
349359
assert(isAsync());
350-
auto *value = CurFn->getArg((unsigned)AsyncFunctionArgumentIndex::Context);
351-
assert(value->getType() == IGM.SwiftContextPtrTy);
352-
return value;
360+
return Builder.CreateLoad(asyncContextLocation);
361+
}
362+
363+
llvm::CallInst *IRGenFunction::emitSuspendAsyncCall(ArrayRef<llvm::Value *> args) {
364+
auto *id =
365+
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async, args);
366+
367+
// Update the current values of task, executor and context.
368+
369+
auto *rawTask = Builder.CreateExtractValue(id,
370+
(unsigned)AsyncFunctionArgumentIndex::Task);
371+
auto *task = Builder.CreateBitCast(rawTask, IGM.SwiftTaskPtrTy);
372+
Builder.CreateStore(task, asyncTaskLocation);
373+
374+
auto *rawExecutor = Builder.CreateExtractValue(id,
375+
(unsigned)AsyncFunctionArgumentIndex::Executor);
376+
auto *executor = Builder.CreateBitCast(rawExecutor, IGM.SwiftExecutorPtrTy);
377+
Builder.CreateStore(executor, asyncExecutorLocation);
378+
379+
auto *calleeContext = Builder.CreateExtractValue(id,
380+
(unsigned)AsyncFunctionArgumentIndex::Context);
381+
llvm::Constant *projectFn = cast<llvm::Constant>(args[1])->stripPointerCasts();
382+
// Get the caller context from the calle context.
383+
llvm::Value *context = Builder.CreateCall(projectFn, {calleeContext});
384+
context = Builder.CreateBitCast(context, IGM.SwiftContextPtrTy);
385+
Builder.CreateStore(context, asyncContextLocation);
386+
387+
return id;
353388
}
354389

355390
llvm::Type *ExplosionSchema::getScalarResultType(IRGenModule &IGM) const {
@@ -2421,9 +2456,7 @@ class AsyncCallEmission final : public CallEmission {
24212456
Builder.CreateBitOrPointerCast(fn.getRawPointer(), IGM.Int8PtrTy));
24222457
for (auto arg: args)
24232458
arguments.push_back(arg);
2424-
auto *id = Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async,
2425-
arguments);
2426-
return id;
2459+
return IGF.emitSuspendAsyncCall(arguments);
24272460
}
24282461
};
24292462

lib/IRGen/GenFunc.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,8 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
13551355
fwd->addAttributes(llvm::AttributeList::FunctionIndex, b);
13561356

13571357
IRGenFunction subIGF(IGM, fwd);
1358-
subIGF.setAsync(origType->isAsync());
1358+
if (origType->isAsync())
1359+
subIGF.setupAsync();
13591360
if (IGM.DebugInfo)
13601361
IGM.DebugInfo->emitArtificialFunction(subIGF, fwd);
13611362

lib/IRGen/GenThunk.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ void IRGenModule::emitDispatchThunk(SILDeclRef declRef) {
144144
}
145145

146146
IRGenFunction IGF(*this, f);
147-
IGF.setAsync(declRef.getAbstractFunctionDecl()->hasAsync());
147+
if (declRef.getAbstractFunctionDecl()->hasAsync())
148+
IGF.setupAsync();
148149

149150
// Look up the method.
150151
auto fn = lookupMethod(IGF, declRef);

lib/IRGen/IRGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ void IRGenFunction::emitAwaitAsyncContinuation(
720720
Builder.CreateBitOrPointerCast(getAsyncExecutor(), IGM.Int8PtrTy));
721721
arguments.push_back(Builder.CreateBitOrPointerCast(
722722
AsyncCoroutineCurrentContinuationContext, IGM.Int8PtrTy));
723-
Builder.CreateIntrinsicCall(llvm::Intrinsic::coro_suspend_async, arguments);
723+
emitSuspendAsyncCall(arguments);
724724

725725
auto results = Builder.CreateAtomicCmpXchg(
726726
contAwaitSyncAddr, null, one,

lib/IRGen/IRGenFunction.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ class IRGenFunction {
132132
llvm::Value *getAsyncExecutor();
133133
llvm::Value *getAsyncContext();
134134

135+
llvm::CallInst *emitSuspendAsyncCall(ArrayRef<llvm::Value *> args);
136+
135137
llvm::Function *getOrCreateResumePrjFn();
136138
llvm::Function *createAsyncDispatchFn(const FunctionPointer &fnPtr,
137139
ArrayRef<llvm::Value *> args);
@@ -162,7 +164,10 @@ class IRGenFunction {
162164
llvm::Value *CoroutineHandle = nullptr;
163165
llvm::Value *AsyncCoroutineCurrentResume = nullptr;
164166
llvm::Value *AsyncCoroutineCurrentContinuationContext = nullptr;
165-
bool IsAsync = false;
167+
168+
Address asyncTaskLocation;
169+
Address asyncExecutorLocation;
170+
Address asyncContextLocation;
166171

167172
/// The unique block that calls @llvm.coro.end.
168173
llvm::BasicBlock *CoroutineExitBlock = nullptr;
@@ -182,8 +187,8 @@ class IRGenFunction {
182187
return getEffectiveOptimizationMode() == OptimizationMode::ForSize;
183188
}
184189

185-
bool isAsync() const { return IsAsync; }
186-
void setAsync(bool async = true) { IsAsync = async; }
190+
void setupAsync();
191+
bool isAsync() const { return asyncTaskLocation.isValid(); }
187192

188193
Address createAlloca(llvm::Type *ty, Alignment align,
189194
const llvm::Twine &name = "");

lib/IRGen/IRGenSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,8 @@ IRGenSILFunction::IRGenSILFunction(IRGenModule &IGM, SILFunction *f)
15041504
IGM.createReplaceableProlog(*this, f);
15051505
}
15061506

1507-
setAsync(f->getLoweredFunctionType()->isAsync());
1507+
if (f->getLoweredFunctionType()->isAsync())
1508+
setupAsync();
15081509
}
15091510

15101511
IRGenSILFunction::~IRGenSILFunction() {

lib/SIL/IR/SILBuilder.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,15 +637,18 @@ DebugValueAddrInst *SILBuilder::createDebugValueAddr(SILLocation Loc,
637637

638638
void SILBuilder::emitScopedBorrowOperation(SILLocation loc, SILValue original,
639639
function_ref<void(SILValue)> &&fun) {
640-
if (original->getType().isAddress()) {
641-
original = createLoadBorrow(loc, original);
640+
SILValue value = original;
641+
if (value->getType().isAddress()) {
642+
value = createLoadBorrow(loc, value);
642643
} else {
643-
original = createBeginBorrow(loc, original);
644+
value = emitBeginBorrowOperation(loc, value);
644645
}
645646

646-
fun(original);
647+
fun(value);
647648

648-
createEndBorrow(loc, original);
649+
// If we actually inserted a borrowing operation... insert the end_borrow.
650+
if (value != original)
651+
createEndBorrow(loc, value);
649652
}
650653

651654
CheckedCastBranchInst *SILBuilder::createCheckedCastBranch(

lib/SILOptimizer/Analysis/EscapeAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,8 @@ void EscapeAnalysis::ConnectionGraph::mergeAllScheduledNodes() {
771771
if (From->mappedValue) {
772772
// values previously mapped to 'From' but not transferred to 'To's
773773
// mappedValue must remain mapped to 'From'. Lookups on those values will
774-
// find 'To' via the mergeTarget. Dropping a value's mapping is illegal
774+
// find 'To' via the mergeTarget and will remap those values to 'To'
775+
// on-the-fly for efficiency. Dropping a value's mapping is illegal
775776
// because it could cause a node to be recreated without the edges that
776777
// have already been discovered.
777778
if (!To->mappedValue) {

lib/SILOptimizer/Differentiation/JVPCloner.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,11 +519,13 @@ class JVPCloner::Implementation final
519519
return;
520520
}
521521
}
522-
auto borrowedDiffFunc = builder.emitBeginBorrowOperation(loc, origCallee);
523-
jvpValue = builder.createDifferentiableFunctionExtract(
524-
loc, NormalDifferentiableFunctionTypeComponent::JVP,
525-
borrowedDiffFunc);
526-
jvpValue = builder.emitCopyValueOperation(loc, jvpValue);
522+
builder.emitScopedBorrowOperation(
523+
loc, origCallee, [&](SILValue borrowedDiffFunc) {
524+
jvpValue = builder.createDifferentiableFunctionExtract(
525+
loc, NormalDifferentiableFunctionTypeComponent::JVP,
526+
borrowedDiffFunc);
527+
jvpValue = builder.emitCopyValueOperation(loc, jvpValue);
528+
});
527529
}
528530

529531
// If JVP has not yet been found, emit an `differentiable_function`
@@ -614,11 +616,13 @@ class JVPCloner::Implementation final
614616
// Record the `differentiable_function` instruction.
615617
context.getDifferentiableFunctionInstWorklist().push_back(diffFuncInst);
616618

617-
auto borrowedADFunc = builder.emitBeginBorrowOperation(loc, diffFuncInst);
618-
auto extractedJVP = builder.createDifferentiableFunctionExtract(
619-
loc, NormalDifferentiableFunctionTypeComponent::JVP, borrowedADFunc);
620-
jvpValue = builder.emitCopyValueOperation(loc, extractedJVP);
621-
builder.emitEndBorrowOperation(loc, borrowedADFunc);
619+
builder.emitScopedBorrowOperation(
620+
loc, diffFuncInst, [&](SILValue borrowedADFunc) {
621+
auto extractedJVP = builder.createDifferentiableFunctionExtract(
622+
loc, NormalDifferentiableFunctionTypeComponent::JVP,
623+
borrowedADFunc);
624+
jvpValue = builder.emitCopyValueOperation(loc, extractedJVP);
625+
});
622626
builder.emitDestroyValueOperation(loc, diffFuncInst);
623627
}
624628

lib/SILOptimizer/Differentiation/VJPCloner.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -495,11 +495,13 @@ class VJPCloner::Implementation final
495495
loc, origCallee, SILType::getPrimitiveObjectType(origFnUnsubstType),
496496
/*withoutActuallyEscaping*/ false);
497497
}
498-
auto borrowedDiffFunc = builder.emitBeginBorrowOperation(loc, origCallee);
499-
vjpValue = builder.createDifferentiableFunctionExtract(
500-
loc, NormalDifferentiableFunctionTypeComponent::VJP,
501-
borrowedDiffFunc);
502-
vjpValue = builder.emitCopyValueOperation(loc, vjpValue);
498+
builder.emitScopedBorrowOperation(
499+
loc, origCallee, [&](SILValue borrowedDiffFunc) {
500+
vjpValue = builder.createDifferentiableFunctionExtract(
501+
loc, NormalDifferentiableFunctionTypeComponent::VJP,
502+
borrowedDiffFunc);
503+
vjpValue = builder.emitCopyValueOperation(loc, vjpValue);
504+
});
503505
auto vjpFnType = vjpValue->getType().castTo<SILFunctionType>();
504506
auto vjpFnUnsubstType = vjpFnType->getUnsubstitutedType(getModule());
505507
if (vjpFnType != vjpFnUnsubstType) {
@@ -601,11 +603,14 @@ class VJPCloner::Implementation final
601603
// Record the `differentiable_function` instruction.
602604
context.getDifferentiableFunctionInstWorklist().push_back(diffFuncInst);
603605

604-
auto borrowedADFunc = builder.emitBeginBorrowOperation(loc, diffFuncInst);
605-
auto extractedVJP = getBuilder().createDifferentiableFunctionExtract(
606-
loc, NormalDifferentiableFunctionTypeComponent::VJP, borrowedADFunc);
607-
vjpValue = builder.emitCopyValueOperation(loc, extractedVJP);
608-
builder.emitEndBorrowOperation(loc, borrowedADFunc);
606+
builder.emitScopedBorrowOperation(
607+
loc, diffFuncInst, [&](SILValue borrowedADFunc) {
608+
auto extractedVJP =
609+
getBuilder().createDifferentiableFunctionExtract(
610+
loc, NormalDifferentiableFunctionTypeComponent::VJP,
611+
borrowedADFunc);
612+
vjpValue = builder.emitCopyValueOperation(loc, extractedVJP);
613+
});
609614
builder.emitDestroyValueOperation(loc, diffFuncInst);
610615
}
611616

lib/Sema/CSBindings.cpp

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,17 @@
2222
using namespace swift;
2323
using namespace constraints;
2424

25+
bool ConstraintSystem::PotentialBinding::isViableForJoin() const {
26+
return Kind == AllowedBindingKind::Supertypes &&
27+
!BindingType->hasLValueType() &&
28+
!BindingType->hasUnresolvedType() &&
29+
!BindingType->hasTypeVariable() &&
30+
!BindingType->hasHole() &&
31+
!BindingType->hasUnboundGenericType() &&
32+
!hasDefaultedLiteralProtocol() &&
33+
!isDefaultableBinding();
34+
}
35+
2536
bool ConstraintSystem::PotentialBindings::isPotentiallyIncomplete() const {
2637
// Generic parameters are always potentially incomplete.
2738
if (isGenericParameter())
@@ -679,30 +690,30 @@ void ConstraintSystem::PotentialBindings::addPotentialBinding(
679690
// If this is a non-defaulted supertype binding,
680691
// check whether we can combine it with another
681692
// supertype binding by computing the 'join' of the types.
682-
if (binding.Kind == AllowedBindingKind::Supertypes &&
683-
!binding.BindingType->hasUnresolvedType() &&
684-
!binding.BindingType->hasTypeVariable() &&
685-
!binding.BindingType->hasHole() &&
686-
!binding.BindingType->hasUnboundGenericType() &&
687-
!binding.hasDefaultedLiteralProtocol() &&
688-
!binding.isDefaultableBinding() && allowJoinMeet) {
689-
if (lastSupertypeIndex) {
690-
auto &lastBinding = Bindings[*lastSupertypeIndex];
691-
auto lastType = lastBinding.BindingType->getWithoutSpecifierType();
692-
auto bindingType = binding.BindingType->getWithoutSpecifierType();
693-
694-
auto join = Type::join(lastType, bindingType);
695-
if (join && !(*join)->isAny() &&
696-
(!(*join)->getOptionalObjectType()
697-
|| !(*join)->getOptionalObjectType()->isAny())) {
698-
// Replace the last supertype binding with the join. We're done.
699-
lastBinding.BindingType = *join;
700-
return;
693+
if (binding.isViableForJoin() && allowJoinMeet) {
694+
bool joined = false;
695+
696+
auto isAcceptableJoin = [](Type type) {
697+
return !type->isAny() && (!type->getOptionalObjectType() ||
698+
!type->getOptionalObjectType()->isAny());
699+
};
700+
701+
for (auto &existingBinding : Bindings) {
702+
if (!existingBinding.isViableForJoin())
703+
continue;
704+
705+
auto join = Type::join(existingBinding.BindingType, binding.BindingType);
706+
707+
if (join && isAcceptableJoin(*join)) {
708+
existingBinding.BindingType = *join;
709+
joined = true;
701710
}
702711
}
703712

704-
// Record this as the most recent supertype index.
705-
lastSupertypeIndex = Bindings.size();
713+
// If new binding has been joined with at least one of existing
714+
// bindings, there is no reason to include it into the set.
715+
if (joined)
716+
return;
706717
}
707718

708719
if (auto *literalProtocol = binding.getDefaultedLiteralProtocol())

0 commit comments

Comments
 (0)