4 ms·
My understanding is that the BEAM vm already has some (optional) runtime typechecks in the form of guards, which this new typesystem will also add for you autom
by bo0tzz 2y ago
My understanding is that the BEAM vm already has some (optional) runtime typechecks in the form of guards, which this new typesystem will also add for you automatically. And that these guards are actually used to speed things up, for example by JITing more optimized code.
- throwawaymaths 2y agoSo inserting those type checks automatically will cause regressions because those checks are not free at runtime, and there are cases where the JIT will look at the code and not bother optimizing.
- dub_gui 2y agoTo clarify, the type-checker does not modify compilation to the beam at all. Instead, it takes into account the predicted runtime checks to inject more static types into its analysis. For instance, without even introducing annotations, if a function head has a guard `is_boolean(x)`, using the + operator on x within that function would lead to a type error.
- throwawaymaths 2y agoexactly. The potential performance regression of guards is exactly why the elixir typechecker doesn't insert them. I guess I hadn't made that point clear in my comment. IIRC The elixir guides talks about excessive typechecking being a code smell.