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 the compiler to be called from any directory #16

Closed
3 tasks
hugomg opened this issue Oct 2, 2018 · 9 comments · Fixed by #534
Closed
3 tasks

Allow the compiler to be called from any directory #16

hugomg opened this issue Oct 2, 2018 · 9 comments · Fixed by #534
Labels
enhancement New feature or request technical-debt

Comments

@hugomg
Copy link
Member

hugomg commented Oct 2, 2018

Currently, pallenec only works if the current directory is the root project directory. If we try to call it elsewhere it fails for the following reasons:

  • The C compiler can't find the headers from our bundled version of Lua
  • The require can't find the modules in the titan-compiler subdirectory. (LUA_PATH issue)
  • The C linker (called in c_compiler.lua) cannot find our runtime library.
@hugomg hugomg added the bug Something isn't working label Oct 2, 2018
@hugomg hugomg added enhancement New feature or request and removed bug Something isn't working labels Oct 2, 2018
@gligneul
Copy link
Member

gligneul commented Oct 8, 2018

Remainder: update readme when done.

@gligneul
Copy link
Member

I don't this this is an issue for the dev version.
This issue could be solved if install Pallene properly with Luarocks.

@hugomg
Copy link
Member Author

hugomg commented Jun 21, 2019

Even for the dev version, being effectively restricted to only running code inside the root directory is a big limitation. It is certainly affecting how we write our benchmark and test scripts. (See #17)

I agree that properly installing pallene via luarocks is the way to go. In fact, figuring out how to do so is exactly why I opened this issue in the first place :)

@hugomg
Copy link
Member Author

hugomg commented Oct 6, 2019

I've been thinking about this problem and I think the tricky bit is going to be the Pallene runtime library. Currently we have a custom Lua interpreter and a runtime library (pallenelib). In theory we could merge one of them into the other but in any case we will need a runtime library component and that brings two problems

  1. The runtime library is not a Lua module that you load with require, and Luarocks is not designed to install something like that.
  2. We currently statically link the pallene library but if we would like the option of dynamically linking it then it would need to be installed to /usr/local/lib instead of the Luarocks installation prefix. Linux doesn't like when your shared library is hidden away inside the Luarocks directory hierarchy.

So what do you think about having a separate installer for the Pallene compiler and for the Pallene runtime library?

The Pallene compiler can continue as a Luarocks module. Luarocks knows how to install it and also takes care of installing our Lua dependencies.

For the Pallene runtime library, we would take our existing makefile and add a make install rule that would install the library and the pallene_core.h header file to the standard system directories. We should also try to configure things so that the local directory takes precedence during development, to make the version we are currently working on take precedence over the installed version.

@hugomg
Copy link
Member Author

hugomg commented Oct 8, 2019

To solve this issue for good I think we will need to clean up the situation with the pallene runtime library and the custom Lua interpreter.

I investigated what private Lua functions we are currently using. For the record, this is the list that I got after running nm on a large Pallene module packed with as many language features as I could:

  • luaC_step
  • luaD_growstack
  • luaH_getn
  • luaH_new
  • luaH_resizearray
  • luaL_error
  • luaL_where
  • luaS_createlngstrobj
  • luaS_newlstr
  • luaS_newudata
  • luaT_typenames

@gligneul
Copy link
Member

gligneul commented Oct 9, 2019

The runtime library is not a Lua module that you load with require, and Luarocks is not designed to install something like that.

The runtime library could be a .so file and we link against the modules generated by Pallene compiler. We could also add a dummy luaopen function to the runtime library so we can use require to load it, but that might be ugly.

So what do you think about having a separate installer for the Pallene compiler and for the Pallene runtime library?

This seems strange. Can't we handle everything inside Luarocks? Also, I'd rather not mix compilation and installation in the same makefile. Compilation is usually generic and unix-portable; installation isn't.

To solve this issue for good I think we will need to clean up the situation with the pallene runtime library and the custom Lua interpreter.

We could merge both. If I recall correctly, this is what Titan is doing. I don't think that we will have any issues. If we choose this path, I think it is important to automate the process of extracting the functions that we need from the Lua interpreter and bundling them to our runtime library.

@hugomg
Copy link
Member Author

hugomg commented Oct 9, 2019

We could also add a dummy luaopen function to the runtime library so we can use require to load it, but that might be ugly.

We would need to use package.loadlib("*") instead of require. By default, require calls dlopen with a flag that hides the non-luaopen symbols in the shared library.

To do that we would also need to pass the full path to the lua library. I think you find that like this but it needs the debug library and would also bake the assumption that Pallene is installed via Luarocks (which would be a problem if someone wanted to package it for a Linux distro for example).

This seems strange. Can't we handle everything inside Luarocks?

Luarocks is geared towards installing Lua modules and the pallenelib is not a Lua module. I think it can be done if you really want to but it is a bit unwieldy.

Annyway, I'm not sure that installing pallene lib separately would be that bad. There is the precedent of those luarocks modules that are a wrapper to some other system library (ex.: expat, sqlite, etc). Usually you need to install those libraries through your system's package manager.

Compilation is usually generic and unix-portable; installation isn't.

I think that can be a good thing. I would rather have the system-specific installation directory stuff in the makefile than inside c_compiler.lua or our generated luaopen functions.

For what it is worth, the plan would be to tell the makefile to install to /usr/local hand have it be configurable with DESTDIR and the other usual make install environment variables. It would be fairly unix portable. (Windows is another story, of course).

We could merge both. If I recall correctly, this is what Titan is doing

IIRC Titan always statically links a copy of liblua into the Titan-generated binaries.

There is as also some sr.lua stuff to be able to generate a self-sufficient executable file instead of an ".so" library. But I don't understand that part very well.

@gligneul
Copy link
Member

gligneul commented Oct 9, 2019

To do that we would also need to pass the full path to the lua library. I think you find that like this but it needs the debug library and would also bake the assumption that Pallene is installed via Luarocks (which would be a problem if someone wanted to package it for a Linux distro for example).

We could use package.searchpath to find the library, no?

> package.searchpath('lfs', package.cpath)
/Users/gligneul/.luarocks/lib/lua/5.3/lfs.so

Annyway, I'm not sure that installing pallene lib separately would be that bad. There is the precedent of those luarocks modules that are a wrapper to some other system library (ex.: expat, sqlite, etc). Usually you need to install those libraries through your system's package manager.

I'd rather hide this from the final user. Moreover, our runtime lib isn't quite a system library, it is very specific to our compiler.

IIRC Titan always statically links a copy of liblua into the Titan-generated binaries.

Yes, but I meant that Titan also statically links the Lua functions it needs against the generated module. We could dynamically link everything we need (runtime library and Lua functions).

@hugomg
Copy link
Member Author

hugomg commented Oct 9, 2019

I hadn't thought about the package.searchpath. That could certainly help.

We'd still need to solve the issue of the internal Lua header files but that is easier than the dynamic library problem.

hugomg added a commit that referenced this issue Jul 22, 2021
This set of commits gets rid of the separate pallenelib library. This is part of the ongoing effort
to simplify the build and installation process for Pallene (see #16, #153). The pallene_core files
are now going to be part of our the custom installation of Lua.

Unfortunately, for some reason it is not working. When I compile the custom Lua, the
`pallene_symbols` are not being exported by the custom Lua executable. We'll need to figure out what
is the problem.

TODO:
- [] Find out why the symbols are not being exported
- [] Fix compilation warnings that appeared because of -Wextra
- [] Update the ".patch" file we use when updating to a new Lua version
- [] Delete the "runtime" folder, and
- [] Update the installation instructions in the README.
hugomg added a commit that referenced this issue Jul 22, 2021
This set of commits gets rid of the separate pallenelib library. This is part of the ongoing effort
to simplify the build and installation process for Pallene (see #16, #153). The pallene_core files
are now going to be part of our the custom installation of Lua.

Unfortunately, for some reason it is not working. When I compile the custom Lua, the
`pallene_symbols` are not being exported by the custom Lua executable. We'll need to figure out what
is the problem.

TODO:
- [] Find out why the symbols are not being exported
- [] Fix compilation warnings that appeared because of -Wextra
- [] Update the ".patch" file we use when updating to a new Lua version
- [] Delete the "runtime" folder, and
- [] Update the installation instructions in the README.
hugomg added a commit that referenced this issue Jul 25, 2021
This set of commits gets rid of the separate pallenelib library. This is part of the ongoing effort
to simplify the build and installation process for Pallene (see #16, #153). The pallene_core files
are now going to be part of our the custom installation of Lua.

Unfortunately, for some reason it is not working. When I compile the custom Lua, the
`pallene_symbols` are not being exported by the custom Lua executable. We'll need to figure out what
is the problem.

TODO:
- [] Find out why the symbols are not being exported
- [] Fix compilation warnings that appeared because of -Wextra
- [] Update the ".patch" file we use when updating to a new Lua version
- [] Delete the "runtime" folder, and
- [] Update the installation instructions in the README.
hugomg added a commit that referenced this issue May 13, 2022
Exciting news! This commit cleans up the way we install Pallene and
resolves several long-standing issues:

* Closes #16
* Closes #18
* Closes #153

Now Pallene can be installed like a regular Luarocks package, using
`luarocks make`. To achieve this I did two things: get rid of #include
directives in the generated C code, and get rid of the custom Lua
interpreter.

Include directives were annoying because they meant you had to pass the
right "-I" flags when you compiled the generated C code. Also, we never
figured out a good place to install the headers in the first place,
which was one of the reasons for #16... My approach to solve this
problem was to get rid of the #include directives completely, fully
expanding the header files. This required introducing a code generation
step to build the Pallene library.

The main thing that motivated me to get rid of the custom Lua is because
a custom Lua also implies a custom Luarocks, and I wanted to make things
as easy as possible to install via Luarocks. The catch, however, is that
we have a requirement saying that Lua needs to be exactly 5.4.4. This is
OK if you're using Fedora, which always has the latest Lua, but on most
other distros you're might need to install Lua from source...

To make things less magical and more compatible with Luarocks, we
implemented the Pallene runtime library as a struct of function
pointers, stored inside an userdata and installed in an extention module
that can be required. This design, without "extern" functions,
completely bypasses the C linker. We no longer need to worry about that
passing the right linker flags to the compiler, and we can get rid of
the "linker hack" that we had added to lapi.c. All in all, the C files
we generate are now a bit more verbose, but I think it is for the
better.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request technical-debt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants