2022-06-16 18:05:14 -07:00
|
|
|
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
|
|
|
|
|
|
#include "Luau/Constraint.h"
|
2023-10-27 14:18:41 -07:00
|
|
|
#include "Luau/VisitType.h"
|
2022-06-16 18:05:14 -07:00
|
|
|
|
|
|
|
namespace Luau
|
|
|
|
{
|
|
|
|
|
2022-09-01 16:14:03 -07:00
|
|
|
Constraint::Constraint(NotNull<Scope> scope, const Location& location, ConstraintV&& c)
|
|
|
|
: scope(scope)
|
|
|
|
, location(location)
|
|
|
|
, c(std::move(c))
|
2022-06-16 18:05:14 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-10-27 14:18:41 -07:00
|
|
|
struct FreeTypeCollector : TypeOnceVisitor
|
|
|
|
{
|
|
|
|
|
|
|
|
DenseHashSet<TypeId>* result;
|
|
|
|
|
|
|
|
FreeTypeCollector(DenseHashSet<TypeId>* result)
|
|
|
|
: result(result)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool visit(TypeId ty, const FreeType&) override
|
|
|
|
{
|
|
|
|
result->insert(ty);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DenseHashSet<TypeId> Constraint::getFreeTypes() const
|
|
|
|
{
|
|
|
|
DenseHashSet<TypeId> types{{}};
|
|
|
|
FreeTypeCollector ftc{&types};
|
|
|
|
|
|
|
|
if (auto sc = get<SubtypeConstraint>(*this))
|
|
|
|
{
|
|
|
|
ftc.traverse(sc->subType);
|
|
|
|
ftc.traverse(sc->superType);
|
|
|
|
}
|
|
|
|
else if (auto psc = get<PackSubtypeConstraint>(*this))
|
|
|
|
{
|
|
|
|
ftc.traverse(psc->subPack);
|
|
|
|
ftc.traverse(psc->superPack);
|
|
|
|
}
|
|
|
|
|
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
2022-06-16 18:05:14 -07:00
|
|
|
} // namespace Luau
|