halide / Halide

a language for fast, portable data-parallel computation
https://halide-lang.org
Other
5.91k stars 1.07k forks source link

Legal names of Vars, Funcs, etc should be well-defined/limited #4239

Open steven-johnson opened 5 years ago

steven-johnson commented 5 years ago

Currently, there are ~no limitations on legal identifiers for most Halide entities; setting some limits on them would make decisions about printing IR easier, and make future options for serializing IR more tractable.

Strawman proposal:

This would (probably) allow the vast majority of existing use cases with only minimal upgrade pain.

(We may also want to forbid $ in user-defined names, and reserve that for our internal use in uniquification.)

abadams commented 5 years ago

+1, except that the implicit vars _0, 1, etc already start with an underscore, so I don't think we can limit that. The DWARF-sniffing code will also name things according to their C-identifier, which may start with .

We could really use internal legal names that would not be legal as user-provided names, so that we can more conveniently namespace our internal stuff (e.g. the names returned by unique_name(char)). If we're maximally restrictive with user-provided names, then we always have the option of loosening up internal names later, so perhaps that doesn't need to be decided here.

steven-johnson commented 5 years ago

Strawman #2:

The gotcha here is that if we add a serializable IR in the future, the distinction between "internal" and "user-provided" becomes fuzzy-to-meaningless; we wouldn't want to have generated IR (which might contain $) illegal to parse back in.

abadams commented 5 years ago

You're right that user-provided names is not an adequately clean distinction in a world where people can say:

Func f1("f"), f2("f");
Func h(f2.name()); // has $ in it

Maybe in terms of invariants we just want a rule for valid identifiers in the IR, and we'll sanitize user-provided Func/Var/etc names in unique_name to map them into the space of unique valid identifiers however we like.