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

Sync to upstream/release/517 #408

Merged
merged 61 commits into from
Mar 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
08c66ef
Sync to upstream/release/502
zeux Nov 5, 2021
5f7504c
Merge branch 'upstream' into merge
zeux Nov 5, 2021
34cf695
Sync to upstream/release/503
zeux Nov 5, 2021
3c4758f
Merge branch 'master' into merge
zeux Nov 5, 2021
22dd6b8
Merge branch 'upstream' into merge
zeux Nov 5, 2021
82d74e6
Sync to upstream/release/504
zeux Nov 12, 2021
ce0bbdd
Merge branch 'master' into merge
zeux Nov 12, 2021
8db1b03
Merge branch 'upstream' into merge
zeux Nov 12, 2021
8fe0dc0
Fix build
zeux Nov 12, 2021
863d3ff
Attempt to work around non-sensical error
zeux Nov 12, 2021
3c3541a
Add a comment
zeux Nov 12, 2021
60e6e86
Sync to upstream/release/505
zeux Nov 18, 2021
c5ac146
Merge branch 'master' into merge
zeux Nov 18, 2021
7835224
Merge branch 'upstream' into merge
zeux Nov 18, 2021
eed18ac
Sync to upstream/release/506
zeux Dec 2, 2021
47f7cbe
Merge branch 'master' into merge
zeux Dec 2, 2021
a179c52
Merge branch 'upstream' into merge
zeux Dec 2, 2021
e440729
Fix signed/unsigned mismatch warning + lower limit to match upstream
zeux Dec 2, 2021
a8673f0
Sync to upstream/release/507-pre
zeux Dec 10, 2021
891948e
Merge branch 'master' into merge
zeux Dec 10, 2021
bcf117b
Merge branch 'upstream' into merge
zeux Dec 10, 2021
a9aa4fa
Sync to upstream/release/508
zeux Jan 6, 2022
44ccd82
Sync to upstream/release/509
zeux Jan 6, 2022
bdf81c0
Merge branch 'master' into merge
zeux Jan 6, 2022
62a40d0
Merge commit 'a9aa4faf24e6cea1ac0e33d0054a7328a35f9d4a' into merge
zeux Jan 6, 2022
c7e1a94
Merge branch 'master' into merge
zeux Jan 7, 2022
8464a78
Merge branch 'upstream' into merge
zeux Jan 7, 2022
d189bd9
Enable V2Read flag early
zeux Jan 7, 2022
80d5c00
Sync to upstream/release/510
zeux Jan 14, 2022
e0af631
Merge branch 'master' into merge
zeux Jan 14, 2022
e6dd6bd
Merge branch 'upstream' into merge
zeux Jan 14, 2022
d70a078
Sync to upstream/release/511
zeux Jan 21, 2022
5b4af97
Merge branch 'master' into merge
zeux Jan 21, 2022
9cfe44e
Merge branch 'upstream' into merge
zeux Jan 21, 2022
699660a
Fix MSVC warnings
zeux Jan 21, 2022
0062000
One more
zeux Jan 21, 2022
9c15f6a
And one more
zeux Jan 21, 2022
6e1e277
Sync to upstream/release/512
zeux Jan 27, 2022
b2c8c3a
Merge branch 'master' into merge
zeux Jan 27, 2022
86b62ac
Merge branch 'upstream' into merge
zeux Jan 27, 2022
78039f4
Thanks gcc, we know you can't compile code.
zeux Jan 27, 2022
f6b4cc9
Sync to upstream/release/513
zeux Feb 3, 2022
4b4a6a7
Merge branch 'master' into merge
zeux Feb 3, 2022
7b3c24f
Merge branch 'upstream' into merge
zeux Feb 3, 2022
4e60eec
Apply fix to the crash
zeux Feb 4, 2022
4748777
Fix isocline warnings
zeux Feb 4, 2022
bbae466
Sync to upstream/release/513
zeux Feb 4, 2022
15bc249
Merge branch 'master' into merge
zeux Feb 4, 2022
6d40eb4
Merge branch 'upstream' into merge
zeux Feb 4, 2022
e9bf182
Sync to upstream/release/514
zeux Feb 11, 2022
46ba695
Merge branch 'master' into merge
zeux Feb 11, 2022
a08f52a
Merge branch 'upstream' into merge
zeux Feb 11, 2022
4930409
Sync to upstream/release/515
zeux Feb 18, 2022
eea0374
Merge branch 'master' into merge
zeux Feb 18, 2022
1f679b0
Merge branch 'upstream' into merge
zeux Feb 18, 2022
a8eabed
Sync to upstream/release/516
zeux Feb 24, 2022
2a549cf
Merge branch 'master' into merge
zeux Feb 24, 2022
8984f49
Merge branch 'upstream' into merge
zeux Feb 24, 2022
9bfecab
Sync to upstream/release/517
zeux Mar 4, 2022
600b8a4
Merge branch 'master' into merge
zeux Mar 4, 2022
75e66f1
Merge branch 'upstream' into merge
zeux Mar 4, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions Analysis/include/Luau/TxnLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ LUAU_FASTFLAG(LuauShareTxnSeen);
namespace Luau
{

using TypeOrPackId = const void*;

// Log of where what TypeIds we are rebinding and what they used to be
// Remove with LuauUseCommitTxnLog
struct DEPRECATED_TxnLog
Expand All @@ -23,7 +25,7 @@ struct DEPRECATED_TxnLog
{
}

explicit DEPRECATED_TxnLog(std::vector<std::pair<TypeId, TypeId>>* sharedSeen)
explicit DEPRECATED_TxnLog(std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen)
: originalSeenSize(sharedSeen->size())
, ownedSeen()
, sharedSeen(sharedSeen)
Expand All @@ -48,15 +50,23 @@ struct DEPRECATED_TxnLog
void pushSeen(TypeId lhs, TypeId rhs);
void popSeen(TypeId lhs, TypeId rhs);

bool haveSeen(TypePackId lhs, TypePackId rhs);
void pushSeen(TypePackId lhs, TypePackId rhs);
void popSeen(TypePackId lhs, TypePackId rhs);

private:
std::vector<std::pair<TypeId, TypeVar>> typeVarChanges;
std::vector<std::pair<TypePackId, TypePackVar>> typePackChanges;
std::vector<std::pair<TableTypeVar*, std::optional<TypeId>>> tableChanges;
size_t originalSeenSize;

bool haveSeen(TypeOrPackId lhs, TypeOrPackId rhs);
void pushSeen(TypeOrPackId lhs, TypeOrPackId rhs);
void popSeen(TypeOrPackId lhs, TypeOrPackId rhs);

public:
std::vector<std::pair<TypeId, TypeId>> ownedSeen; // used to avoid infinite recursion when types are cyclic
std::vector<std::pair<TypeId, TypeId>>* sharedSeen; // shared with all the descendent logs
std::vector<std::pair<TypeOrPackId, TypeOrPackId>> ownedSeen; // used to avoid infinite recursion when types are cyclic
std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen; // shared with all the descendent logs
};

