-
Notifications
You must be signed in to change notification settings - Fork 708
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
[WIP] add saltwater backend #1782
Conversation
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.
Yeah, this looks like a sensible approach to me :)
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I added
#define NAMESPACE foobar
namespace NAMESPACE { ... } It seems that |
I added a commit passing in the macro definitions. The failures look simpler to fix now: diff
|
|
I found the reason for the overflow in enum E {
A = 18444492278190833663
};
<stdin>:2:6: error: integer literal is too large to be represented in a signed integer type, interpreting as unsigned [-Werror,-Wimplicitly-unsigned-literal]
<stdin>:2:2: error: ISO C restricts enumerator values to range of 'int' (18444492278190833663 is too large) [-Werror,-Wpedantic] Do you want me to try and support this? |
@emilio I think everything left requires a policy decision, let me know when you have a chance to look at this :) To summarize:
|
☔ The latest upstream changes (presumably d2e0407) made this pull request unmergeable. Please resolve the merge conflicts. |
I fixed the conflicts and also switched to a published version of rcc so that CI shows meaningful failures instead of blocking network access. Note that I'm still interested in seeing this in bindgen, but I've been having trouble getting in contact with anyone. What are the next steps? Are you still interested in using a different backend for parsing expressions? I'm not sure it makes sense to keep spending time on this if you're not interested. |
The CI failure doesn't seem related to this PR (https://travis-ci.com/github/rust-lang/rust-bindgen/jobs/351921557#L426):
|
I still think this is interesting, sorry for not getting back (I'm just very swamped with real life to invest a lot of time on bindgen r/n). |
That being said, looks like those failures are real regressions. Here's another example from automation:
Seems like we were able to evaluate the constant before and now we're falling back to generating a |
(Which is a bit odd, as we're using clang to evaluate those, in theory...) These patches look generally reasonable. When running tests locally I get:
It seems saltwater is choking at: #define JSVAL_TAG_MASK 0xFFFF800000000000LL Which is kind of a blocker because this is real code, which ought to work. I... don't think that's an integer overflow? The |
Do you know how to reproduce that locally? In a typed context that works fine: $ swcc -c
typedef unsigned long long EasyToOverflow;
const EasyToOverflow k = 0x80000000;
const EasyToOverflow k_expr = 1ULL << 60;
const EasyToOverflow wow = 1ULL << 31;
$ swcc -c
// ok, let's try again with int instead
int i = 0x80000000;
<stdin>:1:9 warning: conversion to int loses precision (-2147483648 != 2147483648)
int i = 0x80000000;
^^^^^^^^^^ So my suspicion is that this is trying to parse it as a signed integer instead of unsigned.
#1782 (comment) (tl;dr: it overflows for
I'm not quite sure how to avoid them and still do macro replacement ... see #1782 (comment). Maybe I could add a special mode that treats |
Another idea is on the bindgen side, I could try first parsing as a signed integer, and if that doesn't work, try unsigned. Let me test that out real quick. |
It seems it depends on the libclang version. So libclang 3.8 should reproduce that error. |
This seemed to work, at least locally. We'll see what pops up in CI. |
The remaining failures are the ones that only happen with llvm < 4. It only happens in |
Yay this is passing except for MSRV 🎉 About minimum versions, the following saltwater deps require later than 1.34:
|
I think bumping the msrv if needed should also be fine, fwiw. We have the check to make sure we notice when we change it. |
|
|
@jyn514, now that you have done all the hard work of getting MSRV requirements lowered ... bumping the MSRV to 1.40.0 is being forced elsewhere (#1826 (comment)). I mention it just in case you get to updating the MSRV before #1826 does. |
After all that hard work :( Oh well, I'll try and rebase this this week. |
@emilio this is ready for review |
☔ The latest upstream changes (presumably 94bce16) made this pull request unmergeable. Please resolve the merge conflicts. |
- Rewrite parse_macro using rcc - Pass in macro definitions to rcc - Remove cexpr - Remove null-terminator from rcc tokens
Just a few more harmless constants
- Don't try to add 'u' if it's already there
This was the same LLVM bug noted in parse_macro, but it seems that cexpr allowed trailing tokens while saltwater does not.
Still waiting on review. This doesn't actually fix any signedness bugs yet though, maybe I should work on that in the meantime. I tried using the parsed -pub const MIN_I32_Minus1: i64 = -2147483649;
-pub const LONG12: i64 = 123456789012;
-pub const LONG_12: i64 = -123456789012;
+pub const MIN_I32_Minus1: u32 = 18446744071562067967;
+pub const LONG12: u64 = 123456789012;
+pub const LONG_12: u32 = 18446743950252762604; I might need to fix jyn514/saltwater#385 first. |
☔ The latest upstream changes (presumably 727dc63) made this pull request unmergeable. Please resolve the merge conflicts. |
Addresses #1762
Not expecting this to be merged, just looking for feedback on whether this is the right approach.
I forgot that the lexer returns its own
Location
s, so I'm using those just to get a prototype going. I can switch to using the proper clang locations later (although since they are never displayed maybe it won't matter?)The lexer currently doesn't allow inputting a single token at a time so I hacked around it by treating the token span as if it were a whole file and assuming there was only one token in the file. I can fix this later, not sure yet how hard it will be on the rcc end.
All the test cases pass locally. Note that this already could fix #1594 if I removed the
as i64
cast and instead returned aLiteral
fromparse_int_literal_tokens
. It looks like bindgen has aVarType
soimpl From<Literal> for VarType
should be pretty simple. It would be nice to add an UnsignedInt variant as well, then the two would match up almost exactly (rcc
has no literal boolean values).What is
parse_macro
doing? It looks like it's supposed to parse the entire#define a 1 + 2
directive? Should it also perform macro replacement, and should that include function macros?cc @emilio