Skip to content

Commit

Permalink
Sync to upstream/release/581 (#958)
Browse files Browse the repository at this point in the history
* Definition files can now ascribe indexers to class types.
(#949)
* Remove --compile support from the REPL. You can just use luau-compile
instead.
* When an exception is thrown during parallel typechecking (usually an
ICE), we now gracefully stop typechecking and drain active workers
before rethrowing the exception.

New solver

* Include more source location information when we hit an internal
compiler error
* Improve the logic that simplifies intersections of tables

JIT

* Save testable type annotations to bytecode
* Improve block placement for linearized blocks
* Add support for lea reg, [rip+offset] for labels
* Unify X64 and A64 codegen for RETURN
* Outline interrupt handlers for X64
* Remove global rArgN in favor of build.abi
* Change A64 INTERRUPT lowering to match X64

---------

Co-authored-by: Arseny Kapoulkine <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
3 people authored Jun 16, 2023
1 parent bc07224 commit d458d24
Show file tree
Hide file tree
Showing 42 changed files with 968 additions and 612 deletions.
8 changes: 4 additions & 4 deletions Analysis/include/Luau/ConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ struct ConstraintSolver
bool blockOnPendingTypes(TypePackId target, NotNull<const Constraint> constraint);

void unblock(NotNull<const Constraint> progressed);
void unblock(TypeId progressed);
void unblock(TypePackId progressed);
void unblock(const std::vector<TypeId>& types);
void unblock(const std::vector<TypePackId>& packs);
void unblock(TypeId progressed, Location location);
void unblock(TypePackId progressed, Location location);
void unblock(const std::vector<TypeId>& types, Location location);
void unblock(const std::vector<TypePackId>& packs, Location location);

/**
* @returns true if the TypeId is in a blocked state.
Expand Down
140 changes: 70 additions & 70 deletions Analysis/src/ConstraintSolver.cpp

Large diffs are not rendered by default.

49 changes: 40 additions & 9 deletions Analysis/src/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ LUAU_FASTINTVARIABLE(LuauAutocompleteCheckTimeoutMs, 100)
LUAU_FASTFLAGVARIABLE(DebugLuauDeferredConstraintResolution, false)
LUAU_FASTFLAGVARIABLE(DebugLuauLogSolverToJson, false)
LUAU_FASTFLAGVARIABLE(DebugLuauReadWriteProperties, false)
LUAU_FASTFLAGVARIABLE(LuauFixBuildQueueExceptionUnwrap, false)

namespace Luau
{
Expand Down Expand Up @@ -596,24 +597,33 @@ std::vector<ModuleName> Frontend::checkQueuedModules(std::optional<FrontendOptio
sendCycleItemTask();

std::vector<size_t> nextItems;
std::optional<size_t> itemWithException;

while (remaining != 0)
{
{
std::unique_lock guard(mtx);

// If nothing is ready yet, wait
if (readyQueueItems.empty())
{
cv.wait(guard, [&readyQueueItems] {
return !readyQueueItems.empty();
});
}
cv.wait(guard, [&readyQueueItems] {
return !readyQueueItems.empty();
});

// Handle checked items
for (size_t i : readyQueueItems)
{
const BuildQueueItem& item = buildQueueItems[i];

if (FFlag::LuauFixBuildQueueExceptionUnwrap)
{
// If exception was thrown, stop adding new items and wait for processing items to complete
if (item.exception)
itemWithException = i;

if (itemWithException)
break;
}

recordItemResult(item);

// Notify items that were waiting for this dependency
Expand Down Expand Up @@ -648,7 +658,16 @@ std::vector<ModuleName> Frontend::checkQueuedModules(std::optional<FrontendOptio

// If we aren't done, but don't have anything processing, we hit a cycle
if (remaining != 0 && processing == 0)
{
// We might have stopped because of a pending exception
if (FFlag::LuauFixBuildQueueExceptionUnwrap && itemWithException)
{
recordItemResult(buildQueueItems[*itemWithException]);
break;
}

sendCycleItemTask();
}
}

std::vector<ModuleName> checkedModules;
Expand Down Expand Up @@ -1104,6 +1123,8 @@ ModulePtr check(const SourceModule& sourceModule, const std::vector<RequireCycle
result->name = sourceModule.name;
result->humanReadableName = sourceModule.humanReadableName;

iceHandler->moduleName = sourceModule.name;

std::unique_ptr<DcrLogger> logger;
if (recordJsonLog)
{
Expand Down Expand Up @@ -1189,9 +1210,19 @@ ModulePtr Frontend::check(const SourceModule& sourceModule, Mode mode, std::vect
prepareModuleScope(name, scope, forAutocomplete);
};

return Luau::check(sourceModule, requireCycles, builtinTypes, NotNull{&iceHandler},
NotNull{forAutocomplete ? &moduleResolverForAutocomplete : &moduleResolver}, NotNull{fileResolver},
environmentScope ? *environmentScope : globals.globalScope, prepareModuleScopeWrap, options, recordJsonLog);
try
{
return Luau::check(sourceModule, requireCycles, builtinTypes, NotNull{&iceHandler},
NotNull{forAutocomplete ? &moduleResolverForAutocomplete : &moduleResolver}, NotNull{fileResolver},
environmentScope ? *environmentScope : globals.globalScope, prepareModuleScopeWrap, options, recordJsonLog);
}
catch (const InternalCompilerError& err)
{
InternalCompilerError augmented = err.location.has_value()
? InternalCompilerError{err.message, sourceModule.humanReadableName, *err.location}
: InternalCompilerError{err.message, sourceModule.humanReadableName};
throw augmented;
}
}
else
{
Expand Down
8 changes: 4 additions & 4 deletions Analysis/src/Normalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2117,15 +2117,15 @@ std::optional<TypeId> Normalizer::intersectionOfTables(TypeId here, TypeId there
TypeId hmtable = nullptr;
if (const MetatableType* hmtv = get<MetatableType>(here))
{
htable = hmtv->table;
hmtable = hmtv->metatable;
htable = follow(hmtv->table);
hmtable = follow(hmtv->metatable);
}
TypeId ttable = there;
TypeId tmtable = nullptr;
if (const MetatableType* tmtv = get<MetatableType>(there))
{
ttable = tmtv->table;
tmtable = tmtv->metatable;
ttable = follow(tmtv->table);
tmtable = follow(tmtv->metatable);
}

const TableType* httv = get<TableType>(htable);
Expand Down
12 changes: 12 additions & 0 deletions Analysis/src/Simplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Luau/ToString.h"
#include "Luau/TypeArena.h"
#include "Luau/Normalize.h" // TypeIds
#include <algorithm>

LUAU_FASTINT(LuauTypeReductionRecursionLimit)

Expand Down Expand Up @@ -236,6 +237,17 @@ Relation relateTables(TypeId left, TypeId right)
NotNull<const TableType> leftTable{get<TableType>(left)};
NotNull<const TableType> rightTable{get<TableType>(right)};
LUAU_ASSERT(1 == rightTable->props.size());
// Disjoint props have nothing in common
// t1 with props p1's cannot appear in t2 and t2 with props p2's cannot appear in t1
bool foundPropFromLeftInRight = std::any_of(begin(leftTable->props), end(leftTable->props), [&](auto prop) {
return rightTable->props.find(prop.first) != end(rightTable->props);
});
bool foundPropFromRightInLeft = std::any_of(begin(rightTable->props), end(rightTable->props), [&](auto prop) {
return leftTable->props.find(prop.first) != end(leftTable->props);
});

if (!(foundPropFromLeftInRight || foundPropFromRightInLeft) && leftTable->props.size() >= 1 && rightTable->props.size() >= 1)
return Relation::Disjoint;

const auto [propName, rightProp] = *begin(rightTable->props);

Expand Down
7 changes: 5 additions & 2 deletions Analysis/src/Substitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,14 @@ static TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log, bool a
else if constexpr (std::is_same_v<T, GenericType>)
return dest.addType(a);
else if constexpr (std::is_same_v<T, BlockedType>)
return ty;
return dest.addType(a);
else if constexpr (std::is_same_v<T, PrimitiveType>)
return ty;
else if constexpr (std::is_same_v<T, PendingExpansionType>)
return ty;
{
PendingExpansionType clone = PendingExpansionType{a.prefix, a.name, a.typeArguments, a.packArguments};
return dest.addType(std::move(clone));
}
else if constexpr (std::is_same_v<T, AnyType>)
return ty;
else if constexpr (std::is_same_v<T, ErrorType>)
Expand Down
Loading

0 comments on commit d458d24

Please sign in to comment.