perf: improve specializer cache keys (#11310)

This PR makes the specializer (correctly) share more cache keys across
invocations, causing us to produce less code bloat.

We observed that in functions with lots of specialization, sometimes
cache keys are defeq but not BEq because one has unused let decls
(introduced by specialization) that the other doesn't. This PR resolves
this conflict by erasing unused let decls from specializer cache keys.
This commit is contained in:
Henrik Böving 2025-11-22 00:21:40 +01:00 committed by GitHub
parent 3a309ba4eb
commit 80224c72c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -238,6 +238,7 @@ def mkKey (params : Array Param) (decls : Array CodeDecl) (body : LetValue) : Co
let key := ToExpr.run do
ToExpr.withParams params do
ToExpr.mkLambdaM params (← ToExpr.abstractM body)
let key ← Meta.MetaM.run' <| Meta.transform (usedLetOnly := true) key
return normLevelParams key
open Internalize in