Skip to content

Commit b70db0f

Browse files
committed
v0.10.0+luau629
1 parent a5b5504 commit b70db0f

Some content is hidden

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

62 files changed

+2038
-1269
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "luau0-src"
3-
version = "0.9.1+luau625"
3+
version = "0.10.0+luau629"
44
authors = ["Aleksandr Orlenko <[email protected]>"]
55
edition = "2021"
66
repository = "https://github.com/khvzak/luau-src-rs"

luau/Ast/include/Luau/Ast.h

+50-10
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class AstStat;
6060
class AstStatBlock;
6161
class AstExpr;
6262
class AstTypePack;
63+
class AstAttr;
64+
class AstExprTable;
6365

6466
struct AstLocal
6567
{
@@ -172,6 +174,10 @@ class AstNode
172174
{
173175
return nullptr;
174176
}
177+
virtual AstAttr* asAttr()
178+
{
179+
return nullptr;
180+
}
175181

176182
template<typename T>
177183
bool is() const
@@ -193,6 +199,28 @@ class AstNode
193199
Location location;
194200
};
195201

202+
class AstAttr : public AstNode
203+
{
204+
public:
205+
LUAU_RTTI(AstAttr)
206+
207+
enum Type
208+
{
209+
Checked,
210+
};
211+
212+
AstAttr(const Location& location, Type type);
213+
214+
AstAttr* asAttr() override
215+
{
216+
return this;
217+
}
218+
219+
void visit(AstVisitor* visitor) override;
220+
221+
Type type;
222+
};
223+
196224
class AstExpr : public AstNode
197225
{
198226
public:
@@ -384,13 +412,15 @@ class AstExprFunction : public AstExpr
384412
public:
385413
LUAU_RTTI(AstExprFunction)
386414

387-
AstExprFunction(const Location& location, const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks,
388-
AstLocal* self, const AstArray<AstLocal*>& args, bool vararg, const Location& varargLocation, AstStatBlock* body, size_t functionDepth,
389-
const AstName& debugname, const std::optional<AstTypeList>& returnAnnotation = {}, AstTypePack* varargAnnotation = nullptr,
415+
AstExprFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstArray<AstGenericType>& generics,
416+
const AstArray<AstGenericTypePack>& genericPacks, AstLocal* self, const AstArray<AstLocal*>& args, bool vararg,
417+
const Location& varargLocation, AstStatBlock* body, size_t functionDepth, const AstName& debugname,
418+
const std::optional<AstTypeList>& returnAnnotation = {}, AstTypePack* varargAnnotation = nullptr,
390419
const std::optional<Location>& argLocation = std::nullopt);
391420

392421
void visit(AstVisitor* visitor) override;
393422

423+
AstArray<AstAttr*> attributes;
394424
AstArray<AstGenericType> generics;
395425
AstArray<AstGenericTypePack> genericPacks;
396426
AstLocal* self;
@@ -810,20 +840,22 @@ class AstStatDeclareFunction : public AstStat
810840
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params, const AstArray<AstArgumentName>& paramNames,
811841
const AstTypeList& retTypes);
812842

813-
AstStatDeclareFunction(const Location& location, const AstName& name, const AstArray<AstGenericType>& generics,
814-
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params, const AstArray<AstArgumentName>& paramNames,
815-
const AstTypeList& retTypes, bool checkedFunction);
843+
AstStatDeclareFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstName& name,
844+
const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& params,
845+
const AstArray<AstArgumentName>& paramNames, const AstTypeList& retTypes);
816846

817847

818848
void visit(AstVisitor* visitor) override;
819849

850+
bool isCheckedFunction() const;
851+
852+
AstArray<AstAttr*> attributes;
820853
AstName name;
821854
AstArray<AstGenericType> generics;
822855
AstArray<AstGenericTypePack> genericPacks;
823856
AstTypeList params;
824857
AstArray<AstArgumentName> paramNames;
825858
AstTypeList retTypes;
826-
bool checkedFunction;
827859
};
828860

829861
struct AstDeclaredClassProp
@@ -936,17 +968,20 @@ class AstTypeFunction : public AstType
936968
AstTypeFunction(const Location& location, const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks,
937969
const AstTypeList& argTypes, const AstArray<std::optional<AstArgumentName>>& argNames, const AstTypeList& returnTypes);
938970

939-
AstTypeFunction(const Location& location, const AstArray<AstGenericType>& generics, const AstArray<AstGenericTypePack>& genericPacks,
940-
const AstTypeList& argTypes, const AstArray<std::optional<AstArgumentName>>& argNames, const AstTypeList& returnTypes, bool checkedFunction);
971+
AstTypeFunction(const Location& location, const AstArray<AstAttr*>& attributes, const AstArray<AstGenericType>& generics,
972+
const AstArray<AstGenericTypePack>& genericPacks, const AstTypeList& argTypes, const AstArray<std::optional<AstArgumentName>>& argNames,
973+
const AstTypeList& returnTypes);
941974

942975
void visit(AstVisitor* visitor) override;
943976

977+
bool isCheckedFunction() const;
978+
979+
AstArray<AstAttr*> attributes;
944980
AstArray<AstGenericType> generics;
945981
AstArray<AstGenericTypePack> genericPacks;
946982
AstTypeList argTypes;
947983
AstArray<std::optional<AstArgumentName>> argNames;
948984
AstTypeList returnTypes;
949-
bool checkedFunction;
950985
};
951986

952987
class AstTypeTypeof : public AstType
@@ -1105,6 +1140,11 @@ class AstVisitor
11051140
return true;
11061141
}
11071142

1143+
virtual bool visit(class AstAttr* node)
1144+
{
1145+
return visit(static_cast<AstNode*>(node));
1146+
}
1147+
11081148
virtual bool visit(class AstExpr* node)
11091149
{
11101150
return visit(static_cast<AstNode*>(node));

luau/Ast/include/Luau/Lexer.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ struct Lexeme
8787
Comment,
8888
BlockComment,
8989

90+
Attribute,
91+
9092
BrokenString,
9193
BrokenComment,
9294
BrokenUnicode,
@@ -115,14 +117,20 @@ struct Lexeme
115117
ReservedTrue,
116118
ReservedUntil,
117119
ReservedWhile,
118-
ReservedChecked,
119120
Reserved_END
120121
};
121122

122123
Type type;
123124
Location location;
125+
126+
// Field declared here, before the union, to ensure that Lexeme size is 32 bytes.
127+
private:
128+
// length is used to extract a slice from the input buffer.
129+
// This field is only valid for certain lexeme types which don't duplicate portions of input
130+
// but instead store a pointer to a location in the input buffer and the length of lexeme.
124131
unsigned int length;
125132

133+
public:
126134
union
127135
{
128136
const char* data; // String, Number, Comment
@@ -135,9 +143,13 @@ struct Lexeme
135143
Lexeme(const Location& location, Type type, const char* data, size_t size);
136144
Lexeme(const Location& location, Type type, const char* name);
137145

146+
unsigned int getLength() const;
147+
138148
std::string toString() const;
139149
};
140150

151+
static_assert(sizeof(Lexeme) <= 32, "Size of `Lexeme` struct should be up to 32 bytes.");
152+
141153
class AstNameTable
142154
{
143155
public:

luau/Ast/include/Luau/Parser.h

+25-10
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ class Parser
8282
// if exp then block {elseif exp then block} [else block] end |
8383
// for Name `=' exp `,' exp [`,' exp] do block end |
8484
// for namelist in explist do block end |
85-
// function funcname funcbody |
86-
// local function Name funcbody |
85+
// [attributes] function funcname funcbody |
86+
// [attributes] local function Name funcbody |
8787
// local namelist [`=' explist]
8888
// laststat ::= return [explist] | break
8989
AstStat* parseStat();
@@ -114,11 +114,25 @@ class Parser
114114
AstExpr* parseFunctionName(Location start, bool& hasself, AstName& debugname);
115115

116116
// function funcname funcbody
117-
AstStat* parseFunctionStat();
117+
LUAU_FORCEINLINE AstStat* parseFunctionStat(const AstArray<AstAttr*>& attributes = {nullptr, 0});
118+
119+
std::pair<bool, AstAttr::Type> validateAttribute(const char* attributeName, const TempVector<AstAttr*>& attributes);
120+
121+
// attribute ::= '@' NAME
122+
void parseAttribute(TempVector<AstAttr*>& attribute);
123+
124+
// attributes ::= {attribute}
125+
AstArray<AstAttr*> parseAttributes();
126+
127+
// attributes local function Name funcbody
128+
// attributes function funcname funcbody
129+
// attributes `declare function' Name`(' [parlist] `)' [`:` Type]
130+
// declare Name '{' Name ':' attributes `(' [parlist] `)' [`:` Type] '}'
131+
AstStat* parseAttributeStat();
118132

119133
// local function Name funcbody |
120134
// local namelist [`=' explist]
121-
AstStat* parseLocal();
135+
AstStat* parseLocal(const AstArray<AstAttr*>& attributes);
122136

123137
// return [explist]
124138
AstStat* parseReturn();
@@ -130,7 +144,7 @@ class Parser
130144

131145
// `declare global' Name: Type |
132146
// `declare function' Name`(' [parlist] `)' [`:` Type]
133-
AstStat* parseDeclaration(const Location& start);
147+
AstStat* parseDeclaration(const Location& start, const AstArray<AstAttr*>& attributes);
134148

135149
// varlist `=' explist
136150
AstStat* parseAssignment(AstExpr* initial);
@@ -143,7 +157,7 @@ class Parser
143157
// funcbodyhead ::= `(' [namelist [`,' `...'] | `...'] `)' [`:` Type]
144158
// funcbody ::= funcbodyhead block end
145159
std::pair<AstExprFunction*, AstLocal*> parseFunctionBody(
146-
bool hasself, const Lexeme& matchFunction, const AstName& debugname, const Name* localName);
160+
bool hasself, const Lexeme& matchFunction, const AstName& debugname, const Name* localName, const AstArray<AstAttr*>& attributes);
147161

148162
// explist ::= {exp `,'} exp
149163
void parseExprList(TempVector<AstExpr*>& result);
@@ -176,10 +190,10 @@ class Parser
176190

177191
AstTableIndexer* parseTableIndexer(AstTableAccess access, std::optional<Location> accessLocation);
178192

179-
AstTypeOrPack parseFunctionType(bool allowPack, bool isCheckedFunction = false);
180-
AstType* parseFunctionTypeTail(const Lexeme& begin, AstArray<AstGenericType> generics, AstArray<AstGenericTypePack> genericPacks,
181-
AstArray<AstType*> params, AstArray<std::optional<AstArgumentName>> paramNames, AstTypePack* varargAnnotation,
182-
bool isCheckedFunction = false);
193+
AstTypeOrPack parseFunctionType(bool allowPack, const AstArray<AstAttr*>& attributes);
194+
AstType* parseFunctionTypeTail(const Lexeme& begin, const AstArray<AstAttr*>& attributes, AstArray<AstGenericType> generics,
195+
AstArray<AstGenericTypePack> genericPacks, AstArray<AstType*> params, AstArray<std::optional<AstArgumentName>> paramNames,
196+
AstTypePack* varargAnnotation);
183197

184198
AstType* parseTableType(bool inDeclarationContext = false);
185199
AstTypeOrPack parseSimpleType(bool allowPack, bool inDeclarationContext = false);
@@ -393,6 +407,7 @@ class Parser
393407

394408
std::vector<unsigned int> matchRecoveryStopOnToken;
395409

410+
std::vector<AstAttr*> scratchAttr;
396411
std::vector<AstStat*> scratchStat;
397412
std::vector<AstArray<char>> scratchString;
398413
std::vector<AstExpr*> scratchExpr;

0 commit comments

Comments
 (0)