Elektrine lite

← Feed

@pervognsen@mastodon.social

Post #1985381

2026-04-28 04:01 UTC

The simplest version of the single-pass algorithm (with no support for subtyping) is that the first (in source order) assignment to a let variable fixes the variable's type and any other assignments to the same variable (necessarily on disjoint paths) check against that type. Anyway, I used to think that one objective advantage of expression-oriented initialization was its simpler interaction with type propagation, but this shows that isn't actually a real difference.

Replies (1)

  • @pervognsen@mastodon.social 2026-04-28 04:18

    Example: In C, ? : is annoying in a single-pass compiler because you have to go back and insert an int-to-double conversion at the end of the basic block, or more likely you use a shim basic block just for that conversion (which I believe is what tcc does), once you determine that the overall expression has type double. You have the same problems (and same solutions) when single-pass compiling the equivalent case with let assignments.

    Open ##1985382