mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-23 11:18:05 +00:00
7d4033071a
### What's new * A bug in exception handling in GCC(11/12/13) on MacOS prevents our test suite from running. * Parser now supports leading `|` or `&` when declaring `Union` and `Intersection` types (#1286) * We now support parsing of attributes on functions as described in the [rfc](https://github.com/luau-lang/rfcs/pull/30) * With this change, expressions such as `local x = @native function(x) return x+1 end` and `f(@native function(x) return x+1 end)` are now valid. * Added support for `@native` attribute - we can now force native compilation of individual functions if the `@native` attribute is specified before the `function` keyword (works for lambdas too). ### New Solver * Many fixes in the new solver for crashes and instability * Refinements now use simplification and not normalization in a specific case of two tables * Assume that compound assignments do not change the type of the left-side operand * Fix error that prevented Class Methods from being overloaded ### VM * Updated description of Garbage Collector invariant --- ### Internal Contributors Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: David Cope <dcope@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
79 lines
2.2 KiB
C++
79 lines
2.2 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Luau/BytecodeSummary.h"
|
|
#include "Luau/BytecodeUtils.h"
|
|
#include "CodeGenLower.h"
|
|
|
|
#include "lua.h"
|
|
#include "lapi.h"
|
|
#include "lobject.h"
|
|
#include "lstate.h"
|
|
|
|
LUAU_FASTFLAG(LuauNativeAttribute)
|
|
|
|
namespace Luau
|
|
{
|
|
namespace CodeGen
|
|
{
|
|
|
|
FunctionBytecodeSummary::FunctionBytecodeSummary(std::string source, std::string name, const int line, unsigned nestingLimit)
|
|
: source(std::move(source))
|
|
, name(std::move(name))
|
|
, line(line)
|
|
, nestingLimit(nestingLimit)
|
|
{
|
|
counts.reserve(nestingLimit);
|
|
for (unsigned i = 0; i < 1 + nestingLimit; ++i)
|
|
{
|
|
counts.push_back(std::vector<unsigned>(getOpLimit(), 0));
|
|
}
|
|
}
|
|
|
|
FunctionBytecodeSummary FunctionBytecodeSummary::fromProto(Proto* proto, unsigned nestingLimit)
|
|
{
|
|
const char* source = getstr(proto->source);
|
|
source = (source[0] == '=' || source[0] == '@') ? source + 1 : "[string]";
|
|
|
|
const char* name = proto->debugname ? getstr(proto->debugname) : "";
|
|
|
|
int line = proto->linedefined;
|
|
|
|
FunctionBytecodeSummary summary(source, name, line, nestingLimit);
|
|
|
|
for (int i = 0; i < proto->sizecode;)
|
|
{
|
|
Instruction insn = proto->code[i];
|
|
uint8_t op = LUAU_INSN_OP(insn);
|
|
summary.incCount(0, op);
|
|
i += Luau::getOpLength(LuauOpcode(op));
|
|
}
|
|
|
|
return summary;
|
|
}
|
|
|
|
std::vector<FunctionBytecodeSummary> summarizeBytecode(lua_State* L, int idx, unsigned nestingLimit)
|
|
{
|
|
CODEGEN_ASSERT(lua_isLfunction(L, idx));
|
|
const TValue* func = luaA_toobject(L, idx);
|
|
|
|
Proto* root = clvalue(func)->l.p;
|
|
|
|
std::vector<Proto*> protos;
|
|
if (FFlag::LuauNativeAttribute)
|
|
gatherFunctions(protos, root, CodeGen_ColdFunctions, root->flags & LPF_NATIVE_FUNCTION);
|
|
else
|
|
gatherFunctions_DEPRECATED(protos, root, CodeGen_ColdFunctions);
|
|
|
|
std::vector<FunctionBytecodeSummary> summaries;
|
|
summaries.reserve(protos.size());
|
|
|
|
for (Proto* proto : protos)
|
|
{
|
|
if (proto)
|
|
summaries.push_back(FunctionBytecodeSummary::fromProto(proto, nestingLimit));
|
|
}
|
|
|
|
return summaries;
|
|
}
|
|
|
|
} // namespace CodeGen
|
|
} // namespace Luau
|