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

在readComponent后直接writeComponentFile,报错,Reference to root::dart:collection is not bound to an AST node. A library was expected #18

Closed
ckdgit opened this issue Oct 11, 2019 · 4 comments

Comments

@ckdgit
Copy link

ckdgit commented Oct 11, 2019

在您的基础上尝试修改component时,read之后直接write就报错了.

Unhandled exception:
Reference to root::dart:collection is not bound to an AST node. A library was expected
#请教下是什么原因呢

Steps to Reproduce

1.void readComponent(Component component, {bool checkCanonicalNames: false})
2. void writeComponentFile(Component component)

Logs

Unhandled exception:
Reference to root::dart:collection is not bound to an AST node. A library was expected
#0      Reference.asLibrary (package:kernel/ast.dart:217:7)
#1      _PrivateName.library (package:kernel/ast.dart:4764:38)
#2      CanonicalName.getChildFromQualifiedName (package:kernel/canonical_name.dart:117:32)
#3      CanonicalName.getChildFromMember (package:kernel/canonical_name.dart:123:10)
#4      Class.computeCanonicalNames (package:kernel/ast.dart:917:21)
#5      Library.computeCanonicalNames (package:kernel/ast.dart:423:14)
#6      Component.computeCanonicalNamesForLibrary (package:kernel/ast.dart:5784:13)
#7      Component.computeCanonicalNames (package:kernel/ast.dart:5778:7)

Finally, paste the output of running flutter doctor -v here.

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, v1.5.4-hotfix.2, on Mac OS X 10.13.6 17G2208, locale zh-Hans-CN)
 
[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
[✓] iOS toolchain - develop for iOS devices (Xcode 10.1)
[✓] Android Studio (version 3.4)
[!] IntelliJ IDEA Ultimate Edition (version 2018.2.4)
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
[✓] Connected device (1 available)

@kangwang1988
Copy link
Contributor

@ckdgit
If you can reproduce this issue using the latest flutter and aspectd, I can have a look at it.
Besides please give a minimal self-contained demo project to reproduce it.

import 'package:args/args.dart';
import 'package:kernel/ast.dart';
import 'package:kernel/kernel.dart';

import '../transformer/transformer_wrapper.dart';
import '../util/dill_ops.dart';

const String _kOptionInput = 'input';
const String _kOptionOutput = 'output';
const String _kOptionSdkRoot = 'sdk-root';
Map<String,Library> libraryAbbrMap = Map<String, Library>();

int main(List<String> args) {
  final ArgParser parser = ArgParser()
    ..addOption(_kOptionInput, help: 'Input dill file')..addOption(
        _kOptionOutput, help: 'Output dill file')..addOption(_kOptionSdkRoot, help: 'Sdk root path');
  final ArgResults argResults = parser.parse(args);
  final String intputDill = argResults[_kOptionInput];
  final String outputDill = argResults[_kOptionOutput];
  final String sdkRoot = argResults[_kOptionSdkRoot];

  DillOps dillOps = new DillOps();
  Component component = dillOps.readComponentFromDill(intputDill);
//  Component platformStrongComponent = null;
//  if(sdkRoot != null) {
//    platformStrongComponent = dillOps.readComponentFromDill(sdkRoot+'platform_strong.dill');
//    for(Library library in platformStrongComponent.libraries){
//      libraryAbbrMap.putIfAbsent(library.name, ()=>library.reference.node);
//    }
//  }
//
//  for(CanonicalName canonicalName in component.root.children){
//    Library library = libraryAbbrMap[canonicalName.name];
//    library ??= libraryAbbrMap[canonicalName.name.replaceAll(':', '.')];
//    if(canonicalName.reference == null) {
//      canonicalName.reference = Reference()..node = library;
//    }
//    else if(canonicalName.reference.canonicalName != null && canonicalName.reference.node==null) {
//      canonicalName.reference.node = library;
//    }
//  }
//
//  TransformerWrapper transformerWrapper = new TransformerWrapper(platformStrongComponent);
//  transformerWrapper.transform(component);

  dillOps.writeDillFile(component, outputDill);
  return 0;
}

Works fine for me.

kylewong@KyleWongs-MacBook-Pro flutter % flutter doctor -v                                                         
[✓] Flutter (Channel master, v1.10.15-pre.121, on Mac OS X 10.15 19A583, locale en-CN)
    • Flutter version 1.10.15-pre.121 at /Users/kylewong/Codes/Flutter/flutter
    • Framework revision b857632306 (8 hours ago), 2019-10-15 00:07:32 -0700
    • Engine revision 540fc977bb
    • Dart version 2.6.0 (build 2.6.0-dev.7.0 70a7ef3f58)

@ckdgit
Copy link
Author

ckdgit commented Oct 17, 2019

yes,when I run it on version 1.9.1-4, that's right. but on 1.5.4, I got same error.
if I run with the code shown below, even on 1.5.4, it's ok. I don't know the reason, Do you have any good explanation?

 DillOps dillOps = new DillOps();
  Component component = dillOps.readComponentFromDill(intputDill);
  Component platformStrongComponent = null;
  if(sdkRoot != null) {
    platformStrongComponent = dillOps.readComponentFromDill(sdkRoot+'platform_strong.dill');
    for(Library library in platformStrongComponent.libraries){
      libraryAbbrMap.putIfAbsent(library.name, ()=>library.reference.node);
    }
  }

  for(CanonicalName canonicalName in component.root.children){
    Library library = libraryAbbrMap[canonicalName.name];
    library ??= libraryAbbrMap[canonicalName.name.replaceAll(':', '.')];
    if(canonicalName.reference == null) {
      canonicalName.reference = Reference()..node = library;
    }
    else if(canonicalName.reference.canonicalName != null && canonicalName.reference.node==null) {
      canonicalName.reference.node = library;
    }
  }
//
//  TransformerWrapper transformerWrapper = new TransformerWrapper(platformStrongComponent);
//  transformerWrapper.transform(component);

  dillOps.writeDillFile(component, outputDill);
  return 0;
}

@kangwang1988
Copy link
Contributor

@ckdgit
I see, some extra work is done in order to process the null reference issue. It's an old logic which is done based on about flutter 1.0 and be compatible with latest master.
As the kernel related api and it's logic behind might vary with flutter evolving, it might be the reason for your issue.

@kangwang1988
Copy link
Contributor

Duple of flutter/flutter#42497
Closing it now.

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

No branches or pull requests

2 participants