Skip to content

Commit d17ab8f

Browse files
[Style] Remove unused headers (#219)
Currently, there are many headers in C++ files that are not used directly. We remove all of them (thanks to clangd). Moreover, it seems that an `inline` is missing in `cpp/support/thread_pool.h`, which may lead to a potential violation of ODR in the future. Maybe this PR should be merged only after a C++ test ci is ready to ensure correctness.
1 parent 70c959f commit d17ab8f

16 files changed

+4
-26
lines changed

cpp/grammar.cc

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
#include <xgrammar/grammar.h>
77

8-
#include "grammar_data_structure.h"
98
#include "grammar_functor.h"
109
#include "grammar_parser.h"
1110
#include "grammar_serializer.h"

cpp/grammar_compiler.cc

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "grammar_data_structure.h"
1111
#include "grammar_functor.h"
1212
#include "grammar_matcher_base.h"
13-
#include "support/encoding.h"
1413
#include "support/thread_pool.h"
1514
#include "support/thread_safe_cache.h"
1615
#include "testing.h"

cpp/grammar_functor.cc

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <xgrammar/xgrammar.h>
99

1010
#include <algorithm>
11+
#include <queue>
1112
#include <unordered_set>
1213
#include <vector>
1314

cpp/grammar_functor.h

-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@
99

1010
#include <xgrammar/xgrammar.h>
1111

12-
#include <queue>
1312
#include <string>
1413

1514
#include "grammar_builder.h"
1615
#include "grammar_data_structure.h"
17-
#include "grammar_serializer.h"
1816

1917
namespace xgrammar {
2018

cpp/grammar_matcher.cc

-4
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,9 @@
88

99
#include <xgrammar/matcher.h>
1010

11-
#include <chrono>
12-
#include <queue>
13-
1411
#include "compiled_grammar_data_structure.h"
1512
#include "grammar_data_structure.h"
1613
#include "grammar_matcher_base.h"
17-
#include "grammar_serializer.h"
1814
#include "persistent_stack.h"
1915
#include "support/dynamic_bitset.h"
2016
#include "support/encoding.h"

cpp/grammar_matcher_base.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
#include <xgrammar/grammar.h>
1010

11-
#include <algorithm>
1211
#include <string>
1312
#include <vector>
1413

cpp/grammar_parser.cc

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
#include <picojson.h>
99

10-
#include <memory>
11-
1210
#include "grammar_builder.h"
1311
#include "grammar_data_structure.h"
1412
#include "support/encoding.h"

cpp/grammar_parser.h

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99

1010
#include <xgrammar/xgrammar.h>
1111

12-
#include "support/logging.h"
13-
1412
namespace xgrammar {
1513

1614
/*!

cpp/json_schema_converter.cc

-3
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@
77
#include <picojson.h>
88

99
#include <iostream>
10-
#include <map>
11-
#include <memory>
1210
#include <optional>
13-
#include <queue>
1411
#include <sstream>
1512
#include <string>
1613
#include <unordered_set>

cpp/regex_converter.cc

-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
#include "regex_converter.h"
66

77
#include <iostream>
8-
#include <optional>
98
#include <string>
109
#include <unordered_map>
11-
#include <utility>
1210
#include <vector>
1311

1412
#include "support/encoding.h"

cpp/structural_tag.cc

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "structural_tag.h"
66

77
#include <algorithm>
8-
#include <chrono>
98
#include <string>
109
#include <string_view>
1110

cpp/support/encoding.h

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
// TODO(yixin): enhance performance
99

1010
#include <cstdint>
11-
#include <iostream>
1211
#include <string>
1312
#include <unordered_map>
1413
#include <vector>

cpp/support/logging.h

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#include <sstream>
1313
#include <string>
1414

15-
#include "cpptrace.h"
16-
1715
/*!
1816
* \brief Whether or not customize the logging output.
1917
* If log customize is enabled, the user must implement

cpp/support/thread_pool.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ class ThreadPool {
172172
int unfinished_task_count_ = 0;
173173
};
174174

175-
void ParallelFor(int low, int high, int num_threads, std::function<void(int)> f) {
175+
inline void ParallelFor(int low, int high, int num_threads, std::function<void(int)> f) {
176176
if (high - low == 1) {
177177
f(low);
178178
return;

include/xgrammar/grammar.h

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <xgrammar/object.h>
1111

12-
#include <cstdint>
1312
#include <optional>
1413
#include <string>
1514
#include <vector>

include/xgrammar/object.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#ifndef XGRAMMAR_OBJECT_H_
88
#define XGRAMMAR_OBJECT_H_
99

10-
#include <memory>
11-
#include <utility>
10+
#include <memory> // IWYU pragma: keep
11+
#include <utility> // IWYU pragma: keep
1212

1313
namespace xgrammar {
1414

0 commit comments

Comments
 (0)