Skip to content

Commit 1cff471

Browse files
committed
Introduce ResultConvention::Guaranteed and ResultConvention::GuaranteedAddress
ResultConvention::Guaranteed will be used by borrow accessors when the storage type can be returned by value. ResultConvention::GuaranteedAddress will be used by mutate accessors and borrow accessors when the storage type cannot be returned by value.
1 parent 5689f65 commit 1cff471

File tree

13 files changed

+60
-1
lines changed

13 files changed

+60
-1
lines changed

include/swift/AST/Types.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4772,7 +4772,7 @@ enum class ResultConvention : uint8_t {
47724772
/// The validity of the return value is dependent on the 'self' parameter,
47734773
/// so it may be invalidated if that parameter is released.
47744774
UnownedInnerPointer,
4775-
4775+
47764776
/// This value has been (or may have been) returned autoreleased.
47774777
/// The caller should make an effort to reclaim the autorelease.
47784778
/// The type must be a class or class existential type, and this
@@ -4784,6 +4784,14 @@ enum class ResultConvention : uint8_t {
47844784
/// depending on the pact type). The callee is responsible for
47854785
/// leaving an initialized object in each element of the pack.
47864786
Pack,
4787+
4788+
/// The caller is responsible for using the returned address within a valid
4789+
/// scope. This is valid only for borrow and mutate accessors.
4790+
GuaranteedAddress,
4791+
4792+
/// The caller is responsible for using the returned value within a valid
4793+
/// scope. This is valid only for borrow accessors.
4794+
Guaranteed,
47874795
};
47884796

47894797
// Does this result require indirect storage for the purpose of reabstraction?
@@ -4940,6 +4948,14 @@ class SILResultInfo {
49404948
return getConvention() == ResultConvention::Pack;
49414949
}
49424950

4951+
bool isGuaranteedAddressResult() const {
4952+
return getConvention() == ResultConvention::GuaranteedAddress;
4953+
}
4954+
4955+
bool isGuaranteedResult() const {
4956+
return getConvention() == ResultConvention::Guaranteed;
4957+
}
4958+
49434959
/// Transform this SILResultInfo by applying the user-provided
49444960
/// function to its type.
49454961
///

include/swift/SIL/SILFunctionConventions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ inline bool SILModuleConventions::isIndirectSILResult(SILResultInfo result,
637637
case ResultConvention::Unowned:
638638
case ResultConvention::UnownedInnerPointer:
639639
case ResultConvention::Autoreleased:
640+
case ResultConvention::GuaranteedAddress:
641+
case ResultConvention::Guaranteed:
640642
return false;
641643
}
642644

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,10 @@ static char getResultConvention(ResultConvention conv) {
22822282
case ResultConvention::UnownedInnerPointer: return 'u';
22832283
case ResultConvention::Autoreleased: return 'a';
22842284
case ResultConvention::Pack: return 'k';
2285+
case ResultConvention::GuaranteedAddress:
2286+
return 'g';
2287+
case ResultConvention::Guaranteed:
2288+
return 'G';
22852289
}
22862290
llvm_unreachable("bad result convention");
22872291
}

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7893,6 +7893,10 @@ static StringRef getStringForResultConvention(ResultConvention conv) {
78937893
case ResultConvention::UnownedInnerPointer: return "@unowned_inner_pointer ";
78947894
case ResultConvention::Autoreleased: return "@autoreleased ";
78957895
case ResultConvention::Pack: return "@pack_out ";
7896+
case ResultConvention::GuaranteedAddress:
7897+
return "@guaranteed_addr ";
7898+
case ResultConvention::Guaranteed:
7899+
return "@guaranteed ";
78967900
}
78977901
llvm_unreachable("bad result convention");
78987902
}

