Matthias Brantner has proposed merging lp:~zorba-coders/zorba/bug-1026250 into 
lp:zorba.

Requested reviews:
  Matthias Brantner (matthias-brantner)

For more details, see:
https://code.launchpad.net/~zorba-coders/zorba/bug-1026250/+merge/138044
-- 
https://code.launchpad.net/~zorba-coders/zorba/bug-1026250/+merge/138044
Your team Zorba Coders is subscribed to branch lp:zorba.
=== modified file 'include/zorba/pregenerated/diagnostic_list.h'
--- include/zorba/pregenerated/diagnostic_list.h	2012-11-12 16:17:02 +0000
+++ include/zorba/pregenerated/diagnostic_list.h	2012-12-05 01:28:26 +0000
@@ -640,6 +640,8 @@
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0036_NON_ROOT_NODE_DELETION;
 
+extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDDY0037_CONCURRENT_MODIFICATION;
+
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDST0001_COLLECTION_ALREADY_DECLARED;
 
 extern ZORBA_DLL_PUBLIC ZorbaErrorCode ZDST0002_COLLECTION_ALREADY_IMPORTED;

=== modified file 'modules/com/zorba-xquery/www/modules/pregenerated/errors.xq'
--- modules/com/zorba-xquery/www/modules/pregenerated/errors.xq	2012-11-08 05:38:30 +0000
+++ modules/com/zorba-xquery/www/modules/pregenerated/errors.xq	2012-12-05 01:28:26 +0000
@@ -566,6 +566,10 @@
 
 (:~
 :)
+declare variable $zerr:ZDDY0037 as xs:QName := fn:QName($zerr:NS, "zerr:ZDDY0037");
+
+(:~
+:)
 declare variable $zerr:ZDST0001 as xs:QName := fn:QName($zerr:NS, "zerr:ZDST0001");
 
 (:~

=== modified file 'src/compiler/codegen/plan_visitor.cpp'
--- src/compiler/codegen/plan_visitor.cpp	2012-10-29 11:41:36 +0000
+++ src/compiler/codegen/plan_visitor.cpp	2012-12-05 01:28:26 +0000
@@ -883,6 +883,9 @@
 
   if (v.is_sequential())
   {
+    pragma* pr = 0;
+    theCCB->lookup_pragma(&v, "materialize", pr);
+
     if (!isGeneral)
     {
       if (v.has_sequential_clauses())
@@ -929,17 +932,11 @@
         }
       }
 
-      // Note: a materialize clause may exist already in case plan serialization
-      // is on (see comment in materialize_clause::clone)
-      if (!isGeneral &&
-          v.get_return_expr()->is_sequential() &&
-          v.get_clause(numClauses-1)->get_kind() != flwor_clause::materialize_clause &&
-          (v.get_order_clause() != NULL || v.get_group_clause() == NULL))
+      if (pr)
       {
         materialize_clause* mat =
         theCCB->theEM->create_materialize_clause(v.get_sctx(),
                                                  v.get_return_expr()->get_loc());
-
         v.add_clause(mat);
         ++numClauses;
       }
@@ -975,7 +972,7 @@
               ++numForClauses;
           }
 
-          if (domExpr->is_sequential())
+          if (pr && domExpr->is_sequential())
           {
             if (k == flwor_clause::for_clause ||
                 k == flwor_clause::window_clause ||

=== modified file 'src/compiler/expression/flwor_expr.cpp'
--- src/compiler/expression/flwor_expr.cpp	2012-10-26 07:13:42 +0000
+++ src/compiler/expression/flwor_expr.cpp	2012-12-05 01:28:26 +0000
@@ -699,7 +699,7 @@
     expr::substitution_t& subst) const
 {
   // we will reach here under the following scenario:
-  // 1. We do plan seriazation
+  // 1. We do plan serialization
   // 2. getPlan is called on udf A; this causes a mat clause to be created
   //    during the codegen on A's body
   // 3. getPlan is called on udf B, which invokes A, and A's body is

=== modified file 'src/compiler/translator/translator.cpp'
--- src/compiler/translator/translator.cpp	2012-11-20 18:17:10 +0000
+++ src/compiler/translator/translator.cpp	2012-12-05 01:28:26 +0000
@@ -2331,6 +2331,31 @@
 }
 
 
+/*******************************************************************************
+********************************************************************************/
+void
+recognizePragma(expr* e, const zstring& aLocalName)
+{
+  for (std::vector<pragma*>::const_iterator lIter = theScopedPragmas.begin();
+       lIter != theScopedPragmas.end();
+       ++lIter)
+  {
+    pragma* p = *lIter;
+    if (p->theQName->getNamespace() == ZORBA_EXTENSIONS_NS)
+    {
+      if (p->theQName->getLocalName() == aLocalName)
+      {
+        e->get_ccb()->add_pragma(e, p);
+        e->setContainsPragma(ANNOTATION_TRUE);
+        break;
+      }
+    }
+  }
+}
+
+
+
+
 /////////////////////////////////////////////////////////////////////////////////
 //                                                                             //
 //  Module, VersionDecl, MainModule, LibraryModule, ModuleDecl                 //
@@ -6290,6 +6315,8 @@
 
   theFlworClausesStack.resize(curClausePos);
 
+  recognizePragma(flwor, "materialize");
+
   push_nodestack(flwor);
 }
 

