// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once #include "Luau/Constraint.h" #include "Luau/NotNull.h" #include "Luau/Scope.h" #include "Luau/Module.h" #include "Luau/ToString.h" #include "Luau/Error.h" #include "Luau/Variant.h" #include #include #include namespace Luau { struct ErrorSnapshot { std::string message; Location location; }; struct BindingSnapshot { std::string typeId; std::string typeString; Location location; }; struct TypeBindingSnapshot { std::string typeId; std::string typeString; }; struct ExprTypesAtLocation { Location location; TypeId ty; std::optional expectedTy; }; struct AnnotationTypesAtLocation { Location location; TypeId resolvedTy; }; struct ConstraintGenerationLog { std::string source; std::vector errors; std::vector exprTypeLocations; std::vector annotationTypeLocations; }; struct ScopeSnapshot { std::unordered_map bindings; std::unordered_map typeBindings; std::unordered_map typePackBindings; std::vector children; }; using ConstraintBlockTarget = Variant>; struct ConstraintBlock { ConstraintBlockTarget target; std::string stringification; }; struct ConstraintSnapshot { std::string stringification; Location location; std::vector blocks; }; struct BoundarySnapshot { DenseHashMap unsolvedConstraints{nullptr}; ScopeSnapshot rootScope; DenseHashMap typeStrings{nullptr}; }; struct StepSnapshot { const Constraint* currentConstraint; bool forced; DenseHashMap unsolvedConstraints{nullptr}; ScopeSnapshot rootScope; DenseHashMap typeStrings{nullptr}; }; struct TypeSolveLog { BoundarySnapshot initialState; std::vector stepStates; BoundarySnapshot finalState; }; struct TypeCheckLog { std::vector errors; }; struct DcrLogger { std::string compileOutput(); void captureSource(std::string source); void captureGenerationError(const TypeError& error); void captureConstraintLocation(NotNull constraint, Location location); void captureGenerationModule(const ModulePtr& module); void pushBlock(NotNull constraint, TypeId block); void pushBlock(NotNull constraint, TypePackId block); void pushBlock(NotNull constraint, NotNull block); void popBlock(TypeId block); void popBlock(TypePackId block); void popBlock(NotNull block); void captureInitialSolverState(const Scope* rootScope, const std::vector>& unsolvedConstraints); StepSnapshot prepareStepSnapshot( const Scope* rootScope, NotNull current, bool force, const std::vector>& unsolvedConstraints); void commitStepSnapshot(StepSnapshot snapshot); void captureFinalSolverState(const Scope* rootScope, const std::vector>& unsolvedConstraints); void captureTypeCheckError(const TypeError& error); private: ConstraintGenerationLog generationLog; std::unordered_map, std::vector> constraintBlocks; TypeSolveLog solveLog; TypeCheckLog checkLog; ToStringOptions opts{true}; std::vector snapshotBlocks(NotNull constraint); void captureBoundaryState(BoundarySnapshot& target, const Scope* rootScope, const std::vector>& unsolvedConstraints); }; } // namespace Luau