-
Notifications
You must be signed in to change notification settings - Fork 260
[SUGGESTION] Ability to disable UFCS both via cppfront and for regions in source code #1004
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
Comments
I can second this. Also the error messages if the lookup fails are usually not very intuitive. |
Thanks for raising this. I appreciate the feedback. The three motivations I see above are: implementation bugs, debugging experience, and error message readability. A fourth one I'm curious about: Have folks encountered significant problems with actually invoking an unintended function? That last one would especially be motivation to make UFCS be opt-in in the language via a distinct third function call syntax, which doesn't need to be too heavyweight... One simple candidate I've considered would be
And I don't think |
I think I'd prefer an opt-out syntax as opposed to an opt-in syntax. Debugging/error messages can be improved over time as tools become cpp2 aware (I hope 🤞.) Something like using // cpp2
vec.this.size();
// lowers to cpp1 as (no UFCS)
vec.size(); To me |
Another opt-in syntax is |
No, I haven't experienced that. I like how it dispatches currently especially with inheritance (code below). A scenario I think has been discussed elsewhere is that adding a member function to a type could change existing code's behaviour if the existing code is depending on UFCS calling a non-member function (of the same name), but that hasn't happened to me so far (though perhaps would only happen with enough elapsed time and code refactoring / library upgrades). UFCS with inheritancemy_string1: type = {
this: std::string;
using std::string::string;
}
my_string2: type = {
this: std::string;
using std::string::string;
}
// Special behaviour for `my_string1`
trim: (inout s : my_string1) = {
s.clear();
}
// Default behaviour
trim: (inout s : std::string) = {
s.erase(
s.begin(),
std::find_if(s.begin(), s.end(), :(ch: char) -> bool = !std::isspace(ch)));
s.erase(
std::find_if(s.rbegin(), s.rend(), :(ch: char) -> bool = !std::isspace(ch)).base(),
s.end());
}
main: () -> int = {
str1: my_string1 = (" hello, world ");
str1.trim();
std::cout << "Expect this to be empty: [(str1)$]\n";
str2: my_string2 = (" hello, world ");
str2.trim();
std::cout << "Expect this to be trimmed: [(str2)$]\n";
return 0;
} |
Thanks! So the issues really are: active bugs, debugging experience, and error message readability. I think I can do something about at least two of those, and maybe all three, in the next month. For example, for error message readability I was considering something like changing the UFCS implementation from
to make the That's a sketch... how does that sound? Edited to add: Something like this...
|
That would really improve the situation. A side note: Allowing to disable UFCS on a call by call basis, could help to find bugs in the implementation. |
Sounds good, I look forward to testing with that new version! |
Adding emphasis:
Update: I think I've improved the third one sufficiently (error message readability) with today's commit. Thanks for pushing on this! Next up, the other two: What UFCS bugs do you most commonly encounter? Just an example here in this thread would be fine, or an issue number link if it's already reported. For the debugging experience, you wrote "because it doesn't step over the function calls like I'd expect" -- can you give an example? (I saw a reference to #844 but that seems to be a different case where the generated function doesn't have a source location in the original code at all, whereas with UFCS the call site is in the original code... unless it's in generated code of course but then that's the proximate issue rather than the UFCS?) |
My wish list would be #999 and #1002 -- I think those are the ones I see most often.
I'll make a GIF/video of this. The problem was that the debugger required 2 steps to step over a UFCS call, instead of 1 like you'd expect. Almost as if the first step was invisibly stepping into the macro. |
Thanks, a video would be good. |
I recall that it's stepping into the IILE first. |
Yes, I think that's it. Here's a video showing the issue in VS 2022. UFCS-step-over.mp4 |
I would suggest using the option to turn off line numbers, and then debug the generated code to see exactly what's happening. I suspect that it's multiple lines of code in cpp that happen to map to the same line in the cpp2. |
As shown in the comment #904 (comment) UFCS macro/template can have a real impact on compile times.
In this thread there have been sugestions for a new syntax:
One idea of mine would be to use metafunctions to change the state of the cppfront compiler. e.g.
|
Thanks! Since even after the changes already made above UFCS still continues to be an issue, including that we now have more data UFCS is a compile-time performance issue, I'm trying out adding Note: If in the future we find that UFCS should not be the default, we can make |
Xref: #1101 |
With 9648191 we have the ability to use My impression is that the changes now done probably do address the motivation behind the request to have such regions, so I'll close this as completed. But feel free to reopen if you think there's a strong reason to reconsider more in this area, and even a lively debate about regions with different meanings for the same code! |
I'd like the ability to disable UFCS with 2 mechanisms:
true
) for a whole Cpp2 file#pragma push/pop
or[[attribute]]
-style code that cppfront would read when parsing the Cpp2 source code to control whether UFCS function calls are enabled for a region of code inside a Cpp2 fileMotivations:
Will your feature suggestion eliminate X% of security vulnerabilities of a given kind in current C++ code?
No
Will your feature suggestion automate or eliminate X% of current C++ guidance literature?
No
The text was updated successfully, but these errors were encountered: