-
Notifications
You must be signed in to change notification settings - Fork 448
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
Tracing POC #2946
Tracing POC #2946
Conversation
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt
Outdated
Show resolved
Hide resolved
Is there a reason to distinguish between Also, is there a reason as to why |
Thanks for your review and feedback @kyay10 🙏
Okay, so this was an attempt to hide
The reason for I would've really liked to sanitise the trace, but I'm not sure if there is a decent way to do this for Native / JS. We could do it on minimum-effort for JVM only, it seems that is also what KotlinX Coroutines is doing. I've played around with the changes, and made a commit applying your suggestions @kyay10. WDYT? To my surprise |
LGTM, perhaps just fix the (very minor) typo I commented above. Should there also be changes to all the comprehension blocks (is that what we still call them btw?) to add a |
Oh yes, missed that in the PR 👍
This shouldn't be necessary you can use |
@kyay10 actually I think this change is impossible without having two types 🤔 Since |
@nomisRev Ah that's peculiar! Could |
It's standard behavior for the JVM. Initialisation order of https://stackoverflow.com/questions/32490714/order-of-initialization-instantiation-of-class-variables-of-derived-class-and-in.
I think it's fine, especially in a library like Arrow. Optimise for the user facing API > optimise for less code in library. |
Maybe Trace could be made a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me :)
this is RaiseCancellationExceptionNoTrace && this.raise === raise -> raised as R | ||
this is RaiseCancellationException && this.raise === raise -> raised as R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is RaiseCancellationExceptionNoTrace && this.raise === raise -> raised as R | |
this is RaiseCancellationException && this.raise === raise -> raised as R | |
this.raise === raise && (this is RaiseCancellationExceptionNoTrace || this is RaiseCancellationException) -> raised as R |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change introduces a compilation error because raise
and raised
properties don't exist in CancellationException
. Those properties belong to RaiseCancellationExceptionNoTrace
and RaiseCancellationException
, so we need the smart cast here.
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Fold.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️
Co-authored-by: Alejandro Serrano <trupill@gmail.com>
Thanks for the great suggestions and review @serras 🙏 |
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Trace.kt
Outdated
Show resolved
Hide resolved
…ise/Trace.kt Co-authored-by: Youssef Shoaib <canonballt@gmail.com>
Thanks for fixing the build @franciscodr |
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Trace.kt
Outdated
Show resolved
Hide resolved
arrow-libs/core/arrow-core/src/commonMain/kotlin/arrow/core/raise/Trace.kt
Outdated
Show resolved
Hide resolved
public static final synthetic fun box-impl (Ljava/util/concurrent/CancellationException;)Larrow/core/raise/Trace; | ||
public static fun constructor-impl (Ljava/util/concurrent/CancellationException;)Ljava/util/concurrent/CancellationException; | ||
public fun equals (Ljava/lang/Object;)Z | ||
public static fun equals-impl (Ljava/util/concurrent/CancellationException;Ljava/lang/Object;)Z | ||
public static final fun equals-impl0 (Ljava/util/concurrent/CancellationException;Ljava/util/concurrent/CancellationException;)Z | ||
public fun hashCode ()I | ||
public static fun hashCode-impl (Ljava/util/concurrent/CancellationException;)I | ||
public static final fun printStackTrace-impl (Ljava/util/concurrent/CancellationException;)V | ||
public static final fun stackTraceToString-impl (Ljava/util/concurrent/CancellationException;)Ljava/lang/String; | ||
public static final fun suppressedExceptions-impl (Ljava/util/concurrent/CancellationException;)Ljava/util/List; | ||
public fun toString ()Ljava/lang/String; | ||
public static fun toString-impl (Ljava/util/concurrent/CancellationException;)Ljava/lang/String; | ||
public final synthetic fun unbox-impl ()Ljava/util/concurrent/CancellationException; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, binary says BOOM due to value class
🤯 Never realised this before
…ise/Trace.kt Co-authored-by: Youssef Shoaib <canonballt@gmail.com>
Discussing some ideas for new features with @raulraja he mentioned tracing for
Effect
, so I was playing around with some ideas and come up with a small POC.Since
raise
already relies onCancellationException
to co-operate with the coroutine system we currently pay a performance penalty forraise
and the stack trace creation that comes withCancellationException
by default. This penalty is not needed, and is stack trace creation is by default also disabled in KotlinX Coroutines.This PR solves the issue of debugging/tracing, and the performance penalty we currently pay for raise.
We can now disable the stack trace creation, and we can ad-hoc enable it for any
Effect
you compose traced upon or anyRaise
program you run within atraced
block.Notes
Since the
Effect
runtime is shared amongst DSL such aseither
,result
,option
,ior
, etc thetraced
operator can be added, or used for all these DSLs, and types. Including any of the DSL methods that result in shifting such asensure
,ensureNotNull
,bind
, etc.Currently only JVM is disabling stack-trace generation. Not sure if we also need to disable it for JS, or Native. (KotlinX Coroutines only disables it for JVM)
What API would we want on
Traced<R>
? Currently we include mentions toShiftCancellationException
and the dynamic call toDefaultShift#shift
which is not part of the user stack trace. Should we slightly change the API such that this is improved?