SpecConstr should treat local and top level non-recursive bindings the same.
SpecConstr currently specializes local non recursive let bindings. But doesn't specialize top level non-recursive let bindings.
This means if we change the local binding in a way which allows it to float to the top performance can suddenly tank as we no longer get specialization for it.
This is however not as trivial as it sounds. In order to make this work coherently in the current design we would need to analyze the whole module for call patterns before we generate a specialization.
But we analyze the whole module for call patterns already! So maybe we could get away with:
- Do what we do now but keep around all call patterns for non-recursive top level bindings.
- We collected all the call patterns and specialize all the recursive bindings.
- Then do one pass over the non-recursive bindings generating specializations for their call patterns as well.
Seems plausible at least.