summaryrefslogtreecommitdiff
path: root/src/compiler/GF/Compile/Optimize.hs
diff options
context:
space:
mode:
authorhallgren <hallgren@chalmers.se>2012-11-13 14:09:15 +0000
committerhallgren <hallgren@chalmers.se>2012-11-13 14:09:15 +0000
commit27e675910a88fec3d7f0cc0ac6020d86f1089fe7 (patch)
treef6824b40c9873e1d5664ea5b98cc671104f7cd6b /src/compiler/GF/Compile/Optimize.hs
parent468464facae428ea5ba0ad053bb295cb94b8b51b (diff)
Adding a new experimental partial evalutator
GF.Compile.Compute.ConcreteNew + two new modules contain a new partial evaluator intended to solve some performance problems with the old partial evalutator in GF.Compile.Compute.ConcreteLazy. It has been around for a while, but is now complete enough to compile the RGL and the Phrasebook. The old partial evaluator is still used by default. The new one can be activated in two ways: - by using the command line option -new-comp when invoking GF. - by using cabal configure -fnew-comp to make -new-comp the default. In this case you can also use the command line option -old-comp to revert to the old partial evaluator. In the GF shell, the cc command uses the old evaluator regardless of -new-comp for now, but you can use "cc -new ..." to invoke the new evaluator. With -new-comp, computations happen in GF.Compile.GeneratePMCFG instead of GF.Compile.Optimize. This is implemented by testing the flag optNewComp in both modules, to omit calls to the old partial evaluator from GF.Compile.Optimize and add calls to the new partial evaluator in GF.Compile.GeneratePMCFG. This also means that -new-comp effectively implies -noexpand. In GF.Compile.CheckGrammar, there is a check that restricted inheritance is used correctly. However, when -noexpand is used, this check causes unexpected errors, so it has been converted to generate warnings, for now. -new-comp no longer enables the new type checker in GF.Compile.Typeckeck.ConcreteNew. The GF version number has been bumped to 3.3.10-darcs
Diffstat (limited to 'src/compiler/GF/Compile/Optimize.hs')
-rw-r--r--src/compiler/GF/Compile/Optimize.hs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/compiler/GF/Compile/Optimize.hs b/src/compiler/GF/Compile/Optimize.hs
index 635a1732c..0599ed85b 100644
--- a/src/compiler/GF/Compile/Optimize.hs
+++ b/src/compiler/GF/Compile/Optimize.hs
@@ -86,7 +86,7 @@ evalInfo opts sgr m c info = do
return $ CncFun mt pde' ppr' mpmcfg -- only cat in type actually needed
ResOper pty pde
- | OptExpand `Set.member` optim -> do
+ | not new && OptExpand `Set.member` optim -> do
pde' <- case pde of
Just (L loc de) -> do de <- computeConcrete gr de
return (Just (L loc (factor param c 0 de)))
@@ -95,6 +95,8 @@ evalInfo opts sgr m c info = do
_ -> return info
where
+ new = flag optNewComp opts -- computations moved to GF.Compile.GeneratePMCFG
+
gr = prependModule sgr m
optim = flag optOptimizations opts
param = OptParametrize `Set.member` optim
@@ -107,13 +109,17 @@ partEval opts gr (context, val) trm = errIn (render (text "partial evaluation" <
args = map Vr vars
subst = [(v, Vr v) | v <- vars]
trm1 = mkApp trm args
- trm2 <- computeTerm gr subst trm1
- trm3 <- if rightType trm2
- then computeTerm gr subst trm2
- else recordExpand val trm2 >>= computeTerm gr subst
+ trm2 <- if new then return trm1 else computeTerm gr subst trm1
+ trm3 <- if new
+ then return trm2
+ else if rightType trm2
+ then computeTerm gr subst trm2 -- compute twice??
+ else recordExpand val trm2 >>= computeTerm gr subst
trm4 <- checkPredefError gr trm3
return $ mkAbs [(Explicit,v) | v <- vars] trm4
where
+ new = flag optNewComp opts -- computations moved to GF.Compile.GeneratePMCFG
+
-- don't eta expand records of right length (correct by type checking)
rightType (R rs) = case val of
RecType ts -> length rs == length ts