mirror of
https://github.com/luau-lang/luau.git
synced 2024-11-15 22:35:43 +08:00
c755875479
- Implemented [Require by String with Relative Paths](https://github.com/luau-lang/rfcs/blob/master/docs/new-require-by-string-semantics.md) RFC - Implemented [Require by String with Aliases](https://github.com/luau-lang/rfcs/blob/master/docs/require-by-string-aliases.md) RFC with support for `paths` and `alias` arrays in .luarc - Added SUBRK and DIVRK bytecode instructions to speed up constant-number and constant/number operations - Added `--vector-lib`, `--vector-ctor` and `--vector-type` options to luau-compile to support code with vectors New Solver - Correctness fixes to subtyping - Improvements to dataflow analysis Native Code Generation - Added bytecode analysis pass to predict type tags used in operations - Fixed rare cases of numerical loops being generated without an interrupt instruction - Restored optimization data propagation into the linear block - Duplicate buffer length checks are optimized away Miscellaneous - Small performance improvements to new non-strict mode - Introduced more scripts for fuzzing Luau and processing the results, including fuzzer build support for CMake Co-authored-by: Alexander McCord <amccord@roblox.com> Co-authored-by: Andy Friesen <afriesen@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: Vighnesh Vijay <vvijay@roblox.com> Co-authored-by: Vyacheslav Egorov <vegorov@roblox.com> --------- 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: 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>
90 lines
2.1 KiB
C++
90 lines
2.1 KiB
C++
// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
|
#include "Luau/Symbol.h"
|
|
#include "Luau/Ast.h"
|
|
|
|
#include "Fixture.h"
|
|
|
|
#include "doctest.h"
|
|
|
|
using namespace Luau;
|
|
|
|
LUAU_FASTFLAG(DebugLuauDeferredConstraintResolution)
|
|
|
|
TEST_SUITE_BEGIN("SymbolTests");
|
|
|
|
TEST_CASE("equality_and_hashing_of_globals")
|
|
{
|
|
std::string s1 = "name";
|
|
std::string s2 = "name";
|
|
|
|
// These two names point to distinct memory areas.
|
|
AstName one{s1.data()};
|
|
AstName two{s2.data()};
|
|
|
|
Symbol n1{one};
|
|
Symbol n2{two};
|
|
|
|
CHECK(n1 == n1);
|
|
CHECK(n1 == n2);
|
|
CHECK(n2 == n2);
|
|
|
|
CHECK_EQ(std::hash<Symbol>()(one), std::hash<Symbol>()(one));
|
|
CHECK_EQ(std::hash<Symbol>()(one), std::hash<Symbol>()(two));
|
|
CHECK_EQ(std::hash<Symbol>()(two), std::hash<Symbol>()(two));
|
|
|
|
std::unordered_map<Symbol, int> theMap;
|
|
theMap[n1] = 5;
|
|
theMap[n2] = 1;
|
|
|
|
REQUIRE_EQ(1, theMap.size());
|
|
}
|
|
|
|
TEST_CASE("equality_and_hashing_of_locals")
|
|
{
|
|
std::string s1 = "name";
|
|
std::string s2 = "name";
|
|
|
|
// These two names point to distinct memory areas.
|
|
AstLocal one{AstName{s1.data()}, Location(), nullptr, 0, 0, nullptr};
|
|
AstLocal two{AstName{s2.data()}, Location(), &one, 0, 0, nullptr};
|
|
|
|
Symbol n1{&one};
|
|
Symbol n2{&two};
|
|
|
|
CHECK(n1 == n1);
|
|
CHECK(n1 != n2);
|
|
CHECK(n2 == n2);
|
|
|
|
CHECK_EQ(std::hash<Symbol>()(&one), std::hash<Symbol>()(&one));
|
|
CHECK_NE(std::hash<Symbol>()(&one), std::hash<Symbol>()(&two));
|
|
CHECK_EQ(std::hash<Symbol>()(&two), std::hash<Symbol>()(&two));
|
|
|
|
std::unordered_map<Symbol, int> theMap;
|
|
theMap[n1] = 5;
|
|
theMap[n2] = 1;
|
|
|
|
REQUIRE_EQ(2, theMap.size());
|
|
}
|
|
|
|
TEST_CASE("equality_of_empty_symbols")
|
|
{
|
|
ScopedFastFlag sff{FFlag::DebugLuauDeferredConstraintResolution, true};
|
|
|
|
std::string s1 = "name";
|
|
std::string s2 = "name";
|
|
|
|
AstName one{s1.data()};
|
|
AstLocal two{AstName{s2.data()}, Location(), nullptr, 0, 0, nullptr};
|
|
|
|
Symbol global{one};
|
|
Symbol local{&two};
|
|
Symbol empty1{};
|
|
Symbol empty2{};
|
|
|
|
CHECK(empty1 != global);
|
|
CHECK(empty1 != local);
|
|
CHECK(empty1 == empty2);
|
|
}
|
|
|
|
TEST_SUITE_END();
|