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

Kernel needs a way to represent generic function instantiations #31550

Closed
stereotype441 opened this Issue Dec 5, 2017 · 2 comments

Comments

Projects
None yet
4 participants
@stereotype441
Member

stereotype441 commented Dec 5, 2017

Example Dart code:

T f1<T>(T v) => ...;
class C {
  static T f2<T>(T v) => ...;
  T f3<T>(T v) => ...;
}
C c = ...;
main() {
  T f4<T>(T v) => ...;
  // All of these implicitly instantiate with type arg <int>
  int Function(int) x1 = f1; // (1)
  int Function(int) x2 = C.f2; // (2)
  int Function(int) x3 = c.f3; // (3)
  int Function(int) x4 = f4; // (4)
}

Lines (1) through (4) need to behave as though they had been written as:

  int Function(int) x1 = (int v) => f1<int>(v); // (1)
  int Function(int) x2 = (int v) => C.f2<int>(v); // (2)
  int Function(int) x3 = (int v) => c.f3<int>(v); // (3)
  int Function(int) x4 = (int v) => f4<int>(v); // (4)

But it doesn't make sense to desugar this in the front end because:

  • There will be problems if the function in question has default parameters
  • It strongly suggests an implementation strategy; a back end might be able to implement generic function instantiation in a more performant way, but in order to do so it would have to reverse-engineer the desugaring.

My preference would be to add a new type of Expression to kernel, e.g.

class Instantiation extends Expression {
  Expression operand;
  final List<DartType> types;
  ...
}
@stereotype441

This comment has been minimized.

Show comment
Hide comment
@stereotype441

stereotype441 Dec 13, 2017

Member

Marking this as P1 since the related front end issue (#31586, which is blocked on this bug) has now been independently discovered by three different people.

Member

stereotype441 commented Dec 13, 2017

Marking this as P1 since the related front end issue (#31586, which is blocked on this bug) has now been independently discovered by three different people.

@a-siva a-siva added this to the 2.0-alpha milestone Dec 13, 2017

whesse pushed a commit that referenced this issue Dec 14, 2017

Add a representation for an instantiated generic function
Kernel allows instantiating a tearoff to type arguments.  This
construct is not yet produced by the front end or supported in any
back end.

Closes issue #31550

Bug: #31550
Change-Id: I5e50d26cdc77a84ba92fa0ea5eea49b42ca83551
Reviewed-on: https://dart-review.googlesource.com/29587
Reviewed-by: Samir Jindel <sjindel@google.com>
Commit-Queue: Kevin Millikin <kmillikin@google.com>
@stereotype441

This comment has been minimized.

Show comment
Hide comment
@stereotype441
Member

stereotype441 commented Dec 14, 2017

Fixed by bc25600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment