2021-12-03 14:41:04 +08:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Luau/Scope.h"
|
|
|
|
#include "Luau/ToDot.h"
|
|
|
|
|
|
|
|
#include "Fixture.h"
|
|
|
|
|
|
|
|
#include "doctest.h"
|
|
|
|
|
|
|
|
using namespace Luau;
|
|
|
|
|
2023-01-21 04:27:03 +08:00
|
|
|
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution);
|
|
|
|
|
2021-12-03 14:41:04 +08:00
|
|
|
struct ToDotClassFixture : Fixture
|
|
|
|
{
|
|
|
|
ToDotClassFixture()
|
|
|
|
{
|
2023-03-11 04:21:07 +08:00
|
|
|
TypeArena& arena = frontend.globals.globalTypes;
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
unfreeze(arena);
|
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
TypeId baseClassMetaType = arena.addType(TableType{});
|
2021-12-03 14:41:04 +08:00
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
TypeId baseClassInstanceType = arena.addType(ClassType{"BaseClass", {}, std::nullopt, baseClassMetaType, {}, {}, "Test"});
|
|
|
|
getMutable<ClassType>(baseClassInstanceType)->props = {
|
2023-03-11 04:21:07 +08:00
|
|
|
{"BaseField", {builtinTypes->numberType}},
|
2021-12-03 14:41:04 +08:00
|
|
|
};
|
2023-03-11 04:21:07 +08:00
|
|
|
frontend.globals.globalScope->exportedTypeBindings["BaseClass"] = TypeFun{{}, baseClassInstanceType};
|
2021-12-03 14:41:04 +08:00
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
TypeId childClassInstanceType = arena.addType(ClassType{"ChildClass", {}, baseClassInstanceType, std::nullopt, {}, {}, "Test"});
|
|
|
|
getMutable<ClassType>(childClassInstanceType)->props = {
|
2023-03-11 04:21:07 +08:00
|
|
|
{"ChildField", {builtinTypes->stringType}},
|
2021-12-03 14:41:04 +08:00
|
|
|
};
|
2023-03-11 04:21:07 +08:00
|
|
|
frontend.globals.globalScope->exportedTypeBindings["ChildClass"] = TypeFun{{}, childClassInstanceType};
|
2021-12-03 14:41:04 +08:00
|
|
|
|
2023-03-11 04:21:07 +08:00
|
|
|
for (const auto& [name, ty] : frontend.globals.globalScope->exportedTypeBindings)
|
2022-05-27 06:08:16 +08:00
|
|
|
persist(ty.type);
|
|
|
|
|
2021-12-03 14:41:04 +08:00
|
|
|
freeze(arena);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST_SUITE_BEGIN("ToDot");
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "primitive")
|
|
|
|
{
|
2023-09-08 08:13:49 +08:00
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="nil"];
|
|
|
|
})",
|
|
|
|
toDot(builtinTypes->nilType));
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="number"];
|
|
|
|
})",
|
2023-09-08 08:13:49 +08:00
|
|
|
toDot(builtinTypes->numberType));
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="any"];
|
|
|
|
})",
|
2023-09-08 08:13:49 +08:00
|
|
|
toDot(builtinTypes->anyType));
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="unknown"];
|
|
|
|
})",
|
|
|
|
toDot(builtinTypes->unknownType));
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="never"];
|
|
|
|
})",
|
|
|
|
toDot(builtinTypes->neverType));
|
|
|
|
}
|
2021-12-03 14:41:04 +08:00
|
|
|
|
2023-09-08 08:13:49 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "no_duplicatePrimitives")
|
|
|
|
{
|
2021-12-03 14:41:04 +08:00
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
opts.duplicatePrimitives = false;
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="PrimitiveType number"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
2023-09-08 08:13:49 +08:00
|
|
|
toDot(builtinTypes->numberType, opts));
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="AnyType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
2023-09-08 08:13:49 +08:00
|
|
|
toDot(builtinTypes->anyType, opts));
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="UnknownType 1"];
|
|
|
|
})",
|
|
|
|
toDot(builtinTypes->unknownType, opts));
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="NeverType 1"];
|
|
|
|
})",
|
|
|
|
toDot(builtinTypes->neverType, opts));
|
2021-12-03 14:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "bound")
|
|
|
|
{
|
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-04 03:26:13 +08:00
|
|
|
TypeArena arena;
|
2021-12-03 14:41:04 +08:00
|
|
|
|
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-04 03:26:13 +08:00
|
|
|
TypeId ty = arena.addType(BoundType{builtinTypes->numberType});
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="BoundType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2;
|
|
|
|
n2 [label="number"];
|
|
|
|
})",
|
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-04 03:26:13 +08:00
|
|
|
toDot(ty, opts));
|
2021-12-03 14:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "function")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local function f(a, ...: string) return a end
|
|
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
|
2022-04-15 07:57:43 +08:00
|
|
|
CHECK_EQ("<a>(a, ...string) -> a", toString(requireType("f")));
|
|
|
|
|
2021-12-03 14:41:04 +08:00
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
2022-04-15 07:57:43 +08:00
|
|
|
|
2023-01-21 04:27:03 +08:00
|
|
|
if (FFlag::DebugLuauDeferredConstraintResolution)
|
|
|
|
{
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="FunctionType 1"];
|
|
|
|
n1 -> n2 [label="arg"];
|
|
|
|
n2 [label="TypePack 2"];
|
|
|
|
n2 -> n3;
|
|
|
|
n3 [label="GenericType 3"];
|
|
|
|
n2 -> n4 [label="tail"];
|
|
|
|
n4 [label="VariadicTypePack 4"];
|
|
|
|
n4 -> n5;
|
|
|
|
n5 [label="string"];
|
|
|
|
n1 -> n6 [label="ret"];
|
|
|
|
n6 [label="TypePack 6"];
|
|
|
|
n6 -> n3;
|
|
|
|
})",
|
|
|
|
toDot(requireType("f"), opts));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="FunctionType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2 [label="arg"];
|
|
|
|
n2 [label="TypePack 2"];
|
|
|
|
n2 -> n3;
|
2023-01-05 04:53:17 +08:00
|
|
|
n3 [label="GenericType 3"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n2 -> n4 [label="tail"];
|
|
|
|
n4 [label="VariadicTypePack 4"];
|
|
|
|
n4 -> n5;
|
|
|
|
n5 [label="string"];
|
|
|
|
n1 -> n6 [label="ret"];
|
|
|
|
n6 [label="BoundTypePack 6"];
|
|
|
|
n6 -> n7;
|
|
|
|
n7 [label="TypePack 7"];
|
|
|
|
n7 -> n3;
|
|
|
|
})",
|
2023-01-21 04:27:03 +08:00
|
|
|
toDot(requireType("f"), opts));
|
|
|
|
}
|
2021-12-03 14:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "union")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local a: string | number
|
|
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="UnionType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2;
|
|
|
|
n2 [label="string"];
|
|
|
|
n1 -> n3;
|
|
|
|
n3 [label="number"];
|
|
|
|
})",
|
|
|
|
toDot(requireType("a"), opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "intersection")
|
|
|
|
{
|
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-04 03:26:13 +08:00
|
|
|
TypeArena arena;
|
|
|
|
|
|
|
|
TypeId ty = arena.addType(IntersectionType{{builtinTypes->stringType, builtinTypes->numberType}});
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="IntersectionType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2;
|
|
|
|
n2 [label="string"];
|
|
|
|
n1 -> n3;
|
|
|
|
n3 [label="number"];
|
|
|
|
})",
|
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-04 03:26:13 +08:00
|
|
|
toDot(ty, opts));
|
2021-12-03 14:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "table")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
type A<T, U...> = { x: T, y: (U...) -> (), [string]: any }
|
|
|
|
local a: A<number, ...string>
|
|
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
2023-01-21 04:27:03 +08:00
|
|
|
if (FFlag::DebugLuauDeferredConstraintResolution)
|
|
|
|
{
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="TableType A"];
|
|
|
|
n1 -> n2 [label="x"];
|
|
|
|
n2 [label="number"];
|
|
|
|
n1 -> n3 [label="y"];
|
|
|
|
n3 [label="FunctionType 3"];
|
|
|
|
n3 -> n4 [label="arg"];
|
|
|
|
n4 [label="TypePack 4"];
|
|
|
|
n4 -> n5 [label="tail"];
|
|
|
|
n5 [label="VariadicTypePack 5"];
|
|
|
|
n5 -> n6;
|
|
|
|
n6 [label="string"];
|
|
|
|
n3 -> n7 [label="ret"];
|
|
|
|
n7 [label="TypePack 7"];
|
|
|
|
n1 -> n8 [label="[index]"];
|
|
|
|
n8 [label="string"];
|
|
|
|
n1 -> n9 [label="[value]"];
|
|
|
|
n9 [label="any"];
|
|
|
|
n1 -> n10 [label="typeParam"];
|
|
|
|
n10 [label="number"];
|
|
|
|
n1 -> n5 [label="typePackParam"];
|
|
|
|
})",
|
|
|
|
toDot(requireType("a"), opts));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="TableType A"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2 [label="x"];
|
|
|
|
n2 [label="number"];
|
|
|
|
n1 -> n3 [label="y"];
|
2023-01-05 04:53:17 +08:00
|
|
|
n3 [label="FunctionType 3"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n3 -> n4 [label="arg"];
|
|
|
|
n4 [label="VariadicTypePack 4"];
|
|
|
|
n4 -> n5;
|
|
|
|
n5 [label="string"];
|
|
|
|
n3 -> n6 [label="ret"];
|
|
|
|
n6 [label="TypePack 6"];
|
|
|
|
n1 -> n7 [label="[index]"];
|
|
|
|
n7 [label="string"];
|
|
|
|
n1 -> n8 [label="[value]"];
|
|
|
|
n8 [label="any"];
|
|
|
|
n1 -> n9 [label="typeParam"];
|
|
|
|
n9 [label="number"];
|
|
|
|
n1 -> n4 [label="typePackParam"];
|
|
|
|
})",
|
2023-01-21 04:27:03 +08:00
|
|
|
toDot(requireType("a"), opts));
|
|
|
|
}
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
// Extra coverage with pointers (unstable values)
|
|
|
|
(void)toDot(requireType("a"));
|
|
|
|
}
|
|
|
|
|
2022-05-14 03:36:37 +08:00
|
|
|
TEST_CASE_FIXTURE(BuiltinsFixture, "metatable")
|
2021-12-03 14:41:04 +08:00
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local a: typeof(setmetatable({}, {}))
|
|
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="MetatableType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2 [label="table"];
|
2023-01-05 04:53:17 +08:00
|
|
|
n2 [label="TableType 2"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n3 [label="metatable"];
|
2023-01-05 04:53:17 +08:00
|
|
|
n3 [label="TableType 3"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
|
|
|
toDot(requireType("a"), opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "free")
|
|
|
|
{
|
2023-08-05 03:18:54 +08:00
|
|
|
ScopedFastFlag sff[] = {
|
2023-12-02 15:46:57 +08:00
|
|
|
{FFlag::DebugLuauDeferredConstraintResolution, false},
|
2023-08-05 03:18:54 +08:00
|
|
|
};
|
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
Type type{TypeVariant{FreeType{TypeLevel{0, 0}}}};
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="FreeType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
|
|
|
toDot(&type, opts));
|
|
|
|
}
|
|
|
|
|
2023-09-08 08:13:49 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "free_with_constraints")
|
|
|
|
{
|
|
|
|
ScopedFastFlag sff[] = {
|
2023-12-02 15:46:57 +08:00
|
|
|
{FFlag::DebugLuauDeferredConstraintResolution, true},
|
2023-09-08 08:13:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Type type{TypeVariant{FreeType{nullptr, builtinTypes->numberType, builtinTypes->optionalNumberType}}};
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="FreeType 1"];
|
|
|
|
n1 -> n2 [label="[lowerBound]"];
|
|
|
|
n2 [label="number"];
|
|
|
|
n1 -> n3 [label="[upperBound]"];
|
|
|
|
n3 [label="UnionType 3"];
|
|
|
|
n3 -> n4;
|
|
|
|
n4 [label="number"];
|
|
|
|
n3 -> n5;
|
|
|
|
n5 [label="nil"];
|
|
|
|
})",
|
|
|
|
toDot(&type, opts));
|
|
|
|
}
|
|
|
|
|
2021-12-03 14:41:04 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "error")
|
|
|
|
{
|
2023-01-05 04:53:17 +08:00
|
|
|
Type type{TypeVariant{ErrorType{}}};
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="ErrorType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
|
|
|
toDot(&type, opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "generic")
|
|
|
|
{
|
2023-01-05 04:53:17 +08:00
|
|
|
Type type{TypeVariant{GenericType{"T"}}};
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="GenericType T"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
|
|
|
toDot(&type, opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(ToDotClassFixture, "class")
|
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local a: ChildClass
|
|
|
|
)");
|
|
|
|
LUAU_REQUIRE_NO_ERRORS(result);
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="ClassType ChildClass"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2 [label="ChildField"];
|
|
|
|
n2 [label="string"];
|
|
|
|
n1 -> n3 [label="[parent]"];
|
2023-01-05 04:53:17 +08:00
|
|
|
n3 [label="ClassType BaseClass"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n3 -> n4 [label="BaseField"];
|
|
|
|
n4 [label="number"];
|
|
|
|
n3 -> n5 [label="[metatable]"];
|
2023-01-05 04:53:17 +08:00
|
|
|
n5 [label="TableType 5"];
|
2021-12-03 14:41:04 +08:00
|
|
|
})",
|
|
|
|
toDot(requireType("a"), opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "free_pack")
|
|
|
|
{
|
|
|
|
TypePackVar pack{TypePackVariant{FreeTypePack{TypeLevel{0, 0}}}};
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="FreeTypePack 1"];
|
|
|
|
})",
|
|
|
|
toDot(&pack, opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "error_pack")
|
|
|
|
{
|
|
|
|
TypePackVar pack{TypePackVariant{Unifiable::Error{}}};
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="ErrorTypePack 1"];
|
|
|
|
})",
|
|
|
|
toDot(&pack, opts));
|
|
|
|
|
|
|
|
// Extra coverage with pointers (unstable values)
|
|
|
|
(void)toDot(&pack);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "generic_pack")
|
|
|
|
{
|
|
|
|
TypePackVar pack1{TypePackVariant{GenericTypePack{}}};
|
|
|
|
TypePackVar pack2{TypePackVariant{GenericTypePack{"T"}}};
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="GenericTypePack 1"];
|
|
|
|
})",
|
|
|
|
toDot(&pack1, opts));
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="GenericTypePack T"];
|
|
|
|
})",
|
|
|
|
toDot(&pack2, opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "bound_pack")
|
|
|
|
{
|
2023-03-11 04:21:07 +08:00
|
|
|
TypePackVar pack{TypePackVariant{TypePack{{builtinTypes->numberType}, {}}}};
|
2021-12-03 14:41:04 +08:00
|
|
|
TypePackVar bound{TypePackVariant{BoundTypePack{&pack}}};
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
|
|
|
n1 [label="BoundTypePack 1"];
|
|
|
|
n1 -> n2;
|
|
|
|
n2 [label="TypePack 2"];
|
|
|
|
n2 -> n3;
|
|
|
|
n3 [label="number"];
|
|
|
|
})",
|
|
|
|
toDot(&bound, opts));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "bound_table")
|
|
|
|
{
|
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-04 03:26:13 +08:00
|
|
|
TypeArena arena;
|
2021-12-03 14:41:04 +08:00
|
|
|
|
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-04 03:26:13 +08:00
|
|
|
TypeId ty = arena.addType(TableType{});
|
|
|
|
getMutable<TableType>(ty)->props["x"] = {builtinTypes->numberType};
|
|
|
|
|
|
|
|
TypeId boundTy = arena.addType(TableType{});
|
|
|
|
getMutable<TableType>(boundTy)->boundTo = ty;
|
2021-12-03 14:41:04 +08:00
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
2023-01-21 04:27:03 +08:00
|
|
|
|
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-04 03:26:13 +08:00
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="TableType 1"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n1 -> n2 [label="boundTo"];
|
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-04 03:26:13 +08:00
|
|
|
n2 [label="TableType 2"];
|
2021-12-03 14:41:04 +08:00
|
|
|
n2 -> n3 [label="x"];
|
|
|
|
n3 [label="number"];
|
|
|
|
})",
|
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-04 03:26:13 +08:00
|
|
|
toDot(boundTy, opts));
|
2021-12-03 14:41:04 +08:00
|
|
|
}
|
|
|
|
|
2023-01-05 04:53:17 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "builtintypes")
|
2022-04-15 07:57:43 +08:00
|
|
|
{
|
|
|
|
CheckResult result = check(R"(
|
|
|
|
local x: "hi" | "\"hello\"" | true | false
|
|
|
|
)");
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
|
|
|
|
CHECK_EQ(R"(digraph graphname {
|
2023-01-05 04:53:17 +08:00
|
|
|
n1 [label="UnionType 1"];
|
2022-04-15 07:57:43 +08:00
|
|
|
n1 -> n2;
|
2023-01-05 04:53:17 +08:00
|
|
|
n2 [label="SingletonType string: hi"];
|
2022-04-15 07:57:43 +08:00
|
|
|
n1 -> n3;
|
|
|
|
)"
|
2023-01-05 04:53:17 +08:00
|
|
|
"n3 [label=\"SingletonType string: \\\"hello\\\"\"];"
|
2022-05-27 06:08:16 +08:00
|
|
|
R"(
|
2022-04-15 07:57:43 +08:00
|
|
|
n1 -> n4;
|
2023-01-05 04:53:17 +08:00
|
|
|
n4 [label="SingletonType boolean: true"];
|
2022-04-15 07:57:43 +08:00
|
|
|
n1 -> n5;
|
2023-01-05 04:53:17 +08:00
|
|
|
n5 [label="SingletonType boolean: false"];
|
2022-05-27 06:08:16 +08:00
|
|
|
})",
|
|
|
|
toDot(requireType("x"), opts));
|
2022-04-15 07:57:43 +08:00
|
|
|
}
|
|
|
|
|
2023-09-08 08:13:49 +08:00
|
|
|
TEST_CASE_FIXTURE(Fixture, "negation")
|
|
|
|
{
|
|
|
|
TypeArena arena;
|
|
|
|
TypeId t = arena.addType(NegationType{builtinTypes->stringType});
|
|
|
|
|
|
|
|
ToDotOptions opts;
|
|
|
|
opts.showPointers = false;
|
|
|
|
|
|
|
|
CHECK(R"(digraph graphname {
|
|
|
|
n1 [label="NegationType 1"];
|
|
|
|
n1 -> n2 [label="[negated]"];
|
|
|
|
n2 [label="string"];
|
|
|
|
})" == toDot(t, opts));
|
|
|
|
}
|
|
|
|
|
2021-12-03 14:41:04 +08:00
|
|
|
TEST_SUITE_END();
|