Skip to content

Implement instantiate-to-bounds in the VM #32076

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

Closed
askeksa-google opened this issue Feb 7, 2018 · 3 comments
Closed

Implement instantiate-to-bounds in the VM #32076

askeksa-google opened this issue Feb 7, 2018 · 3 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. customer-vm front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on

Comments

@askeksa-google
Copy link

When the VM reads the bound of a type parameter on a local function from kernel, it does it using this code, which ignores the actual type and always puts dynamic:

if (type_parameter_scope_ != NULL &&
parameter_index < type_parameter_scope_->outer_parameter_count() +
type_parameter_scope_->parameter_count()) {
result_ ^= Type::DynamicType();
return;
}

This bug is caught by the test language_2/generic_function_bounds_test after the crash is fixed in https://dart-review.googlesource.com/c/sdk/+/39160

@askeksa-google askeksa-google added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. P2 A bug or feature request we're likely to work on area-kernel labels Feb 7, 2018
@sjindel-google sjindel-google self-assigned this Feb 7, 2018
@sjindel-google
Copy link
Contributor

sjindel-google commented Feb 7, 2018

This is only a problem with bounds that reference type parameters from the same type parameter list, e.g.:

f<A extends C<A>>

In this case, until the bounds finalized, the type parameters will be substituted with dynamic, so
the bound will be finalized as C<dynamic>.

@sjindel-google
Copy link
Contributor

I can't reproduce this problem.

Consider:

$ cat >test.dart <<EOF
class A<T> {}
class B implements A<B> {}
class C implements A<dynamic> {}

void main() {
  void test<T extends A<T>>() {}
  dynamic x = test;
  x<B>();
  x<C>();
}
EOF
$ pkg/vm/tool/dart2 test.dart
Unhandled exception:                                                                                                                                                                                                                                                                                                          
type 'C' is not a subtype of type 'A<C>' of 'T' where                                                                                                                                                                                                                                                                         
  C is from file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart                                                                                                                                                                                                                                                  
  A is from file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart                                                                                                                                                                                                                                                  
  C is from file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart                                                                                                                                                                                                                                                  
                                                                                                                                                                                                                                                                                                                              
#0      main.test (file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart)                                                                                                                                                                                                                                          
#1      main (file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart:9:4)                                                                                                                                                                                                                                           
#2      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)                                                                                                                                                                                                                                 
#3      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12) 

The error with generic_function_bounds_test.dart seems to be the result of dynamic being used as the default for a dynamic generic function call without type arguments, where the corresponding type parameter has a bound stricter than dynamic. Here's a simple reproduction:

$ cat >test.dart <<EOF
void test<T extends num>() {}                                                                                                                                                                                                                                                                                                                              
void main() {
  (test as dynamic)();
}
$ pkg/vm/tool/dart2 test.dart
Unhandled exception:                                                                                                                                                                                                                                                                                                          
type 'dynamic' is not a subtype of type 'num' of 'T' where                                                                                                                                                                                                                                                                    
  num is from dart:core                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                              
#0      main (file:///usr/local/google/home/sjindel/src/dart-sdk/sdk/test.dart:4:20)
#1      _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
#2      _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

@sjindel-google sjindel-google changed the title Type parameter bounds on local functions are read as dynamic Implement instantiate-to-bounds in the VM Mar 19, 2018
@sjindel-google
Copy link
Contributor

Related: #31581

@kmillikin kmillikin added legacy-area-front-end Legacy: Use area-dart-model instead. front-end-kernel and removed legacy-area-front-end Legacy: Use area-dart-model instead. labels Sep 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. customer-vm front-end-kernel legacy-area-front-end Legacy: Use area-dart-model instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

3 participants