Skip to content

Conversation

@trivialfis
Copy link
Member

@trivialfis trivialfis commented Jan 26, 2026

We have a semi-working C++ "interface" that's not really an interface. Some files are impossible to use without hacking XGBoost's internals due to forward declarations.

This PR hides the following files to reduce confusion and to reduce the need for broken forward declarations:

  • learner.h
  • gbm.h
  • cache.h
  • predictor.h

Aside from automated header sorting, I did not make many changes. This is to ensure Git recognizes this PR as a simple rename.

We have a semi-working C++ "interface" that's not really an interface. Some files are
impossible to be used without hacking inside XGBoost.

This PR hides the following files to reduce confusion and to reduce the need for broken
forward declarations:

- learner.h
- gbm.h
- cache.h
- predictor.h

Aside from automated headers sorting, I did not make much change, to make sure git
recognize this PR is doing a simple rename.
@trivialfis
Copy link
Member Author

cc @RAMitchell in case this conflicts with the new design of SHAP.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR moves internal header files from the public include/xgboost directory to the src directory to better encapsulate XGBoost's internal implementation details. The headers moved include learner.h, gbm.h, cache.h, and predictor.h, which were previously exposed as part of the public API but were not usable without access to XGBoost's internals.

Changes:

  • Moved four internal header files from include/xgboost/ to their respective implementation directories in src/
  • Updated all include paths across test files, source files, and plugins to reference the new locations
  • Changed header guards from #ifndef/#define/#endif style to #pragma once
  • Updated copyright years from 2025 to 2026 for modified files

Reviewed changes

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

Show a summary per file
File Description
tests/cpp/tree/test_prune.cc Removed unused xgboost/learner.h include
tests/cpp/test_serialization.cc Updated to include ../../src/learner.h instead of xgboost/learner.h
tests/cpp/test_multi_target.cc Updated learner.h include path and reformatted includes
tests/cpp/test_learner.cu Updated learner.h include path
tests/cpp/test_learner.cc Updated learner.h and predictor.h include paths
tests/cpp/test_cache.cc Updated cache.h include path from xgboost/cache.h to ../../src/common/cache.h
tests/cpp/predictor/test_predictor.h Updated predictor.h include path
tests/cpp/predictor/test_predictor.cc Updated predictor.h include path
tests/cpp/predictor/test_gpu_predictor.cu Updated learner.h and predictor.h include paths
tests/cpp/predictor/test_cpu_predictor.cc Updated predictor.h include path
tests/cpp/plugin/test_sycl_predictor.cc Updated predictor.h include path
tests/cpp/linear/test_linear.cu Removed unused xgboost/gbm.h include
tests/cpp/linear/test_linear.cc Removed xgboost/gbm.h and added ../../../src/gbm/gblinear_model.h
tests/cpp/helpers.h Updated learner.h include path
tests/cpp/helpers.cc Updated learner.h, gbm.h, and predictor.h include paths
tests/cpp/gbm/test_gbtree.cu Updated learner.h include path
tests/cpp/gbm/test_gbtree.cc Updated learner.h and predictor.h include paths
tests/cpp/gbm/test_gblinear.cu Updated learner.h include path
tests/cpp/gbm/test_gblinear.cc Updated gbm.h and learner.h include paths
tests/cpp/common/test_categorical.cc Updated learner.h include path
tests/cpp/c_api/test_c_api.cc Updated learner.h include path
src/predictor/utils.h Updated learner.h to use relative path ../learner.h
src/predictor/predictor.h Moved from include, changed to #pragma once, updated cache.h path
src/predictor/predictor.cc Updated to include local predictor.h and relative learner.h path
src/predictor/gpu_predictor.cu Updated to include local predictor.h
src/predictor/cpu_predictor.cc Updated learner.h and predictor.h to use relative paths
src/metric/rank_metric.cc Updated cache.h include path from xgboost/cache.h to ../common/cache.h
src/learner.h Moved from include, changed to #pragma once
src/learner.cc Updated to include local learner.h and relative predictor.h path
src/gbm/gbtree_model.h Updated learner.h to use relative path ../learner.h
src/gbm/gbtree_model.cc Updated learner.h to use relative path
src/gbm/gbtree.h Updated gbm.h and predictor.h to use relative paths
src/gbm/gbtree.cc Updated gbm.h and predictor.h to use relative paths
src/gbm/gbm.h Moved from include, changed to #pragma once
src/gbm/gbm.cc Updated to include local gbm.h and relative learner.h path
src/gbm/gblinear_model.h Updated learner.h to use relative path ../learner.h
src/gbm/gblinear.cc Updated gbm.h, learner.h, and predictor.h to use relative paths
src/data/data.cc Updated learner.h to use relative path ../learner.h
src/common/cache.h Moved from include, changed to #pragma once
src/common/api_entry.h Updated predictor.h to use relative path ../predictor/predictor.h
src/c_api/c_api_utils.h Updated learner.h to use relative path ../learner.h
src/c_api/c_api.cu Updated learner.h to use relative path
src/c_api/c_api.cc Updated learner.h to use relative path, removed predictor.h include
plugin/sycl/predictor/predictor.cc Updated predictor.h to use relative path ../../../src/predictor/predictor.h

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

@hcho3
Copy link
Collaborator

hcho3 commented Jan 26, 2026

Have you considered putting internal headers to include/detail subdirectory, like RAPIDS does?

@trivialfis
Copy link
Member Author

Yes. We will have to add a set of sub directories into details like details/tree/hist. Do you see any benefits of doing so?

@hcho3
Copy link
Collaborator

hcho3 commented Jan 26, 2026

Using src for internal headers will require lots of preceding ../../.. in header includes, whereas using include/detail will not. Granted, we'd need to add subdirectories to include/detail, increasing the complexity somewhat.

Or we should probably consider adding src to include path, so that we don't need the ../../.. ?

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.

2 participants