Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow arbitrary NIF names (e.g. those ending with ! or ?) #505

Closed

Conversation

KoviRobi
Copy link

@KoviRobi KoviRobi commented Dec 9, 2022

There is as far as I know, no reason for the erlang function name to be an identifier.

To use, do

\#[nif(name = "foo!")]
fn foo_bang(...) -> ... {
    ...
}

To use, do

```rust
\#[nif(name = "foo!")]
fn foo_bang(...) -> ... {
    ...
}
```
@KoviRobi KoviRobi force-pushed the allow-arbitrary-nif-names branch from 4830c70 to b349b4d Compare December 10, 2022 01:08
@evnu evnu requested a review from a team December 11, 2022 20:58
@KoviRobi
Copy link
Author

KoviRobi commented Dec 12, 2022

EDIT: Moved to comment above

From https://www.erlang.org/doc/apps/stdlib/unicode_usage.html

> Erlang drivers and NIF-shared objects still cannot be named with names
> containing code points > 127. This limitation will be removed in a
> future release. However, Erlang modules can, but it is definitely not a
> good idea and is still considered experimental.

While I believe this refers to file-names this also seems to apply to
function names, otherwise you get:

    {:error, {:bad_lib, [70, 117, 110, 99, 116, 105, ...]}}

With this, if you try to do it, you get at compile-time the following
error:

    ❯ mix compile
    Compiling 1 file (.ex)
    Compiling crate nif in debug mode (native/nif)
       Compiling nif v0.1.0 (/home/rmk/programming/rust/rustler_raise_error/native/nif)
    error: custom attribute panicked
      --> src/lib.rs:76:1
       |
    76 | #[nif(name = "🧀")]
       | ^^^^^^^^^^^^^^^^^^^
       |
       = help: message: NIF names need to be Latin-1 encoded

    error[E0433]: failed to resolve: use of undeclared crate or module `cheese`
      --> src/lib.rs:90:9
       |
    90 |         cheese
       |         ^^^^^^ use of undeclared crate or module `cheese`

    For more information about this error, try `rustc --explain E0433`.
    error: could not compile `nif` due to 2 previous errors

    == Compilation error in file lib/nif.ex ==
    ** (RuntimeError) Rust NIF compile error (rustc exit code 101)
        (rustler 0.26.0) lib/rustler/compiler.ex:41: Rustler.Compiler.compile_crate/2
        lib/nif.ex:2: (module)
@KoviRobi
Copy link
Author

I'm not sure I understand the CI job failures -- they only say "this job failed" with no log/trace or anything

@evnu
Copy link
Member

evnu commented Feb 14, 2024

@filmor do we still consider this PR?

@filmor
Copy link
Member

filmor commented Feb 14, 2024

I included the relevant portion (not forcing identifier rules and checking for ASCII-ness) in #592 (will move that part to a separate PR once done). This one can be closed.

@KoviRobi I'll refer to you in the new PR, thank you for your contribution :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants