Commit Graph

724 Commits

Author SHA1 Message Date
Michael Pfaff 1917ae1569
Expose internal apis 2023-07-10 23:43:38 -04:00
Michael Pfaff d0b9ad3c48
Allow C functions to yield (unforseen consequences be damned) 2023-07-06 22:13:31 -04:00
vegorov-rbx 76bea81a7b
Sync to upstream/release/582 (#960)
* Optimized operations like instantiation and module export for very
large types

In our new typechecker:
* Typechecking of function calls was rewritten to handle more cases
* Fixed a crash that can happen after self-referential type is exported
from a module
* Fixed a false positive error in string comparison
* Added handling of `` variable type annotations and fixed
issues with the iterator call inside
* Self-referential 'hasProp' and 'setProp' constraints are now handled
In our native code generation (jit):
* Added '--target' argument to luau-compile to test multiple
architectures different from host architecture
* GC barrier tag check is skipped if type is already known to be
* Added GET_TYPE/GET_TYPEOF instructions for type/typeof fast-calls
* Improved code size of interrupt handlers on X64
2023-06-23 23:19:39 -07:00
Andy Friesen d458d240cd
Sync to upstream/release/581 (#958)
* Definition files can now ascribe indexers to class types.
* Remove --compile support from the REPL. You can just use luau-compile
* When an exception is thrown during parallel typechecking (usually an
ICE), we now gracefully stop typechecking and drain active workers
before rethrowing the exception.

New solver

* Include more source location information when we hit an internal
compiler error
* Improve the logic that simplifies intersections of tables


* Save testable type annotations to bytecode
* Improve block placement for linearized blocks
* Add support for lea reg, [rip+offset] for labels
* Unify X64 and A64 codegen for RETURN
* Outline interrupt handlers for X64
* Remove global rArgN in favor of build.abi
* Change A64 INTERRUPT lowering to match X64


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-06-16 10:35:18 -07:00
JohnnyMorganz bc0722471f
Add support for ClassType indexer in definition files (#949) 2023-06-12 13:02:54 -07:00
RadiatedExodus 7fa69377be
Fix Arch Linux install instructions to use AUR (#953)
The existing instruction is incorrect, the luau package exists on the
Arch Linux User Repository (AUR), not at the official repository.

Feel free to suggest edits if something is wrong/missing, thanks!

(I also have a pkgbuild that builds every executable possible excluding
tests (repl, analyze, ast, reduce), however I did not include this since
releases only include repl and analyze)
2023-06-12 12:06:28 -07:00
Arseny Kapoulkine ba65b0e9cd
Build and use luau-compile in CI (#952) 2023-06-12 08:46:44 -07:00
vegorov-rbx 3ecd3a82ab
Sync to upstream/release/580 (#951)
* Added luau-compile executable target to build/test compilation without
having full REPL included.

In our new typechecker:
* Fixed the order in which constraints are checked to get more
deterministic errors in different environments
* Fixed `isNumber`/`isString` checks to fix false positive errors in
binary comparisons
* CannotCallNonFunction error is reported when calling an intersection
type of non-functions
In our native code generation (jit):
* Outlined X64 return instruction code to improve code size
* Improved performance of return instruction on A64
* Added construction of a dominator tree for future optimizations
2023-06-09 10:08:00 -07:00
Arseny Kapoulkine febebde72a
Update (#948)
We haven't updated this document in a while and yet there was a fair
amount of performance work, some of which can be documented here.

Note that this is not fully comprehensive in that it excludes a lot of
internal tuning that is difficult to describe other than with "we made
things faster".
2023-06-06 15:11:29 -07:00
Ben Mactavsin e78897229a
Fix website demo's string highlighting behaviour (#942)
Fixes #935:
* String literals that include `\z` escape sequence followed by newline
characters are now correctly highlighted.
* Unescaped backslash (`\`) character at the end of the line no longer
acts like the `\z` escape sequence inside string literals when
2023-06-06 11:22:31 -07:00
Ben Mactavsin 4f82a77396
Update to specify language on fenced code blocks which have none (#946)
Specified language on the last two fenced code blocks in the page as
they were inconsistent with the others on the same page.
2023-06-06 08:57:36 -07:00
Andy Friesen 63679f7288
Sync to upstream/release/579 (#943)
A pretty small changelist this week:

* When type inference fails to find any matching overload for a
function, we were declining to commit any changes to the type graph at
all. This was resulting in confusing type errors in certain cases. Now,
when a matching overload cannot be found, we always commit to the first
overload we tried.


* Fix missing variadic register invalidation in FALLBACK_GETVARARGS
* Add a missing null pointer check for the result of luaT_gettm


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-06-02 12:52:15 -07:00
vegorov-rbx 271c509046
Sync to upstream/release/578 (#939)
* Fixed gcc warning about uninitialized `std::optional`
* Fixed inlining of functions when they are used to compute their own

In the new type solver:
* Type families that are not part of a function signature cannot be
resolved at instantiation time and will now produce an error. This will
be relaxed in the future when we get constraint clauses on function
signatures (internally)
* `never` type is now comparable
* Improved typechecking of `` statements
* Fixed checks for number type in `Add` type family
* Performance was improved, with particularly large gains on large

And in native code generation (jit):
* We eliminated the call instruction overhead when native code support
is enabled in the VM
* Small optimizations to arm64 lowering
* Reworked LOP_GETIMPORT handling to reduce assembly code size
* Fixed non-deterministic binary output
* Fixed bad code generation caused by incorrect SSA to VM register links


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Andy Friesen <>
2023-05-25 14:36:34 -07:00
Andy Friesen 721f6e10fb
Sync to upstream/release/577 (#934)
Lots of things going on this week:

* Fix a crash that could occur in the presence of a cyclic union. We
shouldn't be creating cyclic unions, but we shouldn't be crashing when
they arise either.
* Minor cleanup of `luau_precall`
* Internal change to make L->top handling slightly more uniform
* Optimize SETGLOBAL & GETGLOBAL fallback C functions.
* The syntax to the `luau-reduce` commandline tool has changed. It now
accepts a script, a command to execute, and an error to search for. It
no longer automatically passes the script to the command which makes it
a lot more flexible. Also be warned that it edits the script it is
passed **in place**. Do not point it at something that is not in source

New solver

* Switch to a greedier but more fallible algorithm for simplifying union
and intersection types that are created as part of refinement
calculation. This has much better and more predictable performance.
* Fix a constraint cycle in recursive function calls.
* Much improved inference of binary addition. Functions like `function
add(x, y) return x + y end` can now be inferred without annotations. We
also accurately typecheck calls to functions like this.
* Many small bugfixes surrounding things like table indexers
* Add support for indexers on class types. This was previously added to
the old solver; we now add it to the new one for feature parity.


* Fuse key.value and loads for CEHCK_SLOT_MATCH in A64
* Implement remaining aliases of BFM for A64
* Implement new callinfo flag for A64
* Add instruction simplification for int->num->int conversion chains
* Don't even load execdata for X64 calls
* Treat opcode fallbacks the same as manually written fallbacks


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-05-19 12:37:30 -07:00
Alex Orlenko da0458bf6e
Add CodeGen C API (#931)
I'd like to experiment with the codegen feature (currently experimental)
and need a public C API for this.

This PR addresses this.
2023-05-18 04:03:29 -07:00
mundusnine cf0ba32597
Enable compile-time user configuration for LUA_VECTOR_SIZE (#929)
Add #ifndef guard to enable users to define at compile-time without
having to modify the luau source.
2023-05-16 05:04:49 -07:00
vegorov-rbx 97965c7c0a
Sync to upstream/release/576 (#928)
* `ClassType` can now have an indexer defined on it. This allows custom
types to be used in `t[x]` expressions.
* Fixed search for closest executable breakpoint line. Previously,
breakpoints might have been skipped in `else` blocks at the end of a
* Fixed how unification is performed for two optional types `a? <: b?`,
previously it might have unified either 'a' or 'b' with 'nil'. Note that
this fix is not enabled by default yet (see the list in

In the new type solver, a concept of 'Type Families' has been
Type families can be thought of as type aliases with custom type
inference/reduction logic included with them.
For example, we can have an `Add<T, U>` type family that will resolve
the type that is the result of adding two values together.
This will help type inference to figure out what 'T' and 'U' might be
when explicit type annotations are not provided.
In this update we don't define any type families, but they will be added
in the near future.
It is also possible for Luau embedders to define their own type families
in the global/environment scope.

Other changes include:
* Fixed scope used to find out which generic types should be included in
the function generic type list
* Fixed a crash after cyclic bound types were created during unification

And in native code generation (jit):
* Use of arm64 target on M1 now requires macOS 13
* Entry into native code has been optimized. This is especially
important for coroutine call/pcall performance as they involve going
through a C call frame
* LOP_LOADK(X) translation into IR has been improved to enable type
tag/constant propagation
* arm64 can use integer immediate values to synthesize floating-point
* x64 assembler removes duplicate 64bit numbers from the data section to
save space
* Linux `perf` can now be used to profile native Luau code (when running
with --codegen-perf CLI argument)
2023-05-12 10:50:47 -07:00
JohnnyMorganz 8d8c7974f5
Use correct globalScope in on demand type checker (#923)
Fixes #922 

Unsure if this needs to be put behind another FFlag, since the on demand
type checker fflag currently exists
2023-05-11 04:35:56 -07:00
Jan 45c6476d41
Add missing include for integer types (#925)
Closes #924

`uintptr_t` and `uint32` (and possibly more) were undefined because
`cstdint` was not included.
2023-05-09 11:42:13 -07:00
Andy Friesen 0014905b69
Luau.Analyze.CLI must link pthreads on Linux. (#920) 2023-05-05 15:41:46 -07:00
Andy Friesen 8453570658
Sync to upstream/release/575 (#919)
* `Luau.Analyze.CLI` now has experimental support for concurrent type
checking. Use the option `-jN` where `N` is the number of threads to
* Improve typechecking performance by ~17% by making the function
`Luau::follow` much more efficient.
* Tighten up the type of ``
* Removed `ParseOptions::allowTypeAnnotations` and

New solver

* Improve the reliability of function overload resolution
* More work toward supporting parallel type checking
* Fix a bug in inference of `==` and `~=` which would erroneously infer
that the operands were `boolean`
* Better error reporting when `` loops are used incorrectly.


* Fix unwind registration when libunwind is used on Linux
* Fixed replaced IR instruction use count
* Convert X64 unwind info generation to standard prologue
* Implement A64 unwind info support for Dwarf2
* Live in/out data for linear blocks is now created
* Add side-exit VM register requirements to the IR dump
* Reuse ConstPropState between block chains 
* Remove redundant base update


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-05-05 14:52:49 -07:00
JohnnyMorganz 5891de6724
Fix grammar issues (#915)
- The type list for function declarations does not accept defaults, but
the grammar incorrectly allowed this.
- Allow the empty table type `{}`
- Allow composite types and types surrounded by parentheses (e.g.
`string??`, `(string)`, `(string | number) & boolean`)


Co-authored-by: vegorov-rbx <>
2023-05-04 05:39:18 -07:00
JohnnyMorganz e8c0550586
Improve the type for `` using overloads (#874)
Improves the type of `` based on its documentation

We know that the DateTypeResult table is only returned when the format
string is either "*t" or "!*t", and otherwise its just a formatted
string. This changes the type to showcase this appropriately.

I put the more strict type first in the overload because the ordering
makes a difference

Note: the API docs used in studio
may need to be updated to reflect the overloaded type instead.


It may be possible to add a lint of this too to provide analysis similar
to how `string.format` works with a FormatString error. Will leave that
for a different PR though
2023-05-01 08:09:05 -07:00
vegorov-rbx 4b267aa5c5
Sync to upstream/release/574 (#910)
* Added a limit on how many instructions the Compiler can safely produce
(reported by @TheGreatSageEqualToHeaven)

C++ API Changes:
* With work started on read-only and write-only properties,
`Property::type` member variable has been replaced with `TypeId type()`
and `setType(TypeId)` functions.
* New `LazyType` unwrap callback now has a `void` return type, all
that's required from the callback is to write into `unwrapped` field.

In our work on the new type solver, the following issues were fixed:

* Work has started to support and
* Refinements are no longer applied on l-values, removing some
false-positive errors
* Improved overload resolution against expected result type
* `Frontend::prepareModuleScope` now works in the new solver
* Cofinite strings are now comparable

And these are the changes in native code generation (JIT):

* Fixed MIN_NUM and MAX_NUM constant fold when one of the arguments is
* Added constant folding for number conversions and bit operations
* Value spilling and rematerialization is now supported on arm64
* Improved FASTCALL2K IR generation to support second argument constant
* Added value numbering and load/store propagation optimizations
* Added STORE_VECTOR on arm64, completing the IR lowering on this target
2023-04-28 12:55:13 -07:00
JohnnyMorganz 8173491d86
Update (#909)
Fix issues mentioned in
2023-04-24 14:21:26 -05:00
Andy Friesen fe7621ee8c
Sync to upstream/release/573 (#903)
* Work toward affording parallel type checking
* The interface to `LazyType` has changed:
* `LazyType` now takes a second callback that is passed the `LazyType&`
itself. This new callback is responsible for populating the field
`TypeId LazyType::unwrapped`. Multithreaded implementations should
acquire a lock in this callback.
* Modules now retain their `humanReadableNames`. This reduces the number
of cases where type checking has to call back to a `ModuleResolver`.
* Add timing info to the Luau REPL compilation output

We've also fixed some bugs and crashes in the new solver as we march
toward readiness.
* Thread ICEs (Internal Compiler Errors) back to the Frontend properly
* Refinements are no longer applied to lvalues
* More miscellaneous stability improvements

Lots of activity in the new JIT engine:

* Implement register spilling/restore for A64
* Correct Luau IR value restore location tracking
* Fixed use-after-free in x86 register allocator spill restore
* Use btz for bit tests
* Finish branch assembly support for A64
* Codesize and performance improvements for A64
* The bit32 library has been implemented for arm and x64


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-04-21 15:14:26 -07:00
JohnnyMorganz 8ed808eb52
Add prefix and name location to AstTypeReference (#902)
Closes #901
2023-04-17 07:19:56 -07:00
vegorov-rbx d141a5c48d
Sync to upstream/release/572 (#899)
* Fixed exported types not being suggested in autocomplete
* `T...` is now convertible to `...any` (Fixes
* Fixed issue with `T?` not being convertible to `T | T` or `T?`
(sometimes when internal pointer identity is different)
* Fixed potential crash in missing table key error suggestion to use a
similar existing key
* `lua_topointer` now returns a pointer for strings

C++ API Changes:
* `prepareModuleScope` callback has moved from TypeChecker to Frontend
* For LSPs, AstQuery functions (and `isWithinComment`) can be used
without full Frontend data

A lot of changes in our two experimental components as well.

In our work on the new type-solver, the following issues were fixed:
* Fixed table union and intersection indexing
* Correct custom type environments are now used
* Fixed issue with values of `free & number` type not accepted in
numeric operations

And these are the changes in native code generation (JIT):
* arm64 lowering is almost complete with support for 99% of IR commands
and all fastcalls
* Fixed x64 assembly encoding for extended byte registers
* More external x64 calls are aware of register allocator
* `math.min`/`math.max` with more than 2 arguments are now lowered to IR
as well
* Fixed correctness issues with `math` library calls with multiple
results in variadic context and with x64 register conflicts
* x64 register allocator learnt to restore values from VM memory instead
of always using stack spills
* x64 exception unwind information now supports multiple functions and
fixes function start offset in Dwarf2 info
2023-04-14 11:06:22 -07:00
Petri Häkkinen 7345891f6b
Add lua_getuserdatadtor (#870)
Some userdata objects may need to support manual destruction in addition
to automatic GC. For example, files, threads, GPU resources and objects
with large external allocations.

With Lua, a finalizer can be _generically_ called by invoking the __gc
metamethod manually, but this is currently not possible with tagged
userdata in Luau because it's not possible to query the destructor
associated with an userdata. While it is possible to workaround this by
duplicating the destructor table locally on client side (*), it's more
convenient to deduplicate the data and get the destructor using the API

(*) Note: a separate destructor table for each VM may be required if the
VMs use different set of tags.

Implementation notes:

1. I first considered adding a typedef for lua_Destructor but
unfortunately there are two kinds of destructors, one with and one
without the lua_State* argument, so I decided against it at this point.
Maybe it should be added later if the destructor API is unified (by
dropping the Lua state pointer argument?).

2. For some reason the conformance test produced warning "qualifier
applied to function type has no meaning; ignored" on VS2017 (possibly
because the test framework does not like function pointers for some
reason?). I silenced this by pulling out the test expressions from those
2023-04-11 12:46:55 -07:00
Andy Friesen ba67fb275e
Sync to upstream/release/571 (#895)
* `table.sort` was improved further. It now guarentees N*log(N) time
complexity in the worst case.
* Fix

We are also working on fixing final bugs and crashes in the new type

On the CodeGen front we have a few things going on:
* We have a smarter register allocator for the x86 JIT
* We lower more instructions on arm64
* The vector constructor builtin is now translated to IR


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-04-07 14:01:29 -07:00
vegorov-rbx d148d7d574
Luau Recap: March 2023 (#886) 2023-03-31 11:52:31 -07:00
vegorov-rbx 1212fdacbf
Sync to upstream/release/570 (#885)
Once again, all of our changes this week are for new type solver and the

In the new type solver, we fixed cyclic type alias handling and multiple
stability issues.

In the JIT, our main progress was for arm64, where, after lowering 36%
of instructions, we start seeing first Luau functions executing
For x64, we performed code cleanup and refactoring to allow for future
2023-03-31 11:42:49 -07:00
Andy Friesen b4ebad4862
Sync to upstream/release/569 (#878)
All of our changes this week have been focused on the new type solver
and the JIT.

As we march toward feature parity with the old solver, we've tightened
up a bunch of lingering issues with overload resolution, unsealed
tables, and type normalization. We've also fixed a bunch of crashes and
assertion failures in the new solver.

On the JIT front, we've started work on an A64 backend, improved the IR
analysis in a bunch of cases, and implemented assembly generation for
the builtin functions `type()` and `typeof()`.


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-03-24 11:03:04 -07:00
Petri Häkkinen 0d6aacf407
RFC: Floor division operator (#832)
2023-03-20 15:12:48 -07:00
Arseny Kapoulkine a4b31f940a
Remove weak opposition to `//` operator as we decided to merge the RFC to support it.
2023-03-20 11:09:58 -07:00
vegorov-rbx 42a2805f85
Sync to upstream/release/568 (#865)
* A small subset of control-flow refinements have been added to
recognize type options that are unreachable after a
conditional/unconditional code block. (Fixes

Some examples:
local function f(x: string?)
    if not x then return end

    -- x is 'string' here
Throwing calls like `error` or `assert(false)` instead of 'return' are
also recognized.
Existing complex refinements like type/typeof and tagged union checks
are expected to work, among others.

To enable this feature, `LuauTinyControlFlowAnalysis` exclusion has to
be removed from `ExperimentalFlags.h`.
If will become enabled unconditionally in the near future.

* Linter has been integrated into the typechecker analysis so that
type-aware lint warnings can work in any mode
`Frontend::lint` methods were deprecated, `Frontend::check` has to be
used instead with `runLintChecks` option set.
Resulting lint warning are located inside `CheckResult`.

* Fixed large performance drop and increased memory consumption when
array is filled at an offset (Fixes
* Part of [Type error suppression
was implemented making subtyping checks with `any` type transitive.

In our work on the new type-solver:
* `--!nocheck` mode no longer reports type errors
* New solver will not be used for `--!nonstrict` modules until all
issues with strict mode typechecking are fixed
* Added control-flow aware type refinements mentioned earlier

In native code generation:
* `LOP_NAMECALL` has been translated to IR
* `type` and `typeof` builtin fastcalls have been translated to
* Additional steps were taken towards arm64 support
2023-03-17 12:20:37 -07:00
Alan Jeffrey 9311c0c57a
Add RFC for type error suppression (#835)
This formalizes our strategy for suppressing type errors, and fixes the
weirdness of `any` being both a top and bottom type.
2023-03-13 19:33:27 -05:00
Arseny Kapoulkine 29d0ea10cf
Add DCR solver to analysis benchmarks (#862)
For now just do this in strict mode. This will help us track performance
over time, although for now the behavior is going to keep changing so
it's not going to be a fully solid metric for a few weeks.
2023-03-13 13:58:29 -07:00
Andy Friesen 1fa8311a18
Sync to upstream/release/567 (#860)
* Fix #817 
* Fix #850 
* Optimize math.floor/ceil/round with SSE4.1
    * Results in a ~7-9% speedup on the math-cordic benchmark.
* Optimized table.sort.
* table.sort is now ~4.1x faster (when not using a predicate) and ~2.1x
faster when using a simple predicate. Performance may improve further in
the future.
* Reorganize the memory ownership of builtin type definitions.
* This is a small initial step toward affording parallel typechecking.

The new type solver is coming along nicely. We are working on fixing
crashes and bugs.

A few major changes to native codegen landed this week:
* Fixed lowering of Luau IR mod instruction when first argument is a
* Added VM register data-flow/capture analysis
* Fixed issues with optimizations in unreachable blocks


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-03-10 12:21:07 -08:00
niansa/tuxifan 78798d4641
Fixed lerp() duplicate when compiling for C++20 (#851) 2023-03-06 04:42:59 -08:00
vegorov-rbx 140e5a1495
Sync to upstream/release/566 (#853)
* Fixed incorrect lexeme generated for string parts in the middle of an
interpolated string (Fixes
* DeprecatedApi lint can report some issues without type inference
* Fixed performance of autocomplete requests when suggestions have large
intersection types (Solves
* Marked `table.getn`/`foreach`/`foreachi` as deprecated ([RFC:
* With -O2 optimization level, we now optimize builtin calls based on
known argument/return count.
Note that this change can be observable if `getfenv/setfenv` is used to
substitute a builtin, especially if arity is different.
Fastcall heavy tests show a 1-2% improvement.
* Luau can now be built with clang-cl (Fixes

We also made many improvements to our experimental components.

For our new type solver:
* Overhauled data flow analysis system, fixed issues with 'repeat'
loops, global variables and type annotations
* Type refinements now work on generic table indexing with a string
* Type refinements will properly track potentially 'nil' values (like
t[x] for a missing key) and their further refinements
* Internal top table type is now isomorphic to `{}` which fixes issues
when `typeof(v) == 'table'` type refinement is handled
* References to non-existent types in type annotations no longer resolve
to 'error' type like in old solver
* Improved handling of class unions in property access expressions
* Fixed default type packs
* Unsealed tables can now have metatables
* Restored expected types for function arguments

And for native code generation:
* Added min and max IR instructions mapping to vminsd/vmaxsd on x64
* We now speculatively extract direct execution fast-paths based on
expected types of expressions which provides better optimization
opportunities inside a single basic block
* Translated existing math fastcalls to IR form to improve tag guard
removal and constant propagation
2023-03-03 12:21:14 -08:00
Arseny Kapoulkine 48172dd5b1
Note that native code gen is currently exempt from any security guarantees as it's a pre-production R&D component right now. This will change in the future as we deploy it to production.
2023-03-01 14:40:40 -08:00
Arseny Kapoulkine 6601c41bff
Correct table.getn/foreach deprecation RFC (#848)
It looks like all three functions actually have been deprecated in Lua
5.1, and removed in Lua 5.2.

We do not plan to remove them to retain backwards compatibility, but the
RFC should be more precise.
2023-02-27 12:30:33 -08:00
Arseny Kapoulkine aef99ae0d4
docs: Add deprecation notice to getn/foreach/foreachi (#849)
2023-02-27 12:30:23 -08:00
Andy Friesen d2ab5df62b
Sync to upstream/release/565 (#845)
We've made a few small changes to reduce the amount of stack we use when
typechecking nested method calls (eg `foo:bar():baz():quux()`).

We've also fixed a small bytecode compiler issue that caused us to emit
redundant jump instructions in code that conditionally uses `break` or

On the new solver, we've switched to a new, better way to handle
augmentations to unsealed tables. We've also made some substantial
improvements to type inference and error reporting on function calls.
These things should both be on par with the old solver now.

The main improvements to the native code generator have been elimination
of some redundant type tag checks. Also, we are starting to inline
particular fastcalls directly to IR.


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-02-24 13:49:38 -08:00
B. Gibbons fbd93cbc03
docs: update readme installation guide (#792)
1. Added information about Homebrew installation (based off this
information [here](
2. Added details related to installing binary files that are downloaded
3. Rearranged and added titles for easier reading

Fixes #791.

Co-authored-by: Arseny Kapoulkine <>
2023-02-23 13:08:45 -08:00
vegorov-rbx b570ff0a37
Sync to upstream/release/564 (#841)
This week we only have updates to new type solver and JIT. Both projects
are still in the process of being built out. Neither are ready for
general use yet.

In the new solver, we fixed issues with recursive type aliases.
Duplicated type parameters are once again reported, exported types are
being recorder and function argument names are placed inside function
We also made improvements to restore parts of bidirectional type

On native code generation side, namecall instruction lowering was fixed,
we fixed inconsistencies in IR command definitions and added utility
function to help with constant folding.
2023-02-17 15:41:51 -08:00
Arseny Kapoulkine 2e5f95ca58
Update 2023-02-14 12:25:58 -08:00
Arseny Kapoulkine 8f37fc6dfc
RFC: Deprecate table.getn/foreach/foreachi (#715)
2023-02-14 12:25:12 -08:00
Arseny Kapoulkine 742702a17d
This RFC is abandoned; for posterity we will keep this in the tree for now, as it's likely that it represents a subset of the future set of LTI rules
2023-02-14 12:23:54 -08:00
Andy Friesen c5089def6e
Sync to upstream/release/563 (#833)
* Fix a bug where reading a property from an unsealed table caused
inference to improperly infer the existence of that property.
* Fix #827

We have also made a lot of progress on the new solver and the JIT. Both
projects are still in the process of being built out. Neither are ready
for general use yet.

We are mostly working to tighten up how the new solver handles
refinements and updates to unsealed tables to bring it up to the same
level as the old solver.


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-02-10 11:40:38 -08:00
Epix 18a1dc3440
Fix comments on jump instructions with AUX (#808)
It seems like for jump instructions that include an AUX 32-bit word,
that index is included as part of the jump offset.
2023-02-09 06:12:58 -08:00
vegorov-rbx c5555c6573
News about string interpolation feature and a syntax page update (#829)
News can be viewed
And syntax can be viewed

Note that link appears to be broken in the news section. It goes to
`` instead of
The link I use in the source is `/syntax#string-interpolation` but the
root 'offset' is different on Luau website (doesn't have extra 'luau'
folder) and on my GitHub pages.
Hope this is ok. But if GitHub page masters know how to avoid this,
please let me know.


Co-authored-by: Alan Jeffrey <>
Co-authored-by: Alexander McCord <>
2023-02-03 11:41:13 -08:00
vegorov-rbx 62483d40f0
Sync to upstream/release/562 (#828)
* Fixed rare use-after-free in analysis during table unification

A lot of work these past months went into two new Luau components:
* A near full rewrite of the typechecker using a new deferred constraint
resolution system
* Native code generation for AoT/JiT compilation of VM bytecode into x64
(avx)/arm64 instructions

Both of these components are far from finished and we don't provide
documentation on building and using them at this point.
However, curious community members expressed interest in learning about
changes that go into these components each week, so we are now listing
them here in the 'sync' pull request descriptions.

New typechecker can be enabled by setting
DebugLuauDeferredConstraintResolution flag to 'true'.
It is considered unstable right now, so try it at your own risk.
Even though it already provides better type inference than the current
one in some cases, our main goal right now is to reach feature parity
with current typechecker.
Features which improve over the capabilities of the current typechecker
are marked as '(NEW)'.

Changes to new typechecker:
* Regular for loop index and parameters are now typechecked
* Invalid type annotations on local variables are ignored to improve
* Fixed missing autocomplete type suggestions for function arguments
* Type reduction is now performed to produce simpler types to be
presented to the user (error messages, custom LSPs)
* Internally, complex types like '((number | string) & ~(false?)) |
string' can be produced, which is just 'string | number' when simplified
* Fixed spots where support for unknown and never types was missing
* (NEW) Length operator '#' is now valid to use on top table type, this
type comes up when doing typeof(x) == "table" guards and isn't available
in current typechecker

Changes to native code generation:
* Additional math library fast calls are now lowered to x64: math.ldexp,
math.round, math.frexp, math.modf, math.sign and math.clamp
2023-02-03 11:26:13 -08:00
Andy Friesen f763f4c948
Sync to upstream/release/561 (#820)
* Fix a potential debugger crash by adding checks for invalid stack
index values


Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-01-27 14:28:31 -08:00
vegorov-rbx 4a2e8013c7
Sync to upstream/release/560 (#810)
* For autocomplete, additional information is included in Scope for type
alias name locations and names of imported modules
* Improved autocomplete suggestions in 'for' and 'while' loop headers
* String match functions return types are now optional strings and
numbers because match is not guaranteed at runtime
* Fixed build issue on gcc 11 and up (Fixes
2023-01-20 12:27:03 -08:00
Harold Cindy 729bc44729
Fix lua_*upvalue() when upvalue names aren't in debug info (#787)
`lua_getupvalue()` and `lua_setupvalue()` don't behave as expected when
working with Lua closure whose `Proto` has no debug info. The code
currently uses `sizeupvalues` to do bounds checking of upvalue indices,
but that's the size of the upvalue _names_ array. It will always be `0`
if the `Proto` doesn't have debug info.

This uses `nups` instead, and just returns `""` as the upvalue name if
we don't have one, same as for C closures.

Co-authored-by: Harold Cindy <>
2023-01-18 06:00:13 -08:00
Andy Friesen a5c6a38b10
Sync to upstream/release/559 (#804)
* Fix autocompletion of if-then-else expressions
* Fix a potential crash surrounding improper use of `%*` in a string
format specifier
* All Python scripts now invoke Python via `python3` rather than
* Improved error handling for string interpolation with too many

Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Vyacheslav Egorov <>
2023-01-13 14:10:01 -08:00
JohnnyMorganz 0af10417cd
Attach definition location to `TableType` (#801)
Having the location where the table type is defined is useful for
tracking other info such as documentation comments, or pointing back
through "Go To Definition" functionality etc.

This adds in the required info
2023-01-12 06:21:25 -08:00
JohnnyMorganz 86494918f5
Pass string content to autocomplete callback (#800)
Closes #718 

We pass an extra `contents` parameter to the string callback function to
provide contextual information for autocomplete.

Because we support both string literals and simple interpolated strings,
we pass it through as a `std::string` value.

This is a breaking change
2023-01-11 08:28:11 -08:00
vegorov-rbx be52bd91e4
Sync to upstream/release/558 (#796)
* Fixed garbage data in module scopes when type graph is not retained
* LOP_MOVE with the same source and target registers is no longer
generated (Fixes
2023-01-06 13:14:35 -08:00
vegorov-rbx 685ca02a30
Keep using ubuntu-20.04 in GitHub Actions (and clang++-10 in coverage) (#795)
### Problem
ubuntu-latest was updated to 22.04 which removes clang++-10 we used for
coverage stats and creates a pre-compiled binary that requires a glibc

### Solution
Pin to ubuntu-20.04 using multi-value matrix configurations.
In coverage configuration, we use clang++-10 once again.
2023-01-06 12:17:25 -08:00
vegorov-rbx 75a2e95714
Sync to upstream/release/557 (#794)
* Fixed unions of `nil` types displaying as `?`
* Internal normalization now handles class types which can make
previously failing (incorrectly) sub-typing checks to succeed
2023-01-04 12:53:17 -08:00
Andy Friesen fb2f146123
Sync to upstream/release/556 (#782)
* The AST JSON encoder will now stringify infinity and NaN according to the JSON5 spec using the tokens `Infinity`, `-Infinity`, and `NaN`.
* Improve autocompletion of table keys if the type of that key is a union of string singletons.
2022-12-09 11:57:01 -08:00
Alex Orlenko e9d4ee7a33
Make pseudo-indices relative to LUAI_MAXCSTACK (#766)
This is useful in particular if redefine `LUAI_MAXCSTACK` to a higher
value than the current one (8000).
Ie. passing `-D LUAI_MAXCSTACK=1000000` would not work as overlaps with
2022-12-06 11:20:24 -08:00
vegorov-rbx 4e6ae32625
Luau Recap: November 2022 (#764)
Co-authored-by: Andy Friesen <>
2022-12-02 10:23:20 -08:00
vegorov-rbx 59ae47db43
Sync to upstream/release/555 (#768)
* Type mismatch errors now mention if unification failed in covariant or
invariant context, to explain why sometimes derived class can't be
converted to base class or why `T` can't be converted into `T?` and so
* Class type indexing is no longer an error in non-strict mode (still an
error in strict mode)
* Fixed cyclic type packs not being displayed in the type
* Added an error when unrelated types are compared with `==`/`~=`
* Fixed false positive errors involving sub-type tests an `never` type
* Fixed miscompilation of multiple assignment statements (Fixes
* Type inference stability improvements
2022-12-02 10:09:59 -08:00
vegorov-rbx 91302d1d4c
Fix coverage github action by using clang++ without a specific version (#769)
Github fails to find clang++-10.
Since we install llvm without a specific version number, we shouldn't
use clang++-10 with a version number.

I tried installing llvm-10, but that package is not available on github
(any more?).
2022-12-02 10:08:55 -08:00
JohnnyMorganz 9095fc4b83
Support `__call` on class type vars (#762)
Currently, the metatable of a class type var is not correctly checked to
see if it is callable (i.e. has a `__call` metatable).
We resolve this issue by checking the metatable in `checkCallOverload`

Fixes #756

Co-authored-by: vegorov-rbx <>
2022-11-28 10:02:41 -08:00
JohnnyMorganz 7dbe47f4dd
Handle cyclically referenced declared classes (#729)
Closes #631 

Performs a "two pass" approach, where we first call `prototype` on the
class definition.
The prototype phase checks for errors and creates a base CTV for the
class, which other types can then reference.

The second `check` phase fills it out with all the defined

Co-authored-by: vegorov-rbx <>
2022-11-28 05:25:44 -08:00
Andy Friesen 95d9c6d194
Sync to upstream/release/553 (#751)
* Autocomplete support for interpolated strings.
* Improved parse errors in various situations involving interpolated
2022-11-18 11:47:21 -08:00
boyned//Kampfkarren aa7c64517c
Fix string interpolation autocomplete and location (#748)
String interpolation autocomplete was not working and was just using
default autocomplete. This fixes it so that inside a string it is
treated as normal, and inside an expression it suggests expression level

Also fixes the range, which was previously just the first lexeme.
2022-11-16 10:15:01 -08:00
vegorov-rbx 816e41a8f2
Sync to upstream/release/553 (#742)
* Type inference of `a and b` and `a or b` has been improved (Fixes
* Improved error message when `for ... in x` loop iterates over a value
that could be 'nil'
* Return type of `next` not includes 'nil' (Fixes
* Improved type inference of `string` type
* Luau library table type names are now reported as `typeof(string)`/etc
instead of just `string` which was misleading
* Added parsing error when optional type alias type parameter wasn't
provided after `=` token
* Improved tagged union type refinement in conditional expressions, type
in `else` branch should no longer include previously handled union
2022-11-10 14:53:13 -08:00
Arseny Kapoulkine 0f04d521e6
Add "Luau origins and evolution" post (#737) 2022-11-04 15:26:37 -07:00
Andy Friesen c33700e473
Sync to upstream/release/552 (#735)
* Reduce the stack utilization of type checking.
* Improve the error message that's reported when a delimiting comma is
missing from a table literal. eg
local t = {
    first = 1
    second = 2
2022-11-04 10:33:22 -07:00
Alan Jeffrey e43a9e927c
Added Sep-Oct 2022 Luau Recap (#726) 2022-11-01 12:02:03 -05:00
boyned//Kampfkarren e37eb3c778
Fix { range to be within the interpolated string (#728)
Corrects `{` range to be inside the interpolated string, needed for syntax highlighting.
2022-10-28 12:22:26 -07:00
vegorov-rbx a6b5051edc
Sync to upstream/release/551 (#727)
* Improved `Failed to unify type packs` error message to be reported as
`Type pack 'X' could not be converted into 'Y'`
* 1% reduction in executed instruction count by removing a check in fast
call dispatch
* Additional fixes to reported error location of OOM errors in VM
* Improve `math.sqrt`, `math.floor` and `math.ceil` performance on
additional compilers and platforms (1-2% geomean improvement including
8-9% on math-cordic)
* All thrown exceptions by Luau analysis are derived from
* When a call site has fewer arguments than required, error now reports
the location of the function name instead of the argument to the
* Fixed

Co-authored-by: Arseny Kapoulkine <>
Co-authored-by: Andy Friesen <>
2022-10-28 03:37:29 -07:00
JohnnyMorganz ad7d006fb2
Use overloaded documentation symbol for class methods/table props (#724)
Right now `getDocumentationSymbol` on an overloaded class method or
table prop just gives the prop name, not prepended with `/overload/ +

This causes the incorrect symbol to be used for `table.insert`,
``, `` etc. (present in

Co-authored-by: vegorov-rbx <>
2022-10-25 16:22:19 -07:00
Arseny Kapoulkine e64d489e57
Update benchmark.yml
Add codegennull runs to compile time benchmarks
2022-10-24 17:24:19 -07:00
Andy Friesen 54324867df
Sync to upstream/release/550 (#723)
* Support `["prop"]` syntax on class definitions in definition files.
* Improve type checking performance for complex overloaded functions
* Fix rare cases of incorrect stack traces for out of memory errors at
2022-10-21 10:54:01 -07:00
JohnnyMorganz 12ee1407a1
Add named parameters to `math` lib (#722)
Name the parameters used in `math` lib

This is mainly done to highlight the particular confusion for
`math.atan2`, where `y` comes before `x`, but this might not be
immediately obvious.

And then I added the rest of the names for consistency.

Note: I didn't add names to `math.random` as it's currently typed as
`(number?, number?) -> number`. Naming it `min` and `max` is technically
incorrect for the 1 argument version.
Maybe it should be typed as an intersection instead?
2022-10-21 08:05:56 -07:00
JohnnyMorganz c4c120513f
Fix reverse deps > 1 node away not correctly marked as dirty (#719)
`Frontend.markDirty()` does not correctly mark reverse dependencies that
are not immediate as dirty.
This is because it would keep adding the reverse deps of `name` into the
queue to mark as dirty, instead of the reverse deps of `next`
2022-10-20 09:07:00 -07:00
Alan Jeffrey 662a5532ec
Minor fixes to the semantic subtyping blog post (#720) 2022-10-19 20:32:29 -05:00
Alan Jeffrey ae5a011465
Add a blog post about semantic subtyping (#700)
Co-authored-by: Alexander McCord <>
2022-10-18 16:56:15 -05:00
JohnnyMorganz edb4453924
Support `["prop"]` syntax on class definitions (#704)
Some classes have properties which are not valid identifiers (such as

This adds support for the following syntax in definition files:
declare class Foo
    ["a property"]: string

Closes #702
2022-10-18 10:15:26 -07:00
Arseny Kapoulkine 49d6bc30ad
Add bench-codegen benchmark (#713)
We will now run luau with --codegen during benchmark runs and collect
the data into separate JSON. Note that we don't yet have the historical
data for these, which will be backfilled later.
2022-10-17 12:18:34 -07:00
Arseny Kapoulkine c6a2d75193
Improve testing coverage with codegen/O2 in mind (#709)
This change adds codegen runs to coverage config and adds O2/codegen
testing to CI.

Note that we don't run O2 combinations in coverage - it's better that we
see gaps in O2 coverage in compiler tests, as these are valuable for
validating codegen intricacies that are difficult to see from
conformance tests passing/failing.
2022-10-17 10:02:21 -07:00
vegorov-rbx 76070f8da2
Sync to upstream/release/549 (#707)
* Reoptimized math.min/max/bit32 builtins assuming at least 2 arguments are used (1-2% lift on some benchmarks)
* Type errors that mention function types no longer have redundant parenthesis around return type
* Luau REPL now supports --compile=remarks which displays the source code with optimization remarks embedded as comments
* Builtin calls are slightly faster when called with 1-2 arguments (~1% improvement in some benchmarks)
2022-10-14 12:48:41 -07:00
JohnnyMorganz ff736fd3e4
Fix segfault in `loadDefinition` for unit tests (#705)
`module` can be empty if the definition file has syntax errors
2022-10-14 07:28:54 -07:00
Arseny Kapoulkine d6aa35583e Add new-release action to automatically build & publish release artifacts 2022-10-06 18:44:51 -07:00
Arseny Kapoulkine d5a2a1585e
Sync to upstream/release/548 (#699)
- Fix rare type checking bugs with invalid generic types escaping the
module scope
- Fix type checking of variadic type packs in certain cases
- Implement type normalization, which resolves a large set of various
issues with unions/intersections in type checker
- Improve parse errors for trailing commas in function calls and type
- Reduce profiling skew when using --profile with very high frequencies
- Improve performance of `lua_getinfo` (``, `debug.traceback`
and profiling overhead are now 20% faster/smaller)
- Improve performance of polymorphic comparisons (1-2% lift on some
- Improve performance of closure creation (1-2% lift on some benchmarks)
- Improve string comparison performance (4% lift on string sorting)
2022-10-06 17:23:29 -07:00
Arseny Kapoulkine cc26ef16df
Update release.yml
Use -j2 for release builds since CMake doesn't do it for us
2022-09-29 16:19:37 -07:00
Arseny Kapoulkine 937ef2efd4
Cleanup benchmark builds a little bit (#691)
We don't need to run any cachegrind benchmarks in benchmark-dev, since
benchmark uses our new callgrind setup instead.

Also removes prototyping filters that we no longer need from all builds.
2022-09-29 15:42:23 -07:00
Arseny Kapoulkine 944e8375aa
Sync to upstream/release/547 (#690)
- Type aliases can no longer override primitive types; attempts to do
that will result in a type error
- Fix misleading type error messages for mismatches in expression list
length during assignment
- Fix incorrect type name display in certain cases
- setmetatable/getmetatable are now ~2x faster
- tools/ can be used to display statistics about profiles
captured via --profile switch
2022-09-29 15:23:10 -07:00
Arseny Kapoulkine 1acd66c97d
Remove prototyping/ and prototyping.yml (#688)
Superseded by
2022-09-29 12:13:00 -07:00
Alexander McCord 5414cddb27
Add `unknown` and `never` to (#682)
Co-authored-by: Arseny Kapoulkine <>
2022-09-26 14:18:04 -07:00
Arseny Kapoulkine a7f8c1045c
Fix Markdown formatting
2022-09-24 09:09:02 -07:00
Arseny Kapoulkine 59fd9de485
Sync to upstream/release/546 (#681) 2022-09-23 12:17:25 -07:00
Petri Häkkinen fc4871989a
Add lua_cleartable (#678)
To my understanding lua_cleartable does not need GC barriers because
it's only removing elements and not modifying the stack. But I'm not a
GC expert so please correct if I'm wrong.

resolves #672

Co-authored-by: Petri Häkkinen <>
2022-09-22 09:54:03 -07:00