Skip to content

Commit 8be3f22

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents f2e7ba8 + 0937c90 commit 8be3f22

File tree

125 files changed

+983
-877
lines changed

Some content is hidden

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

125 files changed

+983
-877
lines changed

include/swift/SIL/DynamicCasts.h

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -329,76 +329,73 @@ struct SILDynamicCastInst {
329329
llvm_unreachable("covered switch");
330330
}
331331

332-
CanType getSourceType() const {
332+
CanType getSourceFormalType() const {
333333
switch (getKind()) {
334334
case SILDynamicCastKind::CheckedCastAddrBranchInst:
335-
return cast<CheckedCastAddrBranchInst>(inst)->getSourceType();
335+
return cast<CheckedCastAddrBranchInst>(inst)->getSourceFormalType();
336336
case SILDynamicCastKind::CheckedCastBranchInst:
337-
return cast<CheckedCastBranchInst>(inst)->getSourceType();
337+
return cast<CheckedCastBranchInst>(inst)->getSourceFormalType();
338338
case SILDynamicCastKind::CheckedCastValueBranchInst:
339-
return cast<CheckedCastValueBranchInst>(inst)->getSourceType();
339+
return cast<CheckedCastValueBranchInst>(inst)->getSourceFormalType();
340340
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst:
341-
return cast<UnconditionalCheckedCastAddrInst>(inst)->getSourceType();
341+
return cast<UnconditionalCheckedCastAddrInst>(inst)->getSourceFormalType();
342342
case SILDynamicCastKind::UnconditionalCheckedCastInst:
343-
return cast<UnconditionalCheckedCastInst>(inst)->getSourceType();
343+
return cast<UnconditionalCheckedCastInst>(inst)->getSourceFormalType();
344344
case SILDynamicCastKind::UnconditionalCheckedCastValueInst:
345-
llvm_unreachable("unsupported");
345+
return cast<UnconditionalCheckedCastValueInst>(inst)->getSourceFormalType();
346346
}
347347
llvm_unreachable("covered switch");
348348
}
349349

350-
SILType getLoweredSourceType() const {
350+
SILType getSourceLoweredType() const {
351351
switch (getKind()) {
352352
case SILDynamicCastKind::CheckedCastAddrBranchInst:
353+
return cast<CheckedCastAddrBranchInst>(inst)->getSourceLoweredType();
353354
case SILDynamicCastKind::CheckedCastBranchInst:
355+
return cast<CheckedCastBranchInst>(inst)->getSourceLoweredType();
354356
case SILDynamicCastKind::CheckedCastValueBranchInst:
355-
llvm_unreachable("unsupported");
356-
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst: {
357-
auto *uccai = cast<UnconditionalCheckedCastAddrInst>(inst);
358-
return uccai->getSrc()->getType();
359-
}
357+
return cast<CheckedCastValueBranchInst>(inst)->getSourceLoweredType();
358+
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst:
359+
return cast<UnconditionalCheckedCastAddrInst>(inst)->getSourceLoweredType();
360360
case SILDynamicCastKind::UnconditionalCheckedCastInst:
361-
return cast<UnconditionalCheckedCastInst>(inst)->getOperand()->getType();
361+
return cast<UnconditionalCheckedCastInst>(inst)->getSourceLoweredType();
362362
case SILDynamicCastKind::UnconditionalCheckedCastValueInst:
363-
llvm_unreachable("unsupported");
363+
return cast<UnconditionalCheckedCastValueInst>(inst)->getSourceLoweredType();
364364
}
365365
}
366366

367-
CanType getTargetType() const {
367+
CanType getTargetFormalType() const {
368368
switch (getKind()) {
369369
case SILDynamicCastKind::CheckedCastAddrBranchInst:
370-
return cast<CheckedCastAddrBranchInst>(inst)->getTargetType();
370+
return cast<CheckedCastAddrBranchInst>(inst)->getTargetFormalType();
371371
case SILDynamicCastKind::CheckedCastBranchInst:
372-
return cast<CheckedCastBranchInst>(inst)->getTargetType();
372+
return cast<CheckedCastBranchInst>(inst)->getTargetFormalType();
373373
case SILDynamicCastKind::CheckedCastValueBranchInst:
374-
return cast<CheckedCastValueBranchInst>(inst)->getTargetType();
374+
return cast<CheckedCastValueBranchInst>(inst)->getTargetFormalType();
375375
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst:
376-
return cast<UnconditionalCheckedCastAddrInst>(inst)->getTargetType();
376+
return cast<UnconditionalCheckedCastAddrInst>(inst)->getTargetFormalType();
377377
case SILDynamicCastKind::UnconditionalCheckedCastInst:
378-
return cast<UnconditionalCheckedCastInst>(inst)->getTargetType();
378+
return cast<UnconditionalCheckedCastInst>(inst)->getTargetFormalType();
379379
case SILDynamicCastKind::UnconditionalCheckedCastValueInst:
380-
llvm_unreachable("unimplemented");
380+
return cast<UnconditionalCheckedCastValueInst>(inst)->getTargetFormalType();
381381
}
382382
llvm_unreachable("covered switch");
383383
}
384384

385-
SILType getLoweredTargetType() const {
385+
SILType getTargetLoweredType() const {
386386
switch (getKind()) {
387387
case SILDynamicCastKind::CheckedCastAddrBranchInst:
388-
llvm_unreachable("unsupported");
388+
return cast<CheckedCastAddrBranchInst>(inst)->getDest()->getType();
389389
case SILDynamicCastKind::CheckedCastBranchInst:
390-
return cast<CheckedCastBranchInst>(inst)->getCastType();
390+
return cast<CheckedCastBranchInst>(inst)->getTargetLoweredType();
391391
case SILDynamicCastKind::CheckedCastValueBranchInst:
392-
return cast<CheckedCastValueBranchInst>(inst)->getCastType();
393-
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst: {
394-
auto *uccai = dyn_cast<UnconditionalCheckedCastAddrInst>(inst);
395-
return uccai->getDest()->getType();
396-
}
397-
case SILDynamicCastKind::UnconditionalCheckedCastInst: {
398-
return cast<UnconditionalCheckedCastInst>(inst)->getType();
399-
}
392+
return cast<CheckedCastValueBranchInst>(inst)->getTargetLoweredType();
393+
case SILDynamicCastKind::UnconditionalCheckedCastAddrInst:
394+
return cast<UnconditionalCheckedCastAddrInst>(inst)->getDest()->getType();
395+
case SILDynamicCastKind::UnconditionalCheckedCastInst:
396+
return cast<UnconditionalCheckedCastInst>(inst)->getTargetLoweredType();
400397
case SILDynamicCastKind::UnconditionalCheckedCastValueInst:
401-
llvm_unreachable("unsupported");
398+
return cast<UnconditionalCheckedCastValueInst>(inst)->getTargetLoweredType();
402399
}
403400
llvm_unreachable("covered switch");
404401
}
@@ -424,14 +421,15 @@ struct SILDynamicCastInst {
424421

425422
DynamicCastFeasibility classifyFeasibility(bool allowWholeModule) const {
426423
return swift::classifyDynamicCast(
427-
getModule().getSwiftModule(), getSourceType(), getTargetType(),
424+
getModule().getSwiftModule(),
425+
getSourceFormalType(), getTargetFormalType(),
428426
isSourceTypeExact(), allowWholeModule && getModule().isWholeModule());
429427
}
430428

431429
bool isBridgingCast() const {
432430
// Bridging casts cannot be further simplified.
433-
auto TargetIsBridgeable = getTargetType()->isBridgeableObjectType();
434-
auto SourceIsBridgeable = getSourceType()->isBridgeableObjectType();
431+
auto TargetIsBridgeable = getTargetFormalType()->isBridgeableObjectType();
432+
auto SourceIsBridgeable = getSourceFormalType()->isBridgeableObjectType();
435433
return TargetIsBridgeable != SourceIsBridgeable;
436434
}
437435

@@ -441,7 +439,7 @@ struct SILDynamicCastInst {
441439
CanType getBridgedSourceType() const {
442440
SILModule &mod = getModule();
443441
Type t = mod.getASTContext().getBridgedToObjC(mod.getSwiftModule(),
444-
getSourceType());
442+
getSourceFormalType());
445443
if (!t)
446444
return CanType();
447445
return t->getCanonicalType();
@@ -453,7 +451,7 @@ struct SILDynamicCastInst {
453451
CanType getBridgedTargetType() const {
454452
SILModule &mod = getModule();
455453
Type t = mod.getASTContext().getBridgedToObjC(mod.getSwiftModule(),
456-
getTargetType());
454+
getTargetFormalType());
457455
if (!t)
458456
return CanType();
459457
return t->getCanonicalType();
@@ -491,7 +489,7 @@ struct SILDynamicCastInst {
491489

492490
bool canUseScalarCheckedCastInstructions() const {
493491
return swift::canUseScalarCheckedCastInstructions(
494-
getModule(), getSourceType(), getTargetType());
492+
getModule(), getSourceFormalType(), getTargetFormalType());
495493
}
496494
};
497495

include/swift/SIL/SILBuilder.h

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,12 @@ class SILBuilder {
10251025
}
10261026

10271027
UncheckedRefCastAddrInst *
1028-
createUncheckedRefCastAddr(SILLocation Loc, SILValue src, CanType sourceType,
1029-
SILValue dest, CanType targetType) {
1028+
createUncheckedRefCastAddr(SILLocation Loc,
1029+
SILValue src, CanType sourceFormalType,
1030+
SILValue dest, CanType targetFormalType) {
10301031
return insert(new (getModule()) UncheckedRefCastAddrInst(
1031-
getSILDebugLocation(Loc), src, sourceType, dest, targetType));
1032+
getSILDebugLocation(Loc), src, sourceFormalType,
1033+
dest, targetFormalType));
10321034
}
10331035

10341036
UncheckedAddrCastInst *createUncheckedAddrCast(SILLocation Loc, SILValue Op,
@@ -1135,26 +1137,32 @@ class SILBuilder {
11351137
}
11361138

11371139
UnconditionalCheckedCastInst *
1138-
createUnconditionalCheckedCast(SILLocation Loc, SILValue op, SILType destTy) {
1140+
createUnconditionalCheckedCast(SILLocation Loc, SILValue op,
1141+
SILType destLoweredTy,
1142+
CanType destFormalTy) {
11391143
return insert(UnconditionalCheckedCastInst::create(
1140-
getSILDebugLocation(Loc), op, destTy, getFunction(),
1141-
C.OpenedArchetypes));
1144+
getSILDebugLocation(Loc), op, destLoweredTy, destFormalTy,
1145+
getFunction(), C.OpenedArchetypes));
11421146
}
11431147

11441148
UnconditionalCheckedCastAddrInst *
1145-
createUnconditionalCheckedCastAddr(SILLocation Loc, SILValue src,
1146-
CanType sourceType, SILValue dest,
1147-
CanType targetType) {
1149+
createUnconditionalCheckedCastAddr(SILLocation Loc,
1150+
SILValue src, CanType sourceFormalType,
1151+
SILValue dest, CanType targetFormalType) {
11481152
return insert(new (getModule()) UnconditionalCheckedCastAddrInst(
1149-
getSILDebugLocation(Loc), src, sourceType, dest, targetType));
1153+
getSILDebugLocation(Loc), src, sourceFormalType,
1154+
dest, targetFormalType));
11501155
}
11511156

11521157
UnconditionalCheckedCastValueInst *
11531158
createUnconditionalCheckedCastValue(SILLocation Loc,
1154-
SILValue op, SILType destTy) {
1159+
SILValue op, CanType srcFormalTy,
1160+
SILType destLoweredTy,
1161+
CanType destFormalTy) {
11551162
return insert(UnconditionalCheckedCastValueInst::create(
1156-
getSILDebugLocation(Loc), op, destTy, getFunction(),
1157-
C.OpenedArchetypes));
1163+
getSILDebugLocation(Loc), op, srcFormalTy,
1164+
destLoweredTy, destFormalTy,
1165+
getFunction(), C.OpenedArchetypes));
11581166
}
11591167

11601168
RetainValueInst *createRetainValue(SILLocation Loc, SILValue operand,
@@ -1957,30 +1965,36 @@ class SILBuilder {
19571965

19581966
CheckedCastBranchInst *
19591967
createCheckedCastBranch(SILLocation Loc, bool isExact, SILValue op,
1960-
SILType destTy, SILBasicBlock *successBB,
1968+
SILType destLoweredTy, CanType destFormalTy,
1969+
SILBasicBlock *successBB,
19611970
SILBasicBlock *failureBB,
19621971
ProfileCounter Target1Count = ProfileCounter(),
19631972
ProfileCounter Target2Count = ProfileCounter());
19641973

19651974
CheckedCastValueBranchInst *
1966-
createCheckedCastValueBranch(SILLocation Loc, SILValue op, SILType destTy,
1975+
createCheckedCastValueBranch(SILLocation Loc,
1976+
SILValue op, CanType srcFormalTy,
1977+
SILType destLoweredTy,
1978+
CanType destFormalTy,
19671979
SILBasicBlock *successBB,
19681980
SILBasicBlock *failureBB) {
19691981
return insertTerminator(CheckedCastValueBranchInst::create(
1970-
getSILDebugLocation(Loc), op, destTy, successBB, failureBB,
1971-
getFunction(), C.OpenedArchetypes));
1982+
getSILDebugLocation(Loc), op, srcFormalTy,
1983+
destLoweredTy, destFormalTy,
1984+
successBB, failureBB, getFunction(), C.OpenedArchetypes));
19721985
}
19731986

19741987
CheckedCastAddrBranchInst *
19751988
createCheckedCastAddrBranch(SILLocation Loc, CastConsumptionKind consumption,
1976-
SILValue src, CanType sourceType, SILValue dest,
1977-
CanType targetType, SILBasicBlock *successBB,
1989+
SILValue src, CanType sourceFormalType,
1990+
SILValue dest, CanType targetFormalType,
1991+
SILBasicBlock *successBB,
19781992
SILBasicBlock *failureBB,
19791993
ProfileCounter Target1Count = ProfileCounter(),
19801994
ProfileCounter Target2Count = ProfileCounter()) {
19811995
return insertTerminator(new (getModule()) CheckedCastAddrBranchInst(
1982-
getSILDebugLocation(Loc), consumption, src, sourceType, dest,
1983-
targetType, successBB, failureBB, Target1Count, Target2Count));
1996+
getSILDebugLocation(Loc), consumption, src, sourceFormalType, dest,
1997+
targetFormalType, successBB, failureBB, Target1Count, Target2Count));
19841998
}
19851999

19862000
//===--------------------------------------------------------------------===//

include/swift/SIL/SILCloner.h

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,8 +1487,8 @@ visitUncheckedRefCastAddrInst(UncheckedRefCastAddrInst *Inst) {
14871487
SILLocation OpLoc = getOpLocation(Inst->getLoc());
14881488
SILValue SrcValue = getOpValue(Inst->getSrc());
14891489
SILValue DestValue = getOpValue(Inst->getDest());
1490-
CanType SrcType = getOpASTType(Inst->getSourceType());
1491-
CanType TargetType = getOpASTType(Inst->getTargetType());
1490+
CanType SrcType = getOpASTType(Inst->getSourceFormalType());
1491+
CanType TargetType = getOpASTType(Inst->getTargetFormalType());
14921492
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
14931493
recordClonedInstruction(
14941494
Inst, getBuilder().createUncheckedRefCastAddr(OpLoc, SrcValue, SrcType,
@@ -1629,10 +1629,12 @@ SILCloner<ImplClass>::visitUnconditionalCheckedCastInst(
16291629
UnconditionalCheckedCastInst *Inst) {
16301630
SILLocation OpLoc = getOpLocation(Inst->getLoc());
16311631
SILValue OpValue = getOpValue(Inst->getOperand());
1632-
SILType OpType = getOpType(Inst->getType());
1632+
SILType OpLoweredType = getOpType(Inst->getTargetLoweredType());
1633+
CanType OpFormalType = getOpASTType(Inst->getTargetFormalType());
16331634
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16341635
recordClonedInstruction(Inst, getBuilder().createUnconditionalCheckedCast(
1635-
OpLoc, OpValue, OpType));
1636+
OpLoc, OpValue,
1637+
OpLoweredType, OpFormalType));
16361638
}
16371639

16381640
template<typename ImplClass>
@@ -1642,8 +1644,8 @@ SILCloner<ImplClass>::visitUnconditionalCheckedCastAddrInst(
16421644
SILLocation OpLoc = getOpLocation(Inst->getLoc());
16431645
SILValue SrcValue = getOpValue(Inst->getSrc());
16441646
SILValue DestValue = getOpValue(Inst->getDest());
1645-
CanType SrcType = getOpASTType(Inst->getSourceType());
1646-
CanType TargetType = getOpASTType(Inst->getTargetType());
1647+
CanType SrcType = getOpASTType(Inst->getSourceFormalType());
1648+
CanType TargetType = getOpASTType(Inst->getTargetFormalType());
16471649
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16481650
recordClonedInstruction(Inst,
16491651
getBuilder().createUnconditionalCheckedCastAddr(
@@ -1655,11 +1657,17 @@ void SILCloner<ImplClass>::visitUnconditionalCheckedCastValueInst(
16551657
UnconditionalCheckedCastValueInst *Inst) {
16561658
SILLocation OpLoc = getOpLocation(Inst->getLoc());
16571659
SILValue OpValue = getOpValue(Inst->getOperand());
1658-
SILType OpType = getOpType(Inst->getType());
1660+
CanType SrcFormalType = getOpASTType(Inst->getSourceFormalType());
1661+
SILType OpLoweredType = getOpType(Inst->getTargetLoweredType());
1662+
CanType OpFormalType = getOpASTType(Inst->getTargetFormalType());
16591663
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
16601664
recordClonedInstruction(
16611665
Inst,
1662-
getBuilder().createUnconditionalCheckedCastValue(OpLoc, OpValue, OpType));
1666+
getBuilder().createUnconditionalCheckedCastValue(OpLoc,
1667+
OpValue,
1668+
SrcFormalType,
1669+
OpLoweredType,
1670+
OpFormalType));
16631671
}
16641672

16651673
template <typename ImplClass>
@@ -2590,7 +2598,9 @@ SILCloner<ImplClass>::visitCheckedCastBranchInst(CheckedCastBranchInst *Inst) {
25902598
recordClonedInstruction(
25912599
Inst, getBuilder().createCheckedCastBranch(
25922600
getOpLocation(Inst->getLoc()), Inst->isExact(),
2593-
getOpValue(Inst->getOperand()), getOpType(Inst->getCastType()),
2601+
getOpValue(Inst->getOperand()),
2602+
getOpType(Inst->getTargetLoweredType()),
2603+
getOpASTType(Inst->getTargetFormalType()),
25942604
OpSuccBB, OpFailBB, TrueCount, FalseCount));
25952605
}
25962606

@@ -2602,8 +2612,12 @@ void SILCloner<ImplClass>::visitCheckedCastValueBranchInst(
26022612
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
26032613
recordClonedInstruction(
26042614
Inst, getBuilder().createCheckedCastValueBranch(
2605-
getOpLocation(Inst->getLoc()), getOpValue(Inst->getOperand()),
2606-
getOpType(Inst->getCastType()), OpSuccBB, OpFailBB));
2615+
getOpLocation(Inst->getLoc()),
2616+
getOpValue(Inst->getOperand()),
2617+
getOpASTType(Inst->getSourceFormalType()),
2618+
getOpType(Inst->getTargetLoweredType()),
2619+
getOpASTType(Inst->getTargetFormalType()),
2620+
OpSuccBB, OpFailBB));
26072621
}
26082622

26092623
template<typename ImplClass>
@@ -2613,8 +2627,8 @@ void SILCloner<ImplClass>::visitCheckedCastAddrBranchInst(
26132627
SILBasicBlock *OpFailBB = getOpBasicBlock(Inst->getFailureBB());
26142628
SILValue SrcValue = getOpValue(Inst->getSrc());
26152629
SILValue DestValue = getOpValue(Inst->getDest());
2616-
CanType SrcType = getOpASTType(Inst->getSourceType());
2617-
CanType TargetType = getOpASTType(Inst->getTargetType());
2630+
CanType SrcType = getOpASTType(Inst->getSourceFormalType());
2631+
CanType TargetType = getOpASTType(Inst->getTargetFormalType());
26182632
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
26192633
auto TrueCount = Inst->getTrueBBCount();
26202634
auto FalseCount = Inst->getFalseBBCount();

0 commit comments

Comments
 (0)