diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 26719ec..d9e0a6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,5 +1,5 @@ -# Derived from cpp-library (https://github.com/stlab/cpp-library). -# CPM fetches the pinned runtime source; runners need Git read access to it. +# Auto-generated from cpp-library (https://github.com/stlab/cpp-library) +# Do not edit this file directly - it will be overwritten when templates are regenerated # Dependency versions are defined in cpp-library's cmake/cpp-library-ci.cmake # (https://github.com/stlab/cpp-library/blob/main/cmake/cpp-library-ci.cmake), not in this repo @@ -61,7 +61,7 @@ jobs: run: | cmake --preset=default cmake --build --preset=default - cmake --install build/default --prefix ${{ runner.temp }}/install + cmake --install build/default --prefix "${{ runner.temp }}/install" env: CC: ${{ matrix.cc }} CXX: ${{ matrix.cxx }} @@ -71,31 +71,12 @@ jobs: run: | cmake --preset=default cmake --build --preset=default - cmake --install build/default --prefix ${{ runner.temp }}/install + cmake --install build/default --prefix "${{ runner.temp }}/install" if: ${{ !matrix.cc }} - - name: Test find_package - shell: bash + - name: Check installed package artifacts run: | - # Create a minimal test to verify the installation works with find_package - mkdir -p ${{ runner.temp }}/test-find-package - cd ${{ runner.temp }}/test-find-package - - # Create test CMakeLists.txt - cat > CMakeLists.txt << EOF - cmake_minimum_required(VERSION 3.20) - project(test-find-package CXX) - - find_package(cel-parser REQUIRED) - - message(STATUS "Successfully found cel-parser") - EOF - - # Convert paths to forward slashes for CMake (works on all platforms) - INSTALL_PREFIX=$(echo '${{ runner.temp }}/install' | sed 's|\\|/|g') - - # Test find_package with CMAKE_PREFIX_PATH - cmake -B build -S . -DCMAKE_PREFIX_PATH="${INSTALL_PREFIX}" + cmake "-DPACKAGE_TEST_PREFIX=${{ runner.temp }}/install" -P build/default/cpp-library-test-package.cmake clang-tidy: runs-on: ubuntu-latest diff --git a/.github/workflows/provisioned-validation.yml b/.github/workflows/provisioned-validation.yml index 2e0310a..3a4dc3e 100644 --- a/.github/workflows/provisioned-validation.yml +++ b/.github/workflows/provisioned-validation.yml @@ -27,7 +27,7 @@ jobs: run: | test -f "$REFERENCE_SOURCE/cel-parser/Cargo.toml" test -f "$REFERENCE_SOURCE/Cargo.lock" - - name: Debug and Release unit, negative compilation, parity, and installed clients + - name: Debug and Release unit, negative compilation, and parity shell: bash env: REFERENCE_SOURCE: ${{ inputs.reference_source }} diff --git a/.scout/memory/index.md b/.scout/memory/index.md index a927275..9cc7c5a 100644 --- a/.scout/memory/index.md +++ b/.scout/memory/index.md @@ -4,5 +4,10 @@ - [[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/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md|Initialize shared installation defaults before CPM runtime and parser targets]] (decision, 0.99) `cmake` `cpm` `dependencies` `installation` +- [[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/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` +- [[knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md|Pin runtime source with a versioned CPM URI]] (decision, 0.99) `cmake` `cpm` `dependencies` `supply-chain` +- [[knowledge/separate-cel-constructor-names-from-runtime-record-identities.md|Separate CEL constructor names from runtime record identities]] (decision, 1.00) `records` `parser` `identifiers` `registration` +- [[knowledge/test-preset-can-inherit-cached-parity-flag.md|Test preset can inherit cached parity flag]] (discovery, 0.97) `cmake` `testing` `parity` `cache` diff --git a/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md b/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md index 7107247..fb9942f 100644 --- a/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md +++ b/.scout/memory/knowledge/admit-numeric-values-by-literal-form-not-converted-binary64-payload.md @@ -3,17 +3,24 @@ title: "Admit numeric values by literal form, not converted binary64 payload" entity_type: pattern confidence: 0.99 created: 2026-11-11T05:46:06Z -last_accessed: 2026-11-11T05:46:06Z -last_reinforced: 2026-11-11T05:46:06Z -access_count: 1 +last_accessed: 2026-11-18T06:48:35Z +last_reinforced: 2026-11-18T06:48:35Z +access_count: 2 sources: - "include/cel/parser.hpp:62-80" - "src/compiler.cpp:405-418" - "src/parser.cpp:373-429" + - "src/compiler.cpp:415-419" + - "src/parser.cpp:379-422" + - "src/lexer.hpp:15-25" + - "tests/expression_test.cpp:157-194" tags: ["parser", "literals", "rust-parity", "tuple-selectors"] tier: knowledge +votes_up: 1 +votes_down: 1 +last_voted: 2026-11-18T06:48:54Z --- # Admit numeric values by literal form, not converted binary64 payload -The text lexer converts numeric tokens to binary64 even when numeric_form is integer. That payload does not make an integer spelling an f64 language value: canonical Rust retains integer literal kinds. Reject integer forms in primary-expression compilation, while retaining integer/radix tokens and raw spelling for tuple selectors. Rejecting integers globally in the lexer would break valid selectors; converting them to f64 in primary would violate the Rust acceptance subset. Keep actual floating spellings such as 1.0, 1e0 and 1.0f64 in positive expression examples and tests. +The parser admits decimal integer-form tokens as binary64 values only when they have the `f64` suffix, such as `1f64`; bare integers and radix-prefixed forms remain unsupported as values. Keep integer/radix token spelling available to tuple selectors, and apply the value-form check in primary-expression compilation rather than globally rejecting tokens. The lexer also requires an exponent sign immediately after `e` or `E`; underscores may follow the sign, but not precede it. diff --git a/.scout/memory/knowledge/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md b/.scout/memory/knowledge/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md index dbb8c2a..259133d 100644 --- a/.scout/memory/knowledge/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md +++ b/.scout/memory/knowledge/initialize-shared-installation-defaults-before-cpm-runtime-and-parser-targets.md @@ -1,19 +1,28 @@ --- title: "Initialize shared installation defaults before CPM runtime and parser targets" entity_type: decision -confidence: 0.99 +confidence: 0.10 created: 2026-11-10T22:04:27Z -last_accessed: 2026-11-10T22:04:27Z -last_reinforced: 2026-11-10T22:04:27Z -access_count: 1 +last_accessed: 2026-11-18T05:05:33Z +last_reinforced: 2026-11-18T04:09:44Z +access_count: 4 sources: - "CMakeLists.txt:20-29" - "CMakeLists.txt:30-49" - "tests/installed_consumer.cmake.in:3-6" + - "CMakeLists.txt:22-25" + - "CMakeLists.txt:28-47" + - "tests/installed_consumer.cmake.in:3-7" + - "tests/installed_consumer.cmake.in:30-45" + - "tests/installed_consumer.cmake.in:54-78" tags: ["cmake", "cpm", "dependencies", "installation"] tier: knowledge +votes_up: 1 +votes_down: 2 +last_voted: 2026-11-18T06:46:42Z +superseded_by: "[[Keep cel-runtime out of parser installation]]" --- # Initialize shared installation defaults before CPM runtime and parser targets -cel-parser acquires cel-runtime as a pinned CPM source dependency before cpp_library_setup. Initialize CEL_INSTALL from PROJECT_IS_TOP_LEVEL before adding the dependency: both libraries use the cel namespace and therefore share cpp-library's installation option. Keep dependency acquisition before parser target setup; the runtime's directory-local docs post-build hook must not see the parser's docs target. Scope BUILD_TESTING OFF through CPM OPTIONS so runtime development targets do not collide with parser tests, without disabling the parser's own tests. The installed-consumer test installs both libraries recursively from this build tree; it must not infer an installed runtime prefix from source-target include directories. +Initialize CEL_INSTALL before acquiring cel-runtime: both libraries share this option. Acquire the runtime before setting up the parser so the runtime documentation hook does not capture the parser docs target. CPM URI shorthand excludes the dependency from the default build and recursive installation unless EXCLUDE_FROM_ALL is explicitly set to NO. Preserve that override so installed consumers receive cel-runtime. Export the minimum compatible runtime version; the installed-consumer test checks both packages resolve from the installation and rejects an older runtime. 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 new file mode 100644 index 0000000..e0ab98c --- /dev/null +++ b/.scout/memory/knowledge/keep-cel-runtime-out-of-parser-installation.md @@ -0,0 +1,28 @@ +--- +title: "Keep cel-runtime out of parser installation" +entity_type: decision +confidence: 0.99 +created: 2026-11-18T06:31:07Z +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" + - "docs/validation.md:121-130" +supersedes: "[[Initialize shared installation defaults before CPM runtime and parser targets]]" +tags: ["cmake", "cpm", "dependencies", "installation"] +tier: knowledge +relationships: + - type: relates_to + 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_down: 0 +last_voted: 2026-11-18T06:46:33Z +--- + +# 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. diff --git a/.scout/memory/knowledge/pin-cpm-dependencies-to-reviewed-commits.md b/.scout/memory/knowledge/pin-cpm-dependencies-to-reviewed-commits.md new file mode 100644 index 0000000..a320bdb --- /dev/null +++ b/.scout/memory/knowledge/pin-cpm-dependencies-to-reviewed-commits.md @@ -0,0 +1,26 @@ +--- +title: "Pin CPM dependencies to reviewed commits" +entity_type: decision +confidence: 0.10 +created: 2026-11-18T05:29:20Z +last_accessed: 2026-11-18T05:29:20Z +last_reinforced: 2026-11-18T05:29:20Z +access_count: 1 +sources: + - "CMakeLists.txt:28" + - "CMakeLists.txt:48" + - "docs/evidence.md:16-18" +tags: ["cmake", "cpm", "dependencies", "supply-chain", "installation"] +tier: knowledge +relationships: + - type: relates_to + target: "Initialize shared installation defaults before CPM runtime and parser targets" +votes_up: 0 +votes_down: 2 +last_voted: 2026-11-18T06:46:45Z +superseded_by: "[[Pin runtime source with a versioned CPM URI]]" +--- + +# Pin CPM dependencies to reviewed commits + +Select CPM source dependencies with an immutable upstream commit SHA rather than a movable release tag. Keep the public package compatibility requirement separate in `cpp_library_map_dependency`, and record the release tag-to-commit relationship in evidence documentation. Package-version validation and installed-consumer checks establish compatibility; they do not pin which source revision CPM fetches. 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 new file mode 100644 index 0000000..f6f329b --- /dev/null +++ b/.scout/memory/knowledge/pin-runtime-source-with-a-versioned-cpm-uri.md @@ -0,0 +1,30 @@ +--- +title: "Pin runtime source with a versioned CPM URI" +entity_type: decision +confidence: 0.99 +created: 2026-11-18T06:31:11Z +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" +supersedes: "[[Pin CPM dependencies to reviewed commits]]" +tags: ["cmake", "cpm", "dependencies", "supply-chain"] +tier: knowledge +relationships: + - type: relates_to + target: "Pin CPM dependencies to reviewed commits" + - type: relates_to + 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_down: 0 +last_voted: 2026-11-18T06:46:38Z +--- + +# 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. diff --git a/.scout/memory/knowledge/separate-cel-constructor-names-from-runtime-record-identities.md b/.scout/memory/knowledge/separate-cel-constructor-names-from-runtime-record-identities.md new file mode 100644 index 0000000..b416eca --- /dev/null +++ b/.scout/memory/knowledge/separate-cel-constructor-names-from-runtime-record-identities.md @@ -0,0 +1,19 @@ +--- +title: "Separate CEL constructor names from runtime record identities" +entity_type: decision +confidence: 1.00 +created: 2026-11-18T01:41:05Z +last_accessed: 2026-11-18T01:41:05Z +last_reinforced: 2026-11-18T01:41:05Z +access_count: 1 +sources: + - "include/cel/parser/lookup.hpp:233-257" + - "src/lookup.cpp:41-79" + - "src/lookup.cpp:143-153" +tags: ["records", "parser", "identifiers", "registration"] +tier: knowledge +--- + +# Separate CEL constructor names from runtime record identities + +Runtime record identities are nominal and may contain characters that CEL identifiers cannot spell, such as `sample.point`. Register an adapted record with an explicit CEL constructor alias via `register_record_type(name)`; multiple aliases can refer to the same runtime descriptor without changing dispatch identity. Registration validates the alias and every nested record field against the actual lexer before inserting the type, and constructor aliases also reject contextual keywords `if`, `else`, and `as`. Keep this validation separate from the runtime's unrestricted record identities. diff --git a/.scout/memory/knowledge/test-preset-can-inherit-cached-parity-flag.md b/.scout/memory/knowledge/test-preset-can-inherit-cached-parity-flag.md new file mode 100644 index 0000000..4e67373 --- /dev/null +++ b/.scout/memory/knowledge/test-preset-can-inherit-cached-parity-flag.md @@ -0,0 +1,21 @@ +--- +title: "Test preset can inherit cached parity flag" +entity_type: discovery +confidence: 0.97 +created: 2026-11-18T06:35:07Z +last_accessed: 2026-11-18T06:35:07Z +last_reinforced: 2026-11-18T06:35:07Z +access_count: 1 +sources: + - "CMakeLists.txt:77-85" + - "CMakePresets.json:15-28" +tags: ["cmake", "testing", "parity", "cache"] +tier: knowledge +votes_up: 1 +votes_down: 0 +last_voted: 2026-11-18T06:46:40Z +--- + +# Test preset can inherit cached parity flag + +The `test` configure preset does not set `CEL_PARSER_ENABLE_PARITY`; CMake's `option(... OFF)` only supplies the default when the cache key is absent. Reusing a `build/test` cache previously configured with parity enabled can therefore require a stale or missing `CEL_PARSER_REFERENCE_SOURCE` and fail configuration. For the ordinary local suite, pass `-DCEL_PARSER_ENABLE_PARITY=OFF` or configure a fresh build directory; enable parity only with a valid local Rust reference checkout. diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 510395a..297e047 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -240,7 +240,7 @@ "$gcc", "$msCompile" ], - "detail": "Release build for installing the library and its source dependencies Requires the CMake Tools extension (ms-vscode.cmake-tools) — without it, this task fails to start.", + "detail": "Release build for installation with CPM_USE_LOCAL_PACKAGES enabled for testing installed packages Requires the CMake Tools extension (ms-vscode.cmake-tools) — without it, this task fails to start.", "windows": { "options": { "shell": { diff --git a/CMakeLists.txt b/CMakeLists.txt index b6c7dc0..9ccdf83 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,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.1") +CPMAddPackage("gh:stlab/cpp-library@6.0.2") include(${cpp-library_SOURCE_DIR}/cpp-library.cmake) # Enable dependency tracking before project() @@ -21,18 +21,12 @@ 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}) -# Keep the dependency eligible for installation; CPM shorthand excludes it. -CPMAddPackage( - NAME cel-runtime - GITHUB_REPOSITORY stlab/cel-runtime - GIT_TAG a8e753b040664172fd3f526f9cf46029858ff788 -) +CPMAddPackage("gh:stlab/cel-runtime@1.1.1#e47232f8ed6cb83bc11f4cb418a8a2249c2415cf") # Setup library cpp_library_setup( DESCRIPTION "UTF-8 CEL expression compilation and checked library extensions" NAMESPACE cel - REQUIRES_CPP_VERSION 20 HEADERS parser.hpp parser/diagnostic.hpp parser/lookup.hpp parser/compiler.hpp parser/all.hpp SOURCES parser.cpp lookup.cpp type.cpp compiler.cpp EXAMPLES example.cpp cached_decoded.cpp @@ -44,10 +38,7 @@ cpp_library_setup( 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" - "STRIP_FROM_PATH = ${CMAKE_CURRENT_SOURCE_DIR}" - "STRIP_FROM_INC_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" ) -cpp_library_map_dependency("cel::runtime" "cel-runtime 1.0.1 CONFIG") target_link_libraries(parser PUBLIC cel::runtime) if(TARGET parity_driver_test) target_sources(parity_driver_test PRIVATE tools/parity/driver.cpp) @@ -66,15 +57,11 @@ if(PROJECT_IS_TOP_LEVEL AND BUILD_TESTING) add_library(header_${header_id} OBJECT "${header_source}") target_link_libraries(header_${header_id} PRIVATE cel::parser) endforeach() - configure_file(tests/installed_consumer.cmake.in installed_consumer.cmake @ONLY) configure_file(tests/source_consumer.cmake.in source_consumer.cmake @ONLY) - add_test(NAME installed_consumer - COMMAND "${CMAKE_COMMAND}" "-DCONFIG=$" - -P "${CMAKE_CURRENT_BINARY_DIR}/installed_consumer.cmake") add_test(NAME source_consumer COMMAND "${CMAKE_COMMAND}" "-DCONFIG=$" -P "${CMAKE_CURRENT_BINARY_DIR}/source_consumer.cmake") - set_tests_properties(installed_consumer source_consumer tests PROPERTIES TIMEOUT 180) + set_tests_properties(source_consumer tests PROPERTIES TIMEOUT 180) endif() option(CEL_PARSER_BUILD_MEASUREMENTS "Build execution timing workloads" OFF) diff --git a/CMakePresets.json b/CMakePresets.json index 588d574..99ba84a 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -77,7 +77,7 @@ { "name": "install", "displayName": "Install Configuration", - "description": "Release build for installing the library and its source dependencies", + "description": "Release build for installation with CPM_USE_LOCAL_PACKAGES enabled for testing installed packages", "binaryDir": "${sourceDir}/build/install", "generator": "Ninja", "cacheVariables": { @@ -85,7 +85,7 @@ "BUILD_TESTING": "OFF", "CMAKE_EXPORT_COMPILE_COMMANDS": "ON", "CMAKE_CXX_EXTENSIONS": "OFF", - "CPM_USE_LOCAL_PACKAGES": "OFF", + "CPM_USE_LOCAL_PACKAGES": "ON", "CPM_SOURCE_CACHE": "${sourceDir}/.cache/cpm" } } diff --git a/docs/evidence.md b/docs/evidence.md index a32c115..9ce88ec 100644 --- a/docs/evidence.md +++ b/docs/evidence.md @@ -11,16 +11,13 @@ P4 fixes malformed selector conversion spans at pinned to the original baseline. The runtime source upstream is [stlab/cel-runtime](https://github.com/stlab/cel-runtime). -CPM pins runtime release `v1.0.1` at revision -`a8e753b040664172fd3f526f9cf46029858ff788`. -This prerequisite includes shared native descriptors, cached operand origins, -result-first operation helpers, stack-independent -executable retirement and complete higher-order result ownership checks; the -earlier P4 runtime revision is insufficient. The parser consumes the public -target from a pinned CPM source dependency; it neither copies runtime -implementation nor includes private headers. -Rebuild the parser and all clients together when upgrading: runtime v1.0.1 -changes the private type-descriptor layout. +The previous P4 baseline used release `v1.0.1` at revision +`a8e753b040664172fd3f526f9cf46029858ff788`. The parser pins release `v1.1.1` +at revision `e47232f8ed6cb83bc11f4cb418a8a2249c2415cf` 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 +parser and all clients together when upgrading the runtime. The delivered Rust evidence establishes these contracts: @@ -91,11 +88,11 @@ All numeric traversal is linear and uses no locale-dependent conversion. ## Dependencies and licenses Production code depends on the C++20 standard library, committed Unicode -property data, and the installed `cel-runtime` package through `cel::runtime`. +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.1` at -`13be83b3d92aeb1969fb6f8d13e81b372bb57d43` under BSL-1.0. Its pinned scaffold +Build infrastructure uses `stlab/cpp-library` release `v6.0.2` at +`df18f94c816df6dc4fbab8078e6b57a7d265a2c2` 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. Doxygen-awesome-css 2.5.0 (MIT) supplies the documentation theme. CPM.cmake @@ -148,4 +145,4 @@ 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, -installed clients, and warmed timing boundaries. +source consumers, and warmed timing boundaries. diff --git a/docs/expression-grammar.md b/docs/expression-grammar.md index bed57fb..9e08092 100644 --- a/docs/expression-grammar.md +++ b/docs/expression-grammar.md @@ -99,9 +99,9 @@ The following cases in `tests/expression_test.cpp` cover the implementation: | `text and token methods` | Both full methods, inline host preservation, producer diagnostics, visible/invisible malformed groups, exact spans | | `recursive input` | Bounded nesting, long arithmetic/unary/cast/member/lazy/list chains | -`tests/type_test.cpp` additionally verifies exact span-output prefix parsing, -and `tests/installed_consumer/compiler.cpp` exercises the public installed -compiler and runtime together. +`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/language.md b/docs/language.md index 0449870..4c03f80 100644 --- a/docs/language.md +++ b/docs/language.md @@ -8,7 +8,8 @@ UTF-8 expression with `cel::parser::parse_str`; trailing input is an error. The built-in scalar types are `bool` and IEEE binary64 `f64`, represented by C++ `bool` and `double`. Numeric values require floating syntax such as `1.0`, -`1e0`, or `1.0f64`. Integer literals are not converted to f64. +`1e0`, `1.0f64`, or `1f64`. Bare integers and radix integers are not converted +to `f64`. The core provides these exact operations: diff --git a/docs/lexical-contract.md b/docs/lexical-contract.md index 0420d97..3a13796 100644 --- a/docs/lexical-contract.md +++ b/docs/lexical-contract.md @@ -89,17 +89,18 @@ Rust LexLexer attribute handler. ## Numbers and punctuation Only bool and binary64 are built-in value types. The expression parser accepts -floating forms such as `1.0`, `1e0`, and `1.0f64`, and rejects integer value -forms, including `1`, radix integers, and `1f64`. Integer tokens remain available -to lexical consumers and tuple selectors; their converted binary64 payload -does not change their syntax classification. +floating forms such as `1.0`, `1e0`, `1.0f64`, and the decimal integer-form +`1f64`. It rejects bare integers and radix integers as values. Integer-form +tokens remain available to lexical consumers and tuple selectors; neither their +converted binary64 payload nor an `f64` suffix changes their syntax classification. The text lexer retains integer and decimal tokens. Its only accepted suffix is `f64`; `f32`, integer suffixes, and arbitrary identifier suffixes are unsupported literals. Decimal, binary `0b`, octal `0o`, and hexadecimal `0x` spellings retain their -source spelling and underscores. Radix prefixes are lowercase. The producer's -permissive underscore placements remain accepted, including `0o_17`, `1_`, -and `1_e_+_2`. +source spelling and underscores. Radix prefixes are lowercase. Underscores are +accepted in forms such as `0o_17`, `1_`, and `1_e+_2`. An exponent's optional +sign must immediately follow `e` or `E`, before any underscores; `1e_+2` is +malformed. Conversion rounds to nearest binary64. Overflow yields positive infinity; underflow rounds to a subnormal or zero. Signs are separate punctuation. diff --git a/docs/libraries.md b/docs/libraries.md index eb7f1c3..6d72a92 100644 --- a/docs/libraries.md +++ b/docs/libraries.md @@ -76,8 +76,51 @@ produce and consume it separately. Use `register_record` with named `cel::record_field` descriptors for a nominal schema. `Name{field: expression}` then constructs that schema, and `.field` -selects a field. Names and complete descriptors are retained; equal layouts or -display names do not make separately identified types compatible. +selects a field. Record source names must name a CEL constructor, and field +names throughout the schema must be CEL identifiers. Registration rejects +names that expressions cannot spell. + +Use `register_record_type("Name")` when `cel::record_adapter` already +declares the nominal schema. The CEL source name is independent of the +adapter's nominal identity: + +```cpp +struct point { + double x; + double y; +}; + +template <> +struct cel::record_adapter { + static cel::value_type type() { + static const auto descriptor = cel::value_type::record( + "sample.point", + std::array{cel::record_field{"x", cel::value_type::leaf()}, + cel::record_field{"y", cel::value_type::leaf()}}); + return descriptor; + } + static cel::value to_value(const point& source) { + return cel::value::record( + type(), + std::array{cel::value::from(source.x), cel::value::from(source.y)}); + } + static point from_value(const cel::value& source); +}; + +cel::op_lookup lookup; +lookup.register_record_type("Point"); +lookup.register_op("length_squared", + [](point p) { return p.x * p.x + p.y * p.y; }); +``` + +Record literals evaluate field expressions in source order, then map those +values to the adapter schema by field name. Operation resolution still compares +complete nominal descriptors, so same-layout records with different identities +do not share overloads. + +The compiled program retains callback captures independently of `op_lookup`. +Store owned state by value, and keep captured references alive for every +execution that uses them. ## Choose a lower-level extension only when needed diff --git a/docs/p4-handoff.md b/docs/p4-handoff.md index ccf0e0c..dce6b4e 100644 --- a/docs/p4-handoff.md +++ b/docs/p4-handoff.md @@ -6,10 +6,11 @@ fixture exemptions are superseded by the [core census](builtin-census.md), [expression grammar](expression-grammar.md), and [exact-source validation](validation.md). -P4 adds public differential tooling, a cached decoded-expression client, -installed clients, separate execution measurements, and explicit provisioned -CI inputs. It does not publish packages or establish overall port completion. -Automated validation does not replace independent code review. +P4 added public differential tooling, a cached decoded-expression client, +separate execution measurements, and explicit provisioned CI inputs. Its +installed-consumer test has since been removed; current validation does not +exercise package installation. P4 did not publish packages or establish overall +port completion. Automated validation does not replace independent code review. ## Feature closure @@ -37,7 +38,7 @@ below add comparisons without claiming exhaustive enumeration of infinite types. | Bracket indexing and finite integral bounds | Explicit C++ adaptation | `cpp-adaptations`; `explicit C++ array indexing validates before structural access`; runtime index/prefix cases | High; Rust has no bracket-postfix syntax | | 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 headers/artifacts and decoded cache/composites/callables | Package-only clients | `installed_consumer` and its five nested clients | High locally; no remote package publication | +| 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 | @@ -50,9 +51,11 @@ away. See [validation](validation.md) for exact adapters and driver contracts. The final integrated wave corrects executable retirement and higher-order result ownership. Use the corrected runtime revision in [source evidence](evidence.md) -and the build/install commands in the [README](../README.md). Validation must -consume normal and instrumented installations of that same runtime revision; -see [validation](validation.md) for the matching sanitizer configuration. +and the build and test commands in the [README](../README.md). Current +validation uses source-built parser and runtime targets; it does not verify +installed parser clients. The generated `cpp-library` package check verifies +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 @@ -60,21 +63,22 @@ owning marker/result intermediates; direct scalar dispatch measurements remain separate. Native owning composites and dynamic invocation retain their costs. The [validation guide](validation.md) supplies reproducible commands, reference -inputs, installed-prefix checks, and measurement boundaries. +inputs, source-consumer checks, and measurement boundaries. 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. ## Local P4 evidence -AppleClang 21 on arm64 macOS passes all 18 parser CTests in Debug, Release, -matching ASan+UBSan, and clang-tidy configurations. Each run includes six -negative-compilation gates, actual differential execution, and installed -consumption. The differential run passes 275 shared fixtures and 14 explicit -C++ adaptations across 19 fixture families. A separate real combined -installation passes all five consumer tests. The Rust driver passes three -tests, formatting, and all-target clippy with warnings denied. Both strict -Doxygen targets pass with `WARN_AS_ERROR=YES`. +AppleClang 21 on arm64 macOS passed all 18 parser CTests in Debug, Release, +matching ASan+UBSan, and clang-tidy configurations at the time of this +historical snapshot. Those runs included six negative-compilation gates, +actual differential execution, and installed-consumer tests, which are no +longer part of current validation. The differential run passed 275 shared +fixtures and 14 explicit C++ adaptations across 19 fixture families. A separate +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. diff --git a/docs/validation.md b/docs/validation.md index 1434a8c..4bc5cd6 100644 --- a/docs/validation.md +++ b/docs/validation.md @@ -1,8 +1,8 @@ # Validate retained contracts and execution costs {#parser_validation} This guide serves library maintainers. It separates public cross-language -exact-source subset checks, diagnostic differences, installed consumption, -and local measurements. +exact-source subset checks, diagnostic differences, source consumption, and +local measurements. The production parser needs neither Rust, Cargo, Python, nor a JSON library. ## Configure the differential gate @@ -12,7 +12,10 @@ Configure Git with read access to its repository; no runtime installation is required. Set `REFERENCE_SOURCE` to your local `cel-rs` checkout. The accepted reference starts at `03d658f8b12acabe1d6a2503281e7c86cf00b6a3`; the P4 selector diagnostic -correction is `1516e45f0799927043352ffeeb2b13d58ac66526`. +correction is `1516e45f0799927043352ffeeb2b13d58ac66526`. It must also contain +the integer-form float fix `c9a45c479a70ef31c9b7b2d86b9f407d46074370` and the +exponent-sign fix `e1ea1d3083fe97fd26b49352e62c88c24ffa7913` in its `HEAD` +history. `prepare_reference.py` verifies both commits before invoking Cargo. Use an ordinary C++20 build without fast-math: ```sh @@ -113,45 +116,19 @@ exceptions. No standard-function or bracket-indexing error adaptation remains. Unexpected errors still fail the driver. Exception wording is not compared between languages. -## Verify installed consumption +## Verify source consumption -`installed_consumer` installs parser and runtime output from the same build tree -into an isolated prefix. It rejects leaked checkout/sibling paths -and verifies both imported libraries and headers resolve to that prefix. -Five package-only clients cover tokens, lookup, compiled composites/callables, -the decoded scalar cache, and execution measurements. They link only -`cel::parser`; `find_dependency` finds the runtime transitively. -The runtime shares the parser's compiler and instrumentation flags. -To check both libraries and installed clients under ASan+UBSan: +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. -```sh -cmake -S . -B build/parser-sanitized -G Ninja \ - -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTING=ON \ - "-DCMAKE_CXX_FLAGS=-fsanitize=address,undefined -fno-omit-frame-pointer" \ - "-DCMAKE_EXE_LINKER_FLAGS=-fsanitize=address,undefined" \ - -DCEL_PARSER_ENABLE_PARITY=ON \ - "-DCEL_PARSER_REFERENCE_SOURCE=$REFERENCE_SOURCE" \ - -DCEL_PARSER_BUILD_MEASUREMENTS=ON -cmake --build build/parser-sanitized -ASAN_OPTIONS=detect_leaks=0 UBSAN_OPTIONS=halt_on_error=1 \ - ctest --test-dir build/parser-sanitized --output-on-failure -``` - -`detect_leaks=0` is required on macOS, which does not support LeakSanitizer. -On a platform with supported LeakSanitizer, omit that override to retain leak -detection. Confirm that parser tests and installed clients pass. - -Set `COMBINED_PREFIX` to the absolute installation prefix containing both -libraries. To repeat with packages you installed yourself: - -```sh -cmake -S tests/installed_consumer -B build/package-client -G Ninja \ - -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH="$COMBINED_PREFIX" -cmake --build build/package-client -ctest --test-dir build/package-client --output-on-failure -``` - -No checkout include directory or explicit runtime target is required. +The `cpp-library`-generated package check verifies that the parser component +is present in the install tree. It doesn't validate consumer discovery or +runtime availability; `find_dependency(cel-runtime)` is expected to fail +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 @@ -178,8 +155,7 @@ No timing threshold appears in unit tests. | `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. Both standalone and installed measurement clients run without analyzer -exclusions. +claims. The standalone measurement client runs without analyzer exclusions. ## Provision CI inputs explicitly @@ -188,8 +164,8 @@ 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, installed clients, parity, -measurements, matching sanitizer tests, lint, driver Cargo checks, and strict docs. +It runs Debug/Release, negative-compilation tests, parity, measurements, +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 Rust checkout, or claim Windows coverage. diff --git a/include/cel/parser/compiler.hpp b/include/cel/parser/compiler.hpp index 8f0b5f2..51c7f00 100644 --- a/include/cel/parser/compiler.hpp +++ b/include/cel/parser/compiler.hpp @@ -50,7 +50,8 @@ class parser { /// Compiles one complete decoded UTF-8 CEL source through an owned source copy. /// Selects grammar alternatives from the current token alone. Consuming a comma requires /// another item except for a required singleton-tuple comma; optional trailing commas fail. - /// Numeric values require floating forms such as 1.0 or 1e0; integer forms are unsupported. + /// Numeric values require floating forms such as 1.0 or 1e0; decimal integer-form floats + /// require an `f64` suffix such as 1f64. Bare and radix-prefixed integers are unsupported. /// Postfix array indexing is not part of the core grammar. /// Returns an owned program under this class's ownership and failure contracts. /// Throws source-located parse_error for malformed_input, unsupported_literal, type_error, diff --git a/include/cel/parser/lookup.hpp b/include/cel/parser/lookup.hpp index 61e3251..3eb21b5 100644 --- a/include/cel/parser/lookup.hpp +++ b/include/cel/parser/lookup.hpp @@ -147,6 +147,12 @@ class op_lookup { /// Inserts an owned leaf or record name; duplicate/reserved names are rejected. /// Complexity: O(name bytes), expected map insertion plus metadata release on failure. void insert_type(std::string_view name, value_type type); + /// Inserts a nominal record under a CEL source name after validating its fields. + /// Throws invalid_argument for an unspellable source name or field name. + /// Complexity: expected O(V + E + S + name bytes) time and O(V + E + L) auxiliary + /// space, where V and E are visited descriptor references and edges, S is field-name + /// bytes, and L is the longest field or source name. + void insert_record_type(std::string_view name, value_type type); /// Keeps the first function emitter while admitting new marker types for that same name. /// Throws invalid_argument if a marker identity already names a distinct function. /// Failure leaves existing bindings and marker reservations unchanged. @@ -235,9 +241,27 @@ class op_lookup { insert_type(name, std::move(type)); } } + /// Registers the adapter's nominal schema under a CEL source name. + /// The source name is independent of the adapter's nominal identity. + /// Throws std::invalid_argument for a non-record descriptor, a duplicate, reserved, + /// or unspellable source name, or a field name that is not a CEL identifier. + /// Complexity: expected O(V + E + S + name bytes) time and O(V + E + L) auxiliary + /// space, where V and E are visited descriptor references and edges, S is field-name + /// bytes, and L is the longest field or source name. + /// Example: lookup.register_record_type("Record"). + template + void register_record_type(std::string_view name) { + auto descriptor = record_adapter::type(); + if (descriptor.kind() != type_kind::record || descriptor.record_identity().empty()) + throw std::invalid_argument("record adapter type must be a nominal record"); + insert_record_type(name, std::move(descriptor)); + } /// Registers an owned complete nominal record schema, never a guessed native layout. - /// Throws invalid_argument for empty/duplicate/reserved names or invalid field names. - /// Complexity: O(fields + field-name bytes + name bytes), expected map insertion. + /// Throws invalid_argument for duplicate, reserved, or unspellable source names, + /// duplicate field names, or field names that cannot be written as CEL identifiers. + /// Complexity: expected O(V + E + S + name bytes) time and O(V + E + L) auxiliary + /// space, where V and E are visited descriptor references and edges, S is field-name + /// bytes, and L is the longest field or source name. /// Example: lookup.register_record("Flag", std::array{record_field{"on", /// value_type::leaf()}}). void register_record(std::string_view name, std::span fields); diff --git a/src/compiler.cpp b/src/compiler.cpp index 9664f71..65976c9 100644 --- a/src/compiler.cpp +++ b/src/compiler.cpp @@ -412,7 +412,9 @@ class expression_compiler { builder.just(value::from(*boolean)); advance(); } else if (const auto* number = std::get_if(¤t().value)) { - if (number->form == numeric_form::integer) + if (number->form == numeric_form::integer && + (number->suffix != "f64" || number->spelling.starts_with("0b") || + number->spelling.starts_with("0o") || number->spelling.starts_with("0x"))) throw parse_error(error_category::unsupported_literal, start, "integer value literals are outside the bool/f64 core"); if (!number->suffix.empty() && number->suffix != "f64") diff --git a/src/lexer.hpp b/src/lexer.hpp index 291b3b8..17a6e05 100644 --- a/src/lexer.hpp +++ b/src/lexer.hpp @@ -13,7 +13,7 @@ namespace cel::parser_detail { /// Retains the numeric syntax independently of its converted binary64 value. /// Example: numeric_form::decimal describes the coalesced selector token "0.1". enum class numeric_form { - integer, ///< Unsuffixed or suffixed integer spelling, including radix prefixes. + integer, ///< Decimal without a dot or exponent, or a radix-prefixed spelling. decimal, ///< Decimal spelling with a dot and without an exponent. exponent ///< Decimal spelling with an exponent, with or without a dot. }; @@ -22,7 +22,7 @@ enum class numeric_form { /// The text lexer uses round-to-nearest binary64 conversion. /// Overflow yields positive infinity and underflow rounds to a subnormal or zero. /// Copying takes O(spelling.size() + suffix.size()) time and space. -/// Integer tokens support lexical consumers and tuple selectors, not core numeric values. +/// Decimal integer-form tokens with the f64 suffix are core numeric values. /// Example: numeric_literal{1.0, "1.0f64", "f64", numeric_form::decimal}. struct numeric_literal { double value; ///< Converted scalar; the text lexer emits signs as punctuation. diff --git a/src/lookup.cpp b/src/lookup.cpp index 35d2fe8..ad2f46d 100644 --- a/src/lookup.cpp +++ b/src/lookup.cpp @@ -1,8 +1,10 @@ // SPDX-License-Identifier: BSL-1.0 +#include "lexer.hpp" #include "lookup_access.hpp" #include #include #include +#include namespace cel { using parser_detail::lookup_selector; @@ -36,6 +38,51 @@ bool reserved_type(std::string_view name) { "RangeFull"}; return std::ranges::find(names, name) != names.end(); } + +/// Checks whether the complete spelling is a CEL identifier. +/// Complexity: O(name bytes) time and auxiliary space. +bool source_identifier(std::string_view name) { + parser_detail::lex_lexer lexer(name); + const auto* identifier = std::get_if(&lexer.current().value); + return identifier && identifier->spelling == name; +} + +/// Rejects field names that cannot be written in CEL throughout a descriptor. +/// Complexity: expected O(V + E + S) time and O(V + E + L) auxiliary space, where V +/// and E are visited descriptor references and edges, S is field-name bytes, and L +/// is the longest field name. +void validate_record_fields(const value_type& type) { + std::vector pending{&type}; + std::unordered_set visited; + while (!pending.empty()) { + const auto* current = pending.back(); + pending.pop_back(); + if (!visited.insert(current).second) continue; + switch (current->kind()) { + case type_kind::leaf: + break; + case type_kind::array: + case type_kind::range: + pending.push_back(¤t->element()); + break; + case type_kind::record: + for (const auto& name : current->field_names()) + if (!source_identifier(name)) + throw std::invalid_argument("record field is not a CEL identifier: " + + name); + [[fallthrough]]; + case type_kind::tuple: + for (const auto& field : current->fields()) + pending.push_back(&field); + break; + case type_kind::callable: + for (const auto& parameter : current->parameters()) + pending.push_back(¶meter); + pending.push_back(¤t->result()); + break; + } + } +} } // namespace void op_lookup::insert(names>& destination, @@ -98,6 +145,14 @@ void op_lookup::insert_type(std::string_view name, value_type type) { types_.emplace(std::string(name), std::move(type)); } +void op_lookup::insert_record_type(std::string_view name, value_type type) { + if (!source_identifier(name) || name == "if" || name == "else" || name == "as") + throw std::invalid_argument("record source name is not a CEL constructor identifier: " + + std::string(name)); + validate_record_fields(type); + insert_type(name, std::move(type)); +} + op_lookup::op_lookup() { types_.emplace("bool", value_type::leaf()); types_.emplace("f64", value_type::leaf()); @@ -111,7 +166,7 @@ op_lookup::op_lookup() { } void op_lookup::register_record(std::string_view name, std::span fields) { - insert_type(name, value_type::record(name, fields)); + insert_record_type(name, value_type::record(name, fields)); } std::optional op_lookup::find_type(std::string_view name) const { diff --git a/src/parser.cpp b/src/parser.cpp index 0c099ac..700d4b4 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -376,6 +376,7 @@ void lex_lexer::number() { ++position_; } } + bool misplaced_exponent_sign = false; if (base == 10 && position_ < text.size() && (text[position_] == 'e' || text[position_] == 'E')) { auto end = position_ + 1; @@ -389,6 +390,7 @@ void lex_lexer::number() { exponent_digit = true; ++end; } else if ((ch == '+' || ch == '-') && !sign && !exponent_digit) { + misplaced_exponent_sign = end != position_ + 1; sign = true; ++end; } else @@ -412,6 +414,11 @@ void lex_lexer::number() { "invalid number boundary"); return; } + if (form == numeric_form::exponent && misplaced_exponent_sign) { + fail(error_category::malformed_input, {start, position_}, + "an exponent sign must immediately follow e or E"); + return; + } const auto suffix = text.substr(suffix_start, position_ - suffix_start); if (!suffix.empty() && suffix != "f64") { fail(error_category::unsupported_literal, {start, position_}, "unsupported numeric suffix"); diff --git a/tests/expression_test.cpp b/tests/expression_test.cpp index ae150d7..f9af35b 100644 --- a/tests/expression_test.cpp +++ b/tests/expression_test.cpp @@ -49,8 +49,62 @@ struct marker {}; struct client { double number; }; +/// Provides one adapter-backed record for parser failure tests. +struct adapted_expr_point { + double x; + double y; +}; +/// Provides a same-layout second nominal record. +struct adapted_expr_point_alias { + double x; + double y; +}; } // namespace +namespace cel { +template <> +struct record_adapter<::adapted_expr_point> { + /// Returns the complete descriptor for adapted_expr_point. + static value_type type() { + static const auto descriptor = value_type::record( + "ExprPoint", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one point value in canonical field order. + static value to_value(const ::adapted_expr_point& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one point value after descriptor validation. + static ::adapted_expr_point from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong expression point type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +template <> +struct record_adapter<::adapted_expr_point_alias> { + /// Returns the complete descriptor for adapted_expr_point_alias. + static value_type type() { + static const auto descriptor = value_type::record( + "ExprPointAlias", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one alias value in canonical field order. + static value to_value(const ::adapted_expr_point_alias& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one alias value after descriptor validation. + static ::adapted_expr_point_alias from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong expression point alias type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; +} // namespace cel + TEST_CASE("retained precedence associativity casts and IEEE numeric spellings") { cel::parser parser{cel::op_lookup{}}; for (const auto& [text, expected] : @@ -83,11 +137,13 @@ TEST_CASE("retained precedence associativity casts and IEEE numeric spellings") TEST_CASE("numeric values require floating literal forms without integer coercion") { cel::parser parser{cel::op_lookup{}}; for (const auto& [text, span] : std::array{ - std::pair{"1", cel::source_span{0, 1}}, std::pair{"1f64", cel::source_span{0, 4}}, + std::pair{"1", cel::source_span{0, 1}}, std::pair{"1 as f64", cel::source_span{0, 1}}, std::pair{"1+2.0", cel::source_span{0, 1}}, std::pair{"1.0+1", cel::source_span{4, 5}}, std::pair{"(|x:f64|x)(1)", cel::source_span{11, 12}}, std::pair{"0x10", cel::source_span{0, 4}}, std::pair{"0b10", cel::source_span{0, 4}}, - std::pair{"0o10", cel::source_span{0, 4}}}) { + std::pair{"0o10", cel::source_span{0, 4}}, std::pair{"0b1f64", cel::source_span{0, 6}}, + std::pair{"0o7_f64", cel::source_span{0, 7}}, + std::pair{"0x1f64", cel::source_span{0, 6}}}) { CAPTURE(text); error_at(parser, text, cel::error_category::unsupported_literal, span); CHECK_THROWS_AS(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)), @@ -98,6 +154,42 @@ TEST_CASE("numeric values require floating literal forms without integer coercio CHECK(evaluate(parser, "(1.0,2.0).0x1").as() == 2.0); } +TEST_CASE("decimal integer-form f64 literals produce floating values") { + cel::parser parser{cel::op_lookup{}}; + for (const auto& [text, expected] : std::array{ + std::pair{"1f64", 1.0}, std::pair{"0f64", 0.0}, std::pair{"1_f64", 1.0}, + std::pair{"1__f64", 1.0}, std::pair{"1_000f64", 1000.0}, + std::pair{"9007199254740993f64", 9007199254740992.0}, std::pair{"1e2f64", 100.0}, + std::pair{"1f64 + 2.0", 3.0}, std::pair{"-1f64", -1.0}, std::pair{"1f64 as f64", 1.0}, + std::pair{"(|x:f64|x)(1f64)", 1.0}}) { + CAPTURE(std::string_view(text)); + CHECK(evaluate(parser, text).as() == expected); + cel::raw_stack stack; + CHECK(cel::parser_detail::parser_access::parse_tokens(parser, tokens(text)) + .execute(stack, {}) + .as() == expected); + } + CHECK(std::signbit(evaluate(parser, "-0f64").as())); + for (auto text : {"1f64x", "1f64_", "1f640", "1f32", "1.0f64x", "(1.0,2.0).1f64"}) { + CAPTURE(text); + CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); + } +} + +TEST_CASE("float exponent signs cannot follow underscores") { + cel::parser parser{cel::op_lookup{}}; + for (const auto& [text, expected] : + std::array{std::pair{"1e+_2f64", 100.0}, std::pair{"1e__2f64", 100.0}, + std::pair{"1e-__2f64", 0.01}, std::pair{"1.0E+__2f64", 100.0}}) { + CAPTURE(std::string_view(text)); + CHECK(evaluate(parser, text).as() == expected); + } + for (auto text : {"1e_+2f64", "1e__-2f64", "1e_+_2f64", "1.0e_+2f64", "1E__+2f64", "1_e_+_2"}) { + CAPTURE(std::string_view(text)); + CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); + } +} + TEST_CASE("postfix brackets remain host input and are not core array indexing") { cel::parser parser{cel::op_lookup{}}; const auto input = tokens("[1.0][0.0]"); @@ -275,6 +367,27 @@ TEST_CASE("registered names member selectors record permutation and source evalu } } +TEST_CASE("record adapter registration enforces exact nominal fields and overload identity") { + std::size_t calls = 0; + cel::op_lookup lookup; + lookup.register_record_type("ExprPoint"); + lookup.register_record_type("ExprPointAlias"); + lookup.register_op("area", [&calls](adapted_expr_point input) { + ++calls; + return input.x * input.y; + }); + cel::parser parser(std::move(lookup)); + CHECK(evaluate(parser, "ExprPoint { y: 4.0, x: 3.0 }.area()").as() == 12.0); + CHECK(calls == 1); + for (auto text : {"ExprPoint{x:3.0}", "ExprPoint{z:3.0,y:4.0}", "ExprPoint{x:true,y:4.0}"}) { + CAPTURE(text); + CHECK_THROWS_AS(parser.parse_str(text), cel::parse_error); + } + const auto before = calls; + CHECK_THROWS_AS(parser.parse_str("ExprPointAlias { y: 4.0, x: 3.0 }.area()"), cel::parse_error); + CHECK(calls == before); +} + TEST_CASE( "closures admit complete arguments client results higher order and empty callable composites") { cel::op_lookup lookup; diff --git a/tests/installed_consumer.cmake.in b/tests/installed_consumer.cmake.in deleted file mode 100644 index e48163a..0000000 --- a/tests/installed_consumer.cmake.in +++ /dev/null @@ -1,79 +0,0 @@ -# SPDX-License-Identifier: BSL-1.0 -# Installs and validates a standalone consumer without source include directories. -set(prefix "@CMAKE_CURRENT_BINARY_DIR@/installed-check/prefix") -set(consumer_build "@CMAKE_CURRENT_BINARY_DIR@/installed-check/consumer") -file(REMOVE_RECURSE "${prefix}" "${consumer_build}") -execute_process(COMMAND "@CMAKE_COMMAND@" --install "@CMAKE_CURRENT_BINARY_DIR@" - --config "${CONFIG}" --prefix "${prefix}" COMMAND_ERROR_IS_FATAL ANY) -foreach(notice LICENSE Unicode-3.0.txt) - if(NOT EXISTS "${prefix}/@CMAKE_INSTALL_DATADIR@/licenses/cel-parser/${notice}") - message(FATAL_ERROR "Installed package omits license notice ${notice}") - endif() -endforeach() -file(GLOB_RECURSE package_configs "${prefix}/*.cmake") -get_filename_component(repository_parent "@CMAKE_CURRENT_SOURCE_DIR@" DIRECTORY) -foreach(config_file IN LISTS package_configs) - file(READ "${config_file}" contents) - foreach(source_path "${repository_parent}" "@CMAKE_CURRENT_SOURCE_DIR@" - "@CEL_PARSER_REFERENCE_SOURCE@") - if(NOT source_path STREQUAL "") - string(FIND "${contents}" "${source_path}" leaked_path) - if(NOT leaked_path EQUAL -1) - message(FATAL_ERROR "Installed configuration leaks a source path: ${config_file}") - endif() - endif() - endforeach() - if(contents MATCHES "(/Users/|/home/|[A-Za-z]:[/\\\\]Users[/\\\\])") - message(FATAL_ERROR "Installed configuration leaks a personal path: ${config_file}") - endif() -endforeach() -execute_process(COMMAND "@CMAKE_COMMAND@" - -S "@CMAKE_CURRENT_SOURCE_DIR@/tests/installed_consumer" -B "${consumer_build}" - -G "@CMAKE_GENERATOR@" "-DCMAKE_BUILD_TYPE=${CONFIG}" - "-DCMAKE_PREFIX_PATH=${prefix}" - "-DCMAKE_CXX_COMPILER=@CMAKE_CXX_COMPILER@" - "-DCMAKE_CXX_FLAGS=@CMAKE_CXX_FLAGS@" - "-DCMAKE_EXE_LINKER_FLAGS=@CMAKE_EXE_LINKER_FLAGS@" - "-DCMAKE_CXX_CLANG_TIDY=@CMAKE_CXX_CLANG_TIDY@" - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF - COMMAND_ERROR_IS_FATAL ANY) -foreach(package parser runtime) - file(READ "${consumer_build}/imported-${package}-${CONFIG}.txt" imported_paths) - foreach(boundary library headers) - string(FIND "${imported_paths}" "${boundary}=${prefix}/" installed_path) - if(installed_path EQUAL -1) - message(FATAL_ERROR "Consumer ${package} ${boundary} does not resolve to the installation") - endif() - endforeach() -endforeach() -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) - -# Runtime 1.0.1 changes private layout; reject older installed packages. -set(old_runtime_prefix "${consumer_build}/old-runtime-prefix") -file(COPY "${prefix}/" DESTINATION "${old_runtime_prefix}") -include(CMakePackageConfigHelpers) -write_basic_package_version_file( - "${old_runtime_prefix}/@CMAKE_INSTALL_LIBDIR@/cmake/cel-runtime/cel-runtimeConfigVersion.cmake" - VERSION 1.0.0 COMPATIBILITY SameMajorVersion ARCH_INDEPENDENT) -set(version_probe "${consumer_build}/version-probe") -file(MAKE_DIRECTORY "${version_probe}") -file(WRITE "${version_probe}/CMakeLists.txt" - "cmake_minimum_required(VERSION 3.24)\n" - "project(runtime_version_probe LANGUAGES NONE)\n" - "find_package(cel-parser CONFIG REQUIRED)\n") -execute_process(COMMAND "@CMAKE_COMMAND@" - -S "${version_probe}" -B "${version_probe}/build" -G "@CMAKE_GENERATOR@" - "-DCMAKE_PREFIX_PATH=${old_runtime_prefix}" - "-DCMAKE_FIND_ROOT_PATH=${old_runtime_prefix}" - -DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY - -DCMAKE_FIND_USE_PACKAGE_REGISTRY=OFF -DCMAKE_FIND_USE_SYSTEM_PACKAGE_REGISTRY=OFF - RESULT_VARIABLE version_result OUTPUT_VARIABLE version_output ERROR_VARIABLE version_error) -if(version_result EQUAL 0 OR NOT "${version_output}${version_error}" MATCHES "cel-runtime" - OR NOT "${version_output}${version_error}" MATCHES "1\\.0\\.1" - OR NOT "${version_output}${version_error}" MATCHES "1\\.0\\.0") - message(FATAL_ERROR - "Installed parser must reject runtime 1.0.0:\n${version_output}${version_error}") -endif() diff --git a/tests/installed_consumer/CMakeLists.txt b/tests/installed_consumer/CMakeLists.txt deleted file mode 100644 index 2ceb0d9..0000000 --- a/tests/installed_consumer/CMakeLists.txt +++ /dev/null @@ -1,50 +0,0 @@ -# SPDX-License-Identifier: BSL-1.0 -cmake_minimum_required(VERSION 3.24) -project(installed_parser_consumer LANGUAGES CXX) -find_package(cel-parser CONFIG REQUIRED) -get_target_property(parser_imported cel::parser IMPORTED) -if(NOT parser_imported) - message(FATAL_ERROR "The consumer requires an installed imported target") -endif() -include(CTest) -add_executable(consumer ../../examples/example.cpp) -target_link_libraries(consumer PRIVATE cel::parser) -set_target_properties(consumer PROPERTIES CXX_EXTENSIONS OFF) -if(MSVC) - target_compile_options(consumer PRIVATE /W4 /WX) -else() - target_compile_options(consumer PRIVATE -Wall -Wextra -Wpedantic -Werror) -endif() -add_test(NAME consumer COMMAND consumer) -add_executable(lookup_consumer lookup.cpp) -target_link_libraries(lookup_consumer PRIVATE cel::parser) -set_target_properties(lookup_consumer PROPERTIES CXX_EXTENSIONS OFF) -add_test(NAME lookup_consumer COMMAND lookup_consumer) -add_executable(compiler_consumer compiler.cpp) -target_link_libraries(compiler_consumer PRIVATE cel::parser) -set_target_properties(compiler_consumer PROPERTIES CXX_EXTENSIONS OFF) -if(MSVC) - target_compile_options(compiler_consumer PRIVATE /W4 /WX) -else() - target_compile_options(compiler_consumer PRIVATE -Wall -Wextra -Wpedantic -Werror) -endif() -add_test(NAME compiler_consumer COMMAND compiler_consumer) -add_executable(cached_consumer ../../examples/cached_decoded.cpp) -target_link_libraries(cached_consumer PRIVATE cel::parser) -set_target_properties(cached_consumer PROPERTIES CXX_EXTENSIONS OFF) -add_test(NAME cached_consumer COMMAND cached_consumer) -add_executable(measurement_consumer ../../tools/measurement.cpp) -target_link_libraries(measurement_consumer PRIVATE cel::parser) -set_target_properties(measurement_consumer PROPERTIES CXX_EXTENSIONS OFF) -add_test(NAME measurement_consumer COMMAND measurement_consumer 10) -foreach(client lookup_consumer cached_consumer measurement_consumer) - if(MSVC) - target_compile_options(${client} PRIVATE /W4 /WX) - else() - target_compile_options(${client} PRIVATE -Wall -Wextra -Wpedantic -Werror) - endif() -endforeach() -file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/imported-parser-$.txt" - CONTENT "library=$\nheaders=$\n") -file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/imported-runtime-$.txt" - CONTENT "library=$\nheaders=$\n") diff --git a/tests/installed_consumer/compiler.cpp b/tests/installed_consumer/compiler.cpp deleted file mode 100644 index a4b1e7c..0000000 --- a/tests/installed_consumer/compiler.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include -#include - -/// Compiles and receives nested callable/composite results with only installed public headers. -/// Exercises retained captures, explicit arguments, empty typed results, and caller-prefix reuse. -int main() try { - auto program = [] { - cel::op_lookup lookup; - lookup.register_record( - "Callbacks", std::array{cel::record_field{ - "f", cel::value_type::callable({}, cel::value_type::leaf())}}); - lookup.register_op( - "offset", [n = std::make_unique(3)](double x) { return x + *n; }); - cel::parser compiler(std::move(lookup)); - return compiler.parse_str("(Callbacks{f:|| 4.0.offset()}, " - "[]:[Fn((),Fn((),f64))], |x:[f64]| || 7.0)"); - }(); - cel::raw_stack stack; - stack.push(99.0); - for (int repeat = 0; repeat != 3; ++repeat) { - auto result = program.execute(stack, {}); - auto fn = cel::callable::from_value(result.at(0).field("f")); - if (fn.call(stack, {}).as() != 7) return 1; - if (result.at(1).size() != 0) return 2; - auto outer = cel::callable::from_value(result.at(2)); - const std::array arguments{cel::value::from(std::vector{1.0, 2.0})}; - auto inner = cel::callable::from_value(outer.call(stack, arguments)); - if (inner.call(stack, {}).as() != 7 || stack.depth() != 1) return 3; - } - return stack.pop() == 99 ? 0 : 4; -} catch (...) { - return 5; -} diff --git a/tests/installed_consumer/lookup.cpp b/tests/installed_consumer/lookup.cpp deleted file mode 100644 index 5853b55..0000000 --- a/tests/installed_consumer/lookup.cpp +++ /dev/null @@ -1,39 +0,0 @@ -// SPDX-License-Identifier: BSL-1.0 -#include -#include -#include -#include - -/// Identifies the client's named identity operation. -struct function_marker {}; - -/// Executes cached owned callbacks and complete composites through installed packages only. -int main() try { - auto program = [] { - cel::op_lookup lookup; - const double offset = 3.0; - lookup.register_op("offset", [offset](double x) { return x + offset; }); - cel::parser compiler(std::move(lookup)); - return compiler.parse_str("4.0.offset()"); - }(); - auto prepared = program.prepare(); - cel::raw_stack stack; - if (prepared.call(stack) != 7.0 || prepared.call(stack) != 7.0) return 1; - cel::op_lookup lookup; - lookup.register_function("identity", function_marker{}); - lookup.register_op("identity", [](double x) { return x; }); - using nested = std::tuple>>>; - const nested input{true, {{2.0, {true, false}}}}; - lookup.register_op("nested", [](nested x) { return x; }); - cel::parser compiler(std::move(lookup)); - if (compiler.parse_str("identity(4.0)").prepare().call(stack) != 4.0) return 2; - if (compiler.parse_str("(true, [(2.0, [true, false])]).nested()") - .prepare() - .call(stack) != input) - return 3; - auto callable = compiler.parse_str("|x:[f64]| true").execute(stack, {}); - if (callable.type().parameters().size() != 1) return 4; - return 0; -} catch (...) { - return 5; -} diff --git a/tests/lookup_test.cpp b/tests/lookup_test.cpp index 9b156d0..1bc7ab6 100644 --- a/tests/lookup_test.cpp +++ b/tests/lookup_test.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: BSL-1.0 #include "lookup_access.hpp" +#include #include #include #include @@ -19,6 +20,25 @@ struct first { struct second { double number; }; +/// Supplies one adapter-backed nominal record for parser registration tests. +struct adapted_point { + double x; + double y; +}; +/// Supplies a same-layout second nominal record. +struct adapted_point_alias { + double x; + double y; +}; +/// Supplies a second adapter for the same nominal identity. +struct adapted_point_duplicate_name { + double x; + double y; +}; +/// Supplies a record whose runtime field name is not a CEL identifier. +struct adapted_unspellable_field { + double value; +}; /// Marks an ordinary registered function independently of its operand overloads. struct named_function {}; /// Marks an independent installer's binding of the same function name. @@ -59,6 +79,91 @@ R operation(const cel::op_lookup& lookup, std::string_view name, A... arguments) } } // namespace +namespace cel { +template <> +struct record_adapter<::adapted_point> { + /// Returns the canonical nominal descriptor for adapted_point. + static value_type type() { + static const auto descriptor = value_type::record( + "sample.point", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one point value in canonical field order. + static value to_value(const ::adapted_point& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one point value after descriptor validation. + static ::adapted_point from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong adapted point type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +template <> +struct record_adapter<::adapted_point_alias> { + /// Returns the canonical nominal descriptor for adapted_point_alias. + static value_type type() { + static const auto descriptor = value_type::record( + "AdapterPointAlias", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one alias value in canonical field order. + static value to_value(const ::adapted_point_alias& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one alias value after descriptor validation. + static ::adapted_point_alias from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong adapted point alias type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +template <> +struct record_adapter<::adapted_point_duplicate_name> { + /// Returns the same nominal identity as adapted_point. + static value_type type() { + static const auto descriptor = value_type::record( + "sample.point", std::array{record_field{"x", value_type::leaf()}, + record_field{"y", value_type::leaf()}}); + return descriptor; + } + /// Encodes one duplicate-name value in canonical field order. + static value to_value(const ::adapted_point_duplicate_name& source) { + return value::record(type(), std::array{value::from(source.x), value::from(source.y)}); + } + /// Decodes one duplicate-name value after descriptor validation. + static ::adapted_point_duplicate_name from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong adapted point duplicate type"); + return {.x = source.field("x").as(), .y = source.field("y").as()}; + } +}; + +template <> +struct record_adapter<::adapted_unspellable_field> { + /// Returns a descriptor containing an unspellable field name. + static value_type type() { + static const auto descriptor = value_type::record( + "Unspellable", std::array{record_field{"first-name", value_type::leaf()}}); + return descriptor; + } + /// Encodes the value as a canonical record. + static value to_value(const ::adapted_unspellable_field& source) { + return value::record(type(), std::array{value::from(source.value)}); + } + /// Decodes the value after checking its descriptor. + static ::adapted_unspellable_field from_value(const value& source) { + if (!source.type().same_shape(type())) + throw std::invalid_argument("wrong unspellable record type"); + return {source.field("first-name").as()}; + } +}; +} // namespace cel + TEST_CASE("structural registrations reject nontrivial adapters without reserving names") { cel::op_lookup lookup; CHECK_THROWS_AS(lookup.register_type>("array"), std::invalid_argument); @@ -213,6 +318,129 @@ TEST_CASE("declined overloads never execute and selected emitter failures propag CHECK_THROWS_WITH(operation(lookup, "throwing"), "callback"); } +TEST_CASE("record adapter registration preserves nominal types and member calls") { + cel::op_lookup lookup; + lookup.register_record_type("AdapterPoint"); + lookup.register_record_type("AdapterPointAlias"); + std::size_t adapted_point_calls = 0; + lookup.register_op("sum", [&adapted_point_calls](adapted_point input) { + ++adapted_point_calls; + return input.x + input.y; + }); + cel::dyn_segment mismatch; + mismatch.just(cel::value::from(adapted_point_alias{.x = 1.0, .y = 2.0})); + CHECK_THROWS_AS(cel::parser_detail::lookup_access::apply(lookup, "sum", mismatch, 1, {}), + cel::parse_error); + CHECK(adapted_point_calls == 0); + CHECK(evaluate(std::move(mismatch)).x == 1.0); + lookup.register_op( + "sum", [](adapted_point_alias input) { return input.x - input.y; }); + cel::parser parser(std::move(lookup)); + cel::raw_stack stack; + CHECK( + parser.parse_str("AdapterPoint { y: 2.0, x: 1.0 }.sum()").execute(stack, {}).as() == + 3.0); + CHECK(parser.parse_str("AdapterPointAlias { y: 2.0, x: 1.0 }.sum()") + .execute(stack, {}) + .as() == -1.0); +} + +TEST_CASE("record adapter registration rejects duplicate CEL source names") { + cel::op_lookup lookup; + lookup.register_record_type("AdapterPoint"); + CHECK_THROWS_AS(lookup.register_record_type("AdapterPoint"), + std::invalid_argument); +} + +TEST_CASE("record adapters separate CEL source names from nominal identities") { + cel::op_lookup lookup; + lookup.register_record_type("Point"); + lookup.register_record_type("OtherPoint"); + const auto type = lookup.find_type("Point"); + if (!type) throw std::logic_error("registered Point missing"); + CHECK(type->record_identity() == "sample.point"); + lookup.register_op( + "sum", [](adapted_point point) { return point.x + point.y; }); + cel::parser parser(std::move(lookup)); + cel::raw_stack stack; + CHECK(parser.parse_str("Point {y: 2.0, x: 1.0}.sum()").execute(stack, {}).as() == 3.0); + CHECK(parser.parse_str("OtherPoint {x: 4.0, y: 5.0}.sum()").execute(stack, {}).as() == + 9.0); + CHECK(parser.parse_str("(|point: Point| point.x)(Point {x: 4.0, y: 5.0})") + .execute(stack, {}) + .as() == 4.0); +} + +TEST_CASE("record registration rejects source names that cannot construct records") { + for (const std::string_view name : + {"sample.point", "first-name", "true", "if", "else", "as", "f64", "name "}) { + CAPTURE(name); + cel::op_lookup lookup; + const auto original = lookup.find_type(name); + CHECK_THROWS_AS(lookup.register_record_type(name), std::invalid_argument); + const bool first_unchanged = lookup.find_type(name).has_value() == original.has_value(); + CHECK(first_unchanged); + CHECK_THROWS_AS(lookup.register_record(name, std::array{cel::record_field{ + "x", cel::value_type::leaf()}}), + std::invalid_argument); + const auto after = lookup.find_type(name); + const bool second_unchanged = after.has_value() == original.has_value(); + CHECK(second_unchanged); + if (original && after) CHECK(after->same_shape(*original)); + } + + cel::op_lookup lookup; + lookup.register_record_type("r#if"); + cel::parser parser(std::move(lookup)); + cel::raw_stack stack; + CHECK(parser.parse_str("r#if {x: 2.0, y: 3.0}.x").execute(stack, {}).as() == 2.0); +} + +TEST_CASE("record registration rejects field names that CEL cannot spell") { + for (const std::string_view name : + {"first-name", "first name", "true", "1name", "name ", "r#_", "\xFF"}) { + CAPTURE(name); + cel::op_lookup lookup; + const auto fields = + std::array{cel::record_field{std::string(name), cel::value_type::leaf()}}; + CHECK_THROWS_AS(lookup.register_record("Bad", fields), std::invalid_argument); + CHECK_FALSE(lookup.find_type("Bad").has_value()); + } + + cel::op_lookup lookup; + CHECK_THROWS_AS(lookup.register_record_type("Unspellable"), + std::invalid_argument); + CHECK_FALSE(lookup.find_type("Unspellable").has_value()); +} + +TEST_CASE("record registration rejects unspellable nested fields") { + const auto nested = cel::value_type::record( + "Nested", std::array{cel::record_field{"first-name", cel::value_type::leaf()}}); + for (const auto& field_type : std::array{ + nested, cel::value_type::array(nested), cel::value_type::tuple(std::array{nested}), + cel::value_type::callable({}, nested), + cel::value_type::callable(std::array{nested}, cel::value_type::leaf())}) { + cel::op_lookup lookup; + CHECK_THROWS_AS( + lookup.register_record("Outer", std::array{cel::record_field{"nested", field_type}}), + std::invalid_argument); + CHECK_FALSE(lookup.find_type("Outer").has_value()); + } +} + +TEST_CASE("record registration accepts spellable field identifiers") { + cel::op_lookup lookup; + 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::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") + .execute(stack, {}) + .as() == 2.0); +} + TEST_CASE("nominal records and arbitrary nested registration use public runtime emitters") { cel::op_lookup lookup; const auto field = cel::record_field{ diff --git a/tests/tests.cpp b/tests/tests.cpp index 38b470c..c908df6 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -44,7 +44,7 @@ TEST_CASE("numbers retain scalar meaning and exact selector spelling") { {"1f64", 1}, {"2.5f64", 2.5}, {"1e+2", 100}, - {"1_e_+_2", 100}, + {"1_e+_2", 100}, {"1_000", 1000}, {"1.", 1}, {"0xff", 255}, @@ -73,6 +73,30 @@ TEST_CASE("numbers retain scalar meaning and exact selector spelling") { CHECK(std::get(t[9].value).suffix == "f64"); } +TEST_CASE("exponent signs precede all exponent underscores") { + for (auto [text, expected] : + std::array{std::pair{"1e+_2f64", 100.0}, std::pair{"1e__2f64", 100.0}, + std::pair{"1e-__2f64", 0.01}, std::pair{"1.0E+__2f64", 100.0}}) { + INFO(std::string_view(text)); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& number = std::get(t[0].value); + CHECK(number.value == expected); + CHECK(number.spelling == text); + CHECK(t[0].span == (cel::source_span{0, std::string_view(text).size()})); + } + for (auto text : {"1e_+2f64", "1e__-2f64", "1e_+_2f64", "1.0e_+2f64", "1E__+2f64", "1_e_+_2"}) { + INFO(std::string_view(text)); + auto t = collect(text); + REQUIRE(t.size() == 2); + REQUIRE(std::holds_alternative(t[0].value)); + auto const& error = std::get(t[0].value); + CHECK(error.category() == cel::error_category::malformed_input); + CHECK(error.span() == (cel::source_span{0, std::string_view(text).size()})); + } +} + TEST_CASE("binary64 boundary conversion preserves Rust infinity and zero results") { auto t = collect("1e9999 1e-9999 1.7976931348623157e308 " "1.7976931348623159e308 5e-324 2e-324 0e9999"); diff --git a/tools/parity/core_corpus.py b/tools/parity/core_corpus.py index 0125c5e..dd92318 100644 --- a/tools/parity/core_corpus.py +++ b/tools/parity/core_corpus.py @@ -6,17 +6,21 @@ def core_corpus(): """Returns authored grammar templates and bounded Cartesian intrinsic combinations. Core registers no client records or functions; record grammar remains in client fixtures. - Rejection cases require a C++ parse failure, while all successes compare real observations. + C++-only rejections require a C++ parse failure. Shared-invalid cases require + both parsers to reject at the same span; successes compare real observations. Complexity: O(corpus size) time and result space. """ rows = [] - def add(family, source, *, reject=False): - """Appends an unchanged source with a required success or checked core rejection.""" + def add(family, source, *, reject=False, category=None): + """Appends an unchanged source with a required success or rejection.""" row = {"id": f"core-{family}-{len(rows)}", "family": f"core-{family}", "source": source, "setup": "core"} if reject: row["cpp_reject"] = "outside bool/f64 core grammar or exact operand types" + if category is not None: + row["category"] = category + row["status"] = "parse" rows.append(row) for left, operator, right in product( @@ -59,6 +63,11 @@ def add(family, source, *, reject=False): for source in [ "1.0", "1.", "1e0", "1.0_f64", "1_0.0f64", "1.0e+0f64", "1e-9999f64", "5e-324f64", "1e9999f64", "-0.0f64", + "1e+_2f64", "1e__2f64", "1e-__2f64", "1.0E+__2f64", + "1f64", "1_f64", "0f64", "1__f64", "1_000f64", "9007199254740993f64", + "340_282_366_920_938_463_463_374_607_431_768_211_456f64", + "-0f64", "1f64+2.0f64", "1f64..2f64", "1f64..=2f64", + "1f64..", "..2f64", "..=2f64", "/* ordinary */true", "true/* nested /* block */ comment */&&false", "true// ordinary trailing comment", "/* */1.0f64 /* */+/* */ 2.0f64", "(1.0f64,2.0f64).0x1", "(1.0f64,2.0f64).0b1", @@ -66,6 +75,9 @@ def add(family, source, *, reject=False): "((1.0f64,2.0f64),).0.1", "(|λ:f64|λ)(1.0f64)", ]: add("lexical-positive", source) + for source in ["1e_+2f64", "1e__-2f64", "1e_+_2f64", "1.0e_+2f64", + "1E__+2f64", "1_e_+_2"]: + add("exponent-invalid", source, category="malformed_input") for source in [ "", " ", "[]", "[1.0f64,]", "(1.0f64,2.0f64,)", "[,]", "(,)", "(1.0f64 2.0f64)", "1.0f64 2.0f64", "true false", "1.0f64;2.0f64", @@ -78,10 +90,12 @@ def add(family, source, *, reject=False): "true & & false", "true | | false", "1.0f64 < = 2.0f64", "1.0f64 = = 2.0f64", "1.0f64 . . 2.0f64", "true&/*jointness*/&false", "/* unterminated", "/// doc comment", "/** doc comment */true", "//! inner doc", "/*! inner doc */true", - "r#true", "trué", "trueλ", "1.0f64foo", "1.0f32", "1f32", "1f64", + "r#true", "trué", "trueλ", "1.0f64foo", "1.0f32", "1f32", + "1f64x", "1f64_", "1f640", "0b1f64", "0o7_f64", "0x1f64", "1 as f64", "1", "0x1", "0b1", "0o1", "1i32", "1u8", "1.0i32", "2+3*4", "2f64+3", "[1.0f64][0]", "[1.0f64][0.0f64]", "([]:[f64])[0]", - "(1.0f64,).0f64", "(1.0f64,).0e0", "(1.0f64,).184467440737095516160", + "(1.0f64,).0f64", "(1f64,).0f64", "(1f64,).0_f64", + "(1.0f64,).0e0", "(1.0f64,).184467440737095516160", "let x=1.0f64", "true?1.0f64:2.0f64", "x=1.0f64", "+1.0f64", "sqrt(4.0f64)", "tap(1.0f64)", "Empty{}", "1.0f64.abs()", "(||1.0f64)()()", "|x:(f64,bool,)|x", "[]:[Fn((f64,bool,),f64)]", diff --git a/tools/parity/prepare_reference.py b/tools/parity/prepare_reference.py index 7d10bd7..decdbb7 100644 --- a/tools/parity/prepare_reference.py +++ b/tools/parity/prepare_reference.py @@ -6,11 +6,32 @@ import subprocess +NUMERIC_FIX_COMMITS = ( + "c9a45c479a70ef31c9b7b2d86b9f407d46074370", + "e1ea1d3083fe97fd26b49352e62c88c24ffa7913", +) + + +def verify_numeric_fixes(source): + """Requires both Rust numeric-parity fixes in the reference checkout.""" + for commit in NUMERIC_FIX_COMMITS: + result = subprocess.run( + ["git", "-C", str(source), "merge-base", "--is-ancestor", commit, "HEAD"], + check=False, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, + ) + if result.returncode != 0: + raise RuntimeError( + f"Rust reference must contain numeric-parity commit {commit} in HEAD history") + + def prepare(source, build): """Builds core packages from canonical paths and locks completed manifest transitions. Seeds changed or unfinished manifests from the canonical lockfile. Repeated successful - preparations require the generated resolved lock unchanged. Never writes the source checkout. + preparations require the generated resolved lock unchanged. Requires both numeric-parity + fixes in the Rust reference history. Never writes the source checkout. """ source, build = Path(source).resolve(), Path(build).resolve() for package in ("cel-parser", "cel-runtime"): @@ -18,6 +39,7 @@ def prepare(source, build): raise FileNotFoundError(f"required Rust reference package: {source / package}") if not (source / "Cargo.lock").is_file(): raise FileNotFoundError("enabled parity gate requires the reference Cargo.lock") + verify_numeric_fixes(source) cargo = shutil.which("cargo") if cargo is None: raise FileNotFoundError("enabled parity gate requires Cargo") diff --git a/tools/parity/test_prepare_reference.py b/tools/parity/test_prepare_reference.py index 5e427f9..d9c67db 100644 --- a/tools/parity/test_prepare_reference.py +++ b/tools/parity/test_prepare_reference.py @@ -1,6 +1,7 @@ """Checks core dependency migration and locked, recoverable reference preparation.""" from pathlib import Path import shutil +from subprocess import CompletedProcess import unittest from unittest.mock import patch import uuid @@ -23,6 +24,28 @@ def setUp(self): (self.source / "Cargo.lock").write_text("# canonical pins\n", encoding="utf-8") self.addCleanup(shutil.rmtree, self.root) + def test_requires_numeric_reference_fixes_before_cargo(self): + """Rejects a reference missing either numeric-parity fix before invoking Cargo.""" + required = [ + "c9a45c479a70ef31c9b7b2d86b9f407d46074370", + "e1ea1d3083fe97fd26b49352e62c88c24ffa7913", + ] + commands = [] + + def run(command, **kwargs): + """Reports the exponent fix as absent after accepting the integer-form fix.""" + commands.append(command) + if command[0] == "git": + return CompletedProcess(command, int(command[5] == required[1]), "", "") + return CompletedProcess(command, 0, "", "") + + with patch("prepare_reference.shutil.which", return_value="cargo"), \ + patch("prepare_reference.subprocess.run", side_effect=run): + with self.assertRaisesRegex(RuntimeError, required[1]): + prepare(self.source, self.build) + self.assertEqual([command[5] for command in commands], required) + self.assertEqual([command[0] for command in commands], ["git", "git"]) + def test_dependency_migration_then_locked_repeat(self): """Drops the optional dependency, seeds canonical pins, then uses the resolved lock.""" self.build.mkdir() @@ -30,13 +53,16 @@ def test_dependency_migration_then_locked_repeat(self): (self.build / "Cargo.lock").write_text("# obsolete pins\n", encoding="utf-8") commands = [] - def build(command, *, check): + def build(command, **kwargs): """Emulates only Cargo resolution after observing the generated input files.""" + if command[0] == "git": + return CompletedProcess(command, 0, "", "") commands.append(command) - self.assertTrue(check) + self.assertTrue(kwargs["check"]) if "--locked" not in command: self.assertEqual((self.build / "Cargo.lock").read_text(), "# canonical pins\n") (self.build / "Cargo.lock").write_text("# resolved pins\n", encoding="utf-8") + return CompletedProcess(command, 0, "", "") with patch("prepare_reference.shutil.which", return_value="cargo"), \ patch("prepare_reference.subprocess.run", side_effect=build): @@ -52,15 +78,30 @@ def build(command, *, check): def test_failed_resolution_is_recoverable(self): """Retries an unfinished manifest transition without treating its old lock as resolved.""" from subprocess import CalledProcessError + + def fail_cargo(command, **kwargs): + """Allows reference checks and fails only Cargo resolution.""" + if command[0] == "git": + return CompletedProcess(command, 0, "", "") + raise CalledProcessError(1, command) + with patch("prepare_reference.shutil.which", return_value="cargo"), \ - patch("prepare_reference.subprocess.run", - side_effect=CalledProcessError(1, "cargo")): + patch("prepare_reference.subprocess.run", side_effect=fail_cargo): with self.assertRaises(CalledProcessError): prepare(self.source, self.build) + commands = [] + + def retry_cargo(command, **kwargs): + """Allows reference checks and records the recovery Cargo invocation.""" + if command[0] == "git": + return CompletedProcess(command, 0, "", "") + commands.append(command) + return CompletedProcess(command, 0, "", "") + with patch("prepare_reference.shutil.which", return_value="cargo"), \ - patch("prepare_reference.subprocess.run") as build: + patch("prepare_reference.subprocess.run", side_effect=retry_cargo): prepare(self.source, self.build) - self.assertNotIn("--locked", build.call_args.args[0]) + self.assertNotIn("--locked", commands[0]) def test_changed_canonical_checkout_reseeds_its_own_pins(self): """Reinitializes dependency resolution when the selected source checkout changes.""" @@ -68,13 +109,16 @@ def test_changed_canonical_checkout_reseeds_its_own_pins(self): shutil.copytree(self.source, other) (other / "Cargo.lock").write_text("# other canonical pins\n", encoding="utf-8") with patch("prepare_reference.shutil.which", return_value="cargo"), \ - patch("prepare_reference.subprocess.run"): + patch("prepare_reference.subprocess.run", side_effect=self.successful_run): prepare(self.source, self.build) observed = [] - def build(command, *, check): + def build(command, **kwargs): """Observes the source-specific lock consumed at the Cargo boundary.""" + if command[0] == "git": + return CompletedProcess(command, 0, "", "") observed.append((command, (self.build / "Cargo.lock").read_text())) + return CompletedProcess(command, 0, "", "") with patch("prepare_reference.shutil.which", return_value="cargo"), \ patch("prepare_reference.subprocess.run", side_effect=build): @@ -82,6 +126,11 @@ def build(command, *, check): self.assertEqual(observed[0][1], "# other canonical pins\n") self.assertNotIn("--locked", observed[0][0]) + @staticmethod + def successful_run(command, **kwargs): + """Reports successful external commands for a reference-check setup.""" + return CompletedProcess(command, 0, "", "") + if __name__ == "__main__": unittest.main()