Skip to content

Commit

Permalink
cleanup assumenosideeffects
Browse files Browse the repository at this point in the history
Summary: This property is only ever used at the method level.

Reviewed By: beicy

Differential Revision: D52918407

fbshipit-source-id: 6b3f53ef7653fe18ade54922af53cd5b027a9b41
  • Loading branch information
Nikolai Tillmann authored and facebook-github-bot committed Jan 24, 2024
1 parent ca1cc45 commit 12c41e6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
3 changes: 2 additions & 1 deletion libredex/IRMetaIO.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class IRMetaIO {
!obj->rstate.inner_struct.m_is_serde)) &&
!obj->rstate.inner_struct.m_by_resources &&
!obj->rstate.inner_struct.m_keep &&
!obj->rstate.inner_struct.m_assumenosideeffects &&
(!obj->rstate.inner_struct.is_method() ||
!obj->rstate.inner_struct.m_assumenosideeffects) &&
!obj->rstate.inner_struct.m_whyareyoukeeping &&
!obj->rstate.inner_struct.m_set_allowshrinking &&
!obj->rstate.inner_struct.m_unset_allowshrinking &&
Expand Down
1 change: 0 additions & 1 deletion libredex/ProguardMatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ void KeepRuleMatcher::process_whyareyoukeeping(DexClass* cls) {

// This function is also executed concurrently.
void KeepRuleMatcher::process_assumenosideeffects(DexClass* cls) {
cls->rstate.set_assumenosideeffects();
++m_class_matches;
// Apply any method-level keep specifications.
apply_method_keeps(cls);
Expand Down
4 changes: 3 additions & 1 deletion libredex/ReachableClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,9 @@ std::string ReferencedState::str() const {
s << inner_struct.m_keep;
s << allowshrinking();
s << allowobfuscation();
s << inner_struct.m_assumenosideeffects;
if (inner_struct.is_method()) {
s << inner_struct.m_assumenosideeffects;
}
s << inner_struct.m_whyareyoukeeping;
return s.str();
}
3 changes: 1 addition & 2 deletions libredex/ReachableClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ inline bool marked_by_string(const DexClass* member) {
return member->rstate.is_referenced_by_string();
}

template <class DexMember>
inline bool assumenosideeffects(DexMember* member) {
inline bool assumenosideeffects(const DexMethod* member) {
return member->rstate.assumenosideeffects();
}
22 changes: 14 additions & 8 deletions libredex/ReferencedState.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ class ReferencedState {
// Whether any keep rule has matched this. This applies for both `-keep` and
// `-keepnames`.
bool m_keep : 1;
// assumenosideeffects allows certain methods to be removed.
bool m_assumenosideeffects : 1;

// If m_whyareyoukeeping is true then report debugging information
// about why this class or member is being kept.
bool m_whyareyoukeeping : 1;
Expand Down Expand Up @@ -101,9 +100,12 @@ class ReferencedState {
bool m_renamable_initialized : 1;
};
// This is for method only. Currently, the number of flags
// is 6. Once new flag is added, please update the corresponding number in
// is 7. Once new flag is added, please update the corresponding number in
// comment.
struct {
// assumenosideeffects allows certain methods to be removed.
bool m_assumenosideeffects : 1;

bool m_no_optimizations : 1;
// This is set by the AnalyzePureMethodsPass. It indicates that a method
// is pure as defined in Purity.h.
Expand Down Expand Up @@ -140,7 +142,6 @@ class ReferencedState {
m_by_resources = false;

m_keep = false;
m_assumenosideeffects = false;
m_whyareyoukeeping = false;

m_set_allowshrinking = false;
Expand Down Expand Up @@ -228,9 +229,6 @@ class ReferencedState {
this->inner_struct.m_keep =
this->inner_struct.m_keep | other.inner_struct.m_keep;

this->inner_struct.m_assumenosideeffects =
this->inner_struct.m_assumenosideeffects &
other.inner_struct.m_assumenosideeffects;
this->inner_struct.m_whyareyoukeeping =
this->inner_struct.m_whyareyoukeeping |
other.inner_struct.m_whyareyoukeeping;
Expand Down Expand Up @@ -267,6 +265,9 @@ class ReferencedState {
this->inner_struct.m_is_kotlin =
this->inner_struct.m_is_kotlin & other.inner_struct.m_is_kotlin;
} else if (this->inner_struct.is_method()) {
this->inner_struct.m_assumenosideeffects =
this->inner_struct.m_assumenosideeffects &
other.inner_struct.m_assumenosideeffects;
this->inner_struct.m_no_optimizations =
this->inner_struct.m_no_optimizations |
other.inner_struct.m_no_optimizations;
Expand Down Expand Up @@ -328,6 +329,7 @@ class ReferencedState {
}

bool assumenosideeffects() const {
always_assert(this->inner_struct.is_method());
return inner_struct.m_assumenosideeffects;
}

Expand Down Expand Up @@ -437,7 +439,11 @@ class ReferencedState {
inner_struct.m_unset_allowshrinking = false;
}

void set_assumenosideeffects() { inner_struct.m_assumenosideeffects = true; }
void set_assumenosideeffects() {
if (this->inner_struct.is_method()) {
inner_struct.m_assumenosideeffects = true;
}
}

void set_whyareyoukeeping() { inner_struct.m_whyareyoukeeping = true; }

Expand Down

0 comments on commit 12c41e6

Please sign in to comment.