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 data collection. #71

Merged
merged 7 commits into from
Nov 9, 2021
Merged

Refactor data collection. #71

merged 7 commits into from
Nov 9, 2021

Conversation

Heimdell
Copy link
Contributor

@Heimdell Heimdell commented Jul 29, 2021

Description

Problem: data collection is a function that calls itself 5 screens below the place it starts and is a pile of different, but unrelated actions, performed simultaneously.

Solution: divide the pile into parts and then combine parts externally.

Concrete changes

  1. The xrefcheck: ignore X functionality is implemented as a separate function.
  2. The data collection is a fold over the tree, and other reducers can be connected.

Results

Anchor/Reference colelctor fits into one screen now.

The Visitor API

foldNode :: (Monoid a, Monad m) => (Node -> m a) -> Node -> m a

Runs the provided action, collects the results.

Related issue(s)

None, preparing for #64

✅ Checklist for your Pull Request

Ideally a PR has all of the checkmarks set.

If something in this list is irrelevant to your PR, you should still set this
checkmark indicating that you are sure it is dealt with (be that by irrelevance).

Related changes (conditional)

  • Tests

    • If I added new functionality, I added tests covering it.
    • If I fixed a bug, I added a regression test to prevent the bug from
      silently reappearing again.
  • Documentation

    • I checked whether I should update the docs and did so if necessary:
  • Public contracts

    • Any modifications of public contracts comply with the Evolution
      of Public Contracts
      policy.
    • I added an entry to the changelog if my changes are visible to the users
      and
    • provided a migration guide for breaking changes if possible

Stylistic guide (mandatory)

Copy link
Contributor

@worm2fed worm2fed left a comment

Choose a reason for hiding this comment

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

Great PR description! but so dirty commit history..
Can you do something with it? It's become really hard to review your changes.

  1. Go through your commits and decide which small steps to your final result this commits lead you.
  2. Add description for each commit (as described in our policy) so we can review this steps separately and understand it.
  3. Use git commit --fixup HASH to fix smth in your previous commits, so we can understand to which commits related your fixes.

src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
exec/Main.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown/ErrorMessage.hs Outdated Show resolved Hide resolved
tests/Main.hs Show resolved Hide resolved
, "\"" <> txt <> "\""
, "perhaps you meant \
\<\"ignore link\"|\"ignore paragraph\"|\"ignore file\"> "
]
Copy link
Member

@Martoon-00 Martoon-00 Jul 29, 2021

Choose a reason for hiding this comment

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

I think this is not a good thing actually. Putting error messages far from the use site, we encourage their divergence from the actual problem (e.g. the actual error can obtain one more condition when it fires, but it is now easy to forget to update the error message respectively).

I think error messages and where they are used should both fit into one screen, maybe put in where/letl block if found to make the code less readable.

Copy link
Member

@Martoon-00 Martoon-00 left a comment

Choose a reason for hiding this comment

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

My opinion, per change:

  1. Using post-imports - kaef (though I wonder, didn't @worm2fed implemented this already somewhere else, taking Add requirement for qualified imports style#11 into account?)
    1.5. Mixins removal - good; import Universum addition - ok.
  2. Using polysemy - I would retract from doing this change until it actually appears necessary, because using it makes things more complex for newcomers, and there might be cases not well supported by it (as with any advanced framework).
  3. Using the Visitor pattern - the same thing, the current Markdown scanner already does most of the things we ever want from it and it just works. After the rewrite, we use only inside event, so things just got more complex without immediate benefit. And it's not clear whether future changes in the scanner logic, if any, will fit into the current model without increasing its complexity in directions other than that you support now.
  4. Error messages extraction to a separate module - responded in another comment. The fact of extraction is good, but error message and condition for it to fire should locate nearby IMO (they didn't before, but putting to a separate module sounds too harsh).
  5. Global -wno-orphans - this sounds like a coolstory, I think orhpans are not a very good pattern so discouraging it with a warning is actually good. Or not? Also I heard that compilation time slightly increases with each module that allows orphan instances.
  6. Trailing -- in haddock - why not just use the same style as in the remainder of the project :pepe_stare: If everyone comes with its own preferred style (that also probably changes every several years), that would be a mess.
  7. The separation of ignored removal and info gathering itself - really nice to obtain it 👍
  8. Moving functions from where to top-level - neat.

Well, quite a wall of comments, but this PR is sorta big too )

I would extract 1 & 1.5, maybe 4 (changed), 7 and 8 to a separate PR and leave other changes pending for now.

instance Default FileInfo where
def = FileInfo [] []
instance Semigroup FileInfo where
FileInfo a b <> FileInfo c d = FileInfo (a <> c) (b <> d)
Copy link
Member

Choose a reason for hiding this comment

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

And here we get O(n^2) for free :nabros:

Btw, it seems to me that having a builder version for some list-like type is quite a common practice, can it be generalized and put to some library 🤔

--
-- (Why isn't `Node` a type alias for `Data.Tree.Node`?)
--
instance {-# overlapping #-} Show DebugNode where
Copy link
Member

Choose a reason for hiding this comment

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

Why is it overlapping?

import Test.Hspec (Spec, describe, it, shouldBe)

import Xrefcheck.Core
import Xrefcheck.Scanners.Markdown

spec :: Spec
spec :: HasCallStack => Spec
Copy link
Member

Choose a reason for hiding this comment

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

Is this constraint necessary here?

|+ "' diverges with its label '" +| build txt
|+ "',\n which might denote copy-paste that ended with either anchor\n\
\ or label left not updated\n\n"

Copy link
Member

Choose a reason for hiding this comment

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

This apparently was intended for another PR )

@worm2fed
Copy link
Contributor

worm2fed commented Aug 6, 2021

@Martoon-00

Using post-imports - kaef (though I wonder, didn't @worm2fed implemented this already somewhere else, taking Add requirement for qualified imports style#11 into account?)

We didn't merge it yet. I'll update my PR soon!)

@Martoon-00
Copy link
Member

@Martoon-00

Using post-imports - kaef (though I wonder, didn't @worm2fed implemented this already somewhere else, taking Add requirement for qualified imports style#11 into account?)

We didn't merge it yet. I'll update my PR soon!)

👍

Just coordinate with @Heimdell who switches this entire project to post-qualified-imports.

@Heimdell Heimdell force-pushed the slowpnir/copy-paste-in-lists branch from 8ed8f3c to fae3d97 Compare October 4, 2021 10:53
Heimdell added a commit that referenced this pull request Oct 20, 2021
Problem:  The tree traversal uses explicit recursion and
          does not-closely-unrelated stuff at once.

Solution: Separate different actions.
src/Xrefcheck/Core.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Core.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
package.yaml Show resolved Hide resolved
package.yaml Show resolved Hide resolved
package.yaml Show resolved Hide resolved
package.yaml Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
Problem:  Stack cannot build projects with mixins, and they only
          used to splice universum instead of base.

Solution: Use `NoImplicitPreduce` and import `Universum`
          everywhere explicitly.
Problem:  In
          ```
          import qualified Foo.Bar as Bar
          import Foo.Bar (Bar)
          ```
          names of the imported modules are on different
          vertical lines, which disables autosorting,
          and makes it harder to read.

Solution: Use `ImportQualifiedPost`
Problem:  The tree traversal uses explicit recursion and
          does not-closely-unrelated stuff at once.

Solution: Separate different actions.
src/Xrefcheck/Scanners/Markdown.hs Show resolved Hide resolved
src/Xrefcheck/Scanners/Markdown.hs Outdated Show resolved Hide resolved
@dcastro
Copy link
Member

dcastro commented Nov 9, 2021

@Martoon-00 do you wanna have another look at this before merging, or are you happy enough with merging as-is?

@Heimdell Heimdell merged commit 7e954c2 into master Nov 9, 2021
@delete-merged-branch delete-merged-branch bot deleted the slowpnir/copy-paste-in-lists branch November 9, 2021 11:37
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.

4 participants