titan-lang / titan

The Titan programming language
http://titan-lang.org
MIT License
406 stars 13 forks source link

Mix static and dynamic loading, make static default when source is present #237

Closed mascarenhas closed 6 years ago

mascarenhas commented 6 years ago

This PR makes static linking the default when source code for an imported module is present, but still allows dynamic linking if there is no source code but a shared library for the imported module.

The titanc compiler now generates either one shared library for each module passed in its command line if there is no main function present. Each of these shared libraries statically embed all their dependencies where source code was found.

If there is a main function in any of the modules passed to titanc a single executable will be generated, statically embedding all of the modules passed in the command line plus their dependencies where source code was present.

codecov-io commented 6 years ago

Codecov Report

Merging #237 into master will decrease coverage by 0.45%. The diff coverage is 57.97%.

Impacted Files Coverage Δ
titan-compiler/coder.lua 95.48% <100%> (-0.89%) :arrow_down:
titan-compiler/driver.lua 79.23% <54.68%> (-0.29%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 8d3b095...5702e91. Read the comment docs.

hishamhm commented 6 years ago

statically embedding all of the modules passed in the command line plus their dependencies where source code was present.

This is, to use a current buzzword, very "opinionated" behavior. I don't mind it myself, currently (would need to see with actual use how good/annoying this is — but I like the principle of picking an option and trying to do the helpful thing by default), but theoretically speaking, how hard would it be to make it disable-able via a flag?

mascarenhas commented 6 years ago

how hard would it be to make it disable-able via a flag?

Very easy, we just need to tweak the default compile-time module loader to respect these flags. The hard work of mixing static and dynamic imports is already being done by the code generator, where you now pass the set of dependencies that are statically compiled instead of blanket flag that either disables dynamic loading or makes everything dynamically loaded.

mascarenhas commented 6 years ago

To be honest l, I would not mind if the policy for titanc would be no dynamic loading of Titan modules from Titan code, while leaving the plumbing for dynamic loading in place, along with the tests for that. It will probably be a while until someone requests a way to distribute binary-only modules.