jdkaplan / blis

Hobby programming language to learn interpreter techniques
Other
6 stars 1 forks source link

test failure: tests::test_programs::path_14_test_programs_objects_blis ... FAILED #1

Open ttiimm opened 4 months ago

ttiimm commented 4 months ago

Saw the following issue on checkout and running cargo test.

---- tests::test_programs::path_14_test_programs_objects_blis stdout ----
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Snapshot Summary ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Snapshot file: src/snapshots/blis__tests__test_programs__objects.blis.stdout.snap
Snapshot: test_programs/objects.blis.stdout
Source: src/lib.rs:62
Input file: test_programs/objects.blis
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
func main() {
    let one = Counter.new("uno");
    let two = Counter.new("dos");

    println(one);
    println(one.id, one.name);

    println(two);
    println(two.id, two.name);

    // Eventually, gradual typing will let you prevent this. But for now...
    one.two = two;
    two.one = one;

    println(one.two);
    println(one["two"]);
    println(two.one);
    println(two["one"]);

    println(Counter.new);
    println(one.incr);
    println(one.add);
    println(two.incr);
    println(two.add);
}

let id = 0;

type Counter with {
    func new(name) {
        id = id + 1;

        Counter {
            id = id,
            name = name,
            count = 0,
        }
    }

    func self.incr() {
        self.add(1);
    }

    func self.add(delta) {
        self.count = self.count + delta;
    }
}

main();

─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
-old snapshot
+new results
────────────┬────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
    8     8 │ <closure new 0x000000000002>
    9     9 │ <bound method incr 0x000000000004>
   10    10 │ <bound method add 0x000000000005>
   11    11 │ <bound method incr 0x000000000006>
   12       │-<bound method add 0x000000000007>
         12 │+<bound method add 0x000000000006>
────────────┴────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
ttiimm commented 4 months ago

Ahh, did I need to run with the gc_tombstone feature? eg. cargo test --features='gc_tombstone'?

jdkaplan commented 4 months ago

Ahh, did I need to run with the gc_tombstone feature? eg. cargo test --features='gc_tombstone'?

Yup, that's it! I usually run cargo make test to get this task because I'm reviewing snapshots. (You can get the cargo make subcommand via cargo-run-bin configured in this repo or from cargo-make itself.)

Those instructions will definitely go in the contributor guide that I've (slowly :sweat_smile:) been working on. But for now, here's a quick explanation of what's happening:

The snapshots only work as test data if they're deterministic and reproducible. Since objects currently print as their memory locations, I chose to rewrite those IDs into small integers.

But then the garbage collector shows up! The gc_tombstone feature changes the GC to not reuse freed memory. Instead of releasing the memory, it replaces the contents with a special "tombstone" object that panics if it ever gets used. That way, object IDs (memory addresses) never get reused, and we can uniquely identify any object printed in the tests.


I'll leave this open as a reminder to at least one of these things: