Skip to content

Use std::forward_list instead of std::map in irept by default [blocks: #3486] #4458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ jobs:
- WITH_MEMORY_ANALYZER=1
script: echo "Not running any tests for a debug build."

# cmake build using g++-7, enable NAMED_SUB_IS_FORWARD_LIST
# cmake build using g++-7, disable NAMED_SUB_IS_FORWARD_LIST
- stage: Test different OS/CXX/Flags
os: linux
sudo: false
Expand All @@ -205,7 +205,7 @@ jobs:
install:
- ccache -z
- ccache --max-size=1G
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST' '-DWITH_MEMORY_ANALYZER=On'
- cmake -H. -Bbuild '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_CXX_COMPILER=/usr/bin/g++-7' '-DCMAKE_CXX_FLAGS=-DNAMED_SUB_IS_FORWARD_LIST=0' '-DWITH_MEMORY_ANALYZER=On'
- git submodule update --init --recursive
- cmake --build build -- -j4
script: (cd build; bin/unit "[core][irept]")
Expand Down
1 change: 1 addition & 0 deletions src/memory-analyzer/gdb_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Author: Malte Mues <[email protected]>
#include <algorithm>
#include <exception>
#include <forward_list>
#include <map>

#include <util/exception_utils.h>

Expand Down
4 changes: 2 additions & 2 deletions src/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void irept::set(const irep_namet &name, const long long value)

void irept::remove(const irep_namet &name)
{
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
return get_named_sub().remove(name);
#else
named_subt &s = get_named_sub();
Expand Down Expand Up @@ -120,7 +120,7 @@ irept &irept::add(const irep_namet &name, irept irep)
{
named_subt &s = get_named_sub();

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
return s.add(name, std::move(irep));
#else
std::pair<named_subt::iterator, bool> entry = s.emplace(
Expand Down
8 changes: 5 additions & 3 deletions src/util/irep.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ Author: Daniel Kroening, [email protected]
#ifndef HASH_CODE
# define HASH_CODE 1
#endif
// #define NAMED_SUB_IS_FORWARD_LIST
#ifndef NAMED_SUB_IS_FORWARD_LIST
# define NAMED_SUB_IS_FORWARD_LIST 1
#endif

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
# include "forward_list_as_map.h"
#else
#include <map>
Expand Down Expand Up @@ -386,7 +388,7 @@ class irept
: public non_sharing_treet<
irept,
#endif
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
forward_list_as_mapt<irep_namet, irept>>
#else
std::map<irep_namet, irept>>
Expand Down
2 changes: 1 addition & 1 deletion src/util/irep_hash_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void irep_hash_container_baset::pack(
{
// we pack: the irep id, the sub size, the subs, the named-sub size, and
// each of the named subs with their ids
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
const std::size_t named_sub_size =
std::distance(named_sub.begin(), named_sub.end());
#else
Expand Down
6 changes: 3 additions & 3 deletions src/util/irep_serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ irept irep_serializationt::read_irep(std::istream &in)
sub.push_back(reference_convert(in));
}

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
irept::named_subt::iterator before = named_sub.before_begin();
#endif
while(in.peek()=='N')
{
in.get();
irep_idt id = read_string_ref(in);
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
named_sub.emplace_after(before, id, reference_convert(in));
++before;
#else
Expand All @@ -95,7 +95,7 @@ irept irep_serializationt::read_irep(std::istream &in)
{
in.get();
irep_idt id = read_string_ref(in);
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
named_sub.emplace_after(before, id, reference_convert(in));
++before;
#else
Expand Down
2 changes: 1 addition & 1 deletion src/util/lispirep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ void irep2lisp(const irept &src, lispexprt &dest)
dest.value.clear();
dest.type=lispexprt::List;

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
const std::size_t named_sub_size =
std::distance(src.get_named_sub().begin(), src.get_named_sub().end());
#else
Expand Down
10 changes: 5 additions & 5 deletions src/util/merge_irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ bool to_be_merged_irept::operator == (const to_be_merged_irept &other) const

if(sub.size()!=o_sub.size())
return false;
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
if(
std::distance(named_sub.begin(), named_sub.end()) !=
std::distance(o_named_sub.begin(), o_named_sub.end()))
Expand Down Expand Up @@ -105,12 +105,12 @@ const merged_irept &merged_irepst::merged(const irept &irep)
const irept::named_subt &src_named_sub=irep.get_named_sub();
irept::named_subt &dest_named_sub=new_irep.get_named_sub();

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
irept::named_subt::iterator before = dest_named_sub.before_begin();
#endif
forall_named_irep(it, src_named_sub)
{
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
dest_named_sub.emplace_after(
before, it->first, merged(it->second)); // recursive call
++before;
Expand Down Expand Up @@ -209,12 +209,12 @@ const irept &merge_full_irept::merged(const irept &irep)
const irept::named_subt &src_named_sub=irep.get_named_sub();
irept::named_subt &dest_named_sub=new_irep.get_named_sub();

#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
irept::named_subt::iterator before = dest_named_sub.before_begin();
#endif
forall_named_irep(it, src_named_sub)
{
#ifdef NAMED_SUB_IS_FORWARD_LIST
#if NAMED_SUB_IS_FORWARD_LIST
dest_named_sub.emplace_after(
before, it->first, merged(it->second)); // recursive call
++before;
Expand Down
3 changes: 2 additions & 1 deletion src/util/type.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ class typet:public irept

explicit typet(const irep_idt &_id):irept(_id) { }

#if defined(__clang__) || !defined(__GNUC__) || __GNUC__ >= 6
// the STL implementation shipped with GCC 5 is broken
#if !defined(__GLIBCXX__) || __GLIBCXX__ >= 20181026
typet(irep_idt _id, typet _subtype)
: irept(std::move(_id), {}, {std::move(_subtype)})
{
Expand Down
2 changes: 1 addition & 1 deletion unit/util/irep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ SCENARIO("irept_memory", "[core][utils][irept]")
REQUIRE(sizeof(std::vector<int>) == 3 * sizeof(void *));
#endif

#ifndef NAMED_SUB_IS_FORWARD_LIST
#if !NAMED_SUB_IS_FORWARD_LIST
const std::size_t named_size = sizeof(std::map<int, int>);
# ifndef _GLIBCXX_DEBUG
# ifdef __APPLE__
Expand Down