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

AtomicInt minusAssign not found #414

Open
lppedd opened this issue Mar 25, 2024 · 2 comments
Open

AtomicInt minusAssign not found #414

lppedd opened this issue Mar 25, 2024 · 2 comments
Labels
compiler-plugin Issues related to the atomicfu-compiler-plugin

Comments

@lppedd
Copy link

lppedd commented Mar 25, 2024

With 0.23.2, If I use the following piece of code:

val position: AtomicInt = atomic(1)
position -= 1

compilation on the JVM fails with:

> Task :myproject:compileKotlinJvm FAILED
e: java.lang.IllegalStateException: No minusAssign function found in CLASS CLASS name:AtomicIntegerFieldUpdater modality:FINAL visibility:public superTypes:[]
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.common.AbstractAtomicSymbols.getAtomicHandlerFunctionSymbol(AbstractAtomicSymbols.kt:84)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.jvm.JvmAtomicfuIrBuilder.callFieldUpdater(JvmAtomicfuIrBuilder.kt:75)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.jvm.AtomicfuJvmIrTransformer$JvmAtomicFunctionCallTransformer.transformAtomicUpdateCallOnProperty(AtomicfuJvmIrTransformer.kt:164)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.common.AbstractAtomicfuTransformer$AtomicFunctionCallTransformer.visitCall(AbstractAtomicfuTransformer.kt:602)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.common.AbstractAtomicfuTransformer$AtomicFunctionCallTransformer.visitCall(AbstractAtomicfuTransformer.kt:550)
	at org.jetbrains.kotlin.ir.expressions.IrCall.accept(IrCall.kt:26)

And on JS with:

> Task :myproject:compileKotlinJs FAILED
e: java.lang.IllegalStateException: Exception while looking for the function `atomicfu_minusAssign` in package `kotlinx.atomicfu`: Collection contains no element matching the predicate.
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.js.TransformerUtilKt.referencePackageFunction(TransformerUtil.kt:268)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.js.AtomicfuJsIrTransformer$AtomicTransformer.getRuntimeFunctionSymbol(AtomicfuJsIrTransformer.kt:414)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.js.AtomicfuJsIrTransformer$AtomicTransformer.inlineAtomicFunction(AtomicfuJsIrTransformer.kt:330)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.js.AtomicfuJsIrTransformer$AtomicTransformer.visitCall(AtomicfuJsIrTransformer.kt:180)
	at org.jetbrains.kotlinx.atomicfu.compiler.backend.js.AtomicfuJsIrTransformer$AtomicTransformer.visitCall(AtomicfuJsIrTransformer.kt:104)
	at org.jetbrains.kotlin.ir.expressions.IrCall.accept(IrCall.kt:26)

Note that I have:

# AtomicFU transformation via compiler plugin
kotlinx.atomicfu.enableJsIrTransformation = true
kotlinx.atomicfu.enableJvmIrTransformation = true
kotlinx.atomicfu.enableNativeIrTransformations = true
@mvicsokolova
Copy link
Collaborator

Hi!
kotlinx-atomicfu does not support minusAssign operator for atomics. Please use decrementAndGet() function instead:

val position: AtomicInt = atomic(1)
// ...
val newValue = position.decrementAndGet()

@lppedd
Copy link
Author

lppedd commented Mar 25, 2024

Thanks @mvicsokolova. I ended up using the underlying getAndAdd function.
I did use minusAssign and plusAssign, as they're part of the AtomicInt API.

image

Maybe removing them would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler-plugin Issues related to the atomicfu-compiler-plugin
Projects
None yet
Development

No branches or pull requests

2 participants