lib/IRGen/GenObjC.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -935,6 +935,8 @@ static llvm::Function *emitObjCPartialApplicationForwarder(IRGenModule &IGM,
935935
case ResultConvention::Owned:
936936
case ResultConvention::Autoreleased:
937937
case ResultConvention::Pack:
938+
case ResultConvention::GuaranteedAddress:
939+
case ResultConvention::Guaranteed:
938940
lifetimeExtendsSelf = false;
939941
break;
940942
}

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,9 @@ static CanSILFunctionType getAutoDiffPullbackType(
719719
case ResultConvention::Indirect:
720720
conv = ParameterConvention::Indirect_In_Guaranteed;
721721
break;
722+
case ResultConvention::GuaranteedAddress:
723+
case ResultConvention::Guaranteed:
724+
llvm_unreachable("borrow/mutate accessor not yet implemented");
722725
}
723726
return conv;
724727
};
@@ -1066,6 +1069,9 @@ CanSILFunctionType SILFunctionType::getAutoDiffTransposeFunctionType(
10661069
case ResultConvention::Indirect:
10671070
newConv = ParameterConvention::Indirect_In_Guaranteed;
10681071
break;
1072+
case ResultConvention::GuaranteedAddress:
1073+
case ResultConvention::Guaranteed:
1074+
llvm_unreachable("borrow accessor is not yet implemented");
10691075
}
10701076
return {result.getInterfaceType(), newConv};
10711077
};
@@ -1431,11 +1437,15 @@ class DestructureResults {
14311437
case ResultConvention::Indirect:
14321438
case ResultConvention::Unowned:
14331439
case ResultConvention::UnownedInnerPointer:
1440+
case ResultConvention::Guaranteed:
14341441
// Leave these as-is.
14351442
break;
14361443

14371444
case ResultConvention::Pack:
14381445
llvm_unreachable("pack convention for non-pack");
1446+
case ResultConvention::GuaranteedAddress:
1447+
llvm_unreachable(
1448+
"Invalid case of ResultConvention::GuaranteedAddress");
14391449

14401450
case ResultConvention::Autoreleased:
14411451
case ResultConvention::Owned:

lib/SIL/IR/SILType.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,10 @@ SILResultInfo::getOwnershipKind(SILFunction &F,
659659
if (IsTrivial)
660660
return OwnershipKind::None;
661661
return OwnershipKind::Unowned;
662+
case ResultConvention::GuaranteedAddress:
663+
return OwnershipKind::None;
664+
case ResultConvention::Guaranteed:
665+
return OwnershipKind::Guaranteed;
662666
}
663667

664668
llvm_unreachable("Unhandled ResultConvention in switch.");

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6247,6 +6247,11 @@ RValue SILGenFunction::emitApply(
62476247
// Unretained. Retain the value.
62486248
result = resultTL.emitCopyValue(B, loc, result);
62496249
break;
6250+
6251+
case ResultConvention::GuaranteedAddress:
6252+
case ResultConvention::Guaranteed:
6253+
llvm_unreachable("borrow accessor is not yet implemented");
6254+
break;
62506255
}
62516256

62526257
directResults.push_back(emitManagedRValueWithCleanup(result, resultTL));

lib/SILGen/SILGenPoly.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5302,6 +5302,9 @@ void ResultPlanner::execute(SmallVectorImpl<SILValue> &innerDirectResultStack,
53025302
LLVM_FALLTHROUGH;
53035303
case ResultConvention::Unowned:
53045304
return SGF.emitManagedCopy(Loc, resultValue, resultTL);
5305+
case ResultConvention::GuaranteedAddress:
5306+
case ResultConvention::Guaranteed:
5307+
llvm_unreachable("borrow accessor not yet implemented");
53055308
}
53065309
llvm_unreachable("bad result convention!");
53075310
};

lib/SILOptimizer/Differentiation/VJPCloner.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,9 @@ SILFunction *VJPCloner::Implementation::createEmptyPullback() {
11331133
case ResultConvention::Pack:
11341134
conv = ParameterConvention::Pack_Guaranteed;
11351135
break;
1136+
case ResultConvention::GuaranteedAddress:
1137+
case ResultConvention::Guaranteed:
1138+
llvm_unreachable("borrow accessor is not yet implemented");
11361139
}
11371140
return {tanType, conv};
11381141
};

0 commit comments

Comments
 (0)