flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.15k stars 151 forks source link

Refactor Namer #7875

Closed magnus-madsen closed 2 months ago

magnus-madsen commented 3 months ago

Each in separate PR:

Try keep local variables, e.g. if the code is:

    case DesugaredAst.Expr.IfThenElse(exp1, exp2, exp3, loc) =>
      val e1 = visitExp(exp1, ns0)
      val e2 = visitExp(exp2, ns0)
      val e3 = visitExp(exp3, ns0)
      mapN(e1, e2, e3) {
        NamedAst.Expr.IfThenElse(_, _, _, loc)
      }

then it simply becomes

    case DesugaredAst.Expr.IfThenElse(exp1, exp2, exp3, loc) =>
      val e1 = visitExp(exp1, ns0)
      val e2 = visitExp(exp2, ns0)
      val e3 = visitExp(exp3, ns0)
      NamedAst.Expr.IfThenElse(e1, e2, e3, loc)

Note: Don't inline the visitExp calls.

Keep the structure: don't make other changes during the refactor.

If during the refactor a validation is needed, just do Validation.success(foo). This keeps each PR clean.

If you see code without local variables, e.g.:

    case DesugaredAst.Expr.FixpointInject(exp, pred, loc) =>
      mapN(visitExp(exp, ns0)) {
        case e => NamedAst.Expr.FixpointInject(e, pred, loc)
      }

please introduce them, e.g. here we would have an e.

magnus-madsen commented 3 months ago

Enjoy your work by seeing how much prettier direct-style is, and seeing if --Xbenchmark-phases improves. (I expect 2x improvement!)

jaschdoc commented 3 months ago