Skip to content

Commit

Permalink
Sync to upstream/release/632 (#1307)
Browse files Browse the repository at this point in the history
# What's Changed?

- Fix #1137 by appropriately retaining additional metadata from
definition files throughout the type system.
- Improve Frontend for LSPs by appropriately allowing the cancellation
of typechecking while running its destructor.

## New Solver

- Added support for the `rawget` type function.
- Reduced overall static memory usage of builtin type functions.
- Fixed a crash where visitors could mutate a union or intersection type
and fail to invalidate iteration over them in doing so.
- Revised autocomplete functionality to not rely on a separate run of
the type solver when using the new solver.
- Implemented a more relaxed semantic rule for casting.
- Fixed some smaller crashes in the new solver.

## Native Code Generation

- Add additional codegen specialization for `math.sign`
- Cleaned up a large number of outstanding fflags in the code.

### Internal Contributors

Co-authored-by: Aaron Weiss <[email protected]>
Co-authored-by: Alexander McCord <[email protected]>
Co-authored-by: Andy Friesen <[email protected]>
Co-authored-by: James McNellis <[email protected]>
Co-authored-by: Jeremy Yoo <[email protected]>
Co-authored-by: Vighnesh Vijay <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>

---------

Co-authored-by: Alexander McCord <[email protected]>
Co-authored-by: Andy Friesen <[email protected]>
Co-authored-by: Vighnesh <[email protected]>
Co-authored-by: Aviral Goel <[email protected]>
Co-authored-by: David Cope <[email protected]>
Co-authored-by: Lily Brown <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>
  • Loading branch information
8 people authored Jun 29, 2024
1 parent caee04d commit 0d26888
Show file tree
Hide file tree
Showing 61 changed files with 1,235 additions and 934 deletions.
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ struct Frontend
void queueModuleCheck(const std::vector<ModuleName>& names);
void queueModuleCheck(const ModuleName& name);
std::vector<ModuleName> checkQueuedModules(std::optional<FrontendOptions> optionOverride = {},
std::function<void(std::function<void()> task)> executeTask = {}, std::function<void(size_t done, size_t total)> progress = {});
std::function<void(std::function<void()> task)> executeTask = {}, std::function<bool(size_t done, size_t total)> progress = {});

std::optional<CheckResult> getCheckResult(const ModuleName& name, bool accumulateNested, bool forAutocomplete = false);

Expand Down
5 changes: 2 additions & 3 deletions Analysis/include/Luau/TypeFamily.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,11 @@ struct BuiltinTypeFamilies
TypeFamily rawkeyofFamily;

TypeFamily indexFamily;
TypeFamily rawgetFamily;

void addToScope(NotNull<TypeArena> arena, NotNull<Scope> scope) const;
};



const BuiltinTypeFamilies kBuiltinTypeFamilies{};
const BuiltinTypeFamilies& builtinTypeFunctions();

} // namespace Luau
22 changes: 22 additions & 0 deletions Analysis/include/Luau/VisitType.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,16 +348,38 @@ struct GenericTypeVisitor
{
if (visit(ty, *utv))
{
bool unionChanged = false;
for (TypeId optTy : utv->options)
{
traverse(optTy);
if (!get<UnionType>(follow(ty)))
{
unionChanged = true;
break;
}
}

if (unionChanged)
traverse(ty);
}
}
else if (auto itv = get<IntersectionType>(ty))
{
if (visit(ty, *itv))
{
bool intersectionChanged = false;
for (TypeId partTy : itv->parts)
{
traverse(partTy);
if (!get<IntersectionType>(follow(ty)))
{
intersectionChanged = true;
break;
}
}

if (intersectionChanged)
traverse(ty);
}
}
else if (auto ltv = get<LazyType>(ty))
Expand Down
27 changes: 27 additions & 0 deletions Analysis/src/AstJsonEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include <math.h>

LUAU_FASTFLAG(LuauDeclarationExtraPropData)

namespace Luau
{

Expand Down Expand Up @@ -735,8 +737,21 @@ struct AstJsonEncoder : public AstVisitor
void write(class AstStatDeclareFunction* node)
{
writeNode(node, "AstStatDeclareFunction", [&]() {
// TODO: attributes
PROP(name);

if (FFlag::LuauDeclarationExtraPropData)
PROP(nameLocation);

PROP(params);

if (FFlag::LuauDeclarationExtraPropData)
{
PROP(paramNames);
PROP(vararg);
PROP(varargLocation);
}

PROP(retTypes);
PROP(generics);
PROP(genericPacks);
Expand All @@ -747,6 +762,10 @@ struct AstJsonEncoder : public AstVisitor
{
writeNode(node, "AstStatDeclareGlobal", [&]() {
PROP(name);

if (FFlag::LuauDeclarationExtraPropData)
PROP(nameLocation);

PROP(type);
});
}
Expand All @@ -756,8 +775,16 @@ struct AstJsonEncoder : public AstVisitor
writeRaw("{");
bool c = pushComma();
write("name", prop.name);

if (FFlag::LuauDeclarationExtraPropData)
write("nameLocation", prop.nameLocation);

writeType("AstDeclaredClassProp");
write("luauType", prop.ty);

if (FFlag::LuauDeclarationExtraPropData)
write("location", prop.location);

popComma(c);
writeRaw("}");
}
Expand Down
13 changes: 11 additions & 2 deletions Analysis/src/Autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1830,12 +1830,21 @@ AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName
if (!sourceModule)
return {};

ModulePtr module = frontend.moduleResolverForAutocomplete.getModule(moduleName);
ModulePtr module;
if (FFlag::DebugLuauDeferredConstraintResolution)
module = frontend.moduleResolver.getModule(moduleName);
else
module = frontend.moduleResolverForAutocomplete.getModule(moduleName);

if (!module)
return {};

NotNull<BuiltinTypes> builtinTypes = frontend.builtinTypes;
Scope* globalScope = frontend.globalsForAutocomplete.globalScope.get();
Scope* globalScope;
if (FFlag::DebugLuauDeferredConstraintResolution)
globalScope = frontend.globals.globalScope.get();
else
globalScope = frontend.globalsForAutocomplete.globalScope.get();

TypeArena typeArena;
return autocomplete(*sourceModule, module, builtinTypes, &typeArena, globalScope, position, callback);
Expand Down
4 changes: 2 additions & 2 deletions Analysis/src/BuiltinDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeC
NotNull<BuiltinTypes> builtinTypes = globals.builtinTypes;

if (FFlag::DebugLuauDeferredConstraintResolution)
kBuiltinTypeFamilies.addToScope(NotNull{&arena}, NotNull{globals.globalScope.get()});
builtinTypeFunctions().addToScope(NotNull{&arena}, NotNull{globals.globalScope.get()});

LoadDefinitionFileResult loadResult = frontend.loadDefinitionFile(
globals, globals.globalScope, getBuiltinDefinitionSource(), "@luau", /* captureComments */ false, typeCheckForAutocomplete);
Expand Down Expand Up @@ -313,7 +313,7 @@ void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeC
// declare function assert<T>(value: T, errorMessage: string?): intersect<T, ~(false?)>
TypeId genericT = arena.addType(GenericType{"T"});
TypeId refinedTy = arena.addType(TypeFamilyInstanceType{
NotNull{&kBuiltinTypeFamilies.intersectFamily}, {genericT, arena.addType(NegationType{builtinTypes->falsyType})}, {}});
NotNull{&builtinTypeFunctions().intersectFamily}, {genericT, arena.addType(NegationType{builtinTypes->falsyType})}, {}});

TypeId assertTy = arena.addType(FunctionType{
{genericT}, {}, arena.addTypePack(TypePack{{genericT, builtinTypes->optionalStringType}}), arena.addTypePack(TypePack{{refinedTy}})});
Expand Down
Loading

0 comments on commit 0d26888

Please sign in to comment.