Skip to content

Commit

Permalink
Rename map into transform
Browse files Browse the repository at this point in the history
Summary:
Our data structures have `map` methods that mutate the current container.
In functional programming languages, `map` usually returns a new value.
It makes more sense to name that method `transform`.

Reviewed By: arnaudvenet

Differential Revision: D50009431

fbshipit-source-id: 8b3a4c8cee25cf8255fcec181235c8bac8b5c389
  • Loading branch information
arthaud authored and facebook-github-bot committed Oct 6, 2023
1 parent 9833240 commit a1b1513
Show file tree
Hide file tree
Showing 17 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion service/cse/CommonSubexpressionElimination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class Analyzer final : public BaseEdgeAwareIRAnalyzer<CseEnvironment> {
}
});
current_state->mutate_ref_env([mask, &any_changes](RefEnvironment* env) {
bool any_map_changes = env->map([mask](ValueIdDomain domain) {
bool any_map_changes = env->transform([mask](ValueIdDomain domain) {
auto c = domain.get_constant();
always_assert(c);
auto value_id = *c;
Expand Down
2 changes: 1 addition & 1 deletion service/type-analysis/LocalTypeAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ bool RegisterTypeAnalyzer::analyze_invoke(const IRInstruction* insn,
if (!array_nullness.is_top() && array_nullness.get_length() &&
*array_nullness.get_length() > 0 && dex_type) {
env->mutate_reg_environment([&](RegTypeEnvironment* env) {
env->map([&](const DexTypeDomain& domain) {
env->transform([&](const DexTypeDomain& domain) {
auto dex_type_local = domain.get_dex_type();
if (dex_type_local && *dex_type == *dex_type_local) {
return DexTypeDomain(*dex_type_local,
Expand Down
2 changes: 1 addition & 1 deletion sparta/include/sparta/FlatMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ class FlatMap final {
}

template <typename MappingFunction> // void(mapped_type*)
void map(MappingFunction&& f) {
void transform(MappingFunction&& f) {
bool has_default_value = false;
for (auto& p : m_map) {
f(&p.second);
Expand Down
2 changes: 1 addition & 1 deletion sparta/include/sparta/HashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class HashMap final {
}

template <typename MappingFunction> // void(mapped_type*)
HashMap& map(MappingFunction&& f) {
HashMap& transform(MappingFunction&& f) {
auto it = m_map.begin(), end = m_map.end();
while (it != end) {
f(&it->second);
Expand Down
4 changes: 2 additions & 2 deletions sparta/include/sparta/HashedAbstractPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@ class HashedAbstractPartition final
}

template <typename Operation> // void(Domain*)
void map(Operation&& f) {
void transform(Operation&& f) {
if (is_top()) {
return;
}
m_map.map(std::forward<Operation>(f));
m_map.transform(std::forward<Operation>(f));
}

bool is_top() const { return m_is_top; }
Expand Down
8 changes: 4 additions & 4 deletions sparta/include/sparta/PatriciaTreeHashMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ class PatriciaTreeHashMap final {
}

template <typename MappingFunction> // void(mapped_type*)
bool map(MappingFunction&& f) {
return m_tree.map(
bool transform(MappingFunction&& f) {
return m_tree.transform(
[f = std::forward<MappingFunction>(f)](FlatMapT flat_map) -> FlatMapT {
flat_map.map(f);
flat_map.transform(f);
return flat_map;
});
}
Expand All @@ -183,7 +183,7 @@ class PatriciaTreeHashMap final {

template <typename Predicate> // bool(const Key&, const ValueType&)
PatriciaTreeHashMap& filter(const Predicate& predicate) {
m_tree.map([&predicate](FlatMapT flat_map) -> FlatMapT {
m_tree.transform([&predicate](FlatMapT flat_map) -> FlatMapT {
flat_map.filter(predicate);
return flat_map;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ class PatriciaTreeHashMapAbstractEnvironment final
}

template <typename Operation> // void(Domain*)
bool map(Operation&& f) {
bool transform(Operation&& f) {
if (this->is_bottom()) {
return false;
}
bool res = this->get_value()->map(std::forward<Operation>(f));
bool res = this->get_value()->transform(std::forward<Operation>(f));
this->normalize();
return res;
}
Expand Down Expand Up @@ -272,8 +272,8 @@ class MapValue final : public AbstractValue<MapValue<Variable, Domain>> {
}

template <typename Operation> // void(Domain*)
bool map(Operation&& f) {
return m_map.map(std::forward<Operation>(f));
bool transform(Operation&& f) {
return m_map.transform(std::forward<Operation>(f));
}

template <typename Operation> // void(Domain*, const Domain&)
Expand Down
4 changes: 2 additions & 2 deletions sparta/include/sparta/PatriciaTreeHashMapAbstractPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ class PatriciaTreeHashMapAbstractPartition final
}

template <typename Operation> // void(Domain*)
bool map(Operation&& f) {
bool transform(Operation&& f) {
if (is_top()) {
return false;
}
return m_map.map(std::forward<Operation>(f));
return m_map.transform(std::forward<Operation>(f));
}

bool is_top() const { return m_is_top; }
Expand Down
2 changes: 1 addition & 1 deletion sparta/include/sparta/PatriciaTreeMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class PatriciaTreeMap final {
}

template <typename MappingFunction> // mapped_type(const mapped_type&)
bool map(MappingFunction&& f) {
bool transform(MappingFunction&& f) {
return m_core.update_all_leafs(
apply_leafs(std::forward<MappingFunction>(f)));
}
Expand Down
8 changes: 4 additions & 4 deletions sparta/include/sparta/PatriciaTreeMapAbstractEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ class PatriciaTreeMapAbstractEnvironment final
}

template <typename Operation> // Domain(const Domain&)
bool map(Operation&& f) {
bool transform(Operation&& f) {
if (this->is_bottom()) {
return false;
}
bool res = this->get_value()->map(std::forward<Operation>(f));
bool res = this->get_value()->transform(std::forward<Operation>(f));
this->normalize();
return res;
}
Expand Down Expand Up @@ -285,8 +285,8 @@ class MapValue final : public AbstractValue<MapValue<Variable, Domain>> {
}

template <typename Operation> // Domain(const Domain&)
bool map(Operation&& f) {
return m_map.map(std::forward<Operation>(f));
bool transform(Operation&& f) {
return m_map.transform(std::forward<Operation>(f));
}

bool erase_all_matching(const Variable& variable_mask) {
Expand Down
4 changes: 2 additions & 2 deletions sparta/include/sparta/PatriciaTreeMapAbstractPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ class PatriciaTreeMapAbstractPartition final
}

template <typename Operation> // Domain(const Domain&)
bool map(Operation&& f) {
bool transform(Operation&& f) {
if (is_top()) {
return false;
}
return m_map.map(std::forward<Operation>(f));
return m_map.transform(std::forward<Operation>(f));
}

bool is_top() const { return m_is_top; }
Expand Down
6 changes: 3 additions & 3 deletions sparta/test/PatriciaTreeHashMapAbstractEnvironmentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ TEST_F(PatriciaTreeHashMapAbstractEnvironmentTest, whiteBox) {
EXPECT_TRUE(e.bindings().reference_equals(before));
}

TEST_F(PatriciaTreeHashMapAbstractEnvironmentTest, map) {
TEST_F(PatriciaTreeHashMapAbstractEnvironmentTest, transform) {
Environment e1({{1, Domain({"a", "b"})}});
bool any_changes = e1.map([](Domain*) {});
bool any_changes = e1.transform([](Domain*) {});
EXPECT_FALSE(any_changes);

any_changes = e1.map([](Domain* d) { d->set_to_top(); });
any_changes = e1.transform([](Domain* d) { d->set_to_top(); });
EXPECT_TRUE(any_changes);
EXPECT_TRUE(e1.is_top());
}
Expand Down
6 changes: 3 additions & 3 deletions sparta/test/PatriciaTreeHashMapAbstractPartitionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,12 @@ TEST(PatriciaTreeHashMapAbstractPartitionTest, destructiveOperations) {
EXPECT_TRUE(p6.is_top());
}

TEST(PatriciaTreeHashMapAbstractPartitionTest, map) {
TEST(PatriciaTreeHashMapAbstractPartitionTest, transform) {
Partition p1({{1, Domain({"a", "b"})}});
bool any_changes = p1.map([](Domain*) {});
bool any_changes = p1.transform([](Domain*) {});
EXPECT_FALSE(any_changes);

any_changes = p1.map([](Domain* d) { d->set_to_bottom(); });
any_changes = p1.transform([](Domain* d) { d->set_to_bottom(); });
EXPECT_TRUE(any_changes);
EXPECT_TRUE(p1.is_bottom());
}
4 changes: 2 additions & 2 deletions sparta/test/PatriciaTreeHashMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ TEST(PatriciaTreeHashMapTest, map) {
constexpr uint32_t default_value = 0;
pth_map m1 = create_pth_map({{0, 1}, {1, 2}, {2, 4}});

bool any_changes = m1.map([](uint32_t*) {});
bool any_changes = m1.transform([](uint32_t*) {});
EXPECT_FALSE(any_changes);
EXPECT_EQ(3, m1.size());
EXPECT_EQ(m1.at(0), 1);
EXPECT_EQ(m1.at(1), 2);
EXPECT_EQ(m1.at(2), 4);

any_changes = m1.map([](uint32_t* value) { --(*value); });
any_changes = m1.transform([](uint32_t* value) { --(*value); });
EXPECT_TRUE(any_changes);
EXPECT_EQ(2, m1.size());
EXPECT_EQ(m1.at(0), default_value);
Expand Down
6 changes: 3 additions & 3 deletions sparta/test/PatriciaTreeMapAbstractEnvironmentTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ TEST_F(PatriciaTreeMapAbstractEnvironmentTest, erase_all_matching) {
EXPECT_TRUE(e1.is_top());
}

TEST_F(PatriciaTreeMapAbstractEnvironmentTest, map) {
TEST_F(PatriciaTreeMapAbstractEnvironmentTest, transform) {
Environment e1({{1, Domain({"a", "b"})}});
bool any_changes = e1.map([](Domain d) { return d; });
bool any_changes = e1.transform([](Domain d) { return d; });
EXPECT_FALSE(any_changes);

any_changes = e1.map([](Domain d) { return Domain::top(); });
any_changes = e1.transform([](Domain d) { return Domain::top(); });
EXPECT_TRUE(any_changes);
EXPECT_TRUE(e1.is_top());
}
Expand Down
6 changes: 3 additions & 3 deletions sparta/test/PatriciaTreeMapAbstractPartitionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,12 @@ TEST(PatriciaTreeMapAbstractPartitionTest, destructiveOperations) {
EXPECT_TRUE(p6.is_top());
}

TEST(PatriciaTreeMapAbstractPartitionTest, map) {
TEST(PatriciaTreeMapAbstractPartitionTest, transform) {
Partition p1({{1, Domain({"a", "b"})}});
bool any_changes = p1.map([](Domain d) { return d; });
bool any_changes = p1.transform([](Domain d) { return d; });
EXPECT_FALSE(any_changes);

any_changes = p1.map([](Domain d) { return Domain::bottom(); });
any_changes = p1.transform([](Domain d) { return Domain::bottom(); });
EXPECT_TRUE(any_changes);
EXPECT_TRUE(p1.is_bottom());
}
6 changes: 3 additions & 3 deletions sparta/test/PatriciaTreeMapTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,18 @@ TEST(PatriciaTreeMapTest, erase_all_matching) {
EXPECT_EQ(m1.at(1), 1);
}

TEST(PatriciaTreeMapTest, map) {
TEST(PatriciaTreeMapTest, transform) {
constexpr uint32_t default_value = 0;
pt_map m1 = create_pt_map({{0, 1}, {1, 2}, {2, 4}});

bool any_changes = m1.map([](uint32_t value) { return value; });
bool any_changes = m1.transform([](uint32_t value) { return value; });
EXPECT_FALSE(any_changes);
EXPECT_EQ(3, m1.size());
EXPECT_EQ(m1.at(0), 1);
EXPECT_EQ(m1.at(1), 2);
EXPECT_EQ(m1.at(2), 4);

any_changes = m1.map([](uint32_t value) { return value - 1; });
any_changes = m1.transform([](uint32_t value) { return value - 1; });
EXPECT_TRUE(any_changes);
EXPECT_EQ(2, m1.size());
EXPECT_EQ(m1.at(0), default_value);
Expand Down

0 comments on commit a1b1513

Please sign in to comment.