futhark icon indicating copy to clipboard operation
futhark copied to clipboard

Cannot capitalize symbols using `rename` and `renameCallback`.

Open nayr7 opened this issue 2 years ago • 1 comments

Hello! This is a very nice tool for C interop, unfortunately while wrapping libvips, I tried to make futhark generate nep1 compliant symbols using rename and renameCallback but capitalizing anything but the first word of a symbol is ineffective.

Example:

  • rename "VipsPrecision", "PrecisionTest" generates Precisiontest
  • rename "VipsPrecision", "precisiontest" generates precisiontest

Setup: Distro: Ubuntu 23.04 Nim Version: 1.6.10 Futhark Version: 0.9.1

Code Prototype:

when defined(useFuthark):
  import futhark
  importc:
    outputPath currentSourcePath.parentDir / "private/generated.nim"

    sysPath "/usr/lib/clang/15/include"
    sysPath "/usr/include/glib-2.0"
    sysPath "/usr/lib/x86_64-linux-gnu/glib-2.0/include"
    path "/usr/local/include/vips"

    rename "VipsPrecision", "PrecisionTest"                           # does not work
    rename "vips_object_get_type", "vipsObjectGetType1" # does not work
    "vips.h"

else:
  include private/generated

Ideally we should be able to tell futhark to generate nep1 compliant symbols for us through a define option, but this is merely a convenience and we should be able to use rename and renameCallback for this, if only they did work ...

nayr7 avatar Apr 25 '23 21:04 nayr7

The reason why this doesn't work is that Futhark internally uses these identifiers in a hash table. So the representation that is kept is the most cleaned version (capital letters kept, all underscores removed, and all other letters made lowercase). Since Nim is style agnostic this shouldn't make a difference to how you can use the code, but it can make it a bit more confusing to read the documentation or code generated.

In order to fix this I think it would be best to create a table of identifiers to "pretty names" and then as the code is about to be written substitute the names for these ones. This should give the wanted effect at the lowest overhead.

PMunch avatar Jun 13 '23 09:06 PMunch

This should be fixed now, and since this is mostly a duplicate of #87 I'll close this now. Please try it out and see if it works!

PMunch avatar Jun 30 '24 19:06 PMunch