zeam-vm / pelemay

Pelemay is a native compiler for Elixir, which generates SIMD instructions. It has a plan to generate for GPU code.
Apache License 2.0
186 stars 13 forks source link

For Numexy.add #46

Open zacky1972 opened 5 years ago

zacky1972 commented 5 years ago

Describe the bug When applying Pelemay to Numexy.add, an error occurs.

The code is as follows: https://github.com/zeam-vm/numexy/blob/zacky1972_develop/lib/numexy.ex#L43

To Reproduce Steps to reproduce the behavior:

  1. Use Pelemay in the source code as follows: https://github.com/zeam-vm/numexy/blob/zacky1972_develop/lib/numexy.ex#L43

  2. Run in the command 'mix test'

  3. See error:

$ mix test
==> pelemay
Compiling 8 files (.ex)
Generated pelemay app
==> numexy
Compiling 2 files (.ex)

== Compilation error in file lib/numexy.ex ==
** (FunctionClauseError) no function clause matching in SumMag.optimize_func/2    

    The following arguments were given to SumMag.optimize_func/2:

        # 1
        {:defp, [line: 44], [{:enum_add_sub, [line: 44], [{:list, [line: 44], nil}, {:s, [line: 44], nil}]}, [do: {:|>, [line: 45], [{:list, [line: 45], nil}, {{:., [line: 45], [{:__aliases__, [line: 45], [:Enum]}, :map]}, [line: 45], [{:&, [line: 45], [{:+, [line: 45], [{:&, [line: 45], [1]}, {:s, [line: 45], nil}]}]}]}]}]]}

        # 2
        #Function<0.131710887/1 in Pelemay."MACRO-defpelemay"/2>

    Attempted function clauses (showing 1 out of 1):

        defp optimize_func({:def, meta, [arg_info, exprs]}, optimizer)

    lib/sum_mag.ex:257: SumMag.optimize_func/2
    (elixir) lib/enum.ex:1336: Enum."-map/2-lists^map/1-0-"/2
    lib/sum_mag.ex:253: SumMag.map/2
    expanding macro: Pelemay.defpelemay/1
    lib/numexy.ex:43: Numexy (module)

Expected behavior mix test should be done successfully.

Screenshots None.

Desktop (please complete the following information):

Elixir 1.9.1 (compiled with Erlang/OTP 22)

 - OS (OS name & version, and `uname -a`): 

macOS Mojave 10.14.6

$ uname -a Darwin *** 18.7.0 Darwin Kernel Version 18.7.0: Tue Aug 20 16:57:14 PDT 2019; root:xnu-4903.271.2~2/RELEASE_X86_64 x86_64


 - Clang versions (`clang -v`):

$ clang -v Apple LLVM version 10.0.1 (clang-1001.0.46.4) Target: x86_64-apple-darwin18.7.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin



**Additional context**

Current Pelemay may support not to use it in `defp` nor to use second parameter in NIFs.
hisaway commented 5 years ago

Pelemay transform Enum.map to a native function with one argument. So, it is no works when variables exist in anonymous function.