Explicitly use minimal type expansion for autodiff-related types (e.g. parameters and pullback result types) (#77831)

As autodiff happens on function types it is not in general possible to determine the real expansion context of the function being differentiated. Use of minimal context is a conservative approach that should work even when libraty evolution mode is enabled.

Fixes #55179
This commit is contained in:
Anton Korobeynikov
2024-12-02 15:02:09 -08:00
committed by GitHub
parent e131682e19
commit 216111172e
2 changed files with 51 additions and 1 deletions

View File

@@ -215,12 +215,17 @@ private:
//--------------------------------------------------------------------------//
/// Get the type lowering for the given AST type.
///
/// Explicitly use minimal type expansion context: in general, differentiation
/// happens on function types, so it cannot know if the original function is
/// resilient or not.
const Lowering::TypeLowering &getTypeLowering(Type type) {
auto pbGenSig =
getPullback().getLoweredFunctionType()->getSubstGenericSignature();
Lowering::AbstractionPattern pattern(pbGenSig,
type->getReducedType(pbGenSig));
return getPullback().getTypeLowering(pattern, type);
return getContext().getTypeConverter().getTypeLowering(
pattern, type, TypeExpansionContext::minimal());
}
/// Remap any archetypes into the current function's context.