Skip to content

Commit 231a59c

Browse files
SPYvegorov-rbxaatxeandyfriesenhgoldstein
authored
Sync to upstream/release/718 (luau-lang#2359)
It is new Friday and new Luau release! This release is mostly focused on improving integer support in Luau VM: - NCG integer lowerings for x64 and Arm64 were added by @tommyscholly (HUGE!) - FASTCALL2K support for integers and other integer fastcall fixes - Test coverage for integers was improved Also: - BytecodeGraph representation is introduced for coming Bytecode -> Bytecode inliner and optimizer - Improved type alias resolution - Fix for constraints resolution of MetatableTypes in LValue position Co-authored-by: Andy Friesen [afriesen@roblox.com](mailto:afriesen@roblox.com) Co-authored-by: Ilya Rezvov [irezvov@roblox.com](mailto:irezvov@roblox.com) Co-authored-by: Thomas Schollenberger [tschollenberger@roblox.com](mailto:tschollenberger@roblox.com) Co-authored-by: Vyacheslav Egorov [vegorov@roblox.com](mailto:vegorov@roblox.com) --------- Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> Co-authored-by: Ariel Weiss <arielweiss@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Hunter Goldstein <hgoldstein@roblox.com> Co-authored-by: Varun Saini <61795485+vrn-sn@users.noreply.github.com> Co-authored-by: Sora Kanosue <skanosue@roblox.com> Co-authored-by: Annie Tang <annietang@roblox.com> Co-authored-by: Annie Tang <98965493+annieetang@users.noreply.github.com>
1 parent 6f2978e commit 231a59c

71 files changed

Lines changed: 9417 additions & 520 deletions

Some content is hidden

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

Analysis/src/BuiltinTypeFunctions.cpp

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ LUAU_FASTFLAG(LuauOverloadGetsInstantiated2)
2424
LUAU_FASTFLAGVARIABLE(LuauTypeFunctionsCaptureNestedInstances)
2525
LUAU_FASTFLAGVARIABLE(LuauTypeFunctionsAddFreeTypePackWithPositivePolarity)
2626
LUAU_FASTFLAGVARIABLE(LuauThreadUniferStateThroughTypeFunctionReduction)
27+
LUAU_FASTFLAGVARIABLE(LuauConcatDoesntAlwaysReturnString)
2728

2829
namespace Luau
2930
{
@@ -698,10 +699,26 @@ TypeFunctionReductionResult<TypeId> concatTypeFunction(
698699
else
699700
inferredArgs = {rhsTy, lhsTy};
700701

701-
if (!solveFunctionCall(ctx, ctx->constraint ? ctx->constraint->location : Location{}, *mmType, ctx->arena->addTypePack(std::move(inferredArgs))))
702-
return {std::nullopt, Reduction::Erroneous, {}, {}};
702+
if (FFlag::LuauConcatDoesntAlwaysReturnString)
703+
{
704+
std::optional<TypePackId> retPack =
705+
solveFunctionCall(ctx, ctx->constraint ? ctx->constraint->location : Location{}, *mmType, ctx->arena->addTypePack(std::move(inferredArgs)));
706+
if (!retPack)
707+
return {std::nullopt, Reduction::Erroneous, {}, {}};
708+
709+
TypePack extracted = extendTypePack(*ctx->arena, ctx->builtins, *retPack, 1);
710+
if (extracted.head.empty())
711+
return {std::nullopt, Reduction::Erroneous, {}, {}};
703712

704-
return {ctx->builtins->stringType, Reduction::MaybeOk, {}, {}};
713+
return {extracted.head.front(), Reduction::MaybeOk, {}, {}};
714+
}
715+
else
716+
{
717+
if (!solveFunctionCall(ctx, ctx->constraint ? ctx->constraint->location : Location{}, *mmType, ctx->arena->addTypePack(std::move(inferredArgs))))
718+
return {std::nullopt, Reduction::Erroneous, {}, {}};
719+
720+
return {ctx->builtins->stringType, Reduction::MaybeOk, {}, {}};
721+
}
705722
}
706723

707724
namespace

Analysis/src/ConstraintSolver.cpp

Lines changed: 34 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ LUAU_FASTFLAGVARIABLE(DebugLuauLogSolver)
4343
LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverIncludeDependencies)
4444
LUAU_FASTFLAGVARIABLE(DebugLuauLogBindings)
4545
LUAU_FASTFLAG(LuauExplicitTypeInstantiationSupport)
46-
LUAU_FASTFLAGVARIABLE(LuauUnifyWithSubtyping2)
4746
LUAU_FASTFLAG(LuauRelateHandlesCoincidentTables)
4847
LUAU_FASTFLAG(LuauUnpackRespectsAnnotations)
4948
LUAU_FASTFLAG(LuauReplacerRespectsReboundGenerics)
5049
LUAU_FASTFLAGVARIABLE(LuauOverloadGetsInstantiated2)
5150
LUAU_FASTFLAGVARIABLE(LuauFollowInExplicitInstantiation)
5251
LUAU_FASTFLAGVARIABLE(LuauUseConstraintSetsToTrackFreeTypes)
52+
LUAU_FASTFLAGVARIABLE(LuauFixPropReadsOnMetatableTypes)
5353

5454
namespace Luau
5555
{
@@ -1712,7 +1712,7 @@ bool ConstraintSolver::tryDispatch(const FunctionCallConstraint& c, NotNull<cons
17121712
if (auto ft = get<FreeType>(ty))
17131713
hasBound |= !is<NeverType>(follow(ft->lowerBound)) || !is<UnknownType>(follow(ft->upperBound));
17141714

1715-
// If we have generics we can bind *and*
1715+
// If we have generics we can bind *and*
17161716
if (auto overloadAsFn = get<FunctionType>(overloadToUse); overloadAsFn && hasBound)
17171717
{
17181718
CloneState cs{builtinTypes};
@@ -3438,6 +3438,11 @@ TablePropLookupResult ConstraintSolver::lookupTableProp(
34383438
if (inConditional)
34393439
return {{}, builtinTypes->unknownType};
34403440
}
3441+
else if (auto mt = get<MetatableType>(subjectType); FFlag::LuauFixPropReadsOnMetatableTypes && mt && context == ValueContext::LValue)
3442+
{
3443+
// TODO __newindex: CLI-199848
3444+
return lookupTableProp(constraint, mt->table, propName, context, inConditional, suppressSimplification, seen);
3445+
}
34413446
else if (auto mt = get<MetatableType>(subjectType); mt && context == ValueContext::RValue)
34423447
{
34433448
auto result = lookupTableProp(constraint, mt->table, propName, context, inConditional, suppressSimplification, seen);
@@ -3624,83 +3629,40 @@ template<typename TID>
36243629
bool ConstraintSolver::unify(NotNull<const Constraint> constraint, TID subTy, TID superTy)
36253630
{
36263631
static_assert(std::is_same_v<TID, TypeId> || std::is_same_v<TID, TypePackId>);
3632+
Subtyping subtyping{builtinTypes, arena, normalizer, typeFunctionRuntime, NotNull{&iceReporter}};
3633+
SubtypingUnifier stu{arena, builtinTypes, NotNull{&iceReporter}};
3634+
SubtypingResult result;
3635+
if constexpr (std::is_same_v<TID, TypeId>)
3636+
result = subtyping.isSubtype(subTy, superTy, constraint->scope);
3637+
else if constexpr (std::is_same_v<TID, TypePackId>)
3638+
result = subtyping.isSubtype(subTy, superTy, constraint->scope, {});
36273639

3628-
if (FFlag::LuauUnifyWithSubtyping2)
3629-
{
3630-
Subtyping subtyping{builtinTypes, arena, normalizer, typeFunctionRuntime, NotNull{&iceReporter}};
3631-
SubtypingUnifier stu{arena, builtinTypes, NotNull{&iceReporter}};
3632-
SubtypingResult result;
3633-
if constexpr (std::is_same_v<TID, TypeId>)
3634-
result = subtyping.isSubtype(subTy, superTy, constraint->scope);
3635-
else if constexpr (std::is_same_v<TID, TypePackId>)
3636-
result = subtyping.isSubtype(subTy, superTy, constraint->scope, {});
3637-
3638-
auto unifierResult = stu.dispatchConstraints(constraint, std::move(result.assumedConstraints));
3639-
3640-
for (auto& cv : unifierResult.outstandingConstraints)
3641-
{
3642-
auto newConstraint = pushConstraint(constraint->scope, constraint->location, std::move(cv));
3643-
inheritBlocks(constraint, newConstraint);
3644-
}
3645-
3646-
for (const auto& [ty, newUpperBounds] : unifierResult.upperBoundContributors)
3647-
{
3648-
auto& upperBounds = upperBoundContributors[ty];
3649-
upperBounds.insert(upperBounds.end(), newUpperBounds.begin(), newUpperBounds.end());
3650-
}
3640+
auto unifierResult = stu.dispatchConstraints(constraint, std::move(result.assumedConstraints));
36513641

3652-
switch (unifierResult.unified)
3653-
{
3654-
case UnifyResult::OccursCheckFailed:
3655-
reportError(OccursCheckFailed{}, constraint->location);
3656-
return false;
3657-
case UnifyResult::TooComplex:
3658-
reportError(UnificationTooComplex{}, constraint->location);
3659-
return false;
3660-
case UnifyResult::Ok:
3661-
default:
3662-
return true;
3663-
}
3664-
}
3665-
else
3642+
for (auto& cv : unifierResult.outstandingConstraints)
36663643
{
3667-
Unifier2 u2{NotNull{arena}, builtinTypes, constraint->scope, NotNull{&iceReporter}, &uninhabitedTypeFunctions};
3668-
3669-
const UnifyResult unifyResult = u2.unify(subTy, superTy);
3670-
3671-
for (ConstraintV& c : u2.incompleteSubtypes)
3672-
{
3673-
NotNull<Constraint> addition = pushConstraint(constraint->scope, constraint->location, std::move(c));
3674-
inheritBlocks(constraint, addition);
3675-
}
3644+
auto newConstraint = pushConstraint(constraint->scope, constraint->location, std::move(cv));
3645+
inheritBlocks(constraint, newConstraint);
3646+
}
36763647

3677-
if (UnifyResult::Ok == unifyResult)
3678-
{
3679-
for (const auto& [expanded, additions] : u2.expandedFreeTypes)
3680-
{
3681-
for (TypeId addition : additions)
3682-
upperBoundContributors[expanded].emplace_back(constraint->location, addition);
3683-
}
3684-
}
3685-
else
3686-
{
3687-
switch (unifyResult)
3688-
{
3689-
case Luau::UnifyResult::Ok:
3690-
break;
3691-
case Luau::UnifyResult::OccursCheckFailed:
3692-
reportError(OccursCheckFailed{}, constraint->location);
3693-
break;
3694-
case Luau::UnifyResult::TooComplex:
3695-
reportError(UnificationTooComplex{}, constraint->location);
3696-
break;
3697-
}
3698-
return false;
3699-
}
3648+
for (const auto& [ty, newUpperBounds] : unifierResult.upperBoundContributors)
3649+
{
3650+
auto& upperBounds = upperBoundContributors[ty];
3651+
upperBounds.insert(upperBounds.end(), newUpperBounds.begin(), newUpperBounds.end());
3652+
}
37003653

3654+
switch (unifierResult.unified)
3655+
{
3656+
case UnifyResult::OccursCheckFailed:
3657+
reportError(OccursCheckFailed{}, constraint->location);
3658+
return false;
3659+
case UnifyResult::TooComplex:
3660+
reportError(UnificationTooComplex{}, constraint->location);
3661+
return false;
3662+
case UnifyResult::Ok:
3663+
default:
37013664
return true;
37023665
}
3703-
37043666
}
37053667

37063668
bool ConstraintSolver::block_(BlockedConstraintId target, NotNull<const Constraint> constraint)

Analysis/src/NonStrictTypeChecker.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ LUAU_FASTFLAG(DebugLuauMagicTypes)
2323

2424
LUAU_FASTINTVARIABLE(LuauNonStrictTypeCheckerRecursionLimit, 300)
2525
LUAU_FASTFLAGVARIABLE(LuauAddRecursionCounterToNonStrictTypeChecker)
26+
LUAU_FASTFLAGVARIABLE(LuauNonStrictModeUseErrorSupressingTag)
2627

2728
namespace Luau
2829
{
@@ -1207,8 +1208,19 @@ struct NonStrictTypeChecker
12071208
SubtypingResult r = subtyping.isSubtype(actualType, *contextTy, scope);
12081209
if (r.normalizationTooComplex)
12091210
reportError(NormalizationTooComplex{}, fragment->location);
1210-
if (r.isSubtype)
1211-
return {actualType};
1211+
if (FFlag::LuauNonStrictModeUseErrorSupressingTag)
1212+
{
1213+
// If this subtype test passed and we did not see an error
1214+
// suppressing bit, then return this as the type that will
1215+
// error at runtime.
1216+
if (r.isSubtype && !r.isErrorSuppressing)
1217+
return {actualType};
1218+
}
1219+
else
1220+
{
1221+
if (r.isSubtype)
1222+
return {actualType};
1223+
}
12121224
}
12131225
}
12141226

0 commit comments

Comments
 (0)