mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
d19a5f0699
## What's Changed? * Optimized the vector dot product by up to 24% * Allow for x/y/z/X/Y/Z vector field access by registering a `vector` metatable with an `__index` method (Fixes #1521) * Fixed a bug preventing consistent recovery from parse errors in table types. * Optimized `k*n` and `k+n` when types are known * Allow fragment autocomplete to handle cases like the automatic insertion of parens, keywords, strings, etc., while maintaining a correct relative positioning ### New Solver * Allow for `nil` assignment to tables and classes with indexers --------- Co-authored-by: Aaron Weiss <aaronweiss@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@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>
90 lines
2.7 KiB
C++
90 lines
2.7 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/NotNull.h"
|
|
#include "Luau/Substitution.h"
|
|
#include "Luau/TxnLog.h"
|
|
#include "Luau/TypeFwd.h"
|
|
#include "Luau/Unifiable.h"
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct TypeArena;
|
|
struct TypeCheckLimits;
|
|
|
|
struct Replacer : Substitution
|
|
{
|
|
DenseHashMap<TypeId, TypeId> replacements;
|
|
DenseHashMap<TypePackId, TypePackId> replacementPacks;
|
|
|
|
Replacer(NotNull<TypeArena> arena, DenseHashMap<TypeId, TypeId> replacements, DenseHashMap<TypePackId, TypePackId> replacementPacks)
|
|
: Substitution(TxnLog::empty(), arena)
|
|
, replacements(std::move(replacements))
|
|
, replacementPacks(std::move(replacementPacks))
|
|
{
|
|
}
|
|
|
|
bool isDirty(TypeId ty) override
|
|
{
|
|
return replacements.find(ty) != nullptr;
|
|
}
|
|
|
|
bool isDirty(TypePackId tp) override
|
|
{
|
|
return replacementPacks.find(tp) != nullptr;
|
|
}
|
|
|
|
TypeId clean(TypeId ty) override
|
|
{
|
|
TypeId res = replacements[ty];
|
|
LUAU_ASSERT(res);
|
|
dontTraverseInto(res);
|
|
return res;
|
|
}
|
|
|
|
TypePackId clean(TypePackId tp) override
|
|
{
|
|
TypePackId res = replacementPacks[tp];
|
|
LUAU_ASSERT(res);
|
|
dontTraverseInto(res);
|
|
return res;
|
|
}
|
|
};
|
|
|
|
// A substitution which replaces generic functions by monomorphic functions
|
|
struct Instantiation2 final : Substitution
|
|
{
|
|
// Mapping from generic types to free types to be used in instantiation.
|
|
DenseHashMap<TypeId, TypeId> genericSubstitutions{nullptr};
|
|
// Mapping from generic type packs to `TypePack`s of free types to be used in instantiation.
|
|
DenseHashMap<TypePackId, TypePackId> genericPackSubstitutions{nullptr};
|
|
|
|
Instantiation2(TypeArena* arena, DenseHashMap<TypeId, TypeId> genericSubstitutions, DenseHashMap<TypePackId, TypePackId> genericPackSubstitutions)
|
|
: Substitution(TxnLog::empty(), arena)
|
|
, genericSubstitutions(std::move(genericSubstitutions))
|
|
, genericPackSubstitutions(std::move(genericPackSubstitutions))
|
|
{
|
|
}
|
|
|
|
bool ignoreChildren(TypeId ty) override;
|
|
bool isDirty(TypeId ty) override;
|
|
bool isDirty(TypePackId tp) override;
|
|
TypeId clean(TypeId ty) override;
|
|
TypePackId clean(TypePackId tp) override;
|
|
};
|
|
|
|
std::optional<TypeId> instantiate2(
|
|
TypeArena* arena,
|
|
DenseHashMap<TypeId, TypeId> genericSubstitutions,
|
|
DenseHashMap<TypePackId, TypePackId> genericPackSubstitutions,
|
|
TypeId ty
|
|
);
|
|
std::optional<TypePackId> instantiate2(
|
|
TypeArena* arena,
|
|
DenseHashMap<TypeId, TypeId> genericSubstitutions,
|
|
DenseHashMap<TypePackId, TypePackId> genericPackSubstitutions,
|
|
TypePackId tp
|
|
);
|
|
|
|
} // namespace Luau
|