Implement value witness table for @differentiable functions (#60875)

@differentiable function is actually a triple (function, jvp, vjp). Previously normal thick function value witness table was used. As a result, for example,  only function was copied, but none of differential components.

This was the cause of uninitialized memory accesses and subsequent segfaults.

Should fix now unavailable TF-1122
This commit is contained in:
Anton Korobeynikov
2022-09-01 12:09:39 +02:00
committed by GitHub
parent 983e2f37d3
commit c89e270b7d
6 changed files with 49 additions and 23 deletions

View File

@@ -1337,7 +1337,16 @@ FunctionCacheEntry::FunctionCacheEntry(const Key &key) {
if (!flags.isEscaping()) {
Data.ValueWitnesses = &VALUE_WITNESS_SYM(NOESCAPE_FUNCTION_MANGLING);
} else {
Data.ValueWitnesses = &VALUE_WITNESS_SYM(FUNCTION_MANGLING);
switch (key.getDifferentiabilityKind().Value) {
case FunctionMetadataDifferentiabilityKind::Reverse:
Data.ValueWitnesses = &VALUE_WITNESS_SYM(DIFF_FUNCTION_MANGLING);
break;
default:
assert(false && "unsupported function witness");
case FunctionMetadataDifferentiabilityKind::NonDifferentiable:
Data.ValueWitnesses = &VALUE_WITNESS_SYM(FUNCTION_MANGLING);
break;
}
}
break;