@@ -515,11 +515,14 @@ class LocalVariableInitialization : public SingleBufferInitialization {
515
515
auto instanceType = SGF.SGM .Types .getLoweredRValueType (
516
516
TypeExpansionContext::minimal (), decl->getTypeInContext ());
517
517
518
- // If we have a no implicit copy param decl, make our instance type
519
- // @moveOnly.
520
- if (!instanceType->isNoncopyable ()) {
518
+
519
+ bool isNoImplicitCopy = instanceType->is <SILMoveOnlyWrappedType>();
520
+
521
+ // If our instance type is not already @moveOnly wrapped, and it's a
522
+ // no-implicit-copy parameter, wrap it.
523
+ if (!isNoImplicitCopy && !instanceType->isNoncopyable ()) {
521
524
if (auto *pd = dyn_cast<ParamDecl>(decl)) {
522
- bool isNoImplicitCopy = pd->isNoImplicitCopy ();
525
+ isNoImplicitCopy = pd->isNoImplicitCopy ();
523
526
isNoImplicitCopy |= pd->getSpecifier () == ParamSpecifier::Consuming;
524
527
if (pd->isSelfParameter ()) {
525
528
auto *dc = pd->getDeclContext ();
@@ -533,9 +536,11 @@ class LocalVariableInitialization : public SingleBufferInitialization {
533
536
}
534
537
}
535
538
539
+ const bool isCopyable = isNoImplicitCopy || !instanceType->isNoncopyable ();
540
+
536
541
auto boxType = SGF.SGM .Types .getContextBoxTypeForCapture (
537
542
decl, instanceType, SGF.F .getGenericEnvironment (),
538
- /* mutable*/ !instanceType-> isNoncopyable () || !decl->isLet ());
543
+ /* mutable= */ isCopyable || !decl->isLet ());
539
544
540
545
// The variable may have its lifetime extended by a closure, heap-allocate
541
546
// it using a box.
@@ -689,7 +694,7 @@ class LetValueInitialization : public Initialization {
689
694
// For noncopyable types, we always need to box them.
690
695
needsTemporaryBuffer =
691
696
(lowering->isAddressOnly () && SGF.silConv .useLoweredAddresses ()) ||
692
- lowering->getLoweredType ().getASTType ()-> isNoncopyable ( );
697
+ lowering->getLoweredType ().isMoveOnly ( /* orWrapped= */ false );
693
698
}
694
699
695
700
// Make sure that we have a non-address only type when binding a
@@ -774,7 +779,7 @@ class LetValueInitialization : public Initialization {
774
779
if (value->getOwnershipKind () == OwnershipKind::None) {
775
780
// Then check if we have a pure move only type. In that case, we need to
776
781
// insert a no implicit copy
777
- if (value->getType ().getASTType ()-> isNoncopyable ( )) {
782
+ if (value->getType ().isMoveOnly ( /* orWrapped= */ false )) {
778
783
value = SGF.B .createMoveValue (PrologueLoc, value, /* isLexical*/ true );
779
784
return SGF.B .createMarkUnresolvedNonCopyableValueInst (
780
785
PrologueLoc, value,
@@ -824,7 +829,7 @@ class LetValueInitialization : public Initialization {
824
829
// We do this before the begin_borrow "normal" path below since move only
825
830
// types do not have no implicit copy attr on them.
826
831
if (value->getOwnershipKind () == OwnershipKind::Owned &&
827
- value->getType ().getASTType ()-> isNoncopyable ( )) {
832
+ value->getType ().isMoveOnly ( /* orWrapped= */ false )) {
828
833
value = SGF.B .createMoveValue (PrologueLoc, value, true /* isLexical*/ );
829
834
return SGF.B .createMarkUnresolvedNonCopyableValueInst (
830
835
PrologueLoc, value,
0 commit comments