A C++23 version of Eric Schmidt's Metamath database
verifier which can run at
compile-time using the constexpr-std-headers
branch of GCC
found here;
and referred to as C'est 2.
- Added the
constexpr
qualifier to all subroutines; - Changed all functions, to member functions (methods) of a trivial struct (called
checkmm
). Global variables (including constexpr ones) cannot be modified at compile-time; - Changed the static variable
names
withinreadtokens
to a class member ofcheckmm
. Whileconstexpr
static variables are now permitted inconstexpr
functions, they are constant, andnames
needs to be modified; constexpr
file IO is not possible, andreadtokens
now accepts a second string parameter, which is used if it isn't empty. An std::istringstream (from C'est 2) is then used to feednexttoken
, rather than an std::ifstream. P2448 from C++23 also allows non-constexpr file IO, when not on the control path taken by the constexpr evaluator;- File-includes within mm database files are not supported when processing at compile-time. An exception is thrown if this occurs;
rem 6. Headers included are from the cest library, so
#include "cest/vector.hpp"
rather than#include <vector>
etc. rem 7. Rather than replace names qualifiedstd::
withcest::
, a namespace aliasns
is used throughout; declared at global scope, and set tocest
by default. - A macro system is leveraged, where a pair of C++11-style raw string literal delimiters are placed before and after the original contents of a file. The
delimit.sh
bash script is provided to help with this. To use this approach, set the preprocessor macroMMFILEPATH
to the script's output, during compilation ofctcheckmm-std.cpp
(e.g.-DMMFILEPATH=miu.mm.raw
).
The delimit.sh
script adds R"#(
before, and )#"
after, the
contents of its input file. The output file name appends .raw
to the name of
the input. Within ctcheckmm-std.cpp
a #include
directive will bring that
(raw string) file in; as a std::string
. This happens if MMFILEPATH
is set
to a valid file path. For example, with a recent version of clang++ (e.g. Clang
18):
wget https://raw.githubusercontent.com/metamath/set.mm/develop/peano.mm
bash delimit.sh peano.mm
clang++ -std=c++23 -Winvalid-constexpr -Wl,-rpath,"$CEST2_ROOT/lib64:$LD_LIBRARY_PATH" -I $CEST2_ROOT/constexpr-std-headers/include/c++/14.0.1 -I $CEST2_ROOT/constexpr-std-headers/include/c++/14.0.1/x86_64-pc-linux-gnu -L $CEST2_ROOT/lib64 -D_GLIBCXX_CEST_CONSTEXPR=constexpr -D_GLIBCXX_CEST_VERSION=1 -fsanitize=address -fconstexpr-steps=$((2**32-1)) -DMMFILEPATH=peano.mm.raw ctcheckmm-std.cpp
With G++, a recent version is required (e.g. GCC 14), and different switches
enables a non-default constexpr
operation count limit:
wget https://raw.githubusercontent.com/metamath/set.mm/develop/peano.mm
bash delimit.sh peano.mm
g++ -std=c++23 -Winvalid-constexpr -Wl,-rpath,"$CEST2_ROOT/lib64:$LD_LIBRARY_PATH" -I $CEST2_ROOT/constexpr-std-headers/include/c++/14.0.1 -I $CEST2_ROOT/constexpr-std-headers/include/c++/14.0.1/x86_64-pc-linux-gnu -L $CEST2_ROOT/lib64 -D_GLIBCXX_CEST_CONSTEXPR=constexpr -D_GLIBCXX_CEST_VERSION=1 -fsanitize=address -static-libasan -fconstexpr-ops-limit=$((2**31-1)) -fconstexpr-loop-limit=$((2**31-1)) -DMMFILEPATH=peano.mm.raw ctcheckmm-std.cpp
Successful compilation (with either compiler) indicates that the Metamath
database was verified. The wget
commands above relate to the
repository.