Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ on:
- 'papers/**'
- 'rfcs/**'
- '*.md'
pull_request:
paths-ignore:
- 'docs/**'
- 'papers/**'
- 'rfcs/**'
- '*.md'
# pull_request:
# paths-ignore:
# - 'docs/**'
# - 'papers/**'
# - 'rfcs/**'
# - '*.md'

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

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

namespace Luau
{

// Search through the expression 'expr' for types that are known to represent
// uniquely held references. Append these types to 'uniqueTypes'.
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstExpr* expr, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);

void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, AstArray<AstExpr*> exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);
void findUniqueTypes(NotNull<DenseHashSet<TypeId>> uniqueTypes, const std::vector<AstExpr*>& exprs, NotNull<const DenseHashMap<const AstExpr*, TypeId>> astTypes);

}
2 changes: 2 additions & 0 deletions Analysis/include/Luau/AutocompleteTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ enum class AutocompleteContext
Type,
Keyword,
String,
HotComment,
};

enum class AutocompleteEntryKind
Expand All @@ -30,6 +31,7 @@ enum class AutocompleteEntryKind
Module,
GeneratedFunction,
RequirePath,
HotComment,
};

enum class ParenthesesRecommendation
Expand Down
33 changes: 16 additions & 17 deletions Analysis/include/Luau/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct GeneralizationConstraint

std::vector<TypeId> interiorTypes;
bool hasDeprecatedAttribute = false;
AstAttr::DeprecatedInfo deprecatedInfo;

/// If true, never introduce generics. Always replace free types by their
/// bounds or unknown. Presently used only to generalize the whole module.
Expand Down Expand Up @@ -91,6 +92,10 @@ struct FunctionCallConstraint
TypeId fn;
TypePackId argsPack;
TypePackId result;

// callSite can be nullptr in the case that this constraint was
// synthetically generated from some other constraint. eg
// IterableConstraint.
class AstExprCall* callSite = nullptr;
std::vector<std::optional<TypeId>> discriminantTypes;

Expand All @@ -115,21 +120,6 @@ struct FunctionCheckConstraint
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
};

// table_check expectedType exprType
//
// If `expectedType` is a table type and `exprType` is _also_ a table type,
// propogate the member types of `expectedType` into the types of `exprType`.
// This is used to implement bidirectional inference on table assignment.
// Also see: FunctionCheckConstraint.
struct TableCheckConstraint
{
TypeId expectedType;
TypeId exprType;
AstExprTable* table = nullptr;
NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes;
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
};

// prim FreeType ExpectedType PrimitiveType
//
// FreeType is bounded below by the singleton type and above by PrimitiveType
Expand Down Expand Up @@ -302,6 +292,15 @@ struct PushFunctionTypeConstraint
bool isSelf;
};

struct PushTypeConstraint
{
TypeId expectedType;
TypeId targetType;
NotNull<DenseHashMap<const AstExpr*, TypeId>> astTypes;
NotNull<DenseHashMap<const AstExpr*, TypeId>> astExpectedTypes;
NotNull<const AstExpr> expr;
};

using ConstraintV = Variant<
SubtypeConstraint,
PackSubtypeConstraint,
Expand All @@ -320,9 +319,9 @@ using ConstraintV = Variant<
ReduceConstraint,
ReducePackConstraint,
EqualityConstraint,
TableCheckConstraint,
SimplifyConstraint,
PushFunctionTypeConstraint>;
PushFunctionTypeConstraint,
PushTypeConstraint>;

struct Constraint
{
Expand Down
8 changes: 6 additions & 2 deletions Analysis/include/Luau/ConstraintGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Luau/ControlFlow.h"
#include "Luau/DataFlowGraph.h"
#include "Luau/EqSatSimplification.h"
#include "Luau/HashUtil.h"
#include "Luau/InsertionOrderedMap.h"
#include "Luau/Module.h"
#include "Luau/ModuleResolver.h"
Expand Down Expand Up @@ -135,6 +136,8 @@ struct ConstraintGenerator

DcrLogger* logger;

bool recursionLimitMet = false;

ConstraintGenerator(
ModulePtr module,
NotNull<Normalizer> normalizer,
Expand Down Expand Up @@ -170,11 +173,12 @@ struct ConstraintGenerator
std::vector<TypePackId> typePacks;
};

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

std::vector<TypeId> unionsToSimplify;

DenseHashMap<std::pair<TypeId, std::string>, TypeId, PairHash<TypeId, std::string>> propIndexPairsSeen{{nullptr, ""}};

// Used to keep track of when we are inside a large table and should
// opt *not* to do type inference for singletons.
size_t largeTableDepth = 0;
Expand Down Expand Up @@ -260,7 +264,6 @@ struct ConstraintGenerator
LUAU_NOINLINE void checkAliases(const ScopePtr& scope, AstStatBlock* block);

ControlFlow visitBlockWithoutChildScope(const ScopePtr& scope, AstStatBlock* block);
ControlFlow visitBlockWithoutChildScope_DEPRECATED(const ScopePtr& scope, AstStatBlock* block);

ControlFlow visit(const ScopePtr& scope, AstStat* stat);
ControlFlow visit(const ScopePtr& scope, AstStatBlock* block);
Expand Down Expand Up @@ -497,6 +500,7 @@ struct ConstraintGenerator

void updateRValueRefinements(const ScopePtr& scope, DefId def, TypeId ty) const;
void updateRValueRefinements(Scope* scope, DefId def, TypeId ty) const;
void resolveGenericDefaultParameters(const ScopePtr& defnScope, AstStatTypeAlias* alias, const TypeFun& fun);
};

} // namespace Luau
11 changes: 6 additions & 5 deletions Analysis/include/Luau/ConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ struct ConstraintSolver
std::vector<NotNull<Constraint>> constraints;
NotNull<DenseHashMap<Scope*, TypeId>> scopeToFunction;
NotNull<Scope> rootScope;
ModuleName currentModuleName;
ModulePtr module;

