Skip to content

Commit dd12206

Browse files
authored
Merge pull request swiftlang#20626 from slavapestov/more-small-fixes
More small fixes
2 parents 55b176f + 7ffe361 commit dd12206

File tree

13 files changed

+235
-156
lines changed

13 files changed

+235
-156
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,7 @@ class GenericSignatureBuilder {
626626
/// where \c Dictionary requires that its key type be \c Hashable,
627627
/// the requirement \c K : Hashable is inferred from the parameter type,
628628
/// because the type \c Dictionary<K,V> cannot be formed without it.
629-
void inferRequirements(ModuleDecl &module, ParameterList *params,
630-
GenericParamList *genericParams);
629+
void inferRequirements(ModuleDecl &module, ParameterList *params);
631630

632631
/// \brief Finalize the set of requirements and compute the generic
633632
/// signature.

lib/AST/Decl.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5890,9 +5890,14 @@ Type EnumElementDecl::getArgumentInterfaceType() const {
58905890

58915891
auto funcTy = interfaceType->castTo<AnyFunctionType>();
58925892
funcTy = funcTy->getResult()->castTo<FunctionType>();
5893-
return AnyFunctionType::composeInput(funcTy->getASTContext(),
5894-
funcTy->getParams(),
5895-
/*canonicalVararg=*/false);
5893+
5894+
auto &ctx = getASTContext();
5895+
SmallVector<TupleTypeElt, 4> elements;
5896+
for (const auto &param : funcTy->getParams()) {
5897+
Type eltType = param.getParameterType(/*canonicalVararg=*/false, &ctx);
5898+
elements.emplace_back(eltType, param.getLabel());
5899+
}
5900+
return TupleType::get(elements, ctx);
58965901
}
58975902

58985903
EnumCaseDecl *EnumElementDecl::getParentCase() const {

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5458,11 +5458,7 @@ void GenericSignatureBuilder::inferRequirements(
54585458

54595459
void GenericSignatureBuilder::inferRequirements(
54605460
ModuleDecl &module,
5461-
ParameterList *params,
5462-
GenericParamList *genericParams) {
5463-
if (genericParams == nullptr)
5464-
return;
5465-
5461+
ParameterList *params) {
54665462
for (auto P : *params) {
54675463
inferRequirements(module, P->getTypeLoc().getType(),
54685464
P->getTypeLoc().getTypeRepr(),

lib/SILGen/SILGenPattern.cpp

Lines changed: 48 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,41 +1566,42 @@ emitCastOperand(SILGenFunction &SGF, SILLocation loc,
15661566
SGFContext ctx;
15671567
if (requiresAddress) {
15681568
init = SGF.emitTemporary(loc, srcAbstractTL);
1569-
1570-
// Okay, if all we need to do is drop the value in an address,
1571-
// this is easy.
1572-
if (!hasAbstraction) {
1573-
// TODO: Refactor this into a materialize method on CastConsumptionKind.
1574-
ManagedValue finalValue = src.getFinalManagedValue();
1575-
if (finalValue.getOwnershipKind() == ValueOwnershipKind::Guaranteed)
1576-
finalValue = finalValue.copy(SGF, loc);
1577-
SGF.B.emitStoreValueOperation(loc, finalValue.forward(SGF),
1578-
init->getAddress(),
1579-
StoreOwnershipQualifier::Init);
1580-
init->finishInitialization(SGF);
1581-
// If we had borrow_always, we need to switch to copy_on_success since
1582-
// that is the address only variant of borrow_always.
1583-
auto consumption = src.getFinalConsumption();
1584-
if (consumption == CastConsumptionKind::BorrowAlways)
1585-
consumption = CastConsumptionKind::CopyOnSuccess;
1586-
ConsumableManagedValue result = {init->getManagedAddress(), consumption};
1587-
if (ArgUnforwarder::requiresUnforwarding(SGF, src))
1588-
borrowedValues.push_back(result);
1589-
return result;
1590-
}
1591-
15921569
ctx = SGFContext(init.get());
15931570
}
15941571

1595-
assert(hasAbstraction);
1596-
assert(src.getType().isObject() &&
1597-
"address-only type with abstraction difference?");
1598-
1599-
// Produce the value at +1.
16001572
ManagedValue substValue = SGF.getManagedValue(loc, src);
1601-
ManagedValue origValue =
1602-
SGF.emitSubstToOrigValue(loc, substValue, abstraction, sourceType);
1603-
return ConsumableManagedValue::forOwned(origValue);
1573+
ManagedValue finalValue;
1574+
if (hasAbstraction) {
1575+
assert(src.getType().isObject() &&
1576+
"address-only type with abstraction difference?");
1577+
// Produce the value at +1.
1578+
finalValue = SGF.emitSubstToOrigValue(loc, substValue,
1579+
abstraction, sourceType, ctx);
1580+
} else {
1581+
finalValue = substValue;
1582+
}
1583+
1584+
if (requiresAddress) {
1585+
if (finalValue.getOwnershipKind() == ValueOwnershipKind::Guaranteed)
1586+
finalValue = finalValue.copy(SGF, loc);
1587+
SGF.B.emitStoreValueOperation(loc, finalValue.forward(SGF),
1588+
init->getAddress(),
1589+
StoreOwnershipQualifier::Init);
1590+
init->finishInitialization(SGF);
1591+
1592+
// If we had borrow_always, we need to switch to copy_on_success since
1593+
// that is the address only variant of borrow_always.
1594+
auto consumption = src.getFinalConsumption();
1595+
if (consumption == CastConsumptionKind::BorrowAlways)
1596+
consumption = CastConsumptionKind::CopyOnSuccess;
1597+
ConsumableManagedValue result = {init->getManagedAddress(), consumption};
1598+
if (ArgUnforwarder::requiresUnforwarding(SGF, src))
1599+
borrowedValues.push_back(result);
1600+
1601+
return result;
1602+
}
1603+
1604+
return ConsumableManagedValue::forOwned(finalValue);
16041605
}
16051606

16061607
/// Perform specialized dispatch for a sequence of IsPatterns.
@@ -2536,6 +2537,7 @@ class Lowering::PatternMatchContext {
25362537
static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
25372538
SILLocation loc,
25382539
ManagedValue value,
2540+
Type subjectTy,
25392541
const EnumDecl *enumDecl) {
25402542
ASTContext &ctx = SGF.getASTContext();
25412543
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCaseValue(nullptr);
@@ -2549,10 +2551,9 @@ static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
25492551
assert(value.getType().isTrivial(SGF.getModule()));
25502552

25512553
// Get the enum type as an Any.Type value.
2552-
CanType switchedValueSwiftType = value.getType().getASTType();
25532554
SILType metatypeType = SGF.getLoweredType(
2554-
CanMetatypeType::get(switchedValueSwiftType,
2555-
MetatypeRepresentation::Thick));
2555+
AbstractionPattern::getOpaque(),
2556+
MetatypeType::get(subjectTy));
25562557
SILValue metatype = SGF.B.createMetatype(loc, metatypeType);
25572558

25582559
// Bitcast the enum value to its raw type. (This is only safe for @objc
@@ -2573,7 +2574,7 @@ static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
25732574
assert(genericParam->getIndex() < 2);
25742575
switch (genericParam->getIndex()) {
25752576
case 0:
2576-
return switchedValueSwiftType;
2577+
return subjectTy;
25772578

25782579
case 1:
25792580
return enumDecl->getRawType();
@@ -2592,7 +2593,8 @@ static void emitDiagnoseOfUnexpectedEnumCaseValue(SILGenFunction &SGF,
25922593

25932594
static void emitDiagnoseOfUnexpectedEnumCase(SILGenFunction &SGF,
25942595
SILLocation loc,
2595-
ManagedValue value) {
2596+
ManagedValue value,
2597+
Type subjectTy) {
25962598
ASTContext &ctx = SGF.getASTContext();
25972599
auto diagnoseFailure = ctx.getDiagnoseUnexpectedEnumCase(nullptr);
25982600
if (!diagnoseFailure) {
@@ -2601,16 +2603,15 @@ static void emitDiagnoseOfUnexpectedEnumCase(SILGenFunction &SGF,
26012603
}
26022604

26032605
// Get the switched-upon value's type.
2604-
CanType switchedValueSwiftType = value.getType().getASTType();
26052606
SILType metatypeType = SGF.getLoweredType(
2606-
CanMetatypeType::get(switchedValueSwiftType,
2607-
MetatypeRepresentation::Thick));
2607+
AbstractionPattern::getOpaque(),
2608+
MetatypeType::get(subjectTy)->getCanonicalType());
26082609
ManagedValue metatype = SGF.B.createValueMetatype(loc, metatypeType, value);
26092610

26102611
auto diagnoseSignature = diagnoseFailure->getGenericSignature();
26112612
auto genericArgsMap = SubstitutionMap::get(
26122613
diagnoseSignature,
2613-
[&](SubstitutableType *type) -> Type { return switchedValueSwiftType; },
2614+
[&](SubstitutableType *type) -> Type { return subjectTy; },
26142615
LookUpConformanceInSignature(*diagnoseSignature));
26152616

26162617
SGF.emitApplyOfLibraryIntrinsic(loc, diagnoseFailure, genericArgsMap,
@@ -2622,9 +2623,12 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
26222623
LLVM_DEBUG(llvm::dbgs() << "emitting switch stmt\n";
26232624
S->dump(llvm::dbgs());
26242625
llvm::dbgs() << '\n');
2626+
2627+
auto subjectTy = S->getSubjectExpr()->getType();
2628+
26252629
// If the subject expression is uninhabited, we're already dead.
26262630
// Emit an unreachable in place of the switch statement.
2627-
if (S->getSubjectExpr()->getType()->isStructurallyUninhabited()) {
2631+
if (subjectTy->isStructurallyUninhabited()) {
26282632
emitIgnoredExpr(S->getSubjectExpr());
26292633
B.createUnreachable(S);
26302634
return;
@@ -2789,12 +2793,13 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
27892793
if (singleEnumDecl->isObjC()) {
27902794
emitDiagnoseOfUnexpectedEnumCaseValue(*this, location,
27912795
subject.getFinalManagedValue(),
2792-
singleEnumDecl);
2796+
subjectTy, singleEnumDecl);
27932797
return;
27942798
}
27952799
}
27962800
emitDiagnoseOfUnexpectedEnumCase(*this, location,
2797-
subject.getFinalManagedValue());
2801+
subject.getFinalManagedValue(),
2802+
subjectTy);
27982803
};
27992804

28002805
// Set up an initial clause matrix.

0 commit comments

Comments
 (0)