R1-03: Core strong types - #2
Merged
Merged
Conversation
aravgarg28
force-pushed
the
task/R1-03-core-types
branch
2 times, most recently
from
July 25, 2026 01:21
a663002 to
5756ce9
Compare
Introduces the dimensioned value types and identifiers that every later module builds on, encoding docs/numerics/NUMERIC_REPRESENTATION.md in the type system: - Price (int64 ticks), Qty (int64 lots), Cash (int64 minor units), SimTime/Duration (int64 ns), Side, and opaque identifiers OrderId, TradeId, Seq (sequential, with next()/first()), ClientOrderId, ParticipantId, InstrumentId. - Operator sets are deliberately narrow: Price +/- int -> Price, Price - Price -> int64 ticks, Qty +/- Qty, Cash signed arithmetic, SimTime +/- Duration and SimTime - SimTime -> Duration. Meaningless operations do not exist as overloads, so they are compile errors. - No implicit conversions to/from raw integers (explicit ctors and named accessors only); ids hash and order for map keys and the monotonicity invariants (INV-9). - std::format formatters and ostream operators print via integer scale math with unit tags (1003t, 50lot, -25mu, 500ns, order#42); currency formatting that needs a tick size is deferred to R1-06. Tests: static_asserts pin allowed-op result types and the no-implicit-conversion rules; runtime tests cover arithmetic, ordering, ids, and formatting; nine compile-fail tests prove the banned operations (Price+Qty, Price+Price, Price*Qty, implicit int<-> Price, Qty+Cash, SimTime+SimTime, Qty*Qty, cross-type compare) do not compile, with a positive control proving the harness discriminates. Verified: 30/30 tests pass under debug and asan-ubsan; -Werror clean; clang-format (pinned 20.1.7) clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
aravgarg28
force-pushed
the
task/R1-03-core-types
branch
from
July 25, 2026 01:25
5756ce9 to
5637ef4
Compare
aravgarg28
added a commit
that referenced
this pull request
Jul 27, 2026
Introduces the dimensioned value types and identifiers that every later module builds on, encoding docs/numerics/NUMERIC_REPRESENTATION.md in the type system: - Price (int64 ticks), Qty (int64 lots), Cash (int64 minor units), SimTime/Duration (int64 ns), Side, and opaque identifiers OrderId, TradeId, Seq (sequential, with next()/first()), ClientOrderId, ParticipantId, InstrumentId. - Operator sets are deliberately narrow: Price +/- int -> Price, Price - Price -> int64 ticks, Qty +/- Qty, Cash signed arithmetic, SimTime +/- Duration and SimTime - SimTime -> Duration. Meaningless operations do not exist as overloads, so they are compile errors. - No implicit conversions to/from raw integers (explicit ctors and named accessors only); ids hash and order for map keys and the monotonicity invariants (INV-9). - std::format formatters and ostream operators print via integer scale math with unit tags (1003t, 50lot, -25mu, 500ns, order#42); currency formatting that needs a tick size is deferred to R1-06. Tests: static_asserts pin allowed-op result types and the no-implicit-conversion rules; runtime tests cover arithmetic, ordering, ids, and formatting; nine compile-fail tests prove the banned operations (Price+Qty, Price+Price, Price*Qty, implicit int<-> Price, Qty+Cash, SimTime+SimTime, Qty*Qty, cross-type compare) do not compile, with a positive control proving the harness discriminates. Verified: 30/30 tests pass under debug and asan-ubsan; -Werror clean; clang-format (pinned 20.1.7) clean.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
R1-03: Core strong types — Completion Report
Status: complete
Branch/PR:
task/R1-03-core-typesWhat was built
src/core/include/microsim/core/types.hpp(+types.cpp): the dimensioned value types and identifiers every later module depends on, encodingdocs/numerics/NUMERIC_REPRESENTATION.mdin the type system.Price(int64 ticks),Qty(int64 lots),Cash(int64 minor units),SimTime/Duration(int64 ns), andSide(+opposite,sign_of,to_cstr).OrderId,TradeId,Seq(sequential, withfirst()/next()for the monotonic assigners),ClientOrderId,ParticipantId,InstrumentId— opaque handles that order and hash but carry no arithmetic.Price ± int → Price,Price − Price → int64ticks,Qty ± Qty,Cashsigned arithmetic,SimTime ± Duration → SimTime,SimTime − SimTime → Duration. Meaningless operations simply have no overload, so they are compile errors.std::format+ ostream printing via integer scale math with unit tags (1003t,50lot,-25mu,500ns,order#42). Currency formatting (needs a tick size) is correctly deferred to R1-06 per the task's Excludes.Acceptance criteria
static_assert(allowed-op result types + no-implicit-conversion) intest_types.cppstatic_assertsuite for type rules — 14 static_asserts (result types, convertibility, size/triviality)std::format/formatter printing via integer scale math —Format.*testsNotional(needs instrument, R1-05), no string conversions (R1-06)Price/Qty/Cash/Time/Side/Ids/Formatsuitestry-style CTest targets (WILL_FAIL), plus a positive controlVerification output
Tests added
static_assert×14 (test_types.cpp)Price.*,Qty.*,Cash.*,Time.*,Side.*Ids.SequentialIdsIncreaseMonotonically,Ids.HashableAsMapKeysFormat.StdFormatUsesUnitTags,Format.OstreamMatchesFormatcore.compile_fail.*×9 +ok_controlDeviations / Questions
Priceprints1003t,Cashprints-25mu. This matches "printing via integer scale math" at the level available here; flagging so it's a conscious choice, not an oversight.Duration * int64(latency composition needsbase * n, LATENCY_MODEL.md) andsign_of(Side)(fill→position sign, used pervasively by accounting). Neither weakens the banned-op guarantees. Happy to remove if you'd rather keep the surface minimal.Notes for reviewer
types.hpp— each states its allowed/banned operations in prose next to the code.tests/CMakeLists.txt,microsim_add_compile_fail) is the interesting infra: each banned op is anEXCLUDE_FROM_ALLtarget a CTest builds and expects to fail;ok_controlbuilds normally so a broken harness fails loudly rather than passing vacuously.main— currently blocked on theworkflowOAuth scope (see the R1-02 status). Locally verified on macOS/AppleClang 17 under debug + asan-ubsan +-Werror.