Skip to content

Commit bdcb159

Browse files
committed
Bump Luau to 0.701
1 parent e530c57 commit bdcb159

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+1075
-149
lines changed

luau/Ast/include/Luau/Ast.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ struct AstTypeList
118118
AstTypePack* tailType = nullptr;
119119
};
120120

121+
// Don't have Luau::Variant available, it's a bit of an overhead, but a plain struct is nice to use
122+
struct AstTypeOrPack
123+
{
124+
AstType* type = nullptr;
125+
AstTypePack* typePack = nullptr;
126+
};
127+
121128
using AstArgumentName = std::pair<AstName, Location>; // TODO: remove and replace when we get a common struct for this pair instead of AstName
122129

123130
extern int gAstRttiIndex;
@@ -415,11 +422,22 @@ class AstExprCall : public AstExpr
415422
public:
416423
LUAU_RTTI(AstExprCall)
417424

418-
AstExprCall(const Location& location, AstExpr* func, const AstArray<AstExpr*>& args, bool self, const Location& argLocation);
425+
AstExprCall(
426+
const Location& location,
427+
AstExpr* func,
428+
const AstArray<AstExpr*>& args,
429+
bool self,
430+
const AstArray<AstTypeOrPack>& explicitTypes,
431+
const Location& argLocation
432+
);
419433

420434
void visit(AstVisitor* visitor) override;
421435

422436
AstExpr* func;
437+
// These will only be filled in specifically `t:f<<A, B>>()`.
438+
// In `f<<A, B>>()`, this is parsed as `f<<A, B>>` as an expression,
439+
// which is then called.
440+
AstArray<AstTypeOrPack> typeArguments;
423441
AstArray<AstExpr*> args;
424442
bool self;
425443
Location argLocation;
@@ -642,6 +660,20 @@ class AstExprInterpString : public AstExpr
642660
AstArray<AstExpr*> expressions;
643661
};
644662

663+
// f<<T>>
664+
class AstExprInstantiate : public AstExpr
665+
{
666+
public:
667+
LUAU_RTTI(AstExprInstantiate)
668+
669+
AstExprInstantiate(const Location& location, AstExpr* expr, AstArray<AstTypeOrPack> typePack);
670+
671+
void visit(AstVisitor* visitor) override;
672+
673+
AstExpr* expr;
674+
AstArray<AstTypeOrPack> typeArguments;
675+
};
676+
645677
class AstStatBlock : public AstStat
646678
{
647679
public:
@@ -1071,13 +1103,6 @@ class AstType : public AstNode
10711103
}
10721104
};
10731105

1074-
// Don't have Luau::Variant available, it's a bit of an overhead, but a plain struct is nice to use
1075-
struct AstTypeOrPack
1076-
{
1077-
AstType* type = nullptr;
1078-
AstTypePack* typePack = nullptr;
1079-
};
1080-
10811106
class AstTypeReference : public AstType
10821107
{
10831108
public:

luau/Ast/include/Luau/Cst.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ class CstExprConstantString : public CstNode
8383
unsigned int blockDepth;
8484
};
8585

86+
// Shared between the expression and call nodes
87+
struct CstTypeInstantiation
88+
{
89+
Position leftArrow1Position = {0,0};
90+
Position leftArrow2Position = {0,0};
91+
92+
AstArray<Position> commaPositions = {};
93+
94+
Position rightArrow1Position = {0,0};
95+
Position rightArrow2Position = {0,0};
96+
};
97+
8698
class CstExprCall : public CstNode
8799
{
88100
public:
@@ -93,6 +105,7 @@ class CstExprCall : public CstNode
93105
std::optional<Position> openParens;
94106
std::optional<Position> closeParens;
95107
AstArray<Position> commaPositions;
108+
CstTypeInstantiation* explicitTypes = nullptr;
96109
};
97110

98111
class CstExprIndexExpr : public CstNode
@@ -192,6 +205,16 @@ class CstExprInterpString : public CstNode
192205
AstArray<Position> stringPositions;
193206
};
194207

