SpecConstr and Specialise should be combined into a single pass.
Structurally they do very much the same thing:
- Traverse the AST looking for function calls we can specialize for.
- Specialize the RHS of the called function.
- Looking at the specialized rhs for additional calls to specialize.
The main difference being that one specializes for dictionary arguments, and the other for value arguments. But to me it seems odd to so strictly separate these two concerns.
I (perhaps naively) assume we could get compile time and maintenance benefits from this in the long run.
- We no longer need to traverse the AST twice.
- We would produce less code in some situations. Currently if we specialize
elem @(Eq Int) (I# 1#) xs
we will first specialise for the dictionary. And then do another specialization for the term argument later one. When we could do both in one go. - We can avoid re-implementing cross-cutting concerns like !8666 (merged) twice for both passes.
That being said doing such a refactor does seem like no small feat. And I have no plans to tackle this in the near future. But it seems like it would be the right thing to do to me.