mcoblenz / Obsidian

Obsidian language development
BSD 3-Clause "New" or "Revised" License
77 stars 10 forks source link

double check the output of TraceThis.obs #434

Open ivoysey opened 2 years ago

ivoysey commented 2 years ago

the TraceThis test produces -2438. sketched out in Python,

class IntContainer:
    def __init__(self):
        self.x = 0

    def set(self, new):
        self.x = new

    def get(self):
        return self.x

class IntContainerBox:
    def __init__(self):
        self.ic1 = IntContainer()
        self.ic2 = IntContainer()
        self.ic3 = IntContainer()

    def set3(self, new1, new2, new3):
        self.ic1.set(new1)
        self.ic2.set(new2)
        self.ic3.set(new3)

    def getsum(self):
        return self.ic1.get() + self.ic2.get() + self.ic3.get() + 4

class IntContainerBoxBag:
    def __init__(self):
        self.icb1 = IntContainerBox()
        self.icb2 = IntContainerBox()

    def set2(self, arg1, arg2, arg3):
        self.icb1.set3(arg1 * arg1, arg2 * arg2, arg3 * arg3)
        self.icb2.set3(arg1 + arg1, arg2 + arg2, arg3 + arg3)
        print(f"inner: {self.icb1.getsum()}, {self.icb2.getsum()}")

    def get(self):
        return self.icb1.getsum() - self.icb2.getsum()

ic1 = IntContainerBoxBag()
ic1.set2(5, 20, -19)

ic2 = IntContainerBoxBag()
ic2.set2(500, 0, 1219)

print(ic1.get() + ic2.get())

the same test produces 1733297. i am more confident that the python version is correct, so i think this is a sign of a bug. nothing crashes during a run of that test case, just the answer is wrong.

one first step would be to run it on the Fabric framework and see what the answer is there, which i don't know how to do immediately.

ivoysey commented 2 years ago

i removed this test case from the JSON listing in https://github.com/mcoblenz/Obsidian/pull/430. prior to that PR, it would run and produce a bad answer (as above). now it runs out of gas. there are a few reasons this could be happening -- it could actually just be running out of gas; i have recently learned that that output can mean mload is getting run on an address out of range, too, which is more likely here.

the description of the test is here:

        {
            "file": "TraceThis.obs",
            "expected": "-2438",
            "shows_that_we_support": "emitting tracers and default constructors for more complicated nestings of objects. note that this emits 30 log messages between deployment and invocation; they look right but haven't been checked carefully"
        }

note that expected ought to be 1733297