Skip to content

Track type spans in ToStringResult to support decomposition#2163

Merged
vegorov-rbx merged 2 commits intoluau-lang:masterfrom
JohnnyMorganz:to-string-decompositions
Jan 15, 2026
Merged

Track type spans in ToStringResult to support decomposition#2163
vegorov-rbx merged 2 commits intoluau-lang:masterfrom
JohnnyMorganz:to-string-decompositions

Conversation

@JohnnyMorganz
Copy link
Copy Markdown
Contributor

This PR implements a new typeSpans field on ToStringResult to record which TypeId produced parts of the substring in the stringified output. This enables tooling to decompose the result and map positions in the type string back to their source types, powering features such as Go-To-Definition in Inlay Hints.

typeSpans is a vector of {startOffset, endOffset, typeId} within the string. We only populate spans for named types, i.e. extern types and named table / metatable types. The rest of the type kinds are ignored.

Special attention needs to be given for UnionType and IntersectionType. When stringifying these compound types, it works by resetting the state.result.name to an empty string before stringifying the part, then recomposing all the parts back to the full string. This can also include a sorting step.

We need to correct the typeSpans during this approach. We introduce a new ElementResult that stores the resulting string and set of spans for each part. Then when reconstructing, we offset each span by the current size of state.result.name.

These changes are gated behind the FFlag LuauToStringDecomposition

Closes #1591

Copy link
Copy Markdown
Collaborator

@vegorov-rbx vegorov-rbx left a comment

Choose a reason for hiding this comment

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

LGTM

@vegorov-rbx vegorov-rbx merged commit af9f26e into luau-lang:master Jan 15, 2026
7 checks passed
andyfriesen added a commit that referenced this pull request Jan 23, 2026
Hey everyone! We've been hard at work fixing bugs and improving native
codegen. Enjoy!

# Analysis

* Rename the class tag to extern in type functions
* Fix #2204
* Rework type unification in terms of subtyping.

This uses the new solver's understanding of subtyping to drive
unification for
some internal callsites. This is a broad change that should result in
more
    consistent inference.  For example:

    ```luau
    local function sum<T>(x: T, y: T, z: (T, T) -> T) return z(x, y) end
    local function sumrec(f: typeof(sum))
return sum(2, 3, function<X>(g: X, h: X): add<X, X> return g + h end)
    end
-- Prior we would claim that `b` is of type `add<X, X> | number`: not
good!
-- We now correctly claim that it is of type `number` thanks to bug
fixes
    -- made to subtyping that did not make their way to the unifier.
    local b = sumrec(sum)
    ```

# Native Codegen

* Improve vector handling in binary operations
* Fix missed optimization causing an assertion failure
* Propagate loads of STORE_VECTOR components produced by UINT_TO_FLOAT
* Constant-fold new operand of CHECK_BUFFER_LEN
* For register load-store propagation, use the second operand only for
LOAD_FLOAT
* TValue store cannot be removed when it's partially over-written
* Rework equality and ordering comparisons to fix issues and be more
type aware
* Migrate Luau NCG IrInst operands representation to SmallVector

# Runtime

* Fix 64-bit countrz to build on 32 bit Windows.
* Remap Luau local debug and type information after performing jump
expansion
* Add support for building Luau as a shared library
* Luau should be able to make fastcalls even if library name is obscured
by a local polyfill

# OSS Contributions

* #2163
* #2167

# Internal Contributors

Co-authored-by: Ariel Weiss <arielweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Ilya Rezvov <irezvov@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>

---------

Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com>
Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com>
Co-authored-by: Menarul Alam <malam@roblox.com>
Co-authored-by: Aviral Goel <agoel@roblox.com>
Co-authored-by: Vighnesh <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Ilya Rezvov <irezvov@roblox.com>
Co-authored-by: Ariel Weiss <arielweiss@roblox.com>
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.

Provide a decomposition of types when a type is stringified using Luau::toString(ty)

3 participants