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
Workaround for expansion of function-like macros #2779
Conversation
104a714
to
3990e2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.5s sounds quite usable! Thanks John!
Some comments below...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks neat. I'm a bit concerned about just using a constant file name in the cwd for this, but that's not unfixable (we could even use a proper temporary file from the tempfile
crate or something). No need to fix it right now.
bindgen/ir/var.rs
Outdated
.open(&file) | ||
.ok()? | ||
.write_all(contents.as_bytes()) | ||
.ok()?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder, do we really need to write this file to disk? Can we somehow abuse the CXUnsavedFile API to do this in memory in both code paths?
Otherwise, should we delete it?
Also, it's a bit unfortunate that if the user happens to have a valuable thing there (unlikely) we'd throw it away.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please take a look at my most recent addition of --clang-macro-fallback-build-dir
. That might address your concern.
3990e2f
to
104bcfe
Compare
I've done a quick pass to fix the low hanging fruit. Will try to get back to this later today to resolve the rest of the concerns and follow up on any outstanding discussions. |
3a52ac5
to
6911401
Compare
10036f1
to
390062a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good with that simplification, but can we add a test for this? Let me know if you need any help with it.
bindgen/ir/var.rs
Outdated
return None; | ||
} | ||
|
||
let file = format!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The translation unit has the file path already, so this could be moved to try_ensure_fallback_translation_unit
, and just use ftu.file_path
below, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This depends a little bit on how you want to see this implemented. On one hand, we could make the member of FallbackTranslationUnit
crate public, but I think we'd require a clone because otherwise when we pass it in, we'd have a mutable reference taken for .reparse()
and an immutable reference taken for &ftu.file_path
. We could also change the API slightly so that .reparse()
only takes file contents as it's only operating on a single file and we may not need the flexibility of supporting reparsing multiple different files. I'd personally prefer the second approach.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the changes to reflect the second option. Let me know what you think.
@emilio What would you like in terms of the test? An integration or unit test or both? |
0e553e3
to
b5df566
Compare
Integration should be fine. Just using the new flags from a regular test (see the tests/headers directory and |
b71bb6f
to
4f319fa
Compare
Okay I think I've addressed everything! |
It seems clang 9.0 doesn't like your test and the new test fails there. Let me know if you have the appetite to chase that down (shouldn't be hard by pulling a pre-built clang for Linux amd64, and pointing to it with LIBCLANG_PATH). Otherwise I guess we can document the option as best effort / not working on older libclang versions (totally fine), and silence the failure there by adding the empty (well with the |
I may need a little bit of help in terms of the explanation but I can reproduce this reusing a precompiled header from 9.x on the latest version and vice versa. I'm wondering if there's a way there's a lingering precompiled header in the test suite somehow. This also raises the question of whether we should also be deleting the precompiled headers because debugging this would be incredibly difficult for users unfamiliar with the code and I expect you'll bump into in increase in issues with this feature if we don't. |
4f319fa
to
9532f2e
Compare
Okay, I managed to track it down to |
6c0044f
to
9ded89d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need a rebase (might be able to do that automatically, we'll see), but looks good to me, thanks!
9ded89d
to
f4d25f6
Compare
This commit resolves an issue where macros that evaluate to a constant but have a function like macro in the macro body would not be properly expanded by cexpr. This adds an opt-in option to use Clang on intermediary files to evaluate the macros one by one. This is opt-in largely because of the compile time implications.
f4d25f6
to
f77b3de
Compare
Merge queue setting changed
@jbaublitz I was able to test this workaround, but it doesn't seem to be working in my case. this is a part of the macros that register the interrupts
and BIT is a macro defined in ndstypes
none of the IRQ defines end up set in the wrapper
|
Related to #753
@ojeda Let me know if you have any thoughts on this. Compared to without the fallback (1s on the contants in the kernel header) I managed to get the compilation times from 2m to 8s to 3.5s. There may be additional optimizations we can do but it seems like it's definitely trending in the right direction.