From d5858d6dd2d194874f6923eed6e4c93e3243a9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20G=C3=A9rard?= Date: Mon, 14 Nov 2011 11:05:16 +0100 Subject: [PATCH] Optimize static evaluation It greatly reduce the amount of constraints kept. Indeed, all the constraints : x = x, x /y = x/y, etc were kept when x and y were local params. --- compiler/global/static.ml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/compiler/global/static.ml b/compiler/global/static.ml index b509564..d140697 100644 --- a/compiler/global/static.ml +++ b/compiler/global/static.ml @@ -75,7 +75,7 @@ let apply_op partial loc op se_list = in let sed_l, has_var = Misc.mapfold has_var_desc false se_list in if (op.qual = Pervasives) && not has_var - then ( + then ( (* concret evaluation *) match op.name, sed_l with | "+", [Sint n1; Sint n2] -> Sint (n1 + n2) | "-", [Sint n1; Sint n2] -> Sint (n1 - n2) @@ -99,11 +99,14 @@ let apply_op partial loc op se_list = | "~-.", [Sfloat f] -> Sfloat (-. f) | f,_ -> Misc.internal_error ("Static evaluation failed of the pervasive operator "^f) ) - else - if partial - then Sop(op, se_list) (* partial evaluation *) - else raise (Partial_evaluation (Unknown_op op, loc)) - + else ( (* symbolic evaluation *) + match op, sed_l with + | {qual = Pervasives; name = "=" }, [sed1;sed2] when sed1 = sed2 -> Sbool true + | _ -> + if partial + then Sop(op, se_list) (* partial evaluation *) + else raise (Partial_evaluation (Unknown_op op, loc)) + )