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

Add new EXPLICITtpt to TASTy format #17298

Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Apr 18, 2023

This is a new encoding of HOLE that differentiates between type and term arguments of the hole.

-- pickled quote trees: These trees can only appear in pickled quotes. They will never be in a TASTy file.
  EXPLICITtpt tpt_Term
    -- Tag for a type tree that in a context where it is not explicitly known that this tree is a type.
  HOLE Length idx_Nat tpe_Type arg_Tree*
    -- Splice hole with index `idx`, the type of the hole `tpe`, type and term arguments of the hole `arg`s

We will pickle type trees in arg_Tree using the EXPLICITtpt tag.

We will only have hole captured types if there is a type defined in a quote and used in a nested quote. Most of the time we do not have those types and therefore no overhead in the encoding compared to before this change.

Alternative to #17225
Fixes #17137

@nicolasstucki nicolasstucki self-assigned this Apr 18, 2023
@nicolasstucki nicolasstucki force-pushed the explicit-type-tree-tasty-hole-encoding branch from 5e95030 to fe1268b Compare April 18, 2023 09:03
@nicolasstucki nicolasstucki marked this pull request as ready for review April 19, 2023 07:16
@nicolasstucki nicolasstucki requested a review from smarter April 19, 2023 07:16
@smarter smarter added the needs-minor-release This PR cannot be merged until the next minor release label Apr 19, 2023
@nicolasstucki nicolasstucki force-pushed the explicit-type-tree-tasty-hole-encoding branch 2 times, most recently from 0076a28 to a181327 Compare April 20, 2023 08:35
@nicolasstucki nicolasstucki force-pushed the explicit-type-tree-tasty-hole-encoding branch from a181327 to bb17e27 Compare May 12, 2023 12:35
@nicolasstucki nicolasstucki marked this pull request as draft May 12, 2023 12:35
This is a new encoding of HOLE that differentiates between type and
term arguments of the hole.

```
-- pickled quote trees: These trees can only appear in pickled quotes. They will never be in a TASTy file.
  EXPLICITtpt tpt_Term
    -- Tag for a type tree that in a context where it is not explicitly known that this tree is a type.
  HOLE Length idx_Nat tpe_Type arg_Tree*
    -- Splice hole with index `idx`, the type of the hole `tpe`, type and term arguments of the hole `arg`s
```

We will only have hole captured types if there is a type defined in a quote and used in a nested quote.
Most of the time we do not have those types and therefore no overhead in the encoding compared to before this change.
@nicolasstucki nicolasstucki force-pushed the explicit-type-tree-tasty-hole-encoding branch from bb17e27 to 9897592 Compare July 25, 2023 15:16
@nicolasstucki nicolasstucki marked this pull request as ready for review August 4, 2023 15:47
@nicolasstucki nicolasstucki requested a review from smarter August 4, 2023 15:47
Copy link
Member

@smarter smarter left a comment

Choose a reason for hiding this comment

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

LGTM, but what do we do in the 3.3 branch?

@nicolasstucki
Copy link
Contributor Author

There is nothing we can or must do in the 3.3 branch. #17137 will not be fixed in 3.3.

The fix will be available in 3.4 and is backward compatible.

@smarter
Copy link
Member

smarter commented Aug 7, 2023

Does #17137 cause crashes in 3.3? Could we detect in the pickler the pattern and abort compilation?

@nicolasstucki
Copy link
Contributor Author

It will cause crashes. It might be possible to detect them in the quote pickler. I will try to do this on 3.3. We would not need that chack in 3.4+ (i.e. for this PR).

@@ -695,7 +695,9 @@ class TreePickler(pickler: TastyPickler) {
writeNat(idx)
pickleType(tree.tpe, richTypes = true)
args.foreach { arg =>
if arg.isType then writeByte(EXPLICITtpt)
arg.tpe match
case _: TermRef if arg.isType => writeByte(EXPLICITtpt)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For 3.3 we can "backport" this change as

arg.tpe match
  case _: TermRef if arg.isType => report.warning(em"Term reference used in type of nested quote. This quote may fail to unpickle due to a bug that cannot be fixed in 3.3.x. This issue is fixed in 3.4.0.", arg)
  case _ =>

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@smarter I added this new commit containing the check to identify the problematic cases and optimize the pickled quote size by eliding the EXPLICITtpt when it is unnecessary.

Copy link
Member

Choose a reason for hiding this comment

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

I also believe this should be an error not a warning, and if possible give a workaround that can be used in 3.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have yet to find an example that fails in 3.3. We used the wrong pickling/unpickling for those term refs.

The issues only arose when trying to fix code that would not compile with some specific term-refs and this-types. When fixing those issues we start encountering the ambiguity in pickling/unpickling of those term-refs.

@nicolasstucki nicolasstucki requested a review from smarter August 7, 2023 15:00
@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Aug 7, 2023

Maybe I should revisit #17109 (and maybe #17138) before we merge this.

@nicolasstucki nicolasstucki merged commit 965818a into scala:main Aug 8, 2023
@nicolasstucki nicolasstucki deleted the explicit-type-tree-tasty-hole-encoding branch August 8, 2023 12:19
@Kordyjan Kordyjan added this to the 3.4.0 milestone Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Encoding of quote HOLE in TASTy
3 participants