mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-05 19:09:11 +00:00
97965c7c0a
* `ClassType` can now have an indexer defined on it. This allows custom types to be used in `t[x]` expressions. * Fixed search for closest executable breakpoint line. Previously, breakpoints might have been skipped in `else` blocks at the end of a function * Fixed how unification is performed for two optional types `a? <: b?`, previously it might have unified either 'a' or 'b' with 'nil'. Note that this fix is not enabled by default yet (see the list in `ExperimentalFlags.h`) In the new type solver, a concept of 'Type Families' has been introduced. Type families can be thought of as type aliases with custom type inference/reduction logic included with them. For example, we can have an `Add<T, U>` type family that will resolve the type that is the result of adding two values together. This will help type inference to figure out what 'T' and 'U' might be when explicit type annotations are not provided. In this update we don't define any type families, but they will be added in the near future. It is also possible for Luau embedders to define their own type families in the global/environment scope. Other changes include: * Fixed scope used to find out which generic types should be included in the function generic type list * Fixed a crash after cyclic bound types were created during unification And in native code generation (jit): * Use of arm64 target on M1 now requires macOS 13 * Entry into native code has been optimized. This is especially important for coroutine call/pcall performance as they involve going through a C call frame * LOP_LOADK(X) translation into IR has been improved to enable type tag/constant propagation * arm64 can use integer immediate values to synthesize floating-point values * x64 assembler removes duplicate 64bit numbers from the data section to save space * Linux `perf` can now be used to profile native Luau code (when running with --codegen-perf CLI argument)
131 lines
5 KiB
C++
131 lines
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/Bytecode.h"
|
|
#include "Luau/CodeAllocator.h"
|
|
#include "Luau/Label.h"
|
|
|
|
#include <memory>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include "ldebug.h"
|
|
#include "lobject.h"
|
|
#include "ltm.h"
|
|
#include "lstate.h"
|
|
|
|
typedef int (*luau_FastFunction)(lua_State* L, StkId res, TValue* arg0, int nresults, StkId args, int nparams);
|
|
|
|
namespace Luau
|
|
{
|
|
namespace CodeGen
|
|
{
|
|
|
|
class UnwindBuilder;
|
|
|
|
using FallbackFn = const Instruction* (*)(lua_State* L, const Instruction* pc, StkId base, TValue* k);
|
|
|
|
struct NativeProto
|
|
{
|
|
// This array is stored before NativeProto in reverse order, so to get offset of instruction i you need to index instOffsets[-i]
|
|
// This awkward layout is helpful for maximally efficient address computation on X64/A64
|
|
uint32_t instOffsets[1];
|
|
|
|
uintptr_t instBase = 0;
|
|
uintptr_t entryTarget = 0; // = instOffsets[0] + instBase
|
|
Proto* proto = nullptr;
|
|
};
|
|
|
|
struct NativeContext
|
|
{
|
|
// Gateway (C => native transition) entry & exit, compiled at runtime
|
|
uint8_t* gateEntry = nullptr;
|
|
uint8_t* gateExit = nullptr;
|
|
|
|
// Helper functions, implemented in C
|
|
int (*luaV_lessthan)(lua_State* L, const TValue* l, const TValue* r) = nullptr;
|
|
int (*luaV_lessequal)(lua_State* L, const TValue* l, const TValue* r) = nullptr;
|
|
int (*luaV_equalval)(lua_State* L, const TValue* t1, const TValue* t2) = nullptr;
|
|
void (*luaV_doarith)(lua_State* L, StkId ra, const TValue* rb, const TValue* rc, TMS op) = nullptr;
|
|
void (*luaV_dolen)(lua_State* L, StkId ra, const TValue* rb) = nullptr;
|
|
void (*luaV_prepareFORN)(lua_State* L, StkId plimit, StkId pstep, StkId pinit) = nullptr;
|
|
void (*luaV_gettable)(lua_State* L, const TValue* t, TValue* key, StkId val) = nullptr;
|
|
void (*luaV_settable)(lua_State* L, const TValue* t, TValue* key, StkId val) = nullptr;
|
|
void (*luaV_getimport)(lua_State* L, Table* env, TValue* k, uint32_t id, bool propagatenil) = nullptr;
|
|
void (*luaV_concat)(lua_State* L, int total, int last) = nullptr;
|
|
|
|
int (*luaH_getn)(Table* t) = nullptr;
|
|
Table* (*luaH_new)(lua_State* L, int narray, int lnhash) = nullptr;
|
|
Table* (*luaH_clone)(lua_State* L, Table* tt) = nullptr;
|
|
void (*luaH_resizearray)(lua_State* L, Table* t, int nasize) = nullptr;
|
|
|
|
void (*luaC_barriertable)(lua_State* L, Table* t, GCObject* v) = nullptr;
|
|
void (*luaC_barrierf)(lua_State* L, GCObject* o, GCObject* v) = nullptr;
|
|
void (*luaC_barrierback)(lua_State* L, GCObject* o, GCObject** gclist) = nullptr;
|
|
size_t (*luaC_step)(lua_State* L, bool assist) = nullptr;
|
|
|
|
void (*luaF_close)(lua_State* L, StkId level) = nullptr;
|
|
|
|
const TValue* (*luaT_gettm)(Table* events, TMS event, TString* ename) = nullptr;
|
|
const TString* (*luaT_objtypenamestr)(lua_State* L, const TValue* o) = nullptr;
|
|
|
|
double (*libm_exp)(double) = nullptr;
|
|
double (*libm_pow)(double, double) = nullptr;
|
|
double (*libm_fmod)(double, double) = nullptr;
|
|
double (*libm_asin)(double) = nullptr;
|
|
double (*libm_sin)(double) = nullptr;
|
|
double (*libm_sinh)(double) = nullptr;
|
|
double (*libm_acos)(double) = nullptr;
|
|
double (*libm_cos)(double) = nullptr;
|
|
double (*libm_cosh)(double) = nullptr;
|
|
double (*libm_atan)(double) = nullptr;
|
|
double (*libm_atan2)(double, double) = nullptr;
|
|
double (*libm_tan)(double) = nullptr;
|
|
double (*libm_tanh)(double) = nullptr;
|
|
double (*libm_log)(double) = nullptr;
|
|
double (*libm_log2)(double) = nullptr;
|
|
double (*libm_log10)(double) = nullptr;
|
|
double (*libm_ldexp)(double, int) = nullptr;
|
|
double (*libm_round)(double) = nullptr;
|
|
double (*libm_frexp)(double, int*) = nullptr;
|
|
double (*libm_modf)(double, double*) = nullptr;
|
|
|
|
// Helper functions
|
|
bool (*forgLoopTableIter)(lua_State* L, Table* h, int index, TValue* ra) = nullptr;
|
|
bool (*forgLoopNodeIter)(lua_State* L, Table* h, int index, TValue* ra) = nullptr;
|
|
bool (*forgLoopNonTableFallback)(lua_State* L, int insnA, int aux) = nullptr;
|
|
void (*forgPrepXnextFallback)(lua_State* L, TValue* ra, int pc) = nullptr;
|
|
Closure* (*callProlog)(lua_State* L, TValue* ra, StkId argtop, int nresults) = nullptr;
|
|
void (*callEpilogC)(lua_State* L, int nresults, int n) = nullptr;
|
|
|
|
Closure* (*callFallback)(lua_State* L, StkId ra, StkId argtop, int nresults) = nullptr;
|
|
Closure* (*returnFallback)(lua_State* L, StkId ra, StkId valend) = nullptr;
|
|
|
|
// Opcode fallbacks, implemented in C
|
|
FallbackFn fallback[LOP__COUNT] = {};
|
|
|
|
// Fast call methods, implemented in C
|
|
luau_FastFunction luauF_table[256] = {};
|
|
};
|
|
|
|
using GateFn = int (*)(lua_State*, Proto*, uintptr_t, NativeContext*);
|
|
|
|
struct NativeState
|
|
{
|
|
NativeState();
|
|
~NativeState();
|
|
|
|
CodeAllocator codeAllocator;
|
|
std::unique_ptr<UnwindBuilder> unwindBuilder;
|
|
|
|
uint8_t* gateData = nullptr;
|
|
size_t gateDataSize = 0;
|
|
|
|
NativeContext context;
|
|
};
|
|
|
|
void initFallbackTable(NativeState& data);
|
|
void initHelperFunctions(NativeState& data);
|
|
|
|
} // namespace CodeGen
|
|
} // namespace Luau
|