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

[ImportVerilog] Bump slang #7792

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft

Conversation

hovind
Copy link
Contributor

@hovind hovind commented Nov 10, 2024

Some groundwork towards using a more up to date slang verison.

TODO

CMakeLists.txt Outdated
FetchContent_MakeAvailable(slang)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where it is most appropriate to set this, input would be much appreciated.

else()
find_package(slang 3.0 REQUIRED)
find_package(slang 7.0 REQUIRED)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO: Ask slang to mint a release so that this version includes everything that we need, including MikePopoloski/slang#1164.

inline bool operator==(uint64_t a, const FVInt &b) { return b == a; }
inline bool operator!=(uint64_t a, const FVInt &b) { return b != a; }
inline bool operator==(uint64_t a, const FVInt &b) { return b.operator==(a); }
inline bool operator!=(uint64_t a, const FVInt &b) { return b.operator!=(a); }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any tips on how to best deal with https://timsong-cpp.github.io/cppwp/n4868/over.match#oper-3.4.4 in a codebase that still needs to support older standards?

@hovind
Copy link
Contributor Author

hovind commented Nov 10, 2024

Currently fails in CI due to

GCC

2024-11-10T17:59:53.5774363Z FAILED: _deps/slang-build/source/CMakeFiles/slang_slang.dir/diagnostics/DiagnosticClient.cpp.o 
2024-11-10T17:59:53.5790822Z /usr/bin/g++ -DSLANG_BOOST_SINGLE_HEADER -DSLANG_STATIC_DEFINE -D_DEBUG -D_GLIBCXX_ASSERTIONS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/__w/circt/circt/llvm/install/include -I/__w/circt/circt/include -I/__w/circt/circt/build/include -I/__w/circt/circt/build/_deps/slang-src/source/../include -I/__w/circt/circt/build/_deps/slang-build/source -isystem /__w/circt/circt/build/_deps/slang-src/source/../external -isystem /__w/circt/circt/build/_deps/fmt-src/include -O3 -DNDEBUG -fvisibility=hidden -fvisibility-inlines-hidden -UNDEBUG -std=c++2a -MD -MT _deps/slang-build/source/CMakeFiles/slang_slang.dir/diagnostics/DiagnosticClient.cpp.o -MF _deps/slang-build/source/CMakeFiles/slang_slang.dir/diagnostics/DiagnosticClient.cpp.o.d -o _deps/slang-build/source/CMakeFiles/slang_slang.dir/diagnostics/DiagnosticClient.cpp.o -c /__w/circt/circt/build/_deps/slang-src/source/diagnostics/DiagnosticClient.cpp
2024-11-10T17:59:53.5806008Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/diagnostics/DiagnosticEngine.h:16,
2024-11-10T17:59:53.5807967Z                  from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/diagnostics/DiagnosticClient.h:10,
2024-11-10T17:59:53.5809625Z                  from /__w/circt/circt/build/_deps/slang-src/source/diagnostics/DiagnosticClient.cpp:8:
2024-11-10T17:59:53.5811625Z /__w/circt/circt/build/_deps/slang-src/source/../include/slang/diagnostics/Diagnostics.h:11:10: fatal error: concepts: No such file or directory
2024-11-10T17:59:53.5813055Z    11 | #include <concepts>

concepts was implemented in gcc-10: https://gcc.gnu.org/gcc-10/changes.html#cxx, while CI has

$ docker run ghcr.io/circt/images/circt-ci-build:20240213211952 /usr/bin/gcc --version
gcc (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0

as far as I can tell.

clang

2024-11-10T18:01:25.2568466Z CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/lib/ccache/clang++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/__w/circt/circt/build/tools/circt/lib/Conversion/ImportVerilog -I/__w/circt/circt/lib/Conversion/ImportVerilog -I/__w/circt/circt/build/include -I/__w/circt/circt/llvm/llvm/include -I/__w/circt/circt/include -I/__w/circt/circt/build/tools/circt/include -I/__w/circt/circt/build/_deps/slang-src/source/../include -I/__w/circt/circt/build/_deps/slang-build/source -I/__w/circt/circt/build/_deps/slang-src/source/../external -I/__w/circt/circt/build/_deps/fmt-src/include -isystem /__w/circt/circt/llvm/llvm/../mlir/include -isystem /__w/circt/circt/build/tools/mlir/include -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -fvisibility-inlines-hidden  -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -Wno-non-virtual-dtor -Wno-ctad-maybe-unsupported -Wno-covered-switch-default -std=c++20 -MD -MT tools/circt/lib/Conversion/ImportVerilog/CMakeFiles/obj.CIRCTImportVerilog.dir/Statements.cpp.o -MF tools/circt/lib/Conversion/ImportVerilog/CMakeFiles/obj.CIRCTImportVerilog.dir/Statements.cpp.o.d -o tools/circt/lib/Conversion/ImportVerilog/CMakeFiles/obj.CIRCTImportVerilog.dir/Statements.cpp.o -c /__w/circt/circt/lib/Conversion/ImportVerilog/Statements.cpp
2024-11-10T18:01:25.2599620Z In file included from /__w/circt/circt/lib/Conversion/ImportVerilog/Statements.cpp:9:
2024-11-10T18:01:25.2601788Z In file included from /__w/circt/circt/lib/Conversion/ImportVerilog/ImportVerilogInternals.h:19:
2024-11-10T18:01:25.2604162Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/ASTVisitor.h:10:
2024-11-10T18:01:25.2606447Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/Constraints.h:10:
2024-11-10T18:01:25.2608744Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/Statements.h:10:
2024-11-10T18:01:25.2610961Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/Expression.h:10:
2024-11-10T18:01:25.2613180Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/ASTContext.h:12:
2024-11-10T18:01:25.2615377Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/ast/Lookup.h:11:
2024-11-10T18:01:25.2617701Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/diagnostics/Diagnostics.h:18:
2024-11-10T18:01:25.2620056Z In file included from /__w/circt/circt/build/_deps/slang-src/source/../include/slang/text/SourceLocation.h:14:
2024-11-10T18:01:25.2622749Z /__w/circt/circt/build/_deps/slang-src/source/../include/slang/util/Hash.h:19:14: fatal error: 'boost/unordered/unordered_flat_map.hpp' file not found

The clang seems to me to be missing -DSLANG_BOOST_SINGLE_HEADER, which is correctly set in the gcc build.

@@ -1,6 +1,4 @@
# slang uses exceptions
set(LLVM_REQUIRES_EH ON)
set(LLVM_REQUIRES_RTTI ON)

# For ABI compatibility, define the DEBUG macro in debug builds. Slang sets this
# internally. If we don't set this here as well, header-defined things like the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really shouldn't be necessary; ideally adding the slang lib as a target should bring along its public compile definitions. Is there something I should be fixing on the slang side to do away with this here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for taking a look here @MikePopoloski, it's much appreciated. I'm not good enough at CMake to answer all of your comments, but I'm hoping that somebody more qualified can chime in where needed.

@@ -15,15 +13,10 @@ add_compile_definitions($<$<CONFIG:Debug>:DEBUG>)
if (MSVC)
# No idea what to put here
else ()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you not specify slang include directories as being -isystem so that you don't need these warning suppressions?

@@ -551,14 +551,17 @@ llvm_canonicalize_cmake_booleans(CIRCT_SLANG_BUILD_FROM_SOURCE)
if(CIRCT_SLANG_FRONTEND_ENABLED)
message(STATUS "slang Verilog frontend is enabled")
if(CIRCT_SLANG_BUILD_FROM_SOURCE)
# slang requires C++20

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this actually needed? slang's CMakeLists already sets these.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I get an error trying to build ImportVerilog due to public headers in slang requiring C++ 20 if I remove this, but perhaps there's a more principled way to solve this?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see, that makes sense. It's a little unfortunate that this is adding friction but I make extensive use of, e.g. std::span that would be hard to remove from the public headers. Hopefully LLVM / MLIR / CIRCT can upgrade to C++20 at some point across the board; it's coming up on 5 years old.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive by comment: in general, it's OK to require c++20 (or other non-llvm-standard things like exceptions) if they're optional and can be disabled. Since slang is an optional dependency, it's OK to require c++20 when slang is being used. We just need to be sure to run a ci build with c++17 and no slang.

@@ -573,6 +576,7 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
set(CMAKE_CXX_FLAGS "")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The MSVC /EHsc is probably not needed now?

@@ -590,17 +593,24 @@ if(CIRCT_SLANG_FRONTEND_ENABLED)
# statically link slang into the CIRCTImportVerilog library, but seems to be
# harder than it ought to be.
set_property(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it seems like all this install / export stuff shouldn't be needed but I'm not enough of a CMake expert to know offhand how to fix it.

@@ -646,8 +646,8 @@ inline FVInt operator-(uint64_t a, const FVInt &b) {

inline FVInt operator-(const APInt &a, const FVInt &b) { return FVInt(a) - b; }

inline bool operator==(uint64_t a, const FVInt &b) { return b == a; }
inline bool operator!=(uint64_t a, const FVInt &b) { return b != a; }
inline bool operator==(uint64_t a, const FVInt &b) { return b.operator==(a); }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this related to the slang version? Is it picking up some overzealous global operator in slang somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a consequence of building circt code with C++ 20 for the first time, where https://timsong-cpp.github.io/cppwp/n4868/over.match#oper-3.4.4 has come into play. If my analysis is correct, operator resolution of == in { return b == a; } where a: uint64_t and b: const FVInt &b resolved to inline bool operator==(uint64_t a, const FVInt &b) { return b == a; } , i.e. itself, leading to infinite recursion.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, just an artifact of C++20 and not anything slang is doing. Maybe you can just ifdef out these overloads when compiling in C++20 mode.

@@ -1,5 +1,5 @@
// RUN: circt-verilog %s -E --verify-diagnostics
// REQUIRES: slang

// expected-error @below {{could not find or open include file}}
// expected-error @below {{'unknown.sv': No such file or directory}}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW this error message comes from the system / OS, so you may find this test fails on a different OS than the one you tested on.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You've got a sharp eye, thanks!

The `OBJECT` library target file generated by `llvm_add_library()`
does not inherit `COMPILE_DEFINITIONS` from its transitive closure
in the current implementation. To avoid generating this library,
the condition `(ARG_SHARED AND ARG_STATIC) OR ARG_OBJECT` must not
be satisfied. Neither `ARG_STATIC` nor `ARG_SHARED` is set at the
moment, but `ARG_OBJECT` is satisfied due to `NEEDS_OBJECT_LIB`
being set due to `NOT ARG_SHARED AND NOT ARG_EXCLUDE_FROM_LIBMLIR
AND NOT XCODE AND NOT MSVC_IDE` being satisfied unless one of
`ARG_SHARED`, `ARG_EXCLUDE_FROM_LIBMLIR`, `XCODE` or `MSVC_IDE`
is satisfied.
Fixes operator overload resolution error on `gcc-11`.
Fixes operator overload resolution error on `gcc-11`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants