Skip to content
This repository has been archived by the owner on Aug 10, 2021. It is now read-only.

Support unsigned types #1854

Merged
merged 2 commits into from
Aug 17, 2018
Merged

Support unsigned types #1854

merged 2 commits into from
Aug 17, 2018

Conversation

SvyatoslavScherbina
Copy link
Collaborator

@SvyatoslavScherbina SvyatoslavScherbina commented Aug 9, 2018

To be merged after #1840 and updating to 1.3.
Migrating C interop to unsigned types is to be added later as a separate PR.

@@ -1091,11 +1104,15 @@ private fun objCFunctionType(context: Context, methodBridge: MethodBridge): LLVM

private val ObjCValueType.llvmType: LLVMTypeRef get() = when (this) {
ObjCValueType.BOOL -> int8Type
ObjCValueType.UNICHAR -> int16Type
Copy link
Contributor

@olonho olonho Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make it map/array indexed by ObjCValueType ordinal?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kotlin compiler appears to optimize when over enum entries.

@@ -237,6 +237,22 @@ external private fun copyImpl(array: IntArray, fromIndex: Int,
external private fun copyImpl(array: LongArray, fromIndex: Int,
destination: LongArray, toIndex: Int, count: Int)

@SymbolName("Kotlin_ByteArray_copyImpl")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add comment that operation is bitwise identical to signed types?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -279,6 +295,30 @@ fun LongArray.copyRangeTo(destination: LongArray, fromIndex: Int, toIndex: Int,
copyImpl(this, fromIndex, destination, destinationIndex, toIndex - fromIndex)
}

@SinceKotlin("1.3")
@ExperimentalUnsignedTypes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the point of this annotation?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is recommended to have one on any declaration that uses unsigned types. That's how Kotlin experimental features are organized.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it makes any sense for Native.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sure that it makes sense for Native.

public fun UByteArray.contentHashCode(): Int {
var result = 1
for (element in this)
result = 31 * result + element.hashCode()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why call element.hashCode() and not just element?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Kotlin doesn't have mixed signed-unsigned operations.
  2. All other variants of this function call hashCode, including one for ints.

@SvyatoslavScherbina SvyatoslavScherbina changed the base branch from inline-classes to 1.3-M2 August 17, 2018 10:46
@SvyatoslavScherbina SvyatoslavScherbina merged commit 7b46f93 into 1.3-M2 Aug 17, 2018
@SvyatoslavScherbina SvyatoslavScherbina deleted the unsigned-types branch August 17, 2018 14:48
vvlevchenko pushed a commit that referenced this pull request Aug 20, 2018
(cherry picked from commit 7b46f93)
vvlevchenko pushed a commit that referenced this pull request Aug 20, 2018
(cherry picked from commit 7b46f93)
vvlevchenko pushed a commit that referenced this pull request Aug 20, 2018
(cherry picked from commit 7b46f93)
vvlevchenko pushed a commit that referenced this pull request Aug 21, 2018
(cherry picked from commit 7b46f93)
vvlevchenko pushed a commit that referenced this pull request Aug 21, 2018
(cherry picked from commit 7b46f93)
vvlevchenko pushed a commit that referenced this pull request Aug 21, 2018
(cherry picked from commit 7b46f93)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants