Skip to content

Commit a20d8f5

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition
2 parents 79ab080 + 9e1684a commit a20d8f5

11 files changed

+72
-93
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3288,7 +3288,7 @@ void RewriteTreeNode::mergeIntoRec(
32883288
for (auto child : children)
32893289
child->mergeIntoRec(other, matchPath);
32903290

3291-
if (auto assocType = getMatch())
3291+
if (getMatch())
32923292
matchPath.pop_back();
32933293
}
32943294

@@ -3646,8 +3646,6 @@ static Type substituteConcreteType(GenericSignatureBuilder &builder,
36463646
proto, parentType, ProtocolConformanceRef(proto));
36473647

36483648
type = type.subst(subMap, SubstFlags::UseErrorType);
3649-
if (!type)
3650-
return ErrorType::get(proto->getASTContext());
36513649
} else {
36523650
// Substitute in the superclass type.
36533651
auto superclass = basePA->getEquivalenceClassIfPresent()->superclass;

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4024,7 +4024,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
40244024
}
40254025

40264026
return getPositionInTupleExpr(DC, CCExpr, tuple, Position, HasName);
4027-
} else if (auto *paren = dyn_cast<ParenExpr>(CallE->getArg())) {
4027+
} else if (isa<ParenExpr>(CallE->getArg())) {
40284028
HasName = false;
40294029
Position = 0;
40304030
return true;

lib/IRGen/LoadableByAddress.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static bool containsFunctionSignature(GenericEnvironment *genEnv,
123123
if (auto optionalObject = objectType.getOptionalObjectType()) {
124124
objectType = optionalObject;
125125
}
126-
if (auto fnType = objectType.getAs<SILFunctionType>()) {
126+
if (objectType.is<SILFunctionType>()) {
127127
return true;
128128
}
129129
}

lib/SIL/InstructionUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ FindClosureResult swift::findClosureForAppliedArg(SILValue V) {
537537
if (auto *bbi = dyn_cast<BeginBorrowInst>(V))
538538
V = bbi->getOperand();
539539

540-
if (auto optionalObjTy = V->getType().getOptionalObjectType())
540+
if (V->getType().getOptionalObjectType())
541541
V = cast<EnumInst>(V)->getOperand();
542542

543543
auto fnType = V->getType().getAs<SILFunctionType>();

lib/SILGen/SILGenBuilder.cpp

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -519,18 +519,56 @@ ManagedValue SILGenBuilder::createLoadCopy(SILLocation loc, ManagedValue v,
519519
return SGF.emitManagedRValueWithCleanup(result, lowering);
520520
}
521521

522-
ManagedValue SILGenBuilder::createFunctionArgument(SILType type,
523-
ValueDecl *decl) {
524-
SILFunction &F = getFunction();
525-
526-
SILFunctionArgument *arg = F.begin()->createFunctionArgument(type, decl);
527-
if (arg->getType().isObject()) {
528-
if (arg->getOwnershipKind().isTrivialOr(ValueOwnershipKind::Owned))
529-
return SGF.emitManagedRValueWithCleanup(arg);
530-
return ManagedValue::forBorrowedRValue(arg);
522+
static ManagedValue createInputFunctionArgument(SILGenBuilder &B, SILType type,
523+
SILLocation loc,
524+
ValueDecl *decl = nullptr) {
525+
auto &SGF = B.getSILGenFunction();
526+
SILFunction &F = B.getFunction();
527+
assert((F.isBare() || decl) &&
528+
"Function arguments of non-bare functions must have a decl");
529+
auto *arg = F.begin()->createFunctionArgument(type, decl);
530+
switch (arg->getArgumentConvention()) {
531+
case SILArgumentConvention::Indirect_In_Guaranteed:
532+
case SILArgumentConvention::Direct_Guaranteed:
533+
// Guaranteed parameters are passed at +0.
534+
return ManagedValue::forUnmanaged(arg);
535+
case SILArgumentConvention::Direct_Unowned:
536+
// Unowned parameters are only guaranteed at the instant of the call, so we
537+
// must retain them even if we're in a context that can accept a +0 value.
538+
return ManagedValue::forUnmanaged(arg).copy(SGF, loc);
539+
540+
case SILArgumentConvention::Direct_Owned:
541+
return SGF.emitManagedRValueWithCleanup(arg);
542+
543+
case SILArgumentConvention::Indirect_In:
544+
if (SGF.silConv.useLoweredAddresses())
545+
return SGF.emitManagedBufferWithCleanup(arg);
546+
return SGF.emitManagedRValueWithCleanup(arg);
547+
548+
case SILArgumentConvention::Indirect_Inout:
549+
case SILArgumentConvention::Indirect_InoutAliasable:
550+
// An inout parameter is +0 and guaranteed, but represents an lvalue.
551+
return ManagedValue::forLValue(arg);
552+
case SILArgumentConvention::Indirect_In_Constant:
553+
llvm_unreachable("Convention not produced by SILGen");
554+
case SILArgumentConvention::Direct_Deallocating:
555+
case SILArgumentConvention::Indirect_Out:
556+
llvm_unreachable("unsupported convention for API");
531557
}
558+
llvm_unreachable("bad parameter convention");
559+
}
560+
561+
ManagedValue SILGenBuilder::createInputFunctionArgument(SILType type,
562+
ValueDecl *decl) {
563+
return ::createInputFunctionArgument(*this, type, SILLocation(decl), decl);
564+
}
532565

533-
return SGF.emitManagedBufferWithCleanup(arg);
566+
ManagedValue
567+
SILGenBuilder::createInputFunctionArgument(SILType type,
568+
Optional<SILLocation> inputLoc) {
569+
assert(inputLoc.hasValue() && "This optional is only for overload resolution "
570+
"purposes! Do not pass in None here!");
571+
return ::createInputFunctionArgument(*this, type, *inputLoc);
534572
}
535573

536574
ManagedValue

lib/SILGen/SILGenBuilder.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,20 @@ class SILGenBuilder : public SILBuilder {
255255
ManagedValue createLoadCopy(SILLocation loc, ManagedValue addr,
256256
const TypeLowering &lowering);
257257

258-
ManagedValue createFunctionArgument(SILType type, ValueDecl *decl);
258+
/// Create a SILArgument for an input parameter. Asserts if used to create a
259+
/// function argument for an out parameter.
260+
ManagedValue createInputFunctionArgument(SILType type, ValueDecl *decl);
261+
262+
/// Create a SILArgument for an input parameter. Uses \p loc to create any
263+
/// copies necessary. Asserts if used to create a function argument for an out
264+
/// parameter.
265+
///
266+
/// *NOTE* This API purposely used an Optional<SILLocation> to distinguish
267+
/// this API from the ValueDecl * API in C++. This is necessary since
268+
/// ValueDecl * can implicitly convert to SILLocation. The optional forces the
269+
/// user to be explicit that they want to use this API.
270+
ManagedValue createInputFunctionArgument(SILType type,
271+
Optional<SILLocation> loc);
259272

260273
using SILBuilder::createEnum;
261274
ManagedValue createEnum(SILLocation loc, ManagedValue payload,

lib/SILGen/SILGenConstructor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
598598
ctor->hasThrows());
599599

600600
SILType selfTy = getLoweredLoadableType(selfDecl->getType());
601-
ManagedValue selfArg = B.createFunctionArgument(selfTy, selfDecl);
601+
ManagedValue selfArg = B.createInputFunctionArgument(selfTy, selfDecl);
602602

603603
if (!NeedsBoxForSelf) {
604604
SILLocation PrologueLoc(selfDecl);

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -785,40 +785,6 @@ ManagedValue Transform::transformTuple(ManagedValue inputTuple,
785785
return SGF.emitManagedRValueWithCleanup(outputTuple, outputTL);
786786
}
787787

788-
static ManagedValue manageParam(SILGenFunction &SGF,
789-
SILLocation loc,
790-
SILValue paramValue,
791-
SILParameterInfo info) {
792-
switch (info.getConvention()) {
793-
case ParameterConvention::Indirect_In_Guaranteed:
794-
if (SGF.silConv.useLoweredAddresses())
795-
return ManagedValue::forUnmanaged(paramValue);
796-
LLVM_FALLTHROUGH;
797-
case ParameterConvention::Direct_Guaranteed:
798-
return SGF.emitManagedBeginBorrow(loc, paramValue);
799-
// Unowned parameters are only guaranteed at the instant of the call, so we
800-
// must retain them even if we're in a context that can accept a +0 value.
801-
case ParameterConvention::Direct_Unowned:
802-
paramValue = SGF.getTypeLowering(paramValue->getType())
803-
.emitCopyValue(SGF.B, loc, paramValue);
804-
LLVM_FALLTHROUGH;
805-
case ParameterConvention::Direct_Owned:
806-
return SGF.emitManagedRValueWithCleanup(paramValue);
807-
808-
case ParameterConvention::Indirect_In:
809-
if (SGF.silConv.useLoweredAddresses())
810-
return SGF.emitManagedBufferWithCleanup(paramValue);
811-
return SGF.emitManagedRValueWithCleanup(paramValue);
812-
813-
case ParameterConvention::Indirect_Inout:
814-
case ParameterConvention::Indirect_InoutAliasable:
815-
return ManagedValue::forLValue(paramValue);
816-
case ParameterConvention::Indirect_In_Constant:
817-
break;
818-
}
819-
llvm_unreachable("bad parameter convention");
820-
}
821-
822788
void SILGenFunction::collectThunkParams(
823789
SILLocation loc, SmallVectorImpl<ManagedValue> &params,
824790
SmallVectorImpl<SILArgument *> *indirectResults) {
@@ -834,9 +800,7 @@ void SILGenFunction::collectThunkParams(
834800
auto paramTypes = F.getLoweredFunctionType()->getParameters();
835801
for (auto param : paramTypes) {
836802
auto paramTy = F.mapTypeIntoContext(F.getConventions().getSILType(param));
837-
auto paramValue = F.begin()->createFunctionArgument(paramTy);
838-
auto paramMV = manageParam(*this, loc, paramValue, param);
839-
params.push_back(paramMV);
803+
params.push_back(B.createInputFunctionArgument(paramTy, loc));
840804
}
841805
}
842806

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -92,39 +92,6 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
9292
: SGF(sgf), parent(parent), loc(l), functionArgs(functionArgs),
9393
parameters(parameters) {}
9494

95-
ManagedValue getManagedValue(SILValue arg, CanType t,
96-
SILParameterInfo parameterInfo) const {
97-
switch (parameterInfo.getConvention()) {
98-
case ParameterConvention::Direct_Guaranteed:
99-
case ParameterConvention::Indirect_In_Guaranteed:
100-
// If we have a guaranteed parameter, it is passed in at +0, and its
101-
// lifetime is guaranteed. We can potentially use the argument as-is
102-
// if the parameter is bound as a 'let' without cleaning up.
103-
return ManagedValue::forUnmanaged(arg);
104-
105-
case ParameterConvention::Direct_Unowned:
106-
// An unowned parameter is passed at +0, like guaranteed, but it isn't
107-
// kept alive by the caller, so we need to retain and manage it
108-
// regardless.
109-
return SGF.emitManagedRetain(loc, arg);
110-
111-
case ParameterConvention::Indirect_Inout:
112-
case ParameterConvention::Indirect_InoutAliasable:
113-
// An inout parameter is +0 and guaranteed, but represents an lvalue.
114-
return ManagedValue::forLValue(arg);
115-
116-
case ParameterConvention::Direct_Owned:
117-
case ParameterConvention::Indirect_In:
118-
// An owned or 'in' parameter is passed in at +1. We can claim ownership
119-
// of the parameter and clean it up when it goes out of scope.
120-
return SGF.emitManagedRValueWithCleanup(arg);
121-
122-
case ParameterConvention::Indirect_In_Constant:
123-
break;
124-
}
125-
llvm_unreachable("bad parameter convention");
126-
}
127-
12895
ManagedValue visitType(CanType t) {
12996
auto argType = SGF.getLoweredType(t);
13097
// Pop the next parameter info.
@@ -136,9 +103,8 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
136103
SGF.getSILType(parameterInfo))
137104
&& "argument does not have same type as specified by parameter info");
138105

139-
SILValue arg =
140-
parent->createFunctionArgument(argType, loc.getAsASTNode<ValueDecl>());
141-
ManagedValue mv = getManagedValue(arg, t, parameterInfo);
106+
ManagedValue mv = SGF.B.createInputFunctionArgument(
107+
argType, loc.getAsASTNode<ValueDecl>());
142108

143109
// If the value is a (possibly optional) ObjC block passed into the entry
144110
// point of the function, then copy it so we can treat the value reliably

lib/SILGen/SILGenThunk.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ void SILGenFunction::emitCurryThunk(SILDeclRef thunk) {
152152
->getInput();
153153
selfTy = vd->getInnermostDeclContext()->mapTypeIntoContext(selfTy);
154154
ManagedValue selfArg =
155-
B.createFunctionArgument(getLoweredType(selfTy), nullptr);
155+
B.createInputFunctionArgument(getLoweredType(selfTy), SILLocation(vd));
156156

157157
// Forward substitutions.
158158
auto subs = F.getForwardingSubstitutions();

lib/SILOptimizer/Mandatory/DiagnoseStaticExclusivity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ static void checkNoEscapePartialApply(PartialApplyInst *PAI) {
10411041
uses.append(EI->getUses().begin(), EI->getUses().end());
10421042
continue;
10431043
}
1044-
if (auto apply = isa<ApplySite>(user)) {
1044+
if (isa<ApplySite>(user)) {
10451045
SILValue arg = oper->get();
10461046
auto ArgumentFnType = getSILFunctionTypeForValue(arg);
10471047
if (ArgumentFnType && ArgumentFnType->isNoEscape()) {

0 commit comments

Comments
 (0)