bazel-contrib / bazel-contrib/buildtools

we need a proper resolver stage after parsing

Open
#1,500 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
1.2k
Forks
471
Avg merge
2d 22h
Merged PRs (30d)
13

Description

By "resolver stage", I mean that each identifier AST node needs to be mapped to a *binding* (the static representation of a variable). In Bazel, this is done by https://github.com/bazelbuild/bazel/blob/master/src/main/java/net/starlark/java/syntax/Resolver.java

In buildtools, we have a half-dozen half-hearted half-implemented attempts to resolve identifiers, sometimes bespoke to individual linter warning implementations. These not-quite-resolvers of course don't share the data structures they build and repeat work unnecessarily.

The code in buildtools that comes closest to being a real resolver is bzlenv/bzlenv.go; it computes a reasonable version of a binding (bzlmod.NameInfo struct), but unfortunately stores these bindings in a _stack_ of blocks rather than a tree or a file-wide map, requiring pointless recomputation of bindings each time we walk the AST.

Ideally, the flow ought to be:

* parse to produce an AST
* resolve to augment the AST with binding information
* report static fatal errors (e.g. var statements that redeclare an already bound variable's type)
* and only then perform linting, editing, etc.

Contributor guide

Open the contributing guide

Research direction

Start with bzlenv/bzlenv.go and its bzlmod.NameInfo binding representation, then compare the intended stages with Bazel's Resolver.java. Clarify how bindings should be stored and shared across the AST before static fatal-error reporting and linting. Done means the project has an agreed resolver stage and shared binding data rather than separate partial implementations.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.