Skip to content

Commit

Permalink
Merge pull request #993 from square/zachklipp/upgrade-kotlin
Browse files Browse the repository at this point in the history
Upgrade Kotlin to 1.3.70 and fix related build errors.
  • Loading branch information
zach-klippenstein authored Mar 3, 2020
2 parents fa6c127 + bf642fc commit 485af5a
Show file tree
Hide file tree
Showing 37 changed files with 86 additions and 84 deletions.
9 changes: 5 additions & 4 deletions kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ buildscript {
ext.versions = [
'targetSdk': 29,
'compose': '0.1.0-dev05',
'kotlin': '1.3.70',
]

rootProject.ext.defaultAndroidConfig = {
Expand Down Expand Up @@ -83,7 +84,7 @@ buildscript {

'kotlin': [
'binaryCompatibilityValidatorPlugin': "org.jetbrains.kotlinx:binary-compatibility-validator:0.2.1",
'gradlePlugin': "org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61",
'gradlePlugin': "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}",
'stdLib': [
'common': "org.jetbrains.kotlin:kotlin-stdlib-common",
'jdk8': "org.jetbrains.kotlin:kotlin-stdlib-jdk8",
Expand All @@ -97,10 +98,10 @@ buildscript {
'test': "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.3.3"
],
'moshi': "com.squareup.moshi:moshi-kotlin:1.9.2",
'reflect': "org.jetbrains.kotlin:kotlin-reflect:1.3.61",
'reflect': "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}",
'serialization': [
'gradlePlugin': "org.jetbrains.kotlin:kotlin-serialization:1.3.61",
'runtime': "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0",
'gradlePlugin': "org.jetbrains.kotlin:kotlin-serialization:${versions.kotlin}",
'runtime': "org.jetbrains.kotlinx:kotlinx-serialization-runtime:0.14.0-1.3.70-eap-134",
'kaml': "com.charleskorn.kaml:kaml:0.15.0",
],
'test': [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import kotlin.time.ExperimentalTime
/**
* Service class that creates [Worker]s to [load][loadBoard] [Board]s.
*/
@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class BoardLoader(
private val ioDispatcher: CoroutineDispatcher,
private val assets: AssetManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.squareup.workflow.ui.modal.AlertContainer
import kotlinx.coroutines.Dispatchers
import kotlin.random.Random
import kotlin.time.ExperimentalTime
import kotlin.time.MonoClock
import kotlin.time.TimeSource.Monotonic

private const val AI_COUNT = 4

Expand All @@ -46,8 +46,8 @@ class Component(context: Context) {

val random = Random(System.currentTimeMillis())

@UseExperimental(ExperimentalTime::class)
val clock = MonoClock
@OptIn(ExperimentalTime::class)
val clock = Monotonic

val vibrator = context.getSystemService(VIBRATOR_SERVICE) as Vibrator

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ interface DungeonApplication {
* Retrieves the loading delay from the application if it is a [DungeonApplication], or else a
* default.
*/
@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
suspend fun Context.delayForFakeLoad() =
(applicationContext as? DungeonApplication)?.delayForFakeLoad()
?: delay(1.seconds.toLongMilliseconds())
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ import com.squareup.sample.timemachine.shakeable.ShakeableTimeMachineWorkflow.Pr
import com.squareup.workflow.RenderContext
import com.squareup.workflow.StatelessWorkflow
import com.squareup.workflow.renderChild
import kotlin.time.Clock
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource

/**
* A workflow that wraps [DungeonAppWorkflow] with a [ShakeableTimeMachineWorkflow] to enable
* time travel debugging.
*/
@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class TimeMachineAppWorkflow(
appWorkflow: DungeonAppWorkflow,
clock: Clock,
clock: TimeSource,
context: Context
) : StatelessWorkflow<BoardPath, Nothing, ShakeableTimeMachineRendering>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private fun <T : Enum<T>> Random.nextEnum(enumClass: KClass<T>): T {
/**
* Scales the tick frequency by a random amount to make direction changes look more arbitrary.
*/
@UseExperimental(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
private fun Worker<Long>.createDirectionTicker(random: Random): Worker<Unit> =
transform { flow ->
flow.transform { tick ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import kotlinx.coroutines.flow.flowOf
*
* adb shell am broadcast -a com.squareup.sample.timemachine.SHAKE
*/
@UseExperimental(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
class ShakeWorker(private val context: Context) : Worker<Unit> {

private val sensorManager = context.getSystemService(SENSOR_SERVICE) as SensorManager
Expand All @@ -63,7 +63,7 @@ class ShakeWorker(private val context: Context) : Worker<Unit> {
awaitClose { context.unregisterReceiver(receiver) }
}

@UseExperimental(FlowPreview::class)
@OptIn(FlowPreview::class)
override fun run(): Flow<Unit> = flowOf(realShakes, fakeShakes).flattenMerge()

override fun doesSameWorkAs(otherWorker: Worker<*>): Boolean = otherWorker is ShakeWorker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import kotlin.time.milliseconds
* Renders [ShakeableTimeMachineWorkflow][ShakeableTimeMachineWorkflow]
* [renderings][ShakeableTimeMachineRendering].
*/
@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class ShakeableTimeMachineLayoutRunner(
private val view: View
) : LayoutRunner<ShakeableTimeMachineRendering> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import com.squareup.sample.timemachine.RecorderWorkflow.Recording
import com.squareup.workflow.RenderContext
import com.squareup.workflow.Snapshot
import com.squareup.workflow.StatefulWorkflow
import kotlin.time.Clock
import kotlin.time.ClockMark
import kotlin.time.TimeMark
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource

/**
* A workflow that will either record values or play them back, depending on the mode selected by
Expand All @@ -39,7 +39,7 @@ import kotlin.time.ExperimentalTime
*/
@ExperimentalTime
internal class RecorderWorkflow<T>(
private val clock: Clock
private val clock: TimeSource
) : StatefulWorkflow<RecorderProps<T>, Recording<T>, Nothing, TimeMachineRendering<T>>() {

/**
Expand All @@ -59,7 +59,7 @@ internal class RecorderWorkflow<T>(
}

data class Recording<out T>(
val startTime: ClockMark,
val startTime: TimeMark,
val series: TimeSeries<T>
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import com.squareup.workflow.StatelessWorkflow
import com.squareup.workflow.Workflow
import com.squareup.workflow.action
import com.squareup.workflow.renderChild
import kotlin.time.Clock
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource

/**
* A workflow that will continuously render [delegateWorkflow] and either record its renderings, or
Expand All @@ -43,7 +43,7 @@ import kotlin.time.ExperimentalTime
@ExperimentalTime
class TimeMachineWorkflow<P, O : Any, out R>(
private val delegateWorkflow: Workflow<P, O, R>,
clock: Clock
clock: TimeSource
) : StatelessWorkflow<TimeMachineProps<P>, O, TimeMachineRendering<R>>() {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import kotlin.time.ExperimentalTime
* An immutable, [append]-only list of values that are each associated with increasing timestamps.
*
* Timestamps are represented as [Duration]s, relative to some starting point (usually a
* [ClockMark][kotlin.time.ClockMark], probably from [Clock.markNow][kotlin.time.Clock.markNow]).
* [TimeMark][kotlin.time.TimeMark], probably from [Clock.markNow][kotlin.time.Clock.markNow]).
*
* The timestamp of the last value is exposed as [duration].
* To get the values without their timestamps, use the [values] sequence.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ import com.squareup.sample.timemachine.RecorderWorkflow.Recording
import com.squareup.workflow.testing.renderTester
import org.junit.Test
import kotlin.time.ExperimentalTime
import kotlin.time.TestClock
import kotlin.time.TestTimeSource
import kotlin.time.milliseconds

@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class RecorderWorkflowTest {

@Test fun `onPropsChanged records value when recording`() {
val clock = TestClock()
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()
clock += 42.milliseconds
Expand All @@ -48,7 +48,7 @@ class RecorderWorkflowTest {
}

@Test fun `onPropsChanged doesn't record value when not recording`() {
val clock = TestClock()
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()
clock += 42.milliseconds
Expand All @@ -67,7 +67,7 @@ class RecorderWorkflowTest {
}

@Test fun `render returns recorded value when recording`() {
val clock = TestClock()
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()

Expand All @@ -85,7 +85,7 @@ class RecorderWorkflowTest {
}

@Test fun `render returns recorded value when playing back`() {
val clock = TestClock()
val clock = TestTimeSource()
val workflow = RecorderWorkflow<String>(clock)
val startTime = clock.markNow()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import com.squareup.workflow.testing.testFromStart
import org.junit.Test
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TestClock
import kotlin.time.TestTimeSource
import kotlin.time.seconds

@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class TimeMachineWorkflowTest {

@Test fun `records and plays back`() {
Expand All @@ -46,7 +46,7 @@ class TimeMachineWorkflowTest {
DelegateRendering(state, setState = { sink.send(it) })
}
)
val clock = TestClock()
val clock = TestTimeSource()
val tmWorkflow = TimeMachineWorkflow(delegateWorkflow, clock)

tmWorkflow.testFromStart(Recording(Unit) as TimeMachineProps<Unit>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import kotlin.time.ExperimentalTime
import kotlin.time.days
import kotlin.time.milliseconds

@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class TimeSeriesTest {

private val series = TimeSeries<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ data class KeyStroke(
}

@Suppress("BlockingMethodInNonBlockingContext")
@UseExperimental(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
internal fun InputProvider.listenForKeyStrokesOn(
scope: CoroutineScope
): BroadcastChannel<KeyStroke> = scope.broadcast {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ data class TerminalSize(
val columns: Int
)

@UseExperimental(ExperimentalCoroutinesApi::class)
@OptIn(ExperimentalCoroutinesApi::class)
internal fun Terminal.listenForResizesOn(
scope: CoroutineScope
): ReceiveChannel<TerminalSize> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class TerminalWorkflowRunner(
/**
* Runs [workflow] until it emits an [ExitCode] and then returns it.
*/
@UseExperimental(
@OptIn(
FlowPreview::class,
ExperimentalCoroutinesApi::class,
ObsoleteCoroutinesApi::class
Expand Down Expand Up @@ -94,7 +94,7 @@ class TerminalWorkflowRunner(
}

@Suppress("BlockingMethodInNonBlockingContext")
@UseExperimental(FlowPreview::class, ExperimentalCoroutinesApi::class)
@OptIn(FlowPreview::class, ExperimentalCoroutinesApi::class)
private suspend fun runTerminalWorkflow(
workflow: TerminalWorkflow,
screen: TerminalScreen,
Expand Down
4 changes: 2 additions & 2 deletions kotlin/trace-encoder/api/trace-encoder.api
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public final class com/squareup/tracing/TraceEncoder : java/io/Closeable {
public fun <init> (Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/ClockMark;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/ClockMark;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/TimeMark;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function0;)V
public synthetic fun <init> (Lkotlinx/coroutines/CoroutineScope;Lkotlin/time/TimeMark;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function0;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun close ()V
public final fun createLogger (Ljava/lang/String;Ljava/lang/String;)Lcom/squareup/tracing/TraceLogger;
public static synthetic fun createLogger$default (Lcom/squareup/tracing/TraceEncoder;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Lcom/squareup/tracing/TraceLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ import kotlinx.coroutines.channels.consumeEach
import okio.BufferedSink
import java.io.Closeable
import java.util.concurrent.atomic.AtomicInteger
import kotlin.time.ClockMark
import kotlin.time.ExperimentalTime
import kotlin.time.MonoClock
import kotlin.time.TimeMark
import kotlin.time.TimeSource

/**
* Encodes and writes [trace events][TraceEvent] to an Okio [BufferedSink].
*
* @param scope The [CoroutineScope] that defines the lifetime for the encoder. When the scope is
* cancelled or fails, the sink returned from [sinkProvider] will be closed.
* @param start The [ClockMark] to consider the beginning timestamp of the trace. All trace events'
* timestamps are relative to this mark. [MonoClock].[markNow][MonoClock.markNow] by default.
* @param start The [TimeMark] to consider the beginning timestamp of the trace. All trace events'
* timestamps are relative to this mark.
* [TimeSource.Monotonic].[markNow][TimeSource.Monotonic.markNow] by default.
* @param ioDispatcher The [CoroutineDispatcher] to use to execute all IO operations.
* [IO] by default.
* @param sinkProvider Returns the [BufferedSink] to use to write trace events to. Called on a
* background thread.
*/
@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class TraceEncoder(
scope: CoroutineScope,
private val start: ClockMark = MonoClock.markNow(),
private val start: TimeMark = TimeSource.Monotonic.markNow(),
ioDispatcher: CoroutineDispatcher = IO,
private val sinkProvider: () -> BufferedSink
) : Closeable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,18 @@ import kotlinx.coroutines.runBlocking
import okio.Buffer
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.time.ClockMark
import kotlin.time.TimeMark
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.microseconds

@UseExperimental(ExperimentalTime::class)
@OptIn(ExperimentalTime::class)
class TraceEncoderTest {

/**
* [ClockMark] that always returns [now] as [elapsedNow].
* [TimeMark] that always returns [now] as [elapsedNow].
*/
private class FakeClockMark : ClockMark() {
private class FakeTimeMark : TimeMark() {
var now: Duration = 0.microseconds
override fun elapsedNow(): Duration = now
}
Expand All @@ -45,14 +45,14 @@ class TraceEncoderTest {

val buffer = Buffer()
runBlocking {
val fakeClockMark = FakeClockMark()
val encoder = TraceEncoder(this, start = fakeClockMark) { buffer }
val fakeTimeMark = FakeTimeMark()
val encoder = TraceEncoder(this, start = fakeTimeMark) { buffer }
val logger = encoder.createLogger("process", "thread")

fakeClockMark.now = 1.microseconds
fakeTimeMark.now = 1.microseconds
logger.log(firstBatch)

fakeClockMark.now = 2.microseconds
fakeTimeMark.now = 2.microseconds
logger.log(secondBatch)

encoder.close()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.squareup.workflow

import kotlin.Experimental.Level.ERROR
import kotlin.RequiresOptIn.Level.ERROR
import kotlin.annotation.AnnotationRetention.BINARY

/**
Expand All @@ -25,5 +25,5 @@ import kotlin.annotation.AnnotationRetention.BINARY
*/
@MustBeDocumented
@Retention(value = BINARY)
@Experimental(level = ERROR)
@RequiresOptIn(level = ERROR)
annotation class VeryExperimentalWorkflow
Loading

0 comments on commit 485af5a

Please sign in to comment.