Skip to content
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

Add a callback for function-like macros #1793

Merged
merged 5 commits into from
Jun 20, 2020
Merged

Conversation

kulp
Copy link
Member

@kulp kulp commented May 23, 2020

Closes #1792.

Because whitespace information is not represented explicitly during parsing, it is non-trivial to reconstruct the exact textual form of the macro from the token list. I had previously inserted whitespace between tokens, which I still believe would be correct and acceptable, but it seems that spelling the tokens separately would be better.

Given this input :

#define jit_get_note(n,u,v,w)	_jit_get_note(_jit,n,u,v,w)

and this callback :

fn func_macro(&self, name: &str, value: &[&[u8]]) {
    dbg!(name);
    dbg!(value);
}

this sort of output is achieved (pseudo-code) :

name = "jit_get_note(n,u,v,w)"
value = &[ "_jit_get_note", "(", "_jit", ",", "n", ",", "u", ",", "v", ",", "w", ")" ]

@kulp kulp marked this pull request as ready for review May 23, 2020 15:43
@kulp

This comment has been minimized.

@kulp

This comment has been minimized.

@kulp

This comment has been minimized.

@kulp kulp marked this pull request as draft June 6, 2020 23:17
@kulp

This comment has been minimized.

@kulp

This comment has been minimized.

@kulp

This comment has been minimized.

@kulp kulp marked this pull request as ready for review June 7, 2020 00:46
Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This looks basically fine. I have some questions, and I think that we should avoid re-tokenizing every macro twice.

src/ir/var.rs Outdated Show resolved Hide resolved
src/ir/var.rs Outdated Show resolved Hide resolved
bindgen-integration/build.rs Outdated Show resolved Hide resolved
src/ir/var.rs Outdated Show resolved Hide resolved
src/clang.rs Outdated Show resolved Hide resolved
@emilio
Copy link
Contributor

emilio commented Jun 8, 2020

Also, why does handle_function_macro take a closure instead of just a &dyn ParseCallbacks or such?

@kulp
Copy link
Member Author

kulp commented Jun 9, 2020

Also, why does handle_function_macro take a closure instead of just a &dyn ParseCallbacks or such?

I had previously passed in &dyn ParseCallbacks as you say, and I will happily change it back if you like. I simply thought that avoiding exposing ParseCallbacks to handle_function_macro lowered the risk of undesirable coupling and made handle_function_macro more composable, but that is probably a philosophy taken a little too far.

@kulp

This comment has been minimized.

@kulp kulp requested a review from emilio June 10, 2020 11:53
kulp added a commit to kulp/lightning-sys that referenced this pull request Jun 11, 2020
@kulp
Copy link
Member Author

kulp commented Jun 13, 2020

@emilio, I believe I have addressed all your questions and concerns. I no longer re-tokenize twice, and I think I have demonstrated that from_utf8 is not called more times than before the current PR.

Please let me know what else I can do.

@kulp
Copy link
Member Author

kulp commented Jun 17, 2020

@emilio, I was not sure if the right etiquette was to mark the conversations as resolved, or to leave them for you to do so -- I marked them as resolved.

Is there anything else this PR needs ?

@emilio
Copy link
Contributor

emilio commented Jun 17, 2020

No, marking as resolved is all fine. Sorry, just have to get to reviewing this properly again (bindgen is not my $dayjob :)).

Sorry for the lag and thanks for updating the patch.

@kulp
Copy link
Member Author

kulp commented Jun 17, 2020

No, marking as resolved is all fine. Sorry, just have to get to reviewing this properly again (bindgen is not my $dayjob :)).

Sure, I understand. No rush -- I just do not know whether things get missed and how much active pushing you want from me. I will come back in a few weeks.

@bors-servo
Copy link

☔ The latest upstream changes (presumably 2ba27bf) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks basically ok to me, with a few minor changes.

src/ir/var.rs Outdated Show resolved Hide resolved
src/ir/var.rs Outdated Show resolved Hide resolved
src/ir/var.rs Outdated Show resolved Hide resolved
@kulp
Copy link
Member Author

kulp commented Jun 20, 2020

☔ The latest upstream changes (presumably 2ba27bf) made this pull request unmergeable. Please resolve the merge conflicts.

I have rebased and force-pushed. I also ensured that every commit passes cargo test both in the root directory and in bindgen-integration, so I can back up to an earlier commit if I have gone too far with my refactoring.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, this looks good to me! Mind adding that minor comment?

I think squashing the commits would also be great, 52 commits may be a bit too much for this. Your call whether you want to leave it all in one commit, or put the implementation and tests in different commits or what not. (Or I can just squash them before merging).

Thanks again!

src/ir/var.rs Show resolved Hide resolved
src/ir/var.rs Show resolved Hide resolved
@kulp
Copy link
Member Author

kulp commented Jun 20, 2020

Thanks, this looks good to me! Mind adding that minor comment?

Certainly, I will do that next. I did not see your quick review response, or I would have held off on my last push.

I think squashing the commits would also be great, 52 commits may be a bit too much for this. Your call whether you want to leave it all in one commit, or put the implementation and tests in different commits or what not. (Or I can just squash them before merging).

I will try to squash down to ten meaningful commits or so.

Thanks again!

Thanks for working with me on this ! It has been a pleasure.

@kulp
Copy link
Member Author

kulp commented Jun 20, 2020

I am as done as I know how to be. I mistakenly re-requested review from you, @emilio.

Thanks for your help.

Copy link
Contributor

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet, thank you!

@emilio emilio merged commit d2e0407 into rust-lang:master Jun 20, 2020
@kulp kulp deleted the function-macros branch June 20, 2020 23:47
@kulp
Copy link
Member Author

kulp commented Jun 26, 2020

@emilio, I could use this feature better in lightning-sys, if a new release were published to crates.io in a week or two. Is that reasonable ?

kulp added a commit to kulp/lightning-sys that referenced this pull request Jun 26, 2020
kulp added a commit to kulp/lightning-sys that referenced this pull request Jun 26, 2020
rust-lang/rust-bindgen#1793 has merged to official master, so point to
it there.
@emilio
Copy link
Contributor

emilio commented Jun 29, 2020

Yes, I'll try to get a release done soonish. Please nag if it's not done by the end of this week :)

kulp added a commit to kulp/lightning-sys that referenced this pull request Jul 4, 2020
kulp added a commit to kulp/lightning-sys that referenced this pull request Jul 4, 2020
rust-lang/rust-bindgen#1793 has merged to official master, so point to
it there.
kulp added a commit to kulp/lightning-sys that referenced this pull request Jul 5, 2020
@kulp
Copy link
Member Author

kulp commented Jul 6, 2020

Yes, I'll try to get a release done soonish. Please nag if it's not done by the end of this week :)

@emilio, here is your nagging :) although it is really not a big deal to me if it takes a few weeks.

Let me know if I can help, for example by writing up a Changelog entry.

kulp added a commit to kulp/lightning-sys that referenced this pull request Jul 6, 2020
@emilio
Copy link
Contributor

emilio commented Jul 6, 2020

Just published a new release. Thanks for all the contributions you've sent so far @kulp!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Proposal: ParseCallbacks::func_macro
4 participants