Back to Luau

Recap: February 2022

news-2022-02-28-luau-recap-february-2022.md

latest6.6 KB
Original Source

Recap: February 2022

February 28, 2022

Default type alias type parameters

We have introduced a syntax to provide default type arguments inside the type alias type parameter list.

It is now possible to have type functions where the instantiation can omit some type arguments.

You can provide concrete types:

Embedded content

Or reference parameters defined earlier in the list:

Embedded content

Type pack parameters can also have a default type pack:

Embedded content

If all type parameters have a default type, it is now possible to reference that without providing any type arguments:

Embedded content

For more details, you can read the original RFC proposal.

Typechecking improvements

This month we had many fixes to improve our type inference and reduce false positive errors.

if-then-else expression can now have different types in each branch:

Embedded content

And if the expected result type is known, you will not get an error in cases like these:

Embedded content


assert result is now known to not be ‘falsy’ (false or nil):

Embedded content


We fixed cases where length operator # reported an error when used on a compatible type:

Embedded content


Functions with different variadic argument/return types are no longer compatible:

Embedded content


We have also fixed:

  • false positive errors caused by incorrect reuse of generic types across different function declarations
  • issues with forward-declared intersection types
  • wrong return type annotation for table.move
  • various crashes reported by developers

Linter improvements

A new static analysis warning was introduced to mark incorrect use of a ‘a and b or c’ pattern. When ‘b’ is ‘falsy’ (false or nil), result will always be ‘c’, even if the expression ‘a’ was true:

Embedded content

Like we say in the warning, new if-then-else expression doesn’t have this pitfall:

Embedded content


We have also introduced a check for misspelled comment directives:

Embedded content

Performance improvements

For performance, we have changed how our Garbage Collector collects unreachable memory.
This rework makes it possible to free memory 2.5x faster and also comes with a small change to how we store Luau objects in memory. For example, each table now uses 16 fewer bytes on 64-bit platforms.

Another optimization was made for select(_, ...) call.
It is now using a special fast path that has constant-time complexity in number of arguments (~3x faster with 10 arguments).

Thanks

A special thanks to all the fine folks who contributed PRs this month!