Skip to content

Commit

Permalink
Sync to upstream Luau 0.575
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnnyMorganz committed May 9, 2023
1 parent 02ad9f0 commit 0b8b1b9
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 37 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
i.e., all functions that call the current function, as well as all functions that the current function calls.
This works at multiple levels, displaying ancestor and descendant functions.

### Changed

- Sync to upstream Luau 0.575

## [1.19.2]

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion luau
Submodule luau updated from 817349 to 001490
36 changes: 18 additions & 18 deletions src/LuauExt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -521,23 +521,23 @@ Luau::LoadDefinitionFileResult registerDefinitions(
{
if (auto* ctv = Luau::getMutable<Luau::ClassType>(instanceType->type))
{
Luau::attachMagicFunction(ctv->props["IsA"].type, types::magicFunctionInstanceIsA);
Luau::attachMagicFunction(ctv->props["FindFirstChildWhichIsA"].type, types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstChildOfClass"].type, types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstAncestorWhichIsA"].type, types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstAncestorOfClass"].type, types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["Clone"].type, types::magicFunctionInstanceClone);
Luau::attachMagicFunction(ctv->props["GetPropertyChangedSignal"].type, magicFunctionGetPropertyChangedSignal);
Luau::attachMagicFunction(ctv->props["IsA"].type(), types::magicFunctionInstanceIsA);
Luau::attachMagicFunction(ctv->props["FindFirstChildWhichIsA"].type(), types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstChildOfClass"].type(), types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstAncestorWhichIsA"].type(), types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["FindFirstAncestorOfClass"].type(), types::magicFunctionFindFirstXWhichIsA);
Luau::attachMagicFunction(ctv->props["Clone"].type(), types::magicFunctionInstanceClone);
Luau::attachMagicFunction(ctv->props["GetPropertyChangedSignal"].type(), magicFunctionGetPropertyChangedSignal);

// Autocomplete ClassNames for :IsA("") and counterparts
Luau::attachTag(ctv->props["IsA"].type, "ClassNames");
Luau::attachTag(ctv->props["FindFirstChildWhichIsA"].type, "ClassNames");
Luau::attachTag(ctv->props["FindFirstChildOfClass"].type, "ClassNames");
Luau::attachTag(ctv->props["FindFirstAncestorWhichIsA"].type, "ClassNames");
Luau::attachTag(ctv->props["FindFirstAncestorOfClass"].type, "ClassNames");
Luau::attachTag(ctv->props["IsA"].type(), "ClassNames");
Luau::attachTag(ctv->props["FindFirstChildWhichIsA"].type(), "ClassNames");
Luau::attachTag(ctv->props["FindFirstChildOfClass"].type(), "ClassNames");
Luau::attachTag(ctv->props["FindFirstAncestorWhichIsA"].type(), "ClassNames");
Luau::attachTag(ctv->props["FindFirstAncestorOfClass"].type(), "ClassNames");

// Autocomplete Properties for :GetPropertyChangedSignal("")
Luau::attachTag(ctv->props["GetPropertyChangedSignal"].type, "Properties");
Luau::attachTag(ctv->props["GetPropertyChangedSignal"].type(), "Properties");

// Go through all the defined classes and if they are a subclass of Instance then give them the
// same metatable identity as Instance so that equality comparison works.
Expand All @@ -561,7 +561,7 @@ Luau::LoadDefinitionFileResult registerDefinitions(
if (auto instanceGlobal = globals.globalScope->lookup(Luau::AstName("Instance")))
if (auto ttv = Luau::get<Luau::TableType>(instanceGlobal.value()))
if (auto newFunction = ttv->props.find("new"); newFunction != ttv->props.end())
if (auto itv = Luau::get<Luau::IntersectionType>(newFunction->second.type))
if (auto itv = Luau::get<Luau::IntersectionType>(newFunction->second.type()))
for (auto& part : itv->parts)
if (auto ftv = Luau::get<Luau::FunctionType>(part))
if (auto it = Luau::begin(ftv->argTypes); it != Luau::end(ftv->argTypes))
Expand All @@ -572,7 +572,7 @@ Luau::LoadDefinitionFileResult registerDefinitions(
if (auto serviceProviderType = globals.globalScope->lookupType("ServiceProvider"))
if (auto* ctv = Luau::getMutable<Luau::ClassType>(serviceProviderType->type))
// :GetService is an intersection of function types, so we assign a tag on the first intersection
if (auto* itv = Luau::getMutable<Luau::IntersectionType>(ctv->props["GetService"].type); itv && itv->parts.size() > 0)
if (auto* itv = Luau::getMutable<Luau::IntersectionType>(ctv->props["GetService"].type()); itv && itv->parts.size() > 0)
Luau::attachTag(itv->parts[0], "PrioritiseCommonServices");

// Move Enums over as imported type bindings
Expand All @@ -587,8 +587,8 @@ Luau::LoadDefinitionFileResult registerDefinitions(
{
if (ctv->name == "EnumItem")
{
Luau::attachMagicFunction(ctv->props["IsA"].type, types::magicFunctionEnumItemIsA);
Luau::attachTag(ctv->props["IsA"].type, "Enums");
Luau::attachMagicFunction(ctv->props["IsA"].type(), types::magicFunctionEnumItemIsA);
Luau::attachTag(ctv->props["IsA"].type(), "Enums");
}
else if (ctv->name != "Enum" && ctv->name != "Enums")
{
Expand Down Expand Up @@ -881,7 +881,7 @@ std::optional<Luau::Property> lookupProp(const Luau::TypeId& parentType, const L
auto indexIt = mtable->props.find("__index");
if (indexIt != mtable->props.end())
{
Luau::TypeId followed = Luau::follow(indexIt->second.type);
Luau::TypeId followed = Luau::follow(indexIt->second.type());
if ((Luau::get<Luau::TableType>(followed) || Luau::get<Luau::MetatableType>(followed)) && followed != parentType) // ensure acyclic
{
return lookupProp(followed, name);
Expand Down
4 changes: 2 additions & 2 deletions src/operations/CallHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ static Luau::TypeId lookupFunctionCallType(Luau::ModulePtr module, const Luau::A
auto parentType = Luau::follow(*parentIt);
auto prop = lookupProp(parentType, index->index.value);
if (prop)
return Luau::follow(prop->type);
return Luau::follow(prop->type());
}
}

Expand Down Expand Up @@ -167,7 +167,7 @@ std::vector<lsp::CallHierarchyItem> WorkspaceFolder::prepareCallHierarchy(const
auto prop = lookupProp(ty, *it);
if (!prop)
return {};
ty = Luau::follow(prop->type);
ty = Luau::follow(prop->type());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/operations/Completion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static std::vector<std::string> getServiceNames(const Luau::ScopePtr& scope)
{
if (auto getService = Luau::lookupClassProp(ctv, "GetService"))
{
if (auto itv = Luau::get<Luau::IntersectionType>(getService->type))
if (auto itv = Luau::get<Luau::IntersectionType>(getService->type()))
{
for (auto part : itv->parts)
{
Expand Down
4 changes: 2 additions & 2 deletions src/operations/GotoDefinition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ lsp::DefinitionResult WorkspaceFolder::gotoDefinition(const lsp::DefinitionParam
std::vector<Luau::Property> properties{};
for (auto it = keys.rbegin(); it != keys.rend(); ++it)
{
auto base = properties.empty() ? *baseType : Luau::follow(properties.back().type);
auto base = properties.empty() ? *baseType : Luau::follow(properties.back().type());
auto prop = lookupProp(base, *it);
if (!prop)
return result;
Expand All @@ -84,7 +84,7 @@ lsp::DefinitionResult WorkspaceFolder::gotoDefinition(const lsp::DefinitionParam
if (!location && it->location)
location = it->location;
if (!definitionModuleName)
definitionModuleName = Luau::getDefinitionModuleName(Luau::follow(it->type));
definitionModuleName = Luau::getDefinitionModuleName(Luau::follow(it->type()));
}

if (!definitionModuleName)
Expand Down
2 changes: 1 addition & 1 deletion src/operations/Hover.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ std::optional<lsp::Hover> WorkspaceFolder::hover(const lsp::HoverParams& params)
auto prop = lookupProp(parentType, indexName);
if (prop)
{
type = prop->type;
type = prop->type();
if (auto definitionModuleName = Luau::getDefinitionModuleName(parentType); definitionModuleName && prop->location)
documentationLocation = {definitionModuleName.value(), prop->location.value()};
}
Expand Down
2 changes: 1 addition & 1 deletion src/operations/References.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::vector<Luau::ModuleName> WorkspaceFolder::findReverseDependencies(const Lua
std::unordered_map<Luau::ModuleName, std::vector<Luau::ModuleName>> reverseDeps;
for (const auto& module : frontend.sourceNodes)
{
for (const auto& dep : module.second.requireSet)
for (const auto& dep : module.second->requireSet)
reverseDeps[dep].push_back(module.first);
}
std::vector<Luau::ModuleName> queue{moduleName};
Expand Down
17 changes: 8 additions & 9 deletions src/operations/SemanticTokens.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ enum struct AstLocalInfo
Parameter,
};

static lsp::SemanticTokenTypes inferTokenType(const Luau::TypeId* ty, lsp::SemanticTokenTypes base)
static lsp::SemanticTokenTypes inferTokenType(const Luau::TypeId ty, lsp::SemanticTokenTypes base)
{
if (!ty)
return base;

auto followedTy = Luau::follow(*ty);
auto followedTy = Luau::follow(ty);

if (auto ftv = Luau::get<Luau::FunctionType>(followedTy))
{
Expand Down Expand Up @@ -164,8 +164,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
auto ty = scope->lookup(var);
if (ty)
{
auto followedTy = Luau::follow(*ty);
auto type = inferTokenType(&followedTy, lsp::SemanticTokenTypes::Variable);
auto type = inferTokenType(*ty, lsp::SemanticTokenTypes::Variable);
if (type == lsp::SemanticTokenTypes::Variable)
return true; // No special semantic token needed, fall back to syntax highlighting
tokens.emplace_back(SemanticToken{var->location.begin, var->location.end, type, lsp::SemanticTokenModifiers::None});
Expand Down Expand Up @@ -222,7 +221,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
}
}

auto type = inferTokenType(module->astTypes.find(local), defaultType);
auto type = inferTokenType(*module->astTypes.find(local), defaultType);
if (type == lsp::SemanticTokenTypes::Variable)
return true;

Expand Down Expand Up @@ -250,7 +249,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
}
else
{
auto type = inferTokenType(&it->second, lsp::SemanticTokenTypes::Variable);
auto type = inferTokenType(it->second, lsp::SemanticTokenTypes::Variable);
tokens.emplace_back(SemanticToken{global->location.begin, global->location.end, type,
lsp::SemanticTokenModifiers::DefaultLibrary | lsp::SemanticTokenModifiers::Readonly});
}
Expand All @@ -261,7 +260,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
if (!ty)
return true;

auto type = inferTokenType(ty, lsp::SemanticTokenTypes::Variable);
auto type = inferTokenType(*ty, lsp::SemanticTokenTypes::Variable);
if (type == lsp::SemanticTokenTypes::Variable)
return true;

Expand Down Expand Up @@ -295,7 +294,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
else if (Luau::hasTag(prop->tags, "EnumItem"))
defaultType = lsp::SemanticTokenTypes::EnumMember;

auto type = inferTokenType(&prop->type, defaultType);
auto type = inferTokenType(prop->type(), defaultType);
auto modifiers = lsp::SemanticTokenModifiers::None;
if (parentIsBuiltin)
{
Expand All @@ -317,7 +316,7 @@ struct SemanticTokensVisitor : public Luau::AstVisitor
{
if (item.kind == Luau::AstExprTable::Item::Kind::Record)
{
auto type = inferTokenType(module->astTypes.find(item.value), lsp::SemanticTokenTypes::Property);
auto type = inferTokenType(*module->astTypes.find(item.value), lsp::SemanticTokenTypes::Property);
tokens.emplace_back(SemanticToken{item.key->location.begin, item.key->location.end, type, lsp::SemanticTokenModifiers::None});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/operations/WorkspaceSymbol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ std::optional<std::vector<lsp::WorkspaceSymbol>> WorkspaceFolder::workspaceSymbo
if (auto textDocument = fileResolver.getTextDocumentFromModuleName(moduleName))
{
WorkspaceSymbolsVisitor visitor{textDocument, params.query};
visitor.visit(sourceModule.root);
visitor.visit(sourceModule->root);
result.insert(result.end(), std::make_move_iterator(visitor.symbols.begin()), std::make_move_iterator(visitor.symbols.end()));
}
else
Expand All @@ -126,7 +126,7 @@ std::optional<std::vector<lsp::WorkspaceSymbol>> WorkspaceFolder::workspaceSymbo
{
auto textDocument = TextDocument{Uri::file(*filePath), "luau", 0, source->source};
WorkspaceSymbolsVisitor visitor{&textDocument, params.query};
visitor.visit(sourceModule.root);
visitor.visit(sourceModule->root);
result.insert(result.end(), std::make_move_iterator(visitor.symbols.begin()), std::make_move_iterator(visitor.symbols.end()));
}
}
Expand Down

0 comments on commit 0b8b1b9

Please sign in to comment.