Skip to content

Commit

Permalink
Use a separate warning for duplicated interface files
Browse files Browse the repository at this point in the history
This warning shouldn't be serialized to interface files because it can
be resolved without changing the source code. For example, if the
warning is triggered and serialized into the interface file, The
interface file would still be considered up-to-date, despite that the
warning might have been resolved.

Fixes #7104.
  • Loading branch information
ibbem authored and andreasabel committed Feb 15, 2024
1 parent c0ceac7 commit a65e3cc
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 15 deletions.
4 changes: 4 additions & 0 deletions doc/user-manual/tools/command-line-options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,10 @@ The list containing any warning ``NAME`` can be produced by ``agda --help=warnin

``record`` expression with duplicate field names.

.. option:: DuplicateInterfaceFiles

There exists both a local interface file and an interface file in ``_build``.

.. option:: DuplicateUsing

Repeated names in ``using`` directive.
Expand Down
21 changes: 8 additions & 13 deletions src/full/Agda/Interaction/FindFile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import qualified Agda.TypeChecking.Monad.Benchmark as Bench
import {-# SOURCE #-} Agda.TypeChecking.Monad.Options
(getIncludeDirs, libToTCM)
import Agda.TypeChecking.Monad.State (topLevelModuleName)
import Agda.TypeChecking.Warnings (runPM, genericWarning)
import Agda.TypeChecking.Warnings (runPM, warning)

import Agda.Version ( version )

Expand Down Expand Up @@ -96,25 +96,20 @@ toIFile (SourceFile src) = do
let buildDir = root </> "_build" </> version </> "agda"
fileName = makeRelative root (filePath localIFile)
separatedIFile = mkAbsolute $ buildDir </> fileName
selectIFile = ifM (optLocalInterfaces <$> commandLineOptions)
(pure localIFile)
(pure separatedIFile)
ifilePreference = ifM (optLocalInterfaces <$> commandLineOptions)
(pure (localIFile, separatedIFile))
(pure (separatedIFile, localIFile))
in do
separatedIFileExists <- liftIO $ doesFileExistCaseSensitive $ filePath separatedIFile
localIFileExists <- liftIO $ doesFileExistCaseSensitive $ filePath localIFile
case (separatedIFileExists, localIFileExists) of
(False, False) -> selectIFile
(False, False) -> fst <$> ifilePreference
(False, True) -> pure localIFile
(True, False) -> pure separatedIFile
(True, True) -> do
ifile <- selectIFile
genericWarning $ P.vcat
[ P.text "There are two interface files:"
, P.nest 4 $ P.text $ filePath separatedIFile
, P.nest 4 $ P.text $ filePath localIFile
, P.nest 2 $ P.text $ "Using " ++ filePath ifile ++ " for now but please remove at least one of them."
]
pure ifile
ifiles <- ifilePreference
warning $ uncurry DuplicateInterfaceFiles ifiles
pure $ fst ifiles

replaceModuleExtension :: String -> AbsolutePath -> AbsolutePath
replaceModuleExtension ext@('.':_) = mkAbsolute . (++ ext) . dropAgdaExtension . filePath
Expand Down
3 changes: 3 additions & 0 deletions src/full/Agda/Interaction/Highlighting/Generate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ warningHighlighting' b w = case tcWarning w of
UnknownNamesInFixityDecl{} -> mempty
UnknownNamesInPolarityPragmas{} -> mempty

-- Not source code related
DuplicateInterfaceFiles{} -> mempty

recordFieldWarningHighlighting ::
RecordFieldWarning -> HighlightingInfoBuilder
recordFieldWarningHighlighting = \case
Expand Down
2 changes: 1 addition & 1 deletion src/full/Agda/Interaction/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,7 @@ buildInterface src topLevel = do
-- when expanding a pattern synonym.
patsyns <- killRange <$> getPatternSyns
let builtin' = Map.mapWithKey (\ x b -> primName x <$> b) builtin
warnings <- getAllWarnings AllWarnings
warnings <- filter (isSourceCodeWarning . warningName . tcWarning) <$> getAllWarnings AllWarnings
let i = Interface
{ iSourceHash = hashText source
, iSource = source
Expand Down
4 changes: 4 additions & 0 deletions src/full/Agda/Interaction/Options/Warnings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ data WarningName
-- Cubical
| FaceConstraintCannotBeHidden_
| FaceConstraintCannotBeNamed_
-- Not source code related
| DuplicateInterfaceFiles_
deriving (Eq, Ord, Show, Read, Enum, Bounded, Generic)

instance NFData WarningName
Expand Down Expand Up @@ -479,3 +481,5 @@ warningNameDescription = \case
-- Cubical
FaceConstraintCannotBeHidden_ -> "Face constraint patterns that are given as implicit arguments."
FaceConstraintCannotBeNamed_ -> "Face constraint patterns that are given as named arguments."
-- Not source code related
DuplicateInterfaceFiles_ -> "Duplicate interface files."
13 changes: 13 additions & 0 deletions src/full/Agda/TypeChecking/Monad/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4259,6 +4259,10 @@ data Warning
-- ^ Face constraint patterns @(i = 0)@ must be visible arguments.
| FaceConstraintCannotBeNamed NamedName
-- ^ Face constraint patterns @(i = 0)@ must be unnamed arguments.

-- Not source code related
| DuplicateInterfaceFiles AbsolutePath AbsolutePath
-- ^ `DuplicateInterfaceFiles selectedInterfaceFile ignoredInterfaceFile`
deriving (Show, Generic)

recordFieldWarningToError :: RecordFieldWarning -> TypeError
Expand Down Expand Up @@ -4339,6 +4343,15 @@ warningName = \case
FaceConstraintCannotBeHidden{} -> FaceConstraintCannotBeHidden_
FaceConstraintCannotBeNamed{} -> FaceConstraintCannotBeNamed_

-- Not source code related
DuplicateInterfaceFiles{} -> DuplicateInterfaceFiles_

-- Indicates wether changes in the source code can silence or influence the
-- warning.
isSourceCodeWarning :: WarningName -> Bool
isSourceCodeWarning DuplicateInterfaceFiles_{} = False
isSourceCodeWarning _ = True

data TCWarning
= TCWarning
{ tcWarningLocation :: CallStack
Expand Down
8 changes: 8 additions & 0 deletions src/full/Agda/TypeChecking/Pretty/Warning.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import Agda.Syntax.Translation.InternalToAbstract
import Agda.Interaction.Options
import Agda.Interaction.Options.Warnings

import Agda.Utils.FileName (filePath)
import Agda.Utils.Lens
import Agda.Utils.List ( editDistance )
import qualified Agda.Utils.List1 as List1
Expand Down Expand Up @@ -239,6 +240,13 @@ prettyWarning = \case

ParseWarning pw -> pretty pw

DuplicateInterfaceFiles selected ignored -> vcat
[ fwords "There are two interface files:"
, nest 4 $ text $ filePath selected
, nest 4 $ text $ filePath ignored
, nest 2 $ fsep $ pwords "Using" ++ [text $ filePath selected] ++ pwords "for now but please remove at least one of them."
]

DeprecationWarning old new version -> fsep $
[text old] ++ pwords "has been deprecated. Use" ++ [text new] ++ pwords
"instead. This will be an error in Agda" ++ [text version <> "."]
Expand Down
2 changes: 1 addition & 1 deletion src/full/Agda/TypeChecking/Serialise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ import Agda.Utils.Impossible
-- 32-bit machines). Word64 does not have these problems.

currentInterfaceVersion :: Word64
currentInterfaceVersion = 20240102 * 10 + 0
currentInterfaceVersion = 20240102 * 10 + 1

-- | The result of 'encode' and 'encodeInterface'.

Expand Down
4 changes: 4 additions & 0 deletions src/full/Agda/TypeChecking/Serialise/Instances/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ instance EmbPrj Warning where
FaceConstraintCannotBeHidden a -> icodeN 47 FaceConstraintCannotBeHidden a
FaceConstraintCannotBeNamed a -> icodeN 48 FaceConstraintCannotBeNamed a
PatternShadowsConstructor a b -> icodeN 49 PatternShadowsConstructor a b
-- Not source code related, therefore they should never be serialized
DuplicateInterfaceFiles a b -> __IMPOSSIBLE__

value = vcase $ \ case
[0, a, b] -> valuN UnreachableClauses a b
Expand Down Expand Up @@ -442,6 +444,7 @@ instance EmbPrj WarningName where
FaceConstraintCannotBeHidden_ -> 102
FaceConstraintCannotBeNamed_ -> 103
PatternShadowsConstructor_ -> 104
DuplicateInterfaceFiles_ -> 105

value = \case
0 -> return OverlappingTokensWarning_
Expand Down Expand Up @@ -549,6 +552,7 @@ instance EmbPrj WarningName where
102 -> return FaceConstraintCannotBeHidden_
103 -> return FaceConstraintCannotBeNamed_
104 -> return PatternShadowsConstructor_
105 -> return DuplicateInterfaceFiles_
_ -> malformed


Expand Down

0 comments on commit a65e3cc

Please sign in to comment.