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 documentations #93

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions docs/compiler-basics.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# BackInTime Compiler Basics

In the brief, the back-in-time compiler performs two key tasks during the compile phase:

- Adds necessary methods and properties to classes to enable back-in-time debugging.
- Inserts state capture calls after properties of the class annotated with `@BackInTime` might
change.

Let's break down one by one.

## Phase1: Make a class back-in-time debuggable (FIR/IR)

The first thing that the compiler does is adding an interface `BackInTimeDebuggable` to your class.

```kotlin
interface BackInTimeDebuggable {
val backInTimeInstanceUUID: String
val backInTimeInitializedPropertyMap: MutableMap<String, Boolean>

fun forceSetValue(propertyName: String, value: Any?)
fun serializeValue(propertyName: String, value: Any?): String
fun deserializeValue(propertyName: String, value: String): Any?
}
```

`BackInTimeFirSupertypeGenerationExtension` will do this job:

```kotlin
@BackInTime
class A { ... }
@BackInTime
class A : BackInTimeDebuggable { ... }
```

Next, `BackInTimeFirDeclarationGenerationExtension` will add declarations which have to be
overridden:

```kotlin
@BackInTime
class A : BackInTimeDebuggable { ... }
@BackInTime
class A : BackInTimeDebuggable {
override val backInTimeInstanceUUID: String
override val backInTimeInitializedPropertyMap: MutableMap<String, Boolean>

override fun forceSetValue(propertyName: String, value: Any?)
override fun serializeValue(propertyName: String, value: Any?): String
override fun deserializeValue(propertyName: String, value: String): Any?
...
}
```

Lastly, inside `BackInTimeIrGenerationExtension`, `BackInTimeDebuggableImplementTransformer` will
add implementations of each methods and properties.

## Phase2: Track state changes and insert capture calls (IR)

The most complicated area in the back-in-time compiler is here.

- `BackInTimeDebuggableConstructorTransformer` adds instance registration call in the constructors. Also resolve the
relationships among back-in-time debuggable instances.
- `BackInTimeCaptureMethodInvocationTransformer` adds
-
Loading