208+
class CstExprExplicitTypeInstantiation : public CstNode
209+
{
210+
public:
211+
LUAU_CST_RTTI(CstExprExplicitTypeInstantiation)
212+
213+
explicit CstExprExplicitTypeInstantiation(CstTypeInstantiation instantiation);
214+
215+
CstTypeInstantiation instantiation;
216+
};
217+
195218
class CstStatDo : public CstNode
196219
{
197220
public:

luau/Ast/include/Luau/Parser.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ class Parser
283283
// prefixexp -> NAME | '(' expr ')'
284284
AstExpr* parsePrefixExpr();
285285

286-
// primaryexp -> prefixexp { `.' NAME | `[' exp `]' | `:' NAME funcargs | funcargs }
286+
// primaryexp -> prefixexp { `.' NAME | `[' exp `]' | TypeInstantiation | `:' NAME [TypeInstantiation] funcargs | funcargs }
287287
AstExpr* parsePrimaryExpr(bool asStatement);
288288

289289
// asexp -> simpleexp [`::' Type]
@@ -310,6 +310,14 @@ class Parser
310310
// stringinterp ::= <INTERP_BEGIN> exp {<INTERP_MID> exp} <INTERP_END>
311311
AstExpr* parseInterpString();
312312

313+
// TypeInstantiation ::= `<' `<' [TypeList] `>' `>'
314+
AstArray<AstTypeOrPack> parseTypeInstantiationExpr(
315+
CstTypeInstantiation* cstNodeOut = nullptr,
316+
Location* endLocationOut = nullptr
317+
);
318+
319+
AstExpr* parseExplicitTypeInstantiationExpr(Position start, AstExpr& basedOnExpr);
320+
313321
// Name
314322
std::optional<Name> parseNameOpt(const char* context = nullptr);
315323
Name parseName(const char* context = nullptr);

luau/Ast/src/Ast.cpp

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "Luau/Common.h"
55
#include "Luau/StringUtils.h"
66

7+
LUAU_FASTFLAG(LuauExplicitTypeExpressionInstantiation)
8+
79
namespace Luau
810
{
911

@@ -32,6 +34,19 @@ static void visitTypeList(AstVisitor* visitor, const AstTypeList& list)
3234
list.tailType->visit(visitor);
3335
}
3436

37+
static void visitTypeOrPackArray(AstVisitor* visitor, const AstArray<AstTypeOrPack>& arrayOfTypeOrPack)
38+
{
39+
LUAU_ASSERT(FFlag::LuauExplicitTypeExpressionInstantiation);
40+
41+
for (const AstTypeOrPack& param : arrayOfTypeOrPack)
42+
{
43+
if (param.type)
44+
param.type->visit(visitor);
45+
else
46+
param.typePack->visit(visitor);
47+
}
48+
}
49+
3550
AstAttr::AstAttr(const Location& location, Type type, AstArray<AstExpr*> args)
3651
: AstNode(ClassIndex(), location)
3752
, type(type)
@@ -210,13 +225,22 @@ void AstExprVarargs::visit(AstVisitor* visitor)
210225
visitor->visit(this);
211226
}
212227

213-
AstExprCall::AstExprCall(const Location& location, AstExpr* func, const AstArray<AstExpr*>& args, bool self, const Location& argLocation)
228+
AstExprCall::AstExprCall(
229+
const Location& location,
230+
AstExpr* func,
231+
const AstArray<AstExpr*>& args,
232+
bool self,
233+
const AstArray<AstTypeOrPack>& explicitTypes,
234+
const Location& argLocation
235+
)
214236
: AstExpr(ClassIndex(), location)
215237
, func(func)
238+
, typeArguments(explicitTypes)
216239
, args(args)
217240
, self(self)
218241
, argLocation(argLocation)
219242
{
243+
LUAU_ASSERT(FFlag::LuauExplicitTypeExpressionInstantiation || explicitTypes.size == 0);
220244
}
221245

222246
void AstExprCall::visit(AstVisitor* visitor)
@@ -522,6 +546,23 @@ void AstExprInterpString::visit(AstVisitor* visitor)
522546
}
523547
}
524548

549+
AstExprInstantiate::AstExprInstantiate(const Location& location, AstExpr* expr, AstArray<AstTypeOrPack> types)
550+
: AstExpr(ClassIndex(), location)
551+
, expr(expr)
552+
, typeArguments(types)
553+
{
554+
LUAU_ASSERT(FFlag::LuauExplicitTypeExpressionInstantiation);
555+
}
556+
557+
void AstExprInstantiate::visit(AstVisitor* visitor)
558+
{
559+
if (visitor->visit(this))
560+
{
561+
visitTypeOrPackArray(visitor, typeArguments);
562+
}
563+
}
564+
565+
525566
void AstExprError::visit(AstVisitor* visitor)
526567
{
527568
if (visitor->visit(this))
@@ -1056,12 +1097,19 @@ void AstTypeReference::visit(AstVisitor* visitor)
10561097
{
10571098
if (visitor->visit(this))
10581099
{
1059-
for (const AstTypeOrPack& param : parameters)
1100+
if (FFlag::LuauExplicitTypeExpressionInstantiation)
1101+
{
1102+
visitTypeOrPackArray(visitor, parameters);
1103+
}
1104+
else
10601105
{
1061-
if (param.type)
1062-
param.type->visit(visitor);
1063-
else
1064-
param.typePack->visit(visitor);
1106+
for (const AstTypeOrPack& param : parameters)
1107+
{
1108+
if (param.type)
1109+
param.type->visit(visitor);
1110+
else
1111+
param.typePack->visit(visitor);
1112+
}
10651113
}
10661114
}
10671115
}

luau/Ast/src/Cst.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ CstExprInterpString::CstExprInterpString(AstArray<AstArray<char>> sourceStrings,
7676
{
7777
}
7878

79+
CstExprExplicitTypeInstantiation::CstExprExplicitTypeInstantiation(CstTypeInstantiation instantiation)
80+
: CstNode(CstClassIndex())
81+
, instantiation(instantiation)
82+
{
83+
}
84+
7985
CstStatDo::CstStatDo(Position endPosition)
8086
: CstNode(CstClassIndex())
8187
, endPosition(endPosition)

0 commit comments

Comments
 (0)