sipa
commented at 2:19 pm on October 16, 2023:
member
It seems modern compilers don’t realize that all invocations of operator""_mst can be evaluated at compile time, despite the constexpr keyword.
Since C++20, we can force them to evaluate at compile time using consteval, turning all the miniscript type constants into actual compile-time constants.
This should give a nice but not very important speedup for miniscript logic, but it’s also a way to start testing C++20 features.
DrahtBot
commented at 2:19 pm on October 16, 2023:
contributor
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
fanquake
commented at 2:46 pm on October 16, 2023:
and also Windows (see the apparent CI failure here).
For reference:
0 D:\a\bitcoin\bitcoin\src\script\miniscript.h(160,13): error C2248: 'miniscript::Type::Type': cannot access private member declared in class 'miniscript::Type'[D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]1D:\a\bitcoin\bitcoin\src\script\miniscript.h(133,5): message : see declaration of 'miniscript::Type::Type'[D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]2D:\a\bitcoin\bitcoin\src\script\miniscript.h(128,7): message : see declaration of 'miniscript::Type'[D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]3D:\a\bitcoin\bitcoin\src\script\miniscript.cpp(17,27): message : while evaluating consteval function'miniscript::operator ""_mst'[D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]4D:\a\bitcoin\bitcoin\src\script\miniscript.cpp(234,33): error C7595: 'miniscript::operator ""_mst': call to immediate function is not a constant expression [D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]5D:\a\bitcoin\bitcoin\src\script\miniscript.cpp(234,33): fatal error C1003: error count exceeds 100; stopping compilation [D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]
fanquake
commented at 2:47 pm on October 16, 2023:
Note that the failing Windows CI is also already using MSVCs C++20 mode.
0 miniscript.cpp
1D:\a\bitcoin\bitcoin\src\script\miniscript.cpp(234,33): error C7595: 'miniscript::operator ""_mst': call to immediate function is not a constant expression [D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]
2D:\a\bitcoin\bitcoin\src\script\miniscript.cpp(234,45): error C7595: 'miniscript::operator ""_mst': call to immediate function is not a constant expression [D:\a\bitcoin\bitcoin\build_msvc\libbitcoin_common\libbitcoin_common.vcxproj]
I don’t think so; MSVC is only complaining about consteval literals inside ( ? : ) ternaries. I’ve pushed another attempt to avoid it by moving the subexpressions out of the ternaries.
sipa renamed this:
miniscript: make operator_mst consteval in C++20 mode
miniscript: make operator""_mst consteval in C++20 mode
on Oct 16, 2023
fanquake added this to the milestone 27.0
on Oct 17, 2023
fanquake
commented at 1:32 pm on October 17, 2023:
member
Concept ACK. It’s annoying that we have to refactor this code just to accomodate MSVC. I agree that we should just wait until branch-off, and use conteval directly. Put this on 27.x.
DrahtBot added the label
CI failed
on Oct 22, 2023
DrahtBot removed the label
CI failed
on Oct 27, 2023
sipa force-pushed
on Dec 11, 2023
sipa
commented at 3:08 pm on December 11, 2023:
member
Rebased.
sipa renamed this:
miniscript: make operator""_mst consteval in C++20 mode
miniscript: make operator""_mst consteval
on Dec 11, 2023
fanquake requested review from darosior
on Dec 11, 2023
DrahtBot added the label
CI failed
on Dec 11, 2023
darosior
commented at 2:17 pm on December 31, 2023:
member
CI is failing with
0/usr/bin/ld: /usr/bin/ld: DWARF error: invalid or unhandled FORM value: 0x23 1libbitcoin_common.a(libbitcoin_common_a-descriptor.o): in function `(anonymous namespace)::ParseScript(unsigned int&, Span<char const>&, (anonymous namespace)::ParseScriptContext, FlatSigningProvider&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&)': 2descriptor.cpp:(.text+0x390f): undefined reference to `miniscript::operator"" _mst(char const*, unsigned int)' 3/usr/bin/ld: descriptor.cpp:(.text+0x396c): undefined reference to `miniscript::operator"" _mst(char const*, unsigned int)' 4/usr/bin/ld: descriptor.cpp:(.text+0x39ed): undefined reference to `miniscript::operator"" _mst(char const*, unsigned int)' 5/usr/bin/ld: libbitcoin_common.a(libbitcoin_common_a-descriptor.o): in function `std::shared_ptr<miniscript::Node<unsigned int>const> miniscript::internal::Parse<unsigned int, (anonymous namespace)::KeyParser>(Span<char const>, (anonymous namespace)::KeyParser const&)': 6descriptor.cpp:(.text+0x1df07): undefined reference to `miniscript::operator"" _mst(char const*, unsigned int)' 7/usr/bin/ld: libbitcoin_common.a(libbitcoin_common_a-descriptor.o): in function `(anonymous namespace)::MiniscriptDescriptor::MaxSatisfactionElems() const': 8descriptor.cpp:(.text+0x2d316): undefined reference to `miniscript::operator"" _mst(char const*, unsigned int)' 9/usr/bin/ld: libbitcoin_common.a(libbitcoin_common_a-descriptor.o):descriptor.cpp:(.text+0x2d333): more undefined references to `miniscript::operator"" _mst(char const*, unsigned int)' follow10clang: error: linker command failed with exit code 1 (use -v to see invocation)
hebasto
commented at 1:31 pm on January 1, 2024:
member
Concept ACK.
hebasto
commented at 5:19 pm on January 1, 2024:
member
Could the CI issues be due to Clang partially supporting consteval before clang-17?
maflcko
commented at 11:08 am on January 2, 2024:
member
Locally, it works, starting with clang++-15.
maflcko
commented at 1:14 pm on January 2, 2024:
member
Confirmed that this cuts a third of the runtime off of the fuzz input from #28832 (comment)
fanquake
commented at 1:16 pm on January 2, 2024:
member
Maybe we should also retry the straight constexpr -> consteval change, without having to do all the refactoring for MSVC? Microsoft might have fixed their compiler.
sipa
commented at 4:24 pm on January 2, 2024:
member
hebasto
commented at 12:55 pm on May 3, 2024:
member
ACK73619b819c37e98bd9a100bea14a3366aebfabb8.
I apologise for messing up.
The #30031, which is built on top of this PR, succeeds. It includes additional code changes in src/test/fuzz/miniscript.cpp (with some inconsistency in local variable naming).
@sipa feel free to pull changes from #30031 into this PR.
DrahtBot requested review from fanquake
on May 3, 2024
DrahtBot removed the label
CI failed
on May 3, 2024
theuni
commented at 1:54 pm on May 3, 2024:
member
utACK with or without @hebasto’s additional changes.
miniscript: make operator_mst consteval
It seems modern compilers don't realize that all invocations of operator""_mst
can be evaluated at compile time, despite the constexpr keyword.
Since C++20, we can force them to evaluate at compile time, turning all the
miniscript type constants into actual compile-time constants.
It appears that MSVC does not support consteval operator"" when used inside
certain expressions. For the few places where this happens, define a
constant outside the operator call.
Co-Authored-By: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This is a metadata mirror of the GitHub repository
bitcoin/bitcoin.
This site is not affiliated with GitHub.
Content is generated from a GitHub metadata backup.
generated: 2024-12-21 15:12 UTC
This site is hosted by @0xB10C More mirrored repositories can be found on mirror.b10c.me