|
2 | 2 | Copyright : (C) 2012-2016, University of Twente, |
3 | 3 | 2016-2017, Myrtle Software Ltd, |
4 | 4 | 2017-2018, Google Inc., |
| 5 | +<<<<<<< HEAD |
5 | 6 | 2021-2023, QBayLogic B.V. |
| 7 | +||||||| parent of 2ad5b613 (FIXED: Reduce constants to NF before specialisation [#3129](https://github.com/clash-lang/clash-compiler/issues/3129) (#3130)) |
| 8 | + 2021-2024, QBayLogic B.V. |
| 9 | +======= |
| 10 | + 2021-2026, QBayLogic B.V. |
| 11 | +>>>>>>> 2ad5b613 (FIXED: Reduce constants to NF before specialisation [#3129](https://github.com/clash-lang/clash-compiler/issues/3129) (#3130)) |
6 | 12 | License : BSD2 (see the file LICENSE) |
7 | 13 | Maintainer : QBayLogic B.V. <devops@qbaylogic.com> |
8 | 14 |
|
@@ -90,7 +96,7 @@ import Clash.Rewrite.Types |
90 | 96 | , typeTranslator, workFreeBinders, debugOpts, topEntities, specializationLimit) |
91 | 97 | import Clash.Rewrite.Util |
92 | 98 | ( mkBinderFor, mkDerivedName, mkFunction, mkTmBinderFor, setChanged, changed |
93 | | - , normalizeTermTypes, normalizeId) |
| 99 | + , normalizeTermTypes, normalizeId, whnfRW) |
94 | 100 | import Clash.Rewrite.WorkFree (isWorkFree) |
95 | 101 | import Clash.Normalize.Types |
96 | 102 | ( NormRewrite, NormalizeSession, specialisationCache, specialisationHistory) |
@@ -293,9 +299,17 @@ constantSpec ctx@(TransformContext is0 tfCtx) e@(App e1 e2) |
293 | 299 | = do specInfo<- constantSpecInfo ctx e2 |
294 | 300 | if csrFoundConstant specInfo then |
295 | 301 | let newBindings = csrNewBindings specInfo in |
296 | | - if null newBindings then |
297 | | - -- Whole of e2 is constant |
298 | | - specialize ctx (App e1 e2) |
| 302 | + if null newBindings then do |
| 303 | + -- Whole of e2 is constant, we reduce it here eagerly before specialization |
| 304 | + -- because we have observed long running compile times when having |
| 305 | + -- recursively defined constants, see: |
| 306 | + -- https://github.com/clash-lang/clash-compiler/issues/3129 |
| 307 | + e2Red <- case collectArgs e2 of |
| 308 | + (Prim p0, _) -> whnfRW False ctx e2 $ \_ctx1 e2Red -> case e2Red of |
| 309 | + (collectArgs -> (Prim p1, _)) | primName p0 == primName p1 -> return e2 |
| 310 | + _ -> changed e2Red |
| 311 | + _ -> return e2 |
| 312 | + specialize ctx (App e1 e2Red) |
299 | 313 | else do |
300 | 314 | -- Parts of e2 are constant |
301 | 315 | let is1 = extendInScopeSetList is0 (fst <$> csrNewBindings specInfo) |
|
0 commit comments