diff --git a/include/swift/SIL/TypeSubstCloner.h b/include/swift/SIL/TypeSubstCloner.h index b908df726504b..768a92e8d612e 100644 --- a/include/swift/SIL/TypeSubstCloner.h +++ b/include/swift/SIL/TypeSubstCloner.h @@ -322,28 +322,29 @@ class TypeSubstCloner : public SILClonerWithScopes { return; } // If the extractee is a derivative function, check whether the *remapped - // derivative function type* (BC) is equal to the *derivative remapped - // function type* (AD). + // derivative function type* (bc) is equal to the *derivative remapped + // function type* (ad). // - // +----------------+ remap +-------------------------+ - // | orig. fn type | -------(A)------> | remapped orig. fn type | - // +----------------+ +-------------------------+ - // | | - // (B, SILGen) getAutoDiffDerivativeFunctionType (D, here) - // V V - // +----------------+ remap +-------------------------+ - // | deriv. fn type | -------(C)------> | remapped deriv. fn type | - // +----------------+ +-------------------------+ + // ┌────────────────┐ remap ┌─────────────────────────┐ + // │ orig. fn type │ ───────(a)──────► │ remapped orig. fn type │ + // └────────────────┘ └─────────────────────────┘ + // │ │ + // (b, SILGen) getAutoDiffDerivativeFunctionType (d, here) + // │ │ + // ▼ ▼ + // ┌────────────────┐ remap ┌─────────────────────────┐ + // │ deriv. fn type │ ───────(c)──────► │ remapped deriv. fn type │ + // └────────────────┘ └─────────────────────────┘ // - // (AD) does not always commute with (BC): - // - (AD) is the result of remapping, then computing the derivative type. + // (ad) does not always commute with (bc): + // - (ad) is the result of remapping, then computing the derivative type. // This is the default cloning behavior, but may break invariants in the // initial SIL generated by SILGen. - // - (BC) is the result of computing the derivative type (SILGen), then + // - (bc) is the result of computing the derivative type (SILGen), then // remapping. This is the expected type, preserving invariants from // earlier transforms. // - // If (AD) is not equal to (BC), use (BC) as the explicit type. + // If (ad) is not equal to (bc), use (bc) as the explicit type. SILType remappedOrigType = getOpType(dfei->getOperand()->getType()); auto remappedOrigFnType = remappedOrigType.castTo(); auto derivativeRemappedFnType = diff --git a/lib/SIL/IR/SILFunctionType.cpp b/lib/SIL/IR/SILFunctionType.cpp index 3bf1f1e1ec5c6..39bf2c3f9a1a7 100644 --- a/lib/SIL/IR/SILFunctionType.cpp +++ b/lib/SIL/IR/SILFunctionType.cpp @@ -3088,30 +3088,31 @@ TypeConverter::getConstantInfo(TypeExpansionContext expansion, // If the constant refers to a derivative function, get the SIL type of the // original function and use it to compute the derivative SIL type. // - // This is necessary because the "lowered AST derivative function type" (BC) + // This is necessary because the "lowered AST derivative function type" (bc) // may differ from the "derivative type of the lowered original function type" - // (AD): + // (ad): // - // +--------------------+ lowering +--------------------+ - // | AST orig. fn type | -------(A)------> | SIL orig. fn type | - // +--------------------+ +--------------------+ - // | | - // (B, Sema) getAutoDiffDerivativeFunctionType (D, here) - // V V - // +--------------------+ lowering +--------------------+ - // | AST deriv. fn type | -------(C)------> | SIL deriv. fn type | - // +--------------------+ +--------------------+ + // ┌────────────────────┐ lowering ┌────────────────────┐ + // │ AST orig. fn type │ ───────(a)──────► │ SIL orig. fn type │ + // └────────────────────┘ └────────────────────┘ + // │ │ + // (b, Sema) getAutoDiffDerivativeFunctionType (d, here) + // │ │ + // ▼ ▼ + // ┌────────────────────┐ lowering ┌────────────────────┐ + // │ AST deriv. fn type │ ───────(c)──────► │ SIL deriv. fn type │ + // └────────────────────┘ └────────────────────┘ // - // (AD) does not always commute with (BC): - // - (BC) is the result of computing the AST derivative type (Sema), then + // (ad) does not always commute with (bc): + // - (bc) is the result of computing the AST derivative type (Sema), then // lowering it via SILGen. This is the default lowering behavior, but may // break SIL typing invariants because expected lowered derivative types are // computed from lowered original function types. - // - (AD) is the result of lowering the original function type, then computing + // - (ad) is the result of lowering the original function type, then computing // its derivative type. This is the expected lowered derivative type, // preserving SIL typing invariants. // - // Always use (AD) to compute lowered derivative function types. + // Always use (ad) to compute lowered derivative function types. if (auto *derivativeId = constant.derivativeFunctionIdentifier) { // Get lowered original function type. auto origFnConstantInfo = getConstantInfo(