Skip to content

Don't print out builtin macro definitions with --emit-clang-ast #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
fitzgen opened this issue Feb 4, 2017 · 17 comments
Closed

Don't print out builtin macro definitions with --emit-clang-ast #476

fitzgen opened this issue Feb 4, 2017 · 17 comments

Comments

@fitzgen
Copy link
Member

fitzgen commented Feb 4, 2017

There are a lot of builtin macros that clutter up our AST dump output, and we never actually care about them.

We should skip printing them in clang::ast_dump.

Basically, if cursor.kind() == CXCursor_MacroDefinition && cursor.location() == "builtin definition", then we should skip dumping this cursor's AST.

Happy to mentor whoever picks this up, and clarify further!

@highfive
Copy link

highfive commented Feb 4, 2017

Please make a comment here if you intend to work on this issue. Thank you!

@tsliang
Copy link

tsliang commented Feb 7, 2017

@fitzgen I'd be happy to take a look. I'll check out clang::ast_dump tonight and see if I have any questions about what I should do.

@emilio
Copy link
Contributor

emilio commented Feb 7, 2017

Awesome! Let us know if you need any help!

@jdm
Copy link
Contributor

jdm commented Feb 23, 2017

@tsliang Have you made any progress with this?

@tsliang
Copy link

tsliang commented Feb 24, 2017

@jdm unfortunately not - I've been extremely sick for the last two weeks. I'm going to work on it this weekend.

@tsliang
Copy link

tsliang commented Feb 26, 2017

@jdm @fitzgen

I'm implementing the skip inside the print_cursor subfunction within ast_dump (is this the right place for it btw?). How would you recommend checking whether a cursor is a builtin definition? SourceLocation::Display outputs the literal "builtin definitions," but is there a way to determine a builtin definition that doesn't rely on checking a string literal?

@emilio
Copy link
Contributor

emilio commented Feb 27, 2017

Hi @tsliang!

First of all, hope you're better now :)

See the fn filter_builtins in src/lib.rs for an example of how we filter builtins during parsing. It'd be ideal to share code for both.

Thanks for working on this! :)

@tsliang
Copy link

tsliang commented Mar 2, 2017

@emilio thanks for the kind words! I am indeed feeling better :)

Thanks for the tip about fn filter_builtins. I like the idea of sharing this logic, but filter_builtins requires a BindgenContext as a parameter, which I don't have access to in ast_dump. How important is the call to ctx.options().builtins in determining whether a cursor is a builtin definition?

@emilio
Copy link
Contributor

emilio commented Mar 2, 2017

@emilio thanks for the kind words! I am indeed feeling better :)

Glad to hear that! :)

Thanks for the tip about fn filter_builtins. I like the idea of sharing this logic, but filter_builtins requires a BindgenContext as a parameter, which I don't have access to in ast_dump. How important is the call to ctx.options().builtins in determining whether a cursor is a builtin definition?

The context parameter is not important to determine whether it's builtin, that is only used to determine whether to generate builtins, so you can remove that argument, and handle it in the caller.

That way, the current:

if !filter_builtins(ctx, cursor) {
    return Continue;
}

would become something like:

if ctx.options().builtins && cursor.is_builtin() {
    return Continue;
}

Where cursor.is_builtin is the function you need to write and that holds that logic that is actually in filter_builtins. Does seem a reasonable way forward?

Thanks again for taking this!

@tsliang
Copy link

tsliang commented Mar 7, 2017

@emilio thanks for the guidance! I've written something and I'll make a PR later today :)

tsliang pushed a commit to tsliang/rust-bindgen that referenced this issue Mar 7, 2017
Resolves issue rust-lang#476. Moves out logic for checking whether a cursor
has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
tsliang pushed a commit to tsliang/rust-bindgen that referenced this issue Mar 7, 2017
Resolves issue rust-lang#476. Moves out logic for checking whether a cursor
has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
@tsliang
Copy link

tsliang commented Mar 7, 2017

ok, one more question: I've done my code changes, and I ran cargo test in the root directory (unlike the last patch I wrote, no libbindgen directory appeared when I built the code). The first time I ran the tests I got 4 failures, but 4 files were changed during the test run (diff attached). After running cargo test again, there are no failures. Is this expected behavior? Should I commit the changed files?

post-test.txt

@fitzgen
Copy link
Member Author

fitzgen commented Mar 7, 2017

@tsliang

The libbindgen directory has been gone for a month or so now, when did you branch off of master?

If you check out the latest master and run cargo test, do the tests pass without any diif to the test expectations' bindings?

It might also help to open a PR so we can comment on the code.

@emilio
Copy link
Contributor

emilio commented Mar 7, 2017 via email

tsliang pushed a commit to tsliang/rust-bindgen that referenced this issue Mar 8, 2017
Resolves issue rust-lang#476. Moves out logic for checking whether a cursor has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
tsliang pushed a commit to tsliang/rust-bindgen that referenced this issue Mar 8, 2017
Resolves issue rust-lang#476. Moves out logic for checking whether a cursor has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
@tsliang
Copy link

tsliang commented Mar 8, 2017

PR made!

@fitzgen The libbindgen folder was just what I remember from the last patch I wrote, which was months ago. Btw, what's the best way to keep up to date with changes like this? I feel bad for bugging you guys with silly questions like this.

Thanks a lot for the help and patience, @fitzgen @emilio and @jdm

@fitzgen
Copy link
Member Author

fitzgen commented Mar 8, 2017

Btw, what's the best way to keep up to date with changes like this? I feel bad for bugging you guys with silly questions like this.

It is not "bugging" us (or at least me) at all :-P

The only way to know is to follow the changes happening, read the emails generated by PRs and comments and everything, which can be a bit much at times.

Really it's no big deal to ask a quick question. That's what we're all here for :)

@tsliang
Copy link

tsliang commented Mar 9, 2017

You're too kind. If you ever come to Amsterdam I'll bring you appreciation snacks :)

bors-servo pushed a commit that referenced this issue Mar 9, 2017
Do not print builtin macro definitions in ast_dump

Resolves issue #476. Moves out logic for checking whether a cursor has a filename (previously used exclusively in private function lib::filter_builtins) into the actual cursor. This code is then used to check whether a cursor is a builtin when dumping the AST.
@jdm
Copy link
Contributor

jdm commented Mar 24, 2017

This was fixed by #566.

@jdm jdm closed this as completed Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants