Skip to content

LSP: check only the edited unit when an edit changes nothing but bodies - #1542

Merged
Frotty merged 8 commits into
masterfrom
body-edit-keeps-nodes
Oct 22, 2026
Merged

Frotty merged 8 commits into
masterfrom
body-edit-keeps-nodes

Conversation

@Frotty

@Frotty Frotty commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Replacing a unit in the language server's model invalidated everything that imports it, transitively. An edit inside a function body of a package that 118 files of a large real map import re-checked 233 units, about 2 s per edit, although no other unit can see a body.

This takes a different route from #1368. #1368 kept importers when a public-ABI hash was unchanged, but they then pointed at the replaced unit's tree. Here, an edit that changes nothing but bodies keeps the unit's tree itself.

What changes:

  • BodyOnlyEdit decides when an edit is body-only. It compares position-normalised copies of the old and the new unit, with these bodies blanked: functions, constructors, destructors and init blocks.

  • A body-only edit is moved into the unit of the model:

    • the new bodies;
    • the new source positions of every node, including a super call's keyword and a closure's arrow;
    • the new parse information.

    Every node the importers resolved to stays, at its new position. The importers keep their attributes and are not checked again; only the edited unit is.

  • That unit's module instantiations survive its check, because the importers point into them. The instantiations' own positions follow the new use positions.

  • The unit stays "edited in place" until something invalidates it, whether or not it has been checked since.

  • These count as declarations, so changing them replaces the unit as before:

    • module bodies, which are copied into the classes that use them;
    • interface bodies, which decide whether a function is abstract;
    • global initialisers, Jass, and anything else outside those bodies.
  • An edit also takes the old path when:

    • any node of a module the unit declares moves (offsets, lines, columns, the arrow or the keyword), because every user of the module holds a copy with its positions;
    • a module use did not expand cleanly (it must resolve, with matching type arguments), because a kept instantiation would not report the error again;
    • the new text has parse errors.
  • When working out dependents, a changed unit edited in place doesn't affect its importers, unless:

    • it imports or declares an affected package;
    • it has a config relative;
    • another affected unit reaches it.

    Any other change to such a unit, or to something it depends on, invalidates it and its dependents as before.

  • The lookup cache is cleared for the unit before its old bodies leave the tree. Purged and removed units leave the in-place set.

Measured on that map: a model loaded once, then five body edits, two runs each, alternating branch and master.

master this branch
Units unchecked after the edit 233 1
Edit and reconcile, median (range) 2,177 ms (1,905–3,165) 552 ms (450–783)
Compile reusing the check, median (range) 1,268 ms (1,204–1,501) 1,481 ms (1,098–2,017)

The compile difference is within the noise of the shared machine.

Tests:

  • BodyOnlyEditTests compares diagnostics and compiled Lua with a build from scratch after each edit. It covers:

    • edits in method, constructor, function and importer bodies;
    • an error introduced in an edited body and then fixed;
    • edits that must not be moved: a parameter, an interface default body, a module body, a field initialiser, a parse error.

    It also checks:

    • that the importer still points at the same declaration node, at its new line, including a field the class got from a module;
    • a body edit and a change of what it imports, reconciled together in either order;
    • an edit synced from disk;
    • a module moved by offset, by line, or only by a closure arrow;
    • a module use with a missing type argument;
    • a super call's keyword;
    • the lookup cache;
    • a purged unit.

    Every fix from the review loop has a test that failed before the fix.

  • IncrementalModelOracleTests with INCREMENTAL_ORACLE_SEEDS=100: all 200 sequences match their fresh builds. A temporary counter showed 353 edits moved in place over the first 60 of them.

  • ModelManagerTests, HoverTests, CompletionDocumentationTests, MapModelReuseTests and every de.peeeq.wurstio.languageserver class pass.

Only Windows was run.

Replacing a unit invalidated everything importing it, transitively: an edit inside a function body of a
package which 118 files of a large real map import re-checked 233 units, about 2 s per edit, although no
other unit can see a body.

An edit which changes nothing but the bodies of functions, constructors, destructors and init blocks is
now moved into the unit of the model (BodyOnlyEdit): the new bodies, the new source positions of every
node and the new parse information. Every node the importers resolved to stays, at its new position, so
they keep their attributes and are not checked again; only the unit is, and its module instantiations
survive that check, because the importers point into them. Bodies of modules (copied into users) and
interfaces (a body decides abstractness), global initialisers, Jass and anything else count as
declarations, as does a unit whose module uses did not all expand; any other change replaces the unit
as before, and invalidates such a unit and what depends on it.

Measured on that map, two alternating runs of five edits each: edit and reconcile 2177 ms median on
master, 552 ms here; a compile reusing the check afterwards is unchanged within noise. BodyOnlyEditTests
compares diagnostics and Lua with a build from scratch for edits in method, constructor and function
bodies, errors in them, and the edits which must not be moved; the incremental model oracle moved 353
edits over 60 seeded sequences and matches its fresh builds over 200.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T17:24:09.823136Z 293c96a Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 88a607b0c2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

… cleanly

A module use with missing type arguments is reported while the module expands, but still gets an
instantiation, so the size check let such a unit be edited in place and the kept instantiation never
reported the error again. Each use must now name a module with as many type parameters as it passes.

Every class using a module, in its unit or another, holds a copy of it with the module's positions, and
the copies are kept; an edit which moved a module left them at the old lines. An edit of a unit is now
made in place only when nothing in the modules it declares changes position.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a31b61d3a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

A body edit of A followed by a change of what A imports, before a reconciliation, left A edited in place
while the change was propagated, so its importers were neither cleared nor made unchecked: they kept
links into the replaced declarations until the reconciliation, and a run in between would use them.

Only a changed unit edited in place, which neither imports nor declares an affected package nor has a
config relative, is quiet now; one reached from an affected unit is affected, and so is what depends on it.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c1a5656bf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…dit in place

Both nodes keep the position of a token besides their own, which errors point at (AttrPos.getErrorPos
of a super call); the transplant moved only their own positions.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5c97eb037c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ines too

A check which validated a unit edited in place took it out of the set, but what imports it still points
into its module instantiations. A file synced from disk is checked by the sync, so the reconciliation
after it found the unit no longer edited in place and checked every importer, and once importers were
left out, it cleared the instantiations under them (a compile then failed on an instantiation without a
parent). The unit now stays in the set until something invalidates it.

Positions are offsets, and lines come from the line table of each parse: an edit which kept every offset
in a module but moved its lines (one comment line becoming two of the same length) left the copies of the
module at the old lines. Lines and columns are compared as well.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b2055a9623

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…odule

Both have a position of their own besides the node's, which a module copy keeps: a module whose
closure moved only its arrow kept its bounds and every child's position, and was edited in place.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b9b6ce991e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

The cache is keyed by nodes and cleared by walking the unit; walked after the edit in place, it
missed the replaced bodies, whose keys then kept them alive with every further edit.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d18ab56f7a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

retainCompilationUnits removed purged units from the model and the unchecked units but not from the
units edited in place, which held every purged tree until a clean.
@Frotty

Frotty commented Oct 22, 2026

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: 293c96adf0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Frotty
Frotty merged commit 9893fb9 into master Oct 22, 2026
2 checks passed
@Frotty
Frotty deleted the body-edit-keeps-nodes branch November 25, 2026 08:53
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.

1 participant