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 19105 - Bogus recursive template expansion via getSymbolsByUDA #7100

Merged
merged 1 commit into from
Jul 10, 2019

Conversation

RazvanN7
Copy link
Collaborator

@RazvanN7 RazvanN7 commented Jul 4, 2019

Issue 19105 was reported as a compiler bug. The reported code is:

module junk;

import std.traits;

struct A(Args...) {}
struct B {}
alias C = A!( getSymbolsByUDA!(junk, B) );

But reading the docs of getSymbolsByUDAis seems that it was meant to work only with aggregate declarations (not with modules). I added a template constraint that requires that the symbol passed is an aggregated type.

The code fails because while getting the members of junk, the innards of getSymbolsByUDA uses aliases for the list of symbols and at some point alias C ends up aliasing to something that aliases itself.

@RazvanN7 RazvanN7 requested a review from PetarKirov as a code owner July 4, 2019 13:10
@dlang-bot
Copy link
Contributor

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 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
19105 normal Bogus recursive template expansion via getSymbolsByUDA

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 + phobos#7100"

@thewilsonator
Copy link
Contributor

This should have that as a test then.

@RazvanN7
Copy link
Collaborator Author

@thewilsonator ok. done.

@dlang-bot dlang-bot merged commit 135f580 into dlang:master Jul 10, 2019
@Biotronic
Copy link
Contributor

This is the wrong fix for 19105. 19105 is in fact a DMD issue, as can be showed by this code:

import std.traits;

struct A(Args...) {}

struct S1 {
    // Recursive template expansion
    alias C = A!( getSymbolsByUDA!(S1, A) );
}
struct S2 {
    // precompute the result:
    alias tmp = getSymbolsByUDA!(S2, A);
    // No recursive template expansion
    alias C = A!( getSymbolsByUDA!(S2, A) );
}

The problem seems to be with caching in the compiler, and the only thing this PR has changed is it's made valid use cases fail to compile.

Here's a reduced test case for the behavior, which doesn't use getSymbolsByUDA:

template test(alias T) {
    enum i = __traits(compiles, __traits(getMember, T, "C"));
    alias test = int;
}

struct A(Args...) {}

struct S1 {
    // Recursive template expansion
    alias C = A!(test!S1);
}
struct S2 {
    // No error
    alias a = test!S2;
    alias C = A!(test!S2);
}

@PetarKirov
Copy link
Member

CC @RazvanN7

@zorael
Copy link

zorael commented Aug 17, 2019

Ping. Still in 2.088 beta

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.

6 participants