lmntal / slim

slim LMNtal implementation
Other
18 stars 5 forks source link

M1 macでmodernization ブランチをビルド時,memory_resourceが無いと言われビルドに失敗する #329

Open kyawaway opened 7 months ago

kyawaway commented 7 months ago

make -j実行時,

In file included from /path/to/slim/src/element/memory_pool.cpp:39:                             
/path/to/slim/src/element/memory_pool.h:49:10: fatal error: 'memory_resource' file not found    
#include <memory_resource>                                                                                             
         ^~~~~~~~~~~~~~~~~   

kyawaway commented 7 months ago

https://forums.developer.apple.com/forums/thread/729688

kyawaway commented 7 months ago

関連:https://github.com/lmntal/slim/issues/313

QRWells commented 7 months ago

https://developer.apple.com/xcode/cpp/#c++17 によると、はC++ 17 Library FeatureとしてXCode 15が必要です。

kyawaway commented 7 months ago

XCode15を入れ,については怒られなくなりました,ありがとうございます.

しかし,が無いと言われビルドに失敗しています.

In file included from /path/to/slim/src/verifier/verifier.h:54:
/path/to/slim/src/verifier/mc_explorer.h:77:22: error: no member named 'atomic_ref' in namespace
 'std'
  auto flags2 = std::atomic_ref(s->flags2);
QRWells commented 7 months ago

cppreferenceによって、AppleClangはまだatomic_refを実装していませんので、commit 511a5fe でstd::atomic_refで引用した変数をstd::atomic<T>に変更しました。

std::atomic_refを使った理由は、Stateflagは局所的にアトミック操作がありますが、std::atomic<T>ではアトミック操作ではない部分を特別な修正が必要なので、便宜上atomic_refを使ってました。

今回すべてアトミック操作にしたから、性能への影響については調査が必要です。(あまりないはず)

kyawaway commented 7 months ago

対応ありがとうございます.

まだ数箇所怒られています.エラーログが全て見通せそうな規模になってきたので,エラーが出ている箇所を上から全て添付します.

(まだ自分では全く調べてないです,明日夜に見ます)

/path/to/slim/src/element/variant.hpp:56:33: error: invalid application of 'sizeof' to an incomp
lete type 'il::instr_arg::inst_list'
  static constexpr auto size  = sizeof(Z);
/path/to/slim/src/element/variant.hpp:57:33: error: invalid application of 'alignof' to an incom
plete type 'il::instr_arg::inst_list'
  static constexpr auto align = alignof(Z);
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/v
ector:836:62: error: arithmetic on a pointer to an incomplete type 'Instruction'
        __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
/path/to/slim/src/element/variant.hpp:56:33: error: invalid application of 'sizeof' to an incomp
lete type 'il::instr_arg::inst_list'
  static constexpr auto size  = sizeof(Z);
/path/to/slim/src/element/variant.hpp:57:33: error: invalid application of 'alignof' to an incom
plete type 'il::instr_arg::inst_list'
  static constexpr auto align = alignof(Z);
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/v
ector:549:52: error: arithmetic on a pointer to an incomplete type 'Instruction'
        {return static_cast<size_type>(__end_cap() - this->__begin_);}
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/v
ector:763:54: error: arithmetic on a pointer to an incomplete type 'const value_type' (aka 'const Instruction')
      __annotate_contiguous_container(data(), data() + capacity(),
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/v
ector:836:62: error: arithmetic on a pointer to an incomplete type 'Instruction'
        __alloc_traits::destroy(__alloc(), std::__to_address(--__soon_to_be_end));
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/_
_memory/allocator.h:131:58: error: invalid application of 'sizeof' to an incomplete type 'Instruction'
            _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
/path/to/slim/src/vm/task.cpp:53:10: fatal error: 'bits/ranges_algo.h' file not found
#include <bits/ranges_algo.h> 
/path/to/slim/src/element/variant.hpp:56:33: error: invalid application of 'sizeof' to an incomp
lete type 'il::instr_arg::inst_list'
  static constexpr auto size  = sizeof(Z);
/path/to/slim/src/element/variant.hpp:57:33: error: invalid application of 'alignof' to an incom
plete type 'il::instr_arg::inst_list'
  static constexpr auto align = alignof(Z);
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.2.sdk/usr/include/c++/v1/_
_memory/allocator.h:131:58: error: invalid application of 'sizeof' to an incomplete type 'Instruction'
            _VSTD::__libcpp_deallocate((void*)__p, __n * sizeof(_Tp), _LIBCPP_ALIGNOF(_Tp));
/path/to/slim/src/verifier/dpor_naive.cpp:41:10: fatal error: 'bits/ranges_algo.h' file not foun
d
#include <bits/ranges_algo.h> 
QRWells commented 7 months ago

12c21e6で必要ないヘッダを削除しましたが、エラーの中にincomplete typeについてはコンパイルフロントエンドの問題だと考えられます。手元のclang 16.0.6とstiltonのgcc 11.2.0ではそのエラーがありません。

kyawaway commented 6 months ago

手元のApple clang version 15.0.0 (clang-1500.1.0.2.5)gcc (Homebrew GCC 13.2.0) 13.2.0 でこのエラーが起きることを確認しています.引き続き調査します.

QRWells commented 6 months ago

原因は大体つかめました。ここで確認できるhttps://godbolt.org/z/a1dMEYPbo

clang 15.0以上はこういう「循環参照」みたいな型はincomplete typeとしてエラーとなる。 (実はill-formedであるかもしれませんからコードの修正は必要だと思います。参照:https://stackoverflow.com/questions/70357084/code-compiles-with-g-but-not-clang-if-incomplete-type-is-used-in-templated-f)

そしてgcc 13.2.0でコンパイルできないのはCMakeLists.txtのバグでもう修正しました。 buildフォルダにある内容を全部削除して、cmake -DCMAKE_C_COMPILER=/usr/bin/gcc -DCMAKE_CXX_COMPILER=/usr/bin/g++ ..gcc/g++のパスは異なるかもしれません)で試してみてください

kyawaway commented 6 months ago

とりあえず手元のgcc 13.2.0でビルドできることが確認できました,ありがとうございます!(そしてhttps://github.com/lmntal/slim/issues/281 で問題になっていたbus errorが起きていないように見える!(要調査))

kyawaway commented 6 months ago

ついでですが,デフォルトのmake install のインストール先を,/usr/local/bin/ではなく,developブランチと同様にこのプロジェクトフォルダ直下にbinディレクトリを作ってインストールするように変えていただけるとありがたいかもです.

QRWells commented 6 months ago

8bfc5abの修正でAppleClangでビルドできるかもしれません。

そして実際にインストールを行った結果、現在developブランチのmake installはデフォルトで/usr/local/bin/にインストールしているようです。

nikosai commented 5 months ago

そして実際にインストールを行った結果、現在developブランチのmake installはデフォルトで/usr/local/bin/にインストールしているようです。

たしかにそうなのですが、実際の運用上は

./configure --prefix=$(pwd)

でプロジェクトルート直下にインストール先を変えていることが多いです。 (複数のバージョンを使い分けたい場面等もあるので……) また、develop のインストール手順(1つ目)もそのようになっています。

そのため、

  1. プロジェクトルートへのインストールをデフォルトにする or
  2. インストール先の指定方法をREADMEに追記する

のいずれかの対応はお願いしたいです。