`Pull`'s public api is unsound
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 2.5k
- Forks
- 636
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 7
Description
Because of Translate we may only G ~> F, not F ~> G. However GetScope and any operator that uses GetScope is subject to a soundness hole since:
Scopeis allocated in the initialF.Scopecannot havemapKsince it must be invariant inF(acquisition of child resources).
Here is an example that throws a class cast exception.
I have been looking at it for a while and I can't see any other road to a sound structure than to require F ~> G if any interaction with the open resources in necessary.
The good news is that either more stream programs can be expressed with F ~> G or at least the current semantics can be retained explicitly.
new FunctionK[F, G] {
def apply[A](fa: F[A]): G[A] = throw new ClassCastException("Oh no, couldn't go from F to G")
}
Assuming the api is used without throwing of exceptions, a bi-directional Translate allows Scope to be exposed (or at-least a subset of Scope's operators).
As of now, the only part of the api which is exposed and subject to this issue is lease. Fortunately lease doesn't invoke any other effects than ones in Scope, so any lossy F ~> G is completely fine, say EitherT[F, String, *] ~> F. Maybe a typeclass to represent non-structure preserving translations to make the G ~> F derivable for most cases?
Another direction could be to ensure that any Pull that is built on GetScope is non-translatable. Although this might require an extra type parameter to Pull and consequently Stream unfortunately.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the Pull API and the interactions among Translate, GetScope, lease, and Stream. Run the linked Scastie example to reproduce the ClassCastException, then trace the proposed translation directions and determine what API behavior or type constraints would make the resource interaction sound.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- api, stream-processing
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100