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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
15 changes: 0 additions & 15 deletions Analysis/include/Luau/AstUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,4 @@ struct TypeGuard

std::optional<TypeGuard> matchTypeGuard(AstExprBinary::Op op, AstExpr* left, AstExpr* right);

// Search through the expression 'expr' for typeArguments that are known to represent
// uniquely held references. Append these typeArguments 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
);

} // namespace Luau
23 changes: 13 additions & 10 deletions Analysis/include/Luau/ConstraintGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,18 @@ struct ConstraintGenerator
DenseHashMap<AstExpr*, Inference> inferredExprCache;

DenseHashMap<AstLocal*, std::unique_ptr<ClassDeclRecord>> classDeclRecords;
DenseHashSet<AstStatClass*> duplicateClassDecls;

DcrLogger* logger;

bool recursionLimitMet = false;

NotNull<ConstraintGraph> cgraph;

TypeStateMap* typestate = nullptr;
// Defer module-level generalization constraints to the solver so that we can generalize them after all other constraints have been solved.
ConstraintPtr moduleGeneralizationConstraint;

CFG::TypeStateMap* typestate = nullptr;
ConstraintGenerator(
ModulePtr module,
NotNull<Normalizer> normalizer,
Expand All @@ -188,7 +189,7 @@ struct ConstraintGenerator
NotNull<DataFlowGraph> dfg,
std::vector<RequireCycle> requireCycles,
NotNull<ConstraintGraph> cgraph,
CFG::TypeStateMap* typestate = nullptr
TypeStateMap* typestate = nullptr
);

ConstraintSet run(AstStatBlock* block);
Expand Down Expand Up @@ -263,9 +264,6 @@ struct ConstraintGenerator
* @param cv the constraint variant to add.
* @return the pointer to the inserted constraint
*/
TypeId resolveRHSType(const ScopePtr& scope, Location location, AstExpr* expr);
TypeId resolveLHSType(const ScopePtr& scope, Location location, const CFG::LValue& lv);

NotNull<Constraint> addConstraint(const ScopePtr& scope, const Location& location, ConstraintV cv);

/**
Expand Down Expand Up @@ -306,7 +304,8 @@ struct ConstraintGenerator
void applyRefinements(const ScopePtr& scope, Location location, RefinementId refinement);

LUAU_NOINLINE void prototypeTypeDefinitions(const ScopePtr& scope, AstStatBlock* block);
void prototypeClass(const ScopePtr& scope, AstStatClass* classDecl, TypeId classObjectTy);
ClassDeclRecord prototypeClass(const ScopePtr& scope, AstStatClass* classDecl, TypeId classObjectTy, Name className);
TypeId resolveSuperclass(const ScopePtr& scope, AstStatClass* statClass, TypeId superValueTy);

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

Expand Down Expand Up @@ -339,8 +338,6 @@ struct ConstraintGenerator
bool generalize
);

InferencePack checkPack_DEPRECATED(const ScopePtr& scope, AstArray<AstExpr*> exprs, const std::vector<std::optional<TypeId>>& expectedTypes = {});

InferencePack checkPack(
const ScopePtr& scope,
AstExpr* expr,
Expand Down Expand Up @@ -398,8 +395,6 @@ struct ConstraintGenerator
Inference check(const ScopePtr& scope, AstExprInterpString* interpString);
Inference check(const ScopePtr& scope, AstExprInstantiate* explicitTypeInstantiation);

Inference check_DEPRECATED(const ScopePtr& scope, AstExprTable* expr, std::optional<TypeId> expectedType);

Inference check(const ScopePtr& scope, AstExprTable* expr, std::optional<TypeId> expectedType, bool generalize);

std::tuple<TypeId, TypeId, RefinementId> checkBinary(
Expand Down Expand Up @@ -594,6 +589,14 @@ 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);

// Takes an expression and returns the reaching definition
TypeId getRHSType(AstExpr* expr) const;
// Takes a symbol and returns the type representing the total domain of that local variable
TypeId getLocalDomain(Symbol sym) const;
void expandDomain(AstExpr* l, TypeId rhs) const;
void expandDomain(AstLocal* l, TypeId rhs) const;
void expandDomain(AstExprGlobal* global, TypeId rhs) const;
};

} // namespace Luau
18 changes: 12 additions & 6 deletions Analysis/include/Luau/ConstraintGraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,14 @@ struct ConstraintList
Iterator end();

private:
DenseHashMap<ConstraintVertex, bool, HashBlockedConstraintId> present;
std::vector<ConstraintVertex> order;
// Clip with LuauTraverseScopeToFunction
DenseHashMap<ConstraintVertex, bool, HashBlockedConstraintId> present_DEPRECATED;
// Clip with LuauTraverseScopeToFunction
std::vector<ConstraintVertex> order_DEPRECATED;

DenseHashMap<ConstraintVertex, size_t, HashBlockedConstraintId> indices;
std::vector<std::pair<ConstraintVertex, bool>> order;

size_t entries = 0;
};

Expand Down Expand Up @@ -237,16 +243,16 @@ struct ConstraintGraph
* - Any constraint with no dependencies can be dispatched.
*/
ConstraintMap dependencies;


NotNull<ConstraintList> findDependencyList(ConstraintVertex vertex);
ConstraintList* findDependencyList(ConstraintVertex vertex);
NotNull<ConstraintList> findOrMakeDependencyList(ConstraintVertex vertex);

/**
* Inverse of the above mapping. Yes, the proper name for this is
* "dependents," but naming it such will result in hellish typos.
*/
ConstraintMap reverseDependencies;
NotNull<ConstraintList> findReverseDependencyList(ConstraintVertex vertex);
ConstraintList* findReverseDependencyList(ConstraintVertex vertex);
NotNull<ConstraintList> findOrMakeReverseDependencyList(ConstraintVertex vertex);

/**
* We do the same pseudo-arena trick as constraints do right now.
Expand Down
29 changes: 21 additions & 8 deletions Analysis/include/Luau/ConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,17 @@ struct ConstraintSolver

void generalizeOneType(TypeId ty);

// Clip with LuauRemoveConstraintSolverEmplace
template<typename T, typename... Args>
void DEPRECATED_emplace(NotNull<const Constraint> constraint, TypeId ty, Args&&... args);
std::optional<std::pair<TypeId, bool>> lookupTablePropHelper(
NotNull<const Constraint> constraint,
TypeId subjectType,
const std::string& propName,
ValueContext context,
TypeIds& blockedTypes,
DenseHashMap<TypeId, std::optional<std::pair<TypeId, bool>>>& cache,
bool inConditional,
bool suppressSimplification
);

// Clip with LuauRemoveConstraintSolverEmplace
template<typename T, typename... Args>
void DEPRECATED_emplace(NotNull<const Constraint> constraint, TypePackId tp, Args&&... args);

public:
/** Attempt to dispatch a constraint. Returns true if it was successful. If
Expand Down Expand Up @@ -256,7 +260,7 @@ struct ConstraintSolver
// for a, ... in next_function, t, ... do
bool tryDispatchIterableFunction(TypeId nextTy, TypeId tableTy, const IterableConstraint& c, NotNull<const Constraint> constraint);

TablePropLookupResult lookupTableProp(
TablePropLookupResult lookupTableProp_DEPRECATED(
NotNull<const Constraint> constraint,
TypeId subjectType,
const std::string& propName,
Expand All @@ -265,7 +269,7 @@ struct ConstraintSolver
bool suppressSimplification = false
);

TablePropLookupResult lookupTableProp(
TablePropLookupResult lookupTableProp_DEPRECATED(
NotNull<const Constraint> constraint,
TypeId subjectType,
const std::string& propName,
Expand All @@ -275,6 +279,15 @@ struct ConstraintSolver
DenseHashSet<TypeId>& seen
);

TablePropLookupResult lookupTableProp(
NotNull<const Constraint> constraint,
TypeId subjectType,
const std::string& propName,
ValueContext context,
bool inConditional,
bool suppressSimplification
);

/**
* Generate constraints to unpack the types of srcTypes and assign each
* value to the corresponding BlockedType in destTypes.
Expand Down
Loading
Loading