mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 14:25:44 +08:00
721f6e10fb
Lots of things going on this week: * Fix a crash that could occur in the presence of a cyclic union. We shouldn't be creating cyclic unions, but we shouldn't be crashing when they arise either. * Minor cleanup of `luau_precall` * Internal change to make L->top handling slightly more uniform * Optimize SETGLOBAL & GETGLOBAL fallback C functions. * https://github.com/Roblox/luau/pull/929 * The syntax to the `luau-reduce` commandline tool has changed. It now accepts a script, a command to execute, and an error to search for. It no longer automatically passes the script to the command which makes it a lot more flexible. Also be warned that it edits the script it is passed **in place**. Do not point it at something that is not in source control! New solver * Switch to a greedier but more fallible algorithm for simplifying union and intersection types that are created as part of refinement calculation. This has much better and more predictable performance. * Fix a constraint cycle in recursive function calls. * Much improved inference of binary addition. Functions like `function add(x, y) return x + y end` can now be inferred without annotations. We also accurately typecheck calls to functions like this. * Many small bugfixes surrounding things like table indexers * Add support for indexers on class types. This was previously added to the old solver; we now add it to the new one for feature parity. JIT * https://github.com/Roblox/luau/pull/931 * Fuse key.value and key.tt loads for CEHCK_SLOT_MATCH in A64 * Implement remaining aliases of BFM for A64 * Implement new callinfo flag for A64 * Add instruction simplification for int->num->int conversion chains * Don't even load execdata for X64 calls * Treat opcode fallbacks the same as manually written fallbacks --------- Co-authored-by: Arseny Kapoulkine <arseny.kapoulkine@gmail.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
112 lines
3.2 KiB
C++
112 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
|
|
#pragma once
|
|
|
|
#include "Luau/Error.h"
|
|
#include "Luau/Linter.h"
|
|
#include "Luau/FileResolver.h"
|
|
#include "Luau/ParseOptions.h"
|
|
#include "Luau/ParseResult.h"
|
|
#include "Luau/Scope.h"
|
|
#include "Luau/TypeArena.h"
|
|
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <unordered_map>
|
|
#include <optional>
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct Module;
|
|
|
|
using ScopePtr = std::shared_ptr<struct Scope>;
|
|
using ModulePtr = std::shared_ptr<Module>;
|
|
|
|
class AstType;
|
|
class AstTypePack;
|
|
|
|
/// Root of the AST of a parsed source file
|
|
struct SourceModule
|
|
{
|
|
ModuleName name; // Module identifier or a filename
|
|
std::string humanReadableName;
|
|
|
|
SourceCode::Type type = SourceCode::None;
|
|
std::optional<std::string> environmentName;
|
|
bool cyclic = false;
|
|
|
|
std::shared_ptr<Allocator> allocator;
|
|
std::shared_ptr<AstNameTable> names;
|
|
std::vector<ParseError> parseErrors;
|
|
|
|
AstStatBlock* root = nullptr;
|
|
std::optional<Mode> mode;
|
|
|
|
std::vector<HotComment> hotcomments;
|
|
std::vector<Comment> commentLocations;
|
|
|
|
SourceModule()
|
|
: allocator(new Allocator)
|
|
, names(new AstNameTable(*allocator))
|
|
{
|
|
}
|
|
};
|
|
|
|
bool isWithinComment(const SourceModule& sourceModule, Position pos);
|
|
bool isWithinComment(const ParseResult& result, Position pos);
|
|
|
|
struct RequireCycle
|
|
{
|
|
Location location;
|
|
std::vector<ModuleName> path; // one of the paths for a require() to go all the way back to the originating module
|
|
};
|
|
|
|
struct Module
|
|
{
|
|
~Module();
|
|
|
|
ModuleName name;
|
|
std::string humanReadableName;
|
|
|
|
TypeArena interfaceTypes;
|
|
TypeArena internalTypes;
|
|
|
|
// Scopes and AST types refer to parse data, so we need to keep that alive
|
|
std::shared_ptr<Allocator> allocator;
|
|
std::shared_ptr<AstNameTable> names;
|
|
|
|
std::vector<std::pair<Location, ScopePtr>> scopes; // never empty
|
|
|
|
DenseHashMap<const AstExpr*, TypeId> astTypes{nullptr};
|
|
DenseHashMap<const AstExpr*, TypePackId> astTypePacks{nullptr};
|
|
DenseHashMap<const AstExpr*, TypeId> astExpectedTypes{nullptr};
|
|
|
|
DenseHashMap<const AstNode*, TypeId> astOriginalCallTypes{nullptr};
|
|
DenseHashMap<const AstNode*, TypeId> astOverloadResolvedTypes{nullptr};
|
|
|
|
DenseHashMap<const AstType*, TypeId> astResolvedTypes{nullptr};
|
|
DenseHashMap<const AstTypePack*, TypePackId> astResolvedTypePacks{nullptr};
|
|
|
|
// Map AST nodes to the scope they create. Cannot be NotNull<Scope> because we need a sentinel value for the map.
|
|
DenseHashMap<const AstNode*, Scope*> astScopes{nullptr};
|
|
|
|
std::unordered_map<Name, TypeId> declaredGlobals;
|
|
ErrorVec errors;
|
|
LintResult lintResult;
|
|
Mode mode;
|
|
SourceCode::Type type;
|
|
bool timeout = false;
|
|
|
|
TypePackId returnType = nullptr;
|
|
std::unordered_map<Name, TypeFun> exportedTypeBindings;
|
|
|
|
bool hasModuleScope() const;
|
|
ScopePtr getModuleScope() const;
|
|
|
|
// Once a module has been typechecked, we clone its public interface into a separate arena.
|
|
// This helps us to force Type ownership into a DAG rather than a DCG.
|
|
void clonePublicInterface(NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
|
|
};
|
|
|
|
} // namespace Luau
|