Skip to content

Commit a99abe9

Browse files
nanavatiquark17
authored andcommitted
Use Changed to improve performance and minimize allocation in the normtypes pass.
This is particularly important to preserve sharing of IType values when possible.
1 parent 85e1113 commit a99abe9

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

src/comp/INormTypes.hs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,32 @@ import Flags(Flags)
99

1010
import PreIds(idSizeOf)
1111
import ISyntax
12+
import Changed
1213
import IConv(iConvT)
1314
import SymTab
1415

1516
iNormTypes :: Flags -> SymTab -> IModule a -> IModule a
1617
iNormTypes flags symt = iNorm fullNorm
17-
where fullNorm c@(ITCon _ _ _) = c
18-
fullNorm n@(ITNum _) = n
19-
fullNorm s@(ITStr _) = s
20-
fullNorm v@(ITVar i) = v
21-
fullNorm (ITForAll i k t) = ITForAll i k $ fullNorm t
22-
fullNorm (ITAp f@(ITCon op _ _) a)
23-
| op == idSizeOf && canNorm a' = normalizeSizeOf $ ITAp f a'
24-
where a' = fullNorm a
18+
where fullNorm :: IType -> IType
19+
fullNorm t = changedOr t $ fullNorm' t
20+
21+
fullNorm' :: IType -> Changed IType
22+
fullNorm' tf@(ITForAll i k t) = changed1 (ITForAll i k) (fullNorm' t)
23+
fullNorm' (ITAp f@(ITCon op _ _) a)
24+
| op == idSizeOf && canNorm a' = Changed $ normalizeSizeOf $ ITAp f a'
25+
where -- Could use changedOr directly, but fullNorm does the right thing
26+
-- because we will normalize this type whether or not a changes
27+
a' = fullNorm a
2528
-- iToCT which we use below cannot handle ITVar and ITForAll
2629
canNorm (ITVar _) = False
2730
canNorm (ITForAll _ _ _) = False
2831
canNorm (ITAp f a) = canNorm f && canNorm a
2932
canNorm _ = True
30-
fullNorm t@(ITAp f a) = normITAp f' a'
31-
where f' = fullNorm f
32-
a' = fullNorm a
33+
fullNorm' t@(ITAp f a) = changed2 normITAp f a f' a'
34+
where f' = fullNorm' f
35+
a' = fullNorm' a
36+
fullNorm' _ = Unchanged
37+
3338
normalizeSizeOf t =
3439
let t' = iConvT flags symt $ iToCT t
3540
in case t' of

0 commit comments

Comments
 (0)