Skip to content

Commit

Permalink
Sync to upstream/release/540 (#635)
Browse files Browse the repository at this point in the history
Also adjust benchmark runs to use config=profile and run clang for all benchmarks + gcc for runtime
  • Loading branch information
zeux committed Aug 11, 2022
1 parent 2c40b76 commit f7d8ad0
Show file tree
Hide file tree
Showing 50 changed files with 2,187 additions and 426 deletions.
38 changes: 28 additions & 10 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ on:

jobs:
callgrind:
name: callgrind ${{ matrix.compiler }}
name: callgrind
strategy:
fail-fast: false
matrix:
os: [ubuntu-22.04]
compiler: [g++]
benchResultsRepo:
- { name: "luau-lang/benchmark-data", branch: "main" }

Expand All @@ -31,12 +30,23 @@ jobs:
run: |
sudo apt-get install valgrind
- name: Build Luau
run: CXX=${{ matrix.compiler }} make config=release CALLGRIND=1 luau luau-analyze
- name: Build Luau (gcc)
run: |
CXX=g++ make config=profile luau
cp luau luau-gcc
- name: Build Luau (clang)
run: |
make config=profile clean
CXX=clang++ make config=profile luau luau-analyze
- name: Run benchmark (bench-gcc)
run: |
python bench/bench.py --callgrind --vm "./luau-gcc -O2" | tee -a bench-gcc-output.txt
- name: Run benchmark (bench)
- name: Run benchmark (bench-clang)
run: |
python bench/bench.py --callgrind --vm "./luau -O2" | tee -a bench-output.txt
python bench/bench.py --callgrind --vm "./luau -O2" | tee -a bench-clang-output.txt
- name: Run benchmark (analyze)
run: |
Expand Down Expand Up @@ -68,13 +78,21 @@ jobs:
token: ${{ secrets.BENCH_GITHUB_TOKEN }}
path: "./gh-pages"

- name: Store results (bench)
- name: Store results (bench-clang)
uses: Roblox/rhysd-github-action-benchmark@v-luau
with:
name: callgrind clang
tool: "benchmarkluau"
output-file-path: ./bench-clang-output.txt
external-data-json-path: ./gh-pages/bench-clang.json

- name: Store results (bench-gcc)
uses: Roblox/rhysd-github-action-benchmark@v-luau
with:
name: callgrind ${{ matrix.compiler }}
name: callgrind gcc
tool: "benchmarkluau"
output-file-path: ./bench-output.txt
external-data-json-path: ./gh-pages/bench.json
output-file-path: ./bench-gcc-output.txt
external-data-json-path: ./gh-pages/bench-gcc.json

- name: Store results (analyze)
uses: Roblox/rhysd-github-action-benchmark@v-luau
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Clone.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ TypePackId clone(TypePackId tp, TypeArena& dest, CloneState& cloneState);
TypeId clone(TypeId tp, TypeArena& dest, CloneState& cloneState);
TypeFun clone(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState);

TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log);
TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log, bool alwaysClone = false);

} // namespace Luau
7 changes: 5 additions & 2 deletions Analysis/include/Luau/ConstraintGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct ConstraintGraphBuilder
std::vector<std::pair<Location, ScopePtr>> scopes;

ModuleName moduleName;
ModulePtr module;
SingletonTypes& singletonTypes;
const NotNull<TypeArena> arena;
// The root scope of the module we're generating constraints for.
Expand All @@ -53,9 +54,9 @@ struct ConstraintGraphBuilder
// Occasionally constraint generation needs to produce an ICE.
const NotNull<InternalErrorReporter> ice;

NotNull<Scope> globalScope;
ScopePtr globalScope;

ConstraintGraphBuilder(const ModuleName& moduleName, TypeArena* arena, NotNull<InternalErrorReporter> ice, NotNull<Scope> globalScope);
ConstraintGraphBuilder(const ModuleName& moduleName, ModulePtr module, TypeArena* arena, NotNull<InternalErrorReporter> ice, const ScopePtr& globalScope);

/**
* Fabricates a new free type belonging to a given scope.
Expand Down Expand Up @@ -103,6 +104,7 @@ struct ConstraintGraphBuilder
void visit(const ScopePtr& scope, AstStatBlock* block);
void visit(const ScopePtr& scope, AstStatLocal* local);
void visit(const ScopePtr& scope, AstStatFor* for_);
void visit(const ScopePtr& scope, AstStatWhile* while_);
void visit(const ScopePtr& scope, AstStatLocalFunction* function);
void visit(const ScopePtr& scope, AstStatFunction* function);
void visit(const ScopePtr& scope, AstStatReturn* ret);
Expand Down Expand Up @@ -131,6 +133,7 @@ struct ConstraintGraphBuilder
TypeId check(const ScopePtr& scope, AstExprIndexExpr* indexExpr);
TypeId check(const ScopePtr& scope, AstExprUnary* unary);
TypeId check(const ScopePtr& scope, AstExprBinary* binary);
TypeId check(const ScopePtr& scope, AstExprTypeAssertion* typeAssert);

struct FunctionSignature
{
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ struct Frontend

LoadDefinitionFileResult loadDefinitionFile(std::string_view source, const std::string& packageName);

NotNull<Scope> getGlobalScope();
ScopePtr getGlobalScope();

private:
ModulePtr check(const SourceModule& sourceModule, Mode mode, const ScopePtr& environmentScope);
Expand Down
1 change: 1 addition & 0 deletions Analysis/include/Luau/Linter.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct LintWarning
Code_MisleadingAndOr = 25,
Code_CommentDirective = 26,
Code_IntegerParsing = 27,
Code_ComparisonPrecedence = 28,

Code__Count
};
Expand Down
4 changes: 0 additions & 4 deletions Analysis/include/Luau/Scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ struct Scope
// All the children of this scope.
std::vector<NotNull<Scope>> children;
std::unordered_map<Symbol, Binding> bindings;
std::unordered_map<Name, TypeFun> typeBindings;
std::unordered_map<Name, TypePackId> typePackBindings;
TypePackId returnType;
std::optional<TypePackId> varargPack;
// All constraints belonging to this scope.
Expand All @@ -52,8 +50,6 @@ struct Scope
std::unordered_map<Name, std::unordered_map<Name, TypeFun>> importedTypeBindings;

std::optional<TypeId> lookup(Symbol sym);
std::optional<TypeFun> lookupTypeBinding(const Name& name);
std::optional<TypePackId> lookupTypePackBinding(const Name& name);

std::optional<TypeFun> lookupType(const Name& name);
std::optional<TypeFun> lookupImportedType(const Name& moduleAlias, const Name& name);
Expand Down
5 changes: 5 additions & 0 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <unordered_map>
#include <unordered_set>

LUAU_FASTFLAG(LuauClassTypeVarsInSubstitution)

namespace Luau
{

Expand Down Expand Up @@ -57,6 +59,9 @@ struct Anyification : Substitution

bool ignoreChildren(TypeId ty) override
{
if (FFlag::LuauClassTypeVarsInSubstitution && get<ClassTypeVar>(ty))
return true;

return ty->persistent;
}
bool ignoreChildren(TypePackId ty) override
Expand Down
7 changes: 5 additions & 2 deletions Analysis/include/Luau/TypeVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,7 @@ struct TypeIterator
stack.push_front({t, 0});

seen.insert(t);
descend();
}

TypeIterator<T>& operator++()
Expand Down Expand Up @@ -748,17 +749,19 @@ struct TypeIterator

const TypeId& operator*()
{
LUAU_ASSERT(!stack.empty());

descend();

LUAU_ASSERT(!stack.empty());

auto [t, currentIndex] = stack.front();
LUAU_ASSERT(t);

const std::vector<TypeId>& types = getTypes(t);
LUAU_ASSERT(currentIndex < types.size());

const TypeId& ty = types[currentIndex];
LUAU_ASSERT(!get<T>(follow(ty)));

return ty;
}

Expand Down
10 changes: 5 additions & 5 deletions Analysis/include/Luau/Unifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ struct Unifier
public:
void unifyLowerBound(TypePackId subTy, TypePackId superTy, TypeLevel demotedLevel);

// Report an "infinite type error" if the type "needle" already occurs within "haystack"
void occursCheck(TypeId needle, TypeId haystack);
void occursCheck(DenseHashSet<TypeId>& seen, TypeId needle, TypeId haystack);
void occursCheck(TypePackId needle, TypePackId haystack);
void occursCheck(DenseHashSet<TypePackId>& seen, TypePackId needle, TypePackId haystack);
// Returns true if the type "needle" already occurs within "haystack" and reports an "infinite type error"
bool occursCheck(TypeId needle, TypeId haystack);
bool occursCheck(DenseHashSet<TypeId>& seen, TypeId needle, TypeId haystack);
bool occursCheck(TypePackId needle, TypePackId haystack);
bool occursCheck(DenseHashSet<TypePackId>& seen, TypePackId needle, TypePackId haystack);

Unifier makeChildUnifier();

Expand Down
4 changes: 4 additions & 0 deletions Analysis/src/ApplyTypeFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "Luau/ApplyTypeFunction.h"

LUAU_FASTFLAG(LuauClassTypeVarsInSubstitution)

namespace Luau
{

Expand Down Expand Up @@ -31,6 +33,8 @@ bool ApplyTypeFunction::ignoreChildren(TypeId ty)
{
if (get<GenericTypeVar>(ty))
return true;
else if (FFlag::LuauClassTypeVarsInSubstitution && get<ClassTypeVar>(ty))
return true;
else
return false;
}
Expand Down
12 changes: 11 additions & 1 deletion Analysis/src/Clone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "Luau/Unifiable.h"

LUAU_FASTFLAG(DebugLuauCopyBeforeNormalizing)
LUAU_FASTFLAG(LuauClonePublicInterfaceLess)

LUAU_FASTINTVARIABLE(LuauTypeCloneRecursionLimit, 300)

Expand Down Expand Up @@ -445,7 +446,7 @@ TypeFun clone(const TypeFun& typeFun, TypeArena& dest, CloneState& cloneState)
return result;
}

TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log)
TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log, bool alwaysClone)
{
ty = log->follow(ty);

Expand Down Expand Up @@ -504,6 +505,15 @@ TypeId shallowClone(TypeId ty, TypeArena& dest, const TxnLog* log)
PendingExpansionTypeVar clone{petv->fn, petv->typeArguments, petv->packArguments};
result = dest.addType(std::move(clone));
}
else if (const ClassTypeVar* ctv = get<ClassTypeVar>(ty); FFlag::LuauClonePublicInterfaceLess && ctv && alwaysClone)
{
ClassTypeVar clone{ctv->name, ctv->props, ctv->parent, ctv->metatable, ctv->tags, ctv->userData, ctv->definitionModuleName};
result = dest.addType(std::move(clone));
}
else if (FFlag::LuauClonePublicInterfaceLess && alwaysClone)
{
result = dest.addType(*ty);
}
else
return result;

Expand Down
Loading

0 comments on commit f7d8ad0

Please sign in to comment.