Skip to content

FFI and Incremental compiler doesn't work together #39840

Closed
@jensjoha

Description

@jensjoha

Because the FFI transformation changes the interface, and the way the CFE works, using FFI together with the incremental compiler doesn't work, and crashes.

This is an overview of what happens (example):

  • We have 2 files, main.dart and lib.dart:
    main.dart:
import 'lib.dart';

main() {
    Coordinate coordinate = new Coordinate.allocate(42.0, 42.0, null);
    print(coordinate.x);
    print(coordinate.y);
    print(coordinate.next);
}

lib.dart

import 'dart:ffi';

class Coordinate extends Struct {
    @Double()
    double x;

    @Double()
    double y;

    Pointer<Coordinate> next;

    factory Coordinate.allocate(double x, double y, Pointer<Coordinate> next) {
    return null;
    }
}
  • We first compile and everything is basically fine. The fields in lib.dart has been replaced though, and internally the CFE builder representing it / that initially build it, now has an inconsistent view of the world.
  • We update main.dart and thus recompile it. Nothing imports main.dart so only main.dart needs to be rebuild. When doing that, type inference looks at "x", finds (via the builder in CFE) the now-removed field, tries to get the class it's in (via the field itself, namely the parent pointer), gets a null value and crashes when it tries to use it.

Even if it hadn't crashed, it would have pointed to something wrong (the basically non-existing field).

I will create a test and point to and from this issue.

Metadata

Metadata

Assignees

Labels

area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.legacy-area-front-endLegacy: Use area-dart-model instead.library-ffi

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions