Mark vars in AST of ||, &&, if, and unless as generated#15328
Mark vars in AST of ||, &&, if, and unless as generated#15328arnodirlam wants to merge 1 commit intoelixir-lang:mainfrom
Conversation
|
Thank you @arnodirlam. Can you please explain when/why this change would be necessary? |
|
I originally stumbled upon this in my library dx, which transforms the fully expanded AST of a module into something new (same approach as nx). In particular, it matches the fully-expanded AST of code that originally was a And, to me, it seems like a mismatch being introduced there, because some instances of the generated I don't know all the repercussions of adding a |
|
You should not expect the different metadata nodes to be equal, even for the same var. the only expectation is that they will have the same counter or name-context pair (or version, if matching on stored definitions). Matching on macro output will have subtleties like this, because the expansion of a macro is not guaranteed to be compatible. my suggestion is to replace && in the host code, like Nx replaces Kernel operators by its own, so it can more reliably match on shape. |
Commit 19c628a introduced a private AST helper
Kernel.x_is_false_or_nil/0to addgenerated: trueto a generated variablexin generated guards for of ||, &&, if, and unless (diff).However, the variable
x, on which the guards refer to, is not marked asgenerated: true, and thus has a different AST signature.For reference, see this diff (expand to see lines 1070-1135).
This PR fixes this by adding another private AST helper
Kernel.x_var/0to addgenerated: trueto the generated variablesxas well.