Skip to content

Commit d17258c

Browse files
author
Joe Shajrawi
committed
@in_constant calling convention - part of passing large loadable types by address
1 parent 8338795 commit d17258c

31 files changed

+76
-14
lines changed

docs/ABI.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ mangled in to disambiguate.
11011101
FUNC-REPRESENTATION ::= 'W' // protocol witness
11021102

11031103
PARAM-CONVENTION ::= 'i' // indirect in
1104+
PARAM-CONVENTION ::= 'c' // indirect in constant
11041105
PARAM-CONVENTION ::= 'l' // indirect inout
11051106
PARAM-CONVENTION ::= 'b' // indirect inout aliasable
11061107
PARAM-CONVENTION ::= 'n' // indirect in guaranteed

docs/SIL.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ number of ways:
479479
initialized object; both the caller and callee promise not to mutate the
480480
pointee, allowing the callee to read it.
481481

482+
- An ``@in_constant`` parameter is indirect. The address must be of an
483+
initialized object; the function will treat the value held there as read-only.
484+
482485
- Otherwise, the parameter is an unowned direct parameter.
483486

484487
- A SIL function type declares the conventions for its results.

include/swift/AST/Attr.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ TYPE_ATTR(in)
5050
TYPE_ATTR(inout)
5151
TYPE_ATTR(inout_aliasable)
5252
TYPE_ATTR(in_guaranteed)
53+
TYPE_ATTR(in_constant)
5354
TYPE_ATTR(owned)
5455
TYPE_ATTR(unowned_inner_pointer)
5556
TYPE_ATTR(guaranteed)

