Missed incremental update of collections on adding to list child

Issue #302 resolved
Jesper Öqvist created an issue

I tried making a small collection attribute collecting C nodes belonging to B nodes (direct children). When starting with empty B nodes and adding new C nodes only one of the collection attributes is incrementally flushed for some reason.

The relevant parts of the test:

aspect Test {
  inh B C.b();
  eq B.getC().b() = this;

  coll HashSet<C> B.cs() root A;

  C contributes this
      to B.cs()
      for b();
}
  public static void main(String[] args) {
    int N = 10;
    A a = new A();
    for (int i = 0; i < N; ++i) {
      a.addB(new B("b"+i, new List<C>()));
    }

    checkCollections(a, "before");

    // Transform:
    a.getB(0).addC(new C("c1"));
    a.getB(3).addC(new C("c2"));
    a.getB(3).addC(new C("c3"));
    a.getB(5).addC(new C("c4"));

    checkCollections(a, "after");
  }

  static void checkCollections(A a, String phase) {
    for (int i = 0; i < a.getNumB(); ++i) {
      testEqual(phase + "@" + a.getB(i).getNAME(), a.getB(i).getNumC(), a.getB(i).cs().size());
    }
  }

Test output:

Test failed. after@b3 Expected: <2>, was: <0>
Test failed. after@b5 Expected: <1>, was: <0>

Comments (4)

  1. Jesper Öqvist reporter

    Fix errors in incremental collection attributes

    Improve dependency tracking and flushing for incremental collection attributes by treating the survey phase as an attribute with its own dependency graph node. This makes all collection attribute instances depend on the survey phase and any change which flushes the survey results leads to flushing all collection attribute instances as well.

    fixes #302 (bitbucket) fixes #303 (bitbucket)

    → <<cset 7938671b06a8>>

  2. Log in to comment