-
-
Notifications
You must be signed in to change notification settings - Fork 609
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
fix Issue 21585 - add __traits(totype, string) to convert mangled typ… #12156
Conversation
|
Thanks for your pull request, @WalterBright! 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#12156" |
4650985 to
94e1966
Compare
|
@WalterBright you can parse the trait as type with this little patch, no need to use templates. |
|
As proposed in the previous PR, I think we should overload based on the last argument to this trait: The motivation is that |
|
@BorisCarvajal @PetarKirov these are both good ideas and would make good follow-on PRs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add:
- an additional fail test to cover all code paths
- a test shows "importing" a private type by it's mangled name.
__traits(toType, magledNameOfTypeFromAnotherModule)- to test the limits of this feature - what happens if you "import" a type from a module that is not being compiled
Otherwise the current implementation looks good to me - simple, but powerful.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The decoToType function would sit better in traits.d. It is the only place where it is called and therefore it can be made private. Plus, we get rid of the import in dmangle.d as traits.d already imports it.
|
Ping @WalterBright |
2de2b9c to
63c0bf0
Compare
|
ping @RazvanN7 |
|
I'm afraid this will disappoint too easily, as the compiler needs to have seen the exact type in advance, e.g. yields It passes if |
|
BTW: the example from the bugzilla entry doesn't compile: results in |
That's because the |
That's right. Unfortunately, there's not an obvious way around the compiler has to see the type before it can demangle it. |
I think |
That makes it very difficult to find a compelling use case for this addition. Maybe it is possible to pass a type as a string to a CTFE function to generate a mixin that allows the mixin to be instantiated anywhere, even if the type is unknown at the point of instantiation. I think this should be explored before merging and should be demonstrated as a test case. |
…e string to an existing type
|
@rainers I didn't know that dmd was changed to allow __traits to act as a type. So I fixed this PR per your suggestion. |
addressed requested changes in the comments
| * Type for succeeded | ||
| */ | ||
|
|
||
| public Type decoToType(const(char)[] deco) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move this function to traits.d ? Then it can be made private.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because traits.d is plenty large enough, and it would be best suited to be with the mangling code.
|
I read the original thread, but I still don't think I see what the rationale is here? |
Provide symmetry to .mangleof. Trying to do this without compiler support would be tedious, slow and fragile. |
OK. I was just making sure I hadn't missed some uber-useful thing buried in the thread/s somewhere. |
|
TypeExp has been there a long time, it is there to deal with the cases of ambiguity in the grammar. |
…e string to an existing type
This is quite a bit simpler than its previous incarnation #11797
But it has a problem. @andralex wrote #11797 (comment) that __traits can return a type. Oops, it cannot, it only returns an Expression. So, there are two options:
mixinwhich can fail if the symbols making up the type are not in scope. Besides, doing a mixin is expensive at compile time, especially when we already have the desired type.In the future we can perhaps enhance the grammar to extend Type to include __traits(toType, string).
I'll do a spec PR if this is approved.