-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Precompute debug operations info in linear time (#3038)
After * #2973 let-folding stopped being linear in the size of the input program. All transformations should be linear whenever possible. This PR makes let-folding linear again.
- Loading branch information
Showing
3 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
module Juvix.Compiler.Core.Info.DebugOpsInfo where | ||
|
||
import Juvix.Compiler.Core.Extra | ||
import Juvix.Compiler.Core.Info qualified as Info | ||
|
||
newtype DebugOpsInfo = DebugOpsInfo | ||
{ _infoHasDebugOps :: Bool | ||
} | ||
|
||
instance IsInfo DebugOpsInfo | ||
|
||
kDebugOpsInfo :: Key DebugOpsInfo | ||
kDebugOpsInfo = Proxy | ||
|
||
makeLenses ''DebugOpsInfo | ||
|
||
-- | Computes debug operations info for each subnode. | ||
computeDebugOpsInfo :: Node -> Node | ||
computeDebugOpsInfo = umap go | ||
where | ||
go :: Node -> Node | ||
go node | ||
| isDebugOp node = | ||
modifyInfo (Info.insert (DebugOpsInfo True)) node | ||
| otherwise = | ||
modifyInfo (Info.insert dbi) node | ||
where | ||
dbi = | ||
DebugOpsInfo | ||
. or | ||
. map (hasDebugOps . (^. childNode)) | ||
$ children node | ||
|
||
getDebugOpsInfo :: Node -> DebugOpsInfo | ||
getDebugOpsInfo = fromJust . Info.lookup kDebugOpsInfo . getInfo | ||
|
||
hasDebugOps :: Node -> Bool | ||
hasDebugOps = (^. infoHasDebugOps) . getDebugOpsInfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters