Skip to content

Fix #8619: Demand transparent for whitebox inlines #8630

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 8 commits into from
Mar 31, 2020

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 29, 2020

Previously, whitebox inlines could be declared in three different ways

  1. writing inline def f <: T = ... for inline methods
  2. writing inline given f as _ <: T = ...` for inline givens
  3. leaving out the result type for inline methods

The last was an oversight, not backed by the spec. It turned out that it
was not that easy to prevent (3), so it was not done, and afterwards
code exploited the loophole.

In the new scheme, "whitebox" inlines demand transparent. The result type
can be given or left out, the effect is the same. The old <: result type
syntax will be phased out in a subseqent PR once the new syntax is in a release.

transparent is a soft modifier. It is valid only together with inline. Why not
allow transparent on its own and let it subsume inline? The point is that
we should steer users firmly towards blackbox macros, since they are much
easier to deal with for tooling. This means we want to make whitebox macros
strictly more verbose than blackbox macros. Otherwise someone might find
transparent "nicer" than inline and simply use it on these grounds without
realizing (or caring about) the consequences.

For the same reason I did not follow the (otherwise tempting) idea to simply
re-use opaque instead of transparent. An opaque inline keeps its type on
expansion whereas a transparent one gets the type of its expansion. But that
would have nudged to user to prefer inline over opaque inline, so would
again have gjven the wrong incentive.

On the other hand, transparent as a dual of opaque is nice. It fits into
the same terminology. It's simply that type aliases are transparent by default
and have to be made opaque with a modifier, whereas inline methods are opaque
by default, and have to be made transparent by a modifier.

odersky added 3 commits March 29, 2020 13:35
Previously, whitebox inlines could be declared in three different ways

 1. writing `inline def f <: T = ...` for inline methods
 2. writing `inline given f: _ <: T` = ...` for inline givens
 3. leaving out the result type for inline methods

The last was an oversight, not backed by the spec. It turned out that it
was not that easy to implement (3), so it was not done, and afterwards
code exploited the loophole.

In the new scheme, `whitebox` inlines demand `transparent`. The result type
can be given or left out, the effect is the same. The old `<:` result type
syntax will be phased out in a subseqent PR once the new syntax is in a release.

`transparent` is a soft modifier. It is valid only together with `inline`. Why not
allow `transparent` on its own and let it subsume `inline`. The point is that
we should steer users firmly towards blackbox macros, since they are much
easier to deal with for tooling. This means we want to make whitebox macros
strictly more verbose than blackbox macros. Otherwise someone might find
`transparent` "nicer" than `inline` and simply use it on these grounds without
realizing (or caring about) the consequences.

For the same reason I did not follow the (otherwise tempting) idea to simply
re-use `opaque` instead of `transparent`. An opaque inline kleeps its type on
expansion whereas a transparent one gets the type of its expansion. But that
would have nudged to user to prefer `inline` over `opaque inline`, so would
again have gjven the wrong incentive.

On the other hand, `transparent` as a dual of `opaque` is nice. It fits into
the same terminology. It's simply that type aliases are transparent by default
and have to be made opaque with a modifier, whereas inline methods are opaque
by default, and have to be made transparent by a modifier.
Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Overall looks good.

@odersky odersky assigned nicolasstucki and unassigned odersky Mar 30, 2020
@odersky odersky merged commit 9a69ea8 into scala:master Mar 31, 2020
@odersky odersky deleted the fix-#8619 branch March 31, 2020 07:49
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.

2 participants