Skip to content

Commit f3f4da1

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 d71ebe4 commit f3f4da1

17 files changed

+17
-168
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 & 1 deletion
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(

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: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,23 @@ Date: May 2018
1616

1717
#include <iosfwd>
1818

19-
#include <util/deprecate.h>
2019
#include <util/find_symbols.h>
2120
#include <util/std_types.h>
2221

2322
#include "goto_program.h"
2423

25-
/// A goto function, consisting of function type (see #type), function body (see
26-
/// #body), and parameter identifiers (see #parameter_identifiers).
24+
/// A goto function, consisting of function body (see #body) and parameter
25+
/// identifiers (see #parameter_identifiers).
2726
class goto_functiont
2827
{
2928
public:
3029
goto_programt body;
3130

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-
3631
typedef std::vector<irep_idt> parameter_identifierst;
37-
3832
/// The identifiers of the parameters of this function
3933
///
4034
/// Note: This is now the preferred way of getting the identifiers of the
41-
/// parameters. The identifiers in the type will go away.
35+
/// parameters. The identifiers in the type are now gone.
4236
parameter_identifierst parameter_identifiers;
4337

4438
bool body_available() const
@@ -54,12 +48,6 @@ class goto_functiont
5448
parameter_identifiers.push_back(parameter.get_identifier());
5549
}
5650

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-
6351
bool is_hidden() const
6452
{
6553
return function_is_hidden;
@@ -70,30 +58,27 @@ class goto_functiont
7058
function_is_hidden = true;
7159
}
7260

73-
goto_functiont() : body(), type({}, empty_typet()), function_is_hidden(false)
61+
goto_functiont() : body(), function_is_hidden(false)
7462
{
7563
}
7664

7765
void clear()
7866
{
7967
body.clear();
80-
type.clear();
8168
parameter_identifiers.clear();
8269
function_is_hidden = false;
8370
}
8471

8572
void swap(goto_functiont &other)
8673
{
8774
body.swap(other.body);
88-
type.swap(other.type);
8975
parameter_identifiers.swap(other.parameter_identifiers);
9076
std::swap(function_is_hidden, other.function_is_hidden);
9177
}
9278

9379
void copy_from(const goto_functiont &other)
9480
{
9581
body.copy_from(other.body);
96-
type = other.type;
9782
parameter_identifiers = other.parameter_identifiers;
9883
function_is_hidden = other.function_is_hidden;
9984
}
@@ -103,7 +88,6 @@ class goto_functiont
10388

10489
goto_functiont(goto_functiont &&other)
10590
: body(std::move(other.body)),
106-
type(std::move(other.type)),
10791
parameter_identifiers(std::move(other.parameter_identifiers)),
10892
function_is_hidden(other.function_is_hidden)
10993
{
@@ -112,7 +96,6 @@ class goto_functiont
11296
goto_functiont &operator=(goto_functiont &&other)
11397
{
11498
body = std::move(other.body);
115-
type = std::move(other.type);
11699
parameter_identifiers = std::move(other.parameter_identifiers);
117100
function_is_hidden = other.function_is_hidden;
118101
return *this;

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 & 4 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);

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
@@ -33,7 +33,6 @@ SRC += analyses/ai/ai.cpp \
3333
goto-checker/report_util/is_property_less_than.cpp \
3434
goto-instrument/cover_instrument.cpp \
3535
goto-instrument/cover/cover_only.cpp \
36-
goto-programs/goto_model_function_type_consistency.cpp \
3736
goto-programs/goto_program_assume.cpp \
3837
goto-programs/goto_program_dead.cpp \
3938
goto-programs/goto_program_declaration.cpp \

unit/goto-programs/goto_model_function_type_consistency.cpp

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)