Skip to content

Commit 6dbd1ba

Browse files
committed
Add second optimization for get_declaration_of, and fix some corner case bugs
On my machine, with this commit here are some typical cppfront compile time data points: - `reflect.h2`: 0.5s - `pure2-last-use.cpp2`: 0.3s - all 134 regression tests: 6.3s When I added the optimization to cache results of calls to g_d_o and checked the results to make sure they were unchanged, I noticed that in fact g_d_o was occasionally returning different answers in different calls for the same arguments. All the examples I found were corner cases in `pure2-last-use.cpp2`. The lookup bugs I found are now fixed in this commit. This commit moves the `-_debug` command line flag from reporting stack instrumentation to reporting things I'm now coding here: Now using that flag will check the g_d_o results computed with vs. without the two new optimizations and ensure the answers are the same. (Disclaimer: Because this exercise led to a few bug fixes, which were applied to both the old and new functions, this isn't quite identical to comparing it to the true "old" way which contained a couple of I-think-innocuous-but-now-fixed bugs. The proof of the pudding is in the regression tests being identical.)
1 parent 166b59e commit 6dbd1ba

File tree

4 files changed

+339
-122
lines changed

4 files changed

+339
-122
lines changed

Diff for: regression-tests/test-results/run-tests.bat

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ cppfront.exe -version > version
33
del *.cpp *.output
44
copy ..\*.cpp2 .
55
set count=0
6+
7+
set STARTTIME=%TIME%
8+
69
for %%f in (mixed-*.cpp2) do (
710
echo Starting cppfront.exe %%f
811
cppfront.exe %%f > %%f.output 2>&1
@@ -29,3 +32,8 @@ echo. %total_count% total
2932
if %total_count% NEQ %count% (
3033
echo. *** MISMATCH: should equal total tests run
3134
)
35+
36+
set ENDTIME=%TIME%
37+
echo.
38+
echo Start time: %STARTTIME%
39+
echo End time: %ENDTIME%

Diff for: source/common.h

+21-16
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ struct error_entry
977977
template <typename T>
978978
class stable_vector
979979
{
980-
static constexpr size_t PageSize = 3; // 1'000;
980+
static constexpr size_t PageSize = 1'000;
981981

982982
std::vector< std::vector<T> > data;
983983

@@ -1033,10 +1033,15 @@ class stable_vector
10331033
}
10341034

10351035
auto pop_back() -> void {
1036-
data.back().pop_back();
1037-
if (data.back().size() == 0) {
1036+
bounds_safety.enforce(size() > 0);
1037+
if (
1038+
data.back().empty()
1039+
&& data.size() > 1
1040+
)
1041+
{
10381042
data.pop_back();
10391043
}
1044+
data.back().pop_back();
10401045
}
10411046

10421047
//-------------------------------------------------------------------
@@ -1190,21 +1195,21 @@ class stackinstr
11901195

11911196
public:
11921197
struct guard {
1193-
guard( std::string_view name, std::string_view file, int line, char* p ) {
1194-
if (flag_internal_debug) {
1195-
entries.emplace_back(name, file, line ,p);
1196-
if (ssize(deepest) < ssize(entries)) {
1197-
deepest = entries;
1198-
}
1199-
if (largest.empty() || largest.back().cumulative < entries.back().cumulative) {
1200-
largest = entries;
1201-
}
1202-
}
1198+
guard( std::string_view /*name*/, std::string_view /*file*/, int /*line*/, char* /*p*/ ) {
1199+
//if (flag_internal_debug) {
1200+
// entries.emplace_back(name, file, line ,p);
1201+
// if (ssize(deepest) < ssize(entries)) {
1202+
// deepest = entries;
1203+
// }
1204+
// if (largest.empty() || largest.back().cumulative < entries.back().cumulative) {
1205+
// largest = entries;
1206+
// }
1207+
//}
12031208
}
12041209
~guard() {
1205-
if (flag_internal_debug) {
1206-
entries.pop_back();
1207-
}
1210+
//if (flag_internal_debug) {
1211+
// entries.pop_back();
1212+
//}
12081213
}
12091214
};
12101215

Diff for: source/cppfront.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ auto main(
141141
}
142142
}
143143

144-
if (flag_internal_debug) {
145-
stackinstr::print_deepest();
146-
stackinstr::print_largest();
147-
}
144+
//if (flag_internal_debug) {
145+
// stackinstr::print_deepest();
146+
// stackinstr::print_largest();
147+
//}
148148

149149
return exit_status;
150150
}

0 commit comments

Comments
 (0)