Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
765591c
Sync to origin/release/656
hgoldstein Jan 10, 2025
a0ed331
Merge branch 'upstream' into merge
hgoldstein Jan 10, 2025
ba71ff1
Explicitly cast size_t to uint64_t in buffer_readbits / buffer_writebits
hgoldstein Jan 10, 2025
aaaeae5
Sync to upstream/release/657
vrn-sn Jan 17, 2025
790dc17
Merge branch 'master' into merge
vrn-sn Jan 17, 2025
c6e2b53
Merge branch 'upstream' into merge
vrn-sn Jan 17, 2025
76e0958
Include <algorithm> and <vector> in IrUtils.cpp
vrn-sn Jan 17, 2025
23241e2
Sync to upstream/release/658
ayoungbloodrbx Jan 24, 2025
6167275
Merge branch 'master' into merge
ayoungbloodrbx Jan 24, 2025
ec5643d
Merge branch 'upstream' into merge
ayoungbloodrbx Jan 24, 2025
768a3a2
Remove duplicate flag
ayoungbloodrbx Jan 24, 2025
c31654d
Move duplicate flag back
ayoungbloodrbx Jan 24, 2025
072195b
Merge branch 'master' into merge
menarulalam Feb 1, 2025
5f0bd2f
Sync to upstream/release/659
menarulalam Feb 1, 2025
a699a21
Merge branch 'upstream' into merge
menarulalam Feb 1, 2025
a3630ef
Merge branch 'upstream' into merge
menarulalam Feb 1, 2025
df60533
Sync to upstream/release/659
menarulalam Feb 1, 2025
7199da8
Sync to upstream/release/660
Feb 7, 2025
fd9b8b0
Merge branch 'master' into merge
Feb 7, 2025
198c1f7
Merge branch 'upstream' into merge
Feb 7, 2025
6b30374
Cast types appropriately to fix compilation error.
Feb 7, 2025
d17d70d
Merge branch 'upstream' into merge
Feb 7, 2025
c9a4113
Explicitly enable FFlags in interpolated string Transpiler tests
Feb 8, 2025
587cf13
Sync to upstream/release/661
Vighnesh-V Feb 14, 2025
aab18f3
Merge branch 'master' into merge
Vighnesh-V Feb 14, 2025
1d001c4
Merge branch 'upstream' into merge
Vighnesh-V Feb 14, 2025
69afd59
Correctly apply unsigned casting patch to merge branch
Vighnesh-V Feb 14, 2025
279e15a
Sync to upstream/release/662
vegorov-rbx Feb 21, 2025
1c3720a
Merge branch 'master' into merge
vegorov-rbx Feb 21, 2025
4717228
Merge branch 'upstream' into merge
vegorov-rbx Feb 21, 2025
6a8da81
Merge fix
vegorov-rbx Feb 21, 2025
b6ca2a0
Sync to upstream/release/663
aatxe Feb 28, 2025
4b3b32a
Merge branch 'master' into merge
aatxe Feb 28, 2025
f43ebc2
Merge branch 'upstream' into merge
aatxe Feb 28, 2025
7568957
Sync to upstream/release/664
vegorov-rbx Mar 7, 2025
a0fad72
Merge branch 'master' into merge
vegorov-rbx Mar 7, 2025
23bc546
Merge branch 'upstream' into merge
vegorov-rbx Mar 7, 2025
af20253
Sync to upstream/release/665
hgoldstein Mar 14, 2025
df92b6c
Merge branch 'master' into merge
hgoldstein Mar 14, 2025
de3f3d2
Merge branch 'upstream' into merge
hgoldstein Mar 14, 2025
2eefa3f
Sync to upstream/release/666
vrn-sn Mar 21, 2025
a371d16
Merge branch 'master' into merge
vrn-sn Mar 21, 2025
716f524
Merge branch 'upstream' into merge
vrn-sn Mar 21, 2025
d4c2c64
Sync to upstream/release/667
ayoungbloodrbx Mar 28, 2025
9ae5f37
Merge branch 'master' into merge
ayoungbloodrbx Mar 28, 2025
08f07a1
Merge branch 'upstream' into merge
ayoungbloodrbx Mar 28, 2025
d9e8ded
Sync to upstream/release/668
Apr 4, 2025
f85407b
Merge branch 'master' into merge
Apr 4, 2025
6e90f90
Merge branch 'upstream' into merge
Apr 4, 2025
d2969f0
Disable failing tests until fixes have been found.
Apr 4, 2025
7a6b561
Sync to upstream/release/669
menarulalam Apr 11, 2025
c3f6c48
Merge branch 'master' into merge
menarulalam Apr 11, 2025
567876e
Merge branch 'upstream' into merge
menarulalam Apr 11, 2025
afaceca
Add missing MIT License header
vrn-sn Apr 11, 2025
8f61efb
Make RequireNavigator depend on Config (hacky, will improve later)
vrn-sn Apr 12, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 21 additions & 7 deletions Analysis/include/Luau/ConstraintGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
#include "Luau/ModuleResolver.h"
#include "Luau/Normalize.h"
#include "Luau/NotNull.h"
#include "Luau/Polarity.h"
#include "Luau/Refinement.h"
#include "Luau/Symbol.h"
#include "Luau/TypeFwd.h"
#include "Luau/TypeUtils.h"
#include "Luau/Variant.h"

