mirror of
https://github.com/luau-lang/luau.git
synced 2025-08-26 11:27:08 +01:00
## General - Introduce `Frontend::parseModules` for parsing a group of modules at once. - Support chained function types in the CST. ## New Type Solver - Enable write-only table properties (described in [this RFC](https://rfcs.luau.org/property-writeonly.html)). - Disable singleton inference for large tables to improve performance. - Fix a bug that occurs when we try to expand a type alias to itself. - Catch cancelation during the type-checking phase in addition to during constraint solving. - Fix stringification of the empty type pack: `()`. - Improve errors for calls being rejected on the primitive `function` type. - Rework generalization: We now generalize types as soon as the last constraint relating to them is finished. We think this will reduce the number of cases where type inference fails to complete and reduce the number of instances where `*blocked*` types appear in the inference result. ## VM/Runtime - Dynamically disable native execution for functions that incur a slowdown (relative to bytecode execution). - Improve names for `thread`/`closure`/`proto` in the Luau heap dump. --- Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Aviral Goel <agoel@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: Alexander Youngblood <ayoungblood@roblox.com> Co-authored-by: Menarul Alam <malam@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <aaronweiss@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com>
149 lines
5.5 KiB
C++
149 lines
5.5 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include "Luau/CodeGenCommon.h"
|
|
#include "Luau/CodeGenOptions.h"
|
|
#include "Luau/LoweringStats.h"
|
|
|
|
#include <array>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
struct lua_State;
|
|
|
|
namespace Luau
|
|
{
|
|
namespace CodeGen
|
|
{
|
|
|
|
// These enum values can be reported through telemetry.
|
|
// To ensure consistency, changes should be additive.
|
|
enum class CodeGenCompilationResult
|
|
{
|
|
Success = 0, // Successfully generated code for at least one function
|
|
NothingToCompile = 1, // There were no new functions to compile
|
|
NotNativeModule = 2, // Module does not have `--!native` comment
|
|
|
|
CodeGenNotInitialized = 3, // Native codegen system is not initialized
|
|
CodeGenOverflowInstructionLimit = 4, // Instruction limit overflow
|
|
CodeGenOverflowBlockLimit = 5, // Block limit overflow
|
|
CodeGenOverflowBlockInstructionLimit = 6, // Block instruction limit overflow
|
|
CodeGenAssemblerFinalizationFailure = 7, // Failure during assembler finalization
|
|
CodeGenLoweringFailure = 8, // Lowering failed
|
|
AllocationFailed = 9, // Native codegen failed due to an allocation error
|
|
|
|
Count = 10,
|
|
};
|
|
|
|
std::string toString(const CodeGenCompilationResult& result);
|
|
|
|
struct ProtoCompilationFailure
|
|
{
|
|
CodeGenCompilationResult result = CodeGenCompilationResult::Success;
|
|
|
|
std::string debugname;
|
|
int line = -1;
|
|
};
|
|
|
|
struct CompilationResult
|
|
{
|
|
CodeGenCompilationResult result = CodeGenCompilationResult::Success;
|
|
|
|
std::vector<ProtoCompilationFailure> protoFailures;
|
|
|
|
[[nodiscard]] bool hasErrors() const
|
|
{
|
|
return result != CodeGenCompilationResult::Success || !protoFailures.empty();
|
|
}
|
|
};
|
|
|
|
struct CompilationStats
|
|
{
|
|
size_t bytecodeSizeBytes = 0;
|
|
size_t nativeCodeSizeBytes = 0;
|
|
size_t nativeDataSizeBytes = 0;
|
|
size_t nativeMetadataSizeBytes = 0;
|
|
|
|
uint32_t functionsTotal = 0;
|
|
uint32_t functionsCompiled = 0;
|
|
uint32_t functionsBound = 0;
|
|
};
|
|
|
|
bool isSupported();
|
|
|
|
class SharedCodeGenContext;
|
|
|
|
struct SharedCodeGenContextDeleter
|
|
{
|
|
void operator()(const SharedCodeGenContext* context) const noexcept;
|
|
};
|
|
|
|
using UniqueSharedCodeGenContext = std::unique_ptr<SharedCodeGenContext, SharedCodeGenContextDeleter>;
|
|
|
|
// Creates a new SharedCodeGenContext that can be used by multiple Luau VMs
|
|
// concurrently, using either the default allocator parameters or custom
|
|
// allocator parameters.
|
|
[[nodiscard]] UniqueSharedCodeGenContext createSharedCodeGenContext();
|
|
|
|
[[nodiscard]] UniqueSharedCodeGenContext createSharedCodeGenContext(AllocationCallback* allocationCallback, void* allocationCallbackContext);
|
|
|
|
[[nodiscard]] UniqueSharedCodeGenContext createSharedCodeGenContext(
|
|
size_t blockSize,
|
|
size_t maxTotalSize,
|
|
AllocationCallback* allocationCallback,
|
|
void* allocationCallbackContext
|
|
);
|
|
|
|
// Destroys the provided SharedCodeGenContext. All Luau VMs using the
|
|
// SharedCodeGenContext must be destroyed before this function is called.
|
|
void destroySharedCodeGenContext(const SharedCodeGenContext* codeGenContext) noexcept;
|
|
|
|
// Initializes native code-gen on the provided Luau VM, using a VM-specific
|
|
// code-gen context and either the default allocator parameters or custom
|
|
// allocator parameters.
|
|
void create(lua_State* L);
|
|
void create(lua_State* L, AllocationCallback* allocationCallback, void* allocationCallbackContext);
|
|
void create(lua_State* L, size_t blockSize, size_t maxTotalSize, AllocationCallback* allocationCallback, void* allocationCallbackContext);
|
|
|
|
// Initializes native code-gen on the provided Luau VM, using the provided
|
|
// SharedCodeGenContext. Note that after this function is called, the
|
|
// SharedCodeGenContext must not be destroyed until after the Luau VM L is
|
|
// destroyed via lua_close.
|
|
void create(lua_State* L, SharedCodeGenContext* codeGenContext);
|
|
|
|
// Check if native execution is enabled
|
|
[[nodiscard]] bool isNativeExecutionEnabled(lua_State* L);
|
|
|
|
// Enable or disable native execution according to `enabled` argument
|
|
void setNativeExecutionEnabled(lua_State* L, bool enabled);
|
|
|
|
void disableNativeExecutionForFunction(lua_State* L, const int level) noexcept;
|
|
|
|
// Given a name, this function must return the index of the type which matches the type array used all CompilationOptions and AssemblyOptions
|
|
// If the type is unknown, 0xff has to be returned
|
|
using UserdataRemapperCallback = uint8_t(void* context, const char* name, size_t nameLength);
|
|
|
|
void setUserdataRemapper(lua_State* L, void* context, UserdataRemapperCallback cb);
|
|
|
|
using ModuleId = std::array<uint8_t, 16>;
|
|
|
|
// Builds target function and all inner functions
|
|
CompilationResult compile(lua_State* L, int idx, unsigned int flags, CompilationStats* stats = nullptr);
|
|
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, unsigned int flags, CompilationStats* stats = nullptr);
|
|
|
|
CompilationResult compile(lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats = nullptr);
|
|
CompilationResult compile(const ModuleId& moduleId, lua_State* L, int idx, const CompilationOptions& options, CompilationStats* stats = nullptr);
|
|
|
|
// Generates assembly for target function and all inner functions
|
|
std::string getAssembly(lua_State* L, int idx, AssemblyOptions options = {}, LoweringStats* stats = nullptr);
|
|
|
|
using PerfLogFn = void (*)(void* context, uintptr_t addr, unsigned size, const char* symbol);
|
|
|
|
void setPerfLog(void* context, PerfLogFn logFn);
|
|
|
|
} // namespace CodeGen
|
|
} // namespace Luau
|