Skip to content
This repository was archived by the owner on Jan 9, 2026. It is now read-only.

Improve advice implementation + remove flag, CPP#1187

Merged
sirlensalot merged 2 commits intomasterfrom
feat/better-advice
Apr 12, 2023
Merged

Improve advice implementation + remove flag, CPP#1187
sirlensalot merged 2 commits intomasterfrom
feat/better-advice

Conversation

@sirlensalot
Copy link
Copy Markdown
Contributor

No description provided.

@jwiegley
Copy link
Copy Markdown
Contributor

I like the changes, but do we have any tests of this advice machinery? Are we relying on the passing of existing tests to confirm that the behavior remains correct?

@sirlensalot
Copy link
Copy Markdown
Contributor Author

I like the changes, but do we have any tests of this advice machinery? Are we relying on the passing of existing tests to confirm that the behavior remains correct?

Re coverage, see #1151 where we added lcov coverage regression, which is the only "production" (in pact tool) use for advice.

Otherwise this now has no-op advice in production code paths, so the main impact to look out for is a performance regression. Once the build is fixed I'll take a look

@sirlensalot
Copy link
Copy Markdown
Contributor Author

Perf seems ok, maybe the tiniest slowdown but difference is probably noise

Master <-> PR, both ubuntu 22.04 +build-tool GHC 8.10.7

image

@jwiegley
Copy link
Copy Markdown
Contributor

This looks like a nice extensions of the Advice concept.

@sirlensalot
Copy link
Copy Markdown
Contributor Author

This looks like a nice extensions of the Advice concept.

It's actually strictly less powerful than what preceded it, but that was a performance nightmare apparently. The old advice allowed advice to modify the return value, which is nifty I guess? But actual use cases (coverage, benchmarking) were just observational, so now it's just a "bracket with context", and doesn't have the thunking that bedeviled the old approach.

@sirlensalot sirlensalot merged commit 10cc8a2 into master Apr 12, 2023
@sirlensalot sirlensalot deleted the feat/better-advice branch April 12, 2023 20:14
post r
return a
_ -> fmap snd f
cover :: MonadIO m => IORef LcovReport -> Info -> AdviceContext r -> m (r -> m())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small syntactic wibble

Suggested change
cover :: MonadIO m => IORef LcovReport -> Info -> AdviceContext r -> m (r -> m())
cover :: MonadIO m => IORef LcovReport -> Info -> AdviceContext r -> m (r -> m ())


advise :: MonadIO m => Info -> Advice -> AdviceContext r -> m (r,a) -> m a
advise i (Advice f) ctx act = f i ctx act
advise :: MonadIO m => Info -> Advice -> AdviceContext r -> m (r -> m())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
advise :: MonadIO m => Info -> Advice -> AdviceContext r -> m (r -> m())
advise :: MonadIO m => Info -> Advice -> AdviceContext r -> m (r -> m ())

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants