@@ -103,10 +103,12 @@ bool swift::ArraySemanticsCall::isValidSignature() {
103
103
}
104
104
case ArrayCallKind::kCheckSubscript : {
105
105
// Int, Bool, Self
106
- if (SemanticsCall->getNumArguments () != 3 ||
107
- !SemanticsCall->getArgument (0 )->getType ().isTrivial (*F))
106
+ unsigned numArgs = SemanticsCall->getNumArguments ();
107
+ if (numArgs != 2 && numArgs != 3 )
108
+ return false ;
109
+ if (!SemanticsCall->getArgument (0 )->getType ().isTrivial (*F))
108
110
return false ;
109
- if (!SemanticsCall->getArgument (1 )->getType ().isTrivial (*F))
111
+ if (numArgs == 3 && !SemanticsCall->getArgument (1 )->getType ().isTrivial (*F))
110
112
return false ;
111
113
auto SelfConvention = FnTy->getSelfParameter ().getConvention ();
112
114
return SelfConvention == ParameterConvention::Direct_Guaranteed ||
@@ -326,23 +328,22 @@ bool swift::ArraySemanticsCall::canHoist(SILInstruction *InsertBefore,
326
328
// Not implemented yet.
327
329
return false ;
328
330
329
- case ArrayCallKind::kCheckSubscript : {
330
- auto IsNativeArg = getArrayPropertyIsNativeTypeChecked ();
331
- ArraySemanticsCall IsNative (IsNativeArg,
332
- " array.props.isNativeTypeChecked" , true );
333
- if (!IsNative) {
334
- // Do we have a constant parameter?
335
- auto *SI = dyn_cast<StructInst>(IsNativeArg);
336
- if (!SI)
337
- return false ;
338
- if (!isa<IntegerLiteralInst>(SI->getOperand (0 )))
331
+ case ArrayCallKind::kCheckSubscript :
332
+ if (SILValue IsNativeArg = getArrayPropertyIsNativeTypeChecked ()) {
333
+ ArraySemanticsCall IsNative (IsNativeArg,
334
+ " array.props.isNativeTypeChecked" , true );
335
+ if (!IsNative) {
336
+ // Do we have a constant parameter?
337
+ auto *SI = dyn_cast<StructInst>(IsNativeArg);
338
+ if (!SI)
339
+ return false ;
340
+ if (!isa<IntegerLiteralInst>(SI->getOperand (0 )))
341
+ return false ;
342
+ } else if (!IsNative.canHoist (InsertBefore, DT))
343
+ // Otherwise, we must be able to hoist the function call.
339
344
return false ;
340
- } else if (!IsNative.canHoist (InsertBefore, DT))
341
- // Otherwise, we must be able to hoist the function call.
342
- return false ;
343
-
345
+ }
344
346
return canHoistArrayArgument (SemanticsCall, getSelf (), InsertBefore, DT);
345
- }
346
347
347
348
case ArrayCallKind::kMakeMutable :
348
349
case ArrayCallKind::kEndMutation :
@@ -450,9 +451,8 @@ ApplyInst *swift::ArraySemanticsCall::hoistOrCopy(SILInstruction *InsertBefore,
450
451
hoistOrCopySelf (SemanticsCall, InsertBefore, DT, LeaveOriginal);
451
452
452
453
SILValue NewArrayProps;
453
- if (Kind == ArrayCallKind:: kCheckSubscript ) {
454
+ if (SILValue IsNativeArg = getArrayPropertyIsNativeTypeChecked () ) {
454
455
// Copy the array.props argument call.
455
- auto IsNativeArg = getArrayPropertyIsNativeTypeChecked ();
456
456
ArraySemanticsCall IsNative (IsNativeArg,
457
457
" array.props.isNativeTypeChecked" , true );
458
458
if (!IsNative) {
@@ -517,14 +517,15 @@ void swift::ArraySemanticsCall::removeCall() {
517
517
518
518
switch (getKind ()) {
519
519
default : break ;
520
- case ArrayCallKind::kCheckSubscript : {
521
- // Remove all uses with the empty tuple ().
522
- auto EmptyDep = SILBuilderWithScope (SemanticsCall)
523
- .createStruct (SemanticsCall->getLoc (),
524
- SemanticsCall->getType (), {});
525
- SemanticsCall->replaceAllUsesWith (EmptyDep);
526
- }
527
- break ;
520
+ case ArrayCallKind::kCheckSubscript :
521
+ if (!SemanticsCall->getType ().isVoid ()){
522
+ // Remove all uses with the empty tuple ().
523
+ auto EmptyDep = SILBuilderWithScope (SemanticsCall)
524
+ .createStruct (SemanticsCall->getLoc (),
525
+ SemanticsCall->getType (), {});
526
+ SemanticsCall->replaceAllUsesWith (EmptyDep);
527
+ }
528
+ break ;
528
529
case ArrayCallKind::kGetElement : {
529
530
// Remove the matching isNativeTypeChecked and check_subscript call.
530
531
ArraySemanticsCall IsNative (getTypeCheckedArgument (),
@@ -554,11 +555,13 @@ SILValue
554
555
swift::ArraySemanticsCall::getArrayPropertyIsNativeTypeChecked () const {
555
556
switch (getKind ()) {
556
557
case ArrayCallKind::kCheckSubscript :
557
- return SemanticsCall->getArgument (1 );
558
+ if (SemanticsCall->getNumArguments () == 3 )
559
+ return SemanticsCall->getArgument (1 );
560
+ return SILValue ();
558
561
case ArrayCallKind::kGetElement :
559
562
return getTypeCheckedArgument ();
560
563
default :
561
- llvm_unreachable ( " Must have an array.props argument " );
564
+ return SILValue ( );
562
565
}
563
566
}
564
567
0 commit comments