Skip to content

Commit

Permalink
Sync to upstream/release/563 (#833)
Browse files Browse the repository at this point in the history
* Fix a bug where reading a property from an unsealed table caused
inference to improperly infer the existence of that property.
* Fix #827

We have also made a lot of progress on the new solver and the JIT. Both
projects are still in the process of being built out. Neither are ready
for general use yet.

We are mostly working to tighten up how the new solver handles
refinements and updates to unsealed tables to bring it up to the same
level as the old solver.

---------

Co-authored-by: Arseny Kapoulkine <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
3 people authored Feb 10, 2023
1 parent 18a1dc3 commit c5089de
Show file tree
Hide file tree
Showing 48 changed files with 2,429 additions and 509 deletions.
3 changes: 2 additions & 1 deletion Analysis/include/Luau/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ struct FunctionCallConstraint
TypePackId argsPack;
TypePackId result;
class AstExprCall* callSite;
std::vector<std::optional<TypeId>> discriminantTypes;
};

// result ~ prim ExpectedType SomeSingletonType MultitonType
Expand Down Expand Up @@ -180,7 +181,7 @@ struct Constraint
Constraint& operator=(const Constraint&) = delete;

NotNull<Scope> scope;
Location location; // TODO: Extract this out into only the constraints that needs a location. Not all constraints needs locations.
Location location;
ConstraintV c;

std::vector<NotNull<Constraint>> dependencies;
Expand Down
1 change: 1 addition & 0 deletions Analysis/include/Luau/DcrLogger.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct ConstraintBlock
struct ConstraintSnapshot
{
std::string stringification;
Location location;
std::vector<ConstraintBlock> blocks;
};

Expand Down
14 changes: 11 additions & 3 deletions Analysis/include/Luau/Refinement.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,20 @@ namespace Luau
struct Type;
using TypeId = const Type*;

struct Variadic;
struct Negation;
struct Conjunction;
struct Disjunction;
struct Equivalence;
struct Proposition;
using Refinement = Variant<Negation, Conjunction, Disjunction, Equivalence, Proposition>;
using Refinement = Variant<Variadic, Negation, Conjunction, Disjunction, Equivalence, Proposition>;
using RefinementId = Refinement*; // Can and most likely is nullptr.

struct Variadic
{
std::vector<RefinementId> refinements;
};

struct Negation
{
RefinementId refinement;
Expand Down Expand Up @@ -56,13 +62,15 @@ const T* get(RefinementId refinement)

struct RefinementArena
{
TypedAllocator<Refinement> allocator;

RefinementId variadic(const std::vector<RefinementId>& refis);
RefinementId negation(RefinementId refinement);
RefinementId conjunction(RefinementId lhs, RefinementId rhs);
RefinementId disjunction(RefinementId lhs, RefinementId rhs);
RefinementId equivalence(RefinementId lhs, RefinementId rhs);
RefinementId proposition(DefId def, TypeId discriminantTy);

private:
TypedAllocator<Refinement> allocator;
};

} // namespace Luau
13 changes: 5 additions & 8 deletions Analysis/include/Luau/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,12 @@ using DcrMagicFunction = bool (*)(MagicFunctionCallContext);

struct MagicRefinementContext
{
ScopePtr scope;
NotNull<struct ConstraintGraphBuilder> cgb;
NotNull<const DataFlowGraph> dfg;
NotNull<RefinementArena> refinementArena;
std::vector<RefinementId> argumentRefinements;
NotNull<Scope> scope;
const class AstExprCall* callSite;
std::vector<std::optional<TypeId>> discriminantTypes;
};

using DcrMagicRefinement = std::vector<RefinementId> (*)(const MagicRefinementContext&);
using DcrMagicRefinement = void (*)(const MagicRefinementContext&);

