Skip to content

Commit 4d935bf

Browse files
committed
Remove support for irep_idt-as-std::string
While #8040 ensured we were still able to compile the code base with `irep_idt` typedef'd to `std::string` (via `USE_STD_STRING`), experiments at that time also demonstrated that performance is substantially worse, and not all tests would pass. This commit now removes this untested feature to pave the way for changes that may break `dstringt` to `std::string` compatibility.
1 parent 69bb2b6 commit 4d935bf

File tree

14 files changed

+6
-106
lines changed

14 files changed

+6
-106
lines changed

Diff for: src/analyses/goto_rw.h

-5
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,7 @@ class shift_exprt;
203203
class rw_range_sett
204204
{
205205
public:
206-
#ifdef USE_DSTRING
207206
typedef std::map<irep_idt, std::unique_ptr<range_domain_baset>> objectst;
208-
#else
209-
typedef std::unordered_map<
210-
irep_idt, std::unique_ptr<range_domain_baset>, string_hash> objectst;
211-
#endif
212207

213208
virtual ~rw_range_sett();
214209

Diff for: src/analyses/reaching_definitions.h

-8
Original file line numberDiff line numberDiff line change
@@ -274,23 +274,15 @@ class rd_range_domaint:public ai_domain_baset
274274
sparse_bitvector_analysist<reaching_definitiont> *const bv_container;
275275

276276
typedef std::set<std::size_t> values_innert;
277-
#ifdef USE_DSTRING
278277
typedef std::map<irep_idt, values_innert> valuest;
279-
#else
280-
typedef std::unordered_map<irep_idt, values_innert> valuest;
281-
#endif
282278
/// It is an ordered map from program variable names to `ID`s of
283279
/// `reaching_definitiont` instances stored in map pointed to by
284280
/// `bv_container`. The map is not empty only if `has_value` is `UNKNOWN`.
285281
/// Variables in the map are all those which are live at the associated
286282
/// instruction.
287283
valuest values;
288284

289-
#ifdef USE_DSTRING
290285
typedef std::map<irep_idt, ranges_at_loct> export_cachet;
291-
#else
292-
typedef std::unordered_map<irep_idt, ranges_at_loct> export_cachet;
293-
#endif
294286
/// It is a helper data structure. It consists of data already stored in
295287
/// `values` and `bv_container`. It is basically (an ordered) map from (a
296288
/// subset of) variables in `values` to iterators to GOTO instructions where

Diff for: src/goto-programs/graphml_witness.cpp

-13
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ Author: Daniel Kroening
2020
#include <util/prefix.h>
2121
#include <util/ssa_expr.h>
2222
#include <util/string_constant.h>
23-
#ifndef USE_DSTRING
24-
# include <util/string_container.h>
25-
#endif
2623
#include <util/symbol.h>
2724

2825
#include <ansi-c/expr2c.h>
@@ -78,12 +75,7 @@ std::string graphml_witnesst::convert_assign_rec(
7875
const irep_idt &identifier,
7976
const code_assignt &assign)
8077
{
81-
#ifdef USE_DSTRING
8278
const auto cit = cache.find({identifier.get_no(), &assign.read()});
83-
#else
84-
const auto cit =
85-
cache.find({get_string_container()[id2string(identifier)], &assign.read()});
86-
#endif
8779
if(cit != cache.end())
8880
return cit->second;
8981

@@ -219,12 +211,7 @@ std::string graphml_witnesst::convert_assign_rec(
219211
result = lhs + " = " + expr_to_string(ns, identifier, clean_rhs) + ";";
220212
}
221213

222-
#ifdef USE_DSTRING
223214
cache.insert({{identifier.get_no(), &assign.read()}, result});
224-
#else
225-
cache.insert(
226-
{{get_string_container()[id2string(identifier)], &assign.read()}, result});
227-
#endif
228215
return result;
229216
}
230217

Diff for: src/libcprover-cpp/verification_result.h

-8
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,8 @@
1212
#include <string>
1313
#include <vector>
1414

15-
#ifndef USE_STD_STRING
16-
# define USE_DSTRING
17-
#endif
18-
19-
#ifdef USE_DSTRING
2015
class dstringt;
2116
typedef dstringt irep_idt;
22-
#else
23-
typedef std::string irep_idt;
24-
#endif
2517

2618
struct property_infot;
2719
using propertiest = std::map<irep_idt, property_infot>;

Diff for: src/pointer-analysis/value_set_fi.h

-8
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,11 @@ class value_set_fit
191191

192192
typedef std::unordered_set<unsigned int> dynamic_object_id_sett;
193193

194-
#ifdef USE_DSTRING
195194
typedef std::map<idt, entryt> valuest;
196195
typedef std::set<idt> flatten_seent;
197196
typedef std::unordered_set<idt> gvs_recursion_sett;
198197
typedef std::unordered_set<idt> recfind_recursion_sett;
199198
typedef std::unordered_set<idt> assign_recursion_sett;
200-
#else
201-
typedef std::unordered_map<idt, entryt, string_hash> valuest;
202-
typedef std::unordered_set<idt, string_hash> flatten_seent;
203-
typedef std::unordered_set<idt, string_hash> gvs_recursion_sett;
204-
typedef std::unordered_set<idt, string_hash> recfind_recursion_sett;
205-
typedef std::unordered_set<idt, string_hash> assign_recursion_sett;
206-
#endif
207199

208200
std::vector<exprt>
209201
get_value_set(const exprt &expr, const namespacet &ns) const;

Diff for: src/util/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ standard data structures as in irept.
7272

7373
\subsection irep_idt_section Strings: dstringt, the string_container and the ID_*
7474

75-
Within cbmc, strings are represented using \ref irep_idt. By default this is
76-
typedefed to \ref dstringt. For debugging purposes you can set `USE_STD_STRING`
77-
to change this typedef to `std::string`. You can also easily convert an
75+
Within cbmc, strings are represented using \ref irep_idt, which is
76+
typedefed to \ref dstringt.
77+
You can also easily convert an
7878
[irep_idt](\ref irep_idt) to a `std::string` using the
7979
[id2string](\ref id2string) function, or to a `char*` using the
8080
[c_str()](\ref dstringt::c_str) member function.

Diff for: src/util/dstring.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ struct diagnostics_helpert;
2929
/// copies of the same string you only have to store the whole string once,
3030
/// which saves space.
3131
///
32-
/// `irep_idt` is typedef-ed to \ref dstringt in irep.h unless `USE_STD_STRING`
33-
/// is set.
32+
/// `irep_idt` is typedef-ed to \ref dstringt in irep.h.
3433
///
3534
///
3635
/// Note: Marked final to disable inheritance. No virtual destructor, so

Diff for: src/util/irep.cpp

-8
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,12 @@ long long irept::get_long_long(const irep_idt &name) const
7676

7777
void irept::set(const irep_idt &name, const long long value)
7878
{
79-
#ifdef USE_DSTRING
8079
add(name).id(to_dstring(value));
81-
#else
82-
add(name).id(std::to_string(value));
83-
#endif
8480
}
8581

8682
void irept::set_size_t(const irep_idt &name, const std::size_t value)
8783
{
88-
#ifdef USE_DSTRING
8984
add(name).id(to_dstring(value));
90-
#else
91-
add(name).id(std::to_string(value));
92-
#endif
9385
}
9486

9587
void irept::remove(const irep_idt &name)

Diff for: src/util/irep.h

+2-14
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,13 @@ Author: Daniel Kroening, [email protected]
3333
#include <map>
3434
#endif
3535

36-
#ifdef USE_DSTRING
3736
typedef dstringt irep_idt;
3837
// NOLINTNEXTLINE(readability/identifiers)
3938
typedef dstring_hash irep_id_hash;
40-
#else
41-
#include "string_hash.h"
42-
typedef std::string irep_idt;
43-
// NOLINTNEXTLINE(readability/identifiers)
44-
typedef string_hash irep_id_hash;
45-
#endif
4639

4740
inline const std::string &id2string(const irep_idt &d)
4841
{
49-
#ifdef USE_DSTRING
5042
return as_string(d);
51-
#else
52-
return d;
53-
#endif
5443
}
5544

5645
#ifdef IREP_DEBUG
@@ -76,9 +65,8 @@ struct ref_count_ift<true>
7665

7766
/// A node with data in a tree, it contains:
7867
///
79-
/// * \ref irept::dt::data : A string (Unless `USE_STD_STRING` is set, this is
80-
/// actually a \ref dstringt and thus an integer which is a reference into a
81-
/// string table.)
68+
/// * \ref irept::dt::data : A \ref dstringt and thus an integer which is a
69+
/// reference into a string table.)
8270
///
8371
/// * \ref irept::dt::named_sub : A map from `irep_idt` (a string) to \ref
8472
/// irept. This is used for named children, i.e. subexpressions, parameters,

Diff for: src/util/irep_ids.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ const char *irep_ids_table[]=
2525
nullptr,
2626
};
2727

28-
#ifdef USE_DSTRING
29-
3028
enum class idt:unsigned
3129
{
3230
#define IREP_ID_ONE(the_id) id_##the_id,
@@ -42,13 +40,6 @@ enum class idt:unsigned
4240
const dstringt ID_##the_id=dstringt::make_from_table_index( \
4341
static_cast<unsigned>(idt::id_##the_id));
4442

45-
#else
46-
47-
#define IREP_ID_ONE(the_id) const std::string ID_##the_id(#the_id);
48-
# define IREP_ID_TWO(the_id, str) const std::string ID_##the_id(# str);
49-
50-
#endif
51-
5243
#include "irep_ids.def" // NOLINT(build/include)
5344

5445
string_containert::string_containert()

Diff for: src/util/irep_ids.h

-17
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,7 @@ Author: Reuben Thomas, [email protected]
1212
#ifndef CPROVER_UTIL_IREP_IDS_H
1313
#define CPROVER_UTIL_IREP_IDS_H
1414

15-
#ifndef USE_STD_STRING
16-
#define USE_DSTRING
17-
#endif
18-
19-
#ifdef USE_DSTRING
2015
#include "dstring.h"
21-
#else
22-
#include <string>
23-
#endif
2416

2517
/// \file
2618
/// The irep_ids are generated using a technique called
@@ -34,18 +26,9 @@ Author: Reuben Thomas, [email protected]
3426
/// into a const extern irep_idt with the variable name `ID_param` and the
3527
/// string value `"contents"`.
3628

37-
#ifdef USE_DSTRING
38-
3929
#define IREP_ID_ONE(the_id) extern const dstringt ID_##the_id;
4030
#define IREP_ID_TWO(the_id, str) extern const dstringt ID_##the_id;
4131

42-
#else
43-
44-
#define IREP_ID_ONE(the_id) extern const std::string ID_##the_id;
45-
#define IREP_ID_TWO(the_id, str) extern const std::string ID_##the_id;
46-
47-
#endif
48-
4932
#include "irep_ids.def"
5033

5134
#endif

Diff for: src/util/irep_serialization.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,7 @@ void irep_serializationt::write_string_ref(
212212
std::ostream &out,
213213
const irep_idt &s)
214214
{
215-
#ifdef USE_DSTRING
216215
size_t id = s.get_no();
217-
#else
218-
size_t id = get_string_container()[s];
219-
#endif
220216
if(id>=ireps_container.string_map.size())
221217
ireps_container.string_map.resize(id+1, false);
222218

Diff for: src/util/json.h

-2
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,10 @@ class json_stringt:public jsont
274274
{
275275
}
276276

277-
#ifdef USE_DSTRING
278277
explicit json_stringt(const irep_idt &_value)
279278
: jsont(kindt::J_STRING, id2string(_value))
280279
{
281280
}
282-
#endif
283281

284282
/// Constructon from string literal.
285283
explicit json_stringt(const char *_value) : jsont(kindt::J_STRING, _value)

Diff for: unit/util/irep.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@ SCENARIO("irept_memory", "[core][utils][irept]")
2222
const std::size_t ref_count_size = 0;
2323
#endif
2424

25-
#ifdef USE_DSTRING
2625
const std::size_t data_size = sizeof(dstringt);
2726
REQUIRE(sizeof(dstringt) == sizeof(unsigned));
28-
#else
29-
const std::size_t data_size = sizeof(std::string);
30-
REQUIRE(sizeof(std::string) == sizeof(void *));
31-
#endif
3227

3328
const std::size_t sub_size = sizeof(std::vector<int>);
3429
#ifndef _GLIBCXX_DEBUG

0 commit comments

Comments
 (0)