diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-06-02 13:12:11 -0400 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2017-06-02 13:12:13 -0400 |
commit | a786b136f48dfcf907dad55bcdbc4fcd247f2794 (patch) | |
tree | 9c6abee43aa398fdd8168b1cb7bd2d3fb5e6bacf /compiler/simplStg | |
parent | 811a2986475d88f73bb22b4600970039e1b582d6 (diff) | |
download | haskell-a786b136f48dfcf907dad55bcdbc4fcd247f2794.tar.gz |
Use lengthIs and friends in more places
While investigating #12545, I discovered several places in the code
that performed length-checks like so:
```
length ts == 4
```
This is not ideal, since the length of `ts` could be much longer than 4,
and we'd be doing way more work than necessary! There are already a slew
of helper functions in `Util` such as `lengthIs` that are designed to do
this efficiently, so I found every place where they ought to be used and
did just that. I also defined a couple more utility functions for list
length that were common patterns (e.g., `ltLength`).
Test Plan: ./validate
Reviewers: austin, hvr, goldfire, bgamari, simonmar
Reviewed By: bgamari, simonmar
Subscribers: goldfire, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3622
Diffstat (limited to 'compiler/simplStg')
-rw-r--r-- | compiler/simplStg/RepType.hs | 2 | ||||
-rw-r--r-- | compiler/simplStg/UnariseStg.hs | 2 |
2 files changed, 2 insertions, 2 deletions
diff --git a/compiler/simplStg/RepType.hs b/compiler/simplStg/RepType.hs index 91e4285341..2acc815125 100644 --- a/compiler/simplStg/RepType.hs +++ b/compiler/simplStg/RepType.hs @@ -155,7 +155,7 @@ ubxSumRepType constrs0 -- has at least two disjuncts. But it could happen if a user writes, e.g., -- forall (a :: TYPE (SumRep [IntRep])). ... -- which could never be instantiated. We still don't want to panic. - | length constrs0 < 2 + | constrs0 `lengthLessThan` 2 = [WordSlot] | otherwise diff --git a/compiler/simplStg/UnariseStg.hs b/compiler/simplStg/UnariseStg.hs index 3f67bc278f..2e8fbda02b 100644 --- a/compiler/simplStg/UnariseStg.hs +++ b/compiler/simplStg/UnariseStg.hs @@ -420,7 +420,7 @@ unariseAlts rho (MultiValAlt n) bndr [(DEFAULT, [], e)] unariseAlts rho (MultiValAlt n) bndr [(DataAlt _, ys, e)] | isUnboxedTupleBndr bndr = do (rho', ys1) <- unariseConArgBinders rho ys - MASSERT(n == length ys1) + MASSERT(ys1 `lengthIs` n) let rho'' = extendRho rho' bndr (MultiVal (map StgVarArg ys1)) e' <- unariseExpr rho'' e return [(DataAlt (tupleDataCon Unboxed n), ys1, e')] |