fix: preserve matrix object identity#130
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Pine matrix wrappers to preserve PineScript-style matrix object identity (reference IDs) across ordinary C++ copies/assignments, while keeping copy() as the explicit detach operation. It also aligns snapshot/restore and Series tests with the new aliasing semantics.
Changes:
- Rework
PineMatrix,PineGenericMatrix<T>, andPineGenericMatrix<bool>to share backing storage viastd::shared_ptr, so copy/assignment aliases the same matrix ID. - Update snapshot/restore to retain and mutate the original identity in-place (so existing aliases observe rollbacks), with explicit invalid-snapshot errors.
- Add/adjust focused tests covering identity, moves, snapshot behavior, and Series aliasing expectations.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_matrix_snapshot_compat.cpp | Updates snapshot compatibility assertions to reflect aliasing-on-assignment semantics. |
| tests/test_matrix_identity.cpp | New targeted test binary validating aliasing, detach via copy(), move semantics, and snapshot identity behavior. |
| tests/test_generic_matrix_series.cpp | Updates Series test to assert that history slots preserve matrix ID aliasing rather than value-detaching. |
| tests/CMakeLists.txt | Registers the new test_matrix_identity executable in the test suite. |
| src/matrix.cpp | Implements storage-backed identity, updated snapshot/restore, and routes operations through storage accessors. |
| include/pineforge/matrix.hpp | Switches PineMatrix to shared storage, defines identity-preserving move semantics, and snapshot identity retention. |
| include/pineforge/generic_matrix.hpp | Applies the same shared-identity model to generic and bool matrices, including snapshot identity retention and restore behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
copy()operation and preserve null/valid-empty behaviorRoot cause
The runtime wrappers owned matrix state by value. C++ assignment therefore detached the destination even though Pine matrix IDs are reference objects. That value behavior could be hidden by codegen-side UDT copies, typed method dispatch, and checkpoint restoration, so it was validated as independent factor D in the full A/B/C/D matrix.
Scope boundary
This PR changes only matrix object identity and its focused tests. It does not add direct-array UDT field support and does not modify strategy sources, TradingView tapes, settings, graders, or tier data. None of the seven changed paths has a Git LFS attribute.
Validation
git diff --check: cleanCompanion milestones are merged: codegen #100 and exhaustive harness #119. The engine base already contains snapshot bridge #128 and Release assertion #129.