[WIP] Lower newExp for scalar types#9433
Conversation
|
Thanks for your pull request and interest in making D better, @edi33416! 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 referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub fetch digger
dub run digger -- build "master + dmd#9433" |
| (*exp.arguments)[0] = e; | ||
| newExpLowering = new ConstructExp(newExpLowering.loc, newExpLowering, e.addressOf()); | ||
| newExpLowering.expressionSemantic(sc); | ||
| } |
There was a problem hiding this comment.
newExpLowering = newExpLowering.expressionSemantic(sc);
There was a problem hiding this comment.
You're also calling expressionSemantic() twice on the same expression.
There was a problem hiding this comment.
Even this works:
newExpLowering = new ConstructExp(newExpLowering.loc, newExpLowering, e.addressOf()).expressionSemantic(sc);But it might be a bit too long.
22142e9 to
772f703
Compare
|
I addressed the feedback. This is still a WIP, as there are some tests failing in How was this previously Another issue that I'm having is that I can't call a non-templated function from Edit: @WalterBright @jacob-carlborg could you please help me with the above? |
| { "__equals"}, | ||
| { "__switch"}, | ||
| { "__switch_error"}, | ||
| { "___d_newitemT" }, |
There was a problem hiding this comment.
No need for triple underscore prefix and T suffix:
| { "___d_newitemT" }, | |
| { "__newitem" }, |
There was a problem hiding this comment.
I also consider double underscore to be wrong usage for regular identifiers in dmd, as these are reserved by the language specification.
There are a couple of places where an identifier behaves slightly different if it starts with __, e.g. https://github.com/dlang/dmd/blob/master/src/dmd/traits.d#L1392.
The mago debugger can also hide variables that start with a double underscore as these are usually compiler generated temporaries.
There was a problem hiding this comment.
I agree with @rainers - the function are extern (D) and templates non the less, so we don't need to resort to legacy C-style naming practices. I think for the time being, we should at least use a name consistent with __switch_error and __equals, like __new_item or more precisely __new_scalar, though newHeapObject (or something along those lines) would be better, considering that we probably want to lower all new expressions to it.
There was a problem hiding this comment.
I think the problem is these symbols are in object.d which is automatically imported by all .d source files. This could cause a naming conflict in user code. If we could fully qualify the symbol (e.g. object.switchError instead of just switchError) in the lowering, we wouldn't need the double underscore prefix. I don't know how to do that. @WalterBright, do you?
There was a problem hiding this comment.
Although the use of double underscores is probably unnecessary in object.d, too, I wasn't actually referring to their use in lowerings, but their use in dmd as Id.__newitem. That way a reserved identifier used in lowerings appears in regular code aswell.
There was a problem hiding this comment.
If we could fully qualify the symbol (e.g. object.switchError instead of just switchError) in the lowering,
Sure we can and have done that even in the past ;-)
It looks like this:
Lines 5663 to 5666 in fd8eb47
There was a problem hiding this comment.
If we could fully qualify the symbol
That should be a requirement. I've already run into issues with a similar case where the fully qualified name wasn't used.
There was a problem hiding this comment.
Regarding the double underscore. Since these need to be public symbols, the double underscore could be used to indicate that these symbols should not be used directly, only by the compiler.
I doubt the original runtime hook was ever called at compile-time. It's currently lowered in e2ir.d which is after all semantic and CTFE opportunity (if my understanding of the compiler is correct). By converting this runtime hook to a template, and lowering in the semantic phase of the compiler, you've now subject the runtime template to CTFE, which has its consequences. The best course of action is to just remove |
| } | ||
| else if (tb.isscalar()) | ||
| { | ||
| // call ___d_newitemT!(exp.newtype)() |
There was a problem hiding this comment.
Should use the fully qualified name when calling the function.
|
Superseded by #14664 |
Lower calls to
newexpression to druntime's_d_newitemTtemplated implementation that uses compile time information about the type instead ofTypeInfo.