Skip to content

Add laziness test suite for type checking dependencies (#3219)#3219

Open
samwgoldman wants to merge 1 commit intomainfrom
export-D102239243
Open

Add laziness test suite for type checking dependencies (#3219)#3219
samwgoldman wants to merge 1 commit intomainfrom
export-D102239243

Conversation

@samwgoldman
Copy link
Copy Markdown
Member

@samwgoldman samwgoldman commented Apr 23, 2026

Summary:

Adds a snapshot-based test suite documenting how much of a file's dependencies get type-checked when the file itself is checked. The laziness goal is that dependencies should stop at the earliest step (Load/Ast/Exports/Answers/Solutions) sufficient to resolve what callers actually need — e.g. a transitively-imported module used only as an annotation should not have its body inferred.

Each test sets up a small module graph, checks one entry-point module, and records in a markdown snapshot the highest step each module reached plus the tree of cross-module demands observed. The snapshots capture current behavior — some document good laziness properties, others document opportunities where dependencies are computed further than callers need. Snapshots regenerate with UPDATE_SNAPSHOTS=1.

Supporting infrastructure:

  • DemandCollector (pyrefly_util::demand_tree) records cross-module LookupExport/LookupAnswer events into a tree. Scoped to a single Transaction via set_demand_collector so parallel checks don't interfere. enter() returns an RAII span guard so the per-thread nesting stack stays balanced even when an Answer lookup panics.
  • pyrefly check --report-demand-tree <path> emits a JSON document ({ module_steps, demand_tree }).
  • The test harness renders the structured tree into a flat indented form for snapshot comparison, and aggregates pervasive builtins/typing demands into a single count so test output stays readable.

Differential Revision: D102239243

@meta-cla meta-cla Bot added the cla signed label Apr 23, 2026
@meta-codesync
Copy link
Copy Markdown
Contributor

meta-codesync Bot commented Apr 23, 2026

@samwgoldman has exported this pull request. If you are a Meta employee, you can view the originating Diff in D102239243.

@github-actions

This comment has been minimized.

@meta-codesync meta-codesync Bot changed the title Add laziness test suite for type checking dependencies Add laziness test suite for type checking dependencies (#3219) Apr 23, 2026
meta-codesync Bot pushed a commit that referenced this pull request Apr 23, 2026
Summary:

Adds a snapshot-based test suite documenting how much of a file's dependencies get type-checked when the file itself is checked. The laziness goal is that dependencies should stop at the earliest step (Load/Ast/Exports/Answers/Solutions) sufficient to resolve what callers actually need — e.g. a transitively-imported module used only as an annotation should not have its body inferred.

Each test sets up a small module graph, checks one entry-point module, and records in a markdown snapshot the highest step each module reached plus the tree of cross-module demands observed. The snapshots capture current behavior — some document good laziness properties, others document opportunities where dependencies are computed further than callers need. Snapshots regenerate with `UPDATE_SNAPSHOTS=1`.

Supporting infrastructure:
- `DemandCollector` (`pyrefly_util::demand_tree`) records cross-module `LookupExport`/`LookupAnswer` events into a tree. Scoped to a single `Transaction` via `set_demand_collector` so parallel checks don't interfere. `enter()` returns an RAII span guard so the per-thread nesting stack stays balanced even when an Answer lookup panics.
- `pyrefly check --report-demand-tree <path>` emits a JSON document (`{ module_steps, demand_tree }`).
- The test harness renders the structured tree into a flat indented form for snapshot comparison, and aggregates pervasive `builtins`/`typing` demands into a single count so test output stays readable.

Differential Revision: D102239243
@meta-codesync meta-codesync Bot force-pushed the export-D102239243 branch from 8e69d4a to 97a19ca Compare April 23, 2026 23:08
@github-actions github-actions Bot added size/xl and removed size/xl labels Apr 23, 2026
@github-actions

This comment has been minimized.

meta-codesync Bot pushed a commit that referenced this pull request Apr 23, 2026
Summary:

Adds a snapshot-based test suite documenting how much of a file's dependencies get type-checked when the file itself is checked. The laziness goal is that dependencies should stop at the earliest step (Load/Ast/Exports/Answers/Solutions) sufficient to resolve what callers actually need — e.g. a transitively-imported module used only as an annotation should not have its body inferred.

Each test sets up a small module graph, checks one entry-point module, and records in a markdown snapshot the highest step each module reached plus the tree of cross-module demands observed. The snapshots capture current behavior — some document good laziness properties, others document opportunities where dependencies are computed further than callers need. Snapshots regenerate with `UPDATE_SNAPSHOTS=1`.

Supporting infrastructure:
- `DemandCollector` (`pyrefly_util::demand_tree`) records cross-module `LookupExport`/`LookupAnswer` events into a tree. Scoped to a single `Transaction` via `set_demand_collector` so parallel checks don't interfere. `enter()` returns an RAII span guard so the per-thread nesting stack stays balanced even when an Answer lookup panics.
- `pyrefly check --report-demand-tree <path>` emits a JSON document (`{ module_steps, demand_tree }`).
- The test harness renders the structured tree into a flat indented form for snapshot comparison, and aggregates pervasive `builtins`/`typing` demands into a single count so test output stays readable.

Differential Revision: D102239243
@meta-codesync meta-codesync Bot force-pushed the export-D102239243 branch from 97a19ca to 3483a70 Compare April 23, 2026 23:38
@github-actions github-actions Bot added size/xl and removed size/xl labels Apr 23, 2026
Summary:
Pull Request resolved: #3219

Adds a snapshot-based test suite documenting how much of a file's dependencies get type-checked when the file itself is checked. The laziness goal is that dependencies should stop at the earliest step (Load/Ast/Exports/Answers/Solutions) sufficient to resolve what callers actually need — e.g. a transitively-imported module used only as an annotation should not have its body inferred.

Each test sets up a small module graph, checks one entry-point module, and records in a markdown snapshot the highest step each module reached plus the tree of cross-module demands observed. The snapshots capture current behavior — some document good laziness properties, others document opportunities where dependencies are computed further than callers need. Snapshots regenerate with `UPDATE_SNAPSHOTS=1`.

Supporting infrastructure:
- `DemandCollector` (`pyrefly_util::demand_tree`) records cross-module `LookupExport`/`LookupAnswer` events into a tree. Scoped to a single `Transaction` via `set_demand_collector` so parallel checks don't interfere. `enter()` returns an RAII span guard so the per-thread nesting stack stays balanced even when an Answer lookup panics.
- `pyrefly check --report-demand-tree <path>` emits a JSON document (`{ module_steps, demand_tree }`).
- The test harness renders the structured tree into a flat indented form for snapshot comparison, and aggregates pervasive `builtins`/`typing` demands into a single count so test output stays readable.

Differential Revision: D102239243
@github-actions
Copy link
Copy Markdown

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Copy Markdown
Contributor

@kinto0 kinto0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review automatically exported from Phabricator review in Meta.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants