Skip to content

Place facts where they are written: origins read path:line:column (Make, CMake, Meson, Cabal, shell scripts, YAML) - #362

Merged
lefticus merged 11 commits into
cpp-best-practices:mainfrom
leftibot:positions
Nov 23, 2026
Merged

lefticus merged 11 commits into
cpp-best-practices:mainfrom
leftibot:positions

Conversation

@leftibot

@leftibot leftibot commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #300 (acceptance: "messages and --explain give path:line:column wherever the source position is known")

Merge after #360. This PR is built on its Make changes, so until #360 merges, this diff also shows its commits.

What changes

Every syntax tree has spans, but almost no fact kept one in its Origin (only tool settings that don't parse), and an Origin never showed it. An origin with a span now reads the way compilers write a position, followed by its place when it has one:

Before After
Makefile:check[40] Makefile:40:1 (check)
CMakeLists.txt:add_compile_options[16] CMakeLists.txt:16:1 (add_compile_options)
CMakeLists.txt (CTest settings, guards, dependency managers) CMakeLists.txt:3:1 (enable_testing)
meson.build:project[1], and the file only for guards and tests meson.build:1:1 (project), meson.build:5:1 (elif)
app.cabal app.cabal:17:3 (ghc-options), app.cabal:27:1 (test-suite)
ci/build.sh ci/build.sh:4:3
.github/workflows/ci.yml:jobs.test.steps[3].run .github/workflows/ci.yml:14:9 (jobs.test.steps[3].run)
.clang-tidy:WarningsAsErrors .clang-tidy:2:1 (WarningsAsErrors)

Editors and terminals open the file at that place.

By reader, one commit each

  • Make: a recipe's origin is its recipe line's span.
  • CMake: an invocation spans from its name to past its closing parenthesis.
    • Every fact made from an invocation is placed there, including those that had only the path: CTest settings, guards, and declared dependency managers.
    • A file that can't be evaluated is unknown at its syntax error, or at the include, subdirectory or call that went past the nesting limit.
  • Meson: tokens have spans, and a statement spans from its first token to its last.
    • Guards are placed at their own if/elif. Before, they took the line of whatever statement came before them.
    • Tests are placed at their test().
    • Syntax errors are placed at their line.
  • Cabal: fields and section headers have spans; a field spans its continuation lines.
  • Shell: commands keep their span. For a repository script file (Script.whole) the text is the file, so its commands are placed there. A CI step's run: block keeps the step's place, since its spans are relative to the block.
  • YAML: yaml_support.places composes the document (PyYAML keeps marks on its nodes) and finds where each place is. A key spans from itself through its value, an item from its start to its end, and a key a mapping merges in (<<: *defaults) is placed where it is written.
    • CI facts and the commands expanders find are placed as the CI commands stage yields them (facts.placed.Placed), each in the file its origin names: the CI file, a file a GitLab pipeline includes, a composite action, a pre-commit configuration, and the commands that ran a command (via).
    • YAML tool settings (clang-tidy, golangci-lint, RuboCop, buf, detekt, SwiftLint, molecule) are placed at their key.

Problem (a reason and where it is) moves to parsing, shared by CMake and Meson.

One visible side effect

Facts that only looked equal because their origins had no position are now separate. Two if(MSVC) guards, or two FetchContent declarations in one file, are two facts, one at each line. The well_configured_c/_cpp snapshots list the second declaration.

Not covered

  • JSON/TOML settings: json and tomllib keep no positions, so these stay at the file.
  • A YAML setting whose key has a dot in it: it doesn't name a place the file has, so it stays at the file.
  • Dockerfile: nothing to do. Its reader only checks well-formedness, and its errors already carry their position.

Verified

🤖 Generated with Claude Code

https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt

leftibot and others added 9 commits November 23, 2026 13:42
`Choices`, `assigned` and `combined` (a variable's values set in branches, each in the builds it takes it in) were
written for Meson's values, but nothing in them is Meson's. They move to `facts.conditions`, generic over the value,
so that Make's evaluator can keep its variables the same way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
Makefiles indent what a conditional holds (neovim's `  CMAKE := cmake` under `ifeq ($(UNIX_LIKE),FALSE)`). Only a
tab starts a recipe line; make reads any other line as if it were not indented. The parser matched assignments,
includes and rules from the line's first column, so an indented one was read as a directive and never set: neovim's
CMAKE was unknown in every recipe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
…lds in

Make read a conditional it could not decide by reading every branch, one after another. A variable set in two
branches kept only the last value, and every recipe line ran on every runner: a Linux job "ran" the Windows branch's
`build.bat`, and `$(RM)` was `rm -f` on Windows too.

The evaluator now reads each line in the builds it holds in, a `Condition`, as Meson's and CMake's do:
- A conditional's test is a `Condition`. A test the makefile and the command line decide takes its branch, as before.
  One on the platform (`$(OS)` is Windows_NT, or empty; what `$(shell uname -s)` prints, also through
  `UNAME_S := $(shell uname -s)`) holds on those platforms. Anything else the environment could decide (`ifdef DEBUG`,
  `ifeq ($(CC),clang)`) holds behind that requirement, so both branches may still run.
- A variable holds each value in the builds its assignment was read in (`=`, `?=`, `+=` alike), and a recipe line
  expands to each text its variables give it, in the builds it takes it in. Prerequisites carry their builds too.
- A recipe line that holds in only some builds is an `expansion.Only`. A CI job follows it only where it may hold on
  the job's runner; on a runner of unknown OS, everywhere. An unknown recipe in a branch that cannot hold there is
  not reported, and one whose program is unknown is reported once, whatever values its arguments take.

Expansion is now recursive, which fixes how a variable that refers to itself was read: argo-cd's
`BUILD_DATE := $(if $(BUILD_DATE),$(BUILD_DATE),…)` was substituted ten times over, doubling each time, into a
375 kB argument. A reference inside its own variable's value now stays as written (make rejects a variable that
refers to itself). A reference whose name is computed (erlang.mk's `$(gen_verbose_$(V))`) is still expanded once its
name is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
A fact's origin could hold where in the file it was found (a span), but it read the same without one: only the
structured place (`jobs.test.steps[3].run`). With a span it now reads as compilers write a position, so that an
editor or terminal opens the file there, followed by the place when there is one: `Makefile:40:1 (check)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
A recipe's origin named its line inside the place (`Makefile:check[40]`). It is the recipe line's span now,
`Makefile:40:1 (check)`, with its end, as the tree has it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
A CMake invocation knew only its line, and a fact's origin named it inside the place (`CMakeLists.txt:set[12]`).
An invocation now spans from its name to past its closing parenthesis, and every fact made from it is placed there:
`CMakeLists.txt:12:3 (set)`. That includes those that held only the file's path: CTest settings, guards
(`if(PROJECT_IS_TOP_LEVEL)`) and declared dependency managers. Two declarations of one manager in a file are now two
facts, one at each.

A file CMake could not evaluate (a syntax error, the nesting limit passed) is unknown where it went wrong, when that
is known: the error's line, or the include, subdirectory or call that went past the limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
Meson's tokens knew only their line, and a fact's origin named it inside the place (`meson.build:project[1]`).
Tokens now have spans, and a statement spans from its first token to its last: facts are placed there
(`meson.build:3:3 (add_project_arguments)`). Guards and tests held only the file's path. A test is now placed at
its `test()`, and a guard at its own `if` or `elif`, through its condition: the frame they were made in still held
the line of the statement before.

A file that does not parse is unknown at the error's line. `Problem`, a reason and where, moves to `parsing` for
CMake and Meson to share.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
The Cabal tree knew each section's line but not where its fields were, so a `ghc-options` value could not be placed:
its facts held only the file's path. A field now spans from its name to the end of its last continuation line, and
a section's header has a span: GHC's options are placed at their field (`app.cabal:17:3 (ghc-options)`), and a test
suite at its stanza (`app.cabal:27:1 (test-suite)`). Options from Stack's and hpack's YAML stay at the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
The shell tree knew where each command was, but the commands it gave did not keep it. A command now carries its
span, and the commands of a script file the project holds (`./ci/build.sh`), whose text is the file's, are placed
there: `ci/build.sh:4:3`. A CI step's own script is a block inside the workflow, so its commands keep the step's
place.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@codecov

codecov Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.74747% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 99.72%. Comparing base (116970c) to head (7e10580).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
...roject_validator/build_systems/cmake/evaluation.py 93.33% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #362      +/-   ##
==========================================
+ Coverage   99.68%   99.72%   +0.03%     
==========================================
  Files         311      312       +1     
  Lines       19734    19950     +216     
  Branches     2303     2333      +30     
==========================================
+ Hits        19672    19895     +223     
+ Misses         62       55       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

leftibot and others added 2 commits November 23, 2026 16:17
…as them

A CI file's facts named their place by its keys (`ci.yml:jobs.test.steps[3].run`), but the YAML loader kept no
positions, so none was placed. `yaml_support.places` composes the document (PyYAML keeps marks on its nodes) and
answers where each place is: a key from itself through its value, a sequence's item from its start to its end, and a
key a mapping merges in (`<<: *defaults`) where it is written.

Facts are placed as the CI commands stage yields them (`facts.placed.Placed`), each in the file its origin names: the
CI file, a file a GitLab pipeline includes, a composite action, a pre-commit configuration, and the commands that ran
a command (`via`). `ci.yml:14:9 (jobs.test.steps[3].run)`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
A tool's YAML settings (clang-tidy, golangci-lint, RuboCop, buf, detekt, SwiftLint, molecule) named their place by
their dotted key under the reader's prefix. Each is placed where the file has that key (`molecule.yml:2:3 (name)`).
A key with a dot in it does not name a place the file has, and is left at the file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ByTXNqDWdM7HzezrFtEvQt
@leftibot leftibot changed the title Place facts where they are written: origins read path:line:column (Make, CMake, Meson, Cabal, shell scripts) Place facts where they are written: origins read path:line:column (Make, CMake, Meson, Cabal, shell scripts, YAML) Nov 23, 2026
@lefticus
lefticus merged commit b56eee5 into cpp-best-practices:main Nov 23, 2026
24 checks passed
@lefticus
lefticus deleted the positions branch November 23, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants