Skip to content

Commit 1d0b449

Browse files
alexmccordzeuxvegorov-rbxandyfriesenAmaranthineCodices
authored
Sync to upstream/release/597 (#1054)
# New Type Solver - Implement bidirectional type inference for higher order functions so that we can provide a more precise type improving the autocomplete's human factors. - We seal all tables, so we changed the stringification to make it a little lighter on users. - Fixed a case of array-out-of-bound access. - Type families no longer depends on `TxnLog` and `Unifier`. - Type refinements now waits until the free types are sufficiently solved. # Native Code Generation - Remove cached slot lookup for `executeSETTABLEKS` function because it is a fallback in the event of a cache miss, making the cached slot lookup redundant. - Optimized repeated array lookups, e.g. `a[3]` in `a[3] = a[3] / 2` is done once. # Misc - On some platforms, it is necessary to use `gmtime_s` with the arguments reversed to get the current time. You can now define `DOCTEST_CONFIG_USE_GMTIME_S` to build and run unit tests on those platforms. --------- Co-authored-by: Arseny Kapoulkine <[email protected]> Co-authored-by: Vyacheslav Egorov <[email protected]> Co-authored-by: Andy Friesen <[email protected]> Co-authored-by: Lily Brown <[email protected]> Co-authored-by: Aaron Weiss <[email protected]>
1 parent 16fbfe9 commit 1d0b449

Some content is hidden

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

46 files changed

+1220
-298
lines changed

Analysis/include/Luau/ConstraintGraphBuilder.h

+13-10
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ struct ConstraintGraphBuilder
106106
std::function<void(const ModuleName&, const ScopePtr&)> prepareModuleScope, DcrLogger* logger, NotNull<DataFlowGraph> dfg,
107107
std::vector<RequireCycle> requireCycles);
108108

109+
/**
110+
* The entry point to the ConstraintGraphBuilder. This will construct a set
111+
* of scopes, constraints, and free types that can be solved later.
112+
* @param block the root block to generate constraints for.
113+
*/
114+
void visitModuleRoot(AstStatBlock* block);
115+
116+
private:
109117
/**
110118
* Fabricates a new free type belonging to a given scope.
111119
* @param scope the scope the free type belongs to.
@@ -143,13 +151,6 @@ struct ConstraintGraphBuilder
143151

144152
void applyRefinements(const ScopePtr& scope, Location location, RefinementId refinement);
145153

146-
/**
147-
* The entry point to the ConstraintGraphBuilder. This will construct a set
148-
* of scopes, constraints, and free types that can be solved later.
149-
* @param block the root block to generate constraints for.
150-
*/
151-
void visit(AstStatBlock* block);
152-
153154
ControlFlow visitBlockWithoutChildScope(const ScopePtr& scope, AstStatBlock* block);
154155

155156
ControlFlow visit(const ScopePtr& scope, AstStat* stat);
@@ -172,7 +173,8 @@ struct ConstraintGraphBuilder
172173
ControlFlow visit(const ScopePtr& scope, AstStatError* error);
173174

174175
InferencePack checkPack(const ScopePtr& scope, AstArray<AstExpr*> exprs, const std::vector<std::optional<TypeId>>& expectedTypes = {});
175-
InferencePack checkPack(const ScopePtr& scope, AstExpr* expr, const std::vector<std::optional<TypeId>>& expectedTypes = {});
176+
InferencePack checkPack(
177+
const ScopePtr& scope, AstExpr* expr, const std::vector<std::optional<TypeId>>& expectedTypes = {}, bool generalize = true);
176178

177179
InferencePack checkPack(const ScopePtr& scope, AstExprCall* call);
178180

@@ -182,18 +184,19 @@ struct ConstraintGraphBuilder
182184
* @param expr the expression to check.
183185
* @param expectedType the type of the expression that is expected from its
184186
* surrounding context. Used to implement bidirectional type checking.
187+
* @param generalize If true, generalize any lambdas that are encountered.
185188
* @return the type of the expression.
186189
*/
187190
Inference check(const ScopePtr& scope, AstExpr* expr, ValueContext context = ValueContext::RValue, std::optional<TypeId> expectedType = {},
188-
bool forceSingleton = false);
191+
bool forceSingleton = false, bool generalize = true);
189192

190193
Inference check(const ScopePtr& scope, AstExprConstantString* string, std::optional<TypeId> expectedType, bool forceSingleton);
191194
Inference check(const ScopePtr& scope, AstExprConstantBool* bool_, std::optional<TypeId> expectedType, bool forceSingleton);
192195
Inference check(const ScopePtr& scope, AstExprLocal* local, ValueContext context);
193196
Inference check(const ScopePtr& scope, AstExprGlobal* global);
194197
Inference check(const ScopePtr& scope, AstExprIndexName* indexName);
195198
Inference check(const ScopePtr& scope, AstExprIndexExpr* indexExpr);
196-
Inference check(const ScopePtr& scope, AstExprFunction* func, std::optional<TypeId> expectedType);
199+
Inference check(const ScopePtr& scope, AstExprFunction* func, std::optional<TypeId> expectedType, bool generalize);
197200
Inference check(const ScopePtr& scope, AstExprUnary* unary);
198201
Inference check(const ScopePtr& scope, AstExprBinary* binary, std::optional<TypeId> expectedType);
199202
Inference check(const ScopePtr& scope, AstExprIfElse* ifElse, std::optional<TypeId> expectedType);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 "Luau/Module.h"
5+
#include "Luau/NotNull.h"
6+
7+
namespace Luau
8+
{
9+
10+
struct BuiltinTypes;
11+
12+
13+
void checkNonStrict(NotNull<BuiltinTypes> builtinTypes, Module* module);
14+
15+
} // namespace Luau

Analysis/src/Clone.cpp

+15-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "Luau/TypePack.h"
99
#include "Luau/Unifiable.h"
1010

11-
LUAU_FASTFLAG(DebugLuauCopyBeforeNormalizing)
1211
LUAU_FASTFLAG(DebugLuauReadWriteProperties)
1312

1413
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution)
@@ -253,8 +252,10 @@ class TypeCloner2
253252

254253
void cloneChildren(FreeType* t)
255254
{
256-
// TODO: clone lower and upper bounds.
257-
// TODO: In the new solver, we should ice.
255+
if (t->lowerBound)
256+
t->lowerBound = shallowClone(t->lowerBound);
257+
if (t->upperBound)
258+
t->upperBound = shallowClone(t->upperBound);
258259
}
259260

260261
void cloneChildren(GenericType* t)
@@ -376,7 +377,11 @@ class TypeCloner2
376377

377378
void cloneChildren(TypeFamilyInstanceType* t)
378379
{
379-
// TODO: In the new solver, we should ice.
380+
for (TypeId& ty : t->typeArguments)
381+
ty = shallowClone(ty);
382+
383+
for (TypePackId& tp : t->packArguments)
384+
tp = shallowClone(tp);
380385
}
381386

382387
void cloneChildren(FreeTypePack* t)
@@ -416,7 +421,11 @@ class TypeCloner2
416421

417422
void cloneChildren(TypeFamilyInstanceTypePack* t)
418423
{
419-
// TODO: In the new solver, we should ice.
424+
for (TypeId& ty : t->typeArguments)
425+
ty = shallowClone(ty);
426+
427+
for (TypePackId& tp : t->packArguments)
428+
tp = shallowClone(tp);
420429
}
421430
};
422431

@@ -560,8 +569,6 @@ struct TypePackCloner
560569
void operator()(const Unifiable::Bound<TypePackId>& t)
561570
{
562571
TypePackId cloned = clone(t.boundTo, dest, cloneState);
563-
if (FFlag::DebugLuauCopyBeforeNormalizing)
564-
cloned = dest.addTypePack(TypePackVar{BoundTypePack{cloned}});
565572
seenTypePacks[typePackId] = cloned;
566573
}
567574

@@ -629,8 +636,6 @@ void TypeCloner::operator()(const GenericType& t)
629636
void TypeCloner::operator()(const Unifiable::Bound<TypeId>& t)
630637
{
631638
TypeId boundTo = clone(t.boundTo, dest, cloneState);
632-
if (FFlag::DebugLuauCopyBeforeNormalizing)
633-
boundTo = dest.addType(BoundType{boundTo});
634639
seenTypes[typeId] = boundTo;
635640
}
636641

@@ -701,7 +706,7 @@ void TypeCloner::operator()(const FunctionType& t)
701706
void TypeCloner::operator()(const TableType& t)
702707
{
703708
// If table is now bound to another one, we ignore the content of the original
704-
if (!FFlag::DebugLuauCopyBeforeNormalizing && t.boundTo)
709+
if (t.boundTo)
705710
{
706711
TypeId boundTo = clone(*t.boundTo, dest, cloneState);
707712
seenTypes[typeId] = boundTo;
@@ -718,9 +723,6 @@ void TypeCloner::operator()(const TableType& t)
718723

719724
ttv->level = TypeLevel{0, 0};
720725

721-
if (FFlag::DebugLuauCopyBeforeNormalizing && t.boundTo)
722-
ttv->boundTo = clone(*t.boundTo, dest, cloneState);
723-
724726
for (const auto& [name, prop] : t.props)
725727
ttv->props[name] = clone(prop, dest, cloneState);
726728

0 commit comments

Comments
 (0)