Skip to content

Commit

Permalink
Sync to upstream/release/584 (#977)
Browse files Browse the repository at this point in the history
* Added support for async typechecking cancellation using a token passed
through frontend options
* Added luaC_enumheap for building debug tools that need a graph of Luau
heap

In our new typechecker:
* Errors or now suppressed when checking property lookup of
error-suppressing unions

In our native code generation (jit):
* Fixed unhandled value type in NOT_ANY lowering
* Fast-call tag checks will exit to VM on failure, instead of relying on
a native fallback
* Added vector type to the type information
* Eliminated redundant direct jumps across dead blocks
* Debugger APIs are now disabled for call frames executing natively
* Implemented support for unwind registration on macOS 14
  • Loading branch information
vegorov-rbx committed Jul 14, 2023
1 parent e25de95 commit 2181591
Show file tree
Hide file tree
Showing 71 changed files with 1,854 additions and 527 deletions.
24 changes: 24 additions & 0 deletions Analysis/include/Luau/Cancellation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include <atomic>

namespace Luau
{

struct FrontendCancellationToken
{
void cancel()
{
cancelled.store(true);
}

bool requested()
{
return cancelled.load();
}

std::atomic<bool> cancelled;
};

} // namespace Luau
24 changes: 20 additions & 4 deletions Analysis/include/Luau/Differ.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ struct DiffPathNode
Kind kind;
// non-null when TableProperty
std::optional<Name> tableProperty;
// non-null when FunctionArgument, FunctionReturn, Union, or Intersection (i.e. anonymous fields)
std::optional<int> index;
// non-null when FunctionArgument (unless variadic arg), FunctionReturn (unless variadic arg), Union, or Intersection (i.e. anonymous fields)
std::optional<size_t> index;

/**
* Do not use for leaf nodes
Expand All @@ -32,7 +32,7 @@ struct DiffPathNode
{
}

DiffPathNode(Kind kind, std::optional<Name> tableProperty, std::optional<int> index)
DiffPathNode(Kind kind, std::optional<Name> tableProperty, std::optional<size_t> index)
: kind(kind)
, tableProperty(tableProperty)
, index(index)
Expand All @@ -42,19 +42,35 @@ struct DiffPathNode
std::string toString() const;

static DiffPathNode constructWithTableProperty(Name tableProperty);

static DiffPathNode constructWithKindAndIndex(Kind kind, size_t index);

static DiffPathNode constructWithKind(Kind kind);
};

struct DiffPathNodeLeaf
{
std::optional<TypeId> ty;
std::optional<Name> tableProperty;
DiffPathNodeLeaf(std::optional<TypeId> ty, std::optional<Name> tableProperty)
std::optional<int> minLength;
bool isVariadic;
DiffPathNodeLeaf(std::optional<TypeId> ty, std::optional<Name> tableProperty, std::optional<int> minLength, bool isVariadic)
: ty(ty)
, tableProperty(tableProperty)
, minLength(minLength)
, isVariadic(isVariadic)
{
}

static DiffPathNodeLeaf detailsNormal(TypeId ty);

static DiffPathNodeLeaf detailsTableProperty(TypeId ty, Name tableProperty);

static DiffPathNodeLeaf detailsLength(int minLength, bool isVariadic);

static DiffPathNodeLeaf nullopts();
};

struct DiffPath
{
std::vector<DiffPathNode> path;
Expand Down
14 changes: 7 additions & 7 deletions Analysis/include/Luau/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,13 @@ struct PackWhereClauseNeeded
bool operator==(const PackWhereClauseNeeded& rhs) const;
};

using TypeErrorData =
Variant<TypeMismatch, UnknownSymbol, UnknownProperty, NotATable, CannotExtendTable, OnlyTablesCanHaveMethods, DuplicateTypeDefinition,
CountMismatch, FunctionDoesNotTakeSelf, FunctionRequiresSelf, OccursCheckFailed, UnknownRequire, IncorrectGenericParameterCount, SyntaxError,
CodeTooComplex, UnificationTooComplex, UnknownPropButFoundLikeProp, GenericError, InternalError, CannotCallNonFunction, ExtraInformation,
DeprecatedApiUsed, ModuleHasCyclicDependency, IllegalRequire, FunctionExitsWithoutReturning, DuplicateGenericParameter,
CannotInferBinaryOperation, MissingProperties, SwappedGenericTypeParameter, OptionalValueAccess, MissingUnionProperty, TypesAreUnrelated,
NormalizationTooComplex, TypePackMismatch, DynamicPropertyLookupOnClassesUnsafe, UninhabitedTypeFamily, UninhabitedTypePackFamily, WhereClauseNeeded, PackWhereClauseNeeded>;
using TypeErrorData = Variant<TypeMismatch, UnknownSymbol, UnknownProperty, NotATable, CannotExtendTable, OnlyTablesCanHaveMethods,
DuplicateTypeDefinition, CountMismatch, FunctionDoesNotTakeSelf, FunctionRequiresSelf, OccursCheckFailed, UnknownRequire,
IncorrectGenericParameterCount, SyntaxError, CodeTooComplex, UnificationTooComplex, UnknownPropButFoundLikeProp, GenericError, InternalError,
CannotCallNonFunction, ExtraInformation, DeprecatedApiUsed, ModuleHasCyclicDependency, IllegalRequire, FunctionExitsWithoutReturning,
DuplicateGenericParameter, CannotInferBinaryOperation, MissingProperties, SwappedGenericTypeParameter, OptionalValueAccess, MissingUnionProperty,
TypesAreUnrelated, NormalizationTooComplex, TypePackMismatch, DynamicPropertyLookupOnClassesUnsafe, UninhabitedTypeFamily,
UninhabitedTypePackFamily, WhereClauseNeeded, PackWhereClauseNeeded>;

struct TypeErrorSummary
{
Expand Down
4 changes: 4 additions & 0 deletions Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ struct ModuleResolver;
struct ParseResult;
struct HotComment;
struct BuildQueueItem;
struct FrontendCancellationToken;

struct LoadDefinitionFileResult
{
Expand Down Expand Up @@ -96,6 +97,8 @@ struct FrontendOptions
std::optional<unsigned> randomizeConstraintResolutionSeed;

std::optional<LintOptions> enabledLintWarnings;

std::shared_ptr<FrontendCancellationToken> cancellationToken;
};

struct CheckResult
Expand Down Expand Up @@ -191,6 +194,7 @@ struct Frontend
std::optional<double> finishTime;
std::optional<int> instantiationChildLimit;
std::optional<int> unifierIterationLimit;
std::shared_ptr<FrontendCancellationToken> cancellationToken;
};

ModulePtr check(const SourceModule& sourceModule, Mode mode, std::vector<RequireCycle> requireCycles, std::optional<ScopePtr> environmentScope,
Expand Down
6 changes: 3 additions & 3 deletions Analysis/include/Luau/InsertionOrderedMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ struct InsertionOrderedMap
{
static_assert(std::is_trivially_copyable_v<K>, "key must be trivially copyable");

private:
private:
using vec = std::vector<std::pair<K, V>>;

public:
public:
using iterator = typename vec::iterator;
using const_iterator = typename vec::const_iterator;

Expand Down Expand Up @@ -131,4 +131,4 @@ struct InsertionOrderedMap
std::unordered_map<K, size_t> indices;
};

}
} // namespace Luau
1 change: 1 addition & 0 deletions Analysis/include/Luau/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct Module
Mode mode;
SourceCode::Type type;
bool timeout = false;
bool cancelled = false;

TypePackId returnType = nullptr;
std::unordered_map<Name, TypeFun> exportedTypeBindings;
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/ToString.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ std::string dump(const std::shared_ptr<Scope>& scope, const char* name);
std::string generateName(size_t n);

std::string toString(const Position& position);
std::string toString(const Location& location);
std::string toString(const Location& location, int offset = 0, bool useBegin = true);

} // namespace Luau
3 changes: 2 additions & 1 deletion Analysis/include/Luau/TypeChecker2.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace Luau
struct DcrLogger;
struct BuiltinTypes;

void check(NotNull<BuiltinTypes> builtinTypes, NotNull<struct UnifierSharedState> sharedState, DcrLogger* logger, const SourceModule& sourceModule, Module* module);
void check(NotNull<BuiltinTypes> builtinTypes, NotNull<struct UnifierSharedState> sharedState, DcrLogger* logger, const SourceModule& sourceModule,
Module* module);

} // namespace Luau
13 changes: 13 additions & 0 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace Luau
struct Scope;
struct TypeChecker;
struct ModuleResolver;
struct FrontendCancellationToken;

using Name = std::string;
using ScopePtr = std::shared_ptr<Scope>;
Expand Down Expand Up @@ -64,6 +65,15 @@ class TimeLimitError : public InternalCompilerError
}
};

class UserCancelError : public InternalCompilerError
{
public:
explicit UserCancelError(const std::string& moduleName)
: InternalCompilerError("Analysis has been cancelled by user", moduleName)
{
}
};

struct GlobalTypes
{
GlobalTypes(NotNull<BuiltinTypes> builtinTypes);
Expand Down Expand Up @@ -262,6 +272,7 @@ struct TypeChecker
[[noreturn]] void ice(const std::string& message, const Location& location);
[[noreturn]] void ice(const std::string& message);
[[noreturn]] void throwTimeLimitError();
[[noreturn]] void throwUserCancelError();

ScopePtr childFunctionScope(const ScopePtr& parent, const Location& location, int subLevel = 0);
ScopePtr childScope(const ScopePtr& parent, const Location& location);
Expand Down Expand Up @@ -387,6 +398,8 @@ struct TypeChecker
std::optional<int> instantiationChildLimit;
std::optional<int> unifierIterationLimit;

std::shared_ptr<FrontendCancellationToken> cancellationToken;

public:
const TypeId nilType;
const TypeId numberType;
Expand Down
3 changes: 1 addition & 2 deletions Analysis/include/Luau/Unifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ struct Unifier
std::vector<TypeId> blockedTypes;
std::vector<TypePackId> blockedTypePacks;

Unifier(
NotNull<Normalizer> normalizer, NotNull<Scope> scope, const Location& location, Variance variance, TxnLog* parentLog = nullptr);
Unifier(NotNull<Normalizer> normalizer, NotNull<Scope> scope, const Location& location, Variance variance, TxnLog* parentLog = nullptr);

// Configure the Unifier to test for scope subsumption via embedded Scope
// pointers rather than TypeLevels.
Expand Down
1 change: 0 additions & 1 deletion Analysis/src/Clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Luau/Unifiable.h"

LUAU_FASTFLAG(DebugLuauCopyBeforeNormalizing)
LUAU_FASTFLAG(LuauClonePublicInterfaceLess2)
LUAU_FASTFLAG(DebugLuauReadWriteProperties)

LUAU_FASTINTVARIABLE(LuauTypeCloneRecursionLimit, 300)
Expand Down
Loading

0 comments on commit 2181591

Please sign in to comment.