// The dataflow graph of the program, used in constraint generation and for magic functions.
NotNull<const DataFlowGraph> dfg;
Expand Down Expand Up @@ -169,7 +169,7 @@ struct ConstraintSolver
NotNull<Normalizer> normalizer,
NotNull<Simplifier> simplifier,
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
ModuleName moduleName,
ModulePtr module,
NotNull<ModuleResolver> moduleResolver,
std::vector<RequireCycle> requireCycles,
DcrLogger* logger,
Expand All @@ -178,14 +178,15 @@ struct ConstraintSolver
ConstraintSet constraintSet
);

// TODO CLI-169086: Replace all uses of this constructor with the ConstraintSet constructor, above.
explicit ConstraintSolver(
NotNull<Normalizer> normalizer,
NotNull<Simplifier> simplifier,
NotNull<TypeFunctionRuntime> typeFunctionRuntime,
NotNull<Scope> rootScope,
std::vector<NotNull<Constraint>> constraints,
NotNull<DenseHashMap<Scope*, TypeId>> scopeToFunction,
ModuleName moduleName,
ModulePtr module,
NotNull<ModuleResolver> moduleResolver,
std::vector<RequireCycle> requireCycles,
DcrLogger* logger,
Expand Down Expand Up @@ -249,8 +250,7 @@ struct ConstraintSolver
bool tryDispatch(const NameConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const TypeAliasExpansionConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const FunctionCallConstraint& c, NotNull<const Constraint> constraint, bool force);
bool tryDispatch(const TableCheckConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const FunctionCheckConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const FunctionCheckConstraint& c, NotNull<const Constraint> constraint, bool force);
bool tryDispatch(const PrimitiveTypeConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const HasPropConstraint& c, NotNull<const Constraint> constraint);

Expand All @@ -275,6 +275,7 @@ struct ConstraintSolver
bool tryDispatch(const SimplifyConstraint& c, NotNull<const Constraint> constraint, bool force);

bool tryDispatch(const PushFunctionTypeConstraint& c, NotNull<const Constraint> constraint);
bool tryDispatch(const PushTypeConstraint& c, NotNull<const Constraint> constraint, bool force);

// for a, ... in some_table do
// also handles __iter metamethod
Expand Down
55 changes: 53 additions & 2 deletions Analysis/include/Luau/Error.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include "Luau/Ast.h"
#include "Luau/Location.h"
#include "Luau/NotNull.h"
#include "Luau/Type.h"
#include "Luau/TypeIds.h"
#include "Luau/Variant.h"
#include "Luau/Ast.h"

#include <set>

Expand Down Expand Up @@ -86,6 +87,15 @@ struct CannotExtendTable
bool operator==(const CannotExtendTable& rhs) const;
};

struct CannotCompareUnrelatedTypes
{
TypeId left;
TypeId right;
AstExprBinary::Op op;

bool operator==(const CannotCompareUnrelatedTypes& rhs) const;
};

struct OnlyTablesCanHaveMethods
{
TypeId tableType;
Expand Down Expand Up @@ -504,12 +514,49 @@ struct MultipleNonviableOverloads
bool operator==(const MultipleNonviableOverloads& rhs) const;
};

// Error where a type alias violates the recursive restraint, ie when a type alias T<A> has T with different arguments on the RHS.
struct RecursiveRestraintViolation
{
bool operator==(const RecursiveRestraintViolation& rhs) const
{
return true;
}
};

// Error during subtyping when the inferred bounds of a generic type are incompatible
struct GenericBoundsMismatch
{
std::string_view genericName;
std::vector<TypeId> lowerBounds;
std::vector<TypeId> upperBounds;

GenericBoundsMismatch(std::string_view genericName, TypeIds lowerBoundSet, TypeIds upperBoundSet);

bool operator==(const GenericBoundsMismatch& rhs) const;
};

// Error when referencing a type function without providing explicit generics.
//
// type function create_table_with_key()
// local tbl = types.newtable()
// tbl:setproperty(types.singleton "key", types.unionof(types.string, types.singleton(nil)))
// return tbl
// end
// local a: create_table_with_key = {}
// ^^^^^^^^^^^^^^^^^^^^^ This should have `<>` at the end.
//
struct UnappliedTypeFunction
{
bool operator==(const UnappliedTypeFunction& rhs) const;
};

