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.
Please read the #242 Using tests from “Violet - Python VM written in Swift” before.
All pass.
🐰 Discussion
Those tests are a bit difficult to grasp. Especially because they start with unary operations. I think it would be better if you started with binary operations:
The general idea is that the original
value
should not be modified when we perform operation oncopy
. It will not test if the copy was created before (var copy = value
) or during the write (actualCOW
), but it will test that the copy was made at some point.The general idea is that
BigInt
will probably allocate on the heap. What happens when we modify the heap value? All of them change? Or maybe only theBigInt
that was used in operation? It is easy to break the invariant if you implement COW by hand.Alternatively you could make
BigInt
non-copyable (move-only). Then you chose:BigInt
copy (no COW)BigInt
is astruct
with explicitcopy/retain
(COW, acting like a smart pointer, RAII etc.)Obviously move-only is extremely un-ergonomic, so…