Skip to content
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 21489 - Duplicated template instantiation using mixin insid… #12034

Merged
merged 1 commit into from
Jan 7, 2021

Conversation

BorisCarvajal
Copy link
Member

…e alias declaration

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @BorisCarvajal! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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

Auto-close Bugzilla Severity Description
21489 normal Duplicated template instantiation using mixin inside alias declaration

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#12034"

Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Thank you for the contribution! However, I do have some requests:

  • All code lines need to be covered by tests.
  • Can you please explain in a few words what was the problem with the code and how your solution fixes it?

src/dmd/typesem.d Show resolved Hide resolved
@BorisCarvajal
Copy link
Member Author

BorisCarvajal commented Jan 6, 2021

* Can you please explain in a few words what was the problem with the code and how your solution fixes it?

The code inside mixin is resolved two times when creating an alias because TypeMixin doesn't cache the semantic evaluation and aliasSemantic() indirectly calls it twice.
That leads to for example, creating two instances of a template if using this kind of mixin.

@12345swordy
Copy link
Contributor

Comment your code on why are you doing this, it hard for newcomers to understand the internals of the compiler already as it.

@BorisCarvajal
Copy link
Member Author

Comment your code on why are you doing this, it hard for newcomers to understand the internals of the compiler already as it.

Look at src/dmd/mtype.d changes:

RootObject obj; // cached result of semantic analysis.

It's easy to follow from that.

@12345swordy
Copy link
Contributor

Comment your code on why are you doing this, it hard for newcomers to understand the internals of the compiler already as it.

Look at src/dmd/mtype.d changes:

RootObject obj; // cached result of semantic analysis.

It's easy to follow from that.

No it is not. There are multiple files that are currently modified by this.

Comment on lines 3076 to 3085
RootObject o = mt.obj;
if (o)
{
pe = o.isExpression();
pt = o.isType();
ps = o.isDsymbol();
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on why are you checking this.

Copy link
Member Author

Choose a reason for hiding this comment

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

Remember: RootObject obj; // cached result of semantic analysis.

I'm checking if the object is already cached, if so just return it in the corresponding variable.

else
returnExp(e);
}
else
returnError();

mt.obj = pe ? pe : (pt ? pt : ps);
Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing here. Comment on why please.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here the opposite. I'm saving the semantic result.

Copy link
Contributor

@12345swordy 12345swordy left a comment

Choose a reason for hiding this comment

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

See my comments

@RazvanN7 RazvanN7 merged commit 4f18b27 into dlang:master Jan 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants