Skip to content

Implement The Complete Bidirectional Class Mapping - #64

Merged
isomarcte merged 12 commits into
typelevel:mainfrom
isomarcte:complete-bidi-mapping
Jan 23, 2023
Merged

Implement The Complete Bidirectional Class Mapping#64
isomarcte merged 12 commits into
typelevel:mainfrom
isomarcte:complete-bidi-mapping

Conversation

@isomarcte

Copy link
Copy Markdown
Member

Originally, I had thought that this was covered in the code generated from "UnicodeData.txt", but after experimenting with it I realized that only a subset of code points have their bidirectional mappings present in that file.

This commit adds code generation using the Unicode character data files "PropertyValueAliases.txt" and "DerivedBidiClass.txt" to generate a complete mapping of the bidirectional mapping for each Unicode code point.

Originally, I had thought that this was covered in the code generated from "UnicodeData.txt", but after experimenting with it I realized that only a subset of code points have their bidirectional mappings present in that file.

This commit adds code generation using the Unicode character data files "PropertyValueAliases.txt" and "DerivedBidiClass.txt" to generate a complete mapping of the bidirectional mapping for each Unicode code point.
@isomarcte
isomarcte requested a review from armanbilge January 8, 2023 16:13
@isomarcte
isomarcte marked this pull request as draft January 8, 2023 16:17
Add headers, scalafix, scalafmt, and other linting for bidirectional class work.
@isomarcte

Copy link
Copy Markdown
Member Author

@armanbilge do you you have any context on this failure? I see some talk in other repos about the native linking taking a long time, but I didn't see anything about a failure like this.

I can reproduce locally on my Linux machine as well.

@armanbilge

Copy link
Copy Markdown
Member

Huh, no, this is new, never seen it. Looks like a legit bug, will take a closer look.

@isomarcte

isomarcte commented Jan 8, 2023

Copy link
Copy Markdown
Member Author

This is the assertion that is throwing, but I don't currently have enough context to know what is going on here.

https://github.com/scala-native/scala-native/blob/51b6b29cb8175194126208ae172d0b08f03cbc56/tools/src/main/scala/scala/scalanative/interflow/UseDef.scala#L89

@armanbilge

Copy link
Copy Markdown
Member

Ah great, thanks for tracking that down! Big help

@isomarcte

Copy link
Copy Markdown
Member Author

@armanbilge

Copy link
Copy Markdown
Member

@isomarcte thanks, I minimized and reported in scala-native/scala-native#3078.

It appears to be related to the size of the List.

@isomarcte

Copy link
Copy Markdown
Member Author

@armanbilge huh, that is odd. Thanks for figuring that out. I've pushed a workaround.

@isomarcte
isomarcte marked this pull request as ready for review January 8, 2023 19:35
Move the grouping code from UnicodeDataCodeGen to `package.scala` and re-use it in `DerivedBidiClassCodeGen.scala` to minimize the generated code size.
@isomarcte isomarcte mentioned this pull request Jan 9, 2023
Comment on lines +173 to +176
l.fold(acc)(value => acc + (value -> v)) match {
case acc =>
r.fold(acc)(value => acc + (value -> v))
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This was a bit of a weird use of match, i think just using a normal variable would be clearer.

Suggested change
l.fold(acc)(value => acc + (value -> v)) match {
case acc =>
r.fold(acc)(value => acc + (value -> v))
}
val leftR = l.fold(acc)(value => acc + (value -> v))
r.fold(leftR)(value => leftR + (value -> v))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I believe I've addressed the syntax complexity with my most recent commit. It changes the return type of difference to be a Option[Ior[CodePointRange, CodePointRange]], which in turn makes this function more simple to write.

Let me know what you think.

Comment thread project/src/main/scala/org/typelevel/idna4s/build/CodePointRange.scala Outdated
Comment thread project/src/main/scala/org/typelevel/idna4s/build/CodePointRange.scala Outdated

@armanbilge armanbilge left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looked through everything, but focused on generated code and tests.

isomarcte and others added 3 commits January 18, 2023 08:21
…eneratedBidirectionalClassTests.scala

Co-authored-by: Arman Bilge <armanbilge@gmail.com>
This commit simplifies the `resolveMissingMapping` function in the `project` directory used for code generation. It also changes the type of the method `difference` on the `CodePointRange` (also in `project`) from `(Option[CodePointRange], Option[CodePointRange])` to `Option[Ior[CodePointRange, CodePointRange]]`. The two are isomorphic, but the new type is easier to work with.

Also, due to a changes on `main` this commit updates a bunch of header files.
@isomarcte
isomarcte requested a review from zarthross January 23, 2023 15:35
@isomarcte

Copy link
Copy Markdown
Member Author

@zarthross let me know if you have any more feedback. I'll probably merge later today, unless I hear otherwise.

Use non-deprecated `Init.apply` overload. This was already updated on `main`, but this is a net new invocation for this branch.
@isomarcte
isomarcte merged commit 16f2274 into typelevel:main Jan 23, 2023
@isomarcte
isomarcte deleted the complete-bidi-mapping branch January 23, 2023 21:22
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