mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Type checker/autocomplete: * `Luau::autocomplete` no longer performs typechecking internally, make sure to run `Frontend::check` before performing autocomplete requests * Autocomplete string suggestions without "" are now only suggested inside the "" * Autocomplete suggestions now include `function (anonymous autofilled)` key with a full suggestion for the function expression (with arguments included) stored in `AutocompleteEntry::insertText` * `AutocompleteEntry::indexedWithSelf` is provided for function call suggestions made with `:` * Cyclic modules now see each other type exports as `any` to prevent memory use-after-free (similar to module return type) Runtime: * Updated inline/loop unroll cost model to better handle assignments (Fixes https://github.com/Roblox/luau/issues/978) * `math.noise` speed was improved by ~30% * `table.concat` speed was improved by ~5-7% * `tonumber` and `tostring` now have fastcall paths that execute ~1.5x and ~2.5x faster respectively (fixes #777) * Fixed crash in `luaL_typename` when index refers to a non-existing value * Fixed potential out of memory scenario when using `string.sub` or `string.char` in a loop * Fixed behavior of some fastcall builtins when called without arguments under -O2 to match original functions * Support for native code execution in VM is now enabled by default (note: native code still has to be generated explicitly) * `Codegen::compile` now accepts `CodeGen_OnlyNativeModules` flag. When set, only modules that have a `--!native` hot-comment at the top will be compiled to native code In our new typechecker: * Generic type packs are no longer considered to be variadic during unification * Timeout and cancellation now works in new solver * Fixed false positive errors around 'table' and 'function' type refinements * Table literals now use covariant unification rules. This is sound since literal has no type specified and has no aliases * Fixed issues with blocked types escaping the constraint solver * Fixed more places where error messages that should've been suppressed were still reported * Fixed errors when iterating over a top table type In our native code generation (jit): * 'DebugLuauAbortingChecks' flag is now supported on A64 * LOP_NEWCLOSURE has been translated to IR
142 lines
4.9 KiB
C
142 lines
4.9 KiB
C
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
// This code is based on Lua 5.x implementation licensed under MIT License; see lua_LICENSE.txt for details
|
|
#pragma once
|
|
|
|
#include "ldo.h"
|
|
#include "lobject.h"
|
|
#include "lstate.h"
|
|
|
|
/*
|
|
** Default settings for GC tunables (settable via lua_gc)
|
|
*/
|
|
#define LUAI_GCGOAL 200 // 200% (allow heap to double compared to live heap size)
|
|
#define LUAI_GCSTEPMUL 200 // GC runs 'twice the speed' of memory allocation
|
|
#define LUAI_GCSTEPSIZE 1 // GC runs every KB of memory allocation
|
|
|
|
/*
|
|
** Possible states of the Garbage Collector
|
|
*/
|
|
#define GCSpause 0
|
|
#define GCSpropagate 1
|
|
#define GCSpropagateagain 2
|
|
#define GCSatomic 3
|
|
#define GCSsweep 4
|
|
|
|
/*
|
|
** macro to tell when main invariant (white objects cannot point to black
|
|
** ones) must be kept. During a collection, the sweep
|
|
** phase may break the invariant, as objects turned white may point to
|
|
** still-black objects. The invariant is restored when sweep ends and
|
|
** all objects are white again.
|
|
*/
|
|
#define keepinvariant(g) ((g)->gcstate == GCSpropagate || (g)->gcstate == GCSpropagateagain || (g)->gcstate == GCSatomic)
|
|
|
|
/*
|
|
** some useful bit tricks
|
|
*/
|
|
#define resetbits(x, m) ((x) &= cast_to(uint8_t, ~(m)))
|
|
#define setbits(x, m) ((x) |= (m))
|
|
#define testbits(x, m) ((x) & (m))
|
|
#define bitmask(b) (1 << (b))
|
|
#define bit2mask(b1, b2) (bitmask(b1) | bitmask(b2))
|
|
#define l_setbit(x, b) setbits(x, bitmask(b))
|
|
#define resetbit(x, b) resetbits(x, bitmask(b))
|
|
#define testbit(x, b) testbits(x, bitmask(b))
|
|
#define set2bits(x, b1, b2) setbits(x, (bit2mask(b1, b2)))
|
|
#define reset2bits(x, b1, b2) resetbits(x, (bit2mask(b1, b2)))
|
|
#define test2bits(x, b1, b2) testbits(x, (bit2mask(b1, b2)))
|
|
|
|
/*
|
|
** Layout for bit use in `marked' field:
|
|
** bit 0 - object is white (type 0)
|
|
** bit 1 - object is white (type 1)
|
|
** bit 2 - object is black
|
|
** bit 3 - object is fixed (should not be collected)
|
|
*/
|
|
|
|
#define WHITE0BIT 0
|
|
#define WHITE1BIT 1
|
|
#define BLACKBIT 2
|
|
#define FIXEDBIT 3
|
|
#define WHITEBITS bit2mask(WHITE0BIT, WHITE1BIT)
|
|
|
|
#define iswhite(x) test2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
|
|
#define isblack(x) testbit((x)->gch.marked, BLACKBIT)
|
|
#define isgray(x) (!testbits((x)->gch.marked, WHITEBITS | bitmask(BLACKBIT)))
|
|
#define isfixed(x) testbit((x)->gch.marked, FIXEDBIT)
|
|
|
|
#define otherwhite(g) (g->currentwhite ^ WHITEBITS)
|
|
#define isdead(g, v) (((v)->gch.marked & (WHITEBITS | bitmask(FIXEDBIT))) == (otherwhite(g) & WHITEBITS))
|
|
|
|
#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
|
|
#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
|
|
|
|
#define luaC_white(g) cast_to(uint8_t, ((g)->currentwhite) & WHITEBITS)
|
|
|
|
#define luaC_needsGC(L) (L->global->totalbytes >= L->global->GCthreshold)
|
|
|
|
#define luaC_checkGC(L) \
|
|
{ \
|
|
condhardstacktests(luaD_reallocstack(L, L->stacksize - EXTRA_STACK)); \
|
|
if (luaC_needsGC(L)) \
|
|
{ \
|
|
condhardmemtests(luaC_validate(L), 1); \
|
|
luaC_step(L, true); \
|
|
} \
|
|
else \
|
|
{ \
|
|
condhardmemtests(luaC_validate(L), 2); \
|
|
} \
|
|
}
|
|
|
|
#define luaC_barrier(L, p, v) \
|
|
{ \
|
|
if (iscollectable(v) && isblack(obj2gco(p)) && iswhite(gcvalue(v))) \
|
|
luaC_barrierf(L, obj2gco(p), gcvalue(v)); \
|
|
}
|
|
|
|
#define luaC_barriert(L, t, v) \
|
|
{ \
|
|
if (iscollectable(v) && isblack(obj2gco(t)) && iswhite(gcvalue(v))) \
|
|
luaC_barriertable(L, t, gcvalue(v)); \
|
|
}
|
|
|
|
#define luaC_barrierfast(L, t) \
|
|
{ \
|
|
if (isblack(obj2gco(t))) \
|
|
luaC_barrierback(L, obj2gco(t), &t->gclist); \
|
|
}
|
|
|
|
#define luaC_objbarrier(L, p, o) \
|
|
{ \
|
|
if (isblack(obj2gco(p)) && iswhite(obj2gco(o))) \
|
|
luaC_barrierf(L, obj2gco(p), obj2gco(o)); \
|
|
}
|
|
|
|
#define luaC_threadbarrier(L) \
|
|
{ \
|
|
if (isblack(obj2gco(L))) \
|
|
luaC_barrierback(L, obj2gco(L), &L->gclist); \
|
|
}
|
|
|
|
#define luaC_init(L, o, tt_) \
|
|
{ \
|
|
o->marked = luaC_white(L->global); \
|
|
o->tt = tt_; \
|
|
o->memcat = L->activememcat; \
|
|
}
|
|
|
|
LUAI_FUNC void luaC_freeall(lua_State* L);
|
|
LUAI_FUNC size_t luaC_step(lua_State* L, bool assist);
|
|
LUAI_FUNC void luaC_fullgc(lua_State* L);
|
|
LUAI_FUNC void luaC_initobj(lua_State* L, GCObject* o, uint8_t tt);
|
|
LUAI_FUNC void luaC_upvalclosed(lua_State* L, UpVal* uv);
|
|
LUAI_FUNC void luaC_barrierf(lua_State* L, GCObject* o, GCObject* v);
|
|
LUAI_FUNC void luaC_barriertable(lua_State* L, Table* t, GCObject* v);
|
|
LUAI_FUNC void luaC_barrierback(lua_State* L, GCObject* o, GCObject** gclist);
|
|
LUAI_FUNC void luaC_validate(lua_State* L);
|
|
LUAI_FUNC void luaC_dump(lua_State* L, void* file, const char* (*categoryName)(lua_State* L, uint8_t memcat));
|
|
LUAI_FUNC void luaC_enumheap(lua_State* L, void* context, void (*node)(void* context, void* ptr, uint8_t tt, uint8_t memcat, const char* name),
|
|
void (*edge)(void* context, void* from, void* to, const char* name));
|
|
LUAI_FUNC int64_t luaC_allocationrate(lua_State* L);
|
|
LUAI_FUNC const char* luaC_statename(int state);
|