Anyway, could you post the SIL you’re generating?
Here is the SIL for the function that actually calls the autodiff builtins which perform the boxed allocations.
// reverse-mode derivative of f(x:)
sil hidden @$s4main1f1xS2f_tFTJrSpSr : $@convention(thin) (Float) -> (Float, @owned @callee_guaranteed (Float) -> Float) {
// %0 // users: %59, %3
bb0(%0 : $Float):
%1 = metatype $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, (Float) -> Float).Type // user: %2
%2 = builtin "autoDiffCreateLinearMapContext"(%1 : $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, (Float) -> Float).Type) : $Builtin.NativeObject // users: %37, %48, %43, %64, %67
debug_value %0 : $Float, let, name "x", argno 1 // id: %3
%4 = float_literal $Builtin.FPIEEE32, 0x3F800000 // 1 // user: %5
%5 = struct $Float (%4 : $Builtin.FPIEEE32) // users: %59, %6
debug_value %5 : $Float, let, name "r" // id: %6
%7 = alloc_stack $IndexingIterator<Range<Int>>, var, name "$generator", implicit // users: %18, %52, %25
%8 = integer_literal $Builtin.Int64, 0 // user: %9
%9 = struct $Int (%8 : $Builtin.Int64) // user: %12
%10 = integer_literal $Builtin.Int64, 1 // user: %11
%11 = struct $Int (%10 : $Builtin.Int64) // user: %12
%12 = struct $Range<Int> (%9 : $Int, %11 : $Int) // user: %14
%13 = alloc_stack $Range<Int> // users: %16, %14, %19
store %12 to %13 : $*Range<Int> // id: %14
// function_ref specialized Collection<>.makeIterator()
%15 = function_ref @$sSlss16IndexingIteratorVyxG0B0RtzrlE04makeB0ACyFSnySiG_Tg5 : $@convention(method) (Range<Int>) -> IndexingIterator<Range<Int>> // user: %17
%16 = load %13 : $*Range<Int> // user: %17
%17 = apply %15(%16) : $@convention(method) (Range<Int>) -> IndexingIterator<Range<Int>> // user: %18
store %17 to %7 : $*IndexingIterator<Range<Int>> // id: %18
dealloc_stack %13 : $*Range<Int> // id: %19
%20 = tuple () // user: %21
%21 = enum $_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0, #_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0.bb0!enumelt, %20 : $() // user: %22
br bb1(%21 : $_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // id: %22
// %23 // user: %32
bb1(%23 : $_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0): // Preds: bb2 bb0
%24 = alloc_stack $Optional<Int> // users: %28, %30, %31
%25 = begin_access [modify] [static] %7 : $*IndexingIterator<Range<Int>> // users: %27, %29
// function_ref specialized IndexingIterator.next()
%26 = function_ref @$ss16IndexingIteratorV4next7ElementQzSgyFSnySiG_Tg5 : $@convention(method) (@inout IndexingIterator<Range<Int>>) -> Optional<Int> // user: %27
%27 = apply %26(%25) : $@convention(method) (@inout IndexingIterator<Range<Int>>) -> Optional<Int> // user: %28
store %27 to %24 : $*Optional<Int> // id: %28
end_access %25 : $*IndexingIterator<Range<Int>> // id: %29
%30 = load %24 : $*Optional<Int> // user: %35
dealloc_stack %24 : $*Optional<Int> // id: %31
%32 = tuple $(predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) (%23) // users: %50, %39
%33 = metatype $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0).Type // user: %37
%34 = metatype $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0).Type // user: %48
switch_enum %30 : $Optional<Int>, case #Optional.some!enumelt: bb2, case #Optional.none!enumelt: bb3 // id: %35
bb2(%36 : $Int): // Preds: bb1
%37 = builtin "autoDiffAllocateSubcontext"(%2 : $Builtin.NativeObject, %33 : $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0).Type) : $Builtin.RawPointer // users: %40, %38
%38 = pointer_to_address %37 : $Builtin.RawPointer to [strict] $*(predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // user: %39
store %32 to %38 : $*(predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // id: %39
%40 = enum $_AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0, #_AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0.bb1!enumelt, %37 : $Builtin.RawPointer // user: %41
%41 = tuple $(predecessor: _AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0) (%40) // user: %45
%42 = metatype $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0).Type // user: %43
%43 = builtin "autoDiffAllocateSubcontext"(%2 : $Builtin.NativeObject, %42 : $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0).Type) : $Builtin.RawPointer // users: %46, %44
%44 = pointer_to_address %43 : $Builtin.RawPointer to [strict] $*(predecessor: _AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0) // user: %45
store %41 to %44 : $*(predecessor: _AD__$s4main1f1xS2f_tF_bb2__Pred__src_0_wrt_0) // id: %45
%46 = enum $_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0, #_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0.bb2!enumelt, %43 : $Builtin.RawPointer // user: %47
br bb1(%46 : $_AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // id: %47
bb3: // Preds: bb1
%48 = builtin "autoDiffAllocateSubcontext"(%2 : $Builtin.NativeObject, %34 : $@thick (predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0).Type) : $Builtin.RawPointer // users: %51, %49
%49 = pointer_to_address %48 : $Builtin.RawPointer to [strict] $*(predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // user: %50
store %32 to %49 : $*(predecessor: _AD__$s4main1f1xS2f_tF_bb1__Pred__src_0_wrt_0) // id: %50
%51 = enum $_AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, #_AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0.bb1!enumelt, %48 : $Builtin.RawPointer // user: %63
dealloc_stack %7 : $*IndexingIterator<Range<Int>> // id: %52
%53 = metatype $@thin Float.Type // user: %59
// function_ref static Float.+ infix(_:_:)
%54 = function_ref @$sSf1poiyS2f_SftFZ : $@convention(method) (Float, Float, @thin Float.Type) -> Float // user: %57
// function_ref autodiff subset parameters thunk for forward-mode derivative from static Float.+ infix(_:_:)
%55 = function_ref @$sSf1poiyS2f_SftFZS3fXMtS3fIegyd_IetMyyydo_TJSfSSUpSrSUUP : $@convention(method) (Float, Float, @thin Float.Type) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %57
// function_ref autodiff subset parameters thunk for reverse-mode derivative from static Float.+ infix(_:_:)
%56 = function_ref @$sSf1poiyS2f_SftFZS3fXMtS3fIegyd_IetMyyydo_TJSrSSUpSrSUUP : $@convention(method) (Float, Float, @thin Float.Type) -> (Float, @owned @callee_guaranteed (Float) -> Float) // user: %57
%57 = differentiable_function [parameters 0] [results 0] %54 : $@convention(method) (Float, Float, @thin Float.Type) -> Float with_derivative {%55 : $@convention(method) (Float, Float, @thin Float.Type) -> (Float, @owned @callee_guaranteed (Float) -> Float), %56 : $@convention(method) (Float, Float, @thin Float.Type) -> (Float, @owned @callee_guaranteed (Float) -> Float)} // user: %58
%58 = differentiable_function_extract [vjp] %57 : $@differentiable(reverse) @convention(method) (Float, @noDerivative Float, @noDerivative @thin Float.Type) -> Float // user: %59
%59 = apply %58(%0, %5, %53) : $@convention(method) (Float, Float, @thin Float.Type) -> (Float, @owned @callee_guaranteed (Float) -> Float) // users: %61, %60
%60 = tuple_extract %59 : $(Float, @callee_guaranteed (Float) -> Float), 0 // user: %68
%61 = tuple_extract %59 : $(Float, @callee_guaranteed (Float) -> Float), 1 // user: %63
// function_ref pullback of f(x:)
%62 = function_ref @$s4main1f1xS2f_tFTJpSpSr : $@convention(thin) (Float, @guaranteed Builtin.NativeObject) -> Float // user: %67
%63 = tuple $(predecessor: _AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, @callee_guaranteed (Float) -> Float) (%51, %61) // user: %66
%64 = builtin "autoDiffProjectTopLevelSubcontext"(%2 : $Builtin.NativeObject) : $Builtin.RawPointer // user: %65
%65 = pointer_to_address %64 : $Builtin.RawPointer to [strict] $*(predecessor: _AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, @callee_guaranteed (Float) -> Float) // user: %66
store %63 to %65 : $*(predecessor: _AD__$s4main1f1xS2f_tF_bb3__Pred__src_0_wrt_0, @callee_guaranteed (Float) -> Float) // id: %66
%67 = partial_apply [callee_guaranteed] %62(%2) : $@convention(thin) (Float, @guaranteed Builtin.NativeObject) -> Float // user: %68
%68 = tuple (%60 : $Float, %67 : $@callee_guaranteed (Float) -> Float) // user: %69
return %68 : $(Float, @callee_guaranteed (Float) -> Float) // id: %69
} // end sil function '$s4main1f1xS2f_tFTJrSpSr'