Skip to content

Commit d69301e

Browse files
committed
Remove goto_functiont::type
Having two function type definitions (one in the symbol table and one in goto_functiont) is just prone to become inconsistent. Instead, always look at the symbol table when we do need type information. If all we care about are the identifiers we can still use goto_functiont::parameter_identifiers.
1 parent d0eba43 commit d69301e

17 files changed

+16
-187
lines changed

src/assembler/remove_asm.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,14 @@ void remove_asmt::gcc_asm_function_call(
122122
symbol.mode = ID_C;
123123

124124
symbol_table.add(symbol);
125-
}
126125

127-
if(
128-
goto_functions.function_map.find(function_identifier) ==
129-
goto_functions.function_map.end())
126+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
127+
}
128+
else
130129
{
131-
auto &f = goto_functions.function_map[function_identifier];
132-
f.type = fkt_type;
130+
DATA_INVARIANT(
131+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
132+
"function types should match");
133133
}
134134
}
135135

@@ -171,14 +171,14 @@ void remove_asmt::msc_asm_function_call(
171171
symbol.mode = ID_C;
172172

173173
symbol_table.add(symbol);
174-
}
175174

176-
if(
177-
goto_functions.function_map.find(function_identifier) ==
178-
goto_functions.function_map.end())
175+
goto_functions.function_map.emplace(function_identifier, goto_functiont());
176+
}
177+
else
179178
{
180-
auto &f = goto_functions.function_map[function_identifier];
181-
f.type = fkt_type;
179+
DATA_INVARIANT(
180+
symbol_table.lookup_ref(function_identifier).type == fkt_type,
181+
"function types should match");
182182
}
183183
}
184184

src/goto-harness/function_call_harness_generator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -453,10 +453,6 @@ void function_call_harness_generatort::implt::
453453

454454
symbol_table->insert(harness_function_symbol);
455455

456-
auto const &generated_harness =
457-
symbol_table->lookup_ref(harness_function_name);
458-
goto_functions->function_map[harness_function_name].type =
459-
to_code_type(generated_harness.type);
460456
goto_convert(*symbol_table, *goto_functions, *message_handler);
461457
}
462458

src/goto-harness/memory_snapshot_harness_generator.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,6 @@ void memory_snapshot_harness_generatort::
322322
CHECK_RETURN(function_iterator_pair.second);
323323

324324
goto_functiont &harness_function = function_iterator_pair.first->second;
325-
harness_function.type = to_code_type(function.type);
326325

327326
goto_convert(
328327
goto_model.symbol_table, goto_model.goto_functions, message_handler);

src/goto-harness/recursive_initialization.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,8 +366,6 @@ irep_idt recursive_initializationt::build_constructor(const exprt &expr)
366366
expr_name,
367367
is_nullable);
368368

369-
goto_model.goto_functions.function_map[function_symbol.name].type =
370-
to_code_type(function_symbol.type);
371369
return type_constructor_names.at(key);
372370
}
373371

src/goto-instrument/code_contracts.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,8 +749,6 @@ bool code_contractst::enforce_contract(const std::string &fun_to_enforce)
749749

750750
goto_functiont &wrapper = goto_functions.function_map[original];
751751
wrapper.parameter_identifiers = mangled_fun->second.parameter_identifiers;
752-
if(mangled_fun->second.type.is_not_nil())
753-
wrapper.type = mangled_fun->second.type;
754752
wrapper.body.add(goto_programt::make_end_function(sl));
755753
add_contract_check(original, mangled, wrapper.body);
756754
return false;

src/goto-instrument/generate_function_bodies.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ void generate_function_bodiest::generate_parameter_names(
6464
symbol_table.add(new_param_sym);
6565
}
6666
}
67-
function.type = to_code_type(function_symbol.type);
6867
function.set_parameter_identifiers(to_code_type(function_symbol.type));
6968
}
7069

@@ -591,8 +590,6 @@ void generate_function_bodies(
591590
model.symbol_table.lookup_ref(havoc_function_symbol.name);
592591

593592
// convert to get the function stub to goto-model
594-
model.goto_functions.function_map[havoc_function_symbol.name].type =
595-
to_code_type(generated_havoc.type);
596593
goto_convert(model.symbol_table, model.goto_functions, message_handler);
597594

598595
// now generate body as above

src/goto-instrument/replace_calls.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ void replace_callst::operator()(
9494
auto f_it2 = goto_functions.function_map.find(new_id);
9595
PRECONDITION(f_it2 != goto_functions.function_map.end());
9696

97-
PRECONDITION(base_type_eq(f_it1->second.type, f_it2->second.type, ns));
98-
9997
// check that returns have not been removed
10098
if(to_code_type(function.type()).return_type().id() != ID_empty)
10199
{

src/goto-programs/goto_convert_functions.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ void goto_convert_functionst::convert_function(
155155

156156
// store the parameter identifiers in the goto functions
157157
const code_typet &code_type = to_code_type(symbol.type);
158-
f.type = code_type;
159158
f.set_parameter_identifiers(code_type);
160159

161160
if(
@@ -227,10 +226,7 @@ void goto_convert_functionst::convert_function(
227226
f.body.update();
228227

229228
if(hide(f.body))
230-
{
231-
f.make_hidden();
232229
symbol_table.get_writeable_ref(identifier).set_hidden();
233-
}
234230

235231
lifetime = parent_lifetime;
236232
}

src/goto-programs/goto_function.cpp

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,4 @@ void goto_functiont::validate(const namespacet &ns, const validation_modet vm)
4646
}
4747

4848
body.validate(ns, vm);
49-
50-
find_symbols_sett typetags;
51-
find_type_symbols(type, typetags);
52-
const symbolt *symbol;
53-
for(const auto &identifier : typetags)
54-
{
55-
DATA_CHECK(
56-
vm, !ns.lookup(identifier, symbol), id2string(identifier) + " not found");
57-
}
58-
59-
// Check that a void function does not contain any RETURN instructions
60-
if(to_code_type(type).return_type().id() == ID_empty)
61-
{
62-
forall_goto_program_instructions(instruction, body)
63-
{
64-
DATA_CHECK(
65-
vm,
66-
!instruction->is_return(),
67-
"void function should not return a value");
68-
}
69-
}
70-
71-
validate_full_type(type, ns, vm);
7249
}

src/goto-programs/goto_function.h

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,23 +22,15 @@ Date: May 2018
2222

2323
#include "goto_program.h"
2424

25-
/// A goto function, consisting of function type (see #type), function body (see
26-
/// #body), and parameter identifiers (see #parameter_identifiers).
25+
/// A goto function, consisting of function body (see #body) and parameter
26+
/// identifiers (see #parameter_identifiers).
2727
class goto_functiont
2828
{
2929
public:
3030
goto_programt body;
3131

32-
/// The type of the function, indicating the return type and parameter types
33-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
34-
code_typet type;
35-
3632
typedef std::vector<irep_idt> parameter_identifierst;
37-
3833
/// The identifiers of the parameters of this function
39-
///
40-
/// Note: This is now the preferred way of getting the identifiers of the
41-
/// parameters. The identifiers in the type will go away.
4234
parameter_identifierst parameter_identifiers;
4335

4436
bool body_available() const
@@ -54,46 +46,23 @@ class goto_functiont
5446
parameter_identifiers.push_back(parameter.get_identifier());
5547
}
5648

57-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
58-
bool is_inlined() const
59-
{
60-
return type.get_bool(ID_C_inlined);
61-
}
62-
63-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
64-
bool is_hidden() const
65-
{
66-
return type.get_bool(ID_C_hide);
67-
}
68-
69-
DEPRECATED(SINCE(2019, 2, 16, "Get the type from the symbol table instead"))
70-
void make_hidden()
71-
{
72-
type.set(ID_C_hide, true);
73-
}
74-
75-
goto_functiont() : body(), type({}, empty_typet())
76-
{
77-
}
49+
goto_functiont() = default;
7850

7951
void clear()
8052
{
8153
body.clear();
82-
type.clear();
8354
parameter_identifiers.clear();
8455
}
8556

8657
void swap(goto_functiont &other)
8758
{
8859
body.swap(other.body);
89-
type.swap(other.type);
9060
parameter_identifiers.swap(other.parameter_identifiers);
9161
}
9262

9363
void copy_from(const goto_functiont &other)
9464
{
9565
body.copy_from(other.body);
96-
type = other.type;
9766
parameter_identifiers = other.parameter_identifiers;
9867
}
9968

@@ -102,15 +71,13 @@ class goto_functiont
10271

10372
goto_functiont(goto_functiont &&other)
10473
: body(std::move(other.body)),
105-
type(std::move(other.type)),
10674
parameter_identifiers(std::move(other.parameter_identifiers))
10775
{
10876
}
10977

11078
goto_functiont &operator=(goto_functiont &&other)
11179
{
11280
body = std::move(other.body);
113-
type = std::move(other.type);
11481
parameter_identifiers = std::move(other.parameter_identifiers);
11582
return *this;
11683
}

src/goto-programs/goto_functions.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ void goto_functionst::validate(const namespacet &ns, const validation_modet vm)
109109
const code_typet::parameterst &parameters =
110110
to_code_type(function_symbol.type).parameters();
111111

112-
DATA_CHECK(
113-
vm,
114-
goto_function.type == ns.lookup(function_name).type,
115-
id2string(function_name) + " type inconsistency\ngoto program type: " +
116-
goto_function.type.id_string() +
117-
"\nsymbol table type: " + ns.lookup(function_name).type.id_string());
118-
119112
DATA_CHECK(
120113
vm,
121114
goto_function.parameter_identifiers.size() == parameters.size(),

src/goto-programs/link_goto_model.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ static void rename_symbols_in_function(
3535
}
3636

3737
goto_programt &program=function.body;
38-
rename_symbol(function.type);
3938

4039
Forall_goto_program_instructions(iit, program)
4140
{
@@ -99,12 +98,6 @@ static bool link_functions(
9998
in_dest_symbol_table.body.swap(src_func.body);
10099
in_dest_symbol_table.parameter_identifiers.swap(
101100
src_func.parameter_identifiers);
102-
in_dest_symbol_table.type=src_func.type;
103-
// the linking code will have ensured that types match
104-
INVARIANT(
105-
base_type_eq(
106-
dest_symbol_table.lookup_ref(final_id).type, src_func.type, ns),
107-
"linking ensures that types match");
108101
}
109102
else if(src_func.body.instructions.empty() ||
110103
src_ns.lookup(src_it->first).is_weak)
@@ -115,13 +108,6 @@ static bool link_functions(
115108
{
116109
// ok, we silently ignore
117110
}
118-
else
119-
{
120-
// the linking code will have ensured that types match
121-
rename_symbol(src_func.type);
122-
INVARIANT(base_type_eq(in_dest_symbol_table.type, src_func.type, ns),
123-
"linking ensures that types match");
124-
}
125111
}
126112
}
127113

src/goto-programs/read_bin_goto_object.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,7 @@ static bool read_bin_goto_object(
7474
{
7575
// makes sure there is an empty function for every function symbol
7676
auto entry = functions.function_map.emplace(sym.name, goto_functiont());
77-
78-
const code_typet &code_type = to_code_type(sym.type);
79-
entry.first->second.type = code_type;
80-
entry.first->second.set_parameter_identifiers(code_type);
77+
entry.first->second.set_parameter_identifiers(to_code_type(sym.type));
8178
}
8279

8380
symbol_table.add(sym);
@@ -161,7 +158,6 @@ static bool read_bin_goto_object(
161158

162159
if(hidden)
163160
{
164-
f.make_hidden();
165161
// can be removed with the next goto-binary version update as the
166162
// information is guaranteed to be stored in the symbol table
167163
#if GOTO_BINARY_VERSION > 5

src/goto-programs/remove_complex.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,6 @@ void remove_complex(symbol_tablet &symbol_table)
283283
static void remove_complex(
284284
goto_functionst::goto_functiont &goto_function)
285285
{
286-
remove_complex(goto_function.type);
287-
288286
for(auto &i : goto_function.body.instructions)
289287
i.transform([](exprt e) -> optionalt<exprt> {
290288
if(have_to_remove_complex(e))

src/goto-programs/remove_vector.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,6 @@ static void remove_vector(symbol_tablet &symbol_table)
217217
/// removes vector data type
218218
void remove_vector(goto_functionst::goto_functiont &goto_function)
219219
{
220-
remove_vector(goto_function.type);
221-
222220
for(auto &i : goto_function.body.instructions)
223221
i.transform([](exprt e) -> optionalt<exprt> {
224222
if(have_to_remove_vector(e))

unit/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ SRC += analyses/ai/ai.cpp \
2323
goto-checker/report_util/is_property_less_than.cpp \
2424
goto-instrument/cover_instrument.cpp \
2525
goto-instrument/cover/cover_only.cpp \
26-
goto-programs/goto_model_function_type_consistency.cpp \
2726
goto-programs/goto_program_assume.cpp \
2827
goto-programs/goto_program_dead.cpp \
2928
goto-programs/goto_program_declaration.cpp \

0 commit comments

Comments
 (0)