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

Migrating the Util.kt and KModifier from JVM to common #2006

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ForteScarlet
Copy link
Contributor

Part of #304, #1959

Migrating Util.kt and KModifier from JVM to common.

  • Non-JVM platform implementations have some questionable implementations (They mark the TODO).
  • There is a known issue (KT-71003) regarding the use of Kotlin Regex in WasmJS.
  • there are some functions that need to wait for other types of migration.

On the JVM, however, the effect is the same before and after migration.

Let me know if there's anything I need to do, thanks.
If these changes are not reviewed until after 2.0, you can always tell me, convert it to draft, or close it~

Comment on lines +18 to +25
internal actual fun <K, V> Map<K, V>.toImmutableMap(): Map<K, V> =
toMap()

internal actual fun <T> Collection<T>.toImmutableList(): List<T> =
toList()

internal actual fun <T> Collection<T>.toImmutableSet(): Set<T> =
toSet()
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're not going to put these in an unmodifiable wrapper on other targets, do we still need to do it on JVM? Are we really worried about Java callers mutating things? I don't think I am.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The original implementation was copied when we forked from JavaPoet, for what it's worth.

Copy link
Contributor Author

@ForteScarlet ForteScarlet Oct 15, 2024

Choose a reason for hiding this comment

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

Well, you have a point. If we no longer care about calls that mutate things on the JVM, do we keep toImmutable* in common and have its result just return a to* (like toSet), or do we simply remove them and use to* instead where appropriate?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it's defending against something that is not a real problem in practice, and I would eliminate the concept entirely and use Kotlin's collection APIs directly everywhere. This should probably be done in its own PR rather than cluttering this one.


internal actual fun Char.isJavaIdentifierPart(): Boolean {
// TODO
// A character may be part of a Java identifier if any of the following conditions are true:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we maybe extract these checks into common to have consistent implementations on all platforms?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can be done in later PRs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently, I am dividing them because I am unsure if the current implementation of non-JVM is the same as the one in JVM.
It would be wonderful to merge them if we can confirm that they have the same effects!

@Egorand
Copy link
Collaborator

Egorand commented Oct 24, 2024

@JakeWharton please merge if everything looks good to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants