// 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/FileResolver.h" #include "Luau/ParseOptions.h" #include "Luau/ParseResult.h" #include "Luau/Scope.h" #include "Luau/TypeArena.h" #include #include #include #include namespace Luau { struct Module; using ScopePtr = std::shared_ptr; using ModulePtr = std::shared_ptr; class AstType; class AstTypePack; /// Root of the AST of a parsed source file struct SourceModule { ModuleName name; // DataModel path if possible. Filename if not. SourceCode::Type type = SourceCode::None; std::optional environmentName; bool cyclic = false; std::shared_ptr allocator; std::shared_ptr names; std::vector parseErrors; AstStatBlock* root = nullptr; std::optional mode; std::vector hotcomments; std::vector commentLocations; SourceModule() : allocator(new Allocator) , names(new AstNameTable(*allocator)) { } }; bool isWithinComment(const SourceModule& sourceModule, Position pos); struct RequireCycle { Location location; std::vector path; // one of the paths for a require() to go all the way back to the originating module }; struct Module { ~Module(); TypeArena interfaceTypes; TypeArena internalTypes; // Scopes and AST types refer to parse data, so we need to keep that alive std::shared_ptr allocator; std::shared_ptr names; std::vector> scopes; // never empty DenseHashMap astTypes{nullptr}; DenseHashMap astTypePacks{nullptr}; DenseHashMap astExpectedTypes{nullptr}; DenseHashMap astOriginalCallTypes{nullptr}; DenseHashMap astOverloadResolvedTypes{nullptr}; DenseHashMap astResolvedTypes{nullptr}; DenseHashMap astOriginalResolvedTypes{nullptr}; DenseHashMap astResolvedTypePacks{nullptr}; // Map AST nodes to the scope they create. Cannot be NotNull because we need a sentinel value for the map. DenseHashMap astScopes{nullptr}; std::unique_ptr reduction; std::unordered_map declaredGlobals; ErrorVec errors; Mode mode; SourceCode::Type type; bool timeout = false; TypePackId returnType = nullptr; std::unordered_map 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, InternalErrorReporter& ice); }; } // namespace Luau