Skip to content

Commit

Permalink
Merge 01f36ef into e13f17e
Browse files Browse the repository at this point in the history
  • Loading branch information
rblanckaert committed May 26, 2022
2 parents e13f17e + 01f36ef commit d174fd1
Show file tree
Hide file tree
Showing 69 changed files with 3,830 additions and 1,719 deletions.
16 changes: 2 additions & 14 deletions Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
#include <vector>
#include <optional>

LUAU_FASTFLAG(LuauSeparateTypechecks)
LUAU_FASTFLAG(LuauDirtySourceModule)

namespace Luau
{

Expand Down Expand Up @@ -60,17 +57,12 @@ struct SourceNode
{
bool hasDirtySourceModule() const
{
LUAU_ASSERT(FFlag::LuauDirtySourceModule);

return dirtySourceModule;
}

bool hasDirtyModule(bool forAutocomplete) const
{
if (FFlag::LuauSeparateTypechecks)
return forAutocomplete ? dirtyModuleForAutocomplete : dirtyModule;
else
return dirtyModule;
return forAutocomplete ? dirtyModuleForAutocomplete : dirtyModule;
}

ModuleName name;
Expand All @@ -90,10 +82,6 @@ struct FrontendOptions
// is complete.
bool retainFullTypeGraphs = false;

// When true, we run typechecking twice, once in the regular mode, and once in strict mode
// in order to get more precise type information (e.g. for autocomplete).
bool typecheckTwice_DEPRECATED = false;

// Run typechecking only in mode required for autocomplete (strict mode in order to get more precise type information)
bool forAutocomplete = false;
};
Expand Down Expand Up @@ -171,7 +159,7 @@ struct Frontend
void applyBuiltinDefinitionToEnvironment(const std::string& environmentName, const std::string& definitionName);

private:
std::pair<SourceNode*, SourceModule*> getSourceNode(CheckResult& checkResult, const ModuleName& name, bool forAutocomplete_DEPRECATED);
std::pair<SourceNode*, SourceModule*> getSourceNode(CheckResult& checkResult, const ModuleName& name);
SourceModule parse(const ModuleName& name, std::string_view src, const ParseOptions& parseOptions);

bool parseGraph(std::vector<ModuleName>& buildQueue, CheckResult& checkResult, const ModuleName& root, bool forAutocomplete);
Expand Down
53 changes: 53 additions & 0 deletions Analysis/include/Luau/Instantiation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include "Luau/Substitution.h"
#include "Luau/TypeVar.h"
#include "Luau/Unifiable.h"

namespace Luau
{

struct TypeArena;
struct TxnLog;

// A substitution which replaces generic types in a given set by free types.
struct ReplaceGenerics : Substitution
{
ReplaceGenerics(
const TxnLog* log, TypeArena* arena, TypeLevel level, const std::vector<TypeId>& generics, const std::vector<TypePackId>& genericPacks)
: Substitution(log, arena)
, level(level)
, generics(generics)
, genericPacks(genericPacks)
{
}

TypeLevel level;
std::vector<TypeId> generics;
std::vector<TypePackId> genericPacks;
bool ignoreChildren(TypeId ty) override;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId tp) override;
};

// A substitution which replaces generic functions by monomorphic functions
struct Instantiation : Substitution
{
Instantiation(const TxnLog* log, TypeArena* arena, TypeLevel level)
: Substitution(log, arena)
, level(level)
{
}

TypeLevel level;
bool ignoreChildren(TypeId ty) override;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId tp) override;
};

} // namespace Luau
2 changes: 1 addition & 1 deletion Analysis/include/Luau/TypeArena.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ struct TypeArena
void freeze(TypeArena& arena);
void unfreeze(TypeArena& arena);

}
} // namespace Luau
39 changes: 0 additions & 39 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,45 +34,6 @@ const AstStat* getFallthrough(const AstStat* node);
struct UnifierOptions;
struct Unifier;

// A substitution which replaces generic types in a given set by free types.
struct ReplaceGenerics : Substitution
{
ReplaceGenerics(
const TxnLog* log, TypeArena* arena, TypeLevel level, const std::vector<TypeId>& generics, const std::vector<TypePackId>& genericPacks)
: Substitution(log, arena)
, level(level)
, generics(generics)
, genericPacks(genericPacks)
{
}

TypeLevel level;
std::vector<TypeId> generics;
std::vector<TypePackId> genericPacks;
bool ignoreChildren(TypeId ty) override;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId tp) override;
};

// A substitution which replaces generic functions by monomorphic functions
struct Instantiation : Substitution
{
Instantiation(const TxnLog* log, TypeArena* arena, TypeLevel level)
: Substitution(log, arena)
, level(level)
{
}

TypeLevel level;
bool ignoreChildren(TypeId ty) override;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId tp) override;
};

// A substitution which replaces free types by any
struct Anyification : Substitution
{
Expand Down
3 changes: 3 additions & 0 deletions Analysis/include/Luau/Unifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ struct Widen : Substitution
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId ty) override;
bool ignoreChildren(TypeId ty) override;

TypeId operator()(TypeId ty);
TypePackId operator()(TypePackId ty);
};

// TODO: Use this more widely.
Expand Down
1 change: 0 additions & 1 deletion Analysis/include/Luau/UnifierSharedState.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ struct UnifierSharedState

InternalErrorReporter* iceHandler;

DenseHashSet<void*> seenAny{nullptr};
DenseHashMap<TypeId, bool> skipCacheForType{nullptr};
DenseHashSet<std::pair<TypeId, TypeId>, TypeIdPairHash> cachedUnify{{nullptr, nullptr}};
DenseHashMap<std::pair<TypeId, TypeId>, TypeErrorData, TypeIdPairHash> cachedUnifyError{{nullptr, nullptr}};
Expand Down
196 changes: 0 additions & 196 deletions Analysis/include/Luau/VisitTypeVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "Luau/TypePack.h"
#include "Luau/TypeVar.h"

LUAU_FASTFLAG(LuauUseVisitRecursionLimit)
LUAU_FASTINT(LuauVisitRecursionLimit)
LUAU_FASTFLAG(LuauNormalizeFlagIsConservative)

Expand Down Expand Up @@ -62,168 +61,6 @@ inline void unsee(DenseHashSet<void*>& seen, const void* tv)
// When DenseHashSet is used for 'visitTypeVarOnce', where don't forget visited elements
}

template<typename F, typename Set>
void visit(TypePackId tp, F& f, Set& seen);

template<typename F, typename Set>
void visit(TypeId ty, F& f, Set& seen)
{
if (visit_detail::hasSeen(seen, ty))
{
f.cycle(ty);
return;
}

if (auto btv = get<BoundTypeVar>(ty))
{
if (apply(ty, *btv, seen, f))
visit(btv->boundTo, f, seen);
}

else if (auto ftv = get<FreeTypeVar>(ty))
apply(ty, *ftv, seen, f);

else if (auto gtv = get<GenericTypeVar>(ty))
apply(ty, *gtv, seen, f);

else if (auto etv = get<ErrorTypeVar>(ty))
apply(ty, *etv, seen, f);

else if (auto ctv = get<ConstrainedTypeVar>(ty))
{
if (apply(ty, *ctv, seen, f))
{
for (TypeId part : ctv->parts)
visit(part, f, seen);
}
}

else if (auto ptv = get<PrimitiveTypeVar>(ty))
apply(ty, *ptv, seen, f);

else if (auto ftv = get<FunctionTypeVar>(ty))
{
if (apply(ty, *ftv, seen, f))
{
visit(ftv->argTypes, f, seen);
visit(ftv->retType, f, seen);
}
}

else if (auto ttv = get<TableTypeVar>(ty))
{
// Some visitors want to see bound tables, that's why we visit the original type
if (apply(ty, *ttv, seen, f))
{
if (ttv->boundTo)
{
visit(*ttv->boundTo, f, seen);
}
else
{
for (auto& [_name, prop] : ttv->props)
visit(prop.type, f, seen);

if (ttv->indexer)
{
visit(ttv->indexer->indexType, f, seen);
visit(ttv->indexer->indexResultType, f, seen);
}
}
}
}

else if (auto mtv = get<MetatableTypeVar>(ty))
{
if (apply(ty, *mtv, seen, f))
{
visit(mtv->table, f, seen);
visit(mtv->metatable, f, seen);
}
}

else if (auto ctv = get<ClassTypeVar>(ty))
{
if (apply(ty, *ctv, seen, f))
{
for (const auto& [name, prop] : ctv->props)
visit(prop.type, f, seen);

if (ctv->parent)
visit(*ctv->parent, f, seen);

if (ctv->metatable)
visit(*ctv->metatable, f, seen);
}
}

else if (auto atv = get<AnyTypeVar>(ty))
apply(ty, *atv, seen, f);

else if (auto utv = get<UnionTypeVar>(ty))
{
if (apply(ty, *utv, seen, f))
{
for (TypeId optTy : utv->options)
visit(optTy, f, seen);
}
}

else if (auto itv = get<IntersectionTypeVar>(ty))
{
if (apply(ty, *itv, seen, f))
{
for (TypeId partTy : itv->parts)
visit(partTy, f, seen);
}
}

visit_detail::unsee(seen, ty);
}

template<typename F, typename Set>
void visit(TypePackId tp, F& f, Set& seen)
{
if (visit_detail::hasSeen(seen, tp))
{
f.cycle(tp);
return;
}

if (auto btv = get<BoundTypePack>(tp))
{
if (apply(tp, *btv, seen, f))
visit(btv->boundTo, f, seen);
}

else if (auto ftv = get<Unifiable::Free>(tp))
apply(tp, *ftv, seen, f);

else if (auto gtv = get<Unifiable::Generic>(tp))
apply(tp, *gtv, seen, f);

else if (auto etv = get<Unifiable::Error>(tp))
apply(tp, *etv, seen, f);

else if (auto pack = get<TypePack>(tp))
{
apply(tp, *pack, seen, f);

for (TypeId ty : pack->head)
visit(ty, f, seen);

if (pack->tail)
visit(*pack->tail, f, seen);
}
else if (auto pack = get<VariadicTypePack>(tp))
{
apply(tp, *pack, seen, f);
visit(pack->ty, f, seen);
}

visit_detail::unsee(seen, tp);
}

} // namespace visit_detail

template<typename S>
Expand Down Expand Up @@ -513,37 +350,4 @@ struct TypeVarOnceVisitor : GenericTypeVarVisitor<DenseHashSet<void*>>
}
};

// Clip with FFlagLuauUseVisitRecursionLimit
template<typename TID, typename F>
void DEPRECATED_visitTypeVar(TID ty, F& f, std::unordered_set<void*>& seen)
{
visit_detail::visit(ty, f, seen);
}

// Delete and inline when clipping FFlagLuauUseVisitRecursionLimit
template<typename TID, typename F>
void DEPRECATED_visitTypeVar(TID ty, F& f)
{
if (FFlag::LuauUseVisitRecursionLimit)
f.traverse(ty);
else
{
std::unordered_set<void*> seen;
visit_detail::visit(ty, f, seen);
}
}

// Delete and inline when clipping FFlagLuauUseVisitRecursionLimit
template<typename TID, typename F>
void DEPRECATED_visitTypeVarOnce(TID ty, F& f, DenseHashSet<void*>& seen)
{
if (FFlag::LuauUseVisitRecursionLimit)
f.traverse(ty);
else
{
seen.clear();
visit_detail::visit(ty, f, seen);
}
}

} // namespace Luau
Loading

0 comments on commit d174fd1

Please sign in to comment.