// Pending state for a TypeVar. Generated by a TxnLog and committed via
Expand Down Expand Up @@ -127,12 +137,12 @@ struct TxnLog
}
}

explicit TxnLog(std::vector<std::pair<TypeId, TypeId>>* sharedSeen)
explicit TxnLog(std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen)
: sharedSeen(sharedSeen)
{
}

TxnLog(TxnLog* parent, std::vector<std::pair<TypeId, TypeId>>* sharedSeen)
TxnLog(TxnLog* parent, std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen)
: parent(parent)
, sharedSeen(sharedSeen)
{
Expand Down Expand Up @@ -173,6 +183,10 @@ struct TxnLog
void pushSeen(TypeId lhs, TypeId rhs);
void popSeen(TypeId lhs, TypeId rhs);

bool haveSeen(TypePackId lhs, TypePackId rhs) const;
void pushSeen(TypePackId lhs, TypePackId rhs);
void popSeen(TypePackId lhs, TypePackId rhs);

// Queues a type for modification. The original type will not change until commit
// is called. Use pending to get the pending state.
//
Expand Down Expand Up @@ -316,12 +330,16 @@ struct TxnLog
// TxnLogs; use sharedSeen instead. This field exists because in the tree
// of TxnLogs, the root must own its seen set. In all descendant TxnLogs,
// this is an empty vector.
std::vector<std::pair<TypeId, TypeId>> ownedSeen;
std::vector<std::pair<TypeOrPackId, TypeOrPackId>> ownedSeen;

bool haveSeen(TypeOrPackId lhs, TypeOrPackId rhs) const;
void pushSeen(TypeOrPackId lhs, TypeOrPackId rhs);
void popSeen(TypeOrPackId lhs, TypeOrPackId rhs);

public:
// Used to avoid infinite recursion when types are cyclic.
// Shared with all the descendent TxnLogs.
std::vector<std::pair<TypeId, TypeId>>* sharedSeen;
std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen;
};

} // namespace Luau
18 changes: 0 additions & 18 deletions Analysis/include/Luau/TypeInfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ struct Instantiation : Substitution
TypePackId clean(TypePackId tp) override;
};

