fix: no stringify in hot loop

This commit is contained in:
2025-12-28 02:19:48 -05:00
parent ee9e71d58e
commit 633d4a4d3b
4 changed files with 25 additions and 11 deletions

View File

@@ -11,16 +11,14 @@ func Substitute(e *Expression, target string, replacement Expression) {
return
}
if !IsFreeVariable(typed.Parameter, replacement) {
Substitute(&typed.Body, target, replacement)
return
if IsFreeVariable(typed.Parameter, replacement) {
replacementFreeVars := GetFreeVariables(replacement)
used := GetFreeVariables(typed.Body)
used.Merge(replacementFreeVars)
freshVar := GenerateFreshName(used)
Rename(typed, typed.Parameter, freshVar)
}
replacementFreeVars := GetFreeVariables(replacement)
used := GetFreeVariables(typed.Body)
used.Merge(replacementFreeVars)
freshVar := GenerateFreshName(used)
Rename(typed, typed.Parameter, freshVar)
Substitute(&typed.Body, target, replacement)
case *Application:
Substitute(&typed.Abstraction, target, replacement)