The app invariant says that the argument in an App must not be unlifted. This gets in the way of rule matching on functions with unlifted arguments (#19313 (closed)), and Simon PJ suggests that we may be better off without that invariant.
There is an analogous invariant on lets (hence “let-app-invariant”). He suggests to keep the let-invariant. (And I suggest to henceforce call it the “let-lifted-invariant” for more clarity.)
I’ll give it a shot and see what comes up.
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Yes, that’s my hope too. Also, we use smart constructors in most places, so enforcing an invariant there instead of here should not be hard. But we’ll see :-)
Removing the invariant on apps is easy, of course. The next problem is of course that much code in the simplifier assumes the app-invariant, especially when simplifying and possibly introducing lets, and it is not obvious to me where I should add branches that handle the needsCaseBinding case.
The starting point seems to be simplLam … (ApplyToVal …). From there we have the following chain of functions:
simplNonRecX
completeNonRecX
completeBind
tryCastWorkerWrapper
mkFloatBind
wrapFloats
And it seems any of them might be a candidate for “do something different”, and it is unclear to me which one should be it.
In particular: Do we want drop the (so far implicit) “float-invariant” as well, and keep these RHSs in floats (turning them into cases when we wrapFloats)? Or do we need to casify then earlier, and never let them be floats?
(Replacing Let with mkCoreLet in wrapFloats seems like the easiest, but I wonder if this might be wrong semantically, given that floats, well, “float” around.)
I think that the place to behave specially is in simplLam itself. Add an initial guard for an isUnliftedType argument. For that we want to behave very like case e of b -> blah. Something like
I’ll release the lock on this one, as I’ll be traveling without a laptop for a while now, and if someone wants to pick this up in the meantime, please do. Early experiments in !6865 (closed), but not much useful there yet.