Skip to content

Commit fb2e38f

Browse files
authored
Merge branch 'main' into fix/issue-1682-dotted-ts-imports
2 parents b3d7940 + 7808686 commit fb2e38f

48 files changed

Lines changed: 757399 additions & 462494 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/_security.yml‎

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,25 @@ jobs:
4242
runs-on: ubuntu-latest
4343
timeout-minutes: 240
4444
steps:
45-
- name: Wait for CodeQL on current commit (max 45 min)
45+
- name: Wait for CodeQL on current commit (max 150 min)
4646
env:
4747
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4848
run: |
4949
# On pull_request events github.sha is the synthetic merge commit;
5050
# CodeQL runs are recorded against the PR head SHA.
5151
CURRENT_SHA="${{ github.event.pull_request.head.sha || github.sha }}"
5252
echo "Waiting for CodeQL to complete on $CURRENT_SHA..."
53-
for attempt in $(seq 1 90); do
53+
# 300 attempts x 30s = 150 min. The previous budget was 90 x 30s = 45 min,
54+
# which is shorter than CodeQL actually takes on this repository: a measured
55+
# run on PR #1426 (head 7b72652a) completed with conclusion=success after
56+
# 124 min, 7 minutes AFTER this gate had already given up. That marked at
57+
# least five contributor PRs red for a scan that passed. The job's own
58+
# timeout-minutes is 240, so 150 still leaves headroom.
59+
for attempt in $(seq 1 300); do
5460
LATEST=$(gh api "repos/${{ github.repository }}/actions/workflows/codeql.yml/runs?head_sha=$CURRENT_SHA&per_page=1" \
5561
--jq '.workflow_runs[] | "\(.conclusion) \(.status)"' 2>/dev/null | head -1 || echo "")
5662
if [ -z "$LATEST" ]; then
57-
echo " $attempt/90: no run yet..."; sleep 30; continue
63+
echo " $attempt/300: no run yet..."; sleep 30; continue
5864
fi
5965
CONCLUSION=$(echo "$LATEST" | cut -d' ' -f1)
6066
STATUS=$(echo "$LATEST" | cut -d' ' -f2)
@@ -63,7 +69,7 @@ jobs:
6369
elif [ "$STATUS" = "completed" ]; then
6470
echo "BLOCKED: CodeQL $CONCLUSION"; exit 1
6571
fi
66-
echo " $attempt/90: $STATUS..."; sleep 30
72+
echo " $attempt/300: $STATUS..."; sleep 30
6773
done
6874
echo "BLOCKED: CodeQL timeout"; exit 1
6975

‎internal/cbm/extract_calls.c‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,65 @@ static char *extract_nickel_callee(CBMArena *a, TSNode node, const char *source,
11611161
return NULL;
11621162
}
11631163

1164+
// Pkl: `unqualifiedAccessExpr` / `qualifiedAccessExpr` are the same node whether
1165+
// they are a call (`helper(a)`) or a bare property read (`host`) — the only
1166+
// discriminator is an `argumentList` child, so both are gated on it. For a
1167+
// qualified call the method name is the `identifier` child that is not the
1168+
// `receiver`; the receiver is prefixed only when it is itself a plain name
1169+
// (`utils.fallback(a)` -> "utils.fallback", module-qualified, which cbm.c
1170+
// shortens to the last dotted segment when resolving). A receiver that is itself
1171+
// a call must NOT be prefixed: `s.trim().toLowerCase()` -> "toLowerCase", since
1172+
// the receiver's text carries parens and would never resolve.
1173+
// `newExpr` resolves to its `declaredType` so `new Server {}` links to the class.
1174+
static char *extract_pkl_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
1175+
if (strcmp(nk, "newExpr") == 0) {
1176+
// `new { ... }` with an inferred type has no declaredType child.
1177+
TSNode dt = cbm_find_child_by_kind(node, "declaredType");
1178+
return ts_node_is_null(dt) ? NULL : cbm_node_text(a, dt, source);
1179+
}
1180+
1181+
bool qualified = strcmp(nk, "qualifiedAccessExpr") == 0;
1182+
if (!qualified && strcmp(nk, "unqualifiedAccessExpr") != 0) {
1183+
return NULL;
1184+
}
1185+
// No argument list -> property read, not a call.
1186+
if (ts_node_is_null(cbm_find_child_by_kind(node, "argumentList"))) {
1187+
return NULL;
1188+
}
1189+
1190+
TSNode recv = ts_node_child_by_field_name(node, TS_FIELD("receiver"));
1191+
TSNode name = (TSNode){0};
1192+
uint32_t nc = ts_node_named_child_count(node);
1193+
for (uint32_t i = 0; i < nc; i++) {
1194+
TSNode child = ts_node_named_child(node, i);
1195+
if (!ts_node_is_null(recv) && ts_node_eq(child, recv)) {
1196+
continue;
1197+
}
1198+
if (strcmp(ts_node_type(child), "identifier") == 0) {
1199+
name = child;
1200+
break;
1201+
}
1202+
}
1203+
if (ts_node_is_null(name)) {
1204+
return NULL;
1205+
}
1206+
char *mn = cbm_node_text(a, name, source);
1207+
if (!mn || !mn[0]) {
1208+
return NULL;
1209+
}
1210+
if (!qualified || ts_node_is_null(recv)) {
1211+
return mn;
1212+
}
1213+
if (strcmp(ts_node_type(recv), "unqualifiedAccessExpr") == 0 &&
1214+
ts_node_is_null(cbm_find_child_by_kind(recv, "argumentList"))) {
1215+
char *rt = cbm_node_text(a, recv, source);
1216+
if (rt && rt[0]) {
1217+
return cbm_arena_sprintf(a, "%s.%s", rt, mn);
1218+
}
1219+
}
1220+
return mn;
1221+
}
1222+
11641223
// Typst: a `call` node's callee is its `item` field (an ident), matching the
11651224
// def-side resolution of `#let greet(name) = ...`.
11661225
static char *extract_typst_callee(CBMArena *a, TSNode node, const char *source, const char *nk) {
@@ -1789,6 +1848,15 @@ static char *extract_callee_name(CBMArena *a, TSNode node, const char *source, C
17891848
}
17901849
}
17911850

1851+
/* Pkl: resolve here and return unconditionally — the access-expr call node
1852+
* types double as plain property reads, so falling through to field-based or
1853+
* generic first-identifier resolution would mint a CALLS edge for every
1854+
* property read (a bare `host` has an `identifier` first child, which the
1855+
* generic fallback would happily emit). NULL here means "not a call". */
1856+
if (lang == CBM_LANG_PKL) {
1857+
return extract_pkl_callee(a, node, source, ts_node_type(node));
1858+
}
1859+
17921860
// Helm / Go templates: resolve `include "x"` / `template "x"` to the
17931861
// referenced named template so it links to the define'd Function (#338).
17941862
if (lang == CBM_LANG_GOTEMPLATE) {

‎internal/cbm/extract_usages.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ typedef enum {
378378
CBM_OCCURRENCE_VHDL_INTERFACE,
379379
CBM_OCCURRENCE_PINE_FUNCTION,
380380
CBM_OCCURRENCE_LLVM_FUNCTION,
381+
CBM_OCCURRENCE_PKL_DECLARATION,
381382
} CBMOccurrencePolicy;
382383

383384
typedef struct {
@@ -497,6 +498,7 @@ static const CBMOccurrenceSpec occurrence_specs[CBM_LANG_COUNT] = {
497498
[CBM_LANG_PINE] = {NULL, NULL, CBM_OCCURRENCE_PINE_FUNCTION, false},
498499
[CBM_LANG_PUPPET] = {NULL, NULL, CBM_OCCURRENCE_STANDARD, true},
499500
[CBM_LANG_LLVM_IR] = {llvm_binding_nodes, NULL, CBM_OCCURRENCE_LLVM_FUNCTION, false},
501+
[CBM_LANG_PKL] = {NULL, NULL, CBM_OCCURRENCE_PKL_DECLARATION, false},
500502
[CBM_LANG_MESON] = {NULL, meson_write_nodes, CBM_OCCURRENCE_STANDARD, true},
501503
[CBM_LANG_GN] = {NULL, gn_write_nodes, CBM_OCCURRENCE_STANDARD, true},
502504
[CBM_LANG_LINKERSCRIPT] = {NULL, linkerscript_write_nodes, CBM_OCCURRENCE_STANDARD, true},
@@ -1006,6 +1008,30 @@ static bool is_pine_function_binding(TSNode node) {
10061008
return ancestor_field_binds(node, "function_declaration_statement", fields);
10071009
}
10081010

1011+
/* Pkl declares names positionally: no production labels the declared identifier
1012+
* with a `name` field, so the generic declared-container rule never binds them
1013+
* and every method name, parameter name, and property name would be re-emitted
1014+
* as an ordinary read of itself. Each container below holds its declared name
1015+
* as named child 0; annotations, defaults, and bodies follow it and stay reads.
1016+
* Resolve against the NEAREST container so a nested declaration's own name is
1017+
* the only occurrence its parent can bind. */
1018+
static bool is_pkl_declaration_binding(TSNode node) {
1019+
static const char *const declaration_kinds[] = {"methodHeader",
1020+
"typedIdentifier",
1021+
"classProperty",
1022+
"objectProperty",
1023+
"clazz",
1024+
"typeAlias",
1025+
NULL};
1026+
for (TSNode parent = ts_node_parent(node); !ts_node_is_null(parent);
1027+
parent = ts_node_parent(parent)) {
1028+
if (kind_in_exact_set(ts_node_type(parent), declaration_kinds)) {
1029+
return named_child_contains(parent, 0, node);
1030+
}
1031+
}
1032+
return false;
1033+
}
1034+
10091035
static bool is_policy_binding(CBMExtractCtx *ctx, TSNode node,
10101036
const CBMOccurrenceSpec *occurrence) {
10111037
switch (occurrence->policy) {
@@ -1062,6 +1088,8 @@ static bool is_policy_binding(CBMExtractCtx *ctx, TSNode node,
10621088
return is_vhdl_interface_binding(node);
10631089
case CBM_OCCURRENCE_PINE_FUNCTION:
10641090
return is_pine_function_binding(node);
1091+
case CBM_OCCURRENCE_PKL_DECLARATION:
1092+
return is_pkl_declaration_binding(node);
10651093
case CBM_OCCURRENCE_LLVM_FUNCTION:
10661094
for (TSNode parent = ts_node_parent(node); !ts_node_is_null(parent);
10671095
parent = ts_node_parent(parent)) {

‎internal/cbm/helpers.c‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -651,29 +651,14 @@ int cbm_count_branching(TSNode node, const char **branching_types) {
651651

652652
// Loop node-type names across tree-sitter grammars, for loop-nesting depth.
653653
bool cbm_is_loop_node_type(const char *kind) {
654-
static const char *const loops[] = {"for_statement",
655-
"while_statement",
656-
"do_statement",
657-
"do_while_statement",
658-
"for_in_statement",
659-
"for_of_statement",
660-
"for_each_statement",
661-
"foreach_statement",
662-
"enhanced_for_statement",
663-
"for_range_loop",
664-
"c_style_for_statement",
665-
"for_expression",
666-
"while_expression",
667-
"loop_expression",
668-
"while_let_expression",
669-
"repeat_statement",
670-
"repeat_while_statement",
671-
"until",
672-
"while_modifier",
673-
"until_modifier",
674-
"for",
675-
"while",
676-
NULL};
654+
static const char *const loops[] = {
655+
"for_statement", "while_statement", "do_statement", "do_while_statement",
656+
"for_in_statement", "for_of_statement", "for_each_statement", "foreach_statement",
657+
"enhanced_for_statement", "for_range_loop", "c_style_for_statement", "for_expression",
658+
"while_expression", "loop_expression", "while_let_expression", "repeat_statement",
659+
"repeat_while_statement",
660+
// Pkl: `for (x in xs) { ... }` inside an object body.
661+
"forGenerator", "until", "while_modifier", "until_modifier", "for", "while", NULL};
677662
for (const char *const *l = loops; *l; l++) {
678663
if (strcmp(kind, *l) == 0) {
679664
return true;

‎internal/cbm/lang_specs.c‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,11 +1594,21 @@ static const char *tlaplus_branch_types[] = {"if_then_else", "case", NULL};
15941594
static const char *tlaplus_var_types[] = {"variable_declaration", NULL};
15951595
static const char *tlaplus_module_types[] = {"source_file", NULL};
15961596
static const char *pkl_func_types[] = {"classMethod", "objectMethod", NULL};
1597-
static const char *pkl_class_types[] = {"clazz", NULL};
1598-
static const char *pkl_import_types[] = {"importClause", "extendsOrAmendsClause", "extends",
1599-
"import", NULL};
1597+
static const char *pkl_class_types[] = {"clazz", "typeAlias", NULL};
1598+
static const char *pkl_import_types[] = {
1599+
"importClause", "importGlobClause", "importExpr", "extendsOrAmendsClause",
1600+
"extends", "import", NULL};
16001601
static const char *pkl_var_types[] = {"classProperty", "objectProperty", NULL};
16011602
static const char *pkl_module_types[] = {"module", NULL};
1603+
/* Both access exprs double as plain property reads; extract_pkl_callee keeps
1604+
* only the ones carrying an argumentList. `newExpr` resolves to its type. */
1605+
static const char *pkl_call_types[] = {"unqualifiedAccessExpr", "qualifiedAccessExpr", "newExpr",
1606+
NULL};
1607+
/* Control-flow only, matching every other spec (short-circuit operators are
1608+
* deliberately excluded). `forGenerator` is also a loop — see helpers.c. */
1609+
static const char *pkl_branch_types[] = {"ifExpr", "whenGenerator", "forGenerator", NULL};
1610+
static const char *pkl_throw_types[] = {"throwExpr", NULL};
1611+
static const char *pkl_decorator_types[] = {"annotation", NULL};
16021612
static const char *gomod_var_types[] = {"require_directive", "replace_directive", NULL};
16031613
static const char *gomod_import_types[] = {"require", NULL};
16041614
static const char *gomod_module_types[] = {"source_file", NULL};
@@ -2630,9 +2640,9 @@ static const CBMLangSpec lang_specs[CBM_LANG_COUNT] = {
26302640

26312641
// CBM_LANG_PKL
26322642
[CBM_LANG_PKL] = {CBM_LANG_PKL, pkl_func_types, pkl_class_types, empty_types, pkl_module_types,
2633-
empty_types, pkl_import_types, empty_types, empty_types, pkl_var_types,
2634-
empty_types, empty_types, NULL, empty_types, NULL, NULL, tree_sitter_pkl,
2635-
NULL},
2643+
pkl_call_types, pkl_import_types, empty_types, pkl_branch_types,
2644+
pkl_var_types, empty_types, pkl_throw_types, NULL, pkl_decorator_types, NULL,
2645+
NULL, tree_sitter_pkl, NULL},
26362646

26372647
// CBM_LANG_GOMOD
26382648
[CBM_LANG_GOMOD] = {CBM_LANG_GOMOD, empty_types, empty_types, empty_types, gomod_module_types,

‎internal/cbm/lsp/c_lsp.c‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2818,7 +2818,10 @@ static const CBMRegisteredFunc *c_lookup_member_depth(CLSPContext *ctx, const ch
28182818
const char *shortn = dot ? dot + 1 : type_qn;
28192819
size_t slen = strlen(shortn);
28202820
const char *best_qn = NULL;
2821-
for (int i = 0; i < ctx->registry->type_count; i++) {
2821+
CBMTypeNameIter it;
2822+
cbm_registry_types_by_short_name(ctx->registry, shortn, &it);
2823+
int i;
2824+
while ((i = cbm_type_name_iter_next(&it)) >= 0) {
28222825
const char *q = ctx->registry->types[i].qualified_name;
28232826
if (!q) {
28242827
continue;
@@ -5972,6 +5975,7 @@ CBMTypeRegistry *cbm_c_build_cross_registry(CBMArena *arena, CBMLSPDef *defs, in
59725975
c_register_lsp_defs(arena, reg, "", d, 1);
59735976
}
59745977
cbm_registry_finalize(reg);
5978+
cbm_registry_build_type_short_index(reg);
59755979
reg->read_only = true; /* seal: shared Tier-2 registry is read-only during resolve */
59765980
return reg;
59775981
}
@@ -6055,6 +6059,7 @@ void cbm_run_c_lsp_cross(CBMArena *arena, const char *source, int source_len, co
60556059
// Finalize registry — O(1) lookups. See go_lsp.c "3c. Finalize"
60566060
// comment for the rationale (linear-scan fallback otherwise).
60576061
cbm_registry_finalize(&reg);
6062+
cbm_registry_build_type_short_index(&reg);
60586063

60596064
// Initialize context and run
60606065
CLSPContext ctx;

0 commit comments

Comments
 (0)