Skip to content
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

Greencat library usage crashes the compiler #28749

Closed
sturmf opened this issue Feb 11, 2017 · 15 comments
Closed

Greencat library usage crashes the compiler #28749

sturmf opened this issue Feb 11, 2017 · 15 comments
Assignees

Comments

@sturmf
Copy link

sturmf commented Feb 11, 2017

Hi, it seems I can no longer use https://github.com/alexeieleusis/greencat/ with dart, the compiler crashes when I use it. Right now I am not sure if it is the compiler at fault or if it trips on some problematic code.

Here is my code which produces the error: https://github.com/sturmf/regatta-angular2/tree/REG-51-switch-to-redux-arc

My dart SDK version is Dart VM version: 1.21.1 on Ubuntu Linux 16.04.

The compiler crashed when compiling this element.
Store.createStore(Reducer<S, A> reducer, {S initialState, Function enhancer})
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The compiler is broken.

When compiling the above element, the compiler crashed. It is not
possible to tell if this is caused by a problem in your program or
not. Regardless, the compiler should not crash.

The Dart team would greatly appreciate if you would take a moment to
report this problem at http://dartbug.com/new.

Please include the following information:

  • the name and version of your operating system,

  • the Dart SDK build number (build number could not be determined), and

  • the entire message you see here (including the full stack trace
    below as well as the source location above).

Build error:
Transform Dart2JS on frontend|test/event_list_test.dart.browser_test.dart threw error: RangeError (index): Invalid value: Not in range 0..2, inclusive: 3
dart:core List.[]
package:compiler_unsupported/src/ssa/codegen.dart 2995 SsaCodeGenerator.visitTypeInfoExpression.
package:compiler_unsupported/src/js_backend/runtime_types.dart 801 TypeRepresentationGenerator.visitTypeVariableType
package:compiler_unsupported/src/dart_types.dart 233 TypeVariableType.accept
package:compiler_unsupported/src/js_backend/runtime_types.dart 798 TypeRepresentationGenerator.visit
package:compiler_unsupported/src/js_backend/runtime_types.dart 819 TypeRepresentationGenerator.visitList
package:compiler_unsupported/src/js_backend/runtime_types.dart 810 TypeRepresentationGenerator.visitInterfaceType
package:compiler_unsupported/src/dart_types.dart 552 InterfaceType.accept
package:compiler_unsupported/src/js_backend/runtime_types.dart 798 TypeRepresentationGenerator.visit
package:compiler_unsupported/src/js_backend/runtime_types.dart 819 TypeRepresentationGenerator.visitList
package:compiler_unsupported/src/js_backend/runtime_types.dart 861 TypeRepresentationGenerator.visitFunctionType
package:compiler_unsupported/src/dart_types.dart 730 FunctionType.accept
package:compiler_unsupported/src/js_backend/runtime_types.dart 798 TypeRepresentationGenerator.visit
package:compiler_unsupported/src/js_backend/runtime_types.dart 787 TypeRepresentationGenerator.getTypeRepresentation
package:compiler_unsupported/src/js_backend/runtime_types.dart 612 _RuntimeTypesEncoder.getTypeRepresentation
package:compiler_unsupported/src/ssa/codegen.dart 2994 SsaCodeGenerator.visitTypeInfoExpression
package:compiler_unsupported/src/ssa/nodes.dart 3365 HTypeInfoExpression.accept
package:compiler_unsupported/src/ssa/codegen.dart 661 SsaCodeGenerator.visit
package:compiler_unsupported/src/ssa/codegen.dart 667 SsaCodeGenerator.visitExpression
package:compiler_unsupported/src/ssa/codegen.dart 648 SsaCodeGenerator.use
package:compiler_unsupported/src/ssa/codegen.dart 2987 SsaCodeGenerator.visitTypeInfoExpression
package:compiler_unsupported/src/ssa/nodes.dart 3365 HTypeInfoExpression.accept
package:compiler_unsupported/src/ssa/codegen.dart 661 SsaCodeGenerator.visit
package:compiler_unsupported/src/ssa/codegen.dart 667 SsaCodeGenerator.visitExpression
package:compiler_unsupported/src/ssa/codegen.dart 648 SsaCodeGenerator.use
package:compiler_unsupported/src/ssa/codegen.dart 538 SsaCodeGenerator.visitArguments
package:compiler_unsupported/src/ssa/codegen.dart 1827 SsaCodeGenerator.visitInvokeStatic
package:compiler_unsupported/src/ssa/nodes.dart 1667 HInvokeStatic.accept
package:compiler_unsupported/src/ssa/codegen.dart 661 SsaCodeGenerator.visit
package:compiler_unsupported/src/ssa/codegen.dart 667 SsaCodeGenerator.visitExpression
package:compiler_unsupported/src/ssa/codegen.dart 633 SsaCodeGenerator.define
package:compiler_unsupported/src/ssa/codegen.dart 1287 SsaCodeGenerator.iterateBasicBlock
package:compiler_unsupported/src/ssa/codegen.dart 1177 SsaCodeGenerator.visitBasicBlock
package:compiler_unsupported/src/ssa/codegen.dart 1434 SsaCodeGenerator.visitGoto
package:compiler_unsupported/src/ssa/nodes.dart 2181 HGoto.accept
package:compiler_unsupported/src/ssa/codegen.dart 661 SsaCodeGenerator.visit
package:compiler_unsupported/src/ssa/codegen.dart 1292 SsaCodeGenerator.iterateBasicBlock
package:compiler_unsupported/src/ssa/codegen.dart 1177 SsaCodeGenerator.visitBasicBlock
package:compiler_unsupported/src/ssa/codegen.dart 375 SsaCodeGenerator.visitGraph
package:compiler_unsupported/src/ssa/codegen.dart 90 SsaCodeGeneratorTask.generateMethod.
package:compiler_unsupported/src/common/tasks.dart 63 CompilerTask.measure
package:compiler_unsupported/src/ssa/codegen.dart 84 SsaCodeGeneratorTask.generateMethod
package:compiler_unsupported/src/ssa/codegen.dart 66 SsaCodeGeneratorTask.generateCode
package:compiler_unsupported/src/ssa/ssa.dart 43 SsaFunctionCompiler.compile
package:compiler_unsupported/src/js_backend/backend.dart 1548 JavaScriptBackend.codegen
package:compiler_unsupported/src/common/codegen.dart 243 CodegenWorkItem.run
package:compiler_unsupported/src/compiler.dart 866 Compiler.emptyQueue.....
package:compiler_unsupported/src/common/tasks.dart 176 CompilerTask.measureSubtask
package:compiler_unsupported/src/compiler.dart 866 Compiler.emptyQueue....
package:compiler_unsupported/src/common/tasks.dart 176 CompilerTask.measureSubtask
package:compiler_unsupported/src/compiler.dart 864 Compiler.emptyQueue...
package:compiler_unsupported/src/compiler.dart 1623 CompilerDiagnosticReporter.withCurrentElement
package:compiler_unsupported/src/compiler.dart 862 Compiler.emptyQueue..
package:compiler_unsupported/src/enqueue.dart 749 EnqueuerStrategy.processWorkItem
package:compiler_unsupported/src/js_backend/enqueuer.dart 452 CodegenEnqueuer.forEach
package:compiler_unsupported/src/compiler.dart 858 Compiler.emptyQueue.
package:compiler_unsupported/src/common/tasks.dart 176 CompilerTask.measureSubtask
package:compiler_unsupported/src/compiler.dart 857 Compiler.emptyQueue
package:compiler_unsupported/src/compiler.dart 886 Compiler.processQueue.
package:compiler_unsupported/src/common/tasks.dart 176 CompilerTask.measureSubtask
package:compiler_unsupported/src/compiler.dart 875 Compiler.processQueue
package:compiler_unsupported/src/compiler.dart 757 Compiler.compileLoadedLibraries.
package:compiler_unsupported/src/common/tasks.dart 176 CompilerTask.measureSubtask
package:compiler_unsupported/src/compiler.dart 646 Compiler.compileLoadedLibraries
package:compiler_unsupported/src/compiler.dart 554 Compiler.runInternal.

