Skip to content

Commit cd16ef8

Browse files
committed
Merge fix/go-weak-selector-calls (DeusData#1907, with main 32445b2) into fix/go-method-receiver-qn
Brings main 32445b2 in through the refreshed DeusData#1907. No conflicts. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
2 parents 7d92e74 + 6856f09 commit cd16ef8

32 files changed

Lines changed: 4896 additions & 263 deletions

‎internal/cbm/cbm.c‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,31 @@ void cbm_imports_push(CBMImportArray *arr, CBMArena *a, CBMImport imp) {
402402
arr->items[arr->count++] = imp;
403403
}
404404

405+
bool cbm_imports_local_span_binds_runtime_name(const CBMImportArray *imports, const char *name,
406+
size_t len) {
407+
if (!imports || !name) {
408+
return true;
409+
}
410+
bool seen = false;
411+
for (int i = 0; i < imports->count; i++) {
412+
const CBMImport *imp = &imports->items[i];
413+
if (!imp->local_name || strncmp(imp->local_name, name, len) != 0 ||
414+
imp->local_name[len] != '\0') {
415+
continue;
416+
}
417+
if (cbm_import_binds_runtime_name(imp)) {
418+
return true;
419+
}
420+
seen = true;
421+
}
422+
return !seen;
423+
}
424+
425+
bool cbm_imports_local_binds_runtime_name(const CBMImportArray *imports, const char *local_name) {
426+
return !local_name ||
427+
cbm_imports_local_span_binds_runtime_name(imports, local_name, strlen(local_name));
428+
}
429+
405430
void cbm_usages_push(CBMUsageArray *arr, CBMArena *a, CBMUsage usage) {
406431
GROW_ARRAY(arr, a);
407432
arr->items[arr->count++] = usage;

‎internal/cbm/cbm.h‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,20 @@ typedef struct {
398398
const char *member; // ES named import: the exported name the local binds (`get` in
399399
// `import { get as navigate } from "axios"`); NULL otherwise
400400
bool is_default; // ES default import (`import X from "Y"`), JS/TS only (#1916)
401+
bool type_checking_only; // Python: inside a module-level `if TYPE_CHECKING:` block --
402+
// binds the name for annotations, never at runtime (#1277)
401403
CBMImportKind kind; // CBM_IMPORT_KIND_DEFAULT unless the syntax names a member kind
402404
} CBMImport;
403405

406+
/* True when an import binds its local name at runtime. A Python import under
407+
* `if TYPE_CHECKING:` exists for annotations only: a call through that name
408+
* cannot happen, so no CALLS import map may bind it (an import_map edge
409+
* through it would be fabricated by construction). THE one rule every CALLS
410+
* import-map builder applies. */
411+
static inline bool cbm_import_binds_runtime_name(const CBMImport *imp) {
412+
return imp && !imp->type_checking_only;
413+
}
414+
404415
/* Content-only ordered Python namespace facts; no resolved target identities. */
405416
#define CBM_PY_NAMESPACE_FACTS_VERSION 1u
406417

@@ -1306,6 +1317,14 @@ void cbm_py_namespace_test_copy_fail_after(int successful_allocations);
13061317
void cbm_defs_push(CBMDefArray *arr, CBMArena *a, CBMDefinition def);
13071318
void cbm_calls_push(CBMCallArray *arr, CBMArena *a, CBMCall call);
13081319
void cbm_imports_push(CBMImportArray *arr, CBMArena *a, CBMImport imp);
1320+
/* True unless every import of `imports` that binds `local_name` is
1321+
* annotation-only (cbm_import_binds_runtime_name), so also true when no import
1322+
* names it: the rule for the builders that key IMPORTS edges by local name. */
1323+
bool cbm_imports_local_binds_runtime_name(const CBMImportArray *imports, const char *local_name);
1324+
/* The same for the `len` bytes at `name` (not NUL-terminated): lets a caller
1325+
* decide before it copies the name. */
1326+
bool cbm_imports_local_span_binds_runtime_name(const CBMImportArray *imports, const char *name,
1327+
size_t len);
13091328
void cbm_usages_push(CBMUsageArray *arr, CBMArena *a, CBMUsage usage);
13101329
void cbm_throws_push(CBMThrowArray *arr, CBMArena *a, CBMThrow thr);
13111330
void cbm_rw_push(CBMRWArray *arr, CBMArena *a, CBMReadWrite rw);

0 commit comments

Comments
 (0)