diff --git a/.github/workflows/provisioned-validation.yml b/.github/workflows/provisioned-validation.yml index 3a4dc3e..4ecf17c 100644 --- a/.github/workflows/provisioned-validation.yml +++ b/.github/workflows/provisioned-validation.yml @@ -37,13 +37,9 @@ jobs: "-DCMAKE_BUILD_TYPE=$mode" -DBUILD_TESTING=ON \ "-DCMAKE_CXX_FLAGS=-Wall -Wextra -Wpedantic -Werror" \ -DCEL_PARSER_ENABLE_PARITY=ON \ - "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" \ - -DCEL_PARSER_BUILD_MEASUREMENTS=ON + "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" cmake --build "build/provisioned-$mode" ctest --test-dir "build/provisioned-$mode" --output-on-failure - if [ "$mode" = Release ]; then - build/provisioned-Release/measurement 100000 - fi done - name: Matching instrumented source builds shell: bash @@ -55,8 +51,7 @@ jobs: -DCEL_PARSER_ENABLE_PARITY=ON \ "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" \ "-DCMAKE_CXX_FLAGS=-Wall -Wextra -Wpedantic -Werror -fsanitize=address,undefined -fno-omit-frame-pointer" \ - "-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address,undefined" \ - -DCEL_PARSER_BUILD_MEASUREMENTS=ON + "-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address,undefined" cmake --build build/provisioned-sanitized if [ "$(uname)" = Darwin ]; then export ASAN_OPTIONS=detect_leaks=0 @@ -72,8 +67,7 @@ jobs: cmake --preset clang-tidy \ "-DCMAKE_CXX_FLAGS=-Wall -Wextra -Wpedantic -Werror" \ -DCEL_PARSER_ENABLE_PARITY=ON \ - "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" \ - -DCEL_PARSER_BUILD_MEASUREMENTS=ON + "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" cmake --build --preset clang-tidy ctest --preset clang-tidy cargo fmt --manifest-path build/provisioned-Debug/parity-reference/Cargo.toml --check diff --git a/.scout/memory/index.md b/.scout/memory/index.md index 9cc7c5a..1de3f08 100644 --- a/.scout/memory/index.md +++ b/.scout/memory/index.md @@ -4,7 +4,9 @@ - [[knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md|Admit numeric values by literal form, not converted binary64 payload]] (pattern, 0.99) `parser` `literals` `rust-parity` `tuple-selectors` - [[knowledge/custom-parser-emitters-must-transfer-runtime-capture-ownership.md|Custom parser emitters must transfer runtime capture ownership]] (pattern, 0.97) `ownership` `public-contracts` `operation-emitters` +- [[knowledge/delegate-public-header-checks-and-license-installation-to-cpp-library.md|Delegate public-header checks and license installation to cpp-library]] (decision, 0.99) `cmake` `cpp-library` `testing` `licenses` - [[knowledge/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md|Initialize shared installation defaults before CPM runtime and parser targets]] (decision, 0.10) `cmake` `cpm` `dependencies` `installation` +- [[knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md|Isolate Apple numeric conversion from the caller's floating-point environment]] (decision, 0.99) `parser` `floating-point` `macos` `locale` `compatibility` - [[knowledge/keep-cel-runtime-out-of-parser-installation.md|Keep cel-runtime out of parser installation]] (decision, 0.99) `cmake` `cpm` `dependencies` `installation` - [[knowledge/keep-operator-local-storage-out-of-recursive-precedence-frames.md|Keep operator-local storage out of recursive precedence frames]] (discovery, 0.98) `parser` `recursion` `stack-usage` `MSVC` - [[knowledge/pin-cpm-dependencies-to-reviewed-commits.md|Pin CPM dependencies to reviewed commits]] (decision, 0.10) `cmake` `cpm` `dependencies` `supply-chain` `installation` diff --git a/.scout/memory/knowledge/delegate-public-header-checks-and-license-installation-to-cpp-library.md b/.scout/memory/knowledge/delegate-public-header-checks-and-license-installation-to-cpp-library.md new file mode 100644 index 0000000..4cec9fc --- /dev/null +++ b/.scout/memory/knowledge/delegate-public-header-checks-and-license-installation-to-cpp-library.md @@ -0,0 +1,23 @@ +--- +title: "Delegate public-header checks and license installation to cpp-library" +entity_type: decision +confidence: 0.99 +created: 2026-11-19T04:10:28Z +last_accessed: 2026-11-19T04:10:28Z +last_reinforced: 2026-11-19T04:10:28Z +access_count: 1 +sources: + - "CMakeLists.txt:17-31" + - "CMakeLists.txt:43-50" +relationships: + - type: relates_to + target: "Keep cel-runtime out of parser installation" +tags: ["cmake", "cpp-library", "testing", "licenses"] +tier: knowledge +--- + +# Delegate public-header checks and license installation to cpp-library + +Keep the public-header list in `cpp_library_setup(HEADERS ...)` as the source for cpp-library's automatic standalone header checks in top-level testing builds. Do not recreate per-header generated translation units or object-library targets. + +Let cpp-library install the root `LICENSE` automatically; declare the additional Unicode notice with `LICENSE_FILES licenses/Unicode-3.0.txt` rather than a separate `install(FILES ...)` block. Private `src` include directories remain necessary for white-box tests; standalone public-header checks do not replace that access. diff --git a/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md b/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md new file mode 100644 index 0000000..b146c73 --- /dev/null +++ b/.scout/memory/knowledge/isolate-apple-numeric-conversion-from-the-caller-s-floating-point-environment.md @@ -0,0 +1,22 @@ +--- +title: "Isolate Apple numeric conversion from the caller's floating-point environment" +entity_type: decision +confidence: 0.99 +created: 2026-11-19T05:47:01Z +last_accessed: 2026-11-19T05:47:01Z +last_reinforced: 2026-11-19T05:47:01Z +access_count: 1 +sources: + - "src/parser.cpp:180-194" + - "tests/tests.cpp:129-153" + - "src/lexer.hpp:21-23" + - "docs/lexical-contract.md:105-109" +tags: ["parser", "floating-point", "macos", "locale", "compatibility"] +tier: knowledge +--- + +# Isolate Apple numeric conversion from the caller's floating-point environment + +`strtod_l(..., LC_C_LOCALE)` isolates the locale but still obeys the caller's rounding mode. Preserve the lexer's round-to-nearest contract by saving the environment with `std::feholdexcept`, selecting `FE_TONEAREST`, converting, and restoring the saved environment with `std::fesetenv` before checking errors. + +Keep allocating or otherwise throwing C++ operations outside the save/restore region. Restore the caller's rounding mode and existing exception flags rather than leaking conversion state. The parser regression covers directed rounding, decimal values, radix ties, overflow, and underflow through real tokenization. diff --git a/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md b/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md index e0ab98c..8dff40b 100644 --- a/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md +++ b/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md @@ -7,8 +7,7 @@ last_accessed: 2026-11-18T06:31:07Z last_reinforced: 2026-11-18T06:31:07Z access_count: 1 sources: - - "CMakeLists.txt:22-24" - - "CMakeLists.txt:42" + - "CMakeLists.txt:17-35" - "docs/validation.md:121-130" supersedes: "[[Initialize shared installation defaults before CPM runtime and parser targets]]" tags: ["cmake", "cpm", "dependencies", "installation"] @@ -18,11 +17,11 @@ relationships: target: "Pin CPM dependencies to reviewed commits" - type: relates_to target: "Initialize shared installation defaults before CPM runtime and parser targets" -votes_up: 1 +votes_up: 2 votes_down: 0 -last_voted: 2026-11-18T06:46:33Z +last_voted: 2026-11-19T04:10:10Z --- # Keep cel-runtime out of parser installation -Set `CEL_INSTALL` before adding `cel-runtime` so both projects see the intended option. Add the runtime with its versioned commit URI and keep CPM's short-form `EXCLUDE_FROM_ALL` default; do not override it to `NO`. With `cpp-library` 6.0.2, CPM registry resolution supplies the package/version without an explicit `cpp_library_map_dependency`. The source-consumer test remains; installed-consumer testing is intentionally omitted, and the generated package check verifies component presence only. +Let `cpp_library_setup` initialize the default `CEL_INSTALL` option before adding `cel-runtime`. Add the runtime with its versioned commit URI and keep CPM's short-form `EXCLUDE_FROM_ALL` default; do not override it to `NO`. CPM registry resolution supplies the package/version without an explicit `cpp_library_map_dependency`. Package validation relies on cpp-library's generated component-presence check, without custom source-consumer or installed-consumer tests. diff --git a/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md b/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md index f6f329b..770b15f 100644 --- a/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md +++ b/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md @@ -7,9 +7,9 @@ last_accessed: 2026-11-18T06:31:11Z last_reinforced: 2026-11-18T06:31:11Z access_count: 1 sources: - - "CMakeLists.txt:6" - - "CMakeLists.txt:24" - - "docs/evidence.md:94-95" + - "CMakeLists.txt:5-6" + - "CMakeLists.txt:33-35" + - "docs/evidence.md:96-100" supersedes: "[[Pin CPM dependencies to reviewed commits]]" tags: ["cmake", "cpm", "dependencies", "supply-chain"] tier: knowledge @@ -20,11 +20,11 @@ relationships: target: "Keep cel-runtime out of parser installation" - type: relates_to target: "Initialize shared installation defaults before CPM runtime and parser targets" -votes_up: 1 +votes_up: 2 votes_down: 0 -last_voted: 2026-11-18T06:46:38Z +last_voted: 2026-11-19T04:10:12Z --- # Pin runtime source with a versioned CPM URI -Pin `cel-runtime` with a CPM URI that includes both the compatibility release (`1.1.1`) and reviewed full commit SHA `e47232f8ed6cb83bc11f4cb418a8a2249c2415cf`. Keep the release tag-to-commit relationship in `docs/evidence.md`. `cpp-library` 6.0.2 resolves the dependency from CPM's registry, so do not add a separate `cpp_library_map_dependency` for this CPM package. +Pin `cel-runtime` with a CPM URI that includes both the compatibility release (`1.1.2`) and reviewed full commit SHA `a819042cfa3fab8ede82052518f2b7f5175af5ad`. Keep the release tag-to-commit relationship in `docs/evidence.md`. `cpp-library` resolves the dependency from CPM's registry, so do not add a separate `cpp_library_map_dependency` for this CPM package. diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ccdf83..090898f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,8 +2,7 @@ cmake_minimum_required(VERSION 3.24) include(cmake/CPM.cmake) -set(CPP_LIBRARY_VERSION "" CACHE STRING "CEL parser package version override") -CPMAddPackage("gh:stlab/cpp-library@6.0.2") +CPMAddPackage("gh:stlab/cpp-library@6.1.0") include(${cpp-library_SOURCE_DIR}/cpp-library.cmake) # Enable dependency tracking before project() @@ -11,17 +10,8 @@ cpp_library_enable_dependency_tracking() # Now declare project project(parser LANGUAGES CXX) -set(CMAKE_CXX_EXTENSIONS OFF) -add_compile_options("$<$:/utf-8>") -include(GNUInstallDirs) -if(PROJECT_IS_TOP_LEVEL) - include(CTest) -endif() - -# Both cel packages share CEL_INSTALL; choose its default before adding dependencies. -option(CEL_INSTALL "Enable installation for cel libraries" ${PROJECT_IS_TOP_LEVEL}) -CPMAddPackage("gh:stlab/cel-runtime@1.1.1#e47232f8ed6cb83bc11f4cb418a8a2249c2415cf") +include(CTest) # Setup library cpp_library_setup( @@ -33,47 +23,33 @@ cpp_library_setup( TESTS tests.cpp lookup_test.cpp type_test.cpp expression_test.cpp cached_test.cpp parity_driver_test.cpp header_layers_test.cpp cursor_copy_fail.cpp lexer_copy_fail.cpp parser_copy_fail.cpp standard_library_fail.cpp converting_registration_fail.cpp converting_result_fail.cpp nontrivial_registration_fail.cpp token_interface_fail.cpp + LICENSE_FILES licenses/Unicode-3.0.txt DOCS_INPUTS README.md docs/build.md docs/get-started.md docs/libraries.md docs/language.md docs/reference.dox + DOCS_EXCLUDE_SYMBOLS cel::detail cel::detail::* cel::parser_detail cel::parser_detail::* DOCS_OPTIONS "USE_MDFILE_AS_MAINPAGE = ${CMAKE_CURRENT_SOURCE_DIR}/README.md" - "EXCLUDE_SYMBOLS = cel::detail cel::detail::* cel::parser_detail cel::parser_detail::*" - "FULL_PATH_NAMES = NO" ) + +# Initialize cpp-library's default CEL_INSTALL before the same-namespace runtime. +CPMAddPackage("gh:stlab/cel-runtime@1.1.2#a819042cfa3fab8ede82052518f2b7f5175af5ad") target_link_libraries(parser PUBLIC cel::runtime) + +# Exercise parity-driver helpers in ordinary unit tests without the driver's main(). if(TARGET parity_driver_test) target_sources(parity_driver_test PRIVATE tools/parity/driver.cpp) target_compile_definitions(parity_driver_test PRIVATE CEL_PARITY_NO_MAIN) endif() -install(FILES LICENSE licenses/Unicode-3.0.txt - DESTINATION "${CMAKE_INSTALL_DATADIR}/licenses/cel-parser") + if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING) + # Give white-box tests access to implementation headers without exporting them. foreach(test tests lookup_test type_test expression_test parity_driver_test cursor_copy_fail lexer_copy_fail) target_include_directories(${test} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") endforeach() - foreach(header parser.hpp parser/diagnostic.hpp parser/lookup.hpp parser/compiler.hpp parser/all.hpp) - string(MAKE_C_IDENTIFIER "${header}" header_id) - set(header_source "${CMAKE_CURRENT_BINARY_DIR}/header_${header_id}.cpp") - file(GENERATE OUTPUT "${header_source}" CONTENT "#include \n") - add_library(header_${header_id} OBJECT "${header_source}") - target_link_libraries(header_${header_id} PRIVATE cel::parser) - endforeach() - configure_file(tests/source_consumer.cmake.in source_consumer.cmake @ONLY) - add_test(NAME source_consumer - COMMAND "${CMAKE_COMMAND}" "-DCONFIG=$" - -P "${CMAKE_CURRENT_BINARY_DIR}/source_consumer.cmake") - set_tests_properties(source_consumer tests PROPERTIES TIMEOUT 180) -endif() -option(CEL_PARSER_BUILD_MEASUREMENTS "Build execution timing workloads" OFF) -if(CEL_PARSER_BUILD_MEASUREMENTS) - add_executable(measurement tools/measurement.cpp) - target_link_libraries(measurement PRIVATE cel::parser) - set_target_properties(measurement PROPERTIES CXX_EXTENSIONS OFF) - if(BUILD_TESTING) - add_test(NAME measurement_contracts COMMAND measurement 10) - endif() + set_tests_properties(tests PROPERTIES TIMEOUT 180) endif() +# Compare C++ and Rust results on shared fixtures; Python and Cargo are test-only. option(CEL_PARSER_ENABLE_PARITY "Require the local public Rust reference differential gate" OFF) set(CEL_PARSER_REFERENCE_SOURCE "" CACHE PATH "Local cel-rs checkout for test-only parity") if(CEL_PARSER_ENABLE_PARITY) @@ -98,7 +74,9 @@ if(CEL_PARSER_ENABLE_PARITY) add_executable(parity_driver tools/parity/driver.cpp) target_include_directories(parity_driver PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src") target_link_libraries(parity_driver PRIVATE cel::parser) - set_target_properties(parity_driver PROPERTIES CXX_EXTENSIONS OFF) + cpp_library_copy_runtime_dlls(parity_driver) + + # Run Python tooling tests as well as end-to-end C++/Rust comparisons. add_test(NAME parity_comparator COMMAND "${Python3_EXECUTABLE}" -m unittest discover -s "${CMAKE_CURRENT_SOURCE_DIR}/tools/parity" -p "test_*.py") add_test(NAME differential COMMAND "${Python3_EXECUTABLE}" @@ -107,13 +85,3 @@ if(CEL_PARSER_ENABLE_PARITY) --rust "${reference_build}/target/release/cel-parity-reference${CMAKE_EXECUTABLE_SUFFIX}") set_tests_properties(differential PROPERTIES TIMEOUT 180) endif() - -foreach(tool cached_decoded cached_test measurement parity_driver parity_driver_test) - if(TARGET ${tool}) - if(MSVC) - target_compile_options(${tool} PRIVATE /W4 /WX) - else() - target_compile_options(${tool} PRIVATE -Wall -Wextra -Wpedantic -Werror) - endif() - endif() -endforeach() diff --git a/docs/build.md b/docs/build.md index de8607f..f67d126 100644 --- a/docs/build.md +++ b/docs/build.md @@ -10,8 +10,9 @@ prefix is needed. ## Before you begin -Use CMake 3.24 or later, Ninja, Git, and a C++20 compiler with floating-point -`std::from_chars` and IEEE binary64 `double`. Do not enable fast-math. +Use CMake 3.24 or later, Ninja, Git, and a C++20 compiler with IEEE binary64 +`double`. Numeric conversion uses C-locale `strtod_l` on Apple platforms and +floating-point `std::from_chars` elsewhere. Do not enable fast-math. The first configuration downloads pinned build infrastructure and `cel-runtime`. You need Git read access to both repositories; no separate runtime checkout is required. diff --git a/docs/evidence.md b/docs/evidence.md index 9ce88ec..50f925e 100644 --- a/docs/evidence.md +++ b/docs/evidence.md @@ -12,8 +12,8 @@ pinned to the original baseline. The runtime source upstream is [stlab/cel-runtime](https://github.com/stlab/cel-runtime). The previous P4 baseline used release `v1.0.1` at revision -`a8e753b040664172fd3f526f9cf46029858ff788`. The parser pins release `v1.1.1` -at revision `e47232f8ed6cb83bc11f4cb418a8a2249c2415cf` because its +`a8e753b040664172fd3f526f9cf46029858ff788`. The parser pins release `v1.1.2` +at revision `a819042cfa3fab8ede82052518f2b7f5175af5ad` because its record-registration API uses the runtime's record adapters. The parser consumes the public target from CPM and exports the matching minimum package version; it neither copies runtime implementation nor includes private headers. Rebuild the @@ -76,11 +76,13 @@ A local `rustc` stdin probe of `str::parse::()` confirmed these outcomes: | `9007199254740993` | `9007199254740992.0` | | `1e999999999999999999999` | Positive infinity | -The C++ implementation uses `std::from_chars`; it doesn't implement decimal -floating-point conversion. Because the standard converter leaves the output -unchanged on range failure, the adapter classifies a decimal's order as positive -or nonpositive and supplies infinity or zero only after a range error. Conversion -of representable values remains the standard converter's responsibility. +The C++ implementation delegates floating-point conversion to the platform +library: C-locale `strtod_l` on Apple platforms and `std::from_chars` elsewhere. +The Apple path uses the converter's infinity, zero, and subnormal results. +Because `std::from_chars` leaves the output unchanged on range failure, its +adapter classifies a decimal's order as positive or nonpositive and supplies +infinity or zero only after a range error. Conversion of representable values +remains the library converter's responsibility. Power-of-two radix digits are regrouped exactly into hexadecimal digits before the same converter runs; no intermediate fixed-width integer narrows the value. All numeric traversal is linear and uses no locale-dependent conversion. @@ -91,10 +93,11 @@ Production code depends on the C++20 standard library, committed Unicode property data, and the `cel-runtime` package through `cel::runtime`. There is no Unicode shared-library dependency. -Build infrastructure uses `stlab/cpp-library` release `v6.0.2` at -`df18f94c816df6dc4fbab8078e6b57a7d265a2c2` under BSL-1.0. Its pinned scaffold +Build infrastructure uses `stlab/cpp-library` release `v6.1.0` at +`13ff79ac9fbbf575bbab0ab3dee0c752b4501fcc` under BSL-1.0. Its pinned scaffold provides CMake presets, doctest 2.5.3 (MIT), generated negative-compilation tests, -CTest, exports, installation, CI, and strict Doxygen configuration. +CTest, standalone public-header checks, exports, license installation, CI, +and strict Doxygen configuration. Doxygen-awesome-css 2.5.0 (MIT) supplies the documentation theme. CPM.cmake 0.43.2 is MIT-licensed. Doxygen, Ninja, Clang tools, and Python are build/generation tools, not exported package dependencies. @@ -144,5 +147,4 @@ boundaries, compound separation, producer cursor termination, and static non-clonability. The differential tooling never rewrites source or exempts C++ acceptance. Named diagnostic differences and selected callback-error normalization apply only to responses, not expressions. See -[validation](validation.md) for configuration, diagnostic rulings, -source consumers, and warmed timing boundaries. +[validation](validation.md) for configuration and diagnostic rulings. diff --git a/docs/expression-grammar.md b/docs/expression-grammar.md index 9e08092..0936a85 100644 --- a/docs/expression-grammar.md +++ b/docs/expression-grammar.md @@ -100,8 +100,6 @@ The following cases in `tests/expression_test.cpp` cover the implementation: | `recursive input` | Bounded nesting, long arithmetic/unary/cast/member/lazy/list chains | `tests/type_test.cpp` additionally verifies exact span-output prefix parsing. -The `source_consumer` test builds the public compiler and runtime APIs from a -source-tree consumer. The differential fixtures cover retained production families with identical sources. Narrower scalar/parameter availability, canonical record carriers, diff --git a/docs/p4-handoff.md b/docs/p4-handoff.md index dce6b4e..f06fd4f 100644 --- a/docs/p4-handoff.md +++ b/docs/p4-handoff.md @@ -39,7 +39,6 @@ below add comparisons without claiming exhaustive enumeration of infinite types. | Removed integers/f32/strings, bitwise/casts/helpers, wrong nominal types | Excluded with public rejection tests | Census removed rows; lexer/type/lookup/expression tests; `type-lookup-errors` | High; no invented conversions/names | | Ownership binding, resource overflow, callable exclusion/reentry | Equivalent public runtime contract paths | Runtime parity ledger and callable/composite/resource tests; typed empty Fn fixtures | High; not relabeled as differential raw-storage tests | | Installed client compatibility | Not exercised | None | Installation is outside current validation | -| Timing boundaries | Warmed Release execution | `measurement` CSV and `measurement_contracts` | Local only; not portable speed or leak claims | | Required CI inputs and fail-closed local parity | Configuration plus negative checks | `provisioned-validation.yml`, CMake parity requirements, harness tests | Local only; runner/hosting and remote execution pending | ## Corrections and remaining boundaries @@ -58,12 +57,11 @@ the parser component only; runtime discovery is expected to fail when the runtime isn't installed. The shipped runtime tests `executable_retirement_test.cpp` and `callable_test.cpp` cover these ownership regressions. -Ordinary named scalar calls allocate -owning marker/result intermediates; direct scalar dispatch measurements remain -separate. Native owning composites and dynamic invocation retain their costs. +Ordinary named scalar calls allocate owning marker/result intermediates. +Native owning composites and dynamic invocation retain their costs. -The [validation guide](validation.md) supplies reproducible commands, reference -inputs, source-consumer checks, and measurement boundaries. +The [validation guide](validation.md) supplies reproducible commands and reference +inputs. Actual GCC, MSVC, macOS LSan, remote CI, hosting, and independent reviews are not established by AppleClang/local evidence. Repeat the validation commands when changing a contract or reference revision. @@ -80,8 +78,8 @@ combined installation passed all five consumer tests in that snapshot. The Rust driver passed three tests, formatting, and all-target clippy with warnings denied. Both strict Doxygen targets passed with `WARN_AS_ERROR=YES`. -The historical snapshot used allocation instrumentation that has been removed. -The maintained measurement tool reports timing only. +The historical snapshot used allocation instrumentation and a timing executable +that are not part of the maintained build. Release uses `-O3 -DNDEBUG`, C++20, and no fast-math. One representative warmed snapshot records these separate passes; it is not a statistical benchmark: diff --git a/docs/validation.md b/docs/validation.md index 4bc5cd6..93603de 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -1,8 +1,7 @@ -# Validate retained contracts and execution costs {#parser_validation} +# Validate retained contracts {#parser_validation} -This guide serves library maintainers. It separates public cross-language -exact-source subset checks, diagnostic differences, source consumption, and -local measurements. +This guide serves library maintainers. It covers public cross-language +exact-source subset checks, diagnostic differences, and package artifact checks. The production parser needs neither Rust, Cargo, Python, nor a JSON library. ## Configure the differential gate @@ -21,8 +20,7 @@ Use an ordinary C++20 build without fast-math: ```sh cmake --preset test \ -DCEL_PARSER_ENABLE_PARITY=ON \ - -DCEL_PARSER_REFERENCE_SOURCE="$REFERENCE_SOURCE" \ - -DCEL_PARSER_BUILD_MEASUREMENTS=ON + -DCEL_PARSER_REFERENCE_SOURCE="$REFERENCE_SOURCE" cmake --build --preset test ctest --preset test ``` @@ -116,12 +114,7 @@ exceptions. No standard-function or bracket-indexing error adaptation remains. Unexpected errors still fail the driver. Exception wording is not compared between languages. -## Verify source consumption - -The `source_consumer` test adds the parser as a subproject, confirms that the -parser and runtime targets are source-built with installation disabled, then -builds and runs a client. It doesn't test package installation or downstream -package discovery. +## Package artifact checks The `cpp-library`-generated package check verifies that the parser component is present in the install tree. It doesn't validate consumer discovery or @@ -130,33 +123,6 @@ because CPM excludes the runtime from recursive installation by default. We don't maintain an installed-consumer test. Address installation failures if a client reports one. -## Measure optimized warmed execution - -Configure Release with the Rust reference checkout and -`CEL_PARSER_BUILD_MEASUREMENTS=ON`, then run: - -```sh -build/release/measurement 100000 -``` - -The CSV reports workload, iterations, total nanoseconds, and observable result -sum. Each workload has 100 warmups, then a monotonic-clock timing pass. -The tool does not replace allocation functions or count allocations. -The stack reserves 4096 bytes aligned to 64 and 256 live slots over a bool prefix. -Compilation, preparation, factory creation, and reservation occur before timing. -No timing threshold appears in unit tests. - -| Workload | Boundary | -| --- | --- | -| `prepared-scalar` | `2.0+3.0*4.0+9.0`; intrinsic arithmetic, typed double result | -| `prepared-closure-aggregate-retirement` | `(\|\|2.0+3.0*4.0+9.0)()`; owning closure invocation and result packing | -| `prepared-owning-nested-array` | `[[1.0,2.0],[3.0,4.0]]`; native nested-vector result conversion and retirement | -| `erased-owning-nested-array` | Same source; public erased owning result, no child inspection | -| `dynamic-callable` | `\|x:f64\|x*2.0+1.0`; shared callable, boxed argument 2.0, public dynamic invocation | - -Keep platform/build-specific timings in the handoff/report, not portable speed -claims. The standalone measurement client runs without analyzer exclusions. - ## Provision CI inputs explicitly The cpp-library-derived hosted jobs fetch their dependencies through CPM. @@ -164,7 +130,7 @@ Runners need Git read access to the runtime repository, including any authentication required for a private repository. The separate manual workflow requires a Rust reference source path, including `Cargo.lock`, on an already provisioned Unix self-hosted runner. -It runs Debug/Release, negative-compilation tests, parity, measurements, +It runs Debug/Release, negative-compilation tests, parity, matching sanitizer tests, lint, driver Cargo checks, and strict docs. It serializes manual dispatches without cancelling an active run and limits each job to 60 minutes. It does not provision a runner, Git credentials, or the diff --git a/src/parser.cpp b/src/parser.cpp index 700d4b4..47a1404 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -5,13 +5,20 @@ #include #include -#include #include #include #include #include #include +#if defined(__APPLE__) +#include +#include +#include +#else +#include +#endif + namespace cel::parser_detail { namespace { @@ -118,6 +125,7 @@ std::string hexadecimal(std::string_view digits, unsigned bits) { return result; } +#if !defined(__APPLE__) /// Classifies a decimal range failure as overflow or underflow without converting it. /// Preconditions: text is a valid, nonnegative, underscore-free decimal number. /// Complexity: O(text.size()) time and O(1) extra space. @@ -155,8 +163,9 @@ bool decimal_overflow(std::string_view text) noexcept { const auto negative_order = first - integer_end; return !negative && exponent > negative_order; } +#endif -/// Converts validated unsigned decimal or radix spelling with locale-independent from_chars. +/// Converts validated unsigned decimal or radix spelling independently of the caller's locale. /// Range failures produce Rust's positive infinity or zero; representable values use /// the standard converter's binary64 rounding. /// Complexity: O(spelling.size()) time and space. @@ -169,6 +178,21 @@ double convert(std::string_view spelling, unsigned base) { std::copy_if(spelling.begin(), spelling.end(), std::back_inserter(normalized), [](char ch) { return ch != '_'; }); } +#if defined(__APPLE__) + if (base != 10) normalized.insert(0, "0x"); + // Keep this save/restore region free of throwing C++ operations. + std::fenv_t environment; + if (std::feholdexcept(&environment) != 0) + throw std::runtime_error("cannot save floating-point environment"); + const auto rounding_status = std::fesetround(FE_TONEAREST); + char* end = nullptr; + const auto value = strtod_l(normalized.c_str(), &end, LC_C_LOCALE); + const auto restore_status = std::fesetenv(&environment); + if (rounding_status != 0 || restore_status != 0) + throw std::runtime_error("cannot set or restore floating-point environment"); + if (end != normalized.c_str() + normalized.size()) + throw std::logic_error("validated CEL number rejected by strtod_l"); +#else double value = 0; const auto result = std::from_chars(normalized.data(), normalized.data() + normalized.size(), value, @@ -179,6 +203,7 @@ double convert(std::string_view spelling, unsigned base) { 0.0; if (result.ec != std::errc{} || result.ptr != normalized.data() + normalized.size()) throw std::logic_error("validated CEL number rejected by from_chars"); +#endif return value; } diff --git a/tests/lookup_test.cpp b/tests/lookup_test.cpp index 1bc7ab6..4920998 100644 --- a/tests/lookup_test.cpp +++ b/tests/lookup_test.cpp @@ -433,10 +433,10 @@ TEST_CASE("record registration accepts spellable field identifiers") { const auto number = cel::value_type::leaf(); lookup.register_record("Valid", std::array{cel::record_field{"if", number}, cel::record_field{"r#true", number}, - cel::record_field{"α", number}}); + cel::record_field{"\xce\xb1", number}}); cel::parser parser(std::move(lookup)); cel::raw_stack stack; - CHECK(parser.parse_str("Valid {if: 1.0, r#true: 2.0, α: 3.0}.r#true") + CHECK(parser.parse_str("Valid {if: 1.0, r#true: 2.0, \xce\xb1: 3.0}.r#true") .execute(stack, {}) .as() == 2.0); } diff --git a/tests/source_consumer.cmake.in b/tests/source_consumer.cmake.in deleted file mode 100644 index aca367c..0000000 --- a/tests/source_consumer.cmake.in +++ /dev/null @@ -1,36 +0,0 @@ -# SPDX-License-Identifier: BSL-1.0 -# Builds a source consumer whose own tests are enabled, without dependency options. -set(consumer_source "@CMAKE_CURRENT_BINARY_DIR@/source-check/source") -set(consumer_build "@CMAKE_CURRENT_BINARY_DIR@/source-check/build") -file(REMOVE_RECURSE "${consumer_source}" "${consumer_build}") -file(MAKE_DIRECTORY "${consumer_source}") -file(WRITE "${consumer_source}/CMakeLists.txt" [=[ -cmake_minimum_required(VERSION 3.24) -project(source_consumer LANGUAGES CXX) -include(CTest) -add_subdirectory("@CMAKE_CURRENT_SOURCE_DIR@" cel-parser) -foreach(target cel::parser cel::runtime) - get_target_property(kind ${target} TYPE) - get_target_property(imported ${target} IMPORTED) - get_target_property(source ${target} SOURCE_DIR) - get_property(dependency_tests DIRECTORY "${source}" PROPERTY TESTS) - if(NOT kind STREQUAL "STATIC_LIBRARY" OR imported OR dependency_tests OR CEL_INSTALL) - message(FATAL_ERROR "Expected source-built static CEL libraries without dependency tests or installation") - endif() -endforeach() -add_executable(client "@CMAKE_CURRENT_SOURCE_DIR@/examples/cached_decoded.cpp") -target_link_libraries(client PRIVATE cel::parser) -add_test(NAME client COMMAND client) -]=]) -execute_process(COMMAND "@CMAKE_COMMAND@" - -S "${consumer_source}" -B "${consumer_build}" - -G "@CMAKE_GENERATOR@" "-DCMAKE_BUILD_TYPE=${CONFIG}" - "-DCMAKE_CXX_COMPILER=@CMAKE_CXX_COMPILER@" - "-DCMAKE_CXX_FLAGS=@CMAKE_CXX_FLAGS@" - "-DCMAKE_EXE_LINKER_FLAGS=@CMAKE_EXE_LINKER_FLAGS@" - "-DCPM_SOURCE_CACHE=@CPM_SOURCE_CACHE@" - COMMAND_ERROR_IS_FATAL ANY) -execute_process(COMMAND "@CMAKE_COMMAND@" --build "${consumer_build}" --config "${CONFIG}" - COMMAND_ERROR_IS_FATAL ANY) -execute_process(COMMAND "@CMAKE_CTEST_COMMAND@" --test-dir "${consumer_build}" - -C "${CONFIG}" --output-on-failure COMMAND_ERROR_IS_FATAL ANY) diff --git a/tests/tests.cpp b/tests/tests.cpp index c908df6..93e9c60 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -11,6 +11,13 @@ #include #include +#if defined(__APPLE__) +#include +#include +#include +#include +#endif + #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN #include @@ -118,6 +125,56 @@ TEST_CASE("binary64 boundary conversion preserves Rust infinity and zero results CHECK(std::get(extremes[1].value).value == 0); } +#if defined(__APPLE__) +TEST_CASE("numeric conversion preserves the calling thread's floating-point environment") { + std::fenv_t saved; + REQUIRE(std::feholdexcept(&saved) == 0); + std::unique_ptr restore(&saved, std::fesetenv); + + for (const auto rounding : {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO}) { + INFO(rounding); + REQUIRE(std::fesetround(rounding) == 0); + REQUIRE(std::feclearexcept(FE_ALL_EXCEPT) == 0); + REQUIRE(std::feraiseexcept(FE_DIVBYZERO) == 0); + const auto flags = std::fetestexcept(FE_ALL_EXCEPT); + + const auto tokens = + collect("1.0000000000000001 0.99999999999999999 0x20000000000001 1e9999 1e-9999"); + CHECK(std::fegetround() == rounding); + CHECK(std::fetestexcept(FE_ALL_EXCEPT) == flags); + REQUIRE(tokens.size() == 6); + CHECK(std::get(tokens[0].value).value == 1.0); + CHECK(std::get(tokens[1].value).value == 1.0); + CHECK(std::get(tokens[2].value).value == + 9007199254740992.0); + CHECK(std::isinf(std::get(tokens[3].value).value)); + CHECK(std::get(tokens[4].value).value == 0.0); + } +} + +TEST_CASE("numeric conversion ignores the calling thread's numeric locale") { + using locale_type = std::remove_pointer_t; + std::unique_ptr locale( + newlocale(LC_NUMERIC_MASK, "de_DE.UTF-8", nullptr), freelocale); + REQUIRE(locale != nullptr); + const auto previous = uselocale(locale.get()); + REQUIRE(previous != nullptr); + const auto restore = [previous](locale_t current) { + uselocale(previous); + freelocale(current); + }; + std::unique_ptr active(locale.release(), restore); + + const auto tokens = collect("1.25 1_5e-1 0o17 0x20000000000001"); + REQUIRE(tokens.size() == 5); + CHECK(std::get(tokens[0].value).value == 1.25); + CHECK(std::get(tokens[1].value).value == 1.5); + CHECK(std::get(tokens[2].value).value == 15); + CHECK(std::get(tokens[3].value).value == + 9007199254740992.0); +} +#endif + TEST_CASE("radix integers round ties without narrowing and retain exact spelling") { constexpr std::array, 10> cases{{ {"0b100000000000000000000000000000000000000000000000000001", 9007199254740992.0}, @@ -179,20 +236,23 @@ TEST_CASE("comment markers at EOF remain bounded") { } TEST_CASE("Unicode identifiers and producer whitespace retain byte boundaries") { - auto t = collect("α\u0301 \u00a0\u200e\u200f日本 \U0003d000"); + auto t = collect("\xce\xb1\xcc\x81 " + "\xc2\xa0\xe2\x80\x8e\xe2\x80\x8f\xe6\x97\xa5\xe6\x9c\xac " + "\xf0\xbd\x80\x80"); REQUIRE(t.size() == 4); - CHECK(std::get(t[0].value).spelling == "α\u0301"); + CHECK(std::get(t[0].value).spelling == "\xce\xb1\xcc\x81"); CHECK(t[0].span.begin == 0); CHECK(t[0].span.end == 4); - CHECK(std::get(t[1].value).spelling == "日本"); + CHECK(std::get(t[1].value).spelling == + "\xe6\x97\xa5\xe6\x9c\xac"); CHECK(t[1].span.begin == 13); CHECK(t[1].span.end == 19); - CHECK(std::get(t[2].value).spelling == "\U0003d000"); + CHECK(std::get(t[2].value).spelling == "\xf0\xbd\x80\x80"); } TEST_CASE("diagnostics identify unsupported versus malformed input") { - for (auto text : {"1f32", "1u8", "1.0i32", "1名字", "\"text\"", "'x'", "b\"x\"", "r#\"x\"#", - "br##\"x\"##", "c\"x\""}) { + for (auto text : {"1f32", "1u8", "1.0i32", "1\xe5\x90\x8d\xe5\xad\x97", "\"text\"", "'x'", + "b\"x\"", "r#\"x\"#", "br##\"x\"##", "c\"x\""}) { INFO(text); auto t = collect(text); REQUIRE(t.size() == 2); @@ -209,8 +269,8 @@ TEST_CASE("diagnostics identify unsupported versus malformed input") { auto const& error = std::get(incomplete[0].value); CHECK(error.category() == cel::error_category::unsupported_literal); CHECK(error.span().end == 2); - for (auto text : - {"0x", "0b2", "\"unfinished", "/*unfinished", "///bare\rCR", "\u0301", "😀", "r#self"}) { + for (auto text : {"0x", "0b2", "\"unfinished", "/*unfinished", "///bare\rCR", "\xcc\x81", + "\xf0\x9f\x98\x80", "r#self"}) { INFO(text); auto t = collect(text); REQUIRE(std::holds_alternative(t[t.size() - 2].value)); @@ -329,7 +389,7 @@ TEST_CASE("inline punctuation validates caller input and owns its bytes") { cel::parser_detail::punctuation punct(source); source.assign(3, 'x'); CHECK(punct.spelling() == "..="); - for (auto invalid : {"", "....", "abc", "α"}) { + for (auto invalid : {"", "....", "abc", "\xce\xb1"}) { CHECK_THROWS_AS(cel::parser_detail::punctuation{invalid}, std::invalid_argument); } } diff --git a/tools/measurement.cpp b/tools/measurement.cpp deleted file mode 100644 index 7a463de..0000000 --- a/tools/measurement.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include "../examples/cached_decoded.hpp" -#include -#include -#include -#include - -namespace { -/// Times a warmed workload with an observable result sink. -/// Throws if the workload's contract result changes; no timing threshold is enforced. -/// Complexity: O(iterations * workload cost). -template -void measure(std::string_view name, std::size_t iterations, double expected, F execute) { - for (int i = 0; i != 100; ++i) - if (execute() != expected) throw std::logic_error("warm result mismatch"); - double timed_sum = 0; - const auto begin = std::chrono::steady_clock::now(); - for (std::size_t i = 0; i != iterations; ++i) - timed_sum += execute(); - const auto elapsed = std::chrono::duration_cast( - std::chrono::steady_clock::now() - begin) - .count(); - if (timed_sum != expected * static_cast(iterations)) - throw std::logic_error("measured result mismatch"); - std::cout << name << ',' << iterations << ',' << elapsed << ',' << timed_sum << '\n'; -} -} // namespace - -/// Measures cached scalar, owned composite, boxed, and dynamic callable costs independently. -/// The optional argument is a positive iteration count; default is 100000. -/// Complexity: O(total compilation + iterations * workload cost). -int main(int argc, char** argv) try { - std::size_t iterations = 100000; - if (argc == 2) { - const std::string_view number(argv[1]); - const auto parsed = - std::from_chars(number.data(), number.data() + number.size(), iterations); - if (parsed.ec != std::errc{} || parsed.ptr != number.data() + number.size() || !iterations) - throw std::invalid_argument("iteration count must be a positive integer"); - } else if (argc != 1) { - throw std::invalid_argument("usage: measurement [ITERATIONS]"); - } - const auto scalars = client::compile_decoded( - std::array{"2.0+3.0*4.0+9.0", "(||2.0+3.0*4.0+9.0)()"}); - const auto composite = [] { - cel::parser compiler(cel::op_lookup{}); - return compiler.parse_str("[[1.0,2.0],[3.0,4.0]]"); - }(); - const auto typed_composite = composite.prepare>>(); - const auto factory = [] { - cel::parser compiler(cel::op_lookup{}); - return compiler.parse_str("|x:f64|x*2.0+1.0"); - }(); - cel::raw_stack stack; - stack.push(true); - stack.reserve(4096, 64); - stack.reserve_depth(256); - const auto fn = cel::callable::from_value(factory.execute(stack, {})); - const std::array arguments{cel::value::from(2.0)}; - std::cout << "workload,iterations,nanoseconds,result_sum\n"; - measure("prepared-scalar", iterations, 23, [&] { return scalars[0].call(stack); }); - measure("prepared-closure-aggregate-retirement", iterations, 23, - [&] { return scalars[1].call(stack); }); - measure("prepared-owning-nested-array", iterations, 4, - [&] { return typed_composite.call(stack)[1][1]; }); - measure("erased-owning-nested-array", iterations, 2, - [&] { return static_cast(composite.execute(stack, {}).size()); }); - measure("dynamic-callable", iterations, 5, - [&] { return fn.call(stack, arguments).as(); }); - if (stack.depth() != 1 || !stack.pop()) - throw std::logic_error("measurement lost the caller prefix"); - return 0; -} catch (const std::exception& error) { - std::cerr << error.what() << '\n'; - return 1; -}