From 44ea16e3eba6b8576e7536ee317a4e5324a81fb6 Mon Sep 17 00:00:00 2001 From: Zachary Snow Date: Wed, 1 May 2019 13:37:50 -0400 Subject: [PATCH] ensure, rather than check, traverseScopesM invariant (perf optimization) --- src/Convert/Traverse.hs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Convert/Traverse.hs b/src/Convert/Traverse.hs index e16af0e..49aaff6 100644 --- a/src/Convert/Traverse.hs +++ b/src/Convert/Traverse.hs @@ -977,14 +977,15 @@ traverseScopesM declMapper moduleItemMapper stmtMapper = redirectModuleItem item = moduleItemMapper item + -- This previously checked the invariant that the module item mappers + -- should not modify the state. Now we simply "enforce" it but resetting + -- the state to its previous value. Comparing the state, as we did + -- previously, incurs a noticeable performance hit. fullModuleItemMapper item = do prevState <- get item' <- redirectModuleItem item - currState <- get - if prevState == currState - then return item' - else error $ "illegal scope state modification: " - ++ show (prevState, item, currState, item') + put prevState + return item' -- applies the given decl conversion across the description, and then performs a -- scoped traversal for each ModuleItem in the description