Skip to content

Automatically opt-in all experimental annotations for types publicly exposed by a benchmark class #301

Open
@dkhalanskyjb

Description

@dkhalanskyjb

I've used https://github.com/fzhinkin/benchmarks-template.

@State(Scope.Benchmark)
open class ExampleBenchmark {
    @Benchmark
    fun parse() =
        @OptIn(ExperimentalTime::class) Instant.parse("2023-10-01T16:12:42.546124Z")

    @Benchmark
    fun parseNoFrac() =
        @OptIn(ExperimentalTime::class) Instant.parse("2023-10-01T16:12:42Z")
}

then fails to compile with

> Task :compileJsBenchmarkKotlinJs FAILED
e: file:///home/jb/IdeaProjects/benchmark-Instant-parse/build/benchmarks/js/sources/kotlinx/benchmark/generated/org/example/ExampleBenchmark_Descriptor.kt:30:52 This declaration needs opt-in. Its usage must be marked with '@kotlin.time.ExperimentalTime' or '@OptIn(kotlin.time.ExperimentalTime::class)'
e: file:///home/jb/IdeaProjects/benchmark-Instant-parse/build/benchmarks/js/sources/kotlinx/benchmark/generated/org/example/ExampleBenchmark_Descriptor.kt:32:52 This declaration needs opt-in. Its usage must be marked with '@kotlin.time.ExperimentalTime' or '@OptIn(kotlin.time.ExperimentalTime::class)'

Moving OptIn somewhere outside also causes the compilation failure. The one way I've found to write this benchmark is to use block bodies for these functions:

    @Benchmark
    fun parse() {
        @OptIn(ExperimentalTime::class) Instant.parse("2023-10-01T16:12:42.546124Z")
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions