Skip to content

Commit 39d5414

Browse files
authored
Merge pull request #10 from secondlife/wip_merge
Merge Luau 0.698
2 parents 9a6536a + 42b3995 commit 39d5414

File tree

238 files changed

+10248
-5540
lines changed

Some content is hidden

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

238 files changed

+10248
-5540
lines changed

Analysis/include/Luau/AstUtils.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ namespace Luau
1313
// uniquely held references. Append these types to 'uniqueTypes'.
1414
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstExpr* expr, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
1515

16-
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstArray<AstExpr*> exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
17-
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, const std::vector<AstExpr*>& exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
16+
void findUniqueTypes(
17+
NotNull<DenseHashSet<TypeId>> uniqueTypes,
18+
AstArray<AstExpr*> exprs,
19+
NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes
20+
);
21+
void findUniqueTypes(
22+
NotNull<DenseHashSet<TypeId>> uniqueTypes,
23+
const std::vector<AstExpr*>& exprs,
24+
NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes
25+
);
1826

19-
}
27+
} // namespace Luau

Analysis/include/Luau/BuiltinDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ TypeId getGlobalBinding(GlobalTypes& globals, const std::string& name);
8888
bool matchSetMetatable(const AstExprCall& call);
8989
bool matchTableFreeze(const AstExprCall& call);
9090
bool matchAssert(const AstExprCall& call);
91+
bool matchTypeOf(const AstExprCall& call);
9192

9293
// Returns `true` if the function should introduce typestate for its first argument.
9394
bool shouldTypestateForFirstArgument(const AstExprCall& call);

Analysis/include/Luau/BuiltinTypeFunctions.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ namespace Luau
99
struct BuiltinTypeFunctions
1010
{
1111
BuiltinTypeFunctions();
12+
BuiltinTypeFunctions(const BuiltinTypeFunctions&) = delete;
13+
void operator=(const BuiltinTypeFunctions&) = delete;
1214

1315
TypeFunction userFunc;
1416

@@ -51,6 +53,6 @@ struct BuiltinTypeFunctions
5153
void addToScope(NotNull<TypeArena> arena, NotNull<Scope> scope) const;
5254
};
5355

54-
const BuiltinTypeFunctions& builtinTypeFunctions();
56+
const BuiltinTypeFunctions& builtinTypeFunctions_DEPRECATED();
5557

5658
} // namespace Luau

Analysis/include/Luau/ConstraintSolver.h

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,6 @@ struct ConstraintSolver
218218

219219
void generalizeOneType(TypeId ty);
220220

221-
/**
222-
* Bind a type variable to another type.
223-
*
224-
* A constraint is required and will validate that blockedTy is owned by this
225-
* constraint. This prevents one constraint from interfering with another's
226-
* blocked types.
227-
*
228-
* Bind will also unblock the type variable for you.
229-
*/
230-
void bind(NotNull<const Constraint> constraint, TypeId ty, TypeId boundTo);
231-
void bind(NotNull<const Constraint> constraint, TypePackId tp, TypePackId boundTo);
232-
233221
template<typename T, typename... Args>
234222
void emplace(NotNull<const Constraint> constraint, TypeId ty, Args&&... args);
235223

@@ -300,7 +288,7 @@ struct ConstraintSolver
300288
ValueContext context,
301289
bool inConditional,
302290
bool suppressSimplification,
303-
DenseHashSet<TypeId>& seen
291+
Set<TypeId>& seen
304292
);
305293

306294
/**
@@ -404,6 +392,18 @@ struct ConstraintSolver
404392
*/
405393
void shiftReferences(TypeId source, TypeId target);
406394

395+
/**
396+
* Bind a type variable to another type.
397+
*
398+
* A constraint is required and will validate that blockedTy is owned by this
399+
* constraint. This prevents one constraint from interfering with another's
400+
* blocked types.
401+
*
402+
* Bind will also unblock the type variable for you.
403+
*/
404+
void bind(NotNull<const Constraint> constraint, TypeId ty, TypeId boundTo);
405+
void bind(NotNull<const Constraint> constraint, TypePackId tp, TypePackId boundTo);
406+
407407
/**
408408
* Generalizes the given free type if the reference counting allows it.
409409
* @param the scope to generalize in
@@ -462,7 +462,12 @@ struct ConstraintSolver
462462
void reproduceConstraints(NotNull<Scope> scope, const Location& location, const Substitution& subst);
463463

464464
TypeId simplifyIntersection(NotNull<Scope> scope, Location location, TypeId left, TypeId right);
465-
TypeId simplifyIntersection(NotNull<Scope> scope, Location location, std::set<TypeId> parts);
465+
466+
// Clip with LuauSimplifyIntersectionNoTreeSet
467+
TypeId simplifyIntersection_DEPRECATED(NotNull<Scope> scope, Location location, std::set<TypeId> parts);
468+
469+
TypeId simplifyIntersection(NotNull<Scope> scope, Location location, TypeIds parts);
470+
466471
TypeId simplifyUnion(NotNull<Scope> scope, Location location, TypeId left, TypeId right);
467472

468473
TypePackId anyifyModuleReturnTypePackGenerics(TypePackId tp);

Analysis/include/Luau/Frontend.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,19 @@ struct Frontend
225225
);
226226

227227
// Batch module checking. Queue modules and check them together, retrieve results with 'getCheckResult'
228-
// If provided, 'executeTask' function is allowed to call the 'task' function on any thread and return without waiting for 'task' to complete
228+
// If provided, 'executeTasks' function is allowed to call any item in 'tasks' on any thread and return without waiting for them to complete
229229
void queueModuleCheck(const std::vector<ModuleName>& names);
230230
void queueModuleCheck(const ModuleName& name);
231-
std::vector<ModuleName> checkQueuedModules(
231+
std::vector<ModuleName> checkQueuedModules_DEPRECATED(
232232
std::optional<FrontendOptions> optionOverride = {},
233233
std::function<void(std::function<void()> task)> executeTask = {},
234234
std::function<bool(size_t done, size_t total)> progress = {}
235235
);
236+
std::vector<ModuleName> checkQueuedModules(
237+
std::optional<FrontendOptions> optionOverride = {},
238+
std::function<void(std::vector<std::function<void()>> tasks)> executeTasks = {},
239+
std::function<bool(size_t done, size_t total)> progress = {}
240+
);
236241

237242
std::optional<CheckResult> getCheckResult(const ModuleName& name, bool accumulateNested, bool forAutocomplete = false);
238243
std::vector<ModuleName> getRequiredScripts(const ModuleName& name);
@@ -270,7 +275,8 @@ struct Frontend
270275
void checkBuildQueueItems(std::vector<BuildQueueItem>& items);
271276
void recordItemResult(const BuildQueueItem& item);
272277
void performQueueItemTask(std::shared_ptr<BuildQueueWorkState> state, size_t itemPos);
273-
void sendQueueItemTask(std::shared_ptr<BuildQueueWorkState> state, size_t itemPos);
278+
void sendQueueItemTask_DEPRECATED(std::shared_ptr<BuildQueueWorkState> state, size_t itemPos);
279+
void sendQueueItemTasks(std::shared_ptr<BuildQueueWorkState> state, const std::vector<size_t>& items);
274280
void sendQueueCycleItemTask(std::shared_ptr<BuildQueueWorkState> state);
275281

276282
static LintResult classifyLints(const std::vector<LintWarning>& warnings, const Config& config);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
2+
#pragma once
3+
4+
#include <stdint.h>
5+
6+
namespace Luau
7+
{
8+
9+
struct NativeStackGuard
10+
{
11+
NativeStackGuard();
12+
13+
// Returns true if we are not dangerously close to overrunning the C stack.
14+
bool isOk() const;
15+
16+
private:
17+
uintptr_t high;
18+
uintptr_t low;
19+
};
20+
21+
}
22+
23+
namespace Luau
24+
{
25+
26+
uintptr_t getStackAddressSpaceSize();
27+
28+
}

Analysis/include/Luau/Normalize.h

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ enum class NormalizationResult
202202
// * G is a union of generic/free/blocked types, intersected with a normalized type
203203
struct NormalizedType
204204
{
205+
NotNull<BuiltinTypes> builtinTypes;
206+
205207
// The top part of the type.
206208
// This type is either never, unknown, or any.
207209
// If this type is not never, all the other fields are null.
@@ -315,6 +317,8 @@ class Normalizer
315317
DenseHashMap<TypeId, bool> cachedIsInhabited{nullptr};
316318
DenseHashMap<std::pair<TypeId, TypeId>, bool, TypeIdPairHash> cachedIsInhabitedIntersection{{nullptr, nullptr}};
317319

320+
std::optional<int> fuel{std::nullopt};
321+
318322
bool withinResourceLimits();
319323
bool useNewLuauSolver() const;
320324

@@ -340,13 +344,29 @@ class Normalizer
340344

341345
// If this returns null, the typechecker should emit a "too complex" error
342346
std::shared_ptr<const NormalizedType> normalize(TypeId ty);
343-
void clearNormal(NormalizedType& norm);
344347

348+
void clearCaches();
349+
350+
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right);
351+
352+
// Check for inhabitance
353+
NormalizationResult isInhabited(TypeId ty);
354+
NormalizationResult isInhabited(const NormalizedType* norm);
355+
356+
// -------- Convert back from a normalized type to a type
357+
TypeId typeFromNormal(const NormalizedType& norm);
358+
359+
std::optional<TypePackId> intersectionOfTypePacks(TypePackId here, TypePackId there);
360+
361+
// Move to private with LuauNormalizerStepwiseFuel
362+
std::optional<TypePackId> intersectionOfTypePacks_INTERNAL(TypePackId here, TypePackId there);
363+
364+
private:
345365
// ------- Cached TypeIds
346366
TypeId unionType(TypeId here, TypeId there);
347367
TypeId intersectionType(TypeId here, TypeId there);
348368
const TypeIds* cacheTypeIds(TypeIds tys);
349-
void clearCaches();
369+
void clearNormal(NormalizedType& norm);
350370

351371
// ------- Normalizing unions
352372
void unionTysWithTy(TypeIds& here, TypeId there);
@@ -387,7 +407,6 @@ class Normalizer
387407
void intersectExternTypes(NormalizedExternType& heres, const NormalizedExternType& theres);
388408
void intersectExternTypesWithExternType(NormalizedExternType& heres, TypeId there);
389409
void intersectStrings(NormalizedStringType& here, const NormalizedStringType& there);
390-
std::optional<TypePackId> intersectionOfTypePacks(TypePackId here, TypePackId there);
391410
std::optional<TypeId> intersectionOfTables(TypeId here, TypeId there, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSet);
392411
void intersectTablesWithTable(TypeIds& heres, TypeId there, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSetTypes);
393412
void intersectTables(TypeIds& heres, const TypeIds& theres);
@@ -409,18 +428,20 @@ class Normalizer
409428
Set<TypeId>& seenSet
410429
);
411430

412-
// Check for inhabitance
413-
NormalizationResult isInhabited(TypeId ty);
414431
NormalizationResult isInhabited(TypeId ty, Set<TypeId>& seen);
415-
NormalizationResult isInhabited(const NormalizedType* norm);
416432
NormalizationResult isInhabited(const NormalizedType* norm, Set<TypeId>& seen);
417433

418434
// Check for intersections being inhabited
419-
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right);
420435
NormalizationResult isIntersectionInhabited(TypeId left, TypeId right, SeenTablePropPairs& seenTablePropPairs, Set<TypeId>& seenSet);
421436

422-
// -------- Convert back from a normalized type to a type
423-
TypeId typeFromNormal(const NormalizedType& norm);
437+
438+
// Fuel setup
439+
440+
bool initializeFuel();
441+
void clearFuel();
442+
void consumeFuel();
443+
444+
friend struct FuelInitializer;
424445
};
425446

426447
} // namespace Luau

Analysis/include/Luau/OverloadResolution.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ struct OverloadResolver
107107
std::optional<TypeId> failedSubTy,
108108
std::optional<TypeId> failedSuperTy
109109
) const;
110+
111+
// Checks if the candidate args are arity-compatible with the desired parameters.
112+
// Used during overload selection to do arity-based filtering of overloads.
113+
// We do not accept nil in place of a generic unless that generic is explicitly optional.
114+
bool isArityCompatible(TypePackId candidate, TypePackId desired, NotNull<BuiltinTypes> builtinTypes) const;
115+
116+
bool testFunctionTypeForOverloadSelection(
117+
const FunctionType* ftv,
118+
NotNull<DenseHashSet<TypeId>> uniqueTypes,
119+
TypePackId argsPack,
120+
bool useFreeTypeBounds
121+
);
110122
};
111123

112124
struct SolveResult

Analysis/include/Luau/RecursionCounter.h

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "Luau/Common.h"
55
#include "Luau/Error.h"
6+
#include "Luau/NativeStackGuard.h"
67

78
#include <stdexcept>
89
#include <exception>
@@ -12,40 +13,28 @@ namespace Luau
1213

1314
struct RecursionLimitException : public InternalCompilerError
1415
{
15-
RecursionLimitException(const std::string system)
16-
: InternalCompilerError("Internal recursion counter limit exceeded in " + system)
17-
{
18-
}
16+
explicit RecursionLimitException(const std::string& system);
1917
};
2018

2119
struct RecursionCounter
2220
{
23-
RecursionCounter(int* count)
24-
: count(count)
25-
{
26-
++(*count);
27-
}
28-
29-
~RecursionCounter()
30-
{
31-
LUAU_ASSERT(*count > 0);
32-
--(*count);
33-
}
21+
explicit RecursionCounter(int* count);
22+
~RecursionCounter();
23+
24+
RecursionCounter(const RecursionCounter&) = delete;
25+
RecursionCounter& operator=(const RecursionCounter&) = delete;
26+
RecursionCounter(RecursionCounter&&) = delete;
27+
RecursionCounter& operator=(RecursionCounter&&) = delete;
3428

3529
protected:
3630
int* count;
3731
};
3832

3933
struct RecursionLimiter : RecursionCounter
4034
{
41-
RecursionLimiter(const std::string system, int* count, int limit)
42-
: RecursionCounter(count)
43-
{
44-
if (limit > 0 && *count > limit)
45-
{
46-
throw RecursionLimitException(system);
47-
}
48-
}
35+
NativeStackGuard nativeStackGuard;
36+
37+
RecursionLimiter(const std::string& system, int* count, int limit);
4938
};
5039

5140
} // namespace Luau

Analysis/include/Luau/Simplify.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Luau/DenseHash.h"
66
#include "Luau/NotNull.h"
77
#include "Luau/TypeFwd.h"
8+
#include "Luau/TypeIds.h"
89

910
#include <optional>
1011
#include <set>
@@ -22,7 +23,11 @@ struct SimplifyResult
2223
};
2324

2425
SimplifyResult simplifyIntersection(NotNull<BuiltinTypes> builtinTypes, NotNull<TypeArena> arena, TypeId left, TypeId right);
25-
SimplifyResult simplifyIntersection(NotNull<BuiltinTypes> builtinTypes, NotNull<TypeArena> arena, std::set<TypeId> parts);
26+
27+
// Clip with LuauSimplifyIntersectionNoTreeSet
28+
SimplifyResult simplifyIntersection_DEPRECATED(NotNull<BuiltinTypes> builtinTypes, NotNull<TypeArena> arena, std::set<TypeId> parts);
29+
30+
SimplifyResult simplifyIntersection(NotNull<BuiltinTypes> builtinTypes, NotNull<TypeArena> arena, TypeIds parts);
2631

2732
SimplifyResult simplifyUnion(NotNull<BuiltinTypes> builtinTypes, NotNull<TypeArena> arena, TypeId left, TypeId right);
2833

0 commit comments

Comments
 (0)