Skip to content

Conversation

sjrd
Copy link
Member

@sjrd sjrd commented Oct 21, 2024

We have been using void in the "theoretical" type system since Scala.js 1.0.0, but for historical, NoType kept its old name.

We now officially rename it to VoidType, and print it as void instead of <notype>, giving it a true Type status.


I've been wanting to do this for a while now. I finally took it up. 😅

@sjrd sjrd requested a review from gzm0 October 21, 2024 15:40
case object VoidType extends PrimTypeWithRef

@deprecated("Use VoidType instead", since = "1.18.0")
lazy val NoType: VoidType.type = VoidType
Copy link
Contributor

Choose a reason for hiding this comment

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

NoType is deprecated but now it refers VoidType but it seems that the tests are changed to use VoidType. Do the tests then still have coverage for NoType? Seems it does but not sure and thought I'd ask.

Copy link
Member Author

Choose a reason for hiding this comment

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

No they don't have coverage for NoType but this isn't a big deal. It's mostly to help migration of whoever may directly use the IR library.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was wondering that too, versus just changing the code since it seemed "internal". I follow to try and learn since this project is very well run :-)

Copy link
Contributor

@gzm0 gzm0 left a comment

Choose a reason for hiding this comment

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

Typo in the last commit message:

but for historical, NoType kept its old name

but for historical reasons, NoType...

Regarding the PR title: I'm not a fan that the PR title suggests this is a merely a rename / printer change, but there is (quite deeply hidden) a rather fundamental change of how we type record types.

To someone looking through a changelog / commit history, I think it would be quite difficult to identify that this change sequence has changed subtyping relationships.

(then again, records are internal, and any attempt to actually return a record type somewhere to JS would likely fail).

* Used by the optimizer to inline classes as records with multiple fields.
* They are desugared as several local variables by JSDesugaring.
* Record types cannot cross method boundaries, so they cannot appear as
* the type of fields or parameters, nor as result types of methods.
* The compiler itself never generates record types.
*
* Record types currently do not feature any form of subtyping. For R1 to be
* a subtype of R2, it must have the same fiels, in the same order, with
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* a subtype of R2, it must have the same fiels, in the same order, with
* a subtype of R2, it must have the same fields, in the same order, with

@sjrd
Copy link
Member Author

sjrd commented Nov 2, 2024

Regarding the PR title: I'm not a fan that the PR title suggests this is a merely a rename / printer change, but there is (quite deeply hidden) a rather fundamental change of how we type record types.

To someone looking through a changelog / commit history, I think it would be quite difficult to identify that this change sequence has changed subtyping relationships.

(then again, records are internal, and any attempt to actually return a record type somewhere to JS would likely fail).

Right, good point. I extracted that functional change in a separate PR #5065.

sjrd added 2 commits November 2, 2024 18:57
The concept of "void" will be reserved for "statement types", not
for expressions with the `undefined` value.
Also clarify that it is the real top type of our type system.

We have been using `void` in the "theoretical" type system since
Scala.js 1.0.0, but for historical reasons, `NoType` kept its old
name.

We now officially rename it to `VoidType`, and print it as `void`
instead of `<notype>`, giving it a true `Type` status.
@sjrd
Copy link
Member Author

sjrd commented Nov 2, 2024

Rebased and fixed the commit message typo.

@sjrd sjrd requested a review from gzm0 November 2, 2024 18:06
@sjrd sjrd merged commit b988843 into scala-js:main Nov 3, 2024
3 checks passed
@sjrd sjrd deleted the ir-void-type branch November 3, 2024 02:12
sjrd added a commit to dotty-staging/dotty that referenced this pull request Jan 17, 2025
And port the changes that were made to the compiler backend.
Most nobably, the changes from the following upstream PRs:

* Introduce non-nullable reference types in the IR.
  scala-js/scala-js#5018
* Opt: Remove useless *Ident indirections in the IR model.
  scala-js/scala-js#5092
* Merge the IR node This into VarRef, with a magic LocalName.
  scala-js/scala-js#5090
* Merge several IR nodes into UnaryOp.
  scala-js/scala-js#5088
* Restrict usages of StoreModule even further.
  scala-js/scala-js#5059
* Allow Return arg to be a void if the target Labeled is a void.
  scala-js/scala-js#5074
* Rename NoType to VoidType and print it as "void".
  scala-js/scala-js#5061
sjrd added a commit to dotty-staging/dotty that referenced this pull request Jan 17, 2025
And port the changes that were made to the compiler backend.
Most notably, the changes from the following upstream PRs:

* Introduce non-nullable reference types in the IR.
  scala-js/scala-js#5018
* Opt: Remove useless *Ident indirections in the IR model.
  scala-js/scala-js#5092
* Merge the IR node This into VarRef, with a magic LocalName.
  scala-js/scala-js#5090
* Merge several IR nodes into UnaryOp.
  scala-js/scala-js#5088
* Restrict usages of StoreModule even further.
  scala-js/scala-js#5059
* Allow Return arg to be a void if the target Labeled is a void.
  scala-js/scala-js#5074
* Rename NoType to VoidType and print it as "void".
  scala-js/scala-js#5061
sjrd added a commit to scala/scala3 that referenced this pull request Jan 22, 2025
And port the changes that were made to the compiler backend.
Most notably, the changes from the following upstream PRs:

* scala-js/scala-js#5018
* scala-js/scala-js#5092
* scala-js/scala-js#5090
* scala-js/scala-js#5088
* scala-js/scala-js#5059
* scala-js/scala-js#5074
* scala-js/scala-js#5061
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