[dmd-internals] [D-Programming-Language/dmd] a29d09: fix Issue 5185 - Recursive template expansion erro...

GitHub noreply at github.com
Tue Dec 10 00:11:26 PST 2013


  Branch: refs/heads/master
  Home:   https://github.com/D-Programming-Language/dmd
  Commit: a29d09aee89885f59d413b1451e1ec843e1e4985
      https://github.com/D-Programming-Language/dmd/commit/a29d09aee89885f59d413b1451e1ec843e1e4985
  Author: k-hara <k.hara.pg at gmail.com>
  Date:   2013-12-09 (Mon, 09 Dec 2013)

  Changed paths:
    M src/template.c
    M test/runnable/template9.d

  Log Message:
  -----------
  fix Issue 5185 - Recursive template expansion error in class method

As the test casein 5185, `checkRecursiveExpansion` would prevent legitimate template instantiation.

If a template instance depends on the definition of itself, it is a true "recursion". But, a declaration sometimes can depend on the declaration itself.

For example, a class can have same class reference in its field (class C { C field; }). All of class types are references in D, so its type size (== definition) is equal to pointer size. So, even if self class type is used in its declaration, it won't cause definition recursion, because compiler can treat the class definition as opaque during semantic analysis of the declaration.

Returning to the template instance case, compiler cannot treat instance definition as opaque. However, to put it another way, compiler cannot detect the "true recursion" until instantiating the template. In other words, we cannot detect template recursion by merely seeing template arguments.

Therefore, I think the check is merely unnecessary. We have to rely on the nest level detector of template instantiations, and circular chain detector of `tinst` during semantic3.


  Commit: e542c5a746fbe72a984444aab2105ac5dd660ace
      https://github.com/D-Programming-Language/dmd/commit/e542c5a746fbe72a984444aab2105ac5dd660ace
  Author: Walter Bright <walter at walterbright.com>
  Date:   2013-12-10 (Tue, 10 Dec 2013)

  Changed paths:
    M src/template.c
    M test/runnable/template9.d

  Log Message:
  -----------
  Merge pull request #2940 from 9rnsr/fix5185

Issue 5185 - Recursive template expansion error in class method


Compare: https://github.com/D-Programming-Language/dmd/compare/cf0a8a4cd1f5...e542c5a746fb


More information about the dmd-internals mailing list