Build completed with 2 errors.

@alexeieleusis
Copy link
Contributor

You seem to be using https://github.com/dart-lang/compiler_unsupported have you tried with stable dart2js?

@sturmf
Copy link
Author

sturmf commented Feb 12, 2017

@alexeieleusis thanks for that info, I never saw that it printed compiler_unsupported! I wonder how that gets pulled in, I am using dart_to_js_script_rewriter: ^1.0.1 which I thought would be fine. Researching that now.

@sturmf
Copy link
Author

sturmf commented Feb 14, 2017

Hmm everything is now ported to the latest version. For completeness. This is my pubspec.yaml. Anything wrong with it that would pull in the unsupported compiler?

name: frontend
version: 0.0.1
description: Regatta frontend
author:
homepage: https://regatta.atlassian.net
documentation:

environment:
  sdk: '>=1.19.0 <2.0.0'

dependencies:
  angular2: 3.0.0-alpha
  angular2_components: 0.3.1-alpha
  reflectable: 1.0.1
  sass_transformer: 0.1.2+1
  greencat: 0.0.2
  browser: 0.10.0+2
  http: 0.11.3+9
  stream_transformers: 0.3.0+3

dev_dependencies:
  test: 0.12.19
  dart_to_js_script_rewriter: 1.0.2
  dart_style: 0.2.16
  pageloader: 2.2.5
  mockito: 1.0.1
  angular_test: 1.0.0-alpha+5

transformers:
  - angular2/transform/codegen:
      platform_directives:
        - 'package:angular2/common.dart#COMMON_DIRECTIVES'
      platform_pipes:
        - 'package:angular2/common.dart#COMMON_PIPES'
      entry_points: web/main.dart
      resolved_identifiers:
        BrowserClient: 'package:http/browser_client.dart'
        Client: 'package:http/http.dart'
  - angular2/transform/reflection_remover:
      $include:
        - test/**_test.dart
        - web/main.dart
  #- reflectable:
  #    entry_points:
  #      - web/main.dart
  #    formatted: true
  - test/pub_serve:
      $include: test/**_test.dart
  - dart_to_js_script_rewriter
  - sass_transformer

@sigmundch
Copy link
Member

@sturmf - you can ignore the compiler_unsupported bit - that's just because pub invokes dart2js by importing it using this package. It is however the same dart2js that got shipped with your SDK, as far as I know.

If you are really curious, you can confirm this by excluding dart2js from pub-build and running dart2js manually (e.g. by adding a transformer that skips dart2js:

- $dart2js:
    $include: []  # nothing goes through dart2js

), running pub build --mode debug to generate dart files in the build folder, and finally calling dart2js on the generated test/event_list_test.dart.browser_test.dart file by hand.

@rakudrama - looks like an issue related to our RTI encoding
https://github.com/dart-lang/sdk/blob/1.21.1/pkg/compiler/lib/src/ssa/codegen.dart#L2995

@rakudrama
Copy link
Member

Can you attach test/event_list_test.dart.browser_test.dart ?

@sturmf
Copy link
Author

sturmf commented Feb 15, 2017

Hmm I didn't figure out how to attach a file so here it is inline:

// Because Angular is using dart:html, we need these tests to run on an actual
// browser. This means that it should be run with `-p dartium` or `-p chrome`.
@Tags(const ['aot'])
@TestOn('browser')
import 'package:angular2/angular2.dart';
import 'package:angular_test/angular_test.dart';
import 'package:test/test.dart';

import 'package:angular2/router.dart';
import 'package:mockito/mockito_no_mirrors.dart';

import 'package:frontend/store/regatta_store.dart';
import 'package:frontend/components/event_list_component/event_list_component.dart';
import 'package:frontend/components/event_list_component/event_list_component_po.dart';
import 'package:frontend/models/event.dart';

// We have to wrap our component in a slim wrapper to resolve it with getInstance later
@Component(selector: 'test', directives: const [EventListComponent], template: '<my-event-list></my-event-list>')
class EventListTestComponent {}

@AngularEntrypoint()
void main() {
  tearDown(disposeAnyRunningTest);

  test('EventListComponent list contains dummy event', () async {
    final router = new MockRouter();
    final regattaStore = new MockRegattaStore();

    when(regattaStore.state.events).thenReturn({1: new Event(1, 'dummy url', 'Dummy Event')});

    final testBed = new NgTestBed<EventListTestComponent>().addProviders([
      provide(Router, useValue: router),
      provide(RegattaStore, useValue: regattaStore),
    ]);

    final fixture = await testBed.create();

    // Get a handle to the list.
    final pageObject = await fixture.resolvePageObject/*<EventListPO>*/(
      EventListPO,
    );

    final items = await pageObject.items;
    await expect(items, hasLength(1));
    await expect(await items[0].visibleText, equals('Dummy Event'));

    regattaStore.close();
  });
}

And this is the way I run it. Call pub serve in one terminal and pub run test -p dartium --pub-serve=8081

The source is also available here: https://github.com/sturmf/regatta-angular2/blob/REG-51-switch-to-redux-arc/frontend/test/event_list_test.dart

@zoechi
Copy link
Contributor

zoechi commented Feb 15, 2017

shouldn't the sass_transformer come before angular2?
Angular2 depends on the CSS files to exist.

@sturmf
Copy link
Author

sturmf commented Feb 27, 2017

@sigmundch Hmm I tried to create the transpiled file. But since it only gets created during the test run I didn't manage to get hold of it. Any ideas how I could get at it? What would the pubspec look like and do I do pub serve --mode debug or more?

@sigmundch
Copy link
Member

Mmm - good question, not sure, is the error above something you see in your pub-serve terminal or in your pub-run-test terminal?

If it is in the pub-serve terminal, then here is what you can do:

  • update pubspec to skip dart2js like this:
name: frontend
version: 0.0.1
description: Regatta frontend
author:
homepage: https://regatta.atlassian.net
documentation:

environment:
  sdk: '>=1.19.0 <2.0.0'

dependencies:
  angular2: 3.0.0-alpha
  angular2_components: 0.3.1-alpha
  reflectable: 1.0.1
  sass_transformer: 0.1.2+1
  greencat: 0.0.2
  browser: 0.10.0+2
  http: 0.11.3+9
  stream_transformers: 0.3.0+3

dev_dependencies:
  test: 0.12.19
  dart_to_js_script_rewriter: 1.0.2
  dart_style: 0.2.16
  pageloader: 2.2.5
  mockito: 1.0.1
  angular_test: 1.0.0-alpha+5

transformers:
  - angular2/transform/codegen:
      platform_directives:
        - 'package:angular2/common.dart#COMMON_DIRECTIVES'
      platform_pipes:
        - 'package:angular2/common.dart#COMMON_PIPES'
      entry_points: web/main.dart
      resolved_identifiers:
        BrowserClient: 'package:http/browser_client.dart'
        Client: 'package:http/http.dart'
  - angular2/transform/reflection_remover:
      $include:
        - test/**_test.dart
        - web/main.dart
  #- reflectable:
  #    entry_points:
  #      - web/main.dart
  #    formatted: true
  - test/pub_serve:
      $include: test/**_test.dart
  - dart_to_js_script_rewriter
  - sass_transformer

  ### extra transformer to skip dart2js:
  - $dart2js:
      $include: []  # nothing goes through dart2js
  ###

Instead of calling pub-serve, you can call pub-build in debug mode on the test folder:

pub build test --mode=debug

You should be able to see the file in build/test/. And a stand-alone version of dart2js will likely crash too:

dart2js build/test/event_list_test.dart.browser_test.dart

@sigmundch
Copy link
Member

Ok - turns out we can reproduce this even if we compile the test without running any transformers. It might be somethign that only comes up because of the use of dart:mirrors though (I noticed that the transformed program still contains calls to mirrors too).

Here is a repro with your current project - I yet have to reduce this further to a simple test case:

git clone git@github.com:sturmf/regatta-angular2.git
pub get
dart2js test/event_list_test.dart

@sigmundch
Copy link
Member

@rakudrama - here is a simpler repro, it still pulls the greencat dependency, but it's much smaller:

pubspec.yaml:

name: repro
dependencies:
  greencat: any

a.dart:

import 'dart:mirrors';
import 'package:greencat/greencat.dart';

void main() {
  reflectClass(Store);
}

repro:

pub get
dart2js a.dart

@sigmundch
Copy link
Member

And here is a standalone repro, with no dependencies:

import 'dart:mirrors';

typedef void F<T>(T value);
typedef F<T> Converter<T>(F<T> function);
typedef Converter<T> ConvertFactory<T>(int input);

class B<T> {
  final field = <ConvertFactory<T>>[];
}

void main() {
  reflectClass(B);
}

@rakudrama
Copy link
Member

Standalone repro without mirrors:

typedef void F<T>(T value);
typedef F<U> Converter<U>(F<U> function);
typedef Converter<V> ConvertFactory<V>(int input);

class B<W> {
  final field = <ConvertFactory<W>>[];
  B(){return;return;}
}

void main() {
  print(new B<int>().field.runtimeType);
}

The crash is because the type parameter for the list allocation, ConvertFactory<W>, when fully expanded as a tree, contains many references to W, whereas the inputs are expected to supply all type variables in the order present in the expansion.

e.g. if I change W to String, the above program on dart2js prints:

JSArray<(int) => ((String) => void) => (String) => void>

I see two ways to fix dart2js at this point:

  1. Keep the typedef terms in the type. This complicates the reified types but preserves typedef information.
  2. Expand typedefs in two steps - bind parameters and then generate the replacement that might share parameters.

I'm inclined to start with the second option, since kernel does not contain typedef nodes.

@asgerf dartk fully expands the typedefs, a potentially exponential operation. What is the plan for kernel for handling type terms that are DAGs? The dartk printout for the above program duplicates the inner function type, but is it not clear of this real duplication or a shared structure printed twice. For optimization, we want to do type algebra without the exponential expansion.

@asgerf
Copy link
Contributor

asgerf commented Apr 13, 2017

@rakudrama I've written up all the boilerplate for typedefs in kernel, but the frontend and backend work is not done. It will probably land next week.

rakudrama added a commit that referenced this issue Apr 13, 2017
The type Map<T, Foo<Set<T>>> contains one type variable referenced twice,
so there are two inputs into the HTypeInfoExpression instruction.

If Foo is a typedef, T can be reused, e.g.

    typedef E Foo<E>(E a, E b);

As the typedef is expanded (to Function(Set<T>, Set<T>) => Set<T>) it
should not consume additional types from the to-level input.  We
prevent this by capturing the types and using the captured type
expressions inside the typedef expansion.

TODO: We should make the type subexpression Foo<...> be a second
HTypeInfoExpression, with Set<T> as its input (a third
HTypeInfoExpression). This would share all the Set<T> subexpressions
instead of duplicating them. This would require HTypeInfoExpression
inputs to correspond to type variables AND typedefs.

BUG= #28749
R=efortuna@google.com

Review-Url: https://codereview.chromium.org/2812393003 .
@rakudrama
Copy link
Member

Fixed via d15da7d

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

No branches or pull requests

7 participants