mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
140e5a1495
* 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
104 lines
2.4 KiB
C++
104 lines
2.4 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Luau/DataFlowGraph.h"
|
|
#include "Luau/Error.h"
|
|
#include "Luau/Parser.h"
|
|
|
|
#include "AstQueryDsl.h"
|
|
#include "ScopedFlags.h"
|
|
|
|
#include "doctest.h"
|
|
|
|
using namespace Luau;
|
|
|
|
struct DataFlowGraphFixture
|
|
{
|
|
// Only needed to fix the operator== reflexivity of an empty Symbol.
|
|
ScopedFastFlag dcr{"DebugLuauDeferredConstraintResolution", true};
|
|
|
|
InternalErrorReporter handle;
|
|
|
|
Allocator allocator;
|
|
AstNameTable names{allocator};
|
|
AstStatBlock* module;
|
|
|
|
std::optional<DataFlowGraph> graph;
|
|
|
|
void dfg(const std::string& code)
|
|
{
|
|
ParseResult parseResult = Parser::parse(code.c_str(), code.size(), names, allocator);
|
|
if (!parseResult.errors.empty())
|
|
throw ParseErrors(std::move(parseResult.errors));
|
|
module = parseResult.root;
|
|
graph = DataFlowGraphBuilder::build(module, NotNull{&handle});
|
|
}
|
|
|
|
template<typename T, int N>
|
|
NullableBreadcrumbId getBreadcrumb(const std::vector<Nth>& nths = {nth<T>(N)})
|
|
{
|
|
T* node = query<T, N>(module, nths);
|
|
REQUIRE(node);
|
|
return graph->getBreadcrumb(node);
|
|
}
|
|
|
|
template<typename T, int N>
|
|
BreadcrumbId requireBreadcrumb(const std::vector<Nth>& nths = {nth<T>(N)})
|
|
{
|
|
auto bc = getBreadcrumb<T, N>(nths);
|
|
REQUIRE(bc);
|
|
return NotNull{bc};
|
|
}
|
|
};
|
|
|
|
TEST_SUITE_BEGIN("DataFlowGraphBuilder");
|
|
|
|
TEST_CASE_FIXTURE(DataFlowGraphFixture, "define_locals_in_local_stat")
|
|
{
|
|
dfg(R"(
|
|
local x = 5
|
|
local y = x
|
|
)");
|
|
|
|
REQUIRE(getBreadcrumb<AstExprLocal, 1>());
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DataFlowGraphFixture, "define_parameters_in_functions")
|
|
{
|
|
dfg(R"(
|
|
local function f(x)
|
|
local y = x
|
|
end
|
|
)");
|
|
|
|
REQUIRE(getBreadcrumb<AstExprLocal, 1>());
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DataFlowGraphFixture, "find_aliases")
|
|
{
|
|
dfg(R"(
|
|
local x = 5
|
|
local y = x
|
|
local z = y
|
|
)");
|
|
|
|
BreadcrumbId x = requireBreadcrumb<AstExprLocal, 1>();
|
|
BreadcrumbId y = requireBreadcrumb<AstExprLocal, 2>();
|
|
REQUIRE(x != y);
|
|
}
|
|
|
|
TEST_CASE_FIXTURE(DataFlowGraphFixture, "independent_locals")
|
|
{
|
|
dfg(R"(
|
|
local x = 5
|
|
local y = 5
|
|
|
|
local a = x
|
|
local b = y
|
|
)");
|
|
|
|
BreadcrumbId x = requireBreadcrumb<AstExprLocal, 1>();
|
|
BreadcrumbId y = requireBreadcrumb<AstExprLocal, 2>();
|
|
REQUIRE(x != y);
|
|
}
|
|
|
|
TEST_SUITE_END();
|