perf: template the kernel's `replace` on its callback

This PR speeds up the kernel's expression traversals (`instantiate`, `instantiate_rev`, `abstract`, `lift_loose_bvars`, `lower_loose_bvars`, `instantiate_lparams`). `replace_tpl` is `replace` templated on its callback, so the callback is inlined instead of being called through a `std::function` at every visited node. It also takes a `skip` predicate: subterms the callback would return unchanged are returned before the cache lookup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed