Skip to content

Commit b40ed9c

Browse files
committed
Merge main to refresh Ruby constructor CI
Signed-off-by: Martin Vogel <[email protected]>
2 parents 124ce0e + 3457b21 commit b40ed9c

5 files changed

Lines changed: 191 additions & 3 deletions

File tree

‎internal/cbm/extract_defs.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,33 @@ static TSNode resolve_lean_func_name(TSNode node, TSNode name) {
416416
return cbm_find_child_by_kind(node, "ident");
417417
}
418418

419+
// Haskell infix-form definition head (`a <+> b`, ``x `plus` y``): the defined
420+
// name is the operator, not the left operand that is the head's first child. A
421+
// backticked `infix_id` yields its inner variable (`plus`); a symbolic `operator`
422+
// is returned as-is and parenthesised by cbm_func_name_node_text, matching the
423+
// prefix form `(<+>) a b = ...` (#2440).
424+
static TSNode resolve_haskell_infix_head_name(TSNode head) {
425+
enum { INFIX_MIN_CHILDREN = 3, INFIX_OP_IDX = 1 };
426+
TSNode op = ts_node_child_by_field_name(head, TS_FIELD("operator"));
427+
if (ts_node_is_null(op) && ts_node_child_count(head) >= INFIX_MIN_CHILDREN) {
428+
op = ts_node_child(head, INFIX_OP_IDX);
429+
}
430+
if (!ts_node_is_null(op)) {
431+
const char *ok = ts_node_type(op);
432+
if (strcmp(ok, "operator") == 0) {
433+
return op;
434+
}
435+
if (strcmp(ok, "infix_id") == 0) {
436+
TSNode v = cbm_find_child_by_kind(op, "variable");
437+
if (!ts_node_is_null(v)) {
438+
return v;
439+
}
440+
}
441+
}
442+
TSNode null_node = {0};
443+
return null_node;
444+
}
445+
419446
// Haskell: resolve function name from first named child (variable/name).
420447
static TSNode resolve_haskell_func_name(TSNode node) {
421448
if (ts_node_named_child_count(node) > 0) {
@@ -424,6 +451,9 @@ static TSNode resolve_haskell_func_name(TSNode node) {
424451
if (strcmp(hk, "variable") == 0 || strcmp(hk, "name") == 0) {
425452
return head;
426453
}
454+
if (strcmp(hk, "infix") == 0) {
455+
return resolve_haskell_infix_head_name(head);
456+
}
427457
if (ts_node_named_child_count(head) > 0) {
428458
TSNode v = ts_node_named_child(head, 0);
429459
const char *vk = ts_node_type(v);

‎internal/cbm/helpers.c‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1213,6 +1213,14 @@ char *cbm_func_name_node_text(CBMArena *a, TSNode name_node, const char *source,
12131213
if (text && lang == CBM_LANG_NIX) {
12141214
cbm_nix_strip_attr_quotes(text);
12151215
}
1216+
/* Haskell infix-form operator definition: `a <+> b = …` resolves to the bare
1217+
* `operator` node `<+>`, while the prefix form `(<+>) a b = …` is named by its
1218+
* `prefix_id` text `(<+>)`. Parenthesise here, not in the resolver, so both
1219+
* forms mint the same name and the def name and the call-scope QN, which both
1220+
* route through this function, cannot disagree (#2440). */
1221+
if (text && lang == CBM_LANG_HASKELL && strcmp(ts_node_type(name_node), "operator") == 0) {
1222+
return cbm_arena_sprintf(a, "(%s)", text);
1223+
}
12161224
return text;
12171225
}
12181226

‎src/cypher/cypher.c‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2899,12 +2899,23 @@ static cyp_partial_t partial_or(cyp_partial_t l, cyp_partial_t r) {
28992899
: CYP_PARTIAL_UNKNOWN;
29002900
}
29012901

2902-
/* A condition whose alias is not bound yet is UNKNOWN; a literal-only LHS
2903-
* (func condition with no variable arg) has nothing to wait for. */
2902+
static bool partial_alias_unbound(binding_t *b, const char *alias) {
2903+
return alias && !binding_get(b, alias) && !binding_get_edge(b, alias);
2904+
}
2905+
2906+
/* A condition is UNKNOWN while any alias it reads is not bound yet: its own
2907+
* variable, and every function argument's -- a func condition is filed under
2908+
* its first argument's alias, so the b in coalesce(a.x, b.name) is only seen
2909+
* here. A literal-only LHS has nothing to wait for. */
29042910
static cyp_partial_t eval_condition_partial(const cbm_condition_t *c, binding_t *b) {
2905-
if (c->variable && !binding_get(b, c->variable) && !binding_get_edge(b, c->variable)) {
2911+
if (partial_alias_unbound(b, c->variable)) {
29062912
return CYP_PARTIAL_UNKNOWN;
29072913
}
2914+
for (int i = 0; i < c->arg_count; i++) {
2915+
if (partial_alias_unbound(b, c->args[i].variable)) {
2916+
return CYP_PARTIAL_UNKNOWN;
2917+
}
2918+
}
29082919
return eval_condition(c, b) ? CYP_PARTIAL_TRUE : CYP_PARTIAL_FALSE;
29092920
}
29102921

‎tests/test_cypher.c‎

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1917,6 +1917,32 @@ TEST(cypher_exists_has_outgoing_calls) {
19171917
ASSERT_EQ(rc, 0);
19181918
ASSERT_EQ(r.row_count, 2);
19191919
cbm_cypher_result_free(&r);
1920+
1921+
rc = cbm_cypher_execute(s,
1922+
"MATCH (a)-[:CALLS]->(b) WHERE b.name <> \"SubmitOrder\" "
1923+
"RETURN a.name, b.name",
1924+
"test", 0, &r);
1925+
ASSERT_EQ(rc, 0);
1926+
ASSERT_EQ(r.row_count, 2);
1927+
cbm_cypher_result_free(&r);
1928+
1929+
rc = cbm_cypher_execute(s,
1930+
"MATCH (a)-[:CALLS]->(b) WHERE b.name = \"SubmitOrder\" OR "
1931+
"NOT b.name = \"SubmitOrder\" RETURN count(*)",
1932+
"test", 0, &r);
1933+
ASSERT_EQ(rc, 0);
1934+
ASSERT_EQ(r.row_count, 1);
1935+
ASSERT_STR_EQ(r.rows[0][0], "3");
1936+
cbm_cypher_result_free(&r);
1937+
1938+
rc = cbm_cypher_execute(s,
1939+
"MATCH (a)-[:CALLS]->(b) WITH a, b WHERE NOT b.name = "
1940+
"\"SubmitOrder\" RETURN a.name, b.name",
1941+
"test", 0, &r);
1942+
ASSERT_EQ(rc, 0);
1943+
ASSERT_EQ(r.row_count, 2);
1944+
cbm_cypher_result_free(&r);
1945+
19201946
cbm_store_close(s);
19211947
PASS();
19221948
}
@@ -3378,6 +3404,86 @@ TEST(cypher_exec_where_mixed_alias_xor) {
33783404
PASS();
33793405
}
33803406

3407+
TEST(cypher_exec_where_not_target_node) {
3408+
cbm_store_t *s = setup_cypher_store();
3409+
cbm_cypher_result_t r = {0};
3410+
int rc = cbm_cypher_execute(s,
3411+
"MATCH (a)-[:CALLS]->(b) WHERE NOT b.name = \"SubmitOrder\" "
3412+
"RETURN a.name, b.name",
3413+
"test", 0, &r);
3414+
ASSERT_EQ(rc, 0);
3415+
ASSERT_EQ(r.row_count, 2);
3416+
cbm_cypher_result_free(&r);
3417+
cbm_store_close(s);
3418+
PASS();
3419+
}
3420+
3421+
TEST(cypher_exec_where_not_target_relationship) {
3422+
cbm_store_t *s = setup_cypher_multi_edge_store();
3423+
cbm_cypher_result_t r = {0};
3424+
int rc = cbm_cypher_execute(s,
3425+
"MATCH (a)-[r:HTTP_CALLS]->(b) WHERE NOT r.url_path = "
3426+
"\"/health\" RETURN r.url_path",
3427+
"testproj", 0, &r);
3428+
ASSERT_EQ(rc, 0);
3429+
ASSERT_EQ(r.row_count, 1);
3430+
ASSERT_STR_EQ(r.rows[0][0], "/api/orders");
3431+
cbm_cypher_result_free(&r);
3432+
cbm_store_close(s);
3433+
PASS();
3434+
}
3435+
3436+
TEST(cypher_exec_where_not_source_node) {
3437+
cbm_store_t *s = setup_cypher_store();
3438+
cbm_cypher_result_t r = {0};
3439+
int rc = cbm_cypher_execute(s,
3440+
"MATCH (a)-[:CALLS]->(b) WHERE NOT a.name = "
3441+
"\"HandleOrder\" RETURN a.name, b.name",
3442+
"test", 0, &r);
3443+
ASSERT_EQ(rc, 0);
3444+
ASSERT_EQ(r.row_count, 1);
3445+
ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");
3446+
cbm_cypher_result_free(&r);
3447+
cbm_store_close(s);
3448+
PASS();
3449+
}
3450+
3451+
TEST(cypher_exec_where_not_target_node_count) {
3452+
cbm_store_t *s = setup_cypher_store();
3453+
cbm_cypher_result_t r = {0};
3454+
int rc = cbm_cypher_execute(s,
3455+
"MATCH (a)-[:CALLS]->(b) WHERE NOT b.name = "
3456+
"\"SubmitOrder\" RETURN count(*)",
3457+
"test", 0, &r);
3458+
ASSERT_EQ(rc, 0);
3459+
ASSERT_EQ(r.row_count, 1);
3460+
ASSERT_STR_EQ(r.rows[0][0], "2");
3461+
cbm_cypher_result_free(&r);
3462+
cbm_store_close(s);
3463+
PASS();
3464+
}
3465+
3466+
/* The early WHERE pass must wait for every alias a condition reads. A function
3467+
* condition is filed under its first argument's alias, so in
3468+
* coalesce(a.no_such_prop, b.name) the target b hid behind the bound a: the
3469+
* seed row read coalesce(NULL, <unbound b>) as a definite mismatch and pruned
3470+
* every row before CALLS expansion, while the same predicate after WITH was
3471+
* right. */
3472+
TEST(cypher_exec_where_func_arg_on_unbound_target) {
3473+
cbm_store_t *s = setup_cypher_store();
3474+
cbm_cypher_result_t r = {0};
3475+
int rc = cbm_cypher_execute(s,
3476+
"MATCH (a)-[:CALLS]->(b) WHERE coalesce(a.no_such_prop, b.name) = "
3477+
"\"SubmitOrder\" RETURN a.name",
3478+
"test", 0, &r);
3479+
ASSERT_EQ(rc, 0);
3480+
ASSERT_EQ(r.row_count, 1);
3481+
ASSERT_STR_EQ(r.rows[0][0], "ValidateOrder");
3482+
cbm_cypher_result_free(&r);
3483+
cbm_store_close(s);
3484+
PASS();
3485+
}
3486+
33813487
TEST(cypher_exec_where_in) {
33823488
cbm_store_t *s = setup_cypher_store();
33833489
cbm_cypher_result_t r = {0};
@@ -6243,6 +6349,11 @@ SUITE(cypher) {
62436349
RUN_TEST(cypher_exec_where_mixed_alias_and);
62446350
RUN_TEST(cypher_exec_where_mixed_alias_or);
62456351
RUN_TEST(cypher_exec_where_mixed_alias_xor);
6352+
RUN_TEST(cypher_exec_where_not_target_node);
6353+
RUN_TEST(cypher_exec_where_not_target_relationship);
6354+
RUN_TEST(cypher_exec_where_not_source_node);
6355+
RUN_TEST(cypher_exec_where_not_target_node_count);
6356+
RUN_TEST(cypher_exec_where_func_arg_on_unbound_target);
62466357
RUN_TEST(cypher_exec_where_in);
62476358
RUN_TEST(cypher_exec_where_not_in);
62486359
RUN_TEST(cypher_exec_where_is_null);

‎tests/test_extraction.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1828,6 +1828,33 @@ TEST(haskell_function) {
18281828
PASS();
18291829
}
18301830

1831+
/* #2440: an infix-form definition (`a <+> b = ...`, ``x `plus` y = ...``) has
1832+
* no `name` field; its first named child is an `infix` node whose first child
1833+
* is the LEFT OPERAND, so the def was named `a` / `x`. It must be named after
1834+
* the operator, consistent with the prefix form `(<+>) a b = ...`. */
1835+
TEST(haskell_infix_definition_name) {
1836+
CBMFileResult *r = extract("module M where\n"
1837+
"\n"
1838+
"(<+>) :: Int -> Int -> Int\n"
1839+
"a <+> b = a + b\n"
1840+
"\n"
1841+
"plus :: Int -> Int -> Int\n"
1842+
"x `plus` y = x + y\n"
1843+
"\n"
1844+
"f :: Int\n"
1845+
"f = 1 <+> 2\n",
1846+
CBM_LANG_HASKELL, "t", "M.hs");
1847+
ASSERT_NOT_NULL(r);
1848+
ASSERT_FALSE(r->has_error);
1849+
ASSERT(has_def(r, "Function", "f"));
1850+
ASSERT(has_def(r, "Function", "plus"));
1851+
ASSERT(has_def(r, "Function", "(<+>)"));
1852+
ASSERT_FALSE(has_def(r, "Function", "a"));
1853+
ASSERT_FALSE(has_def(r, "Function", "x"));
1854+
cbm_free_result(r);
1855+
PASS();
1856+
}
1857+
18311858
/* --- OCaml --- */
18321859
TEST(ocaml_function) {
18331860
CBMFileResult *r =
@@ -13229,6 +13256,7 @@ SUITE(extraction) {
1322913256
RUN_TEST(elixir_function);
1323013257
RUN_TEST(elixir_call_string_argument);
1323113258
RUN_TEST(haskell_function);
13259+
RUN_TEST(haskell_infix_definition_name);
1323213260
RUN_TEST(ocaml_function);
1323313261
RUN_TEST(erlang_function);
1323413262

0 commit comments

Comments
 (0)