Skip to content

Add a deep collection comparison to memoizer in checked mode #1575

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 5 commits into from
Jan 4, 2018

Conversation

jcollins-g
Copy link
Contributor

@jcollins-g jcollins-g commented Dec 20, 2017

Adds a class, ValidatingMemoizer, that in checked mode adds an assert to validate that cached values haven't changed from the return value of f(). There are many areas of dartdoc where these values changing are a sign of underlying bugs. This way we can make use of the cache to verify these.

@googlebot googlebot added the cla: yes Google CLA check succeeded. label Dec 20, 2017
/// memoized function is unchanging using [DeepCollectionEquality]. Still
/// returns the cached value assuming the assertion passes.
class ValidatingMemoizer extends Memoizer {
bool _assert_on_difference;
Copy link
Member

Choose a reason for hiding this comment

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

likely should init to false

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

/// Otherwise, a wrapper around putIfAbsent.
@override
R _cacheIfAbsent<R>(_HashableList key, R Function() f) {
if (_assert_on_difference) {
Copy link
Member

Choose a reason for hiding this comment

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

w/o the init at definition, this will be if (null)

@jcollins-g jcollins-g merged commit 617d928 into master Jan 4, 2018
@jcollins-g jcollins-g deleted the memoizer-slow-mode branch January 4, 2018 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes Google CLA check succeeded.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants