Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and fix contracts for inline functions #3535

Merged
merged 20 commits into from
Nov 22, 2024
Merged

Add and fix contracts for inline functions #3535

merged 20 commits into from
Nov 22, 2024

Conversation

kyay10
Copy link
Collaborator

@kyay10 kyay10 commented Nov 15, 2024

Most of these changes should be straightforward. One that might be confusing at first is zipOrAccumulate having all lambdas marked exactly-once. The reason is that, after the execution of zipOrAccumulate, we're totally guaranteed to have executed them all because if any of them raise, zipOrAccumulate will raise it too. Similarly for withError

Copy link
Contributor

github-actions bot commented Nov 15, 2024

Kover Report

File Coverage [50.19%]
arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/Atomic.kt 85.71%
arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicBoolean.kt 95.24%
arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicInt.kt 85.71%
arrow-libs/core/arrow-atomic/src/commonMain/kotlin/arrow/atomic/AtomicLong.kt 85.71%
arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/NonEmptyList.kt 47.06%
arrow-libs/core/arrow-core-high-arity/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt 17.22%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Either.kt 62.75%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Ior.kt 80.00%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/NonEmptyList.kt 47.06%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/Option.kt 84.75%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Builders.kt 69.84%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/ErrorHandlers.kt 100.00%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Raise.kt 95.24%
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/RaiseAccumulate.kt 17.22%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Bracket.kt 88.89%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZip.kt 88.24%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/ParZipOrAccumulate.kt 0.00%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race2.kt 77.78%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Race3.kt 82.50%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/Resource.kt 79.59%
arrow-libs/fx/arrow-fx-coroutines/src/commonMain/kotlin/arrow/fx/coroutines/await/AwaitAllScope.kt 0.00%
arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/STM.kt 81.93%
arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/TVar.kt 73.08%
arrow-libs/fx/arrow-fx-stm/src/commonMain/kotlin/arrow/fx/stm/internal/Impl.kt 91.67%
arrow-libs/optics/arrow-optics-compose/src/commonMain/kotlin/arrow/optics/Copy.kt 100.00%
arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/CircuitBreaker.kt 87.63%
arrow-libs/resilience/arrow-resilience/src/commonMain/kotlin/arrow/resilience/Schedule.kt 68.59%
Total Project Coverage 45.03%

@serras
Copy link
Member

serras commented Nov 15, 2024

Thanks for your hard work! This is a boring task, but will definitely help our users.

Just one question: does the compiler accept all of these without any further complaints? I've learnt the hard way that if the compiler does not agree with the contract, it's better to leave it out.

@kyay10
Copy link
Collaborator Author

kyay10 commented Nov 15, 2024

Only a few are rejected, and it's because the compiler can't tell that e.g. all accumulating blocks surely must've run and thrown their errors by the end of accumulate. I provided sufficient explanation for when that happens. Also, some of the code can be changed to compile successfully. Where that was easily possible, I did it, but sometimes it needed more involved rewrites (for instance, mapOrAccumulate can technically be written in a way that the compiler would accept, but it would take so many recovers that the code would be awful).
Another place is parZipOrAccumulate and race where the compiler doesn't like that we're using async, but again as long as the asyncs are awaited or canceled within our code, we're fine to assert that all their code would've run if an exception wasn't thrown.
If any of the contracts that use suppression are dubious in your eyes, I'd be happy to remove them!

@kyay10 kyay10 requested a review from serras November 16, 2024 00:31
@serras serras self-requested a review November 22, 2024 10:19
@serras serras merged commit a203862 into main Nov 22, 2024
10 of 11 checks passed
@serras serras deleted the kyay10/contract-fixes branch November 22, 2024 10:19
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.

2 participants