Commit Graph

703 Commits

Author SHA1 Message Date
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 <75688451+vegorov-rbx@users.noreply.github.com>
2023-05-04 05:39:18 -07:00
JohnnyMorganz e8c0550586
Improve the type for `os.date` using overloads (#874)
Improves the type of `os.date` based on its documentation
https://create.roblox.com/docs/reference/engine/libraries/os#date

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
(https://github.com/MaximumADHD/Roblox-Client-Tracker/blob/roblox/api-docs/en-us.json)
may need to be updated to reflect the overloaded type instead.


![image](https://user-images.githubusercontent.com/19635171/226919224-e9e8703b-2729-44b0-93f6-434c01bda204.png)

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 https://github.com/Roblox/luau/pull/77 and
https://github.com/Roblox/luau/pull/79
* 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
NaN
* 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 grammar.md (#909)
Fix issues mentioned in https://github.com/Roblox/luau/issues/908
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`.
* https://github.com/Roblox/luau/pull/902
* 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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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
https://github.com/Roblox/luau/issues/767)
* 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
instead.

(*) 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
CHECKs.
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 https://github.com/Roblox/luau/issues/880

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

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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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
JIT.

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
natively.
For x64, we performed code cleanup and refactoring to allow for future
optimizations.
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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2023-03-24 11:03:04 -07:00
Petri Häkkinen 0d6aacf407
RFC: Floor division operator (#832)
[Rendered](https://github.com/petrihakkinen/luau/blob/rfc-floor-division/rfcs/syntax-floor-division-operator.md)
2023-03-20 15:12:48 -07:00
Arseny Kapoulkine a4b31f940a
Update compatibility.md
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
https://github.com/Roblox/luau/issues/356).

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

    -- x is 'string' here
end
```
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
https://github.com/Roblox/luau/issues/590)
* Part of [Type error suppression
RFC](https://github.com/Roblox/luau/blob/master/rfcs/type-error-suppression.md)
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
IR/assembly
* 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
constant
* Added VM register data-flow/capture analysis
* Fixed issues with optimizations in unreachable blocks

---------

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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 https://github.com/Roblox/luau/issues/744)
* DeprecatedApi lint can report some issues without type inference
information
* Fixed performance of autocomplete requests when suggestions have large
intersection types (Solves
https://github.com/Roblox/luau/discussions/847)
* Marked `table.getn`/`foreach`/`foreachi` as deprecated ([RFC:
Deprecate
table.getn/foreach/foreachi](https://github.com/Roblox/luau/blob/master/rfcs/deprecate-table-getn-foreach.md))
* 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
https://github.com/Roblox/luau/issues/736)

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
literal
* 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
Update SECURITY.md
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)
RFC:
https://github.com/Roblox/luau/blob/master/rfcs/deprecate-table-getn-foreach.md
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
`continue`.

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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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](https://formulae.brew.sh/formula/luau#default))
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 <arseny.kapoulkine@gmail.com>
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
types.
We also made improvements to restore parts of bidirectional type
tracking.

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 STATUS.md 2023-02-14 12:25:58 -08:00
Arseny Kapoulkine 8f37fc6dfc
RFC: Deprecate table.getn/foreach/foreachi (#715)
[Rendered](https://github.com/Roblox/luau/blob/zeux-rfc-deptable/rfcs/deprecate-table-getn-foreach.md)
2023-02-14 12:25:12 -08:00
Arseny Kapoulkine 742702a17d
Update lower-bounds-calculation.md
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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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
[here](https://vegorov-rbx.github.io/luau/2023/02/02/luau-string-interpolation.html)
And syntax can be viewed
[here](https://vegorov-rbx.github.io/luau/syntax#string-interpolation)

Note that link appears to be broken in the news section. It goes to
`https://vegorov-rbx.github.io/syntax#string-interpolation` instead of
`https://vegorov-rbx.github.io/luau/syntax#string-interpolation`
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 <403333+asajeffrey@users.noreply.github.com>
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>
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
autocomplete
* 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 <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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
https://github.com/Roblox/luau/issues/806)
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 <HaroldCindy@users.noreply.github.com>
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
`python`.
* Improved error handling for string interpolation with too many
arguments.

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
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 https://github.com/Roblox/luau/issues/793)
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
upgrade https://github.com/Roblox/luau/issues/773

### 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
`LUA_REGISTRYINDEX` and below.
2022-12-06 11:20:24 -08:00
vegorov-rbx 4e6ae32625
Luau Recap: November 2022 (#764)
Co-authored-by: Andy Friesen <andy.friesen@gmail.com>
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
on
* 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
https://github.com/Roblox/luau/issues/754)
* 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 <75688451+vegorov-rbx@users.noreply.github.com>
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
properties/methods

Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
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
strings.
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
autocomplete.

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
https://github.com/Roblox/luau/issues/730)
* Improved error message when `for ... in x` loop iterates over a value
that could be 'nil'
* Return type of `next` not includes 'nil' (Fixes
https://github.com/Roblox/luau/issues/706)
* 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
options
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
```lua
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)
* https://github.com/Roblox/luau/pull/719
* Improved `Failed to unify type packs` error message to be reported as
`Type pack 'X' could not be converted into 'Y'`
* https://github.com/Roblox/luau/pull/722
* 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
`Luau::InternalCompilerError`
* When a call site has fewer arguments than required, error now reports
the location of the function name instead of the argument to the
function
* https://github.com/Roblox/luau/pull/724
* Fixed https://github.com/Roblox/luau/issues/725

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Co-authored-by: Andy Friesen <afriesen@roblox.com>
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/ +
toString(overload)`.

This causes the incorrect symbol to be used for `table.insert`,
`BrickColor.new`, `Color3.new` etc. (present in
https://raw.githubusercontent.com/MaximumADHD/Roblox-Client-Tracker/roblox/api-docs/en-us.json)

Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
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.
(#704)
* Improve type checking performance for complex overloaded functions
* Fix rare cases of incorrect stack traces for out of memory errors at
runtime
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 <11488393+alexmccord@users.noreply.github.com>
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
https://create.roblox.com/docs/reference/engine/classes/Studio)

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

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
lists
- Reduce profiling skew when using --profile with very high frequencies
- Improve performance of `lua_getinfo` (`debug.info`, `debug.traceback`
and profiling overhead are now 20% faster/smaller)
- Improve performance of polymorphic comparisons (1-2% lift on some
benchmarks)
- 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/perfstat.py 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 https://github.com/luau-lang/agda-typeck
2022-09-29 12:13:00 -07:00
Alexander McCord 5414cddb27
Add `unknown` and `never` to typecheck.md (#682)
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
2022-09-26 14:18:04 -07:00
Arseny Kapoulkine a7f8c1045c
Update library.md
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 <petrih@rmd.remedy.fi>
2022-09-22 09:54:03 -07:00
Aaron Weiss bdf7d8c185
RFC: Expanded Subtyping for Generic Function Types (#641)
[Rendered](https://github.com/aatxe/luau/blob/generic-function-subtyping/rfcs/generic-function-subtyping.md)
2022-09-19 13:42:20 -07:00
Arseny Kapoulkine 8b36409c2c
Update build.yml (#675)
Pass codecov token explicitly, for some reason automatic configuration
stopped working
2022-09-16 11:39:30 -07:00
Arseny Kapoulkine 3d74a8f4d4
Sync to upstream/release/545 (#674)
- Improve type error messages for argument count mismatch in certain
cases
- Fix type checking variadic returns when the type is incompatible which
type checked in certain cases
- Reduce size of upvalue objects by 8 bytes on 64-bit platforms
- Reduce I$ footprint of interpreter by 1.5KB
- Reduce GC pause during atomic stage for programs with a lot of threads
- Remove support for bytecode v2
2022-09-15 15:38:17 -07:00
Petri Häkkinen 6fbea7cc84
Add lua_rawsetfield (#671)
Luau currently has the following functions in the C API for dealing with
tables without invoking metamethods:

lua_rawgetfield
lua_rawget
lua_rawgeti
lua_rawset
lua_rawseti

This change adds the missing function lua_rawsetfield for consistency
and because it's more efficient to use it in place of plain lua_rawset
which requires pushing the key and value separately.

Co-authored-by: Petri Häkkinen <petrih@rmd.remedy.fi>
2022-09-15 08:26:54 -07:00
Allan N Jeremy 366df96393
Feat: Added retry functionality to benchmarks (#667)
Resolves #668 

## The problem
Benchmarks jobs run concurrently for the different operating systems.
This means that when it comes time to push the benchmark results to [the
assigned benchmark results
repo](https://github.com/luau-lang/benchmark-data), there can be two
different jobs trying to push changes at the same time. In such a case,
one of the pushes will fail and we end up missing some benchmark results
data from the workflow run.

## The solution
Whenever a push fails, we need to retry the steps leading up to the push
(checking out the benchmark results repo, storing benchmark results,
pushing the results to [a specific
repo](https://github.com/luau-lang/benchmark-data)).

### Note
There are 3 push attempts before submitting to failure.

## TL;DR
This PR retries pushing benchmark results when they fail to get pushed
(often due to pushing from multiple jobs concurrently)

Co-authored-by: Jamie Kuppens <reshurum@gmail.com>
Co-authored-by: Ignacio Falk <flakolefluk@gmail.com>
2022-09-12 08:45:55 -07:00
Arseny Kapoulkine ce2c3b3a4e
Sync to upstream/release/544 (#669)
- Remove type definitions of
`utf8.nfcnormalize`/`nfdnormalize`/`graphemes` that aren't supported by
standalone Luau library
- Add `lua_costatus` to retrieve extended thread status (similar to
`coroutine.status`)
- Improve GC sweeping performance (2-10% improvement on allocation-heavy
benchmarks)
2022-09-08 15:14:25 -07:00
Alexander McCord b2e357da30
Update title and fix a dead link. (#659)
Originally it was titled "Luau Recap: August 2022" but it got renamed to "Luau Recap: July & August 2022" and we just didn't fix the link here too. Also backports the title change to here too for consistency.
2022-09-04 13:05:25 -07:00
Arseny Kapoulkine ae35ada579
Sync to upstream/release/543 (#657)
- Improve ComparisonPrecedence lint suggestions for three-way comparisons (X < Y < Z)
- Improve type checking stability
- Improve location information for errors when parsing invalid type annotations
- Compiler now generates bytecode version 3 in all configurations
- Improve performance of comparisons against numeric constants on AArch64
2022-09-01 16:14:03 -07:00
Alexander McCord 42c24f98d9
July and August recap (#654)
Co-authored-by: vegorov-rbx <75688451+vegorov-rbx@users.noreply.github.com>
Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
2022-08-31 10:46:06 -07:00
JohnnyMorganz e9e2cba77a
Fix overloaded metamethod in class definitions (#653)
Fixes #652
2022-08-29 08:28:04 -07:00
Arseny Kapoulkine f2b334a4bb Merge branch 'merge' to resynchronize merge tracking history 2022-08-26 12:56:52 -07:00
Arseny Kapoulkine e84bccc5c0
RFC: Prohibit use of interpolated strings in function calls without parentheses (#648)
We've had this restriction in the original RFC, but decided to remove it afterwards. This change puts the restriction back - we need to work through some implications of future support for string-based DSLs together with interpolated strings which may or may not change the behavior here, for example to allow something like

```
local fragment = xml `
  <img src="{self.url}" />
`
```
2022-08-25 14:54:02 -07:00
Arseny Kapoulkine b2f9f53ae3
Sync to upstream/release/542 (#649)
- Fix DeprecatedGlobal warning text in cases when the global is deprecated without a suggested alternative
- Fix an off-by-one error in type error text for incorrect use of string.format
- Reduce stack consumption further during parsing, hopefully eliminating stack overflows during parsing/compilation for good
- Mark interpolated string support as experimental (requires --fflags=LuauInterpolatedStringBaseSupport to enable)
- Simplify garbage collection treatment of upvalues, reducing cache misses during sweeping stage and reducing the cost of upvalue assignment (SETUPVAL); supersedes #643
- Simplify garbage collection treatment of sleeping threads
- Simplify sweeping of alive threads, reducing cache misses during sweeping stage
- Simplify management of string buffers, removing redundant linked list operations
2022-08-25 14:53:50 -07:00
Arseny Kapoulkine 5eb4fb6089 Fix gcc warning 2022-08-25 14:10:12 -07:00
Arseny Kapoulkine 9aa4677829 Merge branch 'upstream' into merge 2022-08-25 13:57:52 -07:00
Arseny Kapoulkine c8adbf2375 Merge branch 'master' into merge 2022-08-25 13:57:43 -07:00
Arseny Kapoulkine 3008da98df Sync to upstream/release/542 2022-08-25 13:55:08 -07:00
boyned//Kampfkarren da9d8e8c60
String interpolation (#614)
Implements the string interpolation RFC (#165).

Adds the string interpolation as per the RFC.

```lua
local name = "world"
print(`Hello {name}!`) -- Hello world!
```

Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com>
Co-authored-by: Alexander McCord <11488393+alexmccord@users.noreply.github.com>
2022-08-24 12:01:00 -07:00
Alexander McCord 0ce4c45436
RFC: Explicitly support escape sequence in string interpolation literals (#642)
This was implicitly assumed to be supported, but we should really just say so explicitly. If we didn't, there'd be two ways to interpret it: string interpolations are raw strings and escape sequences don't exist for the most part (false), or string interpolations are like strings and escape sequences do exist (true).

Also talks about the ambiguity with `\u{` and that it is defined to take priority and does not terminate the interpolation chunk and starts a new expression, instead it must be a well-formed escape sequence `\u{...}`. It is very unlikely there'd be another escape sequence that also has this same ambiguity problem, so we don't need to worry about this.
2022-08-23 12:03:53 -07:00
JohnnyMorganz a95dff3223
Pass environment scope to autocomplete typechecker (#610)
Fixes a bug where the environment scope is not passed to the autocomplete typechecker, so environment-related types are not provided.

This caused an issue where `getModuleEnvironment` returns `typeChecker.globalScope` when there is no environment. We pass this through to `typeCheckerForAutocomplete.check()` then environmentscope is no longer nullopt and it will use `typeChecker.globalScope` instead of falling back to `typeCheckerForAutocomplete.globalScope`.

This is solved by passing `forAutocomplete` to `getModuleEnvironment` so it falls back to the autocomplete global scope if none found.
2022-08-23 11:53:02 -07:00
Arseny Kapoulkine be2769ad14
Sync to upstream/release/541 (#644)
- Fix autocomplete not suggesting globals defined after the cursor (fixes #622)
- Improve type checker stability
- Reduce parser C stack consumption which fixes some stack overflow crashes on deeply nested sources
- Improve performance of bit32.extract/replace when width is implied (~3% faster chess)
- Improve performance of bit32.extract when field/width are constants (~10% faster base64)
- Heap dump now annotates thread stacks with local variable/function names
2022-08-18 14:32:08 -07:00