chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.77k stars 417 forks source link

Genericity - putting it together #21477

Open vasslitvinov opened 1 year ago

vasslitvinov commented 1 year ago

This issue asks how to put all the features together for a coherent update of our genericity story.

Here is my opening proposal:

Insights and further details:

Examples

// a generic class
class MyClass(?) {
  var field: MyRecord(?);
}

// a generic record
record MyRecord(?) {
  var field: borrowed MyClass?(?); // the first '?' is for nilability
  var field2: object?(?);        // the second '?' is for generic mem. management
}

// variables or consts; assuming split-initialization
var v1: MyRecord(?);
var v2: object?(?);
var v3: domain;       // warn/error: need domain(?) or domain(1) etc.
var v4: range;        // warn/error: need range(?) or range(int) etc.
var v5: domain(1);    // ok: fully instantiated using defaults
var v6: range(int,?); // ok: partial instantiation
var v7: rank * MyRecord(?); // a generic tuple
var v8: abc()(?);     // indicate that v8's declared type is generic

// var-like formals (not type/param)
proc p1( v1: MyRecord(?), v2: object?(?) ) {...}

// 'type' things

type t1(?) = MyRecord;   // '(?)' after MyRecord is not required here

class Class2(?) {
  type t2(?);            // t2 can be instantiated with a generic type
}

proc p2( type t2(?) ) {...}   // p2 can be invoked with a generic type

proc p3() type(?) {...}       // p3 can return a generic type

Afterword

The best path to move forward is to prototype these features and evaluate their impact.

mppf commented 1 year ago

record MyRecord(?) { ... }

I am concerned that this syntax will lead people to believe that they can define the type constructor in those parentheses, e.g. record MyRecord(type T) { ... } but as far as I know, you are not proposing that.

Put another way, places where (?) exist mean that you could put some other argument list there, but this proposal would change that.

vasslitvinov commented 11 months ago

No further changes are planned here for 2.0. I removed the 2.0 tag.