@@ -305,6 +305,8 @@ getAutoDiffDifferentialType(SILFunctionType *originalFnTy,
305
305
IndexSubset *parameterIndices, unsigned resultIndex,
306
306
LookupConformanceFn lookupConformance,
307
307
TypeConverter &TC) {
308
+ // Given the tangent type and the corresponding original parameter's
309
+ // convention, returns the tangent parameter's convention.
308
310
auto getTangentParameterConvention =
309
311
[&](CanType tanType,
310
312
ParameterConvention origParamConv) -> ParameterConvention {
@@ -314,6 +316,8 @@ getAutoDiffDifferentialType(SILFunctionType *originalFnTy,
314
316
tanType);
315
317
auto &tl =
316
318
TC.getTypeLowering (pattern, tanType, TypeExpansionContext::minimal ());
319
+ // When the tangent type is address only, we must ensure that the tangent
320
+ // parameter's convention is indirect.
317
321
if (tl.isAddressOnly () && !isIndirectFormalParameter (origParamConv)) {
318
322
switch (origParamConv) {
319
323
case ParameterConvention::Direct_Guaranteed:
@@ -328,6 +332,8 @@ getAutoDiffDifferentialType(SILFunctionType *originalFnTy,
328
332
return origParamConv;
329
333
};
330
334
335
+ // Given the tangent type and the corresponding original result's convention,
336
+ // returns the tangent result's convention.
331
337
auto getTangentResultConvention =
332
338
[&](CanType tanType,
333
339
ResultConvention origResConv) -> ResultConvention {
@@ -337,6 +343,8 @@ getAutoDiffDifferentialType(SILFunctionType *originalFnTy,
337
343
tanType);
338
344
auto &tl =
339
345
TC.getTypeLowering (pattern, tanType, TypeExpansionContext::minimal ());
346
+ // When the tangent type is address only, we must ensure that the tangent
347
+ // result's convention is indirect.
340
348
if (tl.isAddressOnly () && !isIndirectFormalResult (origResConv)) {
341
349
switch (origResConv) {
342
350
case ResultConvention::Owned:
0 commit comments