{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/15819","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/15819/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/15819/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/15819/events","html_url":"https://github.com/rust-lang/rust/issues/15819","id":38250660,"number":15819,"title":"Consider an AST validation function/pass to assist with debugging user-defined macros","user":{"login":"huonw","id":1203825,"avatar_url":"https://avatars.githubusercontent.com/u/1203825?v=3","gravatar_id":"","url":"https://api.github.com/users/huonw","html_url":"https://github.com/huonw","followers_url":"https://api.github.com/users/huonw/followers","following_url":"https://api.github.com/users/huonw/following{/other_user}","gists_url":"https://api.github.com/users/huonw/gists{/gist_id}","starred_url":"https://api.github.com/users/huonw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/huonw/subscriptions","organizations_url":"https://api.github.com/users/huonw/orgs","repos_url":"https://api.github.com/users/huonw/repos","events_url":"https://api.github.com/users/huonw/events{/privacy}","received_events_url":"https://api.github.com/users/huonw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-diagnostics","name":"A-diagnostics","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-plugin","name":"A-plugin","color":"d7e102"},{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-syntaxext","name":"A-syntaxext","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-07-20T04:20:19Z","updated_at":"2015-01-12T23:37:53Z","closed_at":null,"body":"There's a variety of invariants in the AST, e.g. the `Expr` in a `PatLit` should (AFAIK) be an `ExprLit`, and the  `Option<Expr>` in an `ExprIf` should be either a `ExprBlock` or `ExprIf`. It would be convenient if the compiler either had a AST validation pass run after macro expansion (could include verifying that there are no macros left in the AST), a validation function called on the resulting AST after each macro is expanded or just a series of manual functions that syntax extension authors can call on the code they generate to help debugging.\r\n\r\n(The first two should, IMO, be opt-in, since most users won't want to be wasting the compilation time on something that *should* never trigger if they're not writing their own macros.)"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/69669000","html_url":"https://github.com/rust-lang/rust/issues/15819#issuecomment-69669000","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/15819","id":69669000,"user":{"login":"kmcallister","id":444997,"avatar_url":"https://avatars.githubusercontent.com/u/444997?v=3","gravatar_id":"","url":"https://api.github.com/users/kmcallister","html_url":"https://github.com/kmcallister","followers_url":"https://api.github.com/users/kmcallister/followers","following_url":"https://api.github.com/users/kmcallister/following{/other_user}","gists_url":"https://api.github.com/users/kmcallister/gists{/gist_id}","starred_url":"https://api.github.com/users/kmcallister/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kmcallister/subscriptions","organizations_url":"https://api.github.com/users/kmcallister/orgs","repos_url":"https://api.github.com/users/kmcallister/repos","events_url":"https://api.github.com/users/kmcallister/events{/privacy}","received_events_url":"https://api.github.com/users/kmcallister/received_events","type":"User","site_admin":false},"created_at":"2015-01-12T23:37:53Z","updated_at":"2015-01-12T23:37:53Z","body":"It seems like this could be a lint, although we may need a way to run it earlier in the pipeline.  That opens up the possibility of reusing some of the machinery in plugins to enforce style and code structure.  Perhaps there's a nice declarative language for describing valid and invalid AST shapes.\r\n\r\n> The first two should, IMO, be opt-in, since most users won't want to be wasting the compilation time on something that *should* never trigger if they're not writing their own macros.\r\n\r\nMy hunch is that the compile time won't be significant, unless our invariants are *really* complex.  Converting the lint system from one pass to several dozen increased the compile time for librustc (before it was split up) by about half a second.  It's hard to do anything syntax-focused that takes significant time compared to trans and LLVM."}}