Skip to content

Commit

Permalink
Sync to upstream/release/514 (#372)
Browse files Browse the repository at this point in the history
  • Loading branch information
zeux authored Feb 18, 2022
1 parent 1ac64af commit 5b78465
Show file tree
Hide file tree
Showing 84 changed files with 1,492 additions and 574 deletions.
3 changes: 3 additions & 0 deletions Analysis/include/Luau/Documentation.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ struct BasicDocumentation
{
std::string documentation;
std::string learnMoreLink;
std::string codeSample;
};

struct FunctionParameterDocumentation
Expand All @@ -37,6 +38,7 @@ struct FunctionDocumentation
std::vector<FunctionParameterDocumentation> parameters;
std::vector<DocumentationSymbol> returns;
std::string learnMoreLink;
std::string codeSample;
};

struct OverloadedFunctionDocumentation
Expand All @@ -52,6 +54,7 @@ struct TableDocumentation
std::string documentation;
Luau::DenseHashMap<std::string, DocumentationSymbol> keys;
std::string learnMoreLink;
std::string codeSample;
};

using DocumentationDatabase = Luau::DenseHashMap<DocumentationSymbol, Documentation>;
Expand Down
3 changes: 2 additions & 1 deletion Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ struct TypeChecker;
struct FileResolver;
struct ModuleResolver;
struct ParseResult;
struct HotComment;

struct LoadDefinitionFileResult
{
Expand All @@ -35,7 +36,7 @@ struct LoadDefinitionFileResult
LoadDefinitionFileResult loadDefinitionFile(
TypeChecker& typeChecker, ScopePtr targetScope, std::string_view definition, const std::string& packageName);

std::optional<Mode> parseMode(const std::vector<std::string>& hotcomments);
std::optional<Mode> parseMode(const std::vector<HotComment>& hotcomments);

std::vector<std::string_view> parsePathExpr(const AstExpr& pathExpr);

Expand Down
7 changes: 5 additions & 2 deletions Analysis/include/Luau/Linter.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class AstStat;
class AstNameTable;
struct TypeChecker;
struct Module;
struct HotComment;

using ScopePtr = std::shared_ptr<struct Scope>;

Expand Down Expand Up @@ -50,6 +51,7 @@ struct LintWarning
Code_TableOperations = 23,
Code_DuplicateCondition = 24,
Code_MisleadingAndOr = 25,
Code_CommentDirective = 26,

Code__Count
};
Expand All @@ -60,7 +62,7 @@ struct LintWarning

static const char* getName(Code code);
static Code parseName(const char* name);
static uint64_t parseMask(const std::vector<std::string>& hotcomments);
static uint64_t parseMask(const std::vector<HotComment>& hotcomments);
};

struct LintResult
Expand Down Expand Up @@ -90,7 +92,8 @@ struct LintOptions
void setDefaults();
};

std::vector<LintWarning> lint(AstStat* root, const AstNameTable& names, const ScopePtr& env, const Module* module, const LintOptions& options);
std::vector<LintWarning> lint(AstStat* root, const AstNameTable& names, const ScopePtr& env, const Module* module,
const std::vector<HotComment>& hotcomments, const LintOptions& options);

std::vector<AstName> getDeprecatedGlobals(const AstNameTable& names);

Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/Module.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "Luau/TypedAllocator.h"
#include "Luau/ParseOptions.h"
#include "Luau/Error.h"
#include "Luau/Parser.h"
#include "Luau/ParseResult.h"

#include <memory>
#include <vector>
Expand Down Expand Up @@ -37,8 +37,8 @@ struct SourceModule

AstStatBlock* root = nullptr;
std::optional<Mode> mode;
uint64_t ignoreLints = 0;

std::vector<HotComment> hotcomments;
std::vector<Comment> commentLocations;

SourceModule()
Expand Down
5 changes: 1 addition & 4 deletions Analysis/include/Luau/Quantify.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
namespace Luau
{

struct Module;
using ModulePtr = std::shared_ptr<Module>;

void quantify(ModulePtr module, TypeId ty, TypeLevel level);
void quantify(TypeId ty, TypeLevel level);

} // namespace Luau
20 changes: 14 additions & 6 deletions Analysis/include/Luau/Substitution.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,6 @@ struct Tarjan
// This is hot code, so we optimize recursion to a stack.
TarjanResult loop();

// Clear the state
void clear();

// Find or create the index for a vertex.
// Return a boolean which is `true` if it's a freshly created index.
std::pair<int, bool> indexify(TypeId ty);
Expand Down Expand Up @@ -166,7 +163,17 @@ struct FindDirty : Tarjan
// and replaces them with clean ones.
struct Substitution : FindDirty
{
ModulePtr currentModule;
protected:
Substitution(const TxnLog* log_, TypeArena* arena)
: arena(arena)
{
log = log_;
LUAU_ASSERT(log);
LUAU_ASSERT(arena);
}

public:
TypeArena* arena;
DenseHashMap<TypeId, TypeId> newTypes{nullptr};
DenseHashMap<TypePackId, TypePackId> newPacks{nullptr};

Expand All @@ -192,12 +199,13 @@ struct Substitution : FindDirty
template<typename T>
TypeId addType(const T& tv)
{
return currentModule->internalTypes.addType(tv);
return arena->addType(tv);
}

template<typename T>
TypePackId addTypePack(const T& tp)
{
return currentModule->internalTypes.addTypePack(TypePackVar{tp});
return arena->addTypePack(TypePackVar{tp});
}
};

Expand Down
45 changes: 36 additions & 9 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Luau/Error.h"
#include "Luau/Module.h"
#include "Luau/Symbol.h"
#include "Luau/Parser.h"
#include "Luau/Substitution.h"
#include "Luau/TxnLog.h"
#include "Luau/TypePack.h"
Expand Down Expand Up @@ -37,6 +36,15 @@ 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;
Expand All @@ -50,8 +58,13 @@ struct ReplaceGenerics : Substitution
// 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;
ReplaceGenerics replaceGenerics;
bool ignoreChildren(TypeId ty) override;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
Expand All @@ -62,6 +75,12 @@ struct Instantiation : Substitution
// A substitution which replaces free types by generic types.
struct Quantification : Substitution
{
Quantification(TypeArena* arena, TypeLevel level)
: Substitution(TxnLog::empty(), arena)
, level(level)
{
}

TypeLevel level;
std::vector<TypeId> generics;
std::vector<TypePackId> genericPacks;
Expand All @@ -74,6 +93,13 @@ struct Quantification : Substitution
// A substitution which replaces free types by any
struct Anyification : Substitution
{
Anyification(TypeArena* arena, TypeId anyType, TypePackId anyTypePack)
: Substitution(TxnLog::empty(), arena)
, anyType(anyType)
, anyTypePack(anyTypePack)
{
}

TypeId anyType;
TypePackId anyTypePack;
bool isDirty(TypeId ty) override;
Expand All @@ -85,6 +111,13 @@ struct Anyification : Substitution
// A substitution which replaces the type parameters of a type function by arguments
struct ApplyTypeFunction : Substitution
{
ApplyTypeFunction(TypeArena* arena, TypeLevel level)
: Substitution(TxnLog::empty(), arena)
, level(level)
, encounteredForwardedType(false)
{
}

TypeLevel level;
bool encounteredForwardedType;
std::unordered_map<TypeId, TypeId> typeArguments;
Expand Down Expand Up @@ -351,8 +384,7 @@ struct TypeChecker

// Note: `scope` must be a fresh scope.
GenericTypeDefinitions createGenericTypes(const ScopePtr& scope, std::optional<TypeLevel> levelOpt, const AstNode& node,
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames,
bool useCache = false);
const AstArray<AstGenericType>& genericNames, const AstArray<AstGenericTypePack>& genericPackNames, bool useCache = false);

public:
ErrorVec resolve(const PredicateVec& predicates, const ScopePtr& scope, bool sense);
Expand Down Expand Up @@ -392,11 +424,6 @@ struct TypeChecker
ModulePtr currentModule;
ModuleName currentModuleName;

Instantiation instantiation;
Quantification quantification;
Anyification anyification;
ApplyTypeFunction applyTypeFunction;

std::function<void(const ModuleName&, const ScopePtr&)> prepareModuleScope;
InternalErrorReporter* iceHandler;

Expand Down
Loading

0 comments on commit 5b78465

Please sign in to comment.