Skip to content
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

Refactor Stack utility class #495

Merged
merged 1 commit into from
Sep 3, 2020
Merged

Refactor Stack utility class #495

merged 1 commit into from
Sep 3, 2020

Conversation

chfast
Copy link
Collaborator

@chfast chfast commented Aug 18, 2020

I started this to investigate "containter-overflow" issues reported by ASan in XCode 12.0 beta. This does not fix the issue, but at least I minimized the Stack interface and we don't use inheritance any more.

@axic
Copy link
Member

axic commented Aug 23, 2020

@chfast I'm in favour of this, what is blocking here? Is the goal just cleanup or some speed benefit for parsing?

@chfast
Copy link
Collaborator Author

chfast commented Aug 23, 2020

Nothing is blocking this, but unit tests must be updated. See updated description.

@axic
Copy link
Member

axic commented Sep 2, 2020

I'd prefer this PR, unless there is some significant parser slowdown.

@chfast chfast force-pushed the stack_utils branch 2 times, most recently from 117c18b to ed42f15 Compare September 2, 2020 14:18
EXPECT_EQ(stack.size(), 0);
}

TEST(stack, resize)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no test for shrink besides this.

@axic
Copy link
Member

axic commented Sep 2, 2020

Could rename the drop_and_peek test to drop. And maybe group the struct_item test with the others.

lib/fizzy/stack.hpp Outdated Show resolved Hide resolved
lib/fizzy/stack.hpp Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #495 into master will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #495      +/-   ##
==========================================
- Coverage   99.69%   99.69%   -0.01%     
==========================================
  Files          54       54              
  Lines       17180    17091      -89     
==========================================
- Hits        17128    17039      -89     
  Misses         52       52              

@chfast chfast marked this pull request as ready for review September 2, 2020 14:44
@chfast chfast requested a review from gumb0 September 2, 2020 14:44
}

/// Drops @a num_elements elements from the top of the stack.
void drop(size_t num_elements = 1) noexcept { shrink(size() - num_elements); }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, shouldn't this need assert(size() >= num_elements), since size_t is unsigned, the value to shrink could wrap around?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OperandStack::drop has assert(num_elements <= size()) so maybe follow that style.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed drop().

@axic
Copy link
Member

axic commented Sep 2, 2020

The rest looks good to me.

Does this result in any significant regression in parsing?

@chfast
Copy link
Collaborator Author

chfast commented Sep 2, 2020

Not really a change performance-wise

fizzy/parse/blake2b_mean                                -0.0114         -0.0114            23            23            23            23
fizzy/parse/ecpairing_mean                              -0.0003         -0.0003          1338          1337          1338          1337
fizzy/parse/keccak256_mean                              -0.0095         -0.0094            42            42            42            42
fizzy/parse/memset_mean                                 -0.0034         -0.0034             6             6             6             6
fizzy/parse/mul256_opt0_mean                            -0.0269         -0.0269             8             8             8             8
fizzy/parse/ramanujan_pi_mean                           +0.0160         +0.0160            24            24            24            24
fizzy/parse/sha1_mean                                   -0.0008         -0.0008            38            38            38            38
fizzy/parse/sha256_mean                                 +0.0031         +0.0031            63            63            63            63
fizzy/parse/taylor_pi_mean                              -0.0262         -0.0262             3             3             3             3
fizzy/parse/micro/eli_interpreter_mean                  -0.0167         -0.0167             4             4             4             4
fizzy/parse/micro/factorial_mean                        -0.0392         -0.0392             1             1             1             1
fizzy/parse/micro/fibonacci_mean                        -0.0473         -0.0473             1             1             1             1
fizzy/parse/micro/host_adler32_mean                     -0.0250         -0.0250             2             2             2             2
fizzy/parse/micro/spinner_mean                          -0.0160         -0.0160             1             1             1             1

}

T pop()
T pop() noexcept
Copy link
Member

@axic axic Sep 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this marked noexcept because we manually ensure the caller will call it in a bad state? (Enforced by the assert in debug mode) Note that back and pop_back are not noexcept.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert is not relevant. This is noexcept because .back() and .pop_back() are noexcept too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked it when I commented on empty/size, but to me back/pop_back did not seem to be noexcept:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these behaving as noexcept pre-C++20 just not marked so?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Officially they are not noexcept (even in C++20), but in practice they are.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me.

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay to me, but would prefer a second look from @gumb0 on the noexcept question.

@chfast chfast merged commit 999a940 into master Sep 3, 2020
@chfast chfast deleted the stack_utils branch September 3, 2020 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants