Markos Zaharioudakis has proposed merging lp:~zorba-coders/zorba/markos-scratch 
into lp:zorba.

Requested reviews:
  Markos Zaharioudakis (markos-za)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/87879

fixed bug in no-copy rule + made zorba cmd use the for-serialization-only mode
-- 
https://code.launchpad.net/~zorba-coders/zorba/markos-scratch/+merge/87879
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'bin/zorbacmd.cpp'
--- bin/zorbacmd.cpp	2012-01-03 12:10:06 +0000
+++ bin/zorbacmd.cpp	2012-01-08 22:09:33 +0000
@@ -519,7 +519,7 @@
   lHints.for_serialization_only = true;
 
 #if ZORBACMD_LOAD_SYSTEM_PROPERTIES
-  if (!Properties::instance()->serializeOnlyQuery())
+  if (Properties::instance()->serializeOnlyQuery() == 0)
   {
     lHints.for_serialization_only = false;
   }

=== modified file 'src/compiler/rewriter/framework/rewriter_context.h'
--- src/compiler/rewriter/framework/rewriter_context.h	2012-01-03 12:10:06 +0000
+++ src/compiler/rewriter/framework/rewriter_context.h	2012-01-08 22:09:33 +0000
@@ -35,7 +35,6 @@
 typedef std::vector<var_expr*> IdVarMap;
 typedef std::map<const expr *, DynamicBitset> ExprVarsMap;
 
-typedef std::set<fo_expr*> UdfCalls;
 
 /*******************************************************************************
 
@@ -91,8 +90,6 @@
   std::vector<expr_t>          theFlworStack;
   std::vector<bool>            theInReturnClause;
 
-  UdfCalls                     theProcessedUDFCalls;
-
 public:
   RewriterContext(
       CompilerCB* cb,

=== modified file 'src/compiler/rewriter/rules/nodeid_rules.cpp'
--- src/compiler/rewriter/rules/nodeid_rules.cpp	2012-01-05 05:30:51 +0000
+++ src/compiler/rewriter/rules/nodeid_rules.cpp	2012-01-08 22:09:33 +0000
@@ -680,18 +680,34 @@
 
     if (f->isUdf())
     {
-      UdfCalls::iterator ite = rCtx.theProcessedUDFCalls.find(e);
-
-      if (ite == rCtx.theProcessedUDFCalls.end())
+      user_function* udf = static_cast<user_function*>(f);
+
+      UdfCalls::iterator ite = theProcessedUDFCalls.find(e);
+
+      if (ite == theProcessedUDFCalls.end())
       {
-        rCtx.theProcessedUDFCalls.insert(e);
-
-        user_function* udf = static_cast<user_function*>(f);
+        theProcessedUDFCalls.insert(e);
 
         UDFCallChain nextUdfCall(e, &udfCaller);
 
         applyInternal(rCtx, udf->getBody(), nextUdfCall);
       }
+      else
+      {
+        csize numArgs = e->num_args();
+        for (csize i = 0; i < numArgs; ++i)
+        {
+          var_expr* argVar = udf->getArgVar(i);
+
+          if (theSourceFinder->theVarSourcesMap.find(argVar) !=
+              theSourceFinder->theVarSourcesMap.end())
+          {
+            std::vector<expr*> sources;
+            theSourceFinder->findNodeSources(e->get_arg(i), &udfCaller, sources);
+            markSources(sources);
+          }
+        }
+      }
     } // f->isUdf()
     else
     {

=== modified file 'src/compiler/rewriter/rules/ruleset.h'
--- src/compiler/rewriter/rules/ruleset.h	2012-01-03 12:10:06 +0000
+++ src/compiler/rewriter/rules/ruleset.h	2012-01-08 22:09:33 +0000
@@ -129,8 +129,13 @@
 ********************************************************************************/
 class MarkNodeCopyProps : public RewriteRule 
 {
+  typedef std::set<fo_expr*> UdfCalls;
+
 protected:
-  SourceFinder  * theSourceFinder;
+  SourceFinder          * theSourceFinder;
+
+  UdfCalls                theProcessedUDFCalls;
+  //std::vector<fo_expr*>   theUdfCallPath;
 
 public:
   MarkNodeCopyProps() 

=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.cpp'
--- src/compiler/rewriter/tools/dataflow_annotations.cpp	2012-01-03 12:10:06 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.cpp	2012-01-08 22:09:33 +0000
@@ -878,8 +878,8 @@
         ite = (theVarSourcesMap.insert(VarSourcesPair(e, varSources))).first;
       }
 
-      std::vector<expr*>::iterator ite2 = (*ite).second.begin();
-      std::vector<expr*>::iterator end2 = (*ite).second.end();
+      std::vector<expr*>::const_iterator ite2 = (*ite).second.begin();
+      std::vector<expr*>::const_iterator end2 = (*ite).second.end();
       for (; ite2 != end2; ++ite2)
       {
         if (std::find(sources.begin(), sources.end(), *ite2) == sources.end())
@@ -911,6 +911,9 @@
       if (std::find(sources.begin(), sources.end(), node) == sources.end())
         sources.push_back(node);
 
+      std::vector<expr*> varSources;
+      theVarSourcesMap.insert(VarSourcesPair(e, varSources));
+
       return;
     }
 

=== modified file 'src/compiler/rewriter/tools/dataflow_annotations.h'
--- src/compiler/rewriter/tools/dataflow_annotations.h	2012-01-03 12:10:06 +0000
+++ src/compiler/rewriter/tools/dataflow_annotations.h	2012-01-08 22:09:33 +0000
@@ -71,6 +71,8 @@
 
 class SourceFinder
 {
+  friend class MarkNodeCopyProps;
+
   typedef std::map<var_expr*, std::vector<expr*> > VarSourcesMap;
   typedef std::pair<var_expr*, std::vector<expr*> > VarSourcesPair;
 

=== modified file 'src/functions/udf.h'
--- src/functions/udf.h	2012-01-03 12:10:06 +0000
+++ src/functions/udf.h	2012-01-08 22:09:33 +0000
@@ -167,6 +167,8 @@
 
   const std::vector<var_expr_t>& getArgVars() const;
 
+  var_expr* getArgVar(csize i) const { return theArgVars[i].getp(); }
+
   void setOptimized(bool v) { theIsOptimized = v; }
 
   bool isOptimized() const { return theIsOptimized; }

=== modified file 'src/system/zorba_properties.h'
--- src/system/zorba_properties.h	2012-01-03 12:10:06 +0000
+++ src/system/zorba_properties.h	2012-01-08 22:09:33 +0000
@@ -75,7 +75,7 @@
   bool theLoopHoisting;
   bool theInferJoins;
   bool theNoCopyOptim;
-  bool theSerializeOnlyQuery;
+  int theSerializeOnlyQuery;
   bool theTraceTranslator;
   bool theTraceCodegen;
   bool theTraceFulltext;
@@ -118,7 +118,7 @@
     theLoopHoisting = true;
     theInferJoins = true;
     theNoCopyOptim = true;
-    theSerializeOnlyQuery = false;
+    theSerializeOnlyQuery = -1;
     theTraceTranslator = false;
     theTraceCodegen = false;
     theTraceFulltext = false;
@@ -160,7 +160,7 @@
   const bool &loopHoisting () const { return theLoopHoisting; }
   const bool &inferJoins () const { return theInferJoins; }
   const bool &noCopyOptim() const { return theNoCopyOptim; }
-  const bool& serializeOnlyQuery() const { return theSerializeOnlyQuery; }
+  const int& serializeOnlyQuery() const { return theSerializeOnlyQuery; }
   const bool &traceTranslator () const { return theTraceTranslator; }
   const bool &traceCodegen () const { return theTraceCodegen; }
   const bool &traceFulltext () const { return theTraceFulltext; }
@@ -173,7 +173,8 @@
   const std::string &dotPlanFile () const { return theDotPlanFile; }
   const uint32_t &maxUdfCallDepth () const { return theMaxUdfCallDepth; }
 
-  std::string load_argv (int argc, const char **argv) {
+  std::string load_argv (int argc, const char **argv) 
+  {
     if (argv == NULL) return "";
 
     std::string result;
@@ -194,12 +195,14 @@
       else if (strcmp (*argv, "--optimizer") == 0 || strncmp (*argv, "-O", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }        init_val (*argv, theOptimizer, d);
+        if (*argv == NULL) { result = "No value given for --optimizer option"; break; }
+        init_val (*argv, theOptimizer, d);
       }
       else if (strcmp (*argv, "--result-file") == 0 || strncmp (*argv, "-o", 2) == 0) {
         int d = 2;
         if ((*argv) [1] == '-' || (*argv) [2] == '\0') { d = 0; ++argv; }
-        if (*argv == NULL) { result = "No value given for --result-file option"; break; }        init_val (*argv, theResultFile, d);
+        if (*argv == NULL) { result = "No value given for --result-file option"; break; }
+        init_val (*argv, theResultFile, d);
       }
       else if (strcmp (*argv, "--debug-file") == 0) {
         int d = 2;
@@ -368,7 +371,9 @@
     return result;
   }
 
-  const char *get_help_msg () const {
+
+  const char* get_help_msg() const 
+  {
     return
 "--trace-parsing, -p\ntrace parsing\n\n"
 "--trace-scanning, -s\ntrace scanning\n\n"
@@ -400,6 +405,8 @@
 "--inline-udf\ninline functions (1=enabled (default), 0=off)\n\n"
 "--loop-hoisting\nhoist expressions out of loops (1=enabled (default), 0=off)\n\n"
 "--infer-joins\ninfer joins (1=enabled (default), 0=off)\n\n"
+"--no-copy-optim\napply the no-copy optimization (1=enabled (default), 0=off)\n\n"
+"--serialize-only-query\nserialize-only-query (<0=unknown (default), 1=enabled, 0=off)\n\n"
 #ifndef NDEBUG
 "--trace-translator, -l\ntrace the translator\n\n"
 "--trace-codegen, -c\ntrace the codegenerator\n\n"
@@ -416,15 +423,16 @@
 ;
   }
 
-  static const ZorbaProperties *instance () {
+  static const ZorbaProperties* instance() 
+  {
     static ZorbaProperties result;
     return &result;
   }
 
-  ZorbaProperties () { initialize (); }
-  
+  ZorbaProperties() { initialize (); }
 };
 
+
 }   // namespaces
 
 #endif // ZORBA_ZORBAPROPERTIES

=== modified file 'test/apitest.cpp'
--- test/apitest.cpp	2012-01-03 12:10:06 +0000
+++ test/apitest.cpp	2012-01-08 22:09:33 +0000
@@ -112,7 +112,7 @@
 
   chints.for_serialization_only = false;
 
-  if (Properties::instance()->serializeOnlyQuery())
+  if (Properties::instance()->serializeOnlyQuery() > 0)
   {
     chints.for_serialization_only = true;
   }

=== added file 'test/rbkt/ExpQueryResults/zorba/no-copy/udfs2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/no-copy/udfs2.xml.res	1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/no-copy/udfs2.xml.res	2012-01-08 22:09:33 +0000
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+  - submitMessage [0]: xs:string(<submission><suite/></submission>)
+  - submitMessage [0]: xs:string(<submission><suite><test/></suite></submission>)

=== added file 'test/rbkt/Queries/zorba/no-copy/udfs2.xq'
--- test/rbkt/Queries/zorba/no-copy/udfs2.xq	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/no-copy/udfs2.xq	2012-01-08 22:09:33 +0000
@@ -0,0 +1,31 @@
+
+
+declare namespace opt = "http://www.zorba-xquery.com/options/optimizer";;
+
+declare option opt:enable "for-serialization-only";
+
+
+declare function local:dummy($x as xs:integer) as xs:integer
+{
+  $x
+};
+
+
+declare function local:submitMessage($msg)
+{   
+  local:dummy(2);
+
+  fn:trace(fn:serialize($msg), "  - submitMessage");
+};
+
+
+declare function local:publishResults($results)
+{   
+  for $rez in $results
+  return local:submitMessage(<submission>{ $rez/suite }</submission>)
+};
+
+
+local:publishResults(<rez><suite/></rez>);
+
+local:publishResults(<rez><suite>{ <test/> }</suite></rez>);

=== modified file 'test/rbkt/testdriver_common.cpp'
--- test/rbkt/testdriver_common.cpp	2012-01-03 12:10:06 +0000
+++ test/rbkt/testdriver_common.cpp	2012-01-08 22:09:33 +0000
@@ -190,7 +190,7 @@
 
   lHints.for_serialization_only = false;
 
-  if (zorba::Properties::instance()->serializeOnlyQuery())
+  if (zorba::Properties::instance()->serializeOnlyQuery() > 0)
   {
     lHints.for_serialization_only = true;
   }

-- 
Mailing list: https://launchpad.net/~zorba-coders
Post to     : zorba-coders@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zorba-coders
More help   : https://help.launchpad.net/ListHelp

Reply via email to