// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details #pragma once #include "Luau/Scope.h" #include "Luau/NotNull.h" #include "Luau/TypeFwd.h" namespace Luau { template struct GeneralizationParams { bool foundOutsideFunctions = false; size_t useCount = 0; Polarity polarity = Polarity::None; }; template struct GeneralizationResult { std::optional result; // True if the provided type was replaced with a generic. bool wasReplacedByGeneric = false; bool resourceLimitsExceeded = false; explicit operator bool() const { return bool(result); } }; // Replace a single free type by its bounds according to the polarity provided. GeneralizationResult generalizeType( NotNull arena, NotNull builtinTypes, NotNull scope, TypeId freeTy, const GeneralizationParams& params ); // Generalize one type pack GeneralizationResult generalizeTypePack( NotNull arena, NotNull builtinTypes, NotNull scope, TypePackId tp, const GeneralizationParams& params ); void sealTable(NotNull scope, TypeId ty); /** Attempt to generalize a type. * * If generalizationTarget is set, then only that type will be replaced by its * bounds. The way this is intended to be used is that ty is some function that * is not fully generalized, and generalizationTarget is a type within its * signature. There should be no further constraints that could affect the * bounds of generalizationTarget. * * Returns nullopt if generalization failed due to resources limits. */ std::optional generalize( NotNull arena, NotNull builtinTypes, NotNull scope, NotNull> cachedTypes, TypeId ty, std::optional generalizationTarget = {} ); void pruneUnnecessaryGenerics( NotNull arena, NotNull builtinTypes, NotNull scope, NotNull> cachedTypes, TypeId ty ); } // namespace Luau