-
Notifications
You must be signed in to change notification settings - Fork 161
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
Revert "fix sequence partitioning problem" #219
Conversation
This reverts commit a8e391b.
OK, I'll have a look. Before I do, have you looked at the corresponding test that this commit fixes? Perhaps that's a good starting point to base our discussion on possible fixes. |
@djowel Sorry, I didn't see a corresponding test as I only saw the contents of that single commit. I'll take a look. Thanks for the response! |
I'm assuming there is one, as typical. |
@djowel I couldn't seem to find a test related to the fix (sadly, I'm not at all familiar with Spirit's tests) or a related Trac ticket, but I did see a fix for Ticket 11952 that was made on the same day (although that fix seems unrelated to the sequence attribute commit) which added a missing |
OK, I'll take a look. |
How about this... try running the X3 test before and after revert and compare the test results. |
Can do. |
Unless I'm running the X3 tests wrong (just simply doing |
oh no! i must've failed to commit the test it is supposed to fix; surely there is. now i have to go and find it. |
Ok, I did some digging and here's what's appears to be the test case. See " Single element attributes in X3 "still" broken?" in the list. This bad boy breaks without the fix.
|
I added the test. I'll commit pending resolution to your case. |
It appears the error from the repro can be worked around by precedence: a rule of It seems like when the "unused" attributed parser is on the RHS, it fails and the attribute type is |
I still think that the "fix" is correct. I haven't investigated on your use case, but have you considered looking at the fundamental cause why your code breaks? Are you sure you are not exploiting an undocumented behavior? |
I certainly could be relying on undocumented behavior (although when my implementation was originally written, I don't think the X3 docs even covered writing custom parsers; I figured out what I needed from X3's implementation) or simply my custom parser's implementation was never correct in the first place (it's effectively what was presented in the repro gist in terms of definition). Given my limited understanding of how this is supposed to work and that I have an acceptable workaround, I'm more than happy to defer to your expertise in this matter. |
It might well be that you uncovered another possibly unrelated bug. Do you think it is possible to recreate the problem without the custom parsers? Maybe some basic off the shelf parsers with std::string and unused attributes? |
I'll both look into why this is failing for my use case (I'm slowly understanding the implementation here) and see if I can reproduce it with a built-in parser. I'll get back to you; please feel free to close this PR in the meantime or if you feel there's a better place to discuss this. Thanks very much for your feedback and attention on this issue; it is very appreciated. |
I think it's best to keep this open for now. If you find that it is indeed an unrelated bug, then feel free to add more info here. |
Here is a simplified repro without custom parsers. #include <iostream>
#include <string>
#include <cassert>
#include <boost/spirit/home/x3.hpp>
#include <boost/fusion/include/std_pair.hpp>
using namespace std;
namespace x3 = boost::spirit::x3;
int main()
{
string input = "";
pair<string, string> result;
assert(x3::parse(input.begin(), input.end(), x3::attr("foo") > x3::eps > x3::attr("bar"), result));
// Expected output: foobar
cout << result.first << result.second << endl;
return 0;
} Basically the same thing as before: this compiles in 1.60.0 but not 1.61.0. |
There ya go. Now it's time for a bug hunt. Come join me :-) |
I will once I wrap my head around all this metaprogramming :) Same workaround as before applies here: |
Smells like a partitioning bug alright, but we have to make both use cases work. |
@peterhuene #337 should solve the problem. @djowel are you sure that a8e391b was a right thing? You did not add tests for it and I can't wrap my head to come up with. IIUC what it does was already implemented by these specializations spirit/include/boost/spirit/home/x3/operator/detail/sequence.hpp Lines 120 to 131 in f5179c9
I think currently it works by accident and did not break the whole thing because of this spirit/include/boost/spirit/home/x3/support/traits/move_to.hpp Lines 101 to 108 in f5179c9
|
@Kojoley It's hard to recall the essence of that code. Does this thread's test pass with that reverted? And all the tests for that matter? |
Yes.
Let's see. I close-opened to trigger the CI. |
OK, if that's the case, then we can revert. I might have an idea how to track the issue behind that commit after you revert. |
I though that I might should leave here a description of how that change broke the things. The commit introduced a next behavior: sequence parser will not unwrapping a single size container if one of attribute types is unused. So underlying parser now always get a fusion sequence. Example: the sequence spirit/include/boost/spirit/home/x3/support/traits/move_to.hpp Lines 101 to 108 in f5179c9
String parsers (or My point of view: the behavior should be consistent, either it must never unwrap a single item sequence in all the cases or always (there is an exception, if underlying is a sequence parser, but that case is already handled in the code). |
👍 I'm all for consistency. Whether to always or never unwrap, I am not sure. Thanks for looking deeper into this, @Kojoley. |
I see a benefit of not unwrapping for a single item fusion sequence attribute. But I'm not sure about fusion magic, will it move from a single size iterator to a single size sequence? (the iterator that actually wraps a generated sequence of size 1) Also: This specialization seems odd to me: spirit/include/boost/spirit/home/x3/support/traits/move_to.hpp Lines 90 to 99 in f5179c9
|
I think I agree with you about not unwrapping. We can always deal with Fusion if needed. Let's do it and see how it goes. I think it's best to work on this in a special branch. |
I did not say I am for not unwrapping, but I am inclined to it. My argument above is mostly is invalid, I was thinking that x3 like qi wraps attribute to fusion vector (I though I saw the same part in x3) but it is not, so sequence parser will never generate a single item sequence attribute (except Anyway current behavior is something I am totally do not support. It is strange to see an attribute of type |
OK, seems tests are good. Let us proceed. |
Fixed in #340 |
This reverts commit a8e391b.
Please see my mailing list message and the corresponding repro gist for context and repro, respectively.
_I'm putting up this PR for discussion and not for merge consideration as I don't like reverting a commit without replacing it with what the original commit was attempting to fix._