@@ -631,23 +631,23 @@ class ArgumentInitHelper {
631
631
}
632
632
633
633
void updateArgumentValueForBinding (ManagedValue argrv, SILLocation loc,
634
- ParamDecl *pd, SILValue value,
634
+ ParamDecl *pd,
635
635
const SILDebugVariable &varinfo) {
636
636
bool calledCompletedUpdate = false ;
637
637
SWIFT_DEFER {
638
638
assert (calledCompletedUpdate && " Forgot to call completed update along "
639
639
" all paths or manually turn it off" );
640
640
};
641
- auto completeUpdate = [&](SILValue value) -> void {
642
- SGF.B .createDebugValue (loc, value, varinfo);
643
- SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (value);
641
+ auto completeUpdate = [&](ManagedValue value) -> void {
642
+ SGF.B .createDebugValue (loc, value. getValue () , varinfo);
643
+ SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (value. getValue () );
644
644
calledCompletedUpdate = true ;
645
645
};
646
646
647
647
// If we do not need to support lexical lifetimes, just return value as the
648
648
// updated value.
649
649
if (!SGF.getASTContext ().SILOpts .supportsLexicalLifetimes (SGF.getModule ()))
650
- return completeUpdate (value );
650
+ return completeUpdate (argrv );
651
651
652
652
// Look for the following annotations on the function argument:
653
653
// - @noImplicitCopy
@@ -659,15 +659,15 @@ class ArgumentInitHelper {
659
659
// we need to use copyable to move only to convert it to its move only
660
660
// form.
661
661
if (!isNoImplicitCopy) {
662
- if (!value-> getType ().isMoveOnly ()) {
662
+ if (!argrv. getType ().isMoveOnly ()) {
663
663
// Follow the normal path. The value's lifetime will be enforced based
664
664
// on its ownership.
665
- return completeUpdate (value );
665
+ return completeUpdate (argrv );
666
666
}
667
667
668
668
// At this point, we have a noncopyable type. If it is owned, create an
669
669
// alloc_box for it.
670
- if (value-> getOwnershipKind () == OwnershipKind::Owned) {
670
+ if (argrv. getOwnershipKind () == OwnershipKind::Owned) {
671
671
// TODO: Once owned values are mutable, this needs to become mutable.
672
672
auto boxType = SGF.SGM .Types .getContextBoxTypeForCapture (
673
673
pd,
@@ -696,17 +696,18 @@ class ArgumentInitHelper {
696
696
// misleading consuming message. We still are able to pass it to
697
697
// non-escaping closures though since the onstack partial_apply does not
698
698
// consume the value.
699
- assert (value->getOwnershipKind () == OwnershipKind::Guaranteed);
700
- value = SGF.B .createCopyValue (loc, value);
701
- value = SGF.B .createMarkMustCheckInst (
702
- loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
703
- SGF.emitManagedRValueWithCleanup (value);
704
- return completeUpdate (value);
699
+ assert (argrv.getOwnershipKind () == OwnershipKind::Guaranteed);
700
+ argrv = argrv.copy (SGF, loc);
701
+ argrv = SGF.B .createMarkMustCheckInst (
702
+ loc, argrv, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
703
+ return completeUpdate (argrv);
705
704
}
706
705
707
- if (value->getType ().isTrivial (SGF.F )) {
708
- value = SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (loc, value);
709
- value = SGF.B .createMoveValue (loc, value, /* isLexical=*/ true );
706
+ if (argrv.getType ().isTrivial (SGF.F )) {
707
+ SILValue value = SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (
708
+ loc, argrv.getValue ());
709
+ argrv = SGF.emitManagedRValueWithCleanup (value);
710
+ argrv = SGF.B .createMoveValue (loc, argrv, /* isLexical=*/ true );
710
711
711
712
// If our argument was owned, we use no implicit copy. Otherwise, we
712
713
// use no copy.
@@ -723,40 +724,35 @@ class ArgumentInitHelper {
723
724
break ;
724
725
}
725
726
726
- value = SGF.B .createMarkMustCheckInst (loc, value, kind);
727
- SGF.emitManagedRValueWithCleanup (value);
728
- return completeUpdate (value);
727
+ argrv = SGF.B .createMarkMustCheckInst (loc, argrv, kind);
728
+ return completeUpdate (argrv);
729
729
}
730
730
731
- if (value->getOwnershipKind () == OwnershipKind::Guaranteed) {
732
- value = SGF.B .createGuaranteedCopyableToMoveOnlyWrapperValue (loc, value);
733
- value = SGF.B .createCopyValue (loc, value);
734
- value = SGF.B .createMarkMustCheckInst (
735
- loc, value, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
736
- SGF.emitManagedRValueWithCleanup (value);
737
- return completeUpdate (value);
731
+ if (argrv.getOwnershipKind () == OwnershipKind::Guaranteed) {
732
+ argrv = SGF.B .createGuaranteedCopyableToMoveOnlyWrapperValue (loc, argrv);
733
+ argrv = argrv.copy (SGF, loc);
734
+ argrv = SGF.B .createMarkMustCheckInst (
735
+ loc, argrv, MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
736
+ return completeUpdate (argrv);
738
737
}
739
738
740
- if (value-> getOwnershipKind () == OwnershipKind::Owned) {
739
+ if (argrv. getOwnershipKind () == OwnershipKind::Owned) {
741
740
// If we have an owned value, forward it into the mark_must_check to
742
741
// avoid an extra destroy_value.
743
- value = SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (
744
- loc, argrv.forward (SGF));
745
- value = SGF.B .createMoveValue (loc, value, true /* is lexical*/ );
746
- value = SGF.B .createMarkMustCheckInst (
747
- loc, value, MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
748
- SGF.emitManagedRValueWithCleanup (value);
749
- return completeUpdate (value);
742
+ argrv = SGF.B .createOwnedCopyableToMoveOnlyWrapperValue (loc, argrv);
743
+ argrv = SGF.B .createMoveValue (loc, argrv, true /* is lexical*/ );
744
+ argrv = SGF.B .createMarkMustCheckInst (
745
+ loc, argrv, MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
746
+ return completeUpdate (argrv);
750
747
}
751
748
752
- return completeUpdate (value );
749
+ return completeUpdate (argrv );
753
750
}
754
751
755
752
// / Create a SILArgument and store its value into the given Initialization,
756
753
// / if not null.
757
754
void makeArgumentIntoBinding (SILLocation loc, ParamDecl *pd) {
758
755
ManagedValue argrv = makeArgument (loc, pd);
759
- SILValue value = argrv.getValue ();
760
756
if (pd->isInOut ()) {
761
757
assert (argrv.getType ().isAddress () && " expected inout to be address" );
762
758
} else if (!pd->isImmutableInFunctionBody ()) {
@@ -774,33 +770,34 @@ class ArgumentInitHelper {
774
770
SILDebugVariable varinfo (pd->isImmutableInFunctionBody (), ArgNo);
775
771
if (!argrv.getType ().isAddress ()) {
776
772
// NOTE: We setup SGF.VarLocs[pd] in updateArgumentValueForBinding.
777
- updateArgumentValueForBinding (argrv, loc, pd, value, varinfo);
773
+ updateArgumentValueForBinding (argrv, loc, pd, varinfo);
778
774
return ;
779
775
}
780
776
781
- if (auto *allocStack = dyn_cast<AllocStackInst>(value )) {
777
+ if (auto *allocStack = dyn_cast<AllocStackInst>(argrv. getValue () )) {
782
778
allocStack->setArgNo (ArgNo);
783
779
if (SGF.getASTContext ().SILOpts .supportsLexicalLifetimes (
784
780
SGF.getModule ()) &&
785
- SGF.F .getLifetime (pd, value ->getType ()).isLexical ())
781
+ SGF.F .getLifetime (pd, allocStack ->getType ()).isLexical ())
786
782
allocStack->setIsLexical ();
787
- SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (value );
783
+ SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (allocStack );
788
784
return ;
789
785
}
790
786
791
- SILValue debugOperand = value;
792
- if (value->getType ().isMoveOnly ()) {
787
+ SILValue debugOperand = argrv.getValue ();
788
+
789
+ if (argrv.getType ().isMoveOnly ()) {
793
790
switch (pd->getValueOwnership ()) {
794
791
case ValueOwnership::Default:
795
792
if (pd->isSelfParameter ()) {
796
- assert (!isa<MarkMustCheckInst>(value ) &&
793
+ assert (!isa<MarkMustCheckInst>(argrv. getValue () ) &&
797
794
" Should not have inserted mark must check inst in EmitBBArgs" );
798
795
if (!pd->isInOut ()) {
799
- value = SGF.B .createMarkMustCheckInst (
800
- loc, value , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
796
+ argrv = SGF.B .createMarkMustCheckInst (
797
+ loc, argrv , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
801
798
}
802
799
} else {
803
- if (auto *fArg = dyn_cast<SILFunctionArgument>(value )) {
800
+ if (auto *fArg = dyn_cast<SILFunctionArgument>(argrv. getValue () )) {
804
801
switch (fArg ->getArgumentConvention ()) {
805
802
case SILArgumentConvention::Direct_Guaranteed:
806
803
case SILArgumentConvention::Direct_Owned:
@@ -814,51 +811,51 @@ class ArgumentInitHelper {
814
811
case SILArgumentConvention::Pack_Out:
815
812
llvm_unreachable (" Should have been handled elsewhere" );
816
813
case SILArgumentConvention::Indirect_In:
817
- value = SGF.B .createMarkMustCheckInst (
818
- loc, value ,
814
+ argrv = SGF.B .createMarkMustCheckInst (
815
+ loc, argrv ,
819
816
MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
820
817
break ;
821
818
case SILArgumentConvention::Indirect_In_Guaranteed:
822
- value = SGF.B .createMarkMustCheckInst (
823
- loc, value , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
819
+ argrv = SGF.B .createMarkMustCheckInst (
820
+ loc, argrv , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
824
821
}
825
822
} else {
826
- assert (isa<MarkMustCheckInst>(value ) &&
823
+ assert (isa<MarkMustCheckInst>(argrv. getValue () ) &&
827
824
" Should have inserted mark must check inst in EmitBBArgs" );
828
825
}
829
826
}
830
827
break ;
831
828
case ValueOwnership::InOut: {
832
- assert (isa<MarkMustCheckInst>(value)
833
- && " Expected mark must check inst with inout to be handled in "
834
- " emitBBArgs earlier" );
835
- auto mark = cast<MarkMustCheckInst>(value );
829
+ assert (isa<MarkMustCheckInst>(argrv. getValue ()) &&
830
+ " Expected mark must check inst with inout to be handled in "
831
+ " emitBBArgs earlier" );
832
+ auto mark = cast<MarkMustCheckInst>(argrv. getValue () );
836
833
debugOperand = mark->getOperand ();
837
834
break ;
838
835
}
839
836
case ValueOwnership::Owned:
840
- value = SGF.B .createMarkMustCheckInst (
841
- loc, value , MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
837
+ argrv = SGF.B .createMarkMustCheckInst (
838
+ loc, argrv , MarkMustCheckInst::CheckKind::ConsumableAndAssignable);
842
839
break ;
843
840
case ValueOwnership::Shared:
844
- value = SGF.B .createMarkMustCheckInst (
845
- loc, value , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
841
+ argrv = SGF.B .createMarkMustCheckInst (
842
+ loc, argrv , MarkMustCheckInst::CheckKind::NoConsumeOrAssign);
846
843
break ;
847
844
}
848
845
}
849
846
850
847
DebugValueInst *debugInst
851
848
= SGF.B .createDebugValueAddr (loc, debugOperand, varinfo);
852
-
853
- if (value != debugOperand) {
854
- if (auto valueInst = dyn_cast<MarkMustCheckInst>(value )) {
849
+
850
+ if (argrv. getValue () != debugOperand) {
851
+ if (auto valueInst = dyn_cast<MarkMustCheckInst>(argrv. getValue () )) {
855
852
// Move the debug instruction outside of any marker instruction that might
856
853
// have been applied to the value, so that analysis doesn't move the
857
854
// debug_value anywhere it shouldn't be.
858
855
debugInst->moveBefore (valueInst);
859
856
}
860
857
}
861
- SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (value );
858
+ SGF.VarLocs [pd] = SILGenFunction::VarLoc::get (argrv. getValue () );
862
859
}
863
860
864
861
void emitParam (ParamDecl *PD) {
0 commit comments