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

Add support for NumericUnderscores extensions from CLI/config #1618

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

9999years
Copy link
Contributor

Closes #1434

Supercedes #1435, updated for latest master.

Copy link
Collaborator

@zliu41 zliu41 left a comment

Choose a reason for hiding this comment

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

I'll defer this to @ndmitchell. I think the intention of passing extensions to HLint is for parsing, not for deciding if a hint should trigger, although it seems reasonable to do the latter.

Even if we decide to do that, this PR will need a few more updates:

  • I'm not seeing how you are passing the additional extensions from the Yaml config to the places that need them.
  • Since the additional extensions are from the HLint config and not tied to individual modules, it doesn't seem to make sense to associate them with ModuleEx.
  • Need to add some tests.

@9999years 9999years force-pushed the numeric-underscores branch 4 times, most recently from b753135 to 23fb178 Compare February 7, 2025 18:18
@9999years 9999years force-pushed the numeric-underscores branch from 23fb178 to 6a62399 Compare February 7, 2025 18:40
@@ -214,7 +223,7 @@ parseModuleEx flags file str = timedIO "Parse" file $ runExceptT $ do
ExceptT $ parseFailureErr dynFlags str file str $ NE.fromList errs
else do
let fixes = fixitiesFromModule a ++ ghcFixitiesFromParseFlags flags
pure $ ModuleEx (applyFixities fixes a)
pure $ ModuleEx (applyFixities fixes a) (enabledExtensions flags)

Choose a reason for hiding this comment

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

So the provenance of these extensions is in ParseFlags. This is not passed to hints themselves.

The type of DeclHint is:

type DeclHint = Scope -> ModuleEx -> LHsDecl GhcPs -> [Idea]

If we want to propagate this information, we have essentially three choices:

  1. Smuggle it in ModuleEx.
  2. Smuggle it in Scope.
  3. Add another function argument here for the whole hlint configuration (ParseFlags ? and [Setting] maybe?)

Scope is, already, just a convenience/performance/cache wrapper around information that is extracted directly from the contents of a ModuleEx. Here is definition and logic to create.

I think one could argue that Scope is a more reasonable place for this than ModuleEx, but I'd go further: Scope should be part of ModuleEx directly. After all, scopeCreate is called on the ModuleEx - which means that we have already lost the ParseFlags information, if it is not present on ModuleEx.

IMO, a ModuleEx represents "what we know about a parsed module":

-- | Result of 'parseModuleEx', representing a parsed module.
newtype ModuleEx = ModuleEx {
    ghcModule :: Located (HsModule GhcPs)
}

But we don't know - what extensions were enabled while parsing this module?

I think "rearchitecting the way we pass flags around in hlint and breaking the whole API for hints" is probably not appropriate for this PR. If we extend ModuleEx, then we pave the way for further additions to ModuleEx as "the" place to put information relevant to a module. If we extend Scope, then we need to plumb that through anyway, possibly through ModuleEx resulting in duplication. But neither option prevent or impede a more serious refactoring in how this code works.

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.

HLint seems to ignore -XNumericUnderscores
4 participants