Skip to content

Commit 0d26888

Browse files
aatxealexmccordandyfriesenVighnesh-Vaviralg
authored
Sync to upstream/release/632 (#1307)
# 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 <aaronweiss@roblox.com> Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: James McNellis <jmcnellis@roblox.com> Co-authored-by: Jeremy Yoo <jyoo@roblox.com> Co-authored-by: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@roblox.com> Co-authored-by: Vighnesh <vvijay@roblox.com> Co-authored-by: Aviral Goel <agoel@roblox.com> Co-authored-by: David Cope <dcope@roblox.com> Co-authored-by: Lily Brown <lbrown@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com>
1 parent caee04d commit 0d26888

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1235
-934
lines changed

Analysis/include/Luau/Frontend.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ struct Frontend
191191
void queueModuleCheck(const std::vector<ModuleName>& names);
192192
void queueModuleCheck(const ModuleName& name);
193193
std::vector<ModuleName> checkQueuedModules(std::optional<FrontendOptions> optionOverride = {},
194-
std::function<void(std::function<void()> task)> executeTask = {}, std::function<void(size_t done, size_t total)> progress = {});
194+
std::function<void(std::function<void()> task)> executeTask = {}, std::function<bool(size_t done, size_t total)> progress = {});
195195

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

Analysis/include/Luau/TypeFamily.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,12 +180,11 @@ struct BuiltinTypeFamilies
180180
TypeFamily rawkeyofFamily;
181181

182182
TypeFamily indexFamily;
183+
TypeFamily rawgetFamily;
183184

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

187-
188-
189-
const BuiltinTypeFamilies kBuiltinTypeFamilies{};
188+
const BuiltinTypeFamilies& builtinTypeFunctions();
190189

191190
} // namespace Luau

Analysis/include/Luau/VisitType.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,16 +348,38 @@ struct GenericTypeVisitor
348348
{
349349
if (visit(ty, *utv))
350350
{
351+
bool unionChanged = false;
351352
for (TypeId optTy : utv->options)
353+
{
352354
traverse(optTy);
355+
if (!get<UnionType>(follow(ty)))
356+
{
357+
unionChanged = true;
358+
break;
359+
}
360+
}
361+
362+
if (unionChanged)
363+
traverse(ty);
353364
}
354365
}
355366
else if (auto itv = get<IntersectionType>(ty))
356367
{
357368
if (visit(ty, *itv))
358369
{
370+
bool intersectionChanged = false;
359371
for (TypeId partTy : itv->parts)
372+
{
360373
traverse(partTy);
374+
if (!get<IntersectionType>(follow(ty)))
375+
{
376+
intersectionChanged = true;
377+
break;
378+
}
379+
}
380+
381+
if (intersectionChanged)
382+
traverse(ty);
361383
}
362384
}
363385
else if (auto ltv = get<LazyType>(ty))

Analysis/src/AstJsonEncoder.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#include <math.h>
1010

11+
LUAU_FASTFLAG(LuauDeclarationExtraPropData)
12+
1113
namespace Luau
1214
{
1315

@@ -735,8 +737,21 @@ struct AstJsonEncoder : public AstVisitor
735737
void write(class AstStatDeclareFunction* node)
736738
{
737739
writeNode(node, "AstStatDeclareFunction", [&]() {
740+
// TODO: attributes
738741
PROP(name);
742+
743+
if (FFlag::LuauDeclarationExtraPropData)
744+
PROP(nameLocation);
745+
739746
PROP(params);
747+
748+
if (FFlag::LuauDeclarationExtraPropData)
749+
{
750+
PROP(paramNames);
751+
PROP(vararg);
752+
PROP(varargLocation);
753+
}
754+
740755
PROP(retTypes);
741756
PROP(generics);
742757
PROP(genericPacks);
@@ -747,6 +762,10 @@ struct AstJsonEncoder : public AstVisitor
747762
{
748763
writeNode(node, "AstStatDeclareGlobal", [&]() {
749764
PROP(name);
765+
766+
if (FFlag::LuauDeclarationExtraPropData)
767+
PROP(nameLocation);
768+
750769
PROP(type);
751770
});
752771
}
@@ -756,8 +775,16 @@ struct AstJsonEncoder : public AstVisitor
756775
writeRaw("{");
757776
bool c = pushComma();
758777
write("name", prop.name);
778+
779+
if (FFlag::LuauDeclarationExtraPropData)
780+
write("nameLocation", prop.nameLocation);
781+
759782
writeType("AstDeclaredClassProp");
760783
write("luauType", prop.ty);
784+
785+
if (FFlag::LuauDeclarationExtraPropData)
786+
write("location", prop.location);
787+
761788
popComma(c);
762789
writeRaw("}");
763790
}

Analysis/src/Autocomplete.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1830,12 +1830,21 @@ AutocompleteResult autocomplete(Frontend& frontend, const ModuleName& moduleName
18301830
if (!sourceModule)
18311831
return {};
18321832

1833-
ModulePtr module = frontend.moduleResolverForAutocomplete.getModule(moduleName);
1833+
ModulePtr module;
1834+
if (FFlag::DebugLuauDeferredConstraintResolution)
1835+
module = frontend.moduleResolver.getModule(moduleName);
1836+
else
1837+
module = frontend.moduleResolverForAutocomplete.getModule(moduleName);
1838+
18341839
if (!module)
18351840
return {};
18361841

18371842
NotNull<BuiltinTypes> builtinTypes = frontend.builtinTypes;
1838-
Scope* globalScope = frontend.globalsForAutocomplete.globalScope.get();
1843+
Scope* globalScope;
1844+
if (FFlag::DebugLuauDeferredConstraintResolution)
1845+
globalScope = frontend.globals.globalScope.get();
1846+
else
1847+
globalScope = frontend.globalsForAutocomplete.globalScope.get();
18391848

18401849
TypeArena typeArena;
18411850
return autocomplete(*sourceModule, module, builtinTypes, &typeArena, globalScope, position, callback);

Analysis/src/BuiltinDefinitions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ void registerBuiltinGlobals(Frontend& frontend, GlobalTypes& globals, bool typeC
216216
NotNull<BuiltinTypes> builtinTypes = globals.builtinTypes;
217217

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

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

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

0 commit comments

Comments
 (0)