Skip to content

Commit

Permalink
Merge branch 'master' into automap
Browse files Browse the repository at this point in the history
  • Loading branch information
athas committed Nov 23, 2024
2 parents 279de4a + f346bf4 commit 8a23982
Show file tree
Hide file tree
Showing 50 changed files with 594 additions and 369 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ jobs:
dist-newstyle
key: ${{ runner.os }}-cabal-${{ hashFiles('futhark.cabal', 'cabal.project') }}

- name: cabal check
run: cabal check

- name: Build Futhark
run: |
cabal --version
Expand Down
22 changes: 19 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,29 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

### Removed

### Fixed

* Sizes that go out of scope due to use of higher order functions will
now work in more cases by adding existentials. (#2193)

* Tracing inside AD operators with the interpreter now prints values
properly.

### Changed

## [0.25.24]

### Added

* `futhark doc` now produces better (and stable) anchor IDs.

* `futhark profile` now supports multiple JSON files.

* `futhark fmt`, by William Due and Therese Lyngby.

### Removed

### Changed
* Lambdas can now be passed as the last argument to a function application.

### Fixed

Expand All @@ -29,6 +43,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
* A compile time regression for programs that used higher order
functions very aggressively.

* Uniqueness bug related to slice simplification.

## [0.25.23]

### Added
Expand Down
6 changes: 3 additions & 3 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
packages: futhark.cabal
index-state: 2024-10-20T06:00:08Z
index-state: 2024-11-04T14:44:59Z

package futhark
ghc-options: -j -fwrite-ide-info -hiedir=.hie
Expand All @@ -8,5 +8,5 @@ allow-newer: base, template-haskell

source-repository-package
type: git
location: https://github.com/ludat/glpk-hs.git
tag: efcb8354daa1205de2b862898353da2e4beb76b2
location: https://github.com/jyp/glpk-hs.git
tag: 1f276aa19861203ea8367dc27a6ad4c8a31c9062
7 changes: 7 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,13 @@ class FutharkLexer(RegexLexer):
[],
1,
),
(
"man/futhark-fmt",
"futhark-fmt",
"format Futhark programs",
[],
1,
),
("man/futhark-pkg", "futhark-pkg", "manage Futhark packages", [], 1),
(
"man/futhark-literate",
Expand Down
63 changes: 0 additions & 63 deletions docs/error-index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -566,69 +566,6 @@ Such an abbreviation is actually shorthand for
which is erroneous, but with workarounds, as explained in
:ref:`unused-existential`.

.. _unify-param-existential:

"Parameter *x* used as size would go out of scope."
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This error tends to happen when higher-order functions are used in a
way that causes a size requirement to become impossible to express.
Real programs that encounter this issue tend to be complicated, but to
illustrate the problem, consider the following contrived function:

.. code-block:: futhark
def f (n: i64) (m: i64) (b: [n][m]bool) = b[0,0]
We have the following type:

.. code-block:: futhark
val f : (n: i64) -> (m: i64) -> (b: [n][m]bool) -> bool
Now suppose we say:

.. code-block:: futhark
def g = uncurry f
What should be the type of ``g``? Intuitively, something like this:

.. code-block:: futhark
val g : (n: i64, m: i64) -> (b: [n][m]bool) -> bool
But this is *not* expressible in the Futhark type system - and even if
it were, it would not be easy to infer this in general, as it depends
on exactly what ``uncurry`` does, which the type checker does not
know.

As a workaround, we can use explicit type annotation and size
coercions to give ``g`` an acceptable type:

.. code-block:: futhark
def g [a][b] (n,m) (b: [a][b]bool) = f n m (b :> [n][m]bool)
Another workaround, which is often the right one in cases not as
contrived as above, is to modify ``f`` itself to produce a *witness*
of the constraint, in the form of an array of shape ``[n][m]``:

.. code-block:: futhark
def f (n: i64) (m: i64) : ([n][m](), [n][m]bool -> bool) =
(replicate n (replicate m ()), \b -> b[0,0])
Then ``uncurry f`` works just fine and has the following type:

.. code-block:: futhark
(i64, i64) -> ?[n][m].([n][m](), [n][m]bool -> bool)
Programming with such *explicit size witnesses* is a fairly advanced
technique, but often necessary when writing advanced size-dependent
code.

.. _unify-consuming-param:

"Parameter types *x* and *y* are incompatible regarding consuming their arguments
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ the `development blog <https://futhark-lang.org/blog.html>`_.
man/futhark-cuda.rst
man/futhark-dataset.rst
man/futhark-doc.rst
man/futhark-fmt.rst
man/futhark-hip.rst
man/futhark-ispc.rst
man/futhark-literate.rst
Expand Down
39 changes: 39 additions & 0 deletions docs/man/futhark-fmt.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
.. role:: ref(emphasis)

.. _futhark-fmt(1):

===========
futhark-fmt
===========

SYNOPSIS
========

futhark fmt [FILES]

DESCRIPTION
===========

Reformat the given Futhark programs. If no files are provided, read
Futhark program on stdin and produce formatted output on stdout. If
stdout is a terminal, the output will be syntax highlighted.

In contrast to many other automatic formatters, the formatting is
somewhat sensitive to the formatting of the input program. In
particular, single-line expressions will usually be kept on a single
line, even if they are very long. To force ``futhark fmt`` to break
these, insert a linebreak at an arbitrary location.

OPTIONS
=======

-h
Print help text to standard output and exit.

-V
Print version information on standard output and exit.

SEE ALSO
========

:ref:`futhark-doc(1)`
2 changes: 1 addition & 1 deletion docs/man/futhark-ispc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ LIBRARY USAGE

When compiling a program ``foo.fut`` with ``futhark ispc --library``,
a ``foo.kernels.ispc`` file is produced that must be compiled with
:ref:`ispc(1)` and linked with the final program. For example::
``ispc`` and linked with the final program. For example::

$ ispc -o foo.kernels.o foo.kernels.ispc --addressing=64 --pic --woff -O3

Expand Down
7 changes: 0 additions & 7 deletions docs/man/futhark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,6 @@ futhark eval [-f FILE] [-w] <exprs...>
Evaluates expressions given as command-line arguments. Optionally
allows a file import using ``-f``.

futhark fmt [FILE]
------------------

Reformat the given Futhark program. If no file is provided, read
Futhark program on stdin and produce formatted output on stdout. If
stdout is a terminal, the output will be syntax highlighted.

futhark hash PROGRAM
--------------------

Expand Down
4 changes: 2 additions & 2 deletions futhark.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ library
aeson >=2.0.0.0
, ansi-terminal >=0.6.3.1
, array >=0.4
, async >=2.0
, base >=4.15 && <5
, base16-bytestring
, binary >=0.8.3
Expand All @@ -472,7 +473,7 @@ library
, filepath >=1.4.1.1
, free >=5.1.10
, futhark-data >= 1.1.1.0
, futhark-server >= 1.2.2.1
, futhark-server >= 1.2.3.0
, futhark-manifest >= 1.5.0.0
, githash >=0.1.6.1
, half >= 0.3
Expand Down Expand Up @@ -550,7 +551,6 @@ test-suite unit
Language.Futhark.SyntaxTests
Language.Futhark.TypeChecker.TypesTests
Language.Futhark.TypeCheckerTests
Paths_futhark
build-depends:
QuickCheck >=2.8
, mtl >=2.2.1
Expand Down
4 changes: 2 additions & 2 deletions nix/futhark-server.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
}:
mkDerivation {
pname = "futhark-server";
version = "1.2.2.1";
sha256 = "5845ca6f4dd8395ef860164a7e8193e4094dc342a5b7187e314a7842e70b163d";
version = "1.2.3.0";
sha256 = "4bd26a908ae3c41b4eb18343a8fedb193a06c802c9e8a31d99a4f87dc781f189";
libraryHaskellDepends = [
base binary bytestring directory futhark-data mtl process temporary
text
Expand Down
1 change: 1 addition & 0 deletions shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pkgs.stdenv.mkDerivation {
haskell.haskell-language-server
haskellPackages.graphmod
haskellPackages.apply-refact
python
xdot
hlint
pkg-config
Expand Down
11 changes: 5 additions & 6 deletions src/Futhark/CLI/Fmt.hs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
-- | @futhark fmt@
module Futhark.CLI.Fmt (main) where

import Control.Monad (forM_)
import Data.Text.IO qualified as T
import Futhark.Fmt.Printer
import Futhark.Util.Options
Expand All @@ -12,15 +13,13 @@ import System.IO

-- | Run @futhark fmt@.
main :: String -> [String] -> IO ()
main = mainWithOptions () [] "program" $ \args () ->
main = mainWithOptions () [] "[FILES" $ \args () ->
case args of
[] -> Just $ putDoc =<< onInput =<< T.getContents
[file] ->
Just $ do
files ->
Just $ forM_ files $ \file -> do
doc <- onInput =<< T.readFile file
withFile file WriteMode $ \h ->
hPutDoc h doc
_any -> Nothing
withFile file WriteMode $ \h -> hPutDoc h doc
where
onInput s = do
case fmtToDoc "<stdin>" s of
Expand Down
20 changes: 16 additions & 4 deletions src/Futhark/CLI/REPL.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Control.Monad.Except
import Control.Monad.Free.Church
import Control.Monad.State
import Data.Char
import Data.List (intersperse)
import Data.List (intersperse, isPrefixOf)
import Data.List.NonEmpty qualified as NE
import Data.Map qualified as M
import Data.Maybe
Expand Down Expand Up @@ -55,6 +55,10 @@ main = mainWithOptions () [] "options... [program.fut]" run

data StopReason = EOF | Stop | Exit | Load FilePath | Interrupt

replSettings :: Haskeline.Settings IO
replSettings =
Haskeline.setComplete replComplete Haskeline.defaultSettings

repl :: Maybe FilePath -> IO ()
repl maybe_prog = do
when fancyTerminal $ do
Expand Down Expand Up @@ -103,16 +107,15 @@ repl maybe_prog = do
pure s {futharkiLoaded = maybe_prog}
Right s ->
pure s
Haskeline.runInputT Haskeline.defaultSettings $ toploop s
Haskeline.runInputT replSettings $ toploop s

putStrLn "Leaving 'futhark repl'."

-- | Representation of breaking at a breakpoint, to allow for
-- navigating through the stack frames and such.
data Breaking = Breaking
{ breakingStack :: NE.NonEmpty I.StackFrame,
-- | Index of the current breakpoint (with
-- 0 being the outermost).
-- | Index of the current breakpoint (with 0 being the outermost).
breakingAt :: Int
}

Expand Down Expand Up @@ -373,6 +376,15 @@ runInterpreterNoBreak m = runF m (pure . Right) intOp
locText w <> ": " <> "ignoring breakpoint when computating constant."
c

replComplete :: Haskeline.CompletionFunc IO
replComplete = loadComplete
where
loadComplete (prev, aft)
| ":load " `isPrefixOf` reverse prev =
Haskeline.completeFilename (prev, aft)
| otherwise =
Haskeline.noCompletion (prev, aft)

type Command = T.Text -> FutharkiM ()

loadCommand :: Command
Expand Down
Loading

0 comments on commit 8a23982

Please sign in to comment.