quantified-uncertainty / squiggle

An estimation language
https://squiggle-language.com
MIT License
148 stars 22 forks source link

Specification Tags with References Breaks #3111

Closed OAGr closed 3 months ago

OAGr commented 4 months ago

Description of suggestion or shortcoming:

image

spec = Spec.make(
  {name: "rst", documentation: "rstrts", validate: {|e| e} }
)

@spec(spec)
foo = 3

Interestingly enough, this below works:

@specification(Specification.make(
  { title: "My spec", validate: {|e| e}, showAs: {|e| e + 100} }
))
foo = 3
OAGr commented 4 months ago

Hm... getting weird errors:

image
dontUseThisVar = 34

spec1 = Spec.make(
  {name: "rst", documentation: "rstrts", validate: {|f| f} }
)

spec1_copy = spec1

@spec(spec1)
bar = 3

Here, it seems to think the spec1 reference refers to dontUseThisVar.

However, in this case, when I make a copy of spec1, it works:

dontUseThisVar = 34

spec1 = Spec.make(
  {name: "rst", documentation: "rstrts", validate: {|f| f} }
)

spec1_copy = spec1

@spec(spec1_copy)
bar = 3
image
OAGr commented 4 months ago

I did some more digging. Seems like the following fails:

name = "MyName"

@name(name)
foo = 3

When I run testCompile on it, I get:

['(Assign name "MyName")', "(Assign foo (Call Tag.name 3 (StackRef 1)))"]

The problem is that it's using StackRef 1 instead of StackRef 0. This is a mistake.

Looking back, v0.9.3 seems fine. It seems like this bug was introduced in this PR: https://github.com/quantified-uncertainty/squiggle/pull/3054

Which makes sense, as it did change a lot of code around this area.

With a bit more digging, it seems likely like the problem is with compile.ts. specifically around the DecoratedStatement case. I'm not sure how to fix it though, tried a few things, nothing really helped (without breaking other stuff). It would take me much longer to fully understand.