6 ms·
A function's true name should be its content hash. (Where that content hash is calculated after canonicalizing all the call-sites in the function into content h
by derefr 12y ago
A function's true name should be its content hash. (Where that content hash is calculated after canonicalizing all the call-sites in the function into content hash refs themselves.) This way:
- functions are versioned by name
- a function will "pull in" its dependencies, transitively, at compile time; a function will never change behaviour just because a dependency has a new version available
- the global database can store all functions ever created, without worrying about anyone stepping on anyone else's toes
- magical zero-install (runtime reference of a function hash that doesn't exist -> the process blocks while it gets downloaded from the database.) This is safe: presuming a currently-accepted cryptographic hash, if you ask for a function with hash X, you'll be running known code.
- you can still build "curation" schemes on top of this, with author versioning, using basically Freenet's Signed Subspace Key approach (sort of equivalent to a checkout of a git repo). The module author publishes a signed function which returns a function when passed an identifier (this is your "module"). Later, they publish a new function that maps identifiers to other functions. The whole stdlib could live in the DB and be dereferenced into cache on first run from a burned-in module-function ref.
- function unloading can be done automatically when nothing has called into (or is running in the context of) a function for a while. Basically, garbage collection.
- you can still do late binding if you want. In Erlang, "remote" (fully-qualified) calls don't usually mean to switch semantics on version change; they just get conflated with fully-qualified self-calls, which are explicitly for that. In a flat function namespace, you'd probably have to make late-binding explicit for the compiler, since it would never be assumed otherwise. E.g. you'd call apply() with a function identifier, which would kick in the function metadata resolution mechanism (now normally just part of the linker) at runtime.
Plug: I am already working on a BEAM-compatible VM with exactly these semantics. (Also: 1. a container-like concept of security domains, allowing for multiple "virtual nodes" to share the same VM schedulers while keeping isolated heaps, atom tables, etc. [E.g. you set up a container for a given user's web requests to run under; if they crash the VM, no problem, it was just their virtual VM.] 2. Some logic with code signing such that calling a function written by X, where you haven't explicitly trusted X, sets up a domain for X and runs it in there. 3. Some PNaCl-like tricks where object files are simply code-signed binary ASTs, and final compilation happens at load-time. But the cached compiled artifact can sit in the global database and can be checked by the compiler, and reused, as an optimization of actually doing compilation. Etc.) If you want to know more, please send me an email (levi@leviaul.com).
- seiji 12y agoI wrote a prototype programming language + distributed function storage system like this a few years ago. I stopped when the madness became unbearable. Exhibit A: https://github.com/mattsta/zlang/blob/master/priv/site_macros.lfe#L123-L157 https://github.com/mattsta/zlang/blob/master/priv/site_macro... Exhibit B: https://github.com/mattsta/zlang/blob/master/examples/editor.zlang#L239-L246 https://github.com/mattsta/zlang/blob/master/examples/editor... (unbearable from an "i created a new unmaintainable language pov, nothing bad about the distributed function storage feature.)
- agumonkey 12y agothe hash must account for bound variables so that fun add(x, y) { return x + y } is the same as fun add(a, b) { return a + b }. Beta-reduction independance.
- derefr 12y agoRight. Identifier names effectively become metadata; the AST would look like numbered SSA references (as in LLVM, which does a similar transformation, to allow the optimizer pass to just pattern-match known AST "signatures" and rewrite them.)
- pjc50 12y agoa function will never change behaviour just because a dependency has a new version available Presumably this only works for pure-functional languages?
- endergen 12y agoI'm assuming his suggestion is no updates ever unless you update your dependencies version. many module systems like say npm has a culture of using fuzzy matching which means when you do an npm install again you can easily pull in new versions of libraries that have had upgrades since you last did npm install. I'm of a fan of strict dependencies but some people prefer to make it easier to stay to the latest minor patch or other logical upgrade patterns.
- endergen 12y ago