2022-05-05 17:03:43 -07:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
|
|
|
|
|
|
|
#include "Luau/RecursionCounter.h"
|
|
|
|
|
Sync to upstream/release/660 (#1643)
# General
This release introduces initial work on a Roundtrippable AST for Luau,
and numerous fixes to the new type solver, runtime, and fragment
autocomplete.
## Roundtrippable AST
To support tooling around source code transformations, we are extending
the parser to retain source information so that we can re-emit the
initial source code exactly as the author wrote it. We have made
numerous changes to the Transpiler, added new AST types such as
`AstTypeGroup`, and added source information to AST nodes such as
`AstExprInterpString`, `AstExprIfElse`, `AstTypeTable`,
`AstTypeReference`, `AstTypeSingletonString`, and `AstTypeTypeof`.
## New Type Solver
* Implement `setmetatable` and `getmetatable` type functions.
* Fix handling of nested and recursive union type functions to prevent
the solver from getting stuck.
* Free types in both old and new solver now have an upper and lower
bound to resolve mixed mode usage of the solvers in fragment
autocomplete.
* Fix infinite recursion during normalization of cyclic tables.
* Add normalization support for intersections of subclasses with negated
superclasses.
## Runtime
* Fix compilation error in Luau buffer bit operations for big-endian
machines.
## Miscellaneous
* Add test and bugfixes to fragment autocomplete.
* Fixed `clang-tidy` warnings in `Simplify.cpp`.
**Full Changelog**:
https://github.com/luau-lang/luau/compare/0.659...0.660
---
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
---------
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com>
Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com>
Co-authored-by: Menarul Alam <malam@roblox.com>
2025-02-07 16:17:11 -08:00
|
|
|
#include "Luau/Type.h"
|
2022-05-05 17:03:43 -07:00
|
|
|
#include "doctest.h"
|
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
2023-09-22 15:12:15 -04:00
|
|
|
LUAU_FASTINT(LuauVisitRecursionLimit);
|
2024-08-30 16:16:51 -04:00
|
|
|
LUAU_FASTFLAG(LuauSolverV2)
|
2022-05-05 17:03:43 -07:00
|
|
|
|
2023-09-22 15:12:15 -04:00
|
|
|
TEST_SUITE_BEGIN("VisitType");
|
2022-05-05 17:03:43 -07:00
|
|
|
|
2022-06-23 18:56:00 -07:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "throw_when_limit_is_exceeded")
|
2022-05-05 17:03:43 -07:00
|
|
|
{
|
2024-08-30 16:16:51 -04:00
|
|
|
if (FFlag::LuauSolverV2)
|
2024-08-23 09:35:30 -07:00
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 3};
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
CHECK_THROWS_AS(toString(tType), RecursionLimitException);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 3};
|
|
|
|
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
CHECK_THROWS_AS(toString(tType), RecursionLimitException);
|
|
|
|
}
|
2022-05-05 17:03:43 -07:00
|
|
|
}
|
|
|
|
|
2022-06-23 18:56:00 -07:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "dont_throw_when_limit_is_high_enough")
|
2022-05-05 17:03:43 -07:00
|
|
|
{
|
2023-12-01 23:46:57 -08:00
|
|
|
ScopedFastInt sfi{FInt::LuauVisitRecursionLimit, 8};
|
2022-05-05 17:03:43 -07:00
|
|
|
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local t : {a: {b: {c: {d: {e: boolean}}}}}
|
|
|
|
)");
|
|
|
|
|
|
|
|
TypeId tType = requireType("t");
|
|
|
|
|
|
|
|
(void)toString(tType);
|
|
|
|
}
|
|
|
|
|
2023-09-22 15:12:15 -04:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "some_free_types_do_not_have_bounds")
|
|
|
|
{
|
Sync to upstream/release/660 (#1643)
# General
This release introduces initial work on a Roundtrippable AST for Luau,
and numerous fixes to the new type solver, runtime, and fragment
autocomplete.
## Roundtrippable AST
To support tooling around source code transformations, we are extending
the parser to retain source information so that we can re-emit the
initial source code exactly as the author wrote it. We have made
numerous changes to the Transpiler, added new AST types such as
`AstTypeGroup`, and added source information to AST nodes such as
`AstExprInterpString`, `AstExprIfElse`, `AstTypeTable`,
`AstTypeReference`, `AstTypeSingletonString`, and `AstTypeTypeof`.
## New Type Solver
* Implement `setmetatable` and `getmetatable` type functions.
* Fix handling of nested and recursive union type functions to prevent
the solver from getting stuck.
* Free types in both old and new solver now have an upper and lower
bound to resolve mixed mode usage of the solvers in fragment
autocomplete.
* Fix infinite recursion during normalization of cyclic tables.
* Add normalization support for intersections of subclasses with negated
superclasses.
## Runtime
* Fix compilation error in Luau buffer bit operations for big-endian
machines.
## Miscellaneous
* Add test and bugfixes to fragment autocomplete.
* Fixed `clang-tidy` warnings in `Simplify.cpp`.
**Full Changelog**:
https://github.com/luau-lang/luau/compare/0.659...0.660
---
Co-authored-by: Ariel Weiss <aaronweiss@roblox.com>
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
---------
Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com>
Co-authored-by: Alexander Youngblood <ayoungblood@roblox.com>
Co-authored-by: Menarul Alam <malam@roblox.com>
2025-02-07 16:17:11 -08:00
|
|
|
Type t{FreeType{TypeLevel{}, builtinTypes->neverType, builtinTypes->unknownType}};
|
2023-09-22 15:12:15 -04:00
|
|
|
|
|
|
|
(void)toString(&t);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "some_free_types_have_bounds")
|
|
|
|
{
|
2024-08-30 16:16:51 -04:00
|
|
|
ScopedFastFlag sff{FFlag::LuauSolverV2, true};
|
2023-09-22 15:12:15 -04:00
|
|
|
|
|
|
|
Scope scope{builtinTypes->anyTypePack};
|
|
|
|
Type t{FreeType{&scope, builtinTypes->neverType, builtinTypes->numberType}};
|
|
|
|
|
|
|
|
CHECK("('a <: number)" == toString(&t));
|
|
|
|
}
|
|
|
|
|
2022-05-05 17:03:43 -07:00
|
|
|
TEST_SUITE_END();
|