mirror of
https://github.com/luau-lang/luau.git
synced 2024-12-13 13:30:40 +00:00
daf79328fc
### What's new? * Remove a case of unsound `table.move` optimization * Add Luau stack slot reservations that were missing in REPL (fixes #1273) ### New Type Solver * Assignments have been completely reworked to fix a case of cyclic constraint dependency * When indexing, if the fresh type's upper bound already contains a compatible indexer, do not add another upper bound * Distribute type arguments over all type families sans `eq`, `keyof`, `rawkeyof`, and other internal type families * Fix a case where `buffers` component weren't read in two places (fixes #1267) * Fix a case where things that constitutes a strong ref were slightly incorrect * Fix a case where constraint dependencies weren't setup wrt `for ... in` statement ### Native Codegen * Fix an optimization that splits TValue store only when its value and its tag are compatible * Implement a system to plug additional type information for custom host userdata types --- ### 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: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- Co-authored-by: Aaron Weiss <aaronweiss@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>
101 lines
3 KiB
Lua
101 lines
3 KiB
Lua
-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
-- This file is based on Lua 5.x tests -- https://github.com/lua/lua/tree/master/testes
|
|
local function checkerror (msg, f, ...)
|
|
local s, err = pcall(f, ...)
|
|
assert(not s and string.find(err, msg))
|
|
end
|
|
|
|
print("testing move")
|
|
|
|
local maxI = 2147483647
|
|
local minI = -2147483648
|
|
|
|
-- testing move
|
|
do
|
|
|
|
checkerror("table expected", table.move, 1, 2, 3, 4)
|
|
checkerror("table expected", table.move, {}, 2, 3, 4, "foo")
|
|
|
|
local function eqT (a, b)
|
|
for k, v in pairs(a) do assert(b[k] == v) end
|
|
for k, v in pairs(b) do assert(a[k] == v) end
|
|
end
|
|
|
|
local a = table.move({10,20,30}, 1, 3, 2) -- move forward
|
|
eqT(a, {10,10,20,30})
|
|
|
|
-- move forward with overlap of 1
|
|
a = table.move({10, 20, 30}, 1, 3, 3)
|
|
eqT(a, {10, 20, 10, 20, 30})
|
|
|
|
-- moving to the same table (not being explicit about it)
|
|
a = {10, 20, 30, 40}
|
|
table.move(a, 1, 4, 2, a)
|
|
eqT(a, {10, 10, 20, 30, 40})
|
|
|
|
a = table.move({10,20,30}, 2, 3, 1) -- move backward
|
|
eqT(a, {20,30,30})
|
|
|
|
a = {} -- move to new table
|
|
assert(table.move({10,20,30}, 1, 3, 1, a) == a)
|
|
eqT(a, {10,20,30})
|
|
|
|
a = {}
|
|
assert(table.move({10,20,30}, 1, 0, 3, a) == a) -- empty move (no move)
|
|
eqT(a, {})
|
|
|
|
a = table.move({10,20,30}, 1, 10, 1) -- move to the same place
|
|
eqT(a, {10,20,30})
|
|
|
|
-- moving on the fringes
|
|
a = table.move({[maxI - 2] = 1, [maxI - 1] = 2, [maxI] = 3},
|
|
maxI - 2, maxI, -10, {})
|
|
eqT(a, {[-10] = 1, [-9] = 2, [-8] = 3})
|
|
|
|
a = table.move({[minI] = 1, [minI + 1] = 2, [minI + 2] = 3},
|
|
minI, minI + 2, -10, {})
|
|
eqT(a, {[-10] = 1, [-9] = 2, [-8] = 3})
|
|
|
|
a = table.move({45}, 1, 1, maxI)
|
|
eqT(a, {45, [maxI] = 45})
|
|
|
|
a = table.move({[maxI] = 100}, maxI, maxI, minI)
|
|
eqT(a, {[minI] = 100, [maxI] = 100})
|
|
|
|
a = table.move({[minI] = 100}, minI, minI, maxI)
|
|
eqT(a, {[minI] = 100, [maxI] = 100})
|
|
|
|
-- hash part skips array slice
|
|
a = {}
|
|
table.move({[-1] = 1, [0] = 2, [1] = 3, [2] = 4}, -1, 3, 1, a)
|
|
eqT(a, {[1] = 1, [2] = 2, [3] = 3, [4] = 4})
|
|
|
|
a = {}
|
|
table.move({[-1] = 1, [0] = 2, [1] = 3, [2] = 4, [10] = 5, [100] = 6, [1000] = 7}, -1, 3, 1, a)
|
|
eqT(a, {[1] = 1, [2] = 2, [3] = 3, [4] = 4})
|
|
|
|
-- moving ranges containing nil values into tables with values
|
|
a = {1, 2, 3, 4, 5}
|
|
table.move({10}, 1, 3, 2, a)
|
|
eqT(a, {1, 10, nil, nil, 5})
|
|
|
|
a = {1, 2, 3, 4, 5}
|
|
table.move({10}, -1, 1, 2, a)
|
|
eqT(a, {1, nil, nil, 10, 5})
|
|
|
|
a = {[-1000] = 1, [1000] = 2, [1] = 3}
|
|
table.move({10}, -1000, 1000, -1000, a)
|
|
eqT(a, {10})
|
|
end
|
|
|
|
checkerror("too many", table.move, {}, 0, maxI, 1)
|
|
checkerror("too many", table.move, {}, -1, maxI - 1, 1)
|
|
checkerror("too many", table.move, {}, minI, -1, 1)
|
|
checkerror("too many", table.move, {}, minI, maxI, 1)
|
|
checkerror("wrap around", table.move, {}, 1, maxI, 2)
|
|
checkerror("wrap around", table.move, {}, 1, 2, maxI)
|
|
checkerror("wrap around", table.move, {}, minI, -2, 2)
|
|
|
|
checkerror("readonly", table.move, table.freeze({}), 1, 1, 1)
|
|
|
|
return"OK"
|