include/swift/AST/Types.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,11 @@ enum class ParameterConvention {
26632663
/// object.
26642664
Indirect_In,
26652665

2666+
/// This argument is passed indirectly, i.e. by directly passing the address
2667+
/// of an object in memory. The callee must treat the object as read-only
2668+
/// The callee may assume that the address does not alias any valid object.
2669+
Indirect_In_Constant,
2670+
26662671
/// This argument is passed indirectly, i.e. by directly passing the address
26672672
/// of an object in memory. The callee may not modify and does not destroy
26682673
/// the object.
@@ -2675,7 +2680,7 @@ enum class ParameterConvention {
26752680
/// single-threaded aliasing may produce inconsistent results, but should
26762681
/// remain memory safe.
26772682
Indirect_Inout,
2678-
2683+
26792684
/// This argument is passed indirectly, i.e. by directly passing the address
26802685
/// of an object in memory. The object is allowed to be aliased by other
26812686
/// well-typed references, but is not allowed to be escaped. This is the
@@ -2705,6 +2710,7 @@ static_assert(unsigned(ParameterConvention::Direct_Guaranteed) < (1<<3),
27052710
inline bool isIndirectFormalParameter(ParameterConvention conv) {
27062711
switch (conv) {
27072712
case ParameterConvention::Indirect_In:
2713+
case ParameterConvention::Indirect_In_Constant:
27082714
case ParameterConvention::Indirect_Inout:
27092715
case ParameterConvention::Indirect_InoutAliasable:
27102716
case ParameterConvention::Indirect_In_Guaranteed:
@@ -2720,6 +2726,7 @@ inline bool isIndirectFormalParameter(ParameterConvention conv) {
27202726
inline bool isConsumedParameter(ParameterConvention conv) {
27212727
switch (conv) {
27222728
case ParameterConvention::Indirect_In:
2729+
case ParameterConvention::Indirect_In_Constant:
27232730
case ParameterConvention::Direct_Owned:
27242731
return true;
27252732

@@ -2745,6 +2752,7 @@ inline bool isGuaranteedParameter(ParameterConvention conv) {
27452752
case ParameterConvention::Indirect_Inout:
27462753
case ParameterConvention::Indirect_InoutAliasable:
27472754
case ParameterConvention::Indirect_In:
2755+
case ParameterConvention::Indirect_In_Constant:
27482756
case ParameterConvention::Direct_Unowned:
27492757
case ParameterConvention::Direct_Owned:
27502758
return false;

include/swift/SIL/SILArgumentConvention.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ enum class InoutAliasingAssumption {
3737
struct SILArgumentConvention {
3838
enum ConventionType : uint8_t {
3939
Indirect_In,
40+
Indirect_In_Constant,
4041
Indirect_In_Guaranteed,
4142
Indirect_Inout,
4243
Indirect_InoutAliasable,
@@ -55,6 +56,9 @@ struct SILArgumentConvention {
5556
case ParameterConvention::Indirect_In:
5657
Value = SILArgumentConvention::Indirect_In;
5758
return;
59+
case ParameterConvention::Indirect_In_Constant:
60+
Value = SILArgumentConvention::Indirect_In_Constant;
61+
return;
5862
case ParameterConvention::Indirect_Inout:
5963
Value = SILArgumentConvention::Indirect_Inout;
6064
return;
@@ -90,6 +94,7 @@ struct SILArgumentConvention {
9094
bool isNotAliasedIndirectParameter(InoutAliasingAssumption isInoutAliasing) {
9195
switch (Value) {
9296
case SILArgumentConvention::Indirect_In:
97+
case SILArgumentConvention::Indirect_In_Constant:
9398
case SILArgumentConvention::Indirect_Out:
9499
case SILArgumentConvention::Indirect_In_Guaranteed:
95100
return true;

include/swift/SIL/SILFunctionConventions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ inline bool SILModuleConventions::isIndirectSILParam(SILParameterInfo param,
352352
return false;
353353

354354
case ParameterConvention::Indirect_In:
355+
case ParameterConvention::Indirect_In_Constant:
355356
case ParameterConvention::Indirect_In_Guaranteed:
356357
return (loweredAddresses ||
357358
param.getType()->isOpenedExistentialWithError());

include/swift/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const uint16_t VERSION_MAJOR = 0;
5454
/// in source control, you should also update the comment to briefly
5555
/// describe what change you made. The content of this comment isn't important;
5656
/// it just ensures a conflict if two people change the module format.
57-
const uint16_t VERSION_MINOR = 339; // Last change: member canonical types
57+
const uint16_t VERSION_MINOR = 340; // Last change: Indirect_In_Constant
5858

5959
using DeclID = PointerEmbeddedInt<unsigned, 31>;
6060
using DeclIDField = BCFixed<31>;
@@ -199,6 +199,7 @@ enum class ParameterConvention : uint8_t {
199199
Direct_Unowned,
200200
Direct_Guaranteed,
201201
Indirect_In_Guaranteed,
202+
Indirect_In_Constant,
202203
};
203204
using ParameterConventionField = BCFixed<4>;
204205

lib/AST/ASTMangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,8 @@ static char getParamConvention(ParameterConvention conv) {
947947
// different places.
948948
switch (conv) {
949949
case ParameterConvention::Indirect_In: return 'i';
950+
case ParameterConvention::Indirect_In_Constant:
951+
return 'c';
950952
case ParameterConvention::Indirect_Inout: return 'l';
951953
case ParameterConvention::Indirect_InoutAliasable: return 'b';
952954
case ParameterConvention::Indirect_In_Guaranteed: return 'n';

lib/AST/ASTPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,6 +4113,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
41134113
Printer << "@callee_guaranteed ";
41144114
return;
41154115
case ParameterConvention::Indirect_In:
4116+
case ParameterConvention::Indirect_In_Constant:
41164117
case ParameterConvention::Indirect_Inout:
41174118
case ParameterConvention::Indirect_InoutAliasable:
41184119
case ParameterConvention::Indirect_In_Guaranteed:
@@ -4460,6 +4461,8 @@ std::string GenericSignature::getAsString() const {
44604461
static StringRef getStringForParameterConvention(ParameterConvention conv) {
44614462
switch (conv) {
44624463
case ParameterConvention::Indirect_In: return "@in ";
4464+
case ParameterConvention::Indirect_In_Constant:
4465+
return "@in_constant ";
44634466
case ParameterConvention::Indirect_In_Guaranteed: return "@in_guaranteed ";
44644467
case ParameterConvention::Indirect_Inout: return "@inout ";
44654468
case ParameterConvention::Indirect_InoutAliasable: return "@inout_aliasable ";

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,9 @@ NodePointer Demangler::demangleImplParamConvention() {
942942
const char *attr = nullptr;
943943
switch (nextChar()) {
944944
case 'i': attr = "@in"; break;
945+
case 'c':
946+
attr = "@in_constant";
947+
break;
945948
case 'l': attr = "@inout"; break;
946949
case 'b': attr = "@inout_aliasable"; break;
947950
case 'n': attr = "@in_guaranteed"; break;

0 commit comments

Comments
 (0)