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

Dart 2.5.0-dev.1.0 in AOT mode strange behavior annotation with Function reference #37656

Closed
hpoul opened this issue Jul 28, 2019 · 3 comments
Closed
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@hpoul
Copy link

hpoul commented Jul 28, 2019

I was debugging a crash which only occurred in release mode in a flutter application on master channel, but not in stable. I was now able to reproduce the problem in AOT mode in dart 2.5, but it works in dart VM jit mode and dart 2.4.
It seems the AOT compiler does something weird when a property is annotated with a Function reference (even if this function reference is never accessed).

I have reduced the problem to the following code:

class SomeTestAnnotation {
  const SomeTestAnnotation({this.fromJson});
  final Function fromJson;
}

class SomeClass {
  SomeClass() : someValue = 'initial value' {}

  @SomeTestAnnotation(fromJson: idConvert)
  String someValue;

  static String idConvert(dynamic jsonValue) => '';
}

void main() {
  print('creating instance.');
  final a = SomeClass();
  print('a: ${a.someValue}');
  a.someValue = 'updated value';
  print('a: ${a.someValue}');
  print('finished');
}

expected behavior in dart VM:

Herbys-MacBook-Pro-2017:lib$ dart another_try.dart
creating instance.
a: initial value
a: updated value
finished

but when using AOT the value of the property is still null:

Herbys-MacBook-Pro-2017:lib$ dart2aot another_try.dart another_try.dart.aot
Herbys-MacBook-Pro-2017:lib$ dartaotruntime another_try.dart.aot
creating instance.
a: null
a: updated value
finished

The problem goes away when either:

  • Remove the annotation completely
  • just the function reference
  • use a top level function reference like @SomeTestAnnotation(fromJson: print)

Because of some reason the value used during initialization is not assigned to the property? When this is used inside a more complicated code (I have used the json_serializable package to generate json deserialization code) it even crashes the AOT runtime with a segfault:

===== CRASH =====
si_signo=Segmentation fault: 11(11), si_code=1, si_addr=0xbb
Abort trap: 6

i am using mac os with the latest dart 2.5 dev version from homebrew (but since i stumbled onto this crash also on iOS and Android, i'm pretty sure it's not limited to the mac build):

Herbys-MacBook-Pro-2017:lib$ dart --version
Dart VM version: 2.5.0-dev.1.0 (Tue Jul 9 15:27:01 2019 +0200) on "macos_x64"

I haven't found any issue tracking this problem, and i realise this is still in development, so feel free to close it if it's redundant.

@mraleph
Copy link
Member

mraleph commented Jul 28, 2019

@alexmarkov does this ring a bell? This does not reproduce on master HEAD - so it might be fixed.

@mraleph mraleph added area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 28, 2019
@megadrazz
Copy link

e muito relato de problemas esse dart isso ta atrasando a vida de qualquer um!!! aqui da error de mais mano vou migra pra outro fui..

@alexmarkov
Copy link
Contributor

Bisected this bug: the problem appeared since b32d196, and was fixed in 6312030.

It's likely a duplicate to #37544. The fix 6312030 added a check for recursive finalization when reading fields; without that check compiler could see fresh non-finalized fields with invalid offsets (if annotation on a field caused recursive finalization of the current class).

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, FFI, and the AOT and JIT backends. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants