You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do not splice the original function's AST nodes into derivatives.
A generated derivative must share no Stmt node with the primal it is
built from. The primal's AST outlives differentiation, so a node clad
reuses from the original exposes the user's own code to any later
in-place edit of the derivative. Several forward-mode paths handed the
primal node straight through as the "cloned" primal instead of cloning
it: the member `this`, non-differentiable decls, __null and __func__,
captured lambdas, the function-name string inside a PredefinedExpr, and
top-level lambda closures.
Clone each of them so the derivative owns a distinct subtree, and add
findPrimalSharedNode to keep it that way -- the cross-boundary sibling
of findSharedNode. It intersects the Stmt::children() reachability sets
of the derivative and its primal (child edges only, so Clang's
legitimate type, template-argument and default-argument shares are
excluded) and is enforced beside findSharedNode: assert in debug,
diagnostic in release.
0 commit comments