--- a/s7.c +++ b/s7.c @@ -97318,7 +97318,18 @@ * closure_is_fine_1 just checks the type (safe or unsafe closure) * closure_is_ok calls _ok_1, closure_is_fine calls _fine_1 * closure_np_is_ok accepts safe/unsafe etc + */ + +/* a call site optimized for one closure can be given another closure with the same type and + * arity, but the annotations made for the first closure's body (fx_annotate_arg in + * optimize_closure_one_arg for op_safe_closure_p_a etc) are on that body only. A local + * function remade from the same source has the same body; a closure made from new code + * (a lambda built by a run-time macro at each call) does not. */ +static inline bool closure_has_same_body(s7_pointer old, s7_pointer clo) +{ + return((old) && (is_any_closure(old)) && (closure_body(old) == closure_body(clo))); +} static /* inline */ bool closure_is_ok_1(s7_scheme *sc, s7_pointer code, uint16_t type, int32_t args) { @@ -97327,6 +97338,7 @@ ((clo) && /* this fixup check does save time (e.g. cb) */ (low_type_bits(clo) == type) && ((closure_arity(clo) == args) || (closure_arity_to_int(sc, clo) == args)) && /* 3 type bits to replace this but not hit enough to warrant them */ + (closure_has_same_body(opt1_lambda_unchecked(code), clo)) && (set_opt1_lambda(code, clo)))) return(true); sc->last_function = clo; @@ -97340,6 +97352,7 @@ ((clo) && ((low_type_bits(clo) & (Type_Mask | T_Safe_Closure)) == type) && ((closure_arity(clo) == args) || (closure_arity_to_int(sc, clo) == args)) && + (closure_has_same_body(opt1_lambda_unchecked(code), clo)) && (set_opt1_lambda(code, clo)))) return(true); sc->last_function = clo; @@ -97393,6 +97406,7 @@ ((val) && ((low_type_bits(val) & (T_Safe_Closure | Type_Mask)) == type) && (star_arity_is_ok(sc, val, args)) && + (closure_has_same_body(opt1_lambda_unchecked(code), val)) && (set_opt1_lambda(code, val)))) return(true); sc->last_function = val;