Skip to content

Commit 5b66cd3

Browse files
authored
Merge pull request diffblue#3296 from JohnDumbell/jd/enhancement/find_free_suffix_improvement
Adding smallest_unused_suffix cache
2 parents 1577879 + 6425eb1 commit 5b66cd3

File tree

12 files changed

+225
-76
lines changed

12 files changed

+225
-76
lines changed

jbmc/src/java_bytecode/java_bytecode_language.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Author: Daniel Kroening, [email protected]
1919
#include <util/string2int.h>
2020
#include <util/suffix.h>
2121
#include <util/symbol_table.h>
22+
#include <util/symbol_table_builder.h>
2223

2324
#include <json/json_parser.h>
2425

@@ -790,8 +791,11 @@ bool java_bytecode_languaget::typecheck(
790791
break;
791792
case LAZY_METHODS_MODE_EAGER:
792793
{
794+
symbol_table_buildert symbol_table_builder =
795+
symbol_table_buildert::wrap(symbol_table);
796+
793797
journalling_symbol_tablet journalling_symbol_table =
794-
journalling_symbol_tablet::wrap(symbol_table);
798+
journalling_symbol_tablet::wrap(symbol_table_builder);
795799

796800
// Convert all synthetic methods:
797801
for(const auto &function_id_and_type : synthetic_methods)
@@ -842,18 +846,21 @@ bool java_bytecode_languaget::generate_support_functions(
842846
{
843847
PRECONDITION(language_options_initialized);
844848

849+
symbol_table_buildert symbol_table_builder =
850+
symbol_table_buildert::wrap(symbol_table);
851+
845852
main_function_resultt res=
846853
get_main_symbol(symbol_table, main_class, get_message_handler());
847854
if(!res.is_success())
848855
return res.is_error();
849856

850857
// Load the main function into the symbol table to get access to its
851858
// parameter names
852-
convert_lazy_method(res.main_function.name, symbol_table);
859+
convert_lazy_method(res.main_function.name, symbol_table_builder);
853860

854861
// generate the test harness in __CPROVER__start and a call the entry point
855862
return java_entry_point(
856-
symbol_table,
863+
symbol_table_builder,
857864
main_class,
858865
get_message_handler(),
859866
assume_inputs_non_null,
@@ -880,12 +887,15 @@ bool java_bytecode_languaget::do_ci_lazy_method_conversion(
880887
symbol_tablet &symbol_table,
881888
method_bytecodet &method_bytecode)
882889
{
890+
symbol_table_buildert symbol_table_builder =
891+
symbol_table_buildert::wrap(symbol_table);
892+
883893
const method_convertert method_converter =
884-
[this, &symbol_table]
885-
(const irep_idt &function_id, ci_lazy_methods_neededt lazy_methods_needed)
886-
{
894+
[this, &symbol_table_builder](
895+
const irep_idt &function_id,
896+
ci_lazy_methods_neededt lazy_methods_needed) {
887897
return convert_single_method(
888-
function_id, symbol_table, std::move(lazy_methods_needed));
898+
function_id, symbol_table_builder, std::move(lazy_methods_needed));
889899
};
890900

891901
ci_lazy_methodst method_gather(

src/goto-cc/compile.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Date: June 2006
2222
#include <util/file_util.h>
2323
#include <util/get_base_name.h>
2424
#include <util/suffix.h>
25+
#include <util/symbol_table_builder.h>
2526
#include <util/tempdir.h>
2627
#include <util/unicode.h>
2728
#include <util/version.h>
@@ -697,37 +698,40 @@ void compilet::add_compiler_specific_defines(configt &config) const
697698

698699
void compilet::convert_symbols(goto_functionst &dest)
699700
{
701+
symbol_table_buildert symbol_table_builder =
702+
symbol_table_buildert::wrap(goto_model.symbol_table);
703+
700704
goto_convert_functionst converter(
701-
goto_model.symbol_table, get_message_handler());
705+
symbol_table_builder, get_message_handler());
702706

703707
// the compilation may add symbols!
704708

705709
symbol_tablet::symbolst::size_type before=0;
706710

707-
while(before != goto_model.symbol_table.symbols.size())
711+
while(before != symbol_table_builder.symbols.size())
708712
{
709-
before = goto_model.symbol_table.symbols.size();
713+
before = symbol_table_builder.symbols.size();
710714

711715
typedef std::set<irep_idt> symbols_sett;
712716
symbols_sett symbols;
713717

714-
for(const auto &named_symbol : goto_model.symbol_table.symbols)
718+
for(const auto &named_symbol : symbol_table_builder.symbols)
715719
symbols.insert(named_symbol.first);
716720

717721
// the symbol table iterators aren't stable
718722
for(const auto &symbol : symbols)
719723
{
720724
symbol_tablet::symbolst::const_iterator s_it =
721-
goto_model.symbol_table.symbols.find(symbol);
722-
CHECK_RETURN(s_it != goto_model.symbol_table.symbols.end());
725+
symbol_table_builder.symbols.find(symbol);
726+
CHECK_RETURN(s_it != symbol_table_builder.symbols.end());
723727

724728
if(
725729
s_it->second.is_function() && !s_it->second.is_compiled() &&
726730
s_it->second.value.is_not_nil())
727731
{
728732
debug() << "Compiling " << s_it->first << eom;
729733
converter.convert_function(s_it->first, dest.function_map[s_it->first]);
730-
goto_model.symbol_table.get_writeable_ref(symbol).set_compiled();
734+
symbol_table_builder.get_writeable_ref(symbol).set_compiled();
731735
}
732736
}
733737
}

src/goto-programs/goto_convert.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Author: Daniel Kroening, [email protected]
1212
#include "goto_convert.h"
1313

1414
#include <util/arith_tools.h>
15+
#include <util/c_types.h>
1516
#include <util/cprover_prefix.h>
1617
#include <util/exception_utils.h>
1718
#include <util/expr_util.h>
@@ -20,8 +21,7 @@ Author: Daniel Kroening, [email protected]
2021
#include <util/simplify_expr.h>
2122
#include <util/std_expr.h>
2223
#include <util/symbol_table.h>
23-
24-
#include <util/c_types.h>
24+
#include <util/symbol_table_builder.h>
2525

2626
#include "goto_convert_class.h"
2727
#include "destructor.h"
@@ -1939,7 +1939,9 @@ void goto_convert(
19391939
message_handlert &message_handler,
19401940
const irep_idt &mode)
19411941
{
1942-
goto_convertt goto_convert(symbol_table, message_handler);
1942+
symbol_table_buildert symbol_table_builder =
1943+
symbol_table_buildert::wrap(symbol_table);
1944+
goto_convertt goto_convert(symbol_table_builder, message_handler);
19431945
goto_convert.goto_convert(code, dest, mode);
19441946
}
19451947

src/goto-programs/goto_convert_functions.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Date: June 2003
1111
#include "goto_convert_functions.h"
1212

1313
#include <util/base_type.h>
14+
#include <util/fresh_symbol.h>
15+
#include <util/prefix.h>
1416
#include <util/std_code.h>
1517
#include <util/symbol_table.h>
16-
#include <util/prefix.h>
17-
#include <util/fresh_symbol.h>
18+
#include <util/symbol_table_builder.h>
1819

1920
#include "goto_inline.h"
2021

@@ -217,18 +218,23 @@ void goto_convert(
217218
goto_modelt &goto_model,
218219
message_handlert &message_handler)
219220
{
221+
symbol_table_buildert symbol_table_builder =
222+
symbol_table_buildert::wrap(goto_model.symbol_table);
223+
220224
goto_convert(
221-
goto_model.symbol_table,
222-
goto_model.goto_functions,
223-
message_handler);
225+
symbol_table_builder, goto_model.goto_functions, message_handler);
224226
}
225227

226228
void goto_convert(
227229
symbol_table_baset &symbol_table,
228230
goto_functionst &functions,
229231
message_handlert &message_handler)
230232
{
231-
goto_convert_functionst goto_convert_functions(symbol_table, message_handler);
233+
symbol_table_buildert symbol_table_builder =
234+
symbol_table_buildert::wrap(symbol_table);
235+
236+
goto_convert_functionst goto_convert_functions(
237+
symbol_table_builder, message_handler);
232238

233239
goto_convert_functions.goto_convert(functions);
234240
}
@@ -239,7 +245,11 @@ void goto_convert(
239245
goto_functionst &functions,
240246
message_handlert &message_handler)
241247
{
242-
goto_convert_functionst goto_convert_functions(symbol_table, message_handler);
248+
symbol_table_buildert symbol_table_builder =
249+
symbol_table_buildert::wrap(symbol_table);
250+
251+
goto_convert_functionst goto_convert_functions(
252+
symbol_table_builder, message_handler);
243253

244254
goto_convert_functions.convert_function(
245255
identifier, functions.function_map[identifier]);

src/goto-programs/lazy_goto_functions_map.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
#include "goto_functions.h"
1212
#include "goto_convert_functions.h"
1313

14-
#include <util/message.h>
1514
#include <langapi/language_file.h>
1615
#include <util/journalling_symbol_table.h>
16+
#include <util/message.h>
17+
#include <util/symbol_table_builder.h>
1718

1819
/// Provides a wrapper for a map of lazily loaded goto_functiont.
1920
/// This incrementally builds a goto-functions object, while permitting
@@ -142,8 +143,11 @@ class lazy_goto_functions_mapt final
142143
// const first
143144
reference ensure_function_loaded_internal(const key_type &name) const
144145
{
146+
symbol_table_buildert symbol_table_builder =
147+
symbol_table_buildert::wrap(symbol_table);
148+
145149
journalling_symbol_tablet journalling_table =
146-
journalling_symbol_tablet::wrap(symbol_table);
150+
journalling_symbol_tablet::wrap(symbol_table_builder);
147151
reference named_function=ensure_entry_converted(name, journalling_table);
148152
mapped_type function=named_function.second;
149153
if(processed_functions.count(name)==0)

src/jsil/jsil_typecheck.h

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ Author: Michael Tautschnig, [email protected]
1414

1515
#include <unordered_set>
1616

17-
#include <util/typecheck.h>
1817
#include <util/namespace.h>
1918
#include <util/std_code.h>
19+
#include <util/symbol_table_base.h>
20+
#include <util/typecheck.h>
2021

2122
class symbol_exprt;
2223
class codet;
@@ -34,12 +35,12 @@ class jsil_typecheckt:public typecheckt
3435
{
3536
public:
3637
jsil_typecheckt(
37-
symbol_tablet &_symbol_table,
38-
message_handlert &_message_handler):
39-
typecheckt(_message_handler),
40-
symbol_table(_symbol_table),
41-
ns(symbol_table),
42-
proc_name()
38+
symbol_table_baset &_symbol_table,
39+
message_handlert &_message_handler)
40+
: typecheckt(_message_handler),
41+
symbol_table(_symbol_table),
42+
ns(symbol_table),
43+
proc_name()
4344
{
4445
}
4546

@@ -49,7 +50,7 @@ class jsil_typecheckt:public typecheckt
4950
virtual void typecheck_expr(exprt &expr);
5051

5152
protected:
52-
symbol_tablet &symbol_table;
53+
symbol_table_baset &symbol_table;
5354
const namespacet ns;
5455
// prefix to variables which is set in typecheck_declaration
5556
irep_idt proc_name;

src/linking/linking_class.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ class linkingt:public typecheckt
2828
{
2929
public:
3030
linkingt(
31-
symbol_tablet &_main_symbol_table,
32-
symbol_tablet &_src_symbol_table,
33-
message_handlert &_message_handler):
34-
typecheckt(_message_handler),
35-
main_symbol_table(_main_symbol_table),
36-
src_symbol_table(_src_symbol_table),
37-
ns(_main_symbol_table)
31+
symbol_table_baset &_main_symbol_table,
32+
symbol_table_baset &_src_symbol_table,
33+
message_handlert &_message_handler)
34+
: typecheckt(_message_handler),
35+
main_symbol_table(_main_symbol_table),
36+
src_symbol_table(_src_symbol_table),
37+
ns(_main_symbol_table)
3838
{
3939
}
4040

@@ -167,8 +167,8 @@ class linkingt:public typecheckt
167167
const struct_typet &old_type,
168168
const struct_typet &new_type);
169169

170-
symbol_tablet &main_symbol_table;
171-
symbol_tablet &src_symbol_table;
170+
symbol_table_baset &main_symbol_table;
171+
symbol_table_baset &src_symbol_table;
172172

173173
namespacet ns;
174174

src/util/journalling_symbol_table.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ class journalling_symbol_tablet : public symbol_table_baset
100100
return result;
101101
}
102102

103+
std::size_t next_unused_suffix(const std::string &prefix) const override
104+
{
105+
return base_symbol_table.next_unused_suffix(prefix);
106+
}
107+
103108
virtual std::pair<symbolt &, bool> insert(symbolt symbol) override
104109
{
105110
std::pair<symbolt &, bool> result =

src/util/namespace.cpp

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,6 @@ Author: Daniel Kroening, [email protected]
1919
#include "string2int.h"
2020
#include "symbol_table.h"
2121

22-
/// Find smallest unused integer i so that prefix + std::to_string(i)
23-
/// does not exist in the list \p symbols.
24-
/// \param prefix: A string denoting the prefix we want to find the
25-
/// smallest suffix of.
26-
/// \param symbols: The list of symbols we look in for.
27-
/// \return The small unused suffix size.
28-
static std::size_t smallest_unused_suffix(
29-
const std::string &prefix,
30-
const symbol_tablet::symbolst &symbols)
31-
{
32-
std::size_t max_nr = 0;
33-
34-
while(symbols.find(prefix + std::to_string(max_nr)) != symbols.end())
35-
++max_nr;
36-
37-
return max_nr;
38-
}
39-
4022
namespace_baset::~namespace_baset()
4123
{
4224
}
@@ -168,10 +150,10 @@ std::size_t namespacet::smallest_unused_suffix(const std::string &prefix) const
168150
std::size_t m = 0;
169151

170152
if(symbol_table1!=nullptr)
171-
m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table1->symbols));
153+
m = std::max(m, symbol_table1->next_unused_suffix(prefix));
172154

173155
if(symbol_table2!=nullptr)
174-
m = std::max(m, ::smallest_unused_suffix(prefix, symbol_table2->symbols));
156+
m = std::max(m, symbol_table2->next_unused_suffix(prefix));
175157

176158
return m;
177159
}
@@ -221,7 +203,7 @@ multi_namespacet::smallest_unused_suffix(const std::string &prefix) const
221203
std::size_t m = 0;
222204

223205
for(const auto &st : symbol_table_list)
224-
m = std::max(m, ::smallest_unused_suffix(prefix, st->symbols));
206+
m = std::max(m, st->next_unused_suffix(prefix));
225207

226208
return m;
227209
}

0 commit comments

Comments
 (0)