using TypeErrorData = Variant<
TypeMismatch,
UnknownSymbol,
UnknownProperty,
NotATable,
CannotExtendTable,
CannotCompareUnrelatedTypes,
OnlyTablesCanHaveMethods,
DuplicateTypeDefinition,
CountMismatch,
Expand Down Expand Up @@ -559,7 +606,11 @@ using TypeErrorData = Variant<
CannotCheckDynamicStringFormatCalls,
GenericTypeCountMismatch,
GenericTypePackCountMismatch,
MultipleNonviableOverloads>;
MultipleNonviableOverloads,
RecursiveRestraintViolation,
GenericBoundsMismatch,
UnappliedTypeFunction>;


struct TypeErrorSummary
{
Expand Down
3 changes: 2 additions & 1 deletion Analysis/include/Luau/FragmentAutocomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ FragmentAutocompleteResult fragmentAutocomplete(
StringCompletionCallback callback,
std::optional<Position> fragmentEndPosition = std::nullopt,
AstStatBlock* recentParse = nullptr,
IFragmentAutocompleteReporter* reporter = nullptr
IFragmentAutocompleteReporter* reporter = nullptr,
bool isInHotComment = false
);

enum class FragmentAutocompleteStatus
Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ struct Frontend

Frontend(FileResolver* fileResolver, ConfigResolver* configResolver, const FrontendOptions& options = {});

void setLuauSolverSelectionFromWorkspace(SolverMode mode);
void setLuauSolverMode(SolverMode mode);
SolverMode getLuauSolverMode() const;
// The default value assuming there is no workspace setup yet
std::atomic<SolverMode> useNewLuauSolver{FFlag::LuauSolverV2 ? SolverMode::New : SolverMode::Old};
Expand Down Expand Up @@ -330,7 +330,7 @@ ModulePtr check(
NotNull<InternalErrorReporter> iceHandler,
NotNull<ModuleResolver> moduleResolver,
NotNull<FileResolver> fileResolver,
const ScopePtr& globalScope,
const ScopePtr& parentScope,
const ScopePtr& typeFunctionScope,
std::function<void(const ModuleName&, const ScopePtr&)> prepareModuleScope,
FrontendOptions options,
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/GlobalTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct GlobalTypes
TypeArena globalTypes;
SourceModule globalNames; // names for symbols entered into globalScope

ScopePtr globalScope; // shared by all modules
ScopePtr globalScope; // shared by all modules
ScopePtr globalTypeFunctionScope; // shared by all modules

SolverMode mode = SolverMode::Old;
Expand Down
4 changes: 3 additions & 1 deletion Analysis/include/Luau/Instantiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include "Luau/Unifiable.h"
#include "Luau/VisitType.h"

LUAU_FASTFLAG(LuauExplicitSkipBoundTypes)

namespace Luau
{

Expand Down Expand Up @@ -93,7 +95,7 @@ struct GenericTypeFinder : TypeOnceVisitor
bool found = false;

GenericTypeFinder()
: TypeOnceVisitor("GenericTypeFinder")
: TypeOnceVisitor("GenericTypeFinder", FFlag::LuauExplicitSkipBoundTypes)
{
}

Expand Down
1 change: 1 addition & 0 deletions Analysis/include/Luau/IostreamHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ std::ostream& operator<<(std::ostream& lhs, const UnknownSymbol& error);
std::ostream& operator<<(std::ostream& lhs, const UnknownProperty& error);
std::ostream& operator<<(std::ostream& lhs, const NotATable& error);
std::ostream& operator<<(std::ostream& lhs, const CannotExtendTable& error);
std::ostream& operator<<(std::ostream& lhs, const CannotCompareUnrelatedTypes& error);
std::ostream& operator<<(std::ostream& lhs, const OnlyTablesCanHaveMethods& error);
std::ostream& operator<<(std::ostream& lhs, const DuplicateTypeDefinition& error);
std::ostream& operator<<(std::ostream& lhs, const CountMismatch& error);
Expand Down
6 changes: 6 additions & 0 deletions Analysis/include/Luau/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ bool isWithinComment(const std::vector<Comment>& commentLocations, Position pos)
bool isWithinComment(const SourceModule& sourceModule, Position pos);
bool isWithinComment(const ParseResult& result, Position pos);

bool isWithinHotComment(const std::vector<HotComment>& hotComments, Position pos);
bool isWithinHotComment(const SourceModule& sourceModule, Position pos);
bool isWithinHotComment(const ParseResult& result, Position pos);

struct RequireCycle
{
Location location;
Expand Down Expand Up @@ -155,6 +159,8 @@ struct Module
void clonePublicInterface_DEPRECATED(NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);

void clonePublicInterface(NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice, SolverMode mode);

bool constraintGenerationDidNotComplete = true;
};

} // namespace Luau
Loading