Skip to content

Commit

Permalink
Sync to upstream/release/557 (#794)
Browse files Browse the repository at this point in the history
* Fixed unions of `nil` types displaying as `?`
* Internal normalization now handles class types which can make
previously failing (incorrectly) sub-typing checks to succeed
  • Loading branch information
vegorov-rbx authored Jan 4, 2023
1 parent fb2f146 commit 75a2e95
Show file tree
Hide file tree
Showing 117 changed files with 3,812 additions and 2,583 deletions.
8 changes: 4 additions & 4 deletions Analysis/include/Luau/Anyification.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "Luau/NotNull.h"
#include "Luau/Substitution.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"

#include <memory>

Expand All @@ -19,12 +19,12 @@ using ScopePtr = std::shared_ptr<Scope>;
// A substitution which replaces free types by any
struct Anyification : Substitution
{
Anyification(TypeArena* arena, NotNull<Scope> scope, NotNull<SingletonTypes> singletonTypes, InternalErrorReporter* iceHandler, TypeId anyType,
Anyification(TypeArena* arena, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
TypePackId anyTypePack);
Anyification(TypeArena* arena, const ScopePtr& scope, NotNull<SingletonTypes> singletonTypes, InternalErrorReporter* iceHandler, TypeId anyType,
Anyification(TypeArena* arena, const ScopePtr& scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
TypePackId anyTypePack);
NotNull<Scope> scope;
NotNull<SingletonTypes> singletonTypes;
NotNull<BuiltinTypes> builtinTypes;
InternalErrorReporter* iceHandler;

TypeId anyType;
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/ApplyTypeFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Luau/Substitution.h"
#include "Luau/TxnLog.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"

namespace Luau
{
Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/AstQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ struct Binding;
struct SourceModule;
struct Module;

struct TypeVar;
using TypeId = const TypeVar*;
struct Type;
using TypeId = const Type*;

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

Expand Down
6 changes: 3 additions & 3 deletions Analysis/include/Luau/Autocomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include "Luau/Location.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"

#include <unordered_map>
#include <string>
Expand Down Expand Up @@ -65,7 +65,7 @@ struct AutocompleteEntry
// Set if this suggestion matches the type expected in the context
TypeCorrectKind typeCorrect = TypeCorrectKind::None;

std::optional<const ClassTypeVar*> containingClass = std::nullopt;
std::optional<const ClassType*> containingClass = std::nullopt;
std::optional<const Property*> prop = std::nullopt;
std::optional<std::string> documentationSymbol = std::nullopt;
Tags tags;
Expand All @@ -89,7 +89,7 @@ struct AutocompleteResult
};

using ModuleName = std::string;
using StringCompletionCallback = std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassTypeVar*> ctx)>;
using StringCompletionCallback = std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassType*> ctx)>;

AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName, Position position, StringCompletionCallback callback);

Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/BuiltinDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include "Luau/Scope.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"

#include <optional>

Expand Down Expand Up @@ -48,7 +48,7 @@ void attachDcrMagicFunction(TypeId ty, DcrMagicFunction fn);
void attachDcrMagicRefinement(TypeId ty, DcrMagicRefinement fn);

Property makeProperty(TypeId ty, std::optional<std::string> documentationSymbol = std::nullopt);
void assignPropDocumentationSymbols(TableTypeVar::Props& props, const std::string& baseName);
void assignPropDocumentationSymbols(TableType::Props& props, const std::string& baseName);

std::string getBuiltinDefinitionSource();

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 @@ -3,7 +3,7 @@

#include <Luau/NotNull.h>
#include "Luau/TypeArena.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"

#include <unordered_map>

Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/Connective.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Luau
{

struct TypeVar;
using TypeId = const TypeVar*;
struct Type;
using TypeId = const Type*;

struct Negation;
struct Conjunction;
Expand Down
8 changes: 4 additions & 4 deletions Analysis/include/Luau/Constraint.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Luau/Def.h"
#include "Luau/DenseHash.h"
#include "Luau/NotNull.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"
#include "Luau/Variant.h"

#include <string>
Expand All @@ -17,8 +17,8 @@ namespace Luau

struct Scope;

struct TypeVar;
using TypeId = const TypeVar*;
struct Type;
using TypeId = const Type*;

struct TypePackVar;
using TypePackId = const TypePackVar*;
Expand Down Expand Up @@ -94,7 +94,7 @@ struct NameConstraint
// target ~ inst target
struct TypeAliasExpansionConstraint
{
// Must be a PendingExpansionTypeVar.
// Must be a PendingExpansionType.
TypeId target;
};

Expand Down
6 changes: 3 additions & 3 deletions Analysis/include/Luau/ConstraintGraphBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "Luau/ModuleResolver.h"
#include "Luau/NotNull.h"
#include "Luau/Symbol.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"
#include "Luau/Variant.h"

#include <memory>
Expand Down Expand Up @@ -61,7 +61,7 @@ struct ConstraintGraphBuilder

ModuleName moduleName;
ModulePtr module;
NotNull<SingletonTypes> singletonTypes;
NotNull<BuiltinTypes> builtinTypes;
const NotNull<TypeArena> arena;
// The root scope of the module we're generating constraints for.
// This is null when the CGB is initially constructed.
Expand Down Expand Up @@ -114,7 +114,7 @@ struct ConstraintGraphBuilder
DcrLogger* logger;

ConstraintGraphBuilder(const ModuleName& moduleName, ModulePtr module, TypeArena* arena, NotNull<ModuleResolver> moduleResolver,
NotNull<SingletonTypes> singletonTypes, NotNull<InternalErrorReporter> ice, const ScopePtr& globalScope, DcrLogger* logger,
NotNull<BuiltinTypes> builtinTypes, NotNull<InternalErrorReporter> ice, const ScopePtr& globalScope, DcrLogger* logger,
NotNull<DataFlowGraph> dfg);

/**
Expand Down
8 changes: 4 additions & 4 deletions Analysis/include/Luau/ConstraintSolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Luau/Module.h"
#include "Luau/Normalize.h"
#include "Luau/ToString.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"
#include "Luau/Variant.h"

#include <vector>
Expand Down Expand Up @@ -44,7 +44,7 @@ struct HashInstantiationSignature
struct ConstraintSolver
{
TypeArena* arena;
NotNull<SingletonTypes> singletonTypes;
NotNull<BuiltinTypes> builtinTypes;
InternalErrorReporter iceReporter;
NotNull<Normalizer> normalizer;
// The entire set of constraints that the solver is trying to resolve.
Expand Down Expand Up @@ -126,13 +126,13 @@ struct ConstraintSolver

void block(NotNull<const Constraint> target, NotNull<const Constraint> constraint);
/**
* Block a constraint on the resolution of a TypeVar.
* Block a constraint on the resolution of a Type.
* @returns false always. This is just to allow tryDispatch to return the result of block()
*/
bool block(TypeId target, NotNull<const Constraint> constraint);
bool block(TypePackId target, NotNull<const Constraint> constraint);

// Traverse the type. If any blocked or pending typevars are found, block
// Traverse the type. If any blocked or pending types are found, block
// the constraint on them.
//
// Returns false if a type blocks the constraint.
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

#include "Luau/Location.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"
#include "Luau/Variant.h"

namespace Luau
Expand Down
12 changes: 6 additions & 6 deletions Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ struct Frontend
Frontend(FileResolver* fileResolver, ConfigResolver* configResolver, const FrontendOptions& options = {});

CheckResult check(const ModuleName& name, std::optional<FrontendOptions> optionOverride = {}); // new shininess
LintResult lint(const ModuleName& name, std::optional<LintOptions> enabledLintWarnings = {});

LintResult lint(const ModuleName& name, std::optional<LintOptions> enabledLintWarnings = {});
LintResult lint(const SourceModule& module, std::optional<LintOptions> enabledLintWarnings = {});

bool isDirty(const ModuleName& name, bool forAutocomplete = false) const;
Expand Down Expand Up @@ -165,22 +165,22 @@ struct Frontend
ModulePtr check(const SourceModule& sourceModule, Mode mode, const ScopePtr& environmentScope, std::vector<RequireCycle> requireCycles,
bool forAutocomplete = false);

std::pair<SourceNode*, SourceModule*> getSourceNode(CheckResult& checkResult, const ModuleName& name);
std::pair<SourceNode*, SourceModule*> getSourceNode(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);
bool parseGraph(std::vector<ModuleName>& buildQueue, const ModuleName& root, bool forAutocomplete);

static LintResult classifyLints(const std::vector<LintWarning>& warnings, const Config& config);

ScopePtr getModuleEnvironment(const SourceModule& module, const Config& config, bool forAutocomplete = false);
ScopePtr getModuleEnvironment(const SourceModule& module, const Config& config, bool forAutocomplete);

std::unordered_map<std::string, ScopePtr> environments;
std::unordered_map<std::string, std::function<void(TypeChecker&, ScopePtr)>> builtinDefinitions;

SingletonTypes singletonTypes_;
BuiltinTypes builtinTypes_;

public:
const NotNull<SingletonTypes> singletonTypes;
const NotNull<BuiltinTypes> builtinTypes;

FileResolver* fileResolver;
FrontendModuleResolver moduleResolver;
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Instantiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#pragma once

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

namespace Luau
Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/IostreamHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "Luau/Error.h"
#include "Luau/Location.h"
#include "Luau/TypeVar.h"
#include "Luau/Type.h"
#include "Luau/Ast.h"

#include <ostream>
Expand Down Expand Up @@ -43,7 +43,7 @@ std::ostream& operator<<(std::ostream& lhs, const MissingUnionProperty& error);
std::ostream& operator<<(std::ostream& lhs, const TypesAreUnrelated& error);

std::ostream& operator<<(std::ostream& lhs, const TableState& tv);
std::ostream& operator<<(std::ostream& lhs, const TypeVar& tv);
std::ostream& operator<<(std::ostream& lhs, const Type& tv);
std::ostream& operator<<(std::ostream& lhs, const TypePackVar& tv);

std::ostream& operator<<(std::ostream& lhs, const TypeErrorData& ted);
Expand Down
4 changes: 2 additions & 2 deletions Analysis/include/Luau/LValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
namespace Luau
{

struct TypeVar;
using TypeId = const TypeVar*;
struct Type;
using TypeId = const Type*;

struct Field;

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 @@ -89,8 +89,8 @@ struct Module
ScopePtr getModuleScope() const;

// Once a module has been typechecked, we clone its public interface into a separate arena.
// This helps us to force TypeVar ownership into a DAG rather than a DCG.
void clonePublicInterface(NotNull<SingletonTypes> singletonTypes, InternalErrorReporter& ice);
// This helps us to force Type ownership into a DAG rather than a DCG.
void clonePublicInterface(NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter& ice);
};

} // namespace Luau
Loading

0 comments on commit 75a2e95

Please sign in to comment.