struct FunctionType
{
Expand Down Expand Up @@ -304,8 +301,8 @@ struct FunctionType
TypePackId argTypes;
TypePackId retTypes;
MagicFunction magicFunction = nullptr;
DcrMagicFunction dcrMagicFunction = nullptr; // Fired only while solving constraints
DcrMagicRefinement dcrMagicRefinement = nullptr; // Fired only while generating constraints
DcrMagicFunction dcrMagicFunction = nullptr;
DcrMagicRefinement dcrMagicRefinement = nullptr;
bool hasSelf;
bool hasNoGenerics = false;
};
Expand Down
14 changes: 10 additions & 4 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ class TimeLimitError : public InternalCompilerError
}
};

enum class ValueContext
{
LValue,
RValue
};

// All Types are retained via Environment::types. All TypeIds
// within a program are borrowed pointers into this set.
struct TypeChecker
Expand Down Expand Up @@ -119,14 +125,14 @@ struct TypeChecker
std::optional<TypeId> expectedType);

// Returns the type of the lvalue.
TypeId checkLValue(const ScopePtr& scope, const AstExpr& expr);
TypeId checkLValue(const ScopePtr& scope, const AstExpr& expr, ValueContext ctx);

// Returns the type of the lvalue.
TypeId checkLValueBinding(const ScopePtr& scope, const AstExpr& expr);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExpr& expr, ValueContext ctx);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprLocal& expr);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprGlobal& expr);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprIndexName& expr);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprIndexExpr& expr);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprIndexName& expr, ValueContext ctx);
TypeId checkLValueBinding(const ScopePtr& scope, const AstExprIndexExpr& expr, ValueContext ctx);

TypeId checkFunctionName(const ScopePtr& scope, AstExpr& funName, TypeLevel level);
std::pair<TypeId, ScopePtr> checkFunctionSignature(const ScopePtr& scope, int subLevel, const AstExprFunction& expr,
Expand Down
12 changes: 0 additions & 12 deletions Analysis/src/BuiltinDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ static bool dcrMagicFunctionSelect(MagicFunctionCallContext context);
static bool dcrMagicFunctionRequire(MagicFunctionCallContext context);
static bool dcrMagicFunctionPack(MagicFunctionCallContext context);

static std::vector<RefinementId> dcrMagicRefinementAssert(const MagicRefinementContext& context);

TypeId makeUnion(TypeArena& arena, std::vector<TypeId>&& types)
{
return arena.addType(UnionType{std::move(types)});
Expand Down Expand Up @@ -422,7 +420,6 @@ void registerBuiltinGlobals(Frontend& frontend)
}

attachMagicFunction(getGlobalBinding(frontend, "assert"), magicFunctionAssert);
attachDcrMagicRefinement(getGlobalBinding(frontend, "assert"), dcrMagicRefinementAssert);
attachMagicFunction(getGlobalBinding(frontend, "setmetatable"), magicFunctionSetMetaTable);
attachMagicFunction(getGlobalBinding(frontend, "select"), magicFunctionSelect);
attachDcrMagicFunction(getGlobalBinding(frontend, "select"), dcrMagicFunctionSelect);
Expand Down Expand Up @@ -624,15 +621,6 @@ static std::optional<WithPredicate<TypePackId>> magicFunctionAssert(
return WithPredicate<TypePackId>{arena.addTypePack(TypePack{std::move(head), tail})};
}

static std::vector<RefinementId> dcrMagicRefinementAssert(const MagicRefinementContext& ctx)
{
if (ctx.argumentRefinements.empty())
return {};

ctx.cgb->applyRefinements(ctx.scope, ctx.callSite->location, ctx.argumentRefinements[0]);
return {};
}

static std::optional<WithPredicate<TypePackId>> magicFunctionPack(
TypeChecker& typechecker, const ScopePtr& scope, const AstExprCall& expr, WithPredicate<TypePackId> withPredicate)
{
Expand Down
1 change: 1 addition & 0 deletions Analysis/src/Clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log, bool alwaysCl
clone.genericPacks = ftv->genericPacks;
clone.magicFunction = ftv->magicFunction;
clone.dcrMagicFunction = ftv->dcrMagicFunction;
clone.dcrMagicRefinement = ftv->dcrMagicRefinement;
clone.tags = ftv->tags;
clone.argNames = ftv->argNames;
result = dest.addType(std::move(clone));
Expand Down
Loading

0 comments on commit c5089de

Please sign in to comment.