Skip to content

fix(lang): truthful ownership labels in TensorStorageFactory (#927) - #935

Merged
michalharakal merged 5 commits into
developfrom
fix/storage-factory-ownership-labels-927
Aug 10, 2026
Merged

michalharakal merged 5 commits into
developfrom
fix/storage-factory-ownership-labels-927

Conversation

@michalharakal

Copy link
Copy Markdown
Contributor

Full analysis in #927. Two contract violations, one fix strategy: make the labels tell the truth, because BufferHandle.Ownership is the storage layer's authority and MemoryTracker reports key off it.

  • borrowFloatArray — doc said "(zero-copy)", implementation re-encoded floats into a private ByteArray and labeled the copy Borrowed. A FloatArray has no byte-view in common Kotlin, so genuine borrowing is impossible here by construction. Now deprecated with ReplaceWith(fromFloatArray) and honestly returns Owned. Real zero-copy borrowing lives in fromRawBytes (byte input), which the docs now point to.
  • fromTensorData — doc said "borrowed (not copied)" while the dense branches copy. The KDoc now states the per-branch contract: packed Q4_K/Q8_0 borrow genuinely zero-copy (shared packedData), dense arrays convert to owned bytes, everything else materializes.

Tests: the acceptance test that enshrined the false promise (ac3_borrowedConstructorDoesNotCopy) is replaced by the honest assertion; new mutation-visibility tests pin both the genuine-borrow path (fromRawBytes) and the packed zero-copy bridge.

Verified: :skainet-lang:skainet-lang-core:jvmTest green (full module).

Note: CHANGELOG entry included — expect trivial [Unreleased] conflicts with sibling PRs in the #927–#931 series.

Closes #927

borrowFloatArray promised '(zero-copy)' and returned a Borrowed handle,
but a FloatArray has no byte-view in common Kotlin — the implementation
re-encoded every float into a private ByteArray and labeled the copy
Borrowed. That misrepresents ownership to every consumer of
TensorStorage.ownership and to MemoryTracker reports. It is now
deprecated (ReplaceWith fromFloatArray) and honestly returns Owned.

fromTensorData's KDoc claimed 'the underlying data is borrowed (not
copied)' while the dense float/int branches copy via
BufferHandleFactory.owned. The contract is now documented per branch:
packed Q4_K/Q8_0 borrow genuinely zero-copy (shared packedData), dense
arrays convert to owned bytes, everything else materializes.

Tests: the acceptance test that enshrined the false promise
(ac3_borrowedConstructorDoesNotCopy) now asserts the honest OWNED label;
a new ac3 test shows where real borrowing lives (fromRawBytes, with
mutation visibility through the shared array); the fromTensorData bridge
tests gain ownership assertions plus a packed zero-copy
mutation-visibility test.

Closes #927
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-935 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@michalharakal
michalharakal requested a review from aharakal August 10, 2026 08:54
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-935 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-935 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

aharakal
aharakal previously approved these changes Aug 10, 2026
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-935 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

@michalharakal
michalharakal merged commit c1401b2 into develop Aug 10, 2026
13 checks passed
@michalharakal
michalharakal deleted the fix/storage-factory-ownership-labels-927 branch August 10, 2026 13:11
@github-actions

Copy link
Copy Markdown

📖 Documentation Preview

The documentation has been built successfully for this PR.

Generated Files:

  • Operator documentation: docs/modules/operators/_generated_/
  • JSON schema output: operators.json

Artifacts:

  • Download the documentation-preview-935 artifact to view the complete documentation locally.

This comment will be updated automatically when the PR is updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TensorStorageFactory violates its own copy/borrow contracts: "zero-copy" borrowFloatArray copies, "borrowed" fromTensorData owns

2 participants