Skip to content

Metal/CUDA GPU qualifiers (kernel, __global__, device, ...) mint sourceless god nodes #4550

Open

Description

@rajatnagda45

Version

v8 @ 0.9.92 (86c57be)

Problem

Metal (.metal) and CUDA (.cu/.cuh) are C++-derived GPU languages and route through the C++ extractor. Their address-space / execution-space / function qualifiers are not part of the C++ grammar, so tree-sitter-cpp parses a leading qualifier as the declaration's type_identifier (the real type is pushed into an ERROR node). _cpp_collect_type_refs then emits the qualifier as a type reference, and each one becomes a sourceless, corpus-shared god node that every shader/kernel references.

This violates the provenance invariant (a node with no source_file), and the hubs pollute god-node rankings in analyze.

Reproduce

Extract the shipped fixtures:

from graphify.extract import extract_cpp
r = extract_cpp("tests/fixtures/sample.metal")
print(sorted({n["label"] for n in r["nodes"] if not n.get("source_file")}))
# -> ['constant', 'device', 'kernel', 'uint']
r = extract_cpp("tests/fixtures/sample.cu")
print(sorted({n["label"] for n in r["nodes"] if not n.get("source_file")}))
# -> ['__device__', '__global__', ...]  (ids normalize to global/device/host)

Expected vs actual

  • Expected: kernel, device, constant, __global__, __device__, __host__, ... are language keywords, not corpus symbols, and should not become nodes. The genuine struct Vec3 should still resolve.
  • Actual: each qualifier is a sourceless god node with a false references edge.

Notes

These words are legal identifiers in plain C++/CUDA (e.g. a user type named device), so any filter must be keyed by the GPU-dialect file extension, not applied to .cpp/.cc/.h.

Activity

  1. github-actions commented on Oct 18, 2026

    @github-actions

    Thanks for opening this issue, @rajatnagda45. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions