-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sync to
upstream/release/651
(#1513)
### What's New? * Fragment Autocomplete: a new API allows for type checking a small fragment of code against an existing file, significantly speeding up autocomplete performance in large files. ### New Solver * E-Graphs have landed: this is an ongoing approach to make the new type solver simplify types in a more consistent and principled manner, based on similar work (see: https://egraphs-good.github.io/). * Adds support for exporting / local user type functions (previously they were always exported). * Fixes a set of bugs in which the new solver will fail to complete inference for simple expressions with just literals and operators. ### General Updates * Requiring a path with a ".lua" or ".luau" extension will now have a bespoke error suggesting to remove said extension. * Fixes a bug in which whether two `Luau::Symbol`s are equal depends on whether the new solver is enabled. --- Internal Contributors: Co-authored-by: Aaron Weiss <[email protected]> Co-authored-by: Andy Friesen <[email protected]> Co-authored-by: David Cope <[email protected]> Co-authored-by: Hunter Goldstein <[email protected]> Co-authored-by: Varun Saini <[email protected]> Co-authored-by: Vighnesh Vijay <[email protected]> Co-authored-by: Vyacheslav Egorov <[email protected]>
- Loading branch information
1 parent
26b2307
commit a36a3c4
Showing
62 changed files
with
7,315 additions
and
2,456 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details | ||
#pragma once | ||
|
||
#include "Luau/Ast.h" | ||
#include "Luau/Type.h" | ||
|
||
#include <unordered_map> | ||
|
||
namespace Luau | ||
{ | ||
|
||
enum class AutocompleteContext | ||
{ | ||
Unknown, | ||
Expression, | ||
Statement, | ||
Property, | ||
Type, | ||
Keyword, | ||
String, | ||
}; | ||
|
||
enum class AutocompleteEntryKind | ||
{ | ||
Property, | ||
Binding, | ||
Keyword, | ||
String, | ||
Type, | ||
Module, | ||
GeneratedFunction, | ||
RequirePath, | ||
}; | ||
|
||
enum class ParenthesesRecommendation | ||
{ | ||
None, | ||
CursorAfter, | ||
CursorInside, | ||
}; | ||
|
||
enum class TypeCorrectKind | ||
{ | ||
None, | ||
Correct, | ||
CorrectFunctionResult, | ||
}; | ||
|
||
struct AutocompleteEntry | ||
{ | ||
AutocompleteEntryKind kind = AutocompleteEntryKind::Property; | ||
// Nullopt if kind is Keyword | ||
std::optional<TypeId> type = std::nullopt; | ||
bool deprecated = false; | ||
// Only meaningful if kind is Property. | ||
bool wrongIndexType = false; | ||
// Set if this suggestion matches the type expected in the context | ||
TypeCorrectKind typeCorrect = TypeCorrectKind::None; | ||
|
||
std::optional<const ClassType*> containingClass = std::nullopt; | ||
std::optional<const Property*> prop = std::nullopt; | ||
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>; | ||
struct AutocompleteResult | ||
{ | ||
AutocompleteEntryMap entryMap; | ||
std::vector<AstNode*> ancestry; | ||
AutocompleteContext context = AutocompleteContext::Unknown; | ||
|
||
AutocompleteResult() = default; | ||
AutocompleteResult(AutocompleteEntryMap entryMap, std::vector<AstNode*> ancestry, AutocompleteContext context) | ||
: entryMap(std::move(entryMap)) | ||
, ancestry(std::move(ancestry)) | ||
, context(context) | ||
{ | ||
} | ||
}; | ||
|
||
using StringCompletionCallback = | ||
std::function<std::optional<AutocompleteEntryMap>(std::string tag, std::optional<const ClassType*> ctx, std::optional<std::string> contents)>; | ||
|
||
constexpr char kGeneratedAnonymousFunctionEntryName[] = "function (anonymous autofilled)"; | ||
|
||
} // namespace Luau |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details | ||
|
||
#pragma once | ||
|
||
#include "Luau/TypeFwd.h" | ||
#include "Luau/NotNull.h" | ||
#include "Luau/DenseHash.h" | ||
|
||
#include <memory> | ||
#include <optional> | ||
#include <vector> | ||
|
||
namespace Luau | ||
{ | ||
struct TypeArena; | ||
} | ||
|
||
// The EqSat stuff is pretty template heavy, so we go to some lengths to prevent | ||
// the complexity from leaking outside its implementation sources. | ||
namespace Luau::EqSatSimplification | ||
{ | ||
|
||
struct Simplifier; | ||
|
||
using SimplifierPtr = std::unique_ptr<Simplifier, void (*)(Simplifier*)>; | ||
|
||
SimplifierPtr newSimplifier(NotNull<TypeArena> arena, NotNull<BuiltinTypes> builtinTypes); | ||
|
||
} // namespace Luau::EqSatSimplification | ||
|
||
namespace Luau | ||
{ | ||
|
||
struct EqSatSimplificationResult | ||
{ | ||
TypeId result; | ||
|
||
// New type function applications that were created by the reduction phase. | ||
// We return these so that the ConstraintSolver can know to try to reduce | ||
// them. | ||
std::vector<TypeId> newTypeFunctions; | ||
}; | ||
|
||
using EqSatSimplification::newSimplifier; // NOLINT: clang-tidy thinks these are unused. It is incorrect. | ||
using Luau::EqSatSimplification::Simplifier; // NOLINT | ||
using Luau::EqSatSimplification::SimplifierPtr; | ||
|
||
std::optional<EqSatSimplificationResult> eqSatSimplify(NotNull<Simplifier> simplifier, TypeId ty); | ||
|
||
} // namespace Luau |
Oops, something went wrong.