-
-
Notifications
You must be signed in to change notification settings - Fork 608
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
Add a lowering field for AssignExp to store potential lowerings
#14985
Conversation
|
Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla references
Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#14985" |
lowering field for AssignExp to store potential lowerings
3671524
to
42c8674
Compare
|
Is that the only solution to fix 23773 ? edit: In particular and assuming there is a scope flag giving the info that you are in an assert, why not adding a check when the lowering is created ? |
|
No, of course there are other potential hacks that could be employed. However, this is the most general solution. The initial strategy was to lower the hook in the frontend (irrespective if it was in a ctfe block) and if interpretation was required the original expression would be reconstructed. Now we lower the hook only if we know that the code will be codegen-ed and we store it in an additional field. Indeed, this comes with an extra cost, but its peanuts compared to the memory used by template instances. |
|
Fixing 23773 is just a collateral gain of implementing this. |
expressions, including one of their most common form, Assignment ones, are also copied with template instances, i.e function bodies. |
|
Well, we have to agree on some path going forward. It seems that neither is ideal, so I guess it just comes down to what we want to sacrifice: compile time to create/regreate expressions for CTFE or memory to cache the lowering. In the past @ibuclaw has complained about the former approach because of the extra work at compile time and the fact that losing the original expression might affect optimizations for other backends. That is how we ended up with this strategy. @WalterBright what is your input on this? |
|
The unlowering is memory expensive too. So that not every AssignExp gets a redundant lowering field, you could make a new derived node |
|
A general solution to link to where an expression was lowered from is also needed for error messages (I have worked on this in the past). |
Yes, that might work, however, that will pollute the codebase with all kinds of different AST nodes, provided we will use this strategy for other lowerings as well. Anyway, compared to the importC ugliness that was added in the semantic phases I guess it's worth a shot. |
This should be solved by the approach in this PR. |
Yes, exactly. Do we waste the effect of the accumulation of the micro efforts made 2 or 3 years ago or not ? People have worked to save 10 megs here, 20 megs theres, etc. and now let's waste 80 megs because of a bug that basically nobody gives a crack about ? |
|
that will affect the size of all BinaryAssign nodes btw, which are not disallowed as condition. void main(string[] args)
{
int a;
if (a+= 1){} // ok
if (a= 1){} // ng
} To be clear, that PR is going nowhere, trying to fix nothing. |
|
@SixthDot As I've explained earlier: the fix for 23773 is just a side effect of adding the lowering field. We plan on doing variations of this approach for all of the hooks. |
And hopefully a few more non-hook lowerings too. For example, I've just seen someone post this error message. |
…al lowerings and use it for array length expressions
42c8674
to
701e112
Compare
|
@ibuclaw I have implemented the new AST node. cc @SixthDot |
|
I think ArraySetLengthExp would be better so that it isn't some black box the backends can't optimize for. |
|
@ibuclaw There are multiple lowerings that can be performed from an AssignExp. I was hoping that we could use this class for all and not add a new class for each. |
701e112
to
a16c36d
Compare
|
I'm not blocking anything BTW, initially I wanted to encourage to think more about alternative solutions. |
a16c36d
to
4286646
Compare
The backends can still check the original rhs and lhs expressions for optimizations. However, if you consider that the AST node should be specialized, I can do that but that will result in having an AST node for each AssignExp lowering. |
4286646
to
30a8bb0
Compare
30a8bb0
to
5cd0d5d
Compare
|
I have added the "72h no objection -> merge" label. |
PR dlang#14985 introduced `LoweredAssignExp` with a separate field to store the lowering during semantic analysis. Then dlang#15791 placed the lowering of `CatAssignExp`s into this field, but did not remove the code that was previously recreating the original `CatAssignExp` from the lowering during CTFE. Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
PR #14985 introduced `LoweredAssignExp` with a separate field to store the lowering during semantic analysis. Then #15791 placed the lowering of `CatAssignExp`s into this field, but did not remove the code that was previously recreating the original `CatAssignExp` from the lowering during CTFE. Signed-off-by: Teodor Dutu <teodor.dutu@gmail.com>
This PR does the following:
add a field,loweringtoAssignExpto store the potential lowerings that are done in the frontend.useloweringto lower array length expressions.LoweredAssignExpthat inherits from AssignExp and adds aloweringfield.inline.dto inline the call to the lowering, not the AssignExp since that avoids extra copies.hdrgen.dso that if the switch-vcg-astis used we will print the call to the hook not the initial AssignExp. For code that does not use-vcg-astthe AssignExp is printed.cc @WalterBright as this is in line with your work of not generating the hook if in ctfe blocks
cc @teodutu - this needs to be done for all previously implemented templated hooks.