luau/Analysis/src/Def.cpp
Lily Brown 47ad768c69
Sync to upstream/release/619 (#1218)
# What's Changed

## New Type Solver
- Many fixes to crashes, assertions, and hangs
- Binary type family aliases now have a default parameter
- Added a debug check for unsolved types escaping the constraint solver
- Overloaded functions are no longer inferred
- Unification creates additional subtyping constraints for blocked types
- Attempt to guess the result type for type families that are too large
to resolve timely

## Native Code Generation
- Fixed `IrCmd::CHECK_TRUTHY` lowering in a specific case
- Detailed compilation errors are now supported
- More work on the new allocator

---

# Internal Contributors

Co-authored-by: Aaron Weiss <aaronweiss@roblox.com>
Co-authored-by: Alexander McCord <amccord@roblox.com>
Co-authored-by: Andy Friesen <afriesen@roblox.com>
Co-authored-by: James McNellis <jmcnellis@roblox.com>
Co-authored-by: Lily Brown <lbrown@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
2024-03-30 16:14:44 -07:00

63 lines
1.6 KiB
C++

// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#include "Luau/Def.h"
#include "Luau/Common.h"
#include <algorithm>
namespace Luau
{
bool containsSubscriptedDefinition(DefId def)
{
if (auto cell = get<Cell>(def))
return cell->subscripted;
else if (auto phi = get<Phi>(def))
return std::any_of(phi->operands.begin(), phi->operands.end(), containsSubscriptedDefinition);
else
return false;
}
void collectOperands(DefId def, std::vector<DefId>* operands)
{
LUAU_ASSERT(operands);
if (std::find(operands->begin(), operands->end(), def) != operands->end())
return;
else if (get<Cell>(def))
operands->push_back(def);
else if (auto phi = get<Phi>(def))
{
// A trivial phi node has no operands to populate, so we push this definition in directly.
if (phi->operands.empty())
return operands->push_back(def);
for (const Def* operand : phi->operands)
collectOperands(NotNull{operand}, operands);
}
}
DefId DefArena::freshCell(bool subscripted)
{
return NotNull{allocator.allocate(Def{Cell{subscripted}})};
}
DefId DefArena::phi(DefId a, DefId b)
{
return phi({a, b});
}
DefId DefArena::phi(const std::vector<DefId>& defs)
{
std::vector<DefId> operands;
for (DefId operand : defs)
collectOperands(operand, &operands);
// There's no need to allocate a Phi node for a singleton set.
if (operands.size() == 1)
return operands[0];
else
return NotNull{allocator.allocate(Def{Phi{std::move(operands)}})};
}
} // namespace Luau