-
-
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
deprecate Object.factory #14681
deprecate Object.factory #14681
Conversation
|
Thanks for your pull request, @WalterBright! 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 run digger -- build "master + dmd#14681" |
c29c5c9
to
44eed91
Compare
44eed91
to
df3c14c
Compare
df3c14c
to
7625b39
Compare
|
@dkorpel @thewilsonator I'm not sure if @WalterBright's intention was to merge this straight away. I think he wanted to see how this fares on BuildKite. @WalterBright since this PR is merged, I think you should either follow up with a changelog entry, along with deprecation messages and dates for, or revert the change, in case it was just an experiment. |
|
Yeah, this shouldn't have been merged without:
@thewilsonator this isn't a trivial change. |
|
Yes, I had thought this was not ready for inclusion yet. In particular, how to replace the feature with a compile-time registration would be warranted, along with an explanation that |
|
This PR broke the testsuite. https://github.com/dlang/dmd/blob/master/druntime/test/shared/src/finalize.d#L7-L14 |
|
I did not come across this PR until last week. I use object.factory extensively. I have an implementation of IEEE 1800.2 UVM standard implemented in D Language. The UVM standard mandates that the test to be run be implemented as a class and can be specified from the command line when running the test. As a result, I need to create an object of the test class from the given string and Object.factory works right out of the box for my use case. Earlier I had tried implementing the same functionality using a class registration mechanism that used a static constructor for the class to be registered. Soon I found myself struggling with cyclic dependencies in the code modules. I request Object.factory be retained until we find a more robust mechanism to resolve cyclic dependencies in modules when static constructors are used. |
How could it break the test suite when it passed all the tests before being merged? |
|
@puneet the way to deal with cyclical imports A imports B and B imports A, is have both A and B import C, and put the static constructor in C. |
|
How is C supposed to register classes for factory creation from A and B? |
|
|
Keep in mind this is to replace a feature that "just works" at the moment. If possible, it should be easy to do, and not require too much extra machinery or rearrangement of declarations. Sure, you can move all classes into one module, and then you don't need to have circular imports. But then, of course, you have lost all the structure of your project. |
I'm really sorry that dmd's testsuite (specifically druntime's) chooses to ignore compile time warnings/errors when building tests. |
I didn't say all, and it doesn't have to be one module. The thing about two modules running static constructors, which one comes first? The inheritance hierarchy provides a clear resolution. But circular imports don't. How should it "just work"?
The compiler still should compile and run deprecations/warnings successfully. |
For discussion, see:
The language has problems guessing which classes should go into the ModuleInfo, and people don't want more annotations for this. The pragmatic solution is for users to make the list themselves of which classes can be instantiated with a factory.