-
-
Notifications
You must be signed in to change notification settings - Fork 667
Fix Issue 17181 - Local imports in templates should be added to impor… #9221
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
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 fetch digger
dub run digger -- build "master + dmd#9221" |
thewilsonator
left a comment
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.
Tests?
| sc._module.aimports.push(imp.mod); | ||
|
|
||
| // if inside a template instantiation, the instantianting | ||
| // module gets the import. |
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.
auto m = (sc.minst && sc.tinst) ? sc.minst : sc._module;
m.aimports.push(imp.mod);
4 lines of code to 2.
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.
Might want to add a link to 17181 for rationale.
|
@WalterBright done. |
| return imports.test17181a.abc(1); | ||
| } | ||
|
|
||
| static this() { assert(a == 2); } |
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.
A few explanations about this test:
-> before this patch, for the code in the test the compiler issued a wrong cyclic dependency error. This happened because the instantiation of abc, although was in module test17181, was regarded as being in test17181a. This made it look like test17181 relies on test17181a which relies on test17181b, which in turn relies again on test17181a. But that is not true, since the import of test17181b is in a template, therefore the import should be in test17181.
-> the correct order for the static constructors should be: test17181a->test17181b->test17181.
-> the test makes sure that when the static constructor for test117181 is run, the last static constructor ran was the one from test17181b.
|
I suspect there are more complications: if a template is instantiated by mutliple modules, the import is added to the module that happens to be analyzed first. Other modules that reuse the same template instance need to have a dependency on the import, too. |
…ted modules list of module that instantiated it
I added a fix, but I have no idea how to test this case. I don't even think it's possible. |
Custom shellscript with multiple EXTRA_FILES? |
You can't see imports in object files. We are talking aboud seeing an internal list in the compiler. |
Use the DMD frontend as a library. But you need to install Dub for that. I tried to that here [1], but it turned out Dub wasn't available on the auto-tester machines. [1] https://github.com/dlang/dmd/pull/8528/files |
Maybe grep on
Though the existing dub tests for the DMD frontend as a library are already tested on CircleCi. |
But not on all platforms. |
|
I think that we can merge this as is. We have a test for the original problem and its observable effect. The problem that @rainers specified, even though it is solved by this PR it didn't have any observable effects. |
andralex
left a comment
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.
LGTM. @WalterBright? @wilzbach? Any others?
rainers
left a comment
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.
LGTM. A test case that shows the dependency issue with reusing the template instance should be feasible with seperate compilation (especially through library) but probably not worth the trouble.
An interesting change is that a module that only contains templates with imports, but no global imports, now no longer needs to be compiled to an object file as it should never appear in a dependency chain itself. Maybe worth a test case...
You can if you dump the data segments, too. You'll find the imports that are in the dependency chain in the |
Yes please. WE SHOULD REALLY REALLY REALLY LEARN FROM PAST MISTAKES. |
[stable] Follow-up on #9221 merged-on-behalf-of: Nicholas Wilson <thewilsonator@users.noreply.github.com>
…ted modules list of module that instantiated it
I don't know how to test this. @andralex maybe check your PR against this patch?