From ea060dcf8aa0522d5667c59c875b06409d182351 Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Thu, 2 Dec 2021 17:31:55 +0100 Subject: [PATCH] [WASM] Implement lazy with UnsafeLazyImpl --- .../box/callableReference/property/kt15447.kt | 2 -- .../box/inference/builderInference/kt48445.kt | 1 - .../testData/codegen/box/inference/kt39824.kt | 2 -- .../constructorCallableReference.kt | 1 - .../codegen/box/ir/anonymousClassLeak.kt | 2 -- .../box/regressions/objectInsideDelegation.kt | 2 -- libraries/stdlib/wasm/src/kotlin/Kotlin.kt | 16 ++++++---------- 7 files changed, 6 insertions(+), 20 deletions(-) diff --git a/compiler/testData/codegen/box/callableReference/property/kt15447.kt b/compiler/testData/codegen/box/callableReference/property/kt15447.kt index 7679cea4fbc..e385f56babb 100644 --- a/compiler/testData/codegen/box/callableReference/property/kt15447.kt +++ b/compiler/testData/codegen/box/callableReference/property/kt15447.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_LAZY // WITH_STDLIB fun box(): String { diff --git a/compiler/testData/codegen/box/inference/builderInference/kt48445.kt b/compiler/testData/codegen/box/inference/builderInference/kt48445.kt index 6412a2be62c..6f2de7e3bc2 100644 --- a/compiler/testData/codegen/box/inference/builderInference/kt48445.kt +++ b/compiler/testData/codegen/box/inference/builderInference/kt48445.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: WASM // !LANGUAGE: +UnrestrictedBuilderInference // IGNORE_BACKEND_FIR: JVM_IR // FIR status: NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER on lazy call (Name3, T) diff --git a/compiler/testData/codegen/box/inference/kt39824.kt b/compiler/testData/codegen/box/inference/kt39824.kt index 023d98accfc..6b18789b309 100644 --- a/compiler/testData/codegen/box/inference/kt39824.kt +++ b/compiler/testData/codegen/box/inference/kt39824.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_LAZY // WITH_STDLIB fun diContext(context: C): DIContext = DIContext(TypeToken(), context) diff --git a/compiler/testData/codegen/box/inlineClasses/constructorCallableReference.kt b/compiler/testData/codegen/box/inlineClasses/constructorCallableReference.kt index f2d95371e5a..f0604540649 100644 --- a/compiler/testData/codegen/box/inlineClasses/constructorCallableReference.kt +++ b/compiler/testData/codegen/box/inlineClasses/constructorCallableReference.kt @@ -1,7 +1,6 @@ // WITH_STDLIB // KJS_FULL_RUNTIME // SKIP_MANGLE_VERIFICATION -// IGNORE_BACKEND: WASM interface I { companion object { diff --git a/compiler/testData/codegen/box/ir/anonymousClassLeak.kt b/compiler/testData/codegen/box/ir/anonymousClassLeak.kt index 90dcd09e34b..e17fcb1eae1 100644 --- a/compiler/testData/codegen/box/ir/anonymousClassLeak.kt +++ b/compiler/testData/codegen/box/ir/anonymousClassLeak.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_LAZY // WITH_STDLIB // MODULE: lib diff --git a/compiler/testData/codegen/box/regressions/objectInsideDelegation.kt b/compiler/testData/codegen/box/regressions/objectInsideDelegation.kt index 9993840d8f1..1a861736320 100644 --- a/compiler/testData/codegen/box/regressions/objectInsideDelegation.kt +++ b/compiler/testData/codegen/box/regressions/objectInsideDelegation.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: STDLIB_LAZY // WITH_STDLIB val b: First by lazy { diff --git a/libraries/stdlib/wasm/src/kotlin/Kotlin.kt b/libraries/stdlib/wasm/src/kotlin/Kotlin.kt index 8e810da01de..ae29e3993d0 100644 --- a/libraries/stdlib/wasm/src/kotlin/Kotlin.kt +++ b/libraries/stdlib/wasm/src/kotlin/Kotlin.kt @@ -25,10 +25,6 @@ public actual fun interface Comparator { public actual fun compare(a: T, b: T): Int } -// From kotlin.kt - - - // From numbers.kt actual fun Double.isNaN(): Boolean = this != this @@ -87,22 +83,22 @@ public actual fun Float.Companion.fromBits(bits: Int): Float = wasm_f32_reinterp //@Deprecated("Use Volatile annotation from kotlin.jvm package", ReplaceWith("kotlin.jvm.Volatile"), level = DeprecationLevel.WARNING) //public typealias Volatile = kotlin.jvm.Volatile - - - // from lazy.kt -public actual fun lazy(initializer: () -> T): Lazy = TODO("Wasm stdlib: Kotlin") +/** + * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. + */ +public actual fun lazy(initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. * * The [mode] parameter is ignored. */ -public actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = TODO("Wasm stdlib: Kotlin") +public actual fun lazy(mode: LazyThreadSafetyMode, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer) /** * Creates a new instance of the [Lazy] that uses the specified initialization function [initializer]. * * The [lock] parameter is ignored. */ -public actual fun lazy(lock: Any?, initializer: () -> T): Lazy = TODO("Wasm stdlib: Kotlin") +public actual fun lazy(lock: Any?, initializer: () -> T): Lazy = UnsafeLazyImpl(initializer)