Skip to content

Commit

Permalink
futhark fmt: preserve doc comments for local defs.
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Jan 9, 2025
1 parent 1dc7e3e commit ec333e9
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

* GPU backends did not handle array constants correctly in some cases.

* `futhark fmt`: do not throw away doc comments for `local`
definitions.

## [0.25.25]

### Added
Expand Down
2 changes: 1 addition & 1 deletion src/Futhark/Fmt/Printer.hs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ instance Format UncheckedDec where
fmt (ModTypeDec tb) = fmt tb
fmt (ModDec tb) = fmt tb
fmt (OpenDec tb loc) = addComments loc $ "open" <+> fmt tb
fmt (LocalDec tb loc) = addComments loc $ "local" <+> fmt tb
fmt (LocalDec tb loc) = addComments loc $ "local" </> fmt tb
fmt (ImportDec path _tb loc) =
addComments loc $ "import" <+> "\"" <> fmtPretty path <> "\""

Expand Down
3 changes: 2 additions & 1 deletion src/Language/Futhark/Parser/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,15 @@ addDoc doc (ValDec val) = ValDec (val {valBindDoc = Just doc})
addDoc doc (TypeDec tp) = TypeDec (tp {typeDoc = Just doc})
addDoc doc (ModTypeDec sig) = ModTypeDec (sig {modTypeDoc = Just doc})
addDoc doc (ModDec mod) = ModDec (mod {modDoc = Just doc})
addDoc doc (LocalDec dec loc) = LocalDec (addDoc doc dec) loc
addDoc _ dec = dec

addDocSpec :: DocComment -> SpecBase NoInfo Name -> SpecBase NoInfo Name
addDocSpec doc (TypeAbbrSpec tpsig) = TypeAbbrSpec (tpsig {typeDoc = Just doc})
addDocSpec doc (ValSpec name ps t NoInfo _ loc) = ValSpec name ps t NoInfo (Just doc) loc
addDocSpec doc (TypeSpec l name ps _ loc) = TypeSpec l name ps (Just doc) loc
addDocSpec doc (ModSpec name se _ loc) = ModSpec name se (Just doc) loc
addDocSpec _ spec = spec
addDocSpec _ spec@IncludeSpec {} = spec

addAttr :: AttrInfo Name -> UncheckedDec -> UncheckedDec
addAttr attr (ValDec val) =
Expand Down
7 changes: 7 additions & 0 deletions tests_fmt/expected/local.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- | top level.

local
-- | I am a doc comment.
module type mt = {

}
7 changes: 7 additions & 0 deletions tests_fmt/local.fut
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- | top level.

local
-- | I am a doc comment.
module type mt = {

}

0 comments on commit ec333e9

Please sign in to comment.