Typed globals: macro to define multiple, without manual type annotations

Ah, found what I was originally thinking of: it’s the “@stable” macro by @giordano in the Seven Lines of Julia thread:

Simeon’s is a bit robuster indeed, with the $tmp.

@simeonschaub I was also wondering, why the Base.mapany (and not just map)?

EDIT: I found why here (in the SnoopCompile docs) (maybe):

mapany avoids trying to narrow the type of f(v[i]) and just assumes it will be Any, thereby avoiding invalidations of many convert methods.

So, it’s used to spare the compiler some type inference work and/or to avoid convert invalidations, I think

The final thing I wonder about is the @nospecialize:
all Exprs are the same type, so there is no “too many specializations” problem right?

Like, why not say rewrite_assignment(ex::Expr).
And why the Meta.isexpr(ex, …) instead of just ex.head == …?

Ah, these are to handle LineNumberNodes, I assume.

Still, how is the @nospecialize useful?

1 Like