schemagen: cache non-object $defs entries to avoid duplicate types #31

Merged
andrew merged 2 commits from weaselbot/weaseljson:weaselbot/issue-17 into main 2026-06-24 17:02:39 +00:00
Member

Closes #17

This PR resolves issue #17 by extending the per-definition type cache to enum, array, and scalar $defs so multiple $refs reuse the same C++ type.

Closes #17 This PR resolves issue #17 by extending the per-definition type cache to enum, array, and scalar $defs so multiple $refs reuse the same C++ type.
weaselbot added 1 commit 2026-06-24 02:17:36 +00:00
schemagen: cache non-object $defs entries to avoid duplicate types
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Failing after 51s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Failing after 51s
CI / pre-commit (pull_request) Successful in 52s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Failing after 1m12s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Failing after 1m14s
717f30099f
Extend the existing per-definition cache (`self._building`) to enum,
array, and scalar $defs, not just object definitions. This ensures
that multiple $refs to the same non-object definition reuse the same
C++ type instead of generating Role, Role2, Role3, etc.

- Cache the built (type, nullable) tuple under defname for enum,
  scalar, and array definitions.
- Pre-register array definitions before recursing into items so $ref
  cycles resolve to the same TArr instance.
- Store object definitions as (TObj, nullable) tuples so nullable object
  $defs also preserve their nullability when referenced.

Add a regression test for issue #17 covering reused enum and array-of-enum
$defs.
weaselbot changed title from WIP: test to WIP: schemagen: cache non-object $defs entries to avoid duplicate types 2026-06-24 02:17:40 +00:00
weaselbot marked the pull request as ready for review 2026-06-24 02:17:44 +00:00
weaselbot added 1 commit 2026-06-24 13:51:26 +00:00
schemagen: restore nullable tuple return for object schemas
CI / pre-commit (pull_request) Successful in 51s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-arm64, ubuntu-latest-arm64, true) (pull_request) Successful in 1m1s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-arm64, ubuntu-latest-arm64, false) (pull_request) Successful in 1m0s
CI / build (-DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++, clang-amd64, ubuntu-latest-amd64, true) (pull_request) Successful in 1m28s
CI / build (-DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++, gcc-amd64, ubuntu-latest-amd64, false) (pull_request) Successful in 1m23s
e155e0bbf4
The previous change to cache object definitions started returning the
bare TObj from build_type for object schemas, discarding the nullable
flag. This caused nullable root objects to be emitted as plain structs
instead of std::optional<RootInner>, breaking the nullable root tests.

Return the (TObj, nullable) tuple so callers (including the root
emitter) see the correct nullability again.
andrew merged commit e5cbaac401 into main 2026-06-24 17:02:39 +00:00
andrew deleted branch weaselbot/issue-17 2026-06-24 17:02:39 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weaselab/weaseljson#31