diff --git a/src/Juvix/Compiler/Core/Data/IdentDependencyInfo.hs b/src/Juvix/Compiler/Core/Data/IdentDependencyInfo.hs index 132abce630..a2b1fbedd8 100644 --- a/src/Juvix/Compiler/Core/Data/IdentDependencyInfo.hs +++ b/src/Juvix/Compiler/Core/Data/IdentDependencyInfo.hs @@ -97,11 +97,20 @@ recursiveIdentsClosure tab = chlds = fromJust $ HashMap.lookup sym graph -- | Complement of recursiveIdentsClosure +nonRecursiveReachableIdents' :: InfoTable -> HashSet Symbol +nonRecursiveReachableIdents' tab = + HashSet.difference + (HashSet.fromList (HashMap.keys (tab ^. infoIdentifiers))) + (recursiveIdentsClosure tab) + +nonRecursiveReachableIdents :: Module -> HashSet Symbol +nonRecursiveReachableIdents = nonRecursiveReachableIdents' . computeCombinedInfoTable + nonRecursiveIdents' :: InfoTable -> HashSet Symbol nonRecursiveIdents' tab = HashSet.difference (HashSet.fromList (HashMap.keys (tab ^. infoIdentifiers))) - (recursiveIdentsClosure tab) + (recursiveIdents' tab) nonRecursiveIdents :: Module -> HashSet Symbol nonRecursiveIdents = nonRecursiveIdents' . computeCombinedInfoTable diff --git a/src/Juvix/Compiler/Core/Transformation/Optimize/ConstantFolding.hs b/src/Juvix/Compiler/Core/Transformation/Optimize/ConstantFolding.hs index 5bf8c23bbb..97f7105947 100644 --- a/src/Juvix/Compiler/Core/Transformation/Optimize/ConstantFolding.hs +++ b/src/Juvix/Compiler/Core/Transformation/Optimize/ConstantFolding.hs @@ -75,7 +75,7 @@ constantFolding' opts nonRecSyms tab md = -- zero-order. For example, `3 + 4` is evaluated to `7`, and `id 3` is evaluated -- to `3`, but `id id` is not evaluated because the target type is not -- zero-order (it's a function type). This optimization is only applied to --- non-recursive symbols. +-- symbols from which no recursive symbols can be reached. -- -- References: -- - https://github.com/anoma/juvix/pull/2450 @@ -83,6 +83,6 @@ constantFolding' opts nonRecSyms tab md = constantFolding :: (Member (Reader CoreOptions) r) => Module -> Sem r Module constantFolding md = do opts <- ask - return $ constantFolding' opts (nonRecursiveIdents' tab) tab md + return $ constantFolding' opts (nonRecursiveReachableIdents' tab) tab md where tab = computeCombinedInfoTable md diff --git a/src/Juvix/Compiler/Core/Transformation/Optimize/Phase/Main.hs b/src/Juvix/Compiler/Core/Transformation/Optimize/Phase/Main.hs index a5bf3dfc5e..9a4ee89a24 100644 --- a/src/Juvix/Compiler/Core/Transformation/Optimize/Phase/Main.hs +++ b/src/Juvix/Compiler/Core/Transformation/Optimize/Phase/Main.hs @@ -21,10 +21,10 @@ optimize' opts@CoreOptions {..} md = . compose (6 * _optOptimizationLevel) ( doConstantFolding - . doSimplification 2 - . doInlining . doSimplification 1 . specializeArgs + . doSimplification 2 + . doInlining ) . doConstantFolding . letFolding @@ -36,13 +36,16 @@ optimize' opts@CoreOptions {..} md = nonRecs :: HashSet Symbol nonRecs = nonRecursiveIdents' tab + nonRecsReachable :: HashSet Symbol + nonRecsReachable = nonRecursiveReachableIdents' tab + doConstantFolding :: Module -> Module doConstantFolding md' = constantFolding' opts nonRecs' tab' md' where tab' = computeCombinedInfoTable md' nonRecs' - | _optOptimizationLevel > 1 = nonRecursiveIdents' tab' - | otherwise = nonRecs + | _optOptimizationLevel > 1 = nonRecursiveReachableIdents' tab' + | otherwise = nonRecsReachable doInlining :: Module -> Module doInlining md' = inlining' _optInliningDepth nonRecs' md' diff --git a/src/Juvix/Compiler/Core/Transformation/Optimize/SpecializeArgs.hs b/src/Juvix/Compiler/Core/Transformation/Optimize/SpecializeArgs.hs index 15516b5ab4..8f192cd754 100644 --- a/src/Juvix/Compiler/Core/Transformation/Optimize/SpecializeArgs.hs +++ b/src/Juvix/Compiler/Core/Transformation/Optimize/SpecializeArgs.hs @@ -225,7 +225,7 @@ convertNode = dmapLRM go fun = reLambdas lams' body'' letitem = mkLetItem - (ii ^. identifierName) + ("spec_" <> ii ^. identifierName) -- the type is not in the scope of the binder (shift (-1) ty') fun diff --git a/src/Juvix/Compiler/Internal/Translation/FromConcrete.hs b/src/Juvix/Compiler/Internal/Translation/FromConcrete.hs index a165db3dab..edef4b6bdf 100644 --- a/src/Juvix/Compiler/Internal/Translation/FromConcrete.hs +++ b/src/Juvix/Compiler/Internal/Translation/FromConcrete.hs @@ -555,7 +555,7 @@ deriveEq DerivingArgs {..} = do indInfo <- getIndInfo let argty = getArgType indInfo argsInfo <- goArgsInfo _derivingInstanceName - lamName <- Internal.freshFunVar (getLoc _derivingInstanceName) ("__eq__" <> _derivingInstanceName ^. Internal.nameText) + lamName <- Internal.freshFunVar (getLoc _derivingInstanceName) ("eq__" <> _derivingInstanceName ^. Internal.nameText) let lam = Internal.ExpressionIden (Internal.IdenFunction lamName) lamFun <- eqLambda lam indInfo argty lamTy <- Internal.ExpressionHole <$> Internal.freshHole (getLoc _derivingInstanceName)