The interface for cloning a module was made significantly more complex in https://dawn-review.googlesource.com/c/tint/+/35502/ as some of the transforms required constructing symbols before the clone. This was temporary solution in 35502 was to copy the symbol table, then construct the new types, then perform the clone. This lead to a really messy callback interface, that was extremely error prone (e.g. lamda-capturing stack variables from the initializer callback that had been unwound).
Instead, clone the symbols as they're encountered. This may produce an entirely different set of identifiers, but no longer ever-grows the symbol list, and keeps the interface clean.
Bug: tint:396
Bug: tint:390
Change-Id: I54affd68ac3b730b649af9b47eba685c8a1d784a
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/35663
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
ReplaceAll() registers `replacer` to be called whenever the Clone() method is called with a type that matches (or derives from) the type of the first parameter of `replacer`.
`replacer` must be function-like with the signature: `T* (T*)`, where `T` is a type deriving from CastableBase.
If `replacer` returns a nullptr then Clone() will attempt the next registered replacer function that matches the object type. If no replacers match the object type, or all returned nullptr then Clone() will call `T::Clone()` to clone the object.
Example:
```
// Replace all ast::UintLiterals with the number 42
CloneCtx ctx(mod);
ctx.ReplaceAll([&] (ast::UintLiteral* in) {
return ctx.mod->create<ast::UintLiteral>(ctx.Clone(in->type()), 42);
});
auto* out = ctx.Clone(tree);
```
This is to be used by Transforms that want to replace parts of the AST on clone.
Bug: tint:390
Change-Id: I80a0e58aa3711f309f58a504f6b6a06f6c546ea1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/34568
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>