Skip to main content

Crate gdscript_hir

Crate gdscript_hir 

Source
Expand description

gdscript-hir — the semantic / type layer.

Lowers the AST to a HIR (an ItemTree of signatures + per-function Body), runs name resolution (local → class member → inherited → global), gradual type inference (Variant by default, :=/annotations, member lookup over the engine inheritance table, is/as narrowing), and the GDScript warning checks. Single-file in Phase 2; project-wide + scene-aware later.

Phase 2 builds this out bottom-up: the type model (ty), then the item tree, body, name resolution, and inference. Must build for wasm32.

Modules§

body
Body lowering (Playbook §3.1/§3.4): a function body (or a class-level initializer expression) lowered from the CST into a flat arena of Expr/Stmt addressed by ExprId/StmtId, plus a BodySourceMap mapping every ExprId back to its byte range. Every IDE feature (hover, inlay, completion) maps a cursor offset → ExprId through this source map, then reads the inferred type from crate::infer.
def
Canonical symbol identity + cursor classification (Playbook §3.M5) — the basis of cross-file navigation (find-references, rename, goto-definition).
flow
Per-body control-flow narrowing (Phase-6 Workstream 2).
infer
Gradual type inference (Playbook §3.3–§3.6 + §5): a single forward, bottom-up, bidirectional walk over a lowered Body. No unification variables — types flow forward from annotations, literals, and the engine API (rust-analyzer’s structure, Pyright’s gradual semantics).
item_tree
The item tree (Playbook §3.1): a signature-level view of one .gd file — its class_name, extends target, and class members (funcs/vars/consts/signals/enums/inner classes) — lowered from the CST without reading any function body.
project
project.godot autoload parsing (Playbook §3.M4).
queries
The salsa-tracked entry points for the semantic layer, layered on gdscript-db’s parse query.
resolve
Name & type resolution (Playbook §3.2/§3.5): the resolve_external Phase-3 seam, the GDScript source-annotation → Ty resolver, base-class resolution, the per-class ClassScope (the class-member tier of the binder), and global resolution.
ty
The Phase-2 type model (Playbook §2/§3.5): the gradual Ty lattice over Variant, the hard/soft TypeSource, the ported is_assignable compatibility check, and TyRefTy resolution against the engine API.
warnings
The Godot warning catalog + the emit-then-gate seam (Phase-6 Workstream 1).

Structs§

AstPtr
A reparse-stable pointer to a syntax node — its SyntaxKind plus byte TextRange (rust-analyzer’s SyntaxNodePtr). Because it is plain Copy data keyed on text position, identical source re-parses to the identical pointer, which is what lets the crate::item_tree::ItemTree stay Eq while still being able to recover the CST node for deferred body lowering / initializer inference.