Skip to content

Commit e934867

Browse files
committed
Provide a journalling symbol table to process-goto-function
This means that process_goto_function (the per-function post-processing driver) gets, and can continue to use, a journal of symbols created, changed and deleted in the course of loading this function. That means it can implement things like add-failed-symbols affecting only new/changed symbols, rather than making a pass over the whole symbol table and so incurring cost quadratic in the number of functions.
1 parent f0f50e3 commit e934867

23 files changed

+101
-82
lines changed

src/goto-programs/convert_nondet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Author: Reuben Thomas, [email protected]
3232
static goto_programt::targett insert_nondet_init_code(
3333
goto_programt &goto_program,
3434
const goto_programt::targett &target,
35-
symbol_tablet &symbol_table,
35+
symbol_table_baset &symbol_table,
3636
message_handlert &message_handler,
3737
const object_factory_parameterst &object_factory_parameters)
3838
{
@@ -113,7 +113,7 @@ static goto_programt::targett insert_nondet_init_code(
113113
/// \param max_nondet_array_length: Maximum size of new nondet arrays.
114114
void convert_nondet(
115115
goto_programt &goto_program,
116-
symbol_tablet &symbol_table,
116+
symbol_table_baset &symbol_table,
117117
message_handlert &message_handler,
118118
const object_factory_parameterst &object_factory_parameters)
119119
{
@@ -146,7 +146,7 @@ void convert_nondet(
146146

147147
void convert_nondet(
148148
goto_functionst &goto_functions,
149-
symbol_tablet &symbol_table,
149+
symbol_table_baset &symbol_table,
150150
message_handlert &message_handler,
151151
const object_factory_parameterst &object_factory_parameters)
152152
{

src/goto-programs/convert_nondet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Author: Reuben Thomas, [email protected]
1515
#include <cstddef> // size_t
1616

1717
class goto_functionst;
18-
class symbol_tablet;
18+
class symbol_table_baset;
1919
class goto_modelt;
2020
class goto_model_functiont;
2121
class message_handlert;
@@ -30,7 +30,7 @@ struct object_factory_parameterst;
3030
/// objects.
3131
void convert_nondet(
3232
goto_functionst &,
33-
symbol_tablet &,
33+
symbol_table_baset &,
3434
message_handlert &,
3535
const object_factory_parameterst &object_factory_parameters);
3636

src/goto-programs/goto_convert.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2178,7 +2178,7 @@ const symbolt &goto_convertt::lookup(const irep_idt &identifier)
21782178

21792179
void goto_convert(
21802180
const codet &code,
2181-
symbol_tablet &symbol_table,
2181+
symbol_table_baset &symbol_table,
21822182
goto_programt &dest,
21832183
message_handlert &message_handler)
21842184
{
@@ -2212,7 +2212,7 @@ void goto_convert(
22122212
}
22132213

22142214
void goto_convert(
2215-
symbol_tablet &symbol_table,
2215+
symbol_table_baset &symbol_table,
22162216
goto_programt &dest,
22172217
message_handlert &message_handler)
22182218
{

src/goto-programs/goto_convert.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ Author: Daniel Kroening, [email protected]
2020
// start from given code
2121
void goto_convert(
2222
const codet &code,
23-
symbol_tablet &symbol_table,
23+
symbol_table_baset &symbol_table,
2424
goto_programt &dest,
2525
message_handlert &message_handler);
2626

2727
// start from "main"
2828
void goto_convert(
29-
symbol_tablet &symbol_table,
29+
symbol_table_baset &symbol_table,
3030
goto_programt &dest,
3131
message_handlert &message_handler);
3232

src/goto-programs/goto_convert_class.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class goto_convertt:public messaget
2929
void goto_convert(const codet &code, goto_programt &dest);
3030

3131
goto_convertt(
32-
symbol_tablet &_symbol_table,
32+
symbol_table_baset &_symbol_table,
3333
message_handlert &_message_handler):
3434
messaget(_message_handler),
3535
symbol_table(_symbol_table),
@@ -44,7 +44,7 @@ class goto_convertt:public messaget
4444
}
4545

4646
protected:
47-
symbol_tablet &symbol_table;
47+
symbol_table_baset &symbol_table;
4848
namespacet ns;
4949
unsigned temporary_counter;
5050
std::string tmp_symbol_prefix;

src/goto-programs/goto_convert_functions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Date: June 2003
2121
#include "goto_inline.h"
2222

2323
goto_convert_functionst::goto_convert_functionst(
24-
symbol_tablet &_symbol_table,
24+
symbol_table_baset &_symbol_table,
2525
message_handlert &_message_handler):
2626
goto_convertt(_symbol_table, _message_handler)
2727
{
@@ -234,7 +234,7 @@ void goto_convert(
234234
}
235235

236236
void goto_convert(
237-
symbol_tablet &symbol_table,
237+
symbol_table_baset &symbol_table,
238238
goto_functionst &functions,
239239
message_handlert &message_handler)
240240
{
@@ -269,7 +269,7 @@ void goto_convert(
269269

270270
void goto_convert(
271271
const irep_idt &identifier,
272-
symbol_tablet &symbol_table,
272+
symbol_table_baset &symbol_table,
273273
goto_functionst &functions,
274274
message_handlert &message_handler)
275275
{

src/goto-programs/goto_convert_functions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Date: June 2003
2020

2121
// convert it all!
2222
void goto_convert(
23-
symbol_tablet &symbol_table,
23+
symbol_table_baset &symbol_table,
2424
goto_functionst &functions,
2525
message_handlert &);
2626

@@ -32,7 +32,7 @@ void goto_convert(
3232
// just convert a specific function
3333
void goto_convert(
3434
const irep_idt &identifier,
35-
symbol_tablet &symbol_table,
35+
symbol_table_baset &symbol_table,
3636
goto_functionst &functions,
3737
message_handlert &);
3838

@@ -45,7 +45,7 @@ class goto_convert_functionst:public goto_convertt
4545
goto_functionst::goto_functiont &result);
4646

4747
goto_convert_functionst(
48-
symbol_tablet &_symbol_table,
48+
symbol_table_baset &_symbol_table,
4949
message_handlert &_message_handler);
5050

5151
virtual ~goto_convert_functionst();

src/goto-programs/goto_model.h

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#define CPROVER_GOTO_PROGRAMS_GOTO_MODEL_H
1414

1515
#include <util/symbol_table.h>
16+
#include <util/journalling_symbol_table.h>
1617

1718
#include "goto_functions.h"
1819

@@ -82,9 +83,12 @@ class goto_model_functiont
8283
/// goto programs, specifically incrementing its unused_location_number
8384
/// member each time a program is re-numbered.
8485
/// \param goto_function: function to wrap.
85-
explicit goto_model_functiont(
86-
goto_modelt &goto_model, goto_functionst::goto_functiont &goto_function):
87-
goto_model(goto_model),
86+
goto_model_functiont(
87+
journalling_symbol_tablet &symbol_table,
88+
goto_functionst &goto_functions,
89+
goto_functionst::goto_functiont &goto_function):
90+
symbol_table(symbol_table),
91+
goto_functions(goto_functions),
8892
goto_function(goto_function)
8993
{
9094
}
@@ -94,14 +98,16 @@ class goto_model_functiont
9498
/// program order within the program.
9599
void compute_location_numbers()
96100
{
97-
goto_model.goto_functions.compute_location_numbers(goto_function.body);
101+
goto_functions.compute_location_numbers(goto_function.body);
98102
}
99103

100104
/// Get symbol table
101-
/// \return symbol table from the associated GOTO model
102-
symbol_tablet &get_symbol_table()
105+
/// \return journalling symbol table that (a) wraps the global symbol table,
106+
/// and (b) has recorded all symbol mutations (insertions, updates and
107+
/// deletions) that resulted from creating `goto_function`.
108+
journalling_symbol_tablet &get_symbol_table()
103109
{
104-
return goto_model.symbol_table;
110+
return symbol_table;
105111
}
106112

107113
/// Get GOTO function
@@ -111,17 +117,9 @@ class goto_model_functiont
111117
return goto_function;
112118
}
113119

114-
/// Get GOTO model. This returns a const reference because this interface is
115-
/// intended for use where non-const access to the whole model should not be
116-
/// allowed.
117-
/// \return const view of the whole GOTO model.
118-
const goto_modelt &get_goto_model()
119-
{
120-
return goto_model;
121-
}
122-
123120
private:
124-
goto_modelt &goto_model;
121+
journalling_symbol_tablet &symbol_table;
122+
goto_functionst &goto_functions;
125123
goto_functionst::goto_functiont &goto_function;
126124
};
127125

src/goto-programs/lazy_goto_functions_map.h

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "goto_convert_functions.h"
1212
#include <util/message.h>
1313
#include <util/language_file.h>
14-
14+
#include <util/journalling_symbol_table.h>
1515

1616
/// Provides a wrapper for a map of lazily loaded goto_functiont.
1717
/// This incrementally builds a goto-functions object, while permitting
@@ -48,7 +48,9 @@ class lazy_goto_functions_mapt final
4848
typedef std::size_t size_type;
4949

5050
typedef
51-
std::function<void(goto_functionst::goto_functiont &function)>
51+
std::function<void(
52+
goto_functionst::goto_functiont &function,
53+
journalling_symbol_tablet &function_symbols)>
5254
post_process_functiont;
5355

5456
private:
@@ -61,11 +63,8 @@ class lazy_goto_functions_mapt final
6163

6264
language_filest &language_files;
6365
symbol_tablet &symbol_table;
64-
// This is mutable because it has internal state that it changes during the
65-
// course of conversion. Strictly it should make that state mutable or
66-
// recreate it for each conversion, but it's easier just to store it mutable.
67-
mutable goto_convert_functionst convert_functions;
6866
const post_process_functiont post_process_function;
67+
message_handlert &message_handler;
6968

7069
public:
7170
/// Creates a lazy_goto_functions_mapt.
@@ -78,8 +77,8 @@ class lazy_goto_functions_mapt final
7877
: goto_functions(goto_functions),
7978
language_files(language_files),
8079
symbol_table(symbol_table),
81-
convert_functions(symbol_table, message_handler),
82-
post_process_function(std::move(post_process_function))
80+
post_process_function(std::move(post_process_function)),
81+
message_handler(message_handler)
8382
{
8483
}
8584

@@ -122,29 +121,43 @@ class lazy_goto_functions_mapt final
122121
// const first
123122
reference ensure_function_loaded_internal(const key_type &name) const
124123
{
125-
reference named_function=ensure_entry_converted(name);
124+
journalling_symbol_tablet journalling_table =
125+
journalling_symbol_tablet::wrap(symbol_table);
126+
reference named_function=ensure_entry_converted(name, journalling_table);
126127
mapped_type function=named_function.second;
127128
if(processed_functions.count(name)==0)
128129
{
129130
// Run function-pass conversions
130-
post_process_function(function);
131+
post_process_function(function, journalling_table);
131132
// Assign procedure-local location numbers for now
132133
function.body.compute_location_numbers();
133134
processed_functions.insert(name);
134135
}
135136
return named_function;
136137
}
137138

138-
reference ensure_entry_converted(const key_type &name) const
139+
/// Convert a function if not already converted, then return a reference to
140+
/// its goto_functionst map entry.
141+
/// \param name: ID of the function to convert
142+
/// \param function_symbol_table: mutable symbol table reference to be used
143+
/// when converting the function (e.g. to add new local variables).
144+
/// Note we should not use a global pre-cached symbol table reference for
145+
/// this so that our callers can insert a journalling table here if needed.
146+
/// \return reference to the new or existing goto_functions map entry.
147+
reference ensure_entry_converted(
148+
const key_type &name,
149+
symbol_table_baset &function_symbol_table) const
139150
{
140151
typename underlying_mapt::iterator it=goto_functions.find(name);
141152
if(it!=goto_functions.end())
142153
return *it;
143154
// Fill in symbol table entry body if not already done
144155
// If this returns false then it's a stub
145-
language_files.convert_lazy_method(name, symbol_table);
156+
language_files.convert_lazy_method(name, function_symbol_table);
146157
// Create goto_functiont
147158
goto_functionst::goto_functiont function;
159+
goto_convert_functionst convert_functions(
160+
function_symbol_table, message_handler);
148161
convert_functions.convert_function(name, function);
149162
// Add to map
150163
return *goto_functions.emplace(name, std::move(function)).first;

src/goto-programs/lazy_goto_model.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ lazy_goto_modelt::lazy_goto_modelt(
2828
goto_model->goto_functions.function_map,
2929
language_files,
3030
symbol_table,
31-
[this] (goto_functionst::goto_functiont &function) -> void
31+
[this] (
32+
goto_functionst::goto_functiont &function,
33+
journalling_symbol_tablet &journalling_symbol_table) -> void
3234
{
33-
goto_model_functiont model_function(*goto_model, function);
35+
goto_model_functiont model_function(
36+
journalling_symbol_table,
37+
goto_model->goto_functions,
38+
function);
3439
this->post_process_function(model_function, *this);
3540
},
3641
message_handler),
@@ -48,9 +53,14 @@ lazy_goto_modelt::lazy_goto_modelt(lazy_goto_modelt &&other)
4853
goto_model->goto_functions.function_map,
4954
language_files,
5055
symbol_table,
51-
[this] (goto_functionst::goto_functiont &function) -> void
56+
[this] (
57+
goto_functionst::goto_functiont &function,
58+
journalling_symbol_tablet &journalling_symbol_table) -> void
5259
{
53-
goto_model_functiont model_function(*goto_model, function);
60+
goto_model_functiont model_function(
61+
journalling_symbol_table,
62+
goto_model->goto_functions,
63+
function);
5464
this->post_process_function(model_function, *this);
5565
},
5666
other.message_handler),

src/goto-programs/remove_instanceof.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Author: Chris Smowton, [email protected]
2222
class remove_instanceoft
2323
{
2424
public:
25-
explicit remove_instanceoft(symbol_tablet &symbol_table)
25+
explicit remove_instanceoft(symbol_table_baset &symbol_table)
2626
: symbol_table(symbol_table), ns(symbol_table)
2727
{
2828
class_hierarchy(symbol_table);
@@ -35,7 +35,7 @@ class remove_instanceoft
3535
bool lower_instanceof(goto_programt &, goto_programt::targett);
3636

3737
protected:
38-
symbol_tablet &symbol_table;
38+
symbol_table_baset &symbol_table;
3939
namespacet ns;
4040
class_hierarchyt class_hierarchy;
4141

@@ -183,7 +183,7 @@ bool remove_instanceoft::lower_instanceof(goto_programt &goto_program)
183183
void remove_instanceof(
184184
goto_programt::targett target,
185185
goto_programt &goto_program,
186-
symbol_tablet &symbol_table)
186+
symbol_table_baset &symbol_table)
187187
{
188188
remove_instanceoft rem(symbol_table);
189189
rem.lower_instanceof(goto_program, target);
@@ -196,7 +196,7 @@ void remove_instanceof(
196196
/// \param symbol_table: The symbol table to add symbols to.
197197
void remove_instanceof(
198198
goto_functionst::goto_functiont &function,
199-
symbol_tablet &symbol_table)
199+
symbol_table_baset &symbol_table)
200200
{
201201
remove_instanceoft rem(symbol_table);
202202
rem.lower_instanceof(function.body);
@@ -209,7 +209,7 @@ void remove_instanceof(
209209
/// \param symbol_table: The symbol table to add symbols to.
210210
void remove_instanceof(
211211
goto_functionst &goto_functions,
212-
symbol_tablet &symbol_table)
212+
symbol_table_baset &symbol_table)
213213
{
214214
remove_instanceoft rem(symbol_table);
215215
bool changed=false;

0 commit comments

Comments
 (0)