temperlang / temper

3 stars 0 forks source link

Bogus `hs` handling for automatic getter #157

Open tjpalmer opened 3 months ago

tjpalmer commented 3 months ago

For functional-test-suite/.../mutually-referencing-types.temper.md, this code:

console.log(
  "emptyFoo.x has Foo -> ${
    (emptyFoo.x != null).toString()
  }"
);

Becomes this tmpl, which shouldn't have hs in it:

var t#53: Bar__1 | Null;
module init {
  t#53 = hs (fail#41, emptyFoo__8.x);
  if (fail#41) {
    abortLoad;
  }
  (inline nym`Console::log`)(t#73, (inline StrCat)("emptyFoo.x has Foo -> ", (inline nym`Boolean::toString`)((inline BooleanNegation)((inline IsNull)(t#53)))));
}

The frontend tree already has it, too, and there's some hs inside the non-bubbly generated getter in the frontend also:

(Call
  (V nym`=`)
  (L getx__21)
  (Fun
    (Decl (L this__22) (V \impliedThis) (V Bar__1) (V \type) (V Bar__1))
    (V \returnDecl)
    (Decl (L return__23) (V \type) (V Foo__0 | Null) (V \ssa) (V void))
    (V \stay)
    (S)
    (Block
      (stmt-block
        (Decl (L fail#32) (V \var) (V void) (V \fail) (V void) (V \ssa) (V void))
        (Call
          (V hs)
          (L fail#32)
          (Call
            (V nym`=`)
            (L return__23)
            (Call (V getp) (R x__16) (R this__22))))
        (if (R fail#32)
          (stmt-block
            (Call (V bubble)))
          (stmt-block)))))

Tmpl translation seems to figure out the fail is always false, but it still carries along some willingness to return failure:

get.x -> getx__21(this = this__22, this__22: Bar__1): Foo__0 | Null {
  let return__23: Foo__0 | Null;
  @fail var fail#32: Boolean;
  fail#32 = false;
  return__23 = /* this */ this__22.x__16;
  if (fail#32) {
    return failure;
  }
  return return__23;
}

Really, none of this should be bubbly.