-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Change in terminology for typelevel methods #4927
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Commit Messages
We want to keep history, but for that to actually be useful we have
some rules on how to format our commit messages (relevant xkcd).
Please stick to these guidelines for commit messages:
- Separate subject from body with a blank line
- When fixing an issue, start your commit message with
Fix #<ISSUE-NBR>:
- Limit the subject line to 72 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use the imperative mood in the subject line ("Add" instead of "Added")
- Wrap the body at 80 characters
- Use the body to explain what and why vs. how
adapted from https://chris.beams.io/posts/git-commit
Have an awesome day! ☀️
327ae1c
to
f951c6b
Compare
I worry slightly that using |
Bit it's sort of equivalent: You tell the compiler to rewrite the source program according to the rules that are specified. |
I think that's the problem ... it's close enough to cause confusion. |
Do you have a suggestion for another term to use? We want something that marks both definitions and match and if expressions. |
My understanding of the terminology in Agda/Idris/Coq, etc. is that I think that the backwards reasoning aspect fits implicit search extremely well, and I can imagine that if we developed the idea of a tactic language for Scala it would be closely aligned with implicit search. In particular I can imagine putting together a I think that what you're trying to get to here is a label for forwards reasoning, from premises (arguments/scrutinees) to conclusions (result/match RHS). I think we're definitely in the same sort of area, but I don't think we have the terminology quite right yet. I'll try and come up with something better. |
Chatting with @Blaisorblade about this a little, we're both of the opinion (correct me if I'm misrepresenting you @Blaisorblade) that this is in effect a staging annotation. If that's the case, then perhaps we should try and relate the syntax here to the metaprogramming syntax? How about reusing ~ def concat[A, M, N](xs: Vec[A, M], ys: A[A, N])(implicit ev: Add[M, N]): Vec[A, ev.Result]
~ type Add[M <: Nat, N <: Nat] <: Nat = type M match {
case Z => N
case S[type M1] => S[Add[M1, N]]
} It also takes this, rewrite def m(x: T) = ~mImpl('x)
...
def mImpl(x: Expr[T]) = ... to this, ~ def m(x: T) = ~mImpl('x)
...
def mImpl(x: Expr[T]) = ... which I think is quite suggestive ... the compile time nature of the RHS is mirrored on the LHS. As an added bonus this doesn't require another new keyword, and |
There sure are analogies between rewrite and macro splicing, but there are also differences. Splice ~ def size(xs: Tuple): Int = ~ xs match {
case _: Empty => '0
case _: (_ *: xs1) => 'size(erasedValue[xs1]) + 1
} (That's actually the model I started with 6 months ago). But I now believe using There's also the difference that Finally, there's the difference that once I splice a function call, like So I fear merging |
I wasn't proposing changing the semantics, just using the token |
That's what I assumed. My worry is that using |
Regarding usage of |
Fair enough. |
Since |
@ctongfei I am not against
|
@odersky OK I got it. Maybe |
It's a big commit. Who volunteers for reviewing? |
0480620
to
6a86f99
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM
@@ -2519,6 +2543,8 @@ object Parsers { | |||
stats +++= defOrDcl(in.offset, defAnnotsMods(modifierTokens)) | |||
else if (!isStatSep) { | |||
exitOnError = mustStartStat | |||
println(in.token) | |||
println(in.next.token) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should remove these two lines
@odersky this PR needs a rebase |
- also, introduce `rewrite` as a modifier for match expressions and conditionals. - keep `transparent` for methods that are not erased, and don't inline by themselves, yet can be inlined from rewritten code.
Also implements rewrite matches and rewrite ifs. Keeps transparent as a separate modifier with meaning: "inline if called from a rewrite context".
erased can only override erased, non-erased can only override non-erased.
...in new code added through rebase
8a13d19
to
bbe88d1
Compare
This PR changes the
typelevel.md
spec, renamingtransparent
torewrite
.rewrite
as a modifier for match expressions and conditionals.transparent
for methods that are not erased, and don't inline by themselves, yet can be inlined from rewritten code.It's hopefully clearer this way. Also,
rewrite
on conditonals and matches, while being more verbose makes their use more compositional. This PR is based on #4916.