Renumber AST nodes after expansion

After expansion, fold and renumber AST nodes to ensure that each AST node has  a
unique id. Fixes numerous bugs in macro expansion and deriving. Add two
representative tests.

Fixes #7971
Fixes #6304
Fixes #8367
Fixes #8754
Fixes #8852
Fixes #7654

r? @brson