diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b7e551e..b0b96278 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,6 +28,7 @@ add_library(Luau.Ast STATIC) add_library(Luau.Compiler STATIC) add_library(Luau.Config STATIC) add_library(Luau.Analysis STATIC) +add_library(Luau.EqSat STATIC) add_library(Luau.CodeGen STATIC) add_library(Luau.VM STATIC) add_library(isocline STATIC) @@ -83,7 +84,12 @@ target_link_libraries(Luau.Config PUBLIC Luau.Ast) target_compile_features(Luau.Analysis PUBLIC cxx_std_17) target_include_directories(Luau.Analysis PUBLIC Analysis/include) -target_link_libraries(Luau.Analysis PUBLIC Luau.Ast Luau.Config) +target_link_libraries(Luau.Analysis PUBLIC Luau.Ast Luau.EqSat Luau.Config) + +target_compile_features(Luau.EqSat PUBLIC cxx_std_17) +target_include_directories(Luau.EqSat PUBLIC EqSat/include) +target_link_libraries(Luau.EqSat PUBLIC Luau.Common) +set_target_properties(Luau.EqSat PROPERTIES LINKER_LANGUAGE CXX) target_compile_features(Luau.CodeGen PRIVATE cxx_std_17) target_include_directories(Luau.CodeGen PUBLIC CodeGen/include) @@ -141,6 +147,7 @@ endif() target_compile_options(Luau.Ast PRIVATE ${LUAU_OPTIONS}) target_compile_options(Luau.Analysis PRIVATE ${LUAU_OPTIONS}) +target_compile_options(Luau.EqSat PRIVATE ${LUAU_OPTIONS}) target_compile_options(Luau.CLI.lib PRIVATE ${LUAU_OPTIONS}) target_compile_options(Luau.CodeGen PRIVATE ${LUAU_OPTIONS}) target_compile_options(Luau.VM PRIVATE ${LUAU_OPTIONS}) @@ -260,16 +267,16 @@ if(LUAU_BUILD_WEB) target_link_options(Luau.Web PRIVATE -sSINGLE_FILE=1) endif() -add_subdirectory(fuzz) +# add_subdirectory(fuzz) # validate dependencies for internal libraries -foreach(LIB Luau.Ast Luau.Compiler Luau.Config Luau.Analysis Luau.CodeGen Luau.VM) +foreach(LIB Luau.Ast Luau.Compiler Luau.Config Luau.Analysis Luau.EqSat Luau.CodeGen Luau.VM) if(TARGET ${LIB}) get_target_property(DEPENDS ${LIB} LINK_LIBRARIES) if(LIB MATCHES "CodeGen|VM" AND DEPENDS MATCHES "Ast|Analysis|Config|Compiler") message(FATAL_ERROR ${LIB} " is a runtime component but it depends on one of the offline components") endif() - if(LIB MATCHES "Ast|Analysis|Compiler" AND DEPENDS MATCHES "CodeGen|VM") + if(LIB MATCHES "Ast|Analysis|EqSat|Compiler" AND DEPENDS MATCHES "CodeGen|VM") message(FATAL_ERROR ${LIB} " is an offline component but it depends on one of the runtime components") endif() if(LIB MATCHES "Ast|Compiler" AND DEPENDS MATCHES "Analysis|Config") diff --git a/EqSat/include/Luau/Id.h b/EqSat/include/Luau/Id.h new file mode 100644 index 00000000..15d46d84 --- /dev/null +++ b/EqSat/include/Luau/Id.h @@ -0,0 +1,20 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#pragma once + +namespace Luau::EqSat +{ + +struct Id final +{ + explicit Id(size_t id); + + explicit operator size_t() const; + + bool operator==(Id rhs) const; + bool operator!=(Id rhs) const; + +private: + size_t id; +}; + +} // namespace Luau::EqSat diff --git a/EqSat/src/Id.cpp b/EqSat/src/Id.cpp new file mode 100644 index 00000000..e8f2b63e --- /dev/null +++ b/EqSat/src/Id.cpp @@ -0,0 +1,38 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#include "Luau/Id.h" + +#include + +namespace Luau::EqSat +{ + +Id::Id(size_t id) + : id(id) +{ +} + +Id::operator size_t() const +{ + return id; +} + +bool Id::operator==(Id rhs) const +{ + return id == rhs.id; +} + +bool Id::operator!=(Id rhs) const +{ + return id != rhs.id; +} + +} // namespace Luau::EqSat + +template<> +struct std::hash +{ + size_t operator()(Luau::EqSat::Id id) const + { + return std::hash()(size_t(id)); + } +}; diff --git a/Sources.cmake b/Sources.cmake index 4c5504b6..1b87a328 100644 --- a/Sources.cmake +++ b/Sources.cmake @@ -295,6 +295,13 @@ target_sources(Luau.Analysis PRIVATE Analysis/src/Unifier2.cpp ) +# Luau.Analysis Sources +target_sources(Luau.EqSat PRIVATE + EqSat/include/Luau/Id.h + + EqSat/src/Id.cpp +) + # Luau.VM Sources target_sources(Luau.VM PRIVATE VM/include/lua.h diff --git a/tests/EqSat.propositional.test.cpp b/tests/EqSat.propositional.test.cpp new file mode 100644 index 00000000..0cbb2e25 --- /dev/null +++ b/tests/EqSat.propositional.test.cpp @@ -0,0 +1,8 @@ +// This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details +#include + +// Var, Bool, And, Or, Not, Implies + +TEST_SUITE_BEGIN("EqSatPropositionalLogic"); + +TEST_SUITE_END();