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

Use opaque types for Scala 3 #592

Merged
merged 4 commits into from
Oct 17, 2021
Merged

Use opaque types for Scala 3 #592

merged 4 commits into from
Oct 17, 2021

Conversation

armanbilge
Copy link
Member

@armanbilge armanbilge commented Oct 10, 2021

Closes #587. Note: basing against #588 for now.

@armanbilge armanbilge requested a review from sjrd October 10, 2021 01:52
@armanbilge armanbilge linked an issue Oct 10, 2021 that may be closed by this pull request
@armanbilge
Copy link
Member Author

@sjrd I've addressed your comments and created #594 to track the question about subtyping.

@armanbilge armanbilge requested a review from sjrd October 11, 2021 22:15
object IDBTransactionDurability {
@inline def default: IDBTransactionDurability = "default"
@inline def strict: IDBTransactionDurability = "strict"
@inline def relaxed: IDBTransactionDurability = "relaxed"
Copy link
Member

Choose a reason for hiding this comment

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

Is there any reason for some of the constants to be @inline defs instead of vals? It seems that it would be nicer if all of them were vals, doesn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, I'll take a pass through and clean these up.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah that's me, or if it wasn't me, that's something I do. My reasoning is that it reduces unnecessary bytecode. If they're vals they're always present in the output JS (so long as the object is instantiated), where as with defs unused fields can be omitted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, that's a good point. I think the advantage of vals is that they are stable and can be used for matching, but not sure how much use that is here. Happy to go either way.

Copy link
Member Author

Choose a reason for hiding this comment

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

Is there any way these get inlined e.g. if they are final val?

Copy link
Contributor

Choose a reason for hiding this comment

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

Btw: just noting that if a future release of Scala.js gets some kind of purity checking it will be able to remove unused vals from the output too. It wouldn't even need to be complex to detect cases like this. @sjrd: I'm might just ping to put it back on your radar :)

Copy link

Choose a reason for hiding this comment

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

If you used inline val you would also end up with no field in the bytecode.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good to know, can we still make this change binary-compatibly?

Copy link

Choose a reason for hiding this comment

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

I don't know well enough how binary-compatibility works in the Scala.js world so I can't say :).

Copy link
Member

Choose a reason for hiding this comment

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

I don't know well enough the behavior of inline val in terms of compilation scheme so I can't say :).

We'll have to try.

This was referenced Oct 13, 2021
@armanbilge armanbilge added this to the v2.0.0 milestone Oct 16, 2021
Base automatically changed from topic/great-migration to master October 17, 2021 08:23
@armanbilge armanbilge merged commit b613096 into master Oct 17, 2021
@armanbilge armanbilge deleted the topic/opaque-type branch October 17, 2021 08:24
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.

Use opaque type instead of sealed trait for Scala 3
4 participants