You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the builder macros rely on a particular lexical environment.
For example
typeql_lang::typeql_define()// will expand toTypeQLDefine::new(vec![])
requiring the user to have TypeQLDefine in the lexical environment.
This is a problem because it lets users do this sort of thing:
structTypeQLDefine;implTypeQLDefine{fnnew(Vec<typeql_lang::pattern::Definable>) -> Self{Self}}// somewhere where that TypeQLDefine is in scope...typeql_define!(my_type, my_rule)// <-- this line doesn't error
This is a minimal example, but you can see where major problems can arise.
Proposed Solution
Using proper rust macro hygiene fixes this issue, by expanding to fully qualified identifiers.
To fix the define query, for example, is as simple as replacing it with
## What is the goal of this PR?
The problem is described in #298: we have macros that need access to other
items in our crate. Paths to these items were not absolute, and users
had to import that particular items and were able to use their own
objects with the same names and use it in the macros. Now all paths are
absolute, based on the `$crate` metavariable.
## What are the changes implemented in this PR?
- We updated all macros that need access to other items in the crate.
- We removed redundant imports.
closes#298
Problem to Solve
Currently the builder macros rely on a particular lexical environment.
For example
requiring the user to have
TypeQLDefine
in the lexical environment.This is a problem because it lets users do this sort of thing:
This is a minimal example, but you can see where major problems can arise.
Proposed Solution
Using proper rust macro hygiene fixes this issue, by expanding to fully qualified identifiers.
To fix the define query, for example, is as simple as replacing it with
With this we have
Read more on macro hygiene at: https://veykril.github.io/tlborm/decl-macros/minutiae/hygiene.html
The text was updated successfully, but these errors were encountered: