Skip to content

Replace delegate match with summonFrom. #7201

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 12 commits into from
Sep 12, 2019

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Sep 12, 2019

Instead of having a separate syntactic construct (latest incarnation: delegate match), provide
a special method summonFrom in scala.compiletime.

delegate match { 
  case ev_1: TC_1 => e_1
  ...
  case ev_n: TC_n => e_n
}

becomes

summonFrom { 
  case given ev_1: TC_1 => e_1
  ...
  case given ev_n: TC_n => e_n
}

summonFrom is currently implemented by compiler magic. It could be implemented as a macro if we introduce an additional way to control when inline methods expand. See the comment in Applications.scala.

Based on #7194.

Change contextual docs to reflect three changes to `given` syntax:

 - put `given` inside the parentheses of parameters and arguments, as was suggested by @smarter.
 - change given import syntax to make `given` an import selector
 - change `the` to `theGiven`.

All of these should discussed in separate issues.
Following the discussion in scala#7151, choose `:` instead of `as` for given clauses.
Also: Allow inline givens to be whitebox
Syntax:

    given x: T

Allowed anywhere a pattern is allowed. This is useful in for expressions
and as a replacement of given matches, to name just two cases.
Drop `delegate match` and `given match`. They are replaced by `summonFrom`.
@odersky odersky changed the title replace delegate match with summonFrom. Replace delegate match with summonFrom. Sep 12, 2019
@milessabin
Copy link
Contributor

I'll update the shapeless-3 branch in the community build as soon as there's a nightly with these changes.

@odersky
Copy link
Contributor Author

odersky commented Sep 12, 2019

@milessabin How do we proceed with the bootstrap? Here's one way I see would work, but maybe there's something simpler:

  1. I roll everything up to 2b8ba68 into Allow given bindings in patterns #7194 and we merge that first. That gives us summonFrom as well as delegate match.
  2. You update shapeless in the CB once (1) is in the nightly.
  3. We merge this PR once (2) is merged.

Should we do it like this?

@milessabin
Copy link
Contributor

Should we do it like this?

Or simpler ... just let shapeless break in the community build and I'll fix it up afterwards.

@odersky
Copy link
Contributor Author

odersky commented Sep 12, 2019

I was told by @nicolasstucki we can't get a nightly anymore if the CB breaks. So we'll do it in steps.

@odersky
Copy link
Contributor Author

odersky commented Sep 12, 2019

@milessabin I was puzzled why the community build passed, even though delegate match is gone. It seems shapeless still uses implicit match, right? That will be the next to go but in a different PR. So we can get this one in if I get a review thumbs up and then it's over to you for the shapeless update.

@odersky
Copy link
Contributor Author

odersky commented Sep 12, 2019

@biboudis This is actually a stack for 3 PR's:

#7150: Reference docs only, changes the given syntax
#7194: Allow given in patterns
#7201: This PR

I believe they are best reviewed in order, but it's easiest if we do fixes and merges just on this PR.

@milessabin
Copy link
Contributor

It seems shapeless still uses implicit match

Oh! Yes ... I went straight from implicit to given and never changed the matches over.

Yup, go ahead and merge this. Do you want to do the separate PR that removes implicit match right away, or will there be a new nightly including this PR before then?

@milessabin milessabin self-requested a review September 12, 2019 11:30
@odersky
Copy link
Contributor Author

odersky commented Sep 12, 2019

Yup, go ahead and merge this. Do you want to do the separate PR that removes implicit match right away, or will there be a new nightly including this PR before then?

We'll do a new nightly before.

@odersky odersky merged commit 60c3a12 into scala:master Sep 12, 2019
@odersky odersky deleted the add-summonFrom branch September 12, 2019 13:01
@anatoliykmetyuk anatoliykmetyuk added this to the 0.19 Tech Preview milestone Sep 19, 2019
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