-
Notifications
You must be signed in to change notification settings - Fork 589
Request SvPV_helper to be always inline #23571
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
base: blead
Are you sure you want to change the base?
Conversation
It's usually a bad idea to try to work around a limitation in common code by copy-pasting and then modifiying to taste. Fixes/improvements to the common code rarely get propagated to the outlier. I wrote code in 1ef9039 that did just this for the prototype definition of SvPV_helper, because the place where it really belongs, embed.fnc, couldn't (and still doesn't) handle function pointers as arguments (patches welcome). I should have at least added a comment to the common code noting the existence of this outlier. It turns out that that limitation can be worked around by declaring a typedef of the pointer, and then using that in embed.fnc. That's what this commit does. This commit removes the final instance of duplicating the work of embed.fnc in the core, except for some in the regex system whose comments say the reason is to avoid making a typedef public. I haven't investigated these further.
(when the compiler cooperates, that is) I compiled toke.s using -O0 and looked at the output. It had a full copy of SvPV_helper in it. But this function is called with various constants that make much of the code dead when constant folded. That was not being done here. This commit changes to force inlining. Looking at a revised toke.s, I saw that SvPV_helper was inserted multiple times in the code, and that each occurrence had significantly fewer instructions than the original. I infer that the compiler did the constant folding and pruned out the dead code.
I don't see the rational of this ticket.
So If Don't forget about the huge If F11 key press count is too annoying to line advance through a statement that no p5p person needs to debug for the last 30 years, or the tiny STATIC_INLINE is distracting to a human, on Perls built with
If Plus who knows if your bug works on 3-5 other OSes/toolchains/CC brands/how old is that CC or gdb/etc. Easier to switch to |
|
Another C compiler design question, lets say a developer creates a Now comes the question, are the names of |
This PR is using the wrong tool, or the tool with the highest risk of breakage/not accomplishing the goal of the commit message. The fool proof solutions how to reduce single step GUI IDE "noise" lines so they aren't stopped on by step 1 or step into, r listed above. Forceinline token has no guarantee it will be honored by any CC. A force inline in a force inline recursively? Wouldn't that be infinite recursion? No, the CC can refuse to do the inline to break the chain. C preproc solutions work everywhere on ever CC always. An infinite recursion C preprocessor TU would just blow out its 4GB/16GB address space limit and either the CC errors out or kernel ooms/segvs it. Force inline is only a tool for bad decisions made by a CC by looking machine code output and seeing it didn't do what you thought it would do. There are regen.pl created latin1/utf8 static inline functions in |
I'd be more inclined to produce more trivial Perl_SvPV* variants. |
It appears to me you are suggesting that we should not be pro-active in avoiding potential problems before they bite the people that rely on our product working reliably. I'm confident that is not Perl's official policy And it appears to me that you misunderstand the point of the conversion to inline functions. I'm unsure what you mean by "macro in macro". I'm guessing it is that if a macro expands to call another macro there is a possibility of name collision. That is indeed solved by making things into functions. But the reason we have been converting macros into functions is that functions work when called with an argument that is an expression with side effects, and macros may very well have hard-to-debug failures. Your opinion about macros being the way to go is anathema to some others on this project. I myself think there is a place for both . But I strongly believe that any API macro should not evaluate any of its arguments more than once each. Last I looked we had something like a hundred that do. I do not recall ever feeling the need to grouse about the assertions in debugging. And I think that considerations of how current IDEs work should be well down on our list of our priorities of what we do on this project. The reason this particular function was created was because quite a few macros do portions of it, but some went down a maze of twisty little passages, and some went down a maze of little twisty passages. By having a single function that does the whole procedure, there is just one place to maintain. Our primary goal has to be correctness. And that implies correctness ongoing as the project evolves. Having this single function makes it easier to do this; going back to multiple macros doing portions of the implementation makes it more complex to maintain and more likely for bugs to slip in. My experience with compilers is that they evaluate at compile time as much of all expressions that they can, and use the result as a starting point for runtime code generation. If I have an expression The various macros call this function with compile-time constants. If the compiler evaluates those at runtime it will find dead code and omit that. All this commit does is to tell the compiler we want it to try hard to inline the function, and hence do constant folding at the various calls to it in the file. And that worked with a common compiler, gcc. If it doesn't work, correctness is not lost. We do that in other places too, ask for more than some compilers give, and have fallbacks to what is the best possible available behavior. I don't see the problem with it; if the compiler is capable of doing more, great; if not, we haven't lost anything. |
I compiled toke.s using -O0 and looked at the output. It had a full copy of SvPV_helper in it. But this function is called with various constants that make much of the code dead when constant folded. That was not being done here.
This commit changes to force inlining. Looking at a revised toke.s, I saw that SvPV_helper was inserted multiple times in the code, and that each occurrence had significantly fewer instructions than the original. I infer that the compiler did the constant folding and pruned out the dead code for each instance.