mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 05:20:38 +00:00
f2e6a8f4a5
This doesn't contain all changes for 507 yet but we might want to do the Luau 0.507 release a bit earlier to end the year sooner. Changes: - Type ascription (::) now permits casts between related types in both directions, allowing to refine or loosen the type (RFC #56) - Fix type definition for tonumber to return number? since the input string isn't guaranteed to contain a valid number - Fix type refinements for field access via [] - Many stability fixes for type checker - Provide extra information in error messages for type mismatches in more cases - Improve performance of type checking for large unions when union members are string literals - Add coverage reporting support to Repl (--coverage command line argument) and lua_getcoverage C API - Work around code signing issues during Makefile builds on macOS - Improve performance of truthiness checks in some cases, particularly on Apple M1, resulting in 10-25% perf gains on qsort benchmark depending on the CPU/compiler - Fix support for little-endian systems; IBM s390x here we go!
77 lines
3 KiB
C++
77 lines
3 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/Common.h"
|
|
#include "Luau/TypeVar.h"
|
|
|
|
#include <unordered_map>
|
|
#include <optional>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
LUAU_FASTINT(LuauTableTypeMaximumStringifierLength)
|
|
LUAU_FASTINT(LuauTypeMaximumStringifierLength)
|
|
|
|
namespace Luau
|
|
{
|
|
|
|
struct ToStringNameMap
|
|
{
|
|
std::unordered_map<TypeId, std::string> typeVars;
|
|
std::unordered_map<TypePackId, std::string> typePacks;
|
|
};
|
|
|
|
struct ToStringOptions
|
|
{
|
|
bool exhaustive = false; // If true, we produce complete output rather than comprehensible output
|
|
bool useLineBreaks = false; // If true, we insert new lines to separate long results such as table entries/metatable.
|
|
bool functionTypeArguments = false; // If true, output function type argument names when they are available
|
|
bool hideTableKind = false; // If true, all tables will be surrounded with plain '{}'
|
|
bool hideNamedFunctionTypeParameters = false; // If true, type parameters of functions will be hidden at top-level.
|
|
size_t maxTableLength = size_t(FInt::LuauTableTypeMaximumStringifierLength); // Only applied to TableTypeVars
|
|
size_t maxTypeLength = size_t(FInt::LuauTypeMaximumStringifierLength);
|
|
std::optional<ToStringNameMap> nameMap;
|
|
std::shared_ptr<Scope> scope; // If present, module names will be added and types that are not available in scope will be marked as 'invalid'
|
|
};
|
|
|
|
struct ToStringResult
|
|
{
|
|
std::string name;
|
|
ToStringNameMap nameMap;
|
|
|
|
bool invalid = false;
|
|
bool error = false;
|
|
bool cycle = false;
|
|
bool truncated = false;
|
|
};
|
|
|
|
ToStringResult toStringDetailed(TypeId ty, const ToStringOptions& opts = {});
|
|
ToStringResult toStringDetailed(TypePackId ty, const ToStringOptions& opts = {});
|
|
|
|
std::string toString(TypeId ty, const ToStringOptions& opts);
|
|
std::string toString(TypePackId ty, const ToStringOptions& opts);
|
|
|
|
// These are offered as overloads rather than a default parameter so that they can be easily invoked from within the MSVC debugger.
|
|
// You can use them in watch expressions!
|
|
inline std::string toString(TypeId ty)
|
|
{
|
|
return toString(ty, ToStringOptions{});
|
|
}
|
|
inline std::string toString(TypePackId ty)
|
|
{
|
|
return toString(ty, ToStringOptions{});
|
|
}
|
|
|
|
std::string toString(const TypeVar& tv, const ToStringOptions& opts = {});
|
|
std::string toString(const TypePackVar& tp, const ToStringOptions& opts = {});
|
|
|
|
std::string toStringNamedFunction(const std::string& prefix, const FunctionTypeVar& ftv, ToStringOptions opts = {});
|
|
|
|
// It could be useful to see the text representation of a type during a debugging session instead of exploring the content of the class
|
|
// These functions will dump the type to stdout and can be evaluated in Watch/Immediate windows or as gdb/lldb expression
|
|
std::string dump(TypeId ty);
|
|
std::string dump(TypePackId ty);
|
|
|
|
std::string generateName(size_t n);
|
|
|
|
} // namespace Luau
|