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

Handle pickled forward references in pickled expressions #16855

Merged
merged 1 commit into from
Feb 16, 2023

Conversation

nicolasstucki
Copy link
Contributor

To compute forward references it was assumed that the owner of that symbol can be found in the TASTy. This is not always the case with TASTy expressions of pickled quotes. The owner might be outside the quote, in this case the context already has the owner of the referenced symbol. These are local symbols defined at the top-level of the TASTy.

Fixes #16843

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.

/cc @sjrd since this seems like it will affect tasty-query

Comment on lines 7 to 16
val b = ${
val a = '{
(1: Int) match
case x @ (y: Int) => 0
}
a
}

(1: Int) match
case x @ (y: Int) => 0
Copy link
Member

Choose a reason for hiding this comment

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

The test case in #16843 is easier to understand/debug, so I would add it too even if we want to test more complex cases.

current
// If current does not exist it is beacause this is a pickled expression
// and the owner is located outside the expression (i.e. pickled quote).
current.orElse(ctx.owner)
Copy link
Member

Choose a reason for hiding this comment

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

This could hide bugs if we're not in fact in a pickled quote. I think it'd be clearer if we stored the quote owner instead. Something like:

/** If this is a pickled quote, the owner of the quote, otherwise NoSymbol. */
private var rootOwner: Symbol = NoSymbol

...

def unpickle(mode: UnpickleMode)(using Context): List[Tree] = {
  if mode != UnpickleMode.TopLevel then rootOwner = ctx.owner
  ...
}  
...
class OwnerTree(val addr: Addr, tag: Int, reader: TreeReader, val end: Addr) {
  ...
    try search(children, rootOwner)
  ...
}

@smarter smarter assigned nicolasstucki and unassigned smarter Feb 9, 2023
@nicolasstucki
Copy link
Contributor Author

/cc @sjrd since this seems like it will affect tasty-query

We do not generate .tasty files containing quoted expressions. TASTy query will not encounter this kind of code.

To compute forward references it was assumed that the owner of that
symbol can be found in the TASTy. This is not always the case with TASTy
expressions of pickled quotes. The owner might be outside the quote, in
this case the context already has the owner of the referenced symbol.
These are local symbols defined at the top-level of the TASTy.

Fixes scala#16843
@smarter smarter added this pull request to the merge queue Feb 15, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Feb 16, 2023
@nicolasstucki nicolasstucki merged commit 0e5d922 into scala:main Feb 16, 2023
@nicolasstucki nicolasstucki deleted the fix-16843 branch February 16, 2023 09:34
@Kordyjan Kordyjan added this to the 3.3.1 milestone Aug 1, 2023
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.

Pickler crash when binding typed pattern to name
3 participants