diku-dk / futhark

:boom::computer::boom: A data-parallel functional programming language
http://futhark-lang.org
ISC License
2.4k stars 167 forks source link

Futhark requiring ".fut" extension is unintuitive and undocumented #1813

Closed virchau13 closed 1 year ago

virchau13 commented 1 year ago

Running

echo 'def main (x: i32): i32 = x + 1' > test.futhark
futhark c test.futhark
./test

yields this exact output:

No entry point 'main'.  Select another with --entry-point.  Options are:

There appear to be no options for the entry point. The generated code contains:

struct entry_point_entry entry_points[] = {};

And if you compile the code with --library, the manifest contains:

{"backend":"c","entry_points":{},"types":{},"version":"0.22.3"}

However,

Steps to reproduce:

  1. Spin up a container of either Arch Linux or NixOS
  2. Install gcc
  3. Install futhark, either from Nixpkgs, the nightly tarball, or compiling from source (all three don't work).
  4. Run the above commands

NixOS container command that reproduces the issue: sudo nixos-container create test --config 'environment.systemPackages = with pkgs; [ futhark gcc ];'

Sequence of Arch Linux commands to reproduce the issue in a fresh container using docker run -it archlinux:latest:

pacman -Syu
pacman -S gcc
curl 'https://futhark-lang.org/releases/futhark-nightly-linux-x86_64.tar.xz' > futhark.tar.xz
tar xf futhark.tar.xz
cd futhark-nightly-linux-x86_64/bin/
echo 'def main (x: i32): i32 = x + 1' > test.futhark
./futhark c test.futhark
./test

There's probably some step I missed or a mistake I've made somewhere, but I can't find anything in the documentation about extra dependencies, and the Nix version of Futhark should contain all the dependencies, so I'm not exactly sure what's going wrong here.

virchau13 commented 1 year ago

It seems that Futhark isn't detecting any functions. Tracing funs in the following line of code yields []:

https://github.com/diku-dk/futhark/blob/6350b579add2309c5fce799d4bbd165eef34bde3/src/Futhark/CodeGen/Backends/GenericC.hs#L472

Munksgaard commented 1 year ago

echo 'def main (x: i32): i32 = x + 1' > test.futhark futhark c test.futhark ./test

Futhark uses the .fut extension. It should work if you do

echo 'def main (x: i32): i32 = x + 1' > test.fut
futhark c test.fut
./test

(At which point it will wait for input. For instance, type 1 followed by enter Ctrl+D to compute 2.)

Though it's probably not the best UX to just do nothing when a file with the wrong extension is passed.

virchau13 commented 1 year ago

Oh wow, and here I was looking through source code... :)

I must ask though, why does Futhark care about the extension at all? Shouldn't it work with any filename?

athas commented 1 year ago

There are a bunch of places where the extension is automatically added (e.g. when using import), so complete extension-agnosticism is not feasible. It should definitely not just let it pass in silence, though.