This is an automated email from the ASF dual-hosted git repository.
chaokunyang pushed a commit to branch releases-0.11
in repository https://gitbox.apache.org/repos/asf/fury.git
The following commit(s) were added to refs/heads/releases-0.11 by this push:
new f8c1ac4e fix(kotlin): Fix compilation and logical errors for version
0.11 (#2177)
f8c1ac4e is described below
commit f8c1ac4ecbeed868ee7d70dab96624ba9d58a6ec
Author: PAN <[email protected]>
AuthorDate: Thu Apr 24 14:35:54 2025 +0800
fix(kotlin): Fix compilation and logical errors for version 0.11 (#2177)
<!--
**Thanks for contributing to Fury.**
**If this is your first time opening a PR on fury, you can refer to
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).**
Contribution Checklist
- The **Apache Fury (incubating)** community has restrictions on the
naming of pr titles. You can also find instructions in
[CONTRIBUTING.md](https://github.com/apache/fury/blob/main/CONTRIBUTING.md).
- Fury has a strong focus on performance. If the PR you submit will have
an impact on performance, please benchmark it first and provide the
benchmark result here.
-->
## What does this PR do?
<!-- Describe the purpose of this PR. -->
## Related issues
<!--
Is there any related issue? Please attach here.
- #xxxx0
- #xxxx1
- #xxxx2
-->
## Does this PR introduce any user-facing change?
<!--
If any user-facing interface changes, please [open an
issue](https://github.com/apache/fury/issues/new/choose) describing the
need to do so and update the document if necessary.
-->
- [ ] Does this PR introduce any public API change?
- [ ] Does this PR introduce any binary protocol compatibility change?
## Benchmark
<!--
When the PR has an impact on performance (if you don't know whether the
PR will have an impact on performance, you can submit the PR first, and
if it will have impact on performance, the code reviewer will explain
it), be sure to attach a benchmark data here.
-->
---------
Co-authored-by: Shawn Yang <[email protected]>
---
.../fury/builder/BaseObjectCodecBuilder.java | 1 +
.../java/org/apache/fury/codegen/Expression.java | 23 +++++++++++++++++++---
.../org/apache/fury/codegen/ExpressionUtils.java | 10 +++++++++-
.../org/apache/fury/codegen/ExpressionTest.java | 16 +++++++++++++++
.../serializer/collection/MapSerializersTest.java | 18 +++++++++++++++++
.../serializer/kotlin/UnsignedArraySerializers.kt | 5 -----
.../fury/serializer/kotlin/UnsignedSerializer.kt | 5 -----
7 files changed, 64 insertions(+), 14 deletions(-)
diff --git
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
index 744ac711..aae2f236 100644
---
a/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
+++
b/java/fury-core/src/main/java/org/apache/fury/builder/BaseObjectCodecBuilder.java
@@ -1799,6 +1799,7 @@ public abstract class BaseObjectCodecBuilder extends
CodecBuilder {
new Assign(
chunkHeader, cast(bitand(sizeAndHeader, ofInt(0xff)),
PRIMITIVE_INT_TYPE)),
new Assign(size, cast(shift(">>>", sizeAndHeader, 8),
PRIMITIVE_INT_TYPE)));
+ exprs.add(new If(eq(size, ofInt(0)), new Break()));
Expression sizeAndHeader2 =
readChunk(buffer, newMap, size, keyType, valueType,
chunkHeader);
if (inline) {
diff --git
a/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java
b/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java
index 221f9365..059bd048 100644
--- a/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java
+++ b/java/fury-core/src/main/java/org/apache/fury/codegen/Expression.java
@@ -247,6 +247,21 @@ public interface Expression {
return expressions;
}
+ public Expression last() {
+ return expressions.get(expressions.size() - 1);
+ }
+
+ public ListExpression add(Expression expr, boolean copy) {
+ Preconditions.checkNotNull(expr);
+ if (copy) {
+ ListExpression listExpression = new ListExpression();
+ listExpression.addAll(expressions);
+ listExpression.add(expr);
+ return listExpression;
+ }
+ return add(expr);
+ }
+
public ListExpression add(Expression expr) {
Preconditions.checkNotNull(expr);
this.expressions.add(expr);
@@ -1685,7 +1700,9 @@ public interface Expression {
this.predicate = predicate;
this.trueExpr = trueExpr;
this.falseExpr = falseExpr;
-
+ if (ExpressionUtils.isReturn(trueExpr) &&
ExpressionUtils.isReturn(falseExpr)) {
+ type = PRIMITIVE_VOID_TYPE;
+ }
if (trueExpr.type() == falseExpr.type()) {
if (trueExpr.type() != null &&
!PRIMITIVE_VOID_TYPE.equals(trueExpr.type())) {
type = trueExpr.type();
@@ -1746,7 +1763,7 @@ public interface Expression {
}
TypeRef<?> type = this.type;
if (!PRIMITIVE_VOID_TYPE.equals(type.unwrap())) {
- if (trueExpr instanceof Return && falseExpr instanceof Return) {
+ if (ExpressionUtils.isReturn(trueExpr) &&
ExpressionUtils.isReturn(falseExpr)) {
type = PRIMITIVE_VOID_TYPE;
}
}
@@ -2651,7 +2668,7 @@ public interface Expression {
codeBuilder.append(targetExprCode.code()).append('\n');
}
codeBuilder.append("return ").append(targetExprCode.value()).append(';');
- return new ExprCode(codeBuilder.toString(), null, null);
+ return new ExprCode(codeBuilder.toString(), null,
targetExprCode.value());
}
@Override
diff --git
a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java
b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java
index 64f488aa..f3296d17 100644
--- a/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java
+++ b/java/fury-core/src/main/java/org/apache/fury/codegen/ExpressionUtils.java
@@ -44,6 +44,7 @@ import org.apache.fury.codegen.Expression.ListExpression;
import org.apache.fury.codegen.Expression.LogicalAnd;
import org.apache.fury.codegen.Expression.LogicalOr;
import org.apache.fury.codegen.Expression.Null;
+import org.apache.fury.codegen.Expression.Return;
import org.apache.fury.codegen.Expression.Variable;
import org.apache.fury.reflect.ReflectionUtils;
import org.apache.fury.reflect.TypeRef;
@@ -61,6 +62,13 @@ public class ExpressionUtils {
return new NewArray(TypeRef.of(Object[].class), expressions);
}
+ public static boolean isReturn(Expression expr) {
+ if (expr instanceof ListExpression) {
+ expr = ((ListExpression) expr).last();
+ }
+ return expr instanceof Return;
+ }
+
public static Expression ofInt(String name, int v) {
return new Variable(name, Literal.ofInt(v));
}
@@ -98,7 +106,7 @@ public class ExpressionUtils {
public static LogicalOr or(Expression left, Expression right, Expression...
expressions) {
LogicalOr logicalOr = new LogicalOr(left, right);
for (Expression expression : expressions) {
- logicalOr = new LogicalOr(left, expression);
+ logicalOr = new LogicalOr(logicalOr, expression);
}
return logicalOr;
}
diff --git
a/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionTest.java
b/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionTest.java
index 15546e8d..1c6e3133 100644
--- a/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionTest.java
+++ b/java/fury-core/src/test/java/org/apache/fury/codegen/ExpressionTest.java
@@ -19,11 +19,15 @@
package org.apache.fury.codegen;
+import static org.apache.fury.codegen.ExpressionUtils.neq;
+import static org.apache.fury.codegen.ExpressionUtils.or;
import static org.apache.fury.type.TypeUtils.PRIMITIVE_SHORT_TYPE;
import static org.testng.Assert.assertNull;
+import org.apache.fury.codegen.Code.ExprCode;
import org.apache.fury.codegen.Expression.ListExpression;
import org.apache.fury.codegen.Expression.Literal;
+import org.apache.fury.codegen.Expression.LogicalOr;
import org.apache.fury.codegen.Expression.Reference;
import org.apache.fury.codegen.Expression.Return;
import org.testng.Assert;
@@ -78,4 +82,16 @@ public class ExpressionTest {
assertNull(code);
}
}
+
+ @Test
+ public void testMultipleOr() {
+ CodegenContext ctx = new CodegenContext();
+ LogicalOr or =
+ or(
+ Literal.ofBoolean(false),
+ neq(Literal.ofInt(3), Literal.ofInt(4)),
+ neq(Literal.ofInt(5), Literal.ofInt(6)));
+ ExprCode exprCode = or.genCode(ctx);
+ Assert.assertEquals(exprCode.value().code(), "((false || (3 != 4)) || (5
!= 6))");
+ }
}
diff --git
a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java
b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java
index f05de4e7..f0b94ddf 100644
---
a/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java
+++
b/java/fury-core/src/test/java/org/apache/fury/serializer/collection/MapSerializersTest.java
@@ -29,6 +29,7 @@ import com.google.common.collect.ImmutableMap;
import java.io.Serializable;
import java.util.AbstractMap;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
@@ -1004,4 +1005,21 @@ public class MapSerializersTest extends FuryTestBase {
Fury fury =
Fury.builder().requireClassRegistration(false).withCodegen(enableCodegen).build();
fury.deserialize(fury.serialize(obj));
}
+
+ @Data
+ public static class NestedStringLongListMap {
+ public Map<String, List<Long>> stringInt64ListMap;
+ }
+
+ @Test(dataProvider = "enableCodegen")
+ public void testNestedStringLongListMap(boolean enableCodegen) {
+ Fury fury =
Fury.builder().withLanguage(Language.JAVA).withCodegen(enableCodegen).build();
+ fury.register(NestedStringLongListMap.class);
+ NestedStringLongListMap pojo = new NestedStringLongListMap();
+ pojo.stringInt64ListMap = new HashMap<>();
+ pojo.stringInt64ListMap.put("a", Arrays.asList(100L, 200L, 300L));
+ pojo.stringInt64ListMap.put("b", null);
+ serDeCheck(fury, pojo);
+ fury.serialize(pojo);
+ }
}
diff --git
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt
index 5a4e55a4..374d0eea 100644
---
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt
+++
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedArraySerializers.kt
@@ -24,7 +24,6 @@ package org.apache.fury.serializer.kotlin
import org.apache.fury.Fury
import org.apache.fury.memory.MemoryBuffer
import org.apache.fury.serializer.Serializer
-import org.apache.fury.type.Type
public abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
fury: Fury,
@@ -39,10 +38,6 @@ public abstract class AbstractDelegatingArraySerializer<T,
T_Delegate>(
protected abstract fun fromDelegateClass(value: T_Delegate): T
- override fun getXtypeId(): Short {
- return (-Type.LIST.id).toShort()
- }
-
override fun xwrite(buffer: MemoryBuffer, value: T) {
write(buffer, value)
}
diff --git
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedSerializer.kt
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedSerializer.kt
index 2e0df5c2..e2492c2a 100644
---
a/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedSerializer.kt
+++
b/kotlin/src/main/kotlin/org/apache/fury/serializer/kotlin/UnsignedSerializer.kt
@@ -22,7 +22,6 @@ package org.apache.fury.serializer.kotlin
import org.apache.fury.Fury
import org.apache.fury.memory.MemoryBuffer
import org.apache.fury.serializer.Serializers
-import org.apache.fury.type.Type
/**
* UByteSerializer
@@ -35,7 +34,6 @@ public class UByteSerializer(
Serializers.CrossLanguageCompatibleSerializer<UByte>(
fury,
UByte::class.java,
- Type.UINT8.id,
fury.isBasicTypesRefIgnored,
true
) {
@@ -60,7 +58,6 @@ public class UShortSerializer(
Serializers.CrossLanguageCompatibleSerializer<UShort>(
fury,
UShort::class.java,
- Type.UINT16.id,
fury.isBasicTypesRefIgnored,
true
) {
@@ -84,7 +81,6 @@ public class UIntSerializer(
Serializers.CrossLanguageCompatibleSerializer<UInt>(
fury,
UInt::class.java,
- Type.UINT32.id,
fury.isBasicTypesRefIgnored,
true
) {
@@ -109,7 +105,6 @@ public class ULongSerializer(
Serializers.CrossLanguageCompatibleSerializer<ULong>(
fury,
ULong::class.java,
- Type.UINT64.id,
fury.isBasicTypesRefIgnored,
true
) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]