Skip to content

Auto-generate traits from source#6877

Closed
wilzbach wants to merge 5 commits intodlang:masterfrom
wilzbach:autogenerate-traits
Closed

Auto-generate traits from source#6877
wilzbach wants to merge 5 commits intodlang:masterfrom
wilzbach:autogenerate-traits

Conversation

@wilzbach
Copy link
Copy Markdown
Contributor

@wilzbach wilzbach commented Jun 9, 2017

This is a proof of concept following from dlang/dlang.org#1683 and the idea is to generate the spec based on the ddoc comments.

"derivedMembers",
"isSame",
"compiles",
"parameters",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT is parameters not documented nor implemented. Is this a relict?

@andralex
Copy link
Copy Markdown
Member

This looks very nice. I think we should merge it regardless on future directions. @WalterBright ?

@andralex
Copy link
Copy Markdown
Member

@wilzbach mind the odd errors in testers

@wilzbach wilzbach force-pushed the autogenerate-traits branch from 7f2d80d to d1d457d Compare June 11, 2017 01:27
@wilzbach
Copy link
Copy Markdown
Contributor Author

@wilzbach mind the odd errors in testers

Thanks.
This was due to unimplemented and unused parameters traits. I split these changes into a separate commit. If it's controversial, I am happy to drop this commit.


extern (C++) __gshared StringTable traitsStringTable;

/**
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made one more pass, a thought: this exposes a bunch of nicely-named symbols. Can we make them private and still generate the documentation?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so (without bug hacks/work), but DMD != Phobos, so having public symbols shouldn't a big problem. Currently the only users are GCC + LDC and they can't use this without C++ interfaces. Also we are stuck with these traits nearly forever, so I doubt that worrying about the deprecation of a public symbol is a worry here. Deprecating a trait from the language is a different pair of shoes though.

@dlang-bot
Copy link
Copy Markdown
Contributor

dlang-bot commented Jan 8, 2018

Thanks for your pull request, @wilzbach!

Bugzilla references

Your 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 locally

If 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#6877"

@wilzbach wilzbach force-pushed the autogenerate-traits branch from 21e2175 to dfb5cd9 Compare January 8, 2018 21:53
@wilzbach wilzbach force-pushed the autogenerate-traits branch 3 times, most recently from 5650e06 to b128315 Compare January 17, 2018 03:54
@WebFreak001
Copy link
Copy Markdown
Member

this would be really nice for example in DCD where there is a list of traits for autocompletion currently hardcoded in. It would make sense having this in a few places where D code generation is done at CTFE for example as you could go over __traits(allMembers. Except for auto completion programs it could also be used to check using is(typeof(...)) instead of __traits(compiles if a trait is available, which might be a bit nicer

@wilzbach wilzbach force-pushed the autogenerate-traits branch from b128315 to 007e732 Compare January 24, 2018 07:37
@wilzbach
Copy link
Copy Markdown
Contributor Author

Rebased to include the new isDisabled trait.

@wilzbach wilzbach changed the title [Proof of Concept] Auto-generate traits from source Auto-generate traits from source Feb 24, 2018
@wilzbach wilzbach force-pushed the autogenerate-traits branch from c9a5a63 to 4c4592d Compare February 24, 2018 13:39
@wilzbach
Copy link
Copy Markdown
Contributor Author

(rebaseD again).

Another ping on this.
Seems like for the last nine months no one opposed this and @andralex was in favor...

Copy link
Copy Markdown
Member

@andralex andralex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, apologies for the slowness. I think a good next step is to hook this in and eliminate the now redundant docs on dlang.org. Thanks!

false
)
*/
enum isArithmetic = "isArithmetic";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest using __traits(identifier, isArithmetic) to get the string. Instead of having to repeat all the enum names twice.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that what .stringof is for? I see no problem really with the repetition, as the intent is clear.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.stringof will result in a forward reference error.

@WalterBright
Copy link
Copy Markdown
Member

I've been finding it convenient to merely put a link in the code to the spec.

@wilzbach wilzbach force-pushed the autogenerate-traits branch from 4c4592d to e0d1d9c Compare March 26, 2018 06:20
@wilzbach
Copy link
Copy Markdown
Contributor Author

wilzbach commented Jun 6, 2018

It would have been nice to automatically generate the list of traits, but I have bigger fish to fry for now.

@wilzbach wilzbach closed this Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review:Blocking Other Work review and pulling should be a priority Review:Easy Review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants