Skip to content

Auto include template args#103

Merged
kwabenantim merged 3 commits into
developfrom
97-auto-include-template-args
Jul 23, 2026
Merged

Auto include template args#103
kwabenantim merged 3 commits into
developfrom
97-auto-include-template-args

Conversation

@kwabenantim

Copy link
Copy Markdown
Member

Extends #97 by including args in template signatures that never appear in method signatures.

kwabenantim and others added 2 commits July 23, 2026 20:42
auto_includes previously resolved headers only for project types named in a
class's wrapped method/constructor signatures. A type used solely as a template
argument of an instantiation - e.g. the CELL_CYCLE_MODEL in pychaste's
CellsGenerator<CELL_CYCLE_MODEL, DIM> - never appears in a signature, so its
header still had to be listed by hand under source_includes.

Extend resolve_auto_includes() to also resolve the project types named in
class_info.template_arg_lists (the instantiation arguments), reusing the existing
type->header map. Numeric args (dimensions) and library types resolve to nothing,
and the class's own header is dropped as before. Folded into the existing
auto_includes flag - no new config.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Add a header-only CellFactory<CELL_TYPE, DIM> to the cells example that mirrors
pychaste's CellsGenerator: CELL_TYPE is used only inside CreateCell() and never
appears in the wrapped interface, so cppwg sees it only as a template argument.
Wrapped via template_substitutions with [[Cell, 2], [Cell, 3]]; the package-level
auto_includes resolves Cell.hpp from those arguments, so the generated wrapper
(which odr-uses CreateCell and needs the complete Cell) compiles.

Includes the regenerated dynamic/wrappers (CellFactory.cppwg.* auto-includes
Cell.hpp; main + header collection register the two instantiations), the
CellFactory alias in pycells/__init__.py, and a test asserting the instantiations
import and work.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Extends cppwg’s auto_includes dependency resolution to also consider project types that appear only in a class’s template instantiation arguments (not in wrapped method/constructor signatures), addressing cases like Foo<Bar, DIM> where Bar.hpp is still required for the generated wrapper to compile.

Changes:

  • Update PackageInfo.resolve_auto_includes() to resolve headers for project-type template arguments found in class_info.template_arg_lists.
  • Add unit test coverage ensuring template-argument-only project types are auto-included while numeric args and the class’s own header are ignored.
  • Expand the examples/cells package to include a CellFactory<Cell, DIM> case that depends on template-argument auto-includes, with updated wrappers and Python exports.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cppwg/info/package_info.py Implements template-argument scanning in resolve_auto_includes() to auto-include headers for project types referenced only via instantiation args.
tests/test_package_info.py Adds a unit test asserting template-argument project types resolve to their headers and numeric args resolve to nothing.
README.md Documents that auto_includes now scans both wrapped signatures and template instantiation arguments.
examples/cells/src/cpp/cell/CellFactory.hpp Introduces a minimal header-only templated factory to exercise the new auto-include behavior in an example package.
examples/cells/dynamic/config.yaml Wrap configuration for CellFactory with template substitutions used by the example.
examples/cells/dynamic/wrappers/wrapper_header_collection.cppwg.hpp Includes and instantiates CellFactory<Cell, DIM> in the example wrapper header collection.
examples/cells/dynamic/wrappers/all/CellFactory.cppwg.hpp Adds the generated wrapper declarations for the new example template instantiations.
examples/cells/dynamic/wrappers/all/CellFactory.cppwg.cpp Adds the generated pybind11 bindings for CellFactory<Cell, 2> and CellFactory<Cell, 3>.
examples/cells/dynamic/wrappers/all/_pycells_all.main.cppwg.cpp Registers the new CellFactory bindings with the example module.
examples/cells/src/py/pycells/__init__.py Exposes CellFactory via TemplateClassDict so CellFactory[Cell, DIM] works in Python.
examples/cells/tests/test_cells.py Adds an integration-style test that imports and uses CellFactory[Cell, DIM], validating wrapper compilation and runtime behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread examples/cells/src/cpp/cell/CellFactory.hpp Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@kwabenantim
kwabenantim marked this pull request as ready for review July 23, 2026 20:02
@kwabenantim
kwabenantim merged commit 6bf4c4e into develop Jul 23, 2026
13 checks passed
@kwabenantim
kwabenantim deleted the 97-auto-include-template-args branch July 23, 2026 20:16
@kwabenantim kwabenantim linked an issue Jul 23, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auto-include headers for wrapped classes

2 participants