arrow-kt / arrow-kt/arrow-proofs
Simplify `@ContextResolved` IR body generation
- Dominant language
- Kotlin
- Stars
- 10
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Is there any reason why in the IR plugin, the body of the @ContextResolved functions that it creates consists of a call to `arrow.inject.annotations.contextual(ev: T, f: T.() -> R)` for each proof, nested in a lambda recursively, then finally a call to the original function? At least that's what I'm understanding from the code.
I've tried this out myself previously, and the IR backend seems to not really care as to what expression you place as a context receiver argument. In fact, arbitrary function calls work just fine
Is this some future-proofing measure or something that I'm not seeing? Because it seems to be extra code that will need to be maintained down-the-road.
Btw, there's one case in the compiler where a context receiver argument is not just simply a reference to a context in scope, and that is [when an implicit receiver (which includes context receivers) has been smartcasted](https://github.com/JetBrains/kotlin/blob/master/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt#L122) and hence needs a smart-cast expression wrapped around it, So I'm guessing that's why the compiler allows arbitrary expressions there.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the IR plugin code that generates bodies for @ContextResolved functions and compare its nested arrow.inject.annotations.contextual calls with the original function invocation. Verify the behavior against the Kotlin compiler's context-receiver handling, including the smart-cast case linked in FirReceivers.kt; done means either simplifying the generated body with supporting tests or documenting why the wrappers are required.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- compilers
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100