Skip to content

fix(semantic): make dependent queries safe to re-enter - #1306

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:rewrite-common-reentry
Oct 19, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
lewis6991:rewrite-common-reentry

Conversation

@lewis6991

@lewis6991 lewis6991 commented Oct 16, 2026 •

Copy link
Copy Markdown
Collaborator

Recursive semantic analysis can depend on query order, report incorrect type matches, or overflow the stack. Examples include:

  • Member lookup can depend on query order:

    ---@alias Copy<T> {[K in keyof T]: T[K]}
    ---@alias Node<T> {value: T, copy: Copy<Node<T>>}
  • Valid recursive values can be rejected:

    ---@alias Nested<T> T | Nested<T>[]
    ---@type Nested<string>
    local value = "hello"
  • Invalid recursive comparisons can be accepted:

    ---@alias Link<T> {value: T, next: Link<T>}
    ---@alias Other<T> {value: T, next: Other<T>}
    -- Link<string> must not match Other<integer>.

Share caches and recursion state across file views. Keep unfinished results temporary and evaluate recursive fields only when needed. Use work lists and comparison dependencies to handle recursive types. Leave conditional types unresolved until their result is known.

Allow long finite computations within a shared work budget. Report exhaustion as type-complexity and continue independent checks.

@lewis6991
lewis6991 force-pushed the rewrite-common-reentry branch 6 times, most recently from 855312a to 4528244 Compare October 16, 2026 16:57
@lewis6991
lewis6991 marked this pull request as draft October 16, 2026 23:41
@lewis6991
lewis6991 force-pushed the rewrite-common-reentry branch 3 times, most recently from 2b5e9a1 to 04046ba Compare October 17, 2026 20:36
@xuhuanzy

Copy link
Copy Markdown
Member

We should also change SemanticLocalCache into a cache shared within a single request. The key is to prevent model_for from creating an empty cache.

crates\emmylua_code_analysis\src\semantic_model\access.rs pub fn model_for(&self, file_id: FileId) -> Self

@lewis6991
lewis6991 force-pushed the rewrite-common-reentry branch 5 times, most recently from db7b451 to ffbfeba Compare October 18, 2026 16:49
@lewis6991
lewis6991 marked this pull request as ready for review October 18, 2026 16:49
@MillhioreBT

Copy link
Copy Markdown
Contributor

Tested it and it fixes the issue I was having in my project. I'd actually just opened a PR to fix it, but then realized this one already existed, so I closed mine. Hopefully others can review it and it gets merged. Thanks @lewis6991

@xuhuanzy

Copy link
Copy Markdown
Member

Regarding these two failed checks, I think you can download https://pre-commit.com/ or https://github.com/j178/prek. The current project’s .pre-commit-config.yaml is already configured with Git hooks for this.

@lewis6991
lewis6991 force-pushed the rewrite-common-reentry branch from ffbfeba to 86289d0 Compare October 19, 2026 08:20
Recursive semantic analysis can depend on query order, report incorrect
type matches, or overflow the stack. Examples include:

- Member lookup can depend on query order:

    ---@alias Copy<T> {[K in keyof T]: T[K]}
    ---@alias Node<T> {value: T, copy: Copy<Node<T>>}

- Valid recursive values can be rejected:

    ---@alias Nested<T> T | Nested<T>[]
    ---@type Nested<string>
    local value = "hello"

- Invalid recursive comparisons can be accepted:

    ---@alias Link<T> {value: T, next: Link<T>}
    ---@alias Other<T> {value: T, next: Other<T>}
    -- Link<string> must not match Other<integer>.

Share caches and recursion state across file views. Keep unfinished
results temporary and evaluate recursive fields only when needed. Use
work lists and comparison dependencies to handle recursive types. Leave
conditional types unresolved until their result is known.

Allow long finite computations within a shared work budget. Report
exhaustion as type-complexity and continue independent checks.
@lewis6991
lewis6991 force-pushed the rewrite-common-reentry branch from 86289d0 to fa8cd35 Compare October 19, 2026 08:39
@lewis6991

Copy link
Copy Markdown
Collaborator Author

I have pre-commit installed locally. The schema hook only matches tools/schema_json_gen/src/main.rs, so it can miss changes to the diagnostic enum. CI uses --all and catches these. The schema is updated now; we could also widen the hook’s file filter.

@CppCXY
CppCXY merged commit 51f2aa7 into EmmyLuaLs:main Oct 19, 2026
16 checks passed
@lewis6991
lewis6991 deleted the rewrite-common-reentry branch October 19, 2026 12:08
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.

4 participants