-
Notifications
You must be signed in to change notification settings - Fork 0
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
This may be superior to clang-query #1
Comments
Cool, thanks, I'll read through the issue! I'm glad you said something, I've been assuming c++ all along, but I guess there's no need to rule out C. Also, check out https://github.com/theuni/bitcoin-tidy which is actually far more useful as it's able to do transforms, not just compile-time warnings. I'm mostly imagining the clang plugins here will be useful for CI as they're used in the compilation process. |
Yeah in particular C seems to be somewhat delicate (at least in |
Heh, apparently I wasn't alone in treating C as an after-thought :p |
@real-or-random Btw, looking at clang plugins from libsecp's pov, you might be especially interested in the notion of embedded DSL's. See the slides here (starting around 9): https://llvm.org/devmtg/2020-09/slides/Finkel-Changing_Everything_With_Clang_Plugins.pdf If anything strikes you as interesting, please poke me about it. For now I'm just hacking around on plugins to explore and better understand what they can do and how to fit them into Core's workflow, so I'd be happy to shift to something that even has a slight chance of being real-world useful. |
One thing that comes to my mind is bitcoin-core/secp256k1#1001. Not sure if you're familiar with our finite field code. Here, a field element has a "magnitude", which essentially tracks how far the integer it is from being fully reduced (mod the field size), see https://github.com/bitcoin-core/secp256k1/blob/master/src/field.h#L10. The idea is that arithmetic operations increase magnitude (e.g., magnitude( This is just a random idea and nothing we really need. We currently verify the magnitude at run time in the tests if |
Ok, I'm going to have to spend some time looking over and understanding all that, but my hot take based on a quick pass: It sounds like some runtime code could be made static if some functions have already been provably called. If I've got that right, it's a lot like this example. There, each function is analyzed to see if it needs As for the |
Ok, yeah, feel free to have a look but this was just the first idea that came to my mind. It may be instructive to look at the function docs in Here's an example where we track magnitude explicitly in the If magnitude of a value would become too large by an arithmetic operation, we need reduce it before doing the arithmetic by calling The code starting here is an example of this in action: edit: Now that I think about this more carefully, this may be rather difficult or really require an entire type system (and lots of type annotations from the user). For example, how would one handle loops? All our loops are bounded but the compiler may not know a reasonable bound etc. |
I haven't! I chose the clang machinery because we rely on its internals for building bitcoind, so we already "trust" it to be correct. But you're right, that shouldn't preclude experimenting with other tools. I'll have a look at those, thanks! |
Writing a plugin is a very nice and interesting idea. There's an old open secp256k1 PR that does a very basic version of this here using
clang-query
: bitcoin-core/secp256k1#833 I imagine this here is much more powerful and cleaner. On the other hand, I don't know if the LLVM API breaks often.(Not an issue per se, sorry, I just wanted to express my interest. ;) Feel free to close.)
The text was updated successfully, but these errors were encountered: