mirror of
https://github.com/luau-lang/luau.git
synced 2025-01-19 17:28:06 +00:00
a251bc68a2
* New `vector` library! See https://rfcs.luau.org/vector-library.html for details * Replace the use of non-portable `strnlen` with `memchr`. `strnlen` is not part of any C or C++ standard. * Introduce `lua_newuserdatataggedwithmetatable` for faster tagged userdata creation of userdata with metatables registered with `lua_setuserdatametatable` Old Solver * It used to be the case that a module's result type would unconditionally be inferred to be `any` if it imported any module that participates in any import cycle. This is now fixed. New Solver * Improve inference of `table.freeze`: We now infer read-only properties on tables after they have been frozen. * We now correctly flag cases where `string.format` is called with 0 arguments. * Fix a bug in user-defined type functions where table properties could be lost if the table had a metatable * Reset the random number seed for each evaluation of a type function * We now retry subtyping arguments if it failed due to hidden variadics. --------- Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Vighnesh <vvijay@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> Co-authored-by: Junseo Yoo <jyoo@roblox.com>
135 lines
3.2 KiB
C++
135 lines
3.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/TypeArena.h"
|
|
|
|
LUAU_FASTFLAGVARIABLE(DebugLuauFreezeArena);
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
void TypeArena::clear()
|
|
{
|
|
types.clear();
|
|
typePacks.clear();
|
|
}
|
|
|
|
TypeId TypeArena::addTV(Type&& tv)
|
|
{
|
|
TypeId allocated = types.allocate(std::move(tv));
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypeId TypeArena::freshType(TypeLevel level)
|
|
{
|
|
TypeId allocated = types.allocate(FreeType{level});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypeId TypeArena::freshType(Scope* scope)
|
|
{
|
|
TypeId allocated = types.allocate(FreeType{scope});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypeId TypeArena::freshType(Scope* scope, TypeLevel level)
|
|
{
|
|
TypeId allocated = types.allocate(FreeType{scope, level});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypePackId TypeArena::freshTypePack(Scope* scope)
|
|
{
|
|
TypePackId allocated = typePacks.allocate(FreeTypePack{scope});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePack(std::initializer_list<TypeId> types)
|
|
{
|
|
TypePackId allocated = typePacks.allocate(TypePack{std::move(types)});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePack(std::vector<TypeId> types, std::optional<TypePackId> tail)
|
|
{
|
|
TypePackId allocated = typePacks.allocate(TypePack{std::move(types), tail});
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePack(TypePack tp)
|
|
{
|
|
TypePackId allocated = typePacks.allocate(std::move(tp));
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePack(TypePackVar tp)
|
|
{
|
|
TypePackId allocated = typePacks.allocate(std::move(tp));
|
|
|
|
asMutable(allocated)->owningArena = this;
|
|
|
|
return allocated;
|
|
}
|
|
|
|
TypeId TypeArena::addTypeFunction(const TypeFunction& function, std::initializer_list<TypeId> types)
|
|
{
|
|
return addType(TypeFunctionInstanceType{function, std::move(types)});
|
|
}
|
|
|
|
TypeId TypeArena::addTypeFunction(const TypeFunction& function, std::vector<TypeId> typeArguments, std::vector<TypePackId> packArguments)
|
|
{
|
|
return addType(TypeFunctionInstanceType{function, std::move(typeArguments), std::move(packArguments)});
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePackFunction(const TypePackFunction& function, std::initializer_list<TypeId> types)
|
|
{
|
|
return addTypePack(TypeFunctionInstanceTypePack{NotNull{&function}, std::move(types)});
|
|
}
|
|
|
|
TypePackId TypeArena::addTypePackFunction(const TypePackFunction& function, std::vector<TypeId> typeArguments, std::vector<TypePackId> packArguments)
|
|
{
|
|
return addTypePack(TypeFunctionInstanceTypePack{NotNull{&function}, std::move(typeArguments), std::move(packArguments)});
|
|
}
|
|
|
|
void freeze(TypeArena& arena)
|
|
{
|
|
if (!FFlag::DebugLuauFreezeArena)
|
|
return;
|
|
|
|
arena.types.freeze();
|
|
arena.typePacks.freeze();
|
|
}
|
|
|
|
void unfreeze(TypeArena& arena)
|
|
{
|
|
if (!FFlag::DebugLuauFreezeArena)
|
|
return;
|
|
|
|
arena.types.unfreeze();
|
|
arena.typePacks.unfreeze();
|
|
}
|
|
|
|
} // namespace Luau
|