luau/Ast/src/Cst.cpp
vegorov-rbx c2e72666d9
Sync to upstream/release/662 (#1681)
## What's new

This update brings improvements to the new type solver, roundtrippable
AST parsing mode and closes multiple issues reported in this repository.

* `require` dependency tracing for non-string requires now supports `()`
groups in expressions and types as well as an ability to type annotate a
value with a `typeof` of a different module path
* Fixed rare misaligned memory access in Compiler/Typechecker on 32 bit
platforms (Closes #1572)

## New Solver

* Fixed crash/UB in subtyping of type packs (Closes #1449)
* Fixed incorrect type errors when calling `debug.info` (Closes #1534
and Resolves #966)
* Fixed incorrect boolean and string equality comparison result in
user-defined type functions (Closes #1623)
* Fixed incorrect class types being produced in user-defined type
functions when multiple classes share the same name (Closes #1639)
* Improved bidirectional typechecking for table literals containing
elements that have not been solved yet (Closes #1641)

## Roundtrippable AST

* Added source information for `AstStatTypeAlias`
* Fixed an issue with `AstTypeGroup` node (added in #1643) producing
invalid AST json. Contained type is now named 'inner' instead of 'type'
* Fixed end location of the `do ... end` statement

---

Internal Contributors:

Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com>
Co-authored-by: Talha Pathan <tpathan@roblox.com>
Co-authored-by: Varun Saini <vsaini@roblox.com>
Co-authored-by: Vighnesh Vijay <vvijay@roblox.com>
Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
2025-02-21 10:24:12 -08:00

200 lines
5.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/Ast.h"
#include "Luau/Cst.h"
#include "Luau/Common.h"
namespace Luau
{
int gCstRttiIndex = 0;
CstExprConstantNumber::CstExprConstantNumber(const AstArray<char>& value)
: CstNode(CstClassIndex())
, value(value)
{
}
CstExprConstantString::CstExprConstantString(AstArray<char> sourceString, QuoteStyle quoteStyle, unsigned int blockDepth)
: CstNode(CstClassIndex())
, sourceString(sourceString)
, quoteStyle(quoteStyle)
, blockDepth(blockDepth)
{
LUAU_ASSERT(blockDepth == 0 || quoteStyle == QuoteStyle::QuotedRaw);
}
CstExprCall::CstExprCall(std::optional<Position> openParens, std::optional<Position> closeParens, AstArray<Position> commaPositions)
: CstNode(CstClassIndex())
, openParens(openParens)
, closeParens(closeParens)
, commaPositions(commaPositions)
{
}
CstExprIndexExpr::CstExprIndexExpr(Position openBracketPosition, Position closeBracketPosition)
: CstNode(CstClassIndex())
, openBracketPosition(openBracketPosition)
, closeBracketPosition(closeBracketPosition)
{
}
CstExprTable::CstExprTable(const AstArray<Item>& items)
: CstNode(CstClassIndex())
, items(items)
{
}
CstExprOp::CstExprOp(Position opPosition)
: CstNode(CstClassIndex())
, opPosition(opPosition)
{
}
CstExprTypeAssertion::CstExprTypeAssertion(Position opPosition)
: CstNode(CstClassIndex())
, opPosition(opPosition)
{
}
CstExprIfElse::CstExprIfElse(Position thenPosition, Position elsePosition, bool isElseIf)
: CstNode(CstClassIndex())
, thenPosition(thenPosition)
, elsePosition(elsePosition)
, isElseIf(isElseIf)
{
}
CstExprInterpString::CstExprInterpString(AstArray<AstArray<char>> sourceStrings, AstArray<Position> stringPositions)
: CstNode(CstClassIndex())
, sourceStrings(sourceStrings)
, stringPositions(stringPositions)
{
}
CstStatDo::CstStatDo(Position endPosition)
: CstNode(CstClassIndex())
, endPosition(endPosition)
{
}
CstStatRepeat::CstStatRepeat(Position untilPosition)
: CstNode(CstClassIndex())
, untilPosition(untilPosition)
{
}
CstStatReturn::CstStatReturn(AstArray<Position> commaPositions)
: CstNode(CstClassIndex())
, commaPositions(commaPositions)
{
}
CstStatLocal::CstStatLocal(AstArray<Position> varsCommaPositions, AstArray<Position> valuesCommaPositions)
: CstNode(CstClassIndex())
, varsCommaPositions(varsCommaPositions)
, valuesCommaPositions(valuesCommaPositions)
{
}
CstStatFor::CstStatFor(Position equalsPosition, Position endCommaPosition, std::optional<Position> stepCommaPosition)
: CstNode(CstClassIndex())
, equalsPosition(equalsPosition)
, endCommaPosition(endCommaPosition)
, stepCommaPosition(stepCommaPosition)
{
}
CstStatForIn::CstStatForIn(AstArray<Position> varsCommaPositions, AstArray<Position> valuesCommaPositions)
: CstNode(CstClassIndex())
, varsCommaPositions(varsCommaPositions)
, valuesCommaPositions(valuesCommaPositions)
{
}
CstStatAssign::CstStatAssign(AstArray<Position> varsCommaPositions, Position equalsPosition, AstArray<Position> valuesCommaPositions)
: CstNode(CstClassIndex())
, varsCommaPositions(varsCommaPositions)
, equalsPosition(equalsPosition)
, valuesCommaPositions(valuesCommaPositions)
{
}
CstStatCompoundAssign::CstStatCompoundAssign(Position opPosition)
: CstNode(CstClassIndex())
, opPosition(opPosition)
{
}
CstStatLocalFunction::CstStatLocalFunction(Position functionKeywordPosition)
: CstNode(CstClassIndex())
, functionKeywordPosition(functionKeywordPosition)
{
}
CstGenericType::CstGenericType(std::optional<Position> defaultEqualsPosition)
: CstNode(CstClassIndex())
, defaultEqualsPosition(defaultEqualsPosition)
{
}
CstGenericTypePack::CstGenericTypePack(Position ellipsisPosition, std::optional<Position> defaultEqualsPosition)
: CstNode(CstClassIndex())
, ellipsisPosition(ellipsisPosition)
, defaultEqualsPosition(defaultEqualsPosition)
{
}
CstStatTypeAlias::CstStatTypeAlias(
Position typeKeywordPosition,
Position genericsOpenPosition,
AstArray<Position> genericsCommaPositions,
Position genericsClosePosition,
Position equalsPosition
)
: CstNode(CstClassIndex())
, typeKeywordPosition(typeKeywordPosition)
, genericsOpenPosition(genericsOpenPosition)
, genericsCommaPositions(genericsCommaPositions)
, genericsClosePosition(genericsClosePosition)
, equalsPosition(equalsPosition)
{
}
CstTypeReference::CstTypeReference(
std::optional<Position> prefixPointPosition,
Position openParametersPosition,
AstArray<Position> parametersCommaPositions,
Position closeParametersPosition
)
: CstNode(CstClassIndex())
, prefixPointPosition(prefixPointPosition)
, openParametersPosition(openParametersPosition)
, parametersCommaPositions(parametersCommaPositions)
, closeParametersPosition(closeParametersPosition)
{
}
CstTypeTable::CstTypeTable(AstArray<Item> items, bool isArray)
: CstNode(CstClassIndex())
, items(items)
, isArray(isArray)
{
}
CstTypeTypeof::CstTypeTypeof(Position openPosition, Position closePosition)
: CstNode(CstClassIndex())
, openPosition(openPosition)
, closePosition(closePosition)
{
}
CstTypeSingletonString::CstTypeSingletonString(AstArray<char> sourceString, CstExprConstantString::QuoteStyle quoteStyle, unsigned int blockDepth)
: CstNode(CstClassIndex())
, sourceString(sourceString)
, quoteStyle(quoteStyle)
, blockDepth(blockDepth)
{
LUAU_ASSERT(quoteStyle != CstExprConstantString::QuotedInterp);
}
} // namespace Luau