=== modified file 'src/diagnostics/diagnostic_en.xml'
--- src/diagnostics/diagnostic_en.xml	2012-12-01 01:04:39 +0000
+++ src/diagnostics/diagnostic_en.xml	2012-12-05 01:28:26 +0000
@@ -2255,6 +2255,10 @@
       <value>attempt to delete non-root node from collection "$1"</value>
     </diagnostic>
 
+    <diagnostic code="ZDDY0037" name="CONCURRENT_MODIFICATION">
+      <value>"$1": collection was modified while reading</value>
+    </diagnostic>
+
     <diagnostic code="ZDST0001" name="COLLECTION_ALREADY_DECLARED">
       <value>"$1": collection already declared</value>
     </diagnostic>

=== modified file 'src/diagnostics/pregenerated/diagnostic_list.cpp'
--- src/diagnostics/pregenerated/diagnostic_list.cpp	2012-11-12 16:17:02 +0000
+++ src/diagnostics/pregenerated/diagnostic_list.cpp	2012-12-05 01:28:26 +0000
@@ -939,6 +939,9 @@
 ZorbaErrorCode ZDDY0036_NON_ROOT_NODE_DELETION( "ZDDY0036" );
 
 
+ZorbaErrorCode ZDDY0037_CONCURRENT_MODIFICATION( "ZDDY0037" );
+
+
 ZorbaErrorCode ZDST0001_COLLECTION_ALREADY_DECLARED( "ZDST0001" );
 
 

=== modified file 'src/diagnostics/pregenerated/dict_en.cpp'
--- src/diagnostics/pregenerated/dict_en.cpp	2012-12-01 01:04:39 +0000
+++ src/diagnostics/pregenerated/dict_en.cpp	2012-12-05 01:28:26 +0000
@@ -378,6 +378,7 @@
   { "ZDDY0034", "\"$1\": index range-value probe has search keys with incompatible types" },
   { "ZDDY0035", "\"$1\": index inserting more than one key not allowed for general index" },
   { "ZDDY0036", "attempt to delete non-root node from collection \"$1\"" },
+  { "ZDDY0037", "\"$1\": collection was modified while reading" },
   { "ZDST0001", "\"$1\": collection already declared" },
   { "ZDST0002", "\"$1\": collection already imported into module \"$2\"" },
   { "ZDST0003", "\"$1\": collection declaration not allowed in main module" },

=== modified file 'src/store/naive/simple_collection.cpp'
--- src/store/naive/simple_collection.cpp	2012-09-19 21:16:15 +0000
+++ src/store/naive/simple_collection.cpp	2012-12-05 01:28:26 +0000
@@ -46,7 +46,8 @@
   theName(aName),
   theIsDynamic(isDynamic),
   theAnnotations(aAnnotations),
-  theNodeType(aNodeType)
+  theNodeType(aNodeType),
+  theVersion(0)
 {
   theId = GET_STORE().createCollectionId();
   theTreeIdGenerator = GET_STORE().getTreeIdGeneratorFactory().createTreeGenerator(0);
@@ -60,7 +61,8 @@
 SimpleCollection::SimpleCollection()
   : 
   theIsDynamic(false),
-  theNodeType(NULL)
+  theNodeType(NULL),
+  theVersion(0)
 {
   theTreeIdGenerator = GET_STORE().getTreeIdGeneratorFactory().createTreeGenerator(0);
 }
@@ -167,6 +169,8 @@
   else
 #endif
     node->setCollection(this, pos);
+
+  ++theVersion;
 }
 
 
@@ -275,6 +279,8 @@
     theXmlTrees[targetPos + i].transfer(items[i]);
   }
 
+  ++theVersion;
+
   return xs_integer(targetPos);
 }
 
@@ -332,6 +338,7 @@
 
     csize pos = to_xs_unsignedInt(position);
     theXmlTrees.erase(theXmlTrees.begin() + pos);
+    ++theVersion;
     return true;
   }
   else
@@ -382,6 +389,7 @@
     }
 
     theXmlTrees.erase(theXmlTrees.begin() + pos);
+    ++theVersion;
     return true;
   }
 }
@@ -440,6 +448,7 @@
       theXmlTrees.erase(theXmlTrees.begin() + pos);
     }
 
+    ++theVersion;
     return xs_integer(last - pos);
   }
 }
@@ -630,11 +639,14 @@
 ********************************************************************************/
 void SimpleCollection::CollectionIter::open()
 {
-  SYNC_CODE(theCollection->theLatch.rlock();)
+  //SYNC_CODE(theCollection->theLatch.rlock();)
   theHaveLock = true;
 
   theIterator = theCollection->theXmlTrees.begin();
   theEnd = theCollection->theXmlTrees.end();
+
+  theVersion = theCollection->theVersion;
+
   skip();
 }
 
@@ -644,6 +656,12 @@
 ********************************************************************************/
 bool SimpleCollection::CollectionIter::next(store::Item_t& result)
 {
+  if (theVersion != theCollection->theVersion)
+  {
+    throw ZORBA_EXCEPTION(zerr::ZDDY0037_CONCURRENT_MODIFICATION,
+    ERROR_PARAMS(theCollection->getName()->getStringValue()));
+  }
+
   if (!theHaveLock) 
   {
     throw ZORBA_EXCEPTION(zerr::ZDDY0019_COLLECTION_ITERATOR_NOT_OPEN,
@@ -670,6 +688,9 @@
 {
   theIterator = theCollection->theXmlTrees.begin();
   theEnd = theCollection->theXmlTrees.end();
+
+  theVersion = theCollection->theVersion;
+
   skip();
 }
 
@@ -681,7 +702,7 @@
 {
   assert(theHaveLock);
   theHaveLock = false;
-  SYNC_CODE(theCollection->theLatch.unlock();)
+  //SYNC_CODE(theCollection->theLatch.unlock();)
 }
 
 } // namespace simplestore

=== modified file 'src/store/naive/simple_collection.h'
--- src/store/naive/simple_collection.h	2012-09-19 21:16:15 +0000
+++ src/store/naive/simple_collection.h	2012-12-05 01:28:26 +0000
@@ -55,6 +55,7 @@
     checked_vector<store::Item_t>::iterator theEnd;
     bool                                    theHaveLock;
     xs_integer                              theSkip;
+    ulong                                   theVersion;
 
   public:
     CollectionIter(SimpleCollection* collection, 
@@ -82,6 +83,7 @@
   const std::vector<store::Annotation_t> theAnnotations;
 
   store::Item_t                          theNodeType;
+  ulong                                  theVersion;
 
   SYNC_CODE(Latch                        theLatch;)
 

=== removed file 'test/rbkt/ExpQueryResults/zorba/scripting/flwor2.xml.res'
--- test/rbkt/ExpQueryResults/zorba/scripting/flwor2.xml.res	2012-09-19 21:16:15 +0000
+++ test/rbkt/ExpQueryResults/zorba/scripting/flwor2.xml.res	1970-01-01 00:00:00 +0000
@@ -1,2 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-true

=== modified file 'test/rbkt/Queries/zorba/no-copy/dataguide-c.xq'
--- test/rbkt/Queries/zorba/no-copy/dataguide-c.xq	2012-10-08 12:09:36 +0000
+++ test/rbkt/Queries/zorba/no-copy/dataguide-c.xq	2012-12-05 01:28:26 +0000
@@ -2,6 +2,7 @@
   "http://www.zorba-xquery.com/modules/store/data-structures/unordered-map";;
 
 declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+declare namespace ext = "http://www.zorba-xquery.com/extensions";;
 
 declare %ann:assignable variable $co as xs:integer :=0;
 
@@ -30,11 +31,13 @@
   if(empty($x))
   then ()
   else
-    for $y in $x
-    let $n := node-name($y)
-    group by $n
-    order by string($n)
-    return local:collapseNodesSameName($y, $e, $s)
+    (# ext:materialize #) {
+      for $y in $x
+      let $n := node-name($y)
+      group by $n
+      order by string($n)
+      return local:collapseNodesSameName($y, $e, $s)
+    }
 };
 
 
@@ -43,6 +46,7 @@
     $e as xs:boolean, 
     $s as xs:string) as node()*
 {
+  (# ext:materialize #) {
   variable $label as xs:integer ?;
   variable $f:= $x[1];
   variable $n :=node-name($f);

=== modified file 'test/rbkt/Queries/zorba/scripting/flwor1.xq'
--- test/rbkt/Queries/zorba/scripting/flwor1.xq	2012-09-19 21:16:15 +0000
+++ test/rbkt/Queries/zorba/scripting/flwor1.xq	2012-12-05 01:28:26 +0000
@@ -2,6 +2,7 @@
 import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";;
 
 declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+declare namespace ext = "http://www.zorba-xquery.com/extensions";;
 
 declare variable $col := xs:QName("myCollection");
 
@@ -9,11 +10,13 @@
 {
   ddl:create($col, (<a></a>,<b></b>));
 
+  (# ext:materialize #) {
   for $x in dml:collection($col)
   return
     {
       dml:insert-nodes-last($col, <c></c>);
     }
+  };
 
   dml:collection($col)
 };

=== added file 'test/rbkt/Queries/zorba/scripting/flwor2.spec'
--- test/rbkt/Queries/zorba/scripting/flwor2.spec	1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/scripting/flwor2.spec	2012-12-05 01:28:26 +0000
@@ -0,0 +1,1 @@
+Error: http://www.zorba-xquery.com/errors:ZDDY0037

=== modified file 'test/rbkt/Queries/zorba/scripting/flwor6.xq'
--- test/rbkt/Queries/zorba/scripting/flwor6.xq	2012-09-19 21:16:15 +0000
+++ test/rbkt/Queries/zorba/scripting/flwor6.xq	2012-12-05 01:28:26 +0000
@@ -2,6 +2,7 @@
 import module namespace dml = "http://www.zorba-xquery.com/modules/store/dynamic/collections/dml";;
 
 declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+declare namespace ext = "http://www.zorba-xquery.com/extensions";;
 
 declare variable $col := xs:QName("myCollection");
 
@@ -9,6 +10,8 @@
 {
   ddl:create($col, (<a><c>1</c></a>,<b>2</b>));
 
+  (# ext:materialize #) {
+
   let $x := dml:collection($col)[1]/c
   for $i in (1 to count(dml:collection($col)) + 1)
   order by $i descending
@@ -18,6 +21,7 @@
       dml:insert-nodes-first($col, <x i="{$i}">{$x}-{$i}</x>);
       dml:insert-nodes-last($col, <x i="{$i}">{$x}-{$i}</x>);
     }
+  };
 
   dml:collection($col)
 };

=== modified file 'test/rbkt/Queries/zorba/updates/flwor1.xq'
--- test/rbkt/Queries/zorba/updates/flwor1.xq	2012-09-19 21:16:15 +0000
+++ test/rbkt/Queries/zorba/updates/flwor1.xq	2012-12-05 01:28:26 +0000
@@ -1,13 +1,16 @@
 declare namespace ann = "http://www.zorba-xquery.com/annotations";;
+declare namespace ext = "http://www.zorba-xquery.com/extensions";;
 
 declare %ann:sequential function local:test() 
 {
   let $indexHtmlDoc := <doc/>
   return 
-         {
-           for $module in (<m id="5"/>, <m id="2"/>, <m id="4"/>, <m id="1"/>)
-           order by $module/@id
-           return insert nodes <mi>{$module/@id}</mi> as last into $indexHtmlDoc;
+          {
+           (# ext:materialize #) {
+             for $module in (<m id="5"/>, <m id="2"/>, <m id="4"/>, <m id="1"/>)
+             order by $module/@id
+             return insert nodes <mi>{$module/@id}</mi> as last into $indexHtmlDoc
+           };
 
            $indexHtmlDoc
          }

-- 
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