Merge lp:~zorba-coders/zorba/hof-next into lp:zorba

Proposed by Markos Zaharioudakis
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: 11328
Merged at revision: 11325
Proposed branch: lp:~zorba-coders/zorba/hof-next
Merge into: lp:zorba
Diff against target: 341 lines (+88/-121)
4 files modified
src/compiler/translator/translator.cpp (+86/-70)
test/fots/CMakeLists.txt (+0/-1)
test/rbkt/Queries/w3c_known_failures.txt (+1/-50)
test/rbkt/Queries/w3c_known_failures_XQueryX.txt (+1/-0)
To merge this branch: bzr merge lp:~zorba-coders/zorba/hof-next
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Review via email: mp+155722@code.launchpad.net

Commit message

fixed function coersion

Description of the change

fixed function coersion

To post a comment you must log in.
Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/hof-next into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:275 (message):
  Validation queue job hof-next-2013-03-27T12-45-54.501Z is finished. The
  final status was:

  2 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

lp:~zorba-coders/zorba/hof-next updated
11327. By Markos Zaharioudakis

added expected w3c failure

11328. By Markos Zaharioudakis

added expected w3c failure

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job hof-next-2013-03-27T15-58-53.589Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/compiler/translator/translator.cpp'
2--- src/compiler/translator/translator.cpp 2013-03-27 09:32:22 +0000
3+++ src/compiler/translator/translator.cpp 2013-03-27 15:43:22 +0000
4@@ -1517,14 +1517,21 @@
5 PROMOTE_FUNC_PARAM,
6 func->getName());
7 }
8+ else if (paramType->type_kind() == XQType::FUNCTION_TYPE_KIND)
9+ {
10+ // function coercion
11+ argExpr = wrap_in_coercion(paramType, argExpr, loc);
12+
13+ xqtref_t cardType = tm->create_any_item_type(paramType->get_quantifier());
14+
15+ argExpr = wrap_in_type_match(argExpr,
16+ cardType,
17+ loc,
18+ TREAT_FUNC_PARAM,
19+ func->getName());
20+ }
21 else
22 {
23- if (paramType->type_kind() == XQType::FUNCTION_TYPE_KIND)
24- {
25- // function coercion
26- argExpr = wrap_in_coercion(paramType, argExpr, loc, theCCB);
27- }
28-
29 argExpr = wrap_in_type_match(argExpr,
30 paramType,
31 loc,
32@@ -1538,83 +1545,94 @@
33
34
35 /*******************************************************************************
36+ The coersion expr is a flwor that looks like this:
37+
38+ for $fi in argExpr
39+ return function($p1 as t1, ... $pn as tn) { $fi(p1, ..., pn) }
40
41 ********************************************************************************/
42 expr* wrap_in_coercion(
43 xqtref_t targetType,
44- expr* theExpr,
45- const QueryLoc& loc,
46- CompilerCB* theCCB,
47- bool is_func_return = false)
48+ expr* argExpr,
49+ const QueryLoc& loc)
50 {
51- const FunctionXQType* func_type = static_cast<const FunctionXQType*>(targetType.getp());
52-
53- // Create the dynamic call body
54-
55- function_item_expr* fiExpr =
56+ const FunctionXQType* funcType =
57+ static_cast<const FunctionXQType*>(targetType.getp());
58+
59+ xqtref_t returnType = funcType->get_return_type();
60+
61+ push_scope();
62+
63+ flwor_expr* coersionFlwor = CREATE(flwor)(theRootSctx, theUDF, loc, false);
64+ for_clause* fiClause = wrap_in_forclause(argExpr, NULL);
65+ var_expr* fiVar = fiClause->get_var();
66+ coersionFlwor->add_clause(fiClause);
67+
68+ function_item_expr* inlineFuncExpr =
69 CREATE(function_item)(theRootSctx, theUDF, loc, true, false, true);
70
71- push_nodestack(fiExpr);
72-
73- push_scope();
74-
75- // handle the function item expression
76- flwor_expr* fnItem_flwor = CREATE(flwor)(theRootSctx, theUDF, loc, false);
77- for_clause* fnItem_fc = wrap_in_forclause(theExpr, NULL);
78- var_expr* fnItem_var = fnItem_fc->get_var();
79- fnItem_flwor->add_clause(fnItem_fc);
80- var_expr* inner_subst_var = bind_var(loc, fnItem_var->get_name(), var_expr::hof_var);
81- fiExpr->add_variable(fnItem_var, inner_subst_var, fnItem_var->get_name(), 0 /*var is not global*/);
82-
83- // bind the function item variable in the inner flwor
84- flwor_expr* inner_flwor = CREATE(flwor)(theRootSctx, theUDF, loc, false);
85-
86- // Handle parameters. For each parameter, a let binding is added to the inner flwor.
87+ coersionFlwor->set_return_expr(inlineFuncExpr);
88+
89+ var_expr* fiSubstVar = bind_var(loc, fiVar->get_name(), var_expr::hof_var);
90+
91+ inlineFuncExpr->add_variable(fiVar, fiSubstVar, fiVar->get_name(), 0);
92+
93+ // Create the inline udf obj.
94+ user_function_t inlineUDF =
95+ new user_function(loc,
96+ signature(function_item_expr::create_inline_fname(loc),
97+ funcType->get_param_types(),
98+ returnType),
99+ NULL,
100+ SIMPLE_EXPR,
101+ theCCB);
102+
103+ inlineFuncExpr->set_function(inlineUDF);
104+
105+ std::vector<var_expr*> argVars;
106 std::vector<expr*> arguments; // Arguments to the dynamic function call
107- for(csize i = 0; i < func_type->get_number_params(); i++)
108- {
109- xqtref_t paramType = func_type->operator[](i);
110-
111- var_expr* arg_var = create_temp_var(loc, var_expr::arg_var);
112- var_expr* subst_var = bind_var(loc, arg_var->get_name(), var_expr::let_var);
113- let_clause* lc = wrap_in_letclause(&*arg_var, subst_var);
114-
115- arg_var->set_param_pos(inner_flwor->num_clauses());
116- arg_var->set_type(paramType);
117-
118- inner_flwor->add_clause(lc);
119-
120- arguments.push_back(CREATE(wrapper)(theRootSctx, theUDF, loc, subst_var));
121- }
122-
123- if (inner_flwor->num_clauses() == 0)
124- {
125- inner_flwor = NULL;
126+ csize numParams = funcType->get_number_params();
127+ for(csize i = 0; i < numParams; ++i)
128+ {
129+ xqtref_t paramType = funcType->operator[](i);
130+
131+ var_expr* argVar = create_temp_var(loc, var_expr::arg_var);
132+ argVar->set_param_pos(i);
133+ argVar->set_type(paramType);
134+ argVars.push_back(argVar);
135+
136+ expr* arg = CREATE(wrapper)(theRootSctx, theUDF, loc, argVar);
137+ arg = normalize_fo_arg(i, arg, inlineUDF, loc);
138+ arguments.push_back(arg);
139 }
140
141 expr* body =
142 CREATE(dynamic_function_invocation)(theRootSctx,
143 theUDF,
144 loc,
145- CREATE(wrapper)(theRootSctx, theUDF, loc, inner_subst_var),
146+ CREATE(wrapper)(theRootSctx, theUDF, loc,
147+ fiSubstVar),
148 arguments,
149 NULL);
150
151- create_inline_function(body,
152- inner_flwor,
153- func_type->get_param_types(),
154- func_type->get_return_type(),
155- loc,
156- true);
157+ if (returnType->isBuiltinAtomicAny())
158+ {
159+ body = wrap_in_type_promotion(body, returnType, PROMOTE_TYPE_PROMOTION);
160+ }
161+ else
162+ {
163+ body = wrap_in_type_match(body, returnType, loc, TREAT_TYPE_MATCH);
164+ }
165
166- theExpr = pop_nodestack();
167- fnItem_flwor->set_return_expr(theExpr);
168- theExpr = fnItem_flwor;
169+ inlineUDF->setBody(body);
170+ inlineUDF->setScriptingKind(body->get_scripting_detail());
171+ inlineUDF->setArgVars(argVars);
172+ inlineUDF->setOptimized(true);
173
174 // pop the scope.
175 pop_scope();
176
177- return theExpr;
178+ return coersionFlwor;
179 }
180
181
182@@ -3984,7 +4002,7 @@
183 // Wrap in coercion if the return type is a function item
184 if (returnType->type_kind() == XQType::FUNCTION_TYPE_KIND)
185 {
186- body = wrap_in_coercion(returnType, body, loc, theCCB, true);
187+ body = wrap_in_coercion(returnType, body, loc);
188 }
189
190 // If function has any params, they have been wraped in a flwor expr. Set the
191@@ -12069,7 +12087,7 @@
192 }
193 }
194
195- create_inline_function(body, flwor, paramTypes, returnType, loc, false);
196+ create_inline_function(body, flwor, paramTypes, returnType, loc);
197
198 // pop the scope.
199 pop_scope();
200@@ -12084,8 +12102,7 @@
201 flwor_expr* flwor,
202 const std::vector<xqtref_t>& paramTypes,
203 xqtref_t returnType,
204- const QueryLoc& loc,
205- bool is_coercion)
206+ const QueryLoc& loc)
207 {
208 std::vector<var_expr*> argVars;
209
210@@ -12131,11 +12148,10 @@
211 // invoked in many other places, it is not possible to perform function
212 // call normalization. Instead the domain expressions of arg vars is
213 // wrapped in type matches.
214- if (!is_coercion)
215- letClause->set_expr(normalize_fo_arg(i,
216- letClause->get_expr(),
217- udf.getp(),
218- loc));
219+ letClause->set_expr(normalize_fo_arg(i,
220+ letClause->get_expr(),
221+ udf.getp(),
222+ loc));
223 }
224 }
225
226
227=== modified file 'test/fots/CMakeLists.txt'
228--- test/fots/CMakeLists.txt 2013-03-27 09:26:16 +0000
229+++ test/fots/CMakeLists.txt 2013-03-27 15:43:22 +0000
230@@ -643,7 +643,6 @@
231 EXPECTED_FOTS_FAILURE (fn-function-lookup fn-function-lookup-528 0)
232 EXPECTED_FOTS_FAILURE (fn-map-pairs fn-map-pairs-026 0)
233 EXPECTED_FOTS_FAILURE (misc-HigherOrderFunctions hof-036 0)
234-EXPECTED_FOTS_FAILURE (misc-HigherOrderFunctions hof-919 0)
235 EXPECTED_FOTS_FAILURE (misc-HigherOrderFunctions xqhof12 0)
236 EXPECTED_FOTS_FAILURE (misc-HigherOrderFunctions xqhof14 0)
237 EXPECTED_FOTS_FAILURE (misc-HigherOrderFunctions xqhof15 0)
238
239=== modified file 'test/rbkt/Queries/w3c_known_failures.txt'
240--- test/rbkt/Queries/w3c_known_failures.txt 2013-03-15 08:22:41 +0000
241+++ test/rbkt/Queries/w3c_known_failures.txt 2013-03-27 15:43:22 +0000
242@@ -4,34 +4,17 @@
243 test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFLWORExpr/ST-PITest-01
244 test/rbkt/w3c_testsuite/XQuery/StaticTyping/STFunctions/ST-Data001
245 test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-013
246-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-006
247-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-012
248-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-009
249-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-001
250-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-008
251-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-011
252-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-002
253-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-004
254-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-005
255-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-003
256-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-010
257-test/rbkt/w3c_testsuite/XQuery/Basics/EQNames/eqname-007
258+test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-044
259 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-904
260 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-031
261 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-037
262 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-047
263-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-007
264-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-028
265-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-018
266 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-036
267 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-008
268 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-024
269 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-046
270 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-038
271-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-049
272-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-017
273 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-913
274-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-021
275 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-015
276 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-029
277 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-039
278@@ -39,7 +22,6 @@
279 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-915
280 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-916
281 test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-030
282-test/rbkt/w3c_testsuite/XQuery/Expressions/HigherOrder/hof-009
283 test/rbkt/w3c_testsuite/XQuery/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-7
284 test/rbkt/w3c_testsuite/XQuery/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-8
285 test/rbkt/w3c_testsuite/XQuery/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-10
286@@ -48,43 +30,12 @@
287 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-001
288 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-002
289 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-007
290-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-902
291-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-004
292-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-901
293-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-903
294-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-005
295-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-006
296-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Map/map-003
297-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-903
298-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-902
299-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-004
300-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-005
301-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-003
302-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-901
303-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/Filter/filter-002
304-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-004
305-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-003
306-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-009
307-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-002
308-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-005
309-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-008
310-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldLeft/fold-left-001
311-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-004
312 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-001
313 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-002
314 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-005
315 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-003
316 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-006
317 test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/FoldRight/fold-right-007
318-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-007
319-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-005
320-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-001
321-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-902
322-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-003
323-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-006
324-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-901
325-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-002
326-test/rbkt/w3c_testsuite/XQuery/Functions/HigherOrder/MapPairs/map-pairs-008
327 test/rbkt/w3c_testsuite/XQuery/FunctX/functx-fn-tokenize/functx-fn-tokenize-all
328 test/rbkt/w3c_testsuite/XQuery/FunctX/functx-fn-tokenize/functx-fn-tokenize-7
329 test/rbkt/w3c_testsuite/XQuery/Functions/AllStringFunc/MatchStringFunc/MatchesFunc/K2-MatchesFunc-5
330
331=== modified file 'test/rbkt/Queries/w3c_known_failures_XQueryX.txt'
332--- test/rbkt/Queries/w3c_known_failures_XQueryX.txt 2013-03-15 08:22:41 +0000
333+++ test/rbkt/Queries/w3c_known_failures_XQueryX.txt 2013-03-27 15:43:22 +0000
334@@ -11,6 +11,7 @@
335 test/rbkt/w3c_testsuite/XQueryX/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-7
336 test/rbkt/w3c_testsuite/XQueryX/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-8
337 test/rbkt/w3c_testsuite/XQueryX/Expressions/Construct/DirectConElem/DirectConElemContent/Constr-cont-nsmode-10
338+test/rbkt/w3c_testsuite/XQueryX/Expressions/HigherOrder/hof-044
339 test/rbkt/w3c_testsuite/XQueryX/Expressions/HigherOrder/hof-009
340 test/rbkt/w3c_testsuite/XQueryX/Expressions/HigherOrder/hof-008
341 test/rbkt/w3c_testsuite/XQueryX/Expressions/HigherOrder/hof-021

Subscribers

People subscribed via source and target branches