// A substitution which replaces free types by generic types.
struct Quantification : Substitution
{
Quantification(TypeArena* arena, TypeLevel level)
: Substitution(TxnLog::empty(), arena)
, level(level)
{
}

TypeLevel level;
std::vector<TypeId> generics;
std::vector<TypePackId> genericPacks;
bool isDirty(TypeId ty) override;
bool isDirty(TypePackId tp) override;
TypeId clean(TypeId ty) override;
TypePackId clean(TypePackId tp) override;
};

// A substitution which replaces free types by any
struct Anyification : Substitution
{
Expand Down
5 changes: 4 additions & 1 deletion Analysis/include/Luau/TypeVar.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ struct TableTypeVar

TableTypeVar() = default;
explicit TableTypeVar(TableState state, TypeLevel level);
TableTypeVar(const Props& props, const std::optional<TableIndexer>& indexer, TypeLevel level, TableState state = TableState::Unsealed);
TableTypeVar(const Props& props, const std::optional<TableIndexer>& indexer, TypeLevel level, TableState state);

Props props;
std::optional<TableIndexer> indexer;
Expand Down Expand Up @@ -477,6 +477,9 @@ bool isOptional(TypeId ty);
bool isTableIntersection(TypeId ty);
bool isOverloadedFunction(TypeId ty);

// True when string is a subtype of ty
bool maybeString(TypeId ty);

std::optional<TypeId> getMetatable(TypeId type);
TableTypeVar* getMutableTableType(TypeId type);
const TableTypeVar* getTableType(TypeId type);
Expand Down
2 changes: 1 addition & 1 deletion Analysis/include/Luau/Unifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ struct Unifier

Unifier(TypeArena* types, Mode mode, const Location& location, Variance variance, UnifierSharedState& sharedState,
TxnLog* parentLog = nullptr);
Unifier(TypeArena* types, Mode mode, std::vector<std::pair<TypeId, TypeId>>* sharedSeen, const Location& location,
Unifier(TypeArena* types, Mode mode, std::vector<std::pair<TypeOrPackId, TypeOrPackId>>* sharedSeen, const Location& location,
Variance variance, UnifierSharedState& sharedState, TxnLog* parentLog = nullptr);

// Test whether the two type vars unify. Never commits the result.
Expand Down
62 changes: 20 additions & 42 deletions Analysis/src/Autocomplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
LUAU_FASTFLAG(LuauUseCommittingTxnLog)
LUAU_FASTFLAGVARIABLE(LuauAutocompleteAvoidMutation, false);
LUAU_FASTFLAGVARIABLE(LuauMissingFollowACMetatables, false);
LUAU_FASTFLAGVARIABLE(PreferToCallFunctionsForIntersects, false);
LUAU_FASTFLAGVARIABLE(LuauIfElseExprFixCompletionIssue, false);

static const std::unordered_set<std::string> kStatementStartingKeywords = {
Expand Down Expand Up @@ -272,55 +271,34 @@ static TypeCorrectKind checkTypeCorrectKind(const Module& module, TypeArena* typ

TypeId expectedType = follow(*typeAtPosition);

if (FFlag::PreferToCallFunctionsForIntersects)
{
auto checkFunctionType = [&canUnify, &expectedType](const FunctionTypeVar* ftv) {
auto [retHead, retTail] = flatten(ftv->retType);

if (!retHead.empty() && canUnify(retHead.front(), expectedType))
return true;

// We might only have a variadic tail pack, check if the element is compatible
if (retTail)
{
if (const VariadicTypePack* vtp = get<VariadicTypePack>(follow(*retTail)); vtp && canUnify(vtp->ty, expectedType))
return true;
}
auto checkFunctionType = [&canUnify, &expectedType](const FunctionTypeVar* ftv) {
auto [retHead, retTail] = flatten(ftv->retType);

return false;
};
if (!retHead.empty() && canUnify(retHead.front(), expectedType))
return true;

// We also want to suggest functions that return compatible result
if (const FunctionTypeVar* ftv = get<FunctionTypeVar>(ty); ftv && checkFunctionType(ftv))
// We might only have a variadic tail pack, check if the element is compatible
if (retTail)
{
return TypeCorrectKind::CorrectFunctionResult;
}
else if (const IntersectionTypeVar* itv = get<IntersectionTypeVar>(ty))
{
for (TypeId id : itv->parts)
{
if (const FunctionTypeVar* ftv = get<FunctionTypeVar>(id); ftv && checkFunctionType(ftv))
{
return TypeCorrectKind::CorrectFunctionResult;
}
}
if (const VariadicTypePack* vtp = get<VariadicTypePack>(follow(*retTail)); vtp && canUnify(vtp->ty, expectedType))
return true;
}

return false;
};

// We also want to suggest functions that return compatible result
if (const FunctionTypeVar* ftv = get<FunctionTypeVar>(ty); ftv && checkFunctionType(ftv))
{
return TypeCorrectKind::CorrectFunctionResult;
}
else
else if (const IntersectionTypeVar* itv = get<IntersectionTypeVar>(ty))
{
// We also want to suggest functions that return compatible result
if (const FunctionTypeVar* ftv = get<FunctionTypeVar>(ty))
for (TypeId id : itv->parts)
{
auto [retHead, retTail] = flatten(ftv->retType);

if (!retHead.empty() && canUnify(retHead.front(), expectedType))
return TypeCorrectKind::CorrectFunctionResult;

// We might only have a variadic tail pack, check if the element is compatible
if (retTail)
if (const FunctionTypeVar* ftv = get<FunctionTypeVar>(id); ftv && checkFunctionType(ftv))
{
if (const VariadicTypePack* vtp = get<VariadicTypePack>(follow(*retTail)); vtp && canUnify(vtp->ty, expectedType))
return TypeCorrectKind::CorrectFunctionResult;
return TypeCorrectKind::CorrectFunctionResult;
}
}
}
Expand Down
13 changes: 11 additions & 2 deletions Analysis/src/BuiltinDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <algorithm>

LUAU_FASTFLAG(LuauAssertStripsFalsyTypes)
LUAU_FASTFLAGVARIABLE(LuauTableCloneType, false)

/** FIXME: Many of these type definitions are not quite completely accurate.
*
Expand Down Expand Up @@ -283,8 +284,16 @@ void registerBuiltinTypes(TypeChecker& typeChecker)
attachMagicFunction(getGlobalBinding(typeChecker, "setmetatable"), magicFunctionSetMetaTable);
attachMagicFunction(getGlobalBinding(typeChecker, "select"), magicFunctionSelect);

auto tableLib = getMutable<TableTypeVar>(getGlobalBinding(typeChecker, "table"));
attachMagicFunction(tableLib->props["pack"].type, magicFunctionPack);
if (TableTypeVar* ttv = getMutable<TableTypeVar>(getGlobalBinding(typeChecker, "table")))
{
// tabTy is a generic table type which we can't express via declaration syntax yet
ttv->props["freeze"] = makeProperty(makeFunction(arena, std::nullopt, {tabTy}, {tabTy}), "@luau/global/table.freeze");

if (FFlag::LuauTableCloneType)
ttv->props["clone"] = makeProperty(makeFunction(arena, std::nullopt, {tabTy}, {tabTy}), "@luau/global/table.clone");

attachMagicFunction(ttv->props["pack"].type, magicFunctionPack);
}

attachMagicFunction(getGlobalBinding(typeChecker, "require"), magicFunctionRequire);
}
Expand Down
1 change: 0 additions & 1 deletion Analysis/src/EmbeddedBuiltinDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ declare function gcinfo(): number
move: <V>({V}, number, number, number, {V}?) -> {V},
clear: <K, V>({[K]: V}) -> (),

freeze: <K, V>({[K]: V}) -> {[K]: V},
isfrozen: <K, V>({[K]: V}) -> boolean,
}

Expand Down
44 changes: 14 additions & 30 deletions Analysis/src/JsonEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include "Luau/StringUtils.h"
#include "Luau/Common.h"

LUAU_FASTFLAG(LuauTypeAliasDefaults)

namespace Luau
{

Expand Down Expand Up @@ -369,38 +367,24 @@ struct AstJsonEncoder : public AstVisitor

void write(const AstGenericType& genericType)
{
if (FFlag::LuauTypeAliasDefaults)
{
writeRaw("{");
bool c = pushComma();
write("name", genericType.name);
if (genericType.defaultValue)
write("type", genericType.defaultValue);
popComma(c);
writeRaw("}");
}
else
{
write(genericType.name);
}
writeRaw("{");
bool c = pushComma();
write("name", genericType.name);
if (genericType.defaultValue)
write("type", genericType.defaultValue);
popComma(c);
writeRaw("}");
}

void write(const AstGenericTypePack& genericTypePack)
{
if (FFlag::LuauTypeAliasDefaults)
{
writeRaw("{");
bool c = pushComma();
write("name", genericTypePack.name);
if (genericTypePack.defaultValue)
write("type", genericTypePack.defaultValue);
popComma(c);
writeRaw("}");
}
else
{
write(genericTypePack.name);
}
writeRaw("{");
bool c = pushComma();
write("name", genericTypePack.name);
if (genericTypePack.defaultValue)
write("type", genericTypePack.defaultValue);
popComma(c);
writeRaw("}");
}

void write(AstExprTable::Item::Kind kind)
Expand Down
Loading