Skip to content

Replace ShortcutImplicits #8386

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

Merged
merged 6 commits into from
Mar 6, 2020
Merged

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 26, 2020

Don't duplicate methods in ShortcutImplicits. Instead, always merge
context function result parameters with normal parameters in one erased
method, as long as the context functions were expanded as closures
in the method's rhs.

In some cases (notably, but not exclusively, for bridges) this needs
an eta expansion step at erasure.

@odersky odersky marked this pull request as ready for review February 28, 2020 15:58
@odersky odersky force-pushed the change-cf-encoding branch 5 times, most recently from 9a2e8ad to 41cd7d1 Compare February 29, 2020 17:12
@odersky
Copy link
Contributor Author

odersky commented Feb 29, 2020

@nicolasstucki @anatoliykmetyuk Could you investigate why the test disabled in 41cd7d1 fails? It seems to have nothing to do with the changes in this PR.

@odersky odersky changed the title Replace shortcutImplicits Replace ShortcutImplicits Feb 29, 2020
@odersky
Copy link
Contributor Author

odersky commented Mar 2, 2020

Here's the failing test:

echo "testing sbt dotc with suspension"
clear_out "$OUT"
"$SBT" "dotc -d $OUT tests/pos-macros/macros-in-same-project-1/Bar.scala tests/pos-macros/macros-in-same-project-1/Foo.scala"

The test does not fail locally on my machine (either running sbt test) or executing the command by hand.

@odersky
Copy link
Contributor Author

odersky commented Mar 2, 2020

I think I know what goes on. The command test dotc has the following classpath

[info] running (fork) dotty.tools.dotc.Main -classpath /Users/odersky/.coursier/cache/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.1/scala-library-2.13.1.jar:/Users/odersky/workspace/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.23/dotty-library_0.23-0.23.0-bin-SNAPSHOT.jar -d /Users/odersky/classes tests/pos-macros/macros-in-same-project-1/Bar.scala tests/pos-macros/macros-in-same-project-1/Foo.scala

It looks for scala.internal.quoted.Unpickler$.unpickleExpr in workspace/dotty/library/../out/bootstrap/dotty-library-bootstrapped/scala-0.23/dotty-library_0.23-0.23.0-bin-SNAPSHOT.jar. But since unpickleExpr returns a CFT, its type has changed in this PR. So it does not find the method under the correct type and gives the error message

java.lang.NoSuchMethodError: scala.internal.quoted.Unpickler$.unpickleExpr(Lscala/collection/immutable/List;Lscala/collection/immutable/Seq;Lscala/quoted/QuoteContext;)Lscala/quoted/Expr;

So the correct way to set up the test is to use the output directory instead of SNAPSHOT-jar when searching for unpickleExpr.

Alternatively, we could leave the test disabled and revive it again once unpickleExpr with the new type signature is in SNAPSHOT.jar. That's easier. And the type of this method should not change that often.

[That also explains why the test worked locally: I have the output directory on the classpath, so it found the right unpickleExpr.]

@odersky
Copy link
Contributor Author

odersky commented Mar 2, 2020

So, this is ready for review now.

@smarter
Copy link
Member

smarter commented Mar 2, 2020

OK, so this should work fine if dotc is replaced by dotty-compiler-bootstrapped/dotc in the command (the non-bootstrapped compiler should never be used to run macro code to avoid this exact sort of problem).

@odersky
Copy link
Contributor Author

odersky commented Mar 2, 2020

@smarter That seems to work, yes. At least locally it worked. Let's see what the CI says.

Copy link
Contributor

@anatoliykmetyuk anatoliykmetyuk left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

* dependent refinements. Optionally returns a triple consisting of the argument
* types `As`, the result type `B` and a whether the type is an erased context function.
*/
object ContextFunctionType:
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this object belongs at Types.scala.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

One can debate this. I put it next to isContextFunctionType and asContextFunctionType, since it is related.

odersky added 5 commits March 6, 2020 09:04
A re-implementation of the uncurrying part of erasure. It now goes "bottom-up" by
temporarily admitting Apply's that dop not yet have all their arguments. The previous
implementation was "top-down" by looking at the prototypes.

# Conflicts:
#	compiler/src/dotty/tools/dotc/transform/Erasure.scala
Don't duplicate methods in ShortcutImplicits. Instead, always merge
context function result parameters with normal parameters in one erased
method, as long as the context functions were expanded as closures
in the method's rhs.

Om some cases (notably, but not exclusively, for bridges) this needs
an eta expansion step at erasure.

# Conflicts:
#	compiler/src/dotty/tools/dotc/core/NameKinds.scala
#	compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Always use bootstrapped compiler for macro operations
@odersky odersky force-pushed the change-cf-encoding branch from a830325 to 923d591 Compare March 6, 2020 08:06
@odersky odersky merged commit f548a18 into scala:master Mar 6, 2020
@odersky odersky deleted the change-cf-encoding branch March 6, 2020 09:06
anatoliykmetyuk added a commit to dotty-staging/dotty that referenced this pull request Mar 11, 2020
The test in question was introduced by scala#8386. The test
was failing on Java 11 from the very first time it was
introduced. The first commit where
`testCompilation context-functions` fails under Java 11 is
cbd21a0.
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.

4 participants