#include <memory>
#include <vector>
#include <unordered_map>

namespace Luau
{
Expand Down Expand Up @@ -162,19 +161,26 @@ struct ConstraintGenerator
void visitFragmentRoot(const ScopePtr& resumeScope, AstStatBlock* block);

private:
std::vector<std::vector<TypeId>> interiorTypes;
struct InteriorFreeTypes
{
std::vector<TypeId> types;
std::vector<TypePackId> typePacks;
};

std::vector<std::vector<TypeId>> DEPRECATED_interiorTypes;
std::vector<InteriorFreeTypes> interiorFreeTypes;

/**
* Fabricates a new free type belonging to a given scope.
* @param scope the scope the free type belongs to.
*/
TypeId freshType(const ScopePtr& scope);
TypeId freshType(const ScopePtr& scope, Polarity polarity = Polarity::Unknown);

/**
* Fabricates a new free type pack belonging to a given scope.
* @param scope the scope the free type pack belongs to.
*/
TypePackId freshTypePack(const ScopePtr& scope);
TypePackId freshTypePack(const ScopePtr& scope, Polarity polarity = Polarity::Unknown);

/**
* Allocate a new TypePack with the given head and tail.
Expand Down Expand Up @@ -295,7 +301,7 @@ struct ConstraintGenerator
);

Inference check(const ScopePtr& scope, AstExprConstantString* string, std::optional<TypeId> expectedType, bool forceSingleton);
Inference check(const ScopePtr& scope, AstExprConstantBool* bool_, std::optional<TypeId> expectedType, bool forceSingleton);
Inference check(const ScopePtr& scope, AstExprConstantBool* boolExpr, std::optional<TypeId> expectedType, bool forceSingleton);
Inference check(const ScopePtr& scope, AstExprLocal* local);
Inference check(const ScopePtr& scope, AstExprGlobal* global);
Inference checkIndexName(const ScopePtr& scope, const RefinementKey* key, AstExpr* indexee, const std::string& index, Location indexLocation);
Expand Down Expand Up @@ -371,6 +377,11 @@ struct ConstraintGenerator
**/
TypeId resolveType(const ScopePtr& scope, AstType* ty, bool inTypeArguments, bool replaceErrorWithFresh = false);

// resolveType() is recursive, but we only want to invoke
// inferGenericPolarities() once at the very end. We thus isolate the
// recursive part of the algorithm to this internal helper.
TypeId resolveType_(const ScopePtr& scope, AstType* ty, bool inTypeArguments, bool replaceErrorWithFresh = false);

/**
* Resolves a type pack from its AST annotation.
* @param scope the scope that the type annotation appears within.
Expand All @@ -380,6 +391,9 @@ struct ConstraintGenerator
**/
TypePackId resolveTypePack(const ScopePtr& scope, AstTypePack* tp, bool inTypeArguments, bool replaceErrorWithFresh = false);

// Inner hepler for resolveTypePack
TypePackId resolveTypePack_(const ScopePtr& scope, AstTypePack* tp, bool inTypeArguments, bool replaceErrorWithFresh = false);

/**
* Resolves a type pack from its AST annotation.
* @param scope the scope that the type annotation appears within.
Expand Down Expand Up @@ -418,7 +432,7 @@ struct ConstraintGenerator
**/
std::vector<std::pair<Name, GenericTypePackDefinition>> createGenericPacks(
const ScopePtr& scope,
AstArray<AstGenericTypePack*> packs,
AstArray<AstGenericTypePack*> generics,
bool useCache = false,
bool addTypes = true
);
Expand Down
8 changes: 4 additions & 4 deletions Analysis/include/Luau/DataFlowGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ struct DataFlowGraphBuilder

/// A stack of scopes used by the visitor to see where we are.
ScopeStack scopeStack;

DfgScope* currentScope();
NotNull<DfgScope> currentScope();
DfgScope* currentScope_DEPRECATED();

struct FunctionCapture
{
Expand All @@ -148,8 +148,8 @@ struct DataFlowGraphBuilder
void joinBindings(DfgScope* p, const DfgScope& a, const DfgScope& b);
void joinProps(DfgScope* p, const DfgScope& a, const DfgScope& b);

DefId lookup(Symbol symbol);
DefId lookup(DefId def, const std::string& key);
DefId lookup(Symbol symbol, Location location);
DefId lookup(DefId def, const std::string& key, Location location);

ControlFlow visit(AstStatBlock* b);
ControlFlow visitBlockWithoutChildScope(AstStatBlock* b);
Expand Down
8 changes: 6 additions & 2 deletions Analysis/include/Luau/Def.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
#include "Luau/NotNull.h"
#include "Luau/TypedAllocator.h"
#include "Luau/Variant.h"

#include "Luau/Location.h"
#include "Luau/Symbol.h"
#include <string>
#include <optional>

Expand All @@ -13,6 +14,7 @@ namespace Luau

struct Def;
using DefId = NotNull<const Def>;
struct AstLocal;

/**
* A cell is a "single-object" value.
Expand Down Expand Up @@ -64,6 +66,8 @@ struct Def
using V = Variant<struct Cell, struct Phi>;

V v;
Symbol name;
Location location;
};

template<typename T>
Expand All @@ -79,7 +83,7 @@ struct DefArena
{
TypedAllocator<Def> allocator;

DefId freshCell(bool subscripted = false);
DefId freshCell(Symbol sym, Location location, bool subscripted = false);
DefId phi(DefId a, DefId b);
DefId phi(const std::vector<DefId>& defs);
};
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/FragmentAutocomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct FragmentAutocompleteResult
{
ModulePtr incrementalModule;
Scope* freshScope;
TypeArena arenaForAutocomplete;
TypeArena arenaForAutocomplete_DEPRECATED;
AutocompleteResult acResults;
};

Expand Down
29 changes: 28 additions & 1 deletion Analysis/include/Luau/Generalization.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,39 @@
namespace Luau
{

template<typename TID>
struct GeneralizationParams
{
bool foundOutsideFunctions = false;
size_t useCount = 0;
Polarity polarity = Polarity::None;
};

// Replace a single free type by its bounds according to the polarity provided.
std::optional<TypeId> generalizeType(
NotNull<TypeArena> arena,
NotNull<BuiltinTypes> builtinTypes,
NotNull<Scope> scope,
TypeId freeTy,
const GeneralizationParams<TypeId>& params
);

// Generalize one type pack
std::optional<TypePackId> generalizeTypePack(
NotNull<TypeArena> arena,
NotNull<BuiltinTypes> builtinTypes,
NotNull<Scope> scope,
TypePackId tp,
const GeneralizationParams<TypePackId>& params
);

void sealTable(NotNull<Scope> scope, TypeId ty);

std::optional<TypeId> generalize(
NotNull<TypeArena> arena,
NotNull<BuiltinTypes> builtinTypes,
NotNull<Scope> scope,
NotNull<DenseHashSet<TypeId>> cachedTypes,
TypeId ty
);

}
16 changes: 16 additions & 0 deletions Analysis/include/Luau/InferPolarity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include "Luau/NotNull.h"
#include "Luau/TypeFwd.h"

namespace Luau
{

struct Scope;
struct TypeArena;

void inferGenericPolarities(NotNull<TypeArena> arena, NotNull<Scope> scope, TypeId ty);
void inferGenericPolarities(NotNull<TypeArena> arena, NotNull<Scope> scope, TypePackId tp);

} // namespace Luau
13 changes: 13 additions & 0 deletions Analysis/include/Luau/InsertionOrderedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,19 @@ struct InsertionOrderedMap
return &pairs.at(it->second).second;
}

V& operator[](const K& k)
{
auto it = indices.find(k);
if (it == indices.end())
{
pairs.push_back(std::make_pair(k, V()));
indices[k] = pairs.size() - 1;
return pairs.back().second;
}
else
return pairs.at(it->second).second;
}

const_iterator begin() const
{
return pairs.begin();
Expand Down
68 changes: 68 additions & 0 deletions Analysis/include/Luau/Polarity.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include <cstdint>

namespace Luau
{

enum struct Polarity : uint8_t
{
None = 0b000,
Positive = 0b001,
Negative = 0b010,
Mixed = 0b011,
Unknown = 0b100,
};

inline Polarity operator|(Polarity lhs, Polarity rhs)
{
return Polarity(uint8_t(lhs) | uint8_t(rhs));
}

inline Polarity& operator|=(Polarity& lhs, Polarity rhs)
{
lhs = lhs | rhs;
return lhs;
}

inline Polarity operator&(Polarity lhs, Polarity rhs)
{
return Polarity(uint8_t(lhs) & uint8_t(rhs));
}

inline Polarity& operator&=(Polarity& lhs, Polarity rhs)
{
lhs = lhs & rhs;
return lhs;
}

inline bool isPositive(Polarity p)
{
return bool(p & Polarity::Positive);
}

inline bool isNegative(Polarity p)
{
return bool(p & Polarity::Negative);
}

inline bool isKnown(Polarity p)
{
return p != Polarity::Unknown;
}

inline Polarity invert(Polarity p)
{
switch (p)
{
case Polarity::Positive:
return Polarity::Negative;
case Polarity::Negative:
return Polarity::Positive;
default:
return p;
}
}

} // namespace Luau
3 changes: 2 additions & 1 deletion Analysis/include/Luau/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct Scope
// All the children of this scope.
std::vector<NotNull<Scope>> children;
std::unordered_map<Symbol, Binding> bindings;
TypePackId returnType;
TypePackId returnType = nullptr;
std::optional<TypePackId> varargPack;

TypeLevel level;
Expand Down Expand Up @@ -100,6 +100,7 @@ struct Scope
std::unordered_map<Name, TypePackId> typeAliasTypePackParameters;

std::optional<std::vector<TypeId>> interiorFreeTypes;
std::optional<std::vector<TypePackId>> interiorFreeTypePacks;
};

// Returns true iff the left scope encloses the right scope. A Scope* equal to
Expand Down
24 changes: 10 additions & 14 deletions Analysis/include/Luau/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

#include "Luau/Ast.h"
#include "Luau/Common.h"
#include "Luau/Refinement.h"
#include "Luau/DenseHash.h"
#include "Luau/NotNull.h"
#include "Luau/Polarity.h"
#include "Luau/Predicate.h"
#include "Luau/Refinement.h"
#include "Luau/Unifiable.h"
#include "Luau/Variant.h"
#include "Luau/VecDeque.h"
Expand Down Expand Up @@ -37,15 +38,6 @@ struct Constraint;
struct Subtyping;
struct TypeChecker2;

enum struct Polarity : uint8_t
{
None = 0b000,
Positive = 0b001,
Negative = 0b010,
Mixed = 0b011,
Unknown = 0b100,
};

/**
* There are three kinds of type variables:
* - `Free` variables are metavariables, which stand for unconstrained types.
Expand Down Expand Up @@ -80,7 +72,7 @@ struct FreeType
// New constructors
explicit FreeType(TypeLevel level, TypeId lowerBound, TypeId upperBound);
// This one got promoted to explicit
explicit FreeType(Scope* scope, TypeId lowerBound, TypeId upperBound);
explicit FreeType(Scope* scope, TypeId lowerBound, TypeId upperBound, Polarity polarity = Polarity::Unknown);
explicit FreeType(Scope* scope, TypeLevel level, TypeId lowerBound, TypeId upperBound);
// Old constructors
explicit FreeType(TypeLevel level);
Expand All @@ -99,6 +91,8 @@ struct FreeType
// Only used under local type inference
TypeId lowerBound = nullptr;
TypeId upperBound = nullptr;

Polarity polarity = Polarity::Unknown;
};

struct GenericType
Expand All @@ -107,8 +101,8 @@ struct GenericType
GenericType();

explicit GenericType(TypeLevel level);
explicit GenericType(const Name& name);
explicit GenericType(Scope* scope);
explicit GenericType(const Name& name, Polarity polarity = Polarity::Unknown);
explicit GenericType(Scope* scope, Polarity polarity = Polarity::Unknown);

GenericType(TypeLevel level, const Name& name);
GenericType(Scope* scope, const Name& name);
Expand All @@ -118,6 +112,8 @@ struct GenericType
Scope* scope = nullptr;
Name name;
bool explicitName = false;

Polarity polarity = Polarity::Unknown;
};

// When an equality constraint is found, it is then "bound" to that type,
Expand Down Expand Up @@ -1206,7 +1202,7 @@ struct TypeIterator
}
};

TypeId freshType(NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtinTypes, Scope* scope);
TypeId freshType(NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtinTypes, Scope* scope, Polarity polarity = Polarity::Unknown);

using TypeIdPredicate = std::function<std::optional<TypeId>(TypeId)>;
std::vector<TypeId> filterMap(TypeId type, TypeIdPredicate predicate);
Expand Down
Loading
Loading