Skip to content

Error accessing static field from nested function. #39929

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
rbehrends opened this issue Dec 26, 2019 · 7 comments
Closed

Error accessing static field from nested function. #39929

rbehrends opened this issue Dec 26, 2019 · 7 comments
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. NNBD Issues related to NNBD Release vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked
Milestone

Comments

@rbehrends
Copy link

rbehrends commented Dec 26, 2019

This crash is a bit of a doozy, especially as it seems to occur only under very specific circumstances:

$ cat test.dart
class C {
  static List<int> list = List.filled(25, 0);

  void iter() {
    int item(int p) {
      return list[p];
    }
    for (int p = 0; p < 25; p++) {
      item(p);
    }
  }
}

void loop(int steps) {
  var c = C();
  for (int i = 0; i < steps; i++) c.iter();
}

void main() {
  loop(1000);
}
$ dart --version
Dart VM version: 2.8.0-dev.0.0 (Wed Dec 11 10:31:10 2019 +0100) on "macos_x64"
$ dart --enable-experiment=non-nullable --snapshot-kind=app-jit --snapshot=test.snap test.dart && dart --enable-experiment=non-nullable test.snap
Unhandled exception:
NoSuchMethodError: Closure call with mismatched arguments: function '[]'
Receiver: null
Tried calling: [](0)
#0      Object.noSuchMethod (dart:core-patch/object_patch.dart:53:5)
#1      C.iter.item (file:///private/tmp/test.dart:6:18)
#2      C.iter (file:///private/tmp/test.dart:9:11)
#3      loop (file:///private/tmp/test.dart:16:37)
#4      main (file:///private/tmp/test.dart:20:3)
#5      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
#6      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
$ dart --snapshot-kind=app-jit --snapshot=test.snap test.dart && dart test.snap

This bug happens only with --enable-experiment=non-nullable. It happens with dart 2.7.0 and 2.8.0-dev.0.0, but not with dart 2.6.1, and only when generating an app-jit snapshot, not during normal execution.

If you reduce the loop argument enough, eventually the bug also disappears.

If you make the list field non-static, the bug disappears.

If you remove the for loop in iter(), the bug also disappears.

I can trigger the bug on both macOS & Linux.

Edit: reduced the example a bit more and narrowed the conditions where it happens further.

@rbehrends rbehrends changed the title Error accessing static final field that is initialized via a temporary closure. Error accessing static field. Dec 27, 2019
@rbehrends rbehrends changed the title Error accessing static field. Error accessing static field from nested function. Dec 28, 2019
@devoncarew devoncarew added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. NNBD Issues related to NNBD Release labels Dec 30, 2019
@mkustermann
Copy link
Member

@rbehrends Please notice that NNBD is still in implementation phase in the VM.

/cc @crelier @a-siva

@crelier
Copy link
Contributor

crelier commented Jan 2, 2020

@liamappelbe, could this be related to your recent work on late fields?

@rbehrends
Copy link
Author

Please notice that NNBD is still in implementation phase in the VM.

Yeah, I know that. I reported it anyway, because it didn't look like something that was simply a gap in the implementation (unlike, say, type inference for map[x] ?? y breaking with NNBD).

@a-siva
Copy link
Contributor

a-siva commented Jan 3, 2020

Strange that the error happens only when running from the generated app-jit snapshot, are we not serializing some field or NNBD info into the snapshot?

@crelier
Copy link
Contributor

crelier commented Jan 3, 2020

I am not able to reproduce this issue on linux with the latest build.
Note that we have put safeguards in place recently making sure that the platform dill is consistent in regards to NNBD. In other words, you will be prevented to specify --enable-experiment=non-nullable on a platform not built for it.

Here are my steps:

rm -rf out
./tools/gn.py --mode=debug,release --arch=x64 --nnbd
./tools/build.py --mode=debug --arch=x64 runtime --nnbd
out/DebugX64NNBD/dart --enable-experiment=non-nullable --snapshot-kind=app-jit --snapshot=test.snap test.dart
out/DebugX64NNBD/dart --enable-experiment=non-nullable test.snap

No error reported.

Note that if use a non-nnbd version of dart, I get an error:

out/DebugX64/dart --enable-experiment=non-nullable --snapshot-kind=app-jit --snapshot=test.snap test.dart
VM initialization failed: Snapshot not compatible with the current VM configuration: the snapshot requires 'debug no-dwarf_stack_traces use_bare_instructions' but the VM has 'debug no-dwarf_stack_traces use_bare_instructions nnbd-experiment'

Could that be the problem here?

BTW, @liamappelbe, it looks like the error message has the required and expected features swapped, no?

@crelier
Copy link
Contributor

crelier commented Jan 3, 2020

BTW, @liamappelbe, it looks like the error message has the required and expected features swapped, no?

Never mind, I was not reading the error message correctly. "Snapshot" in the error message does not refer to the snapshot we are trying to generate (requiring nnbd), but to the platform snapshot (missing nnbd) that the VM is running on.

@a-siva a-siva added the vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked label Jan 16, 2020
@franklinyow franklinyow added this to the D28 Release milestone Jan 21, 2020
@a-siva
Copy link
Contributor

a-siva commented Feb 12, 2020

Tried the test on bleeding edge and it works.

@a-siva a-siva closed this as completed Feb 12, 2020
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. NNBD Issues related to NNBD Release vm-nnbd-unfork-sdk Label for all issues that need to be done before the nnbd sdk can be unforked
Projects
None yet
Development

No branches or pull requests

7 participants