Skip to content

Commit ec18806

Browse files
committed
Merge tag '0.697' into wip_merge
2 parents f9b1974 + 5836a9c commit ec18806

Some content is hidden

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

51 files changed

+1186
-375
lines changed
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/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/TypeFunction.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ struct TypeFunctionReductionResult
108108
std::optional<std::string> error;
109109
/// Messages printed out from user-defined type functions
110110
std::vector<std::string> messages;
111+
/// Some type function reduction rules may _create_ type functions (e.g.
112+
/// the numeric type functions can "distribute" over an inner union). If
113+
/// any type functions were created this way, we must add them here.
114+
std::vector<Ty> freshTypes;
111115
};
112116

113117
template<typename T>

Analysis/src/BuiltinTypeFunctions.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ LUAU_FASTFLAG(LuauExplicitSkipBoundTypes)
2929
LUAU_FASTFLAG(LuauNoMoreComparisonTypeFunctions)
3030
LUAU_FASTFLAGVARIABLE(LuauBuiltinTypeFunctionsArentGlobal)
3131
LUAU_FASTFLAG(LuauPassBindableGenericsByReference)
32+
LUAU_FASTFLAG(LuauEnqueueUnionsOfDistributedTypeFunctions)
3233

3334
namespace Luau
3435
{
@@ -122,7 +123,10 @@ std::optional<TypeFunctionReductionResult<TypeId>> tryDistributeTypeFunctionApp(
122123
if (ctx->solver)
123124
ctx->pushConstraint(ReduceConstraint{resultTy});
124125

125-
return {{resultTy, Reduction::MaybeOk, {}, {}}};
126+
if (FFlag::LuauEnqueueUnionsOfDistributedTypeFunctions)
127+
return {{resultTy, Reduction::MaybeOk, {}, {}, {}, {}, {resultTy}}};
128+
else
129+
return {{resultTy, Reduction::MaybeOk, {}, {}}};
126130
}
127131

128132
return std::nullopt;
@@ -2468,7 +2472,7 @@ static TypeFunctionReductionResult<TypeId> getmetatableHelper(TypeId targetTy, c
24682472
std::optional<TypeId> result = std::nullopt;
24692473
bool erroneous = true;
24702474

2471-
if (auto table = get<TableType>(targetTy))
2475+
if (get<TableType>(targetTy))
24722476
erroneous = false;
24732477

24742478
if (auto mt = get<MetatableType>(targetTy))

Analysis/src/ConstraintGenerator.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatFunction* f
15631563
sig.bodyScope->lvalueTypes[def] = sig.signature;
15641564
updateRValueRefinements(sig.bodyScope, def, sig.signature);
15651565
}
1566-
else if (AstExprIndexName* indexName = function->name->as<AstExprIndexName>())
1566+
else if (function->name->is<AstExprIndexName>())
15671567
{
15681568
updateRValueRefinements(sig.bodyScope, def, sig.signature);
15691569
}
@@ -1673,7 +1673,7 @@ ControlFlow ConstraintGenerator::visit(const ScopePtr& scope, AstStatFunction* f
16731673
{
16741674
visitLValue(scope, indexName, generalizedType);
16751675
}
1676-
else if (AstExprError* err = function->name->as<AstExprError>())
1676+
else if (function->name->is<AstExprError>())
16771677
{
16781678
generalizedType = builtinTypes->errorType;
16791679
}
@@ -2360,7 +2360,7 @@ InferencePack ConstraintGenerator::checkPack(
23602360

23612361
if (AstExprCall* call = expr->as<AstExprCall>())
23622362
result = checkPack(scope, call);
2363-
else if (AstExprVarargs* varargs = expr->as<AstExprVarargs>())
2363+
else if (expr->is<AstExprVarargs>())
23642364
{
23652365
if (scope->varargPack)
23662366
result = InferencePack{*scope->varargPack};

Analysis/src/ConstraintSolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ bool ConstraintSolver::tryDispatch(const TypeAliasExpansionConstraint& c, NotNul
12261226
}
12271227

12281228
// Adding ReduceConstraint on type function for the constraint solver
1229-
if (auto typeFn = get<TypeFunctionInstanceType>(follow(tf->type)))
1229+
if (get<TypeFunctionInstanceType>(follow(tf->type)))
12301230
pushConstraint(NotNull(constraint->scope.get()), constraint->location, ReduceConstraint{tf->type});
12311231

12321232
// Due to how pending expansion types and TypeFun's are created
@@ -3660,7 +3660,7 @@ bool ConstraintSolver::isBlocked(TypePackId tp) const
36603660
{
36613661
tp = follow(tp);
36623662

3663-
if (auto tfitp = get<TypeFunctionInstanceTypePack>(tp))
3663+
if (get<TypeFunctionInstanceTypePack>(tp))
36643664
return uninhabitedTypeFunctions.contains(tp) == false;
36653665

36663666
return nullptr != get<BlockedTypePack>(tp);

Analysis/src/DataFlowGraph.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ ControlFlow DataFlowGraphBuilder::visit(AstStatLocal* l)
574574
if (i < l->values.size)
575575
{
576576
AstExpr* e = l->values.data[i];
577-
if (const AstExprTable* tbl = e->as<AstExprTable>())
577+
if (e->is<AstExprTable>())
578578
{
579579
def = defs[i];
580580
}
@@ -1165,17 +1165,17 @@ void DataFlowGraphBuilder::visitType(AstType* t)
11651165
return visitType(f);
11661166
else if (auto tyof = t->as<AstTypeTypeof>())
11671167
return visitType(tyof);
1168-
else if (auto o = t->as<AstTypeOptional>())
1168+
else if (t->is<AstTypeOptional>())
11691169
return;
11701170
else if (auto u = t->as<AstTypeUnion>())
11711171
return visitType(u);
11721172
else if (auto i = t->as<AstTypeIntersection>())
11731173
return visitType(i);
11741174
else if (auto e = t->as<AstTypeError>())
11751175
return visitType(e);
1176-
else if (auto s = t->as<AstTypeSingletonBool>())
1176+
else if (t->is<AstTypeSingletonBool>())
11771177
return; // ok
1178-
else if (auto s = t->as<AstTypeSingletonString>())
1178+
else if (t->is<AstTypeSingletonString>())
11791179
return; // ok
11801180
else if (auto g = t->as<AstTypeGroup>())
11811181
return visitType(g->type);
@@ -1243,7 +1243,7 @@ void DataFlowGraphBuilder::visitTypePack(AstTypePack* p)
12431243
return visitTypePack(e);
12441244
else if (auto v = p->as<AstTypePackVariadic>())
12451245
return visitTypePack(v);
1246-
else if (auto g = p->as<AstTypePackGeneric>())
1246+
else if (p->is<AstTypePackGeneric>())
12471247
return; // ok
12481248
else
12491249
handle->ice("Unknown AstTypePack in DataFlowGraphBuilder::visitTypePack");

Analysis/src/EqSatSimplification.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ Id toId(
286286
// First, handle types which do not contain other types. They obviously
287287
// cannot participate in cycles, so we don't have to check for that.
288288

289-
if (auto freeTy = get<FreeType>(ty))
289+
if (get<FreeType>(ty))
290290
return egraph.add(TOpaque{ty});
291291
else if (get<GenericType>(ty))
292292
return egraph.add(TOpaque{ty});
@@ -765,7 +765,7 @@ TypeId fromId(
765765
return arena->addType(SingletonType{StringSingleton{strings.asString(s->value())}});
766766
else if (auto fun = node.get<TFunction>())
767767
return fun->value();
768-
else if (auto tbl = node.get<TTable>())
768+
else if (node.get<TTable>())
769769
{
770770
TypeId res = arena->addType(BlockedType{});
771771
seen[rootId] = res;
@@ -1310,7 +1310,7 @@ void unionWithType(EGraph& egraph, CanonicalizedType& ct, Id part)
13101310
if (!ct.functionPart)
13111311
ct.functionParts.insert(part);
13121312
}
1313-
else if (auto tclass = isTag<TClass>(egraph, part))
1313+
else if (isTag<TClass>(egraph, part))
13141314
unionClasses(egraph, ct.classParts, part);
13151315
else if (isTag<TAny>(egraph, part))
13161316
{
@@ -1415,7 +1415,7 @@ bool subtract(EGraph& egraph, CanonicalizedType& ct, Id part)
14151415
ct.tablePart.reset();
14161416
else if (etype->get<TTopClass>())
14171417
ct.classParts.clear();
1418-
else if (auto tclass = etype->get<TClass>())
1418+
else if (etype->get<TClass>())
14191419
{
14201420
auto it = std::find(ct.classParts.begin(), ct.classParts.end(), part);
14211421
if (it != ct.classParts.end())

Analysis/src/Error.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ struct ErrorConverter
697697
if (tfit->typeArguments.size() != 2)
698698
return "Type function instance " + Luau::toString(e.ty) + " is ill-formed, and thus invalid";
699699

700-
if (auto errType = get<ErrorType>(tfit->typeArguments[1])) // Second argument to (index | rawget)<_,_> is not a type
700+
if (get<ErrorType>(tfit->typeArguments[1])) // Second argument to (index | rawget)<_,_> is not a type
701701
return "Second argument to " + tfit->function->name + "<" + Luau::toString(tfit->typeArguments[0]) + ", _> is not a valid index type";
702702
else // Property `indexer` does not exist on type `indexee`
703703
return "Property '" + Luau::toString(tfit->typeArguments[1]) + "' does not exist on type '" + Luau::toString(tfit->typeArguments[0]) +
@@ -757,12 +757,8 @@ struct ErrorConverter
757757
std::string operator()(const CheckedFunctionCallError& e) const
758758
{
759759
// TODO: What happens if checkedFunctionName cannot be found??
760-
if (FFlag::LuauNewNonStrictReportsOneIndexedErrors)
761-
return "Function '" + e.checkedFunctionName + "' expects '" + toString(e.expected) + "' at argument #" +
762-
std::to_string(e.argumentIndex + 1) + ", but got '" + Luau::toString(e.passed) + "'";
763-
else
764-
return "Function '" + e.checkedFunctionName + "' expects '" + toString(e.expected) + "' at argument #" + std::to_string(e.argumentIndex) +
765-
", but got '" + Luau::toString(e.passed) + "'";
760+
return "Function '" + e.checkedFunctionName + "' expects '" + toString(e.expected) + "' at argument #" +
761+
std::to_string(e.argumentIndex + 1) + ", but got '" + Luau::toString(e.passed) + "'";
766762
}
767763

768764
std::string operator()(const NonStrictFunctionDefinitionError& e) const

Analysis/src/FragmentAutocomplete.cpp

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ LUAU_FASTINT(LuauTarjanChildLimit)
3333
LUAU_FASTFLAGVARIABLE(DebugLogFragmentsFromAutocomplete)
3434
LUAU_FASTFLAG(LuauUseWorkspacePropToChooseSolver)
3535
LUAU_FASTFLAGVARIABLE(LuauFragmentRequiresCanBeResolvedToAModule)
36-
LUAU_FASTFLAGVARIABLE(LuauPopulateSelfTypesInFragment)
37-
LUAU_FASTFLAGVARIABLE(LuauForInProvidesRecommendations)
3836
LUAU_FASTFLAGVARIABLE(LuauForInRangesConsiderInLocation)
3937

4038
namespace Luau
@@ -119,7 +117,7 @@ Location getFragmentLocation(AstStat* nearestStatement, const Position& cursorPo
119117
{
120118
Location nonEmpty{nearestStatement->location.begin, cursorPosition};
121119
// If your sibling is a do block, do nothing
122-
if (auto doEnd = nearestStatement->as<AstStatBlock>())
120+
if (nearestStatement->as<AstStatBlock>())
123121
return empty;
124122

125123
// If you're inside the body of the function and this is your sibling, empty fragment
@@ -156,27 +154,20 @@ Location getFragmentLocation(AstStat* nearestStatement, const Position& cursorPo
156154

157155
if (auto forStat = nearestStatement->as<AstStatFor>())
158156
{
159-
160-
if (FFlag::LuauForInProvidesRecommendations)
161-
{
162-
if (forStat->step && forStat->step->location.containsClosed(cursorPosition))
163-
return {forStat->step->location.begin, cursorPosition};
164-
if (forStat->to && forStat->to->location.containsClosed(cursorPosition))
165-
return {forStat->to->location.begin, cursorPosition};
166-
if (forStat->from && forStat->from->location.containsClosed(cursorPosition))
167-
return {forStat->from->location.begin, cursorPosition};
168-
}
157+
if (forStat->step && forStat->step->location.containsClosed(cursorPosition))
158+
return {forStat->step->location.begin, cursorPosition};
159+
if (forStat->to && forStat->to->location.containsClosed(cursorPosition))
160+
return {forStat->to->location.begin, cursorPosition};
161+
if (forStat->from && forStat->from->location.containsClosed(cursorPosition))
162+
return {forStat->from->location.begin, cursorPosition};
169163

170164
if (!forStat->hasDo)
171165
return nonEmpty;
172166
else
173167
{
174-
if (FFlag::LuauForInProvidesRecommendations)
175-
{
176168
auto completeableExtents = Location{forStat->location.begin, forStat->doLocation.begin};
177169
if (completeableExtents.containsClosed(cursorPosition))
178170
return nonEmpty;
179-
}
180171

181172
return empty;
182173
}
@@ -188,21 +179,18 @@ Location getFragmentLocation(AstStat* nearestStatement, const Position& cursorPo
188179
return nonEmpty;
189180
else
190181
{
191-
if (FFlag::LuauForInProvidesRecommendations)
182+
auto completeableExtents = Location{forIn->location.begin, forIn->doLocation.begin};
183+
if (completeableExtents.containsClosed(cursorPosition))
192184
{
193-
auto completeableExtents = Location{forIn->location.begin, forIn->doLocation.begin};
194-
if (completeableExtents.containsClosed(cursorPosition))
185+
if (!forIn->hasIn)
186+
return nonEmpty;
187+
else
195188
{
196-
if (!forIn->hasIn)
189+
// [for ... in ... do] - the cursor can either be between [for ... in] or [in ... do]
190+
if (FFlag::LuauForInRangesConsiderInLocation && cursorPosition < forIn->inLocation.begin)
197191
return nonEmpty;
198192
else
199-
{
200-
// [for ... in ... do] - the cursor can either be between [for ... in] or [in ... do]
201-
if (FFlag::LuauForInRangesConsiderInLocation && cursorPosition < forIn->inLocation.begin)
202-
return nonEmpty;
203-
else
204-
return Location{forIn->inLocation.begin, cursorPosition};
205-
}
193+
return Location{forIn->inLocation.begin, cursorPosition};
206194
}
207195
}
208196
return empty;
@@ -429,13 +417,10 @@ FragmentAutocompleteAncestryResult findAncestryForFragmentParse(AstStatBlock* st
429417
{
430418
if (globFun->location.contains(cursorPos))
431419
{
432-
if (FFlag::LuauPopulateSelfTypesInFragment)
420+
if (auto local = globFun->func->self)
433421
{
434-
if (auto local = globFun->func->self)
435-
{
436-
localStack.push_back(local);
437-
localMap[local->name] = local;
438-
}
422+
localStack.push_back(local);
423+
localMap[local->name] = local;
439424
}
440425

441426
for (AstLocal* loc : globFun->func->args)

0 commit comments

Comments
 (0)