mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
36e0e64715
* Include `windows.h` rather than `Windows.h` to make things compile on MinGW. * Custom implementation of timegm/os.time for all platforms * Disable builtin constant folding when getfenv/setfenv are used * Fixes https://github.com/Roblox/luau/issues/1042 * Fixes https://github.com/Roblox/luau/issues/1043 New Type Checker * Initial work toward type states. * Rework most overloadable operators to use type families. * Initial work toward our new nonstrict mode. Native Codegen * Fix native code generation for dead loops * Annotate top-level functions as cold * Slightly smaller/faster x64 Luau calls * emitInstCall used to not set savedpc itself, but now it does for consistency with all other implementations * Implement cmov support for X64 * Fix assertion in luau-compile when module is empty * Optimize A64 calls at some code size cost * Inline constant array index offset into the load/store instruction * Increase x64 spill slots from 5 to 13 --------- Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com> Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com>
116 lines
2.9 KiB
C++
116 lines
2.9 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Luau/NonStrictTypeChecker.h"
|
|
|
|
#include "Fixture.h"
|
|
|
|
#include "Luau/Common.h"
|
|
#include "Luau/Ast.h"
|
|
#include "Luau/ModuleResolver.h"
|
|
#include "ScopedFlags.h"
|
|
#include "doctest.h"
|
|
#include <iostream>
|
|
|
|
using namespace Luau;
|
|
|
|
struct NonStrictTypeCheckerFixture : Fixture
|
|
{
|
|
|
|
ParseResult parse(std::string source)
|
|
{
|
|
ParseOptions opts;
|
|
opts.allowDeclarationSyntax = true;
|
|
ScopedFastFlag sff{"LuauCheckedFunctionSyntax", true};
|
|
return tryParse(source, opts);
|
|
}
|
|
};
|
|
|
|
|
|
TEST_SUITE_BEGIN("NonStrictTypeCheckerTest");
|
|
|
|
TEST_CASE_FIXTURE(Fixture, "basic")
|
|
{
|
|
Luau::checkNonStrict(builtinTypes, nullptr);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "parse_top_level_checked_fn")
|
|
{
|
|
std::string src = R"BUILTIN_SRC(
|
|
declare function @checked abs(n: number): number
|
|
)BUILTIN_SRC";
|
|
|
|
ParseResult pr = parse(src);
|
|
LUAU_ASSERT(pr.errors.size() == 0);
|
|
|
|
LUAU_ASSERT(pr.root->body.size == 1);
|
|
AstStat* root = *(pr.root->body.data);
|
|
auto func = root->as<AstStatDeclareFunction>();
|
|
LUAU_ASSERT(func);
|
|
LUAU_ASSERT(func->checkedFunction);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "parse_declared_table_checked_member")
|
|
{
|
|
std::string src = R"BUILTIN_SRC(
|
|
declare math : {
|
|
abs : @checked (number) -> number
|
|
}
|
|
)BUILTIN_SRC";
|
|
|
|
ParseResult pr = parse(src);
|
|
LUAU_ASSERT(pr.errors.size() == 0);
|
|
|
|
LUAU_ASSERT(pr.root->body.size == 1);
|
|
AstStat* root = *(pr.root->body.data);
|
|
auto glob = root->as<AstStatDeclareGlobal>();
|
|
LUAU_ASSERT(glob);
|
|
auto tbl = glob->type->as<AstTypeTable>();
|
|
LUAU_ASSERT(tbl);
|
|
LUAU_ASSERT(tbl->props.size == 1);
|
|
auto prop = *tbl->props.data;
|
|
auto func = prop.type->as<AstTypeFunction>();
|
|
LUAU_ASSERT(func);
|
|
LUAU_ASSERT(func->checkedFunction);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "parse_checked_outside_decl_fails")
|
|
{
|
|
auto src = R"(
|
|
local @checked = 3
|
|
)";
|
|
|
|
ParseResult pr = parse(src);
|
|
LUAU_ASSERT(pr.errors.size() > 0);
|
|
auto ts = pr.errors[1].getMessage();
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "parse_checked_in_and_out_of_decl_fails")
|
|
{
|
|
auto src = R"(
|
|
local @checked = 3
|
|
declare function @checked abs(n: number): number
|
|
)";
|
|
auto pr = parse(src);
|
|
LUAU_ASSERT(pr.errors.size() == 2);
|
|
LUAU_ASSERT(pr.errors[0].getLocation().begin.line == 1);
|
|
LUAU_ASSERT(pr.errors[1].getLocation().begin.line == 1);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "parse_checked_as_function_name_fails")
|
|
{
|
|
auto pr = parse(R"(
|
|
function @checked(x: number) : number
|
|
end
|
|
)");
|
|
LUAU_ASSERT(pr.errors.size() > 0);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(NonStrictTypeCheckerFixture, "cannot_use_@_as_variable_name")
|
|
{
|
|
auto pr = parse(R"(
|
|
local @blah = 3
|
|
)");
|
|
|
|
LUAU_ASSERT(pr.errors.size() > 0);
|
|
}
|
|
|
|
TEST_SUITE_END();
|