-
Notifications
You must be signed in to change notification settings - Fork 424
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
should Chapel allow pure virtual methods? #8566
Comments
I'm generally in favor of adding support for pure virtual methods unless our eventual implementation of constrained generics would make them pointless. |
Syntax suggestion: |
|
Would an attribute such as Edit: I realize that we probably can't freely deprecate attributes either 😢. Well, I'd also be fine with having both ways for the forseeable future, but I understand that may not be preferable. |
I think syntax would be a better choice than attributes since the features is very intrinsic to how the language functions and isn't something that could be ignored. My mental model for attributes currently is "Is this part of a conversation between the programmer and the compiler/tools?" and this doesn't fit that for me. Thinking about the expression of this for the first time in awhile: A keyword-less approach would be to simply interpret the lack of a procedure body as an indication of a p.v.m. Currently, we disallow this for anything other than class C {
proc myMethod(...args...) ...<ret-signature>..; // where `<ret-signature>` is meant to include whatever return type signature, intent, where-clause, etc.
} I'm not opposed to introducing a keyword as well to make it less subtle, where I'd probably pick class C {
abstract proc myMethod(...args...) ...<ret-signature>...;
} If we wanted to use a keyword but reuse an existing one, we could say: class C {
override proc myMethod(...args...) ...<ret-signature>...;
} The downside is that normally this says "I override my parent" and here I'm abusing it to say "I must be overridden" which seems potentially too confusing. The only reason I suggest it is that it doesn't introduce a new keyword.\ I like the Bryant and Michael ideas to put the override into more of the body of the method as well. Bryant's reads very cleanly to me, but is a bit odd in that it's the only place Oh, now that we have single-statement procedures, we could require Michael's to be written: class C {
proc myMethod(...args...) ...<ret-signature>... do override;
} which I think feels less funny somehow—probably because it doesn't suggest other statements could also be in the body and could be pattern-matched directly in the parser. FWIW, I'd love to resolve this and make it happen. It feels overdue. |
I like I'm not sure if And you can totally make the argument that |
Maybe it's time to put our 4-6 favorite approaches in front of the team for a post-meeting vote. |
How about we narrow down to the following?
I've opted to drop Here I'd conceptually group the options into some different categories:
|
I'd probably leave |
I think that syntax with I'm in favor of
|
FWIW, my favorite is something along the lines of I personally find these |
Of all the words mentioned above, |
@vasslitvinov - do you think we need to have a different way of writing a "pure virtual method" vs "method not provided"? The "method not provided" case is what I was imagining |
I tend to agree with Michael here that we should probably reserve |
The difference between the case "this method should not be provided implicitly" (15271) and the case of a pure virtual method is pretty subtle. OK, I am open to |
Great, I've added |
I think you're right that it would need to be a keyword, Daniel. In some past discussions about the Chapel language and breaking changes, users have admitted that we'd likely need to continue reserving new keywords after 2.0, and I think there are other cases on-deck that will likely require new keywords as well. But there's obviously a discussion to be had there. |
Other languages, e.g. C++ and Java, allow pure virtual methods. Currently some Chapel internal module code mocks this up with methods that halt. But, the compiler could check that a pure virtual method can never be called.
Some syntax inspirations from other languages:
virtual int myMethod() = 0;
abstract int myMethod();
abstract int myMethod()
It seems Swift does not support this mechanism and rather expects use of
protocols
(which are like concepts/interfaces a-la CHIP 2).The text was updated successfully, but these errors were encountered: