Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the Luau interpreter to 0.637. #266

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
brew install pkg-config glfw3 python3 cmark fmt coreutils make
brew link --overwrite python3
python3 -m pip install --upgrade Pillow
brew install pillow
- name: make
run: |
gmake -j$(nproc) BUILDTYPE=osx
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ifeq ($(BUILDTYPE),windows)
EXT = .exe
else
export CC = gcc
export CXX = g++
export CXX = g++ -std=c++20
export CFLAGS
export CXXFLAGS
export LDFLAGS
Expand Down Expand Up @@ -77,4 +77,4 @@ bin/wordgrinder-minimal-dependencies-for-debian.tar.xz:
wordgrinder.man \
xwordgrinder.man

include build/ab.mk
include build/ab.mk
2 changes: 1 addition & 1 deletion src/c/filesystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ static int readfile_cb(lua_State* L)
if (i < 0)
goto error;

luaL_addlstring(&buffer, b, i, -1);
luaL_addlstring(&buffer, b, i);
}

fclose(fp);
Expand Down
147 changes: 147 additions & 0 deletions third_party/luau/Analysis/include/Luau/AnyTypeSummary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
#pragma once

#include "Luau/AstQuery.h"
#include "Luau/Config.h"
#include "Luau/ModuleResolver.h"
#include "Luau/Scope.h"
#include "Luau/Variant.h"
#include "Luau/Normalize.h"
#include "Luau/TypePack.h"
#include "Luau/TypeArena.h"

#include <mutex>
#include <string>
#include <vector>
#include <optional>

namespace Luau
{

class AstStat;
class ParseError;
struct TypeError;
struct LintWarning;
struct GlobalTypes;
struct ModuleResolver;
struct ParseResult;
struct DcrLogger;

struct TelemetryTypePair
{
std::string annotatedType;
std::string inferredType;
};

struct AnyTypeSummary
{
TypeArena arena;

AstStatBlock* rootSrc = nullptr;
DenseHashSet<TypeId> seenTypeFamilyInstances{nullptr};

int recursionCount = 0;

std::string root;
int strictCount = 0;

DenseHashMap<const void*, bool> seen{nullptr};

AnyTypeSummary();

void traverse(const Module* module, AstStat* src, NotNull<BuiltinTypes> builtinTypes);

std::pair<bool, TypeId> checkForAnyCast(const Scope* scope, AstExprTypeAssertion* expr);

bool containsAny(TypePackId typ);
bool containsAny(TypeId typ);

bool isAnyCast(const Scope* scope, AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
bool isAnyCall(const Scope* scope, AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);

bool hasVariadicAnys(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
bool hasArgAnys(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
bool hasAnyReturns(const Scope* scope, AstExprFunction* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);

TypeId checkForFamilyInhabitance(const TypeId instance, Location location);
TypeId lookupType(const AstExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
TypePackId reconstructTypePack(const AstArray<AstExpr*> exprs, const Module* module, NotNull<BuiltinTypes> builtinTypes);

DenseHashSet<TypeId> seenTypeFunctionInstances{nullptr};
TypeId lookupAnnotation(AstType* annotation, const Module* module, NotNull<BuiltinTypes> builtintypes);
std::optional<TypePackId> lookupPackAnnotation(AstTypePack* annotation, const Module* module);
TypeId checkForTypeFunctionInhabitance(const TypeId instance, const Location location);

enum Pattern: uint64_t
{
Casts,
FuncArg,
FuncRet,
FuncApp,
VarAnnot,
VarAny,
TableProp,
Alias,
Assign
};

struct TypeInfo
{
Pattern code;
std::string node;
TelemetryTypePair type;

explicit TypeInfo(Pattern code, std::string node, TelemetryTypePair type);
};

struct FindReturnAncestry final : public AstVisitor
{
AstNode* currNode{nullptr};
AstNode* stat{nullptr};
Position rootEnd;
bool found = false;

explicit FindReturnAncestry(AstNode* stat, Position rootEnd);

bool visit(AstType* node) override;
bool visit(AstNode* node) override;
bool visit(AstStatFunction* node) override;
bool visit(AstStatLocalFunction* node) override;
};

std::vector<TypeInfo> typeInfo;

/**
* Fabricates a scope that is a child of another scope.
* @param node the lexical node that the scope belongs to.
* @param parent the parent scope of the new scope. Must not be null.
*/
const Scope* childScope(const AstNode* node, const Scope* parent);

std::optional<AstExpr*> matchRequire(const AstExprCall& call);
AstNode* getNode(AstStatBlock* root, AstNode* node);
const Scope* findInnerMostScope(const Location location, const Module* module);
const AstNode* findAstAncestryAtLocation(const AstStatBlock* root, AstNode* node);

void visit(const Scope* scope, AstStat* stat, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatBlock* block, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatIf* ifStatement, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatWhile* while_, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatRepeat* repeat, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatReturn* ret, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatLocal* local, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatFor* for_, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatForIn* forIn, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatAssign* assign, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatCompoundAssign* assign, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatFunction* function, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatLocalFunction* function, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatTypeAlias* alias, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatExpr* expr, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatDeclareGlobal* declareGlobal, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatDeclareClass* declareClass, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatDeclareFunction* declareFunction, const Module* module, NotNull<BuiltinTypes> builtinTypes);
void visit(const Scope* scope, AstStatError* error, const Module* module, NotNull<BuiltinTypes> builtinTypes);
};

} // namespace Luau
24 changes: 18 additions & 6 deletions third_party/luau/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/Type.h"
#include "Luau/TypeFwd.h"

#include <memory>

Expand All @@ -19,10 +19,22 @@ using ScopePtr = std::shared_ptr<Scope>;
// A substitution which replaces free types by any
struct Anyification : Substitution
{
Anyification(TypeArena* arena, NotNull<Scope> scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
TypePackId anyTypePack);
Anyification(TypeArena* arena, const ScopePtr& scope, NotNull<BuiltinTypes> builtinTypes, InternalErrorReporter* iceHandler, TypeId anyType,
TypePackId anyTypePack);
Anyification(
TypeArena* arena,
NotNull<Scope> scope,
NotNull<BuiltinTypes> builtinTypes,
InternalErrorReporter* iceHandler,
TypeId anyType,
TypePackId anyTypePack
);
Anyification(
TypeArena* arena,
const ScopePtr& scope,
NotNull<BuiltinTypes> builtinTypes,
InternalErrorReporter* iceHandler,
TypeId anyType,
TypePackId anyTypePack
);
NotNull<Scope> scope;
NotNull<BuiltinTypes> builtinTypes;
InternalErrorReporter* iceHandler;
Expand All @@ -39,4 +51,4 @@ struct Anyification : Substitution
bool ignoreChildren(TypePackId ty) override;
};

} // namespace Luau
} // namespace Luau
2 changes: 1 addition & 1 deletion third_party/luau/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/Type.h"
#include "Luau/TypeFwd.h"

namespace Luau
{
Expand Down
20 changes: 17 additions & 3 deletions third_party/luau/Analysis/include/Luau/AstQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "Luau/Ast.h"
#include "Luau/Documentation.h"
#include "Luau/TypeFwd.h"

#include <memory>

Expand All @@ -13,9 +14,6 @@ struct Binding;
struct SourceModule;
struct Module;

struct Type;
using TypeId = const Type*;

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

struct ExprOrLocal
Expand Down Expand Up @@ -63,6 +61,22 @@ struct ExprOrLocal
AstLocal* local = nullptr;
};

struct FindFullAncestry final : public AstVisitor
{
std::vector<AstNode*> nodes;
Position pos;
Position documentEnd;
bool includeTypes = false;

explicit FindFullAncestry(Position pos, Position documentEnd, bool includeTypes = false);

bool visit(AstType* type) override;

bool visit(AstStatFunction* node) override;

bool visit(AstNode* node) override;
};

std::vector<AstNode*> findAncestryAtPositionForAutocomplete(const SourceModule& source, Position pos);
std::vector<AstNode*> findAncestryAtPositionForAutocomplete(AstStatBlock* root, Position pos);
std::vector<AstNode*> findAstAncestryOfPosition(const SourceModule& source, Position pos, bool includeTypes = false);
Expand Down
7 changes: 7 additions & 0 deletions third_party/luau/Analysis/include/Luau/Autocomplete.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum class AutocompleteEntryKind
String,
Type,
Module,
GeneratedFunction,
};

enum class ParenthesesRecommendation
Expand Down Expand Up @@ -70,6 +71,10 @@ struct AutocompleteEntry
std::optional<std::string> documentationSymbol = std::nullopt;
Tags tags;
ParenthesesRecommendation parens = ParenthesesRecommendation::None;
std::optional<std::string> insertText;

// Only meaningful if kind is Property.
bool indexedWithSelf = false;
};

using AutocompleteEntryMap = std::unordered_map<std::string, AutocompleteEntry>;
Expand All @@ -94,4 +99,6 @@ using StringCompletionCallback =

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

constexpr char kGeneratedAnonymousFunctionEntryName[] = "function (anonymous autofilled)";

} // namespace Luau
75 changes: 0 additions & 75 deletions third_party/luau/Analysis/include/Luau/Breadcrumb.h

This file was deleted.

Loading
Loading