2021-10-29 16:25:12 -04:00
|
|
|
// 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/Location.h"
|
2023-01-04 15:53:17 -05:00
|
|
|
#include "Luau/Type.h"
|
2022-12-09 14:57:01 -05:00
|
|
|
#include "Luau/TypePack.h"
|
2021-10-29 16:25:12 -04:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2022-09-01 19:14:03 -04:00
|
|
|
struct TxnLog;
|
2022-12-09 14:57:01 -05:00
|
|
|
struct TypeArena;
|
2022-09-01 19:14:03 -04:00
|
|
|
|
2021-10-29 16:25:12 -04:00
|
|
|
using ScopePtr = std::shared_ptr<struct Scope>;
|
|
|
|
|
2022-09-08 18:14:25 -04:00
|
|
|
std::optional<TypeId> findMetatableEntry(
|
2023-01-04 15:53:17 -05:00
|
|
|
NotNull<BuiltinTypes> builtinTypes, ErrorVec& errors, TypeId type, const std::string& entry, Location location);
|
2022-09-08 18:14:25 -04:00
|
|
|
std::optional<TypeId> findTablePropertyRespectingMeta(
|
2023-01-04 15:53:17 -05:00
|
|
|
NotNull<BuiltinTypes> builtinTypes, ErrorVec& errors, TypeId ty, const std::string& name, Location location);
|
2022-09-01 19:14:03 -04:00
|
|
|
|
|
|
|
// Returns the minimum and maximum number of types the argument list can accept.
|
2022-09-15 18:38:17 -04:00
|
|
|
std::pair<size_t, std::optional<size_t>> getParameterExtents(const TxnLog* log, TypePackId tp, bool includeHiddenVariadics = false);
|
2021-10-29 16:25:12 -04:00
|
|
|
|
2022-12-02 13:09:59 -05:00
|
|
|
// Extend the provided pack to at least `length` types.
|
|
|
|
// Returns a temporary TypePack that contains those types plus a tail.
|
2023-03-03 15:21:14 -05:00
|
|
|
TypePack extendTypePack(
|
|
|
|
TypeArena& arena, NotNull<BuiltinTypes> builtinTypes, TypePackId pack, size_t length, std::vector<std::optional<TypeId>> overrides = {});
|
2022-09-29 18:23:10 -04:00
|
|
|
|
2022-10-21 13:54:01 -04:00
|
|
|
/**
|
|
|
|
* Reduces a union by decomposing to the any/error type if it appears in the
|
|
|
|
* type list, and by merging child unions. Also strips out duplicate (by pointer
|
|
|
|
* identity) types.
|
|
|
|
* @param types the input type list to reduce.
|
|
|
|
* @returns the reduced type list.
|
2022-11-04 13:33:22 -04:00
|
|
|
*/
|
2022-10-21 13:54:01 -04:00
|
|
|
std::vector<TypeId> reduceUnion(const std::vector<TypeId>& types);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tries to remove nil from a union type, if there's another option. T | nil
|
|
|
|
* reduces to T, but nil itself does not reduce.
|
2023-01-04 15:53:17 -05:00
|
|
|
* @param builtinTypes the singleton types to use
|
2022-10-21 13:54:01 -04:00
|
|
|
* @param arena the type arena to allocate the new type in, if necessary
|
|
|
|
* @param ty the type to remove nil from
|
|
|
|
* @returns a type with nil removed, or nil itself if that were the only option.
|
2022-11-04 13:33:22 -04:00
|
|
|
*/
|
2023-01-04 15:53:17 -05:00
|
|
|
TypeId stripNil(NotNull<BuiltinTypes> builtinTypes, TypeArena& arena, TypeId ty);
|
2022-10-21 13:54:01 -04:00
|
|
|
|
2021-10-29 16:25:12 -04:00
|
|
|
} // namespace Luau
|