11 ms·
Turing Incomplete Languages
- baq 6y agothere are a few languages guaranteed to terminate: - JSON - YAML - TOML - all dialects of INI - CSV i don't see these languages getting recursion added anytime soon, but you might want to program in them, so you add recursion with jinja or whatever. if you want a configuration language that is guaranteed to terminate, you may want to end up with a turing-incomplete language: https://dhall-lang.org/ https://dhall-lang.org/
- phoe-krk 6y agoNone of those listed are programming languages. They are data formats. They perform no computation. Calling them Turing-complete or Turing-incomplete is meaningless.
- baq 6y agoyes, hence the jinja2 comment.
- btilly 6y agoThey are all data formats that are used for configuration. Configuration systems tend to sprout macro systems of various kinds. So you're writing in JSON, but it is fed into a macro system and voila! You have a programming language. The progression from data format to custom programming language is surprisingly short. And sometimes the transition is unexpected. For example https://beza1e1.tuxen.de/articles/accidentally_turing_complete.html https://beza1e1.tuxen.de/articles/accidentally_turing_comple... includes as an example of a Turing complete language, HTML+CSS!
- phoe-krk 6y agoI'm aware of the distinction. Data syntax from data formats is sometimes used directly for programming languages, too; the path from S-expressions to Lisp is very short, too, and I write that as a lisper. A very relevant recent article is https://news.ycombinator.com/item?id=24892297 https://news.ycombinator.com/item?id=24892297 The point is that when we are talking about "JSON, but with macros" we already have a programming language in play, not merely just a data format. This is because macros are functions from text into text, or from data into data, and these functions require to be written in some sort of actual programming language. At this point the data format becomes an extension of this programming language, either some sort of input for functions in this programming language or another means of expressiong this language's syntax.
- a1369209993 6y agoActually they do perform (drastically cutailed) computation; for example INI performs computations of the form: [foo] # section = "foo" bar=baz # table[section]["bar"] = "baz" Similarly, wc is a programming language with ~4 operations: 'a' # inc byte counter, add word flag to word counter, clear word flag # any other non-space/newline is the same as 'a' ' ' # inc byte counter, mark word flag \n # inc byte counter, mark word flag, inc line counter EOF # (implied) print counters That set of operations is of extremely limited usefulness, but that's more or less true of any non-turing-complete language (and many that are turing-complete, even).
- deleted 6y ago[deleted]
- goto11 6y agoINI does not perform any computations, it is a file format without any execution model defined. What you describe is a possible execution model by an INI parser, but an INI parser is not required to do that.
- baq 6y agothis point is dangerous - the same logic can be applied to C code or any other programming language. source files only encode the AST, after all. it's the compiler/interpreter doing the actual work. it just so happens that the INI interpreter doesn't usually do much else than load the list of key value maps - and that's the problem - people extend INI source files in a different language which can do more.
- goto11 6y agoNo, a programming language like C have both a syntax and an execution model. In Turing-machine terminology, it has a set of symbols and rules for processing the symbols. This is why you can reason about things like the halting-problem. If you only have a set of symbols but no rules for processing the symbols, you don't have a machine, and you cant meaningfully talk about "termination". INI does not have a defined execution model, so it is not a machine the way C is. A particular implementation could read the data into key-value maps but it is not required to. E.g. it could just search through the file for a specific key. Or it could do nothing.
- samatman 6y agoThis is a dangerous misconception, which those of us in langsec have worked hard to dispel. Data is not inert. Trivially, yes, insofar as a .json file just sits there until you do something with it – but this is true of .js as well. Data in use is active, it is an input to your program which drives computation. This is the same as inputs which are Turing complete, just restricted in various ways. Being complacent about this fact is a great way to receive a malicious payload, which puts your program into an unexpected and exploitable state.
- phoe-krk 6y agoI agree with your statement even though it seems to completely miss the original point that I have made. Yes, you are correct, if you are running a suid binary and you specify / as a temporary directory instead of the default that looks like /tmp/foo-12345abcd/ in its configuration file, then the script may invalidly perform cleanup by deleting everything on the filesystem. But this does not suddenly mean that Unix pathnames are Turing-complete or Turing-incomplete or that Turing-completeness somehow applies to strings as data formats. It's not the path string that does the deletion. It's not the path string that was written in a programming language that performs the unlink() syscall. It's not the data itself that causes people to curse loudly. Sure, secure your data, validate your inputs, ensure that your code cannot be misused, just don't say that data, even when it is in use, performs some computation on its own.
- samatman 6y agoI'm getting the sense that you're not quite picking up what I'm laying down here. Code also performs no computation on its own. A function with no parameters is just a complex constant. Computation is always the union of code and data. People can and do embed full programs in 'inert' formats like JSON, and write an interpreter for that program. This is a bad idea, and the notion that JSON is "just data" is exactly what fools people into writing such inner languages (implementing, of course, half of Common Lisp). Reducing the motivating examples (JSON, TOML, etc.) to path strings is a weak argument, because path strings are not strong enough to provide for such an inner platform, while the data formats under discussion are, it happens all the time. The very fact that I can point out that a path string is capable of driving less complex calculations than YAML is, points out that there is in fact a continuum from pure code to 'mere data' (a float, let's say), which undermines the argument that there is some strong distinction to be made here.
- goto11 6y agoYou can't say they are guaranteed to terminate since they are not executable languages at all. Of course a language could be implemented with JSON syntax, but whether it was guaranteed to terminate would then depend on the language semantics, not the syntax.
- vbrandl 6y agoIdris is an other example for a programming language that always terminates. For that matter any total functional programming language does and is therefore turing incomplete.
- dddbbb 6y agoTotality is optional in Idris. Also, the big dependently-typed languages like Coq, Agda, Idris all support corecursion, so they can run programs infinitely provided the program does something productive.
- ignoranceprior 6y agoDepending on the parser, YAML can be used for execution of arbirtrary code: https://alexwlchan.net/2019/12/yaml-impossible/ https://alexwlchan.net/2019/12/yaml-impossible/
- pron 6y ago> Most languages ... do not gain any benefit from this restriction. One exception is in domains where you are proving properties or doing analysis Not even then. In some cases you need to forbid recursion in the proof language to make it consistent if it is based on the lambda calculus, but making the object (programming) language non-Turing complete does not make analysis/proof easier, unless you consider going from potentially infinite difficulty to unbounded difficulty "easier." The complexity of analysing a program written in a language with only if/else, no recursion, not even bounded loops, and just boolean variables and no arrays is already PSPACE-complete in the size of the program. Some people think that program analysis is hard because of the halting theorem (or its corollary, Rice's theorem), but that's just the simple story told to first-year students. A generalisation of those theorems (sometimes called "bounded halting", but it's part of one of the most theorems in computer science, the time-hierarchy theorem) says, roughly, that, in the worst case, you cannot determine in under N steps whether a program will halt (/emit some output/reach a certain state) on input X within N steps. That's the "master" theorem that determines the difficulty of program analysis/proof, and not only does it hold for some of the more powerful non-Turing complete languages, it even holds for the simplest computational models: finite state machines. To give an intuition as to why termination cannot possibly make analysing programs or proving interesting properties about them, consider that we can take any program, in any language, and mechanically translate it into such a termination language (even better: into a finite state machine!) while maintaining its behaviour for all practical intents and purposes: We add a decrementing counter, initialised to, say, 2^1000, to all loops/recursive calls, and terminate the program when it reaches zero (possibly changing types to allow that, but that is easy to do even mechanically). This program will behave just like the original at least for the duration of the universe, so we don't care about any differences that could arise later. In other words, if termination (or even "finite-statedness") alone made a difference to program analysis, we can already assume, without loss of (practical) generality, that all programs are like that already. On the other hands, many specific instances of programs in either terminating or Turing-complete languages are relatively easy to analyse.
- Jhsto 6y agoAny paper recommendations on the bounded halting or the topic in general?
- 7373737373 6y ago> Resource bounded languages such as Hume, which allow better analysis and implementation techniques by restricting how expressive the language is. Hume seems to use a finite state machine and recursive functions as its "substrate": https://www.macs.hw.ac.uk/~greg/hume/ https://www.macs.hw.ac.uk/~greg/hume/ There's a more intuitive way: In a virtual machine interpreter loop, increase a value (commonly called "gas") at every instruction step (or each block of instructions). Different instructions can have different costs. The Ethereum Virtual Machine (EVM) uses this for example: https://blockgeeks.com/guides/ethereum-gas/ https://blockgeeks.com/guides/ethereum-gas/ Stackless Python as well: https://stackless.readthedocs.io/en/latest/library/stackless/pickling.html https://stackless.readthedocs.io/en/latest/library/stackless... This can even work recursively: https://esolangs.org/wiki/RarVM https://esolangs.org/wiki/RarVM
- hinkley 6y agoWe need a moniker for Turing Incomplete that's easier to explain. I'd really like to see this become more of a thing. When groups organize, you can lean on their expertise and expenditure of effort to make your point for you rather than having to fight on your own the whole time. I'm trying to put together a community wiki for a non-technical group (with ideas of expanding it out to others should I succeed) and every time I dig back into it I'm pretty sure I want a markdown format, and any fancy layout is up to me to sort out. But most markdown engines allow embedded HTML. Which is great when all content is authored by the maintainers, not so great when one tech-savvy troublemaker misuses it to put turing-complete content into the page. I'm thinking of switching implementation languages to Elixir, and the Elixir Markdown implementations all seem to assume inline HTML is a feature you wouldn't want to toggle. I am already biting off too much, I don't want to throw a parser into that too.
- pmiller2 6y agoEh, I dunno. "Turing complete" is a pretty easy concept to understand: such a language is capable of simulating a universal Turing machine. "Turing incomplete" could just be "not Turing complete." It's pretty clear that this is a well-defined definition, because every computer language either is, or is not Turing complete.
- hinkley 6y agoYou are living in a bubble. The people who make budgetary decisions are not in this bubble, which is a big part of why we keep getting overruled on important things. We can either go on acting surprised, or we can figure out how to do the work of communicating. We have decades of evidence that the rest of the world really doesn't give a damn, and are willing to pay a lot of money to continue not giving a damn. Turing complete sounds like something people want to have. Why are you the "good guy" for trying to make something incomplete? Wouldn't it be more desirable if we completed it?
- pmiller2 6y agoWell, then, that's where you explain the principle of least privilege. Besides, why are you even using terms like "Turing complete" with people who don't have a CS or SWE background, anyway?
- tutfbhuf 6y agoOne important example is eBPF. I think we will see many interesting turning incomplete eBPF kernel space programs in the future.
- comex 6y agoIn eBPF's case, at least the verifier puts a static cap on the total number of instructions that can be executed when invoking an eBPF hook – a reasonable cap, not "this will terminate some time after the heat death of the universe". This means you can be sure your eBPF hook will always run to completion in practice, as opposed to timing out or wedging the system indefinitely. That's a real benefit, but it requires stricter limitations than you see in "Turing-incomplete because we can" languages. This limitation also allows the verifier to be simpler, while still allowing the program to be JITted to high-performance native code, that is guaranteed safe without unnecessary bounds checks. That simplicity is a second benefit, albeit one for kernel developers rather than eBPF-program developers. (You could say the performance benefits eBPF-program developers, but more complex JIT designs can achieve comparable performance without the limitations.) In contrast, "Turing-incomplete because we can" languages are typically high-level interpreted languages: they're not particularly fast to start with, and they wouldn't get any faster if the restrictions on recursion were lifted. Despite the two aforementioned benefits, I believe that eBPF's guaranteed termination is somewhat overrated; I think it could benefit from a mode that allows arbitrary loops, even if that would require moving some compile-time checks to runtime.
- rstuart4133 6y agoAnother example is bitcoin validation signatures which are actually computer programs.
- heynk 6y ago(Shameless plug, I work at Blockstack) Blockstack is working on a new version of our blockchain with smart contracting capabilities. We've created a new language, called Clarity, for smart contract development on our platform. It's lisp-based and is _not_ Turing complete. We believe that decidability is quite important for smart contracts. Algorand has joined our efforts, and they will support Clarity on their blockchain. I am not involved with the development of Clarity, but I really enjoy writing smart contracts with it! https://clarity-lang.org https://clarity-lang.org Web-based REPL: https://clarity.tools/ https://clarity.tools/
- derriz 6y agoTuring incomplete languages are not necessarily niche or a pita to use. For example SQL (before version 3) had no recursion yet was very widely used. Even today, I'd guess 99% of written SQL does not use recursive CTEs.
- munificent 6y agoThe fun follow-up question is whether we should extend this observation to static type systems too. Should we just accept that those should be Turing-complete too?
- deleted 6y ago[deleted]
- dwohnitmok 6y agoMy personal conclusion is a need for "escape hatches" in any language with strong constraints rather than an indictment of Turin-incompleteness in general. The usual criticism that is leveled at Turing-incomplete languages is "well you've only changed the problem from taking an infinite time to taking more time than the heat death of the universe which really isn't that much better," but that's completely ignoring the ergonomics of how this actually plays out in real-life coding. In real-life coding, the choice is almost never between "does not terminate" and "heat death of the universe." When we write buggy, non-terminating code, the fix is usually a small change that takes it from "does not terminate" to "terminates in a reasonable amount of time." The fix usually does not take it to "indistinguishable from non-termination." This might be forgetting a base case in a recursive definition or getting a loop termination condition wrong. More insidiously this can happen when termination conditions are based off of non-local things and therefore depend on assumptions that "far away" from the original code. The point of Turing-incomplete languages is to go after those use cases, where the function would otherwise complete in a reasonable amount of time, save for one small little issue. What the article is pointing out is that in pursuit of that dream, the language can be overly restrictive to the point that people are forced to write "heat death"-style functions to get around its restrictions. This is an important distinction! People aren't accidentally writing functions that take insane amounts of time to complete in Turing-incomplete languages, but are rather doing so intentionally because that's the only way they can get their desired functionality. This is why the analogy of "non-termination" to "termination after the heat death of the universe" doesn't work. The former occurs when people don't realize that they've done that. The latter is a conscious, angry choice by users. That's why I think you need escape hatches to make sure people aren't forced to abuse the language when its restrictions really make a certain task impossible to complete in a reasonable amount of time.
- nextos 6y agoI think it's not just about termination, it's broadly about restricted semantics. If we had a meta-language like Lisp or ML that had very good capabilities to quickly develop DSLs with very clean restricted semantics for every particular component of a big system, and tooling to automate proofs for said restricted semantics, it'd be much easier to prove the validity of any piece of code. The scenario we currently have is quite different, so it requires heroic efforts to get any kind of guarantee on big systems (e.g. the Astree static analyzer or seL4). Citing Alan Perlis: "Beware of the Turing tar pit, where everything is possible but nothing of interest is easy".
- dukoid 6y agoI was hoping for a list of existing turing-incomplete languages... O:) I'd expect that OCL, SQL and GLSL are turing incomplete, is that correct?
- wizzwizz4 6y agoSadly not. SQL (or, at least, T-SQL and Postgres) can implement a cyclic tag system, GLSL can run the Game of Life and OCL supports an ad hoc, bug-ridden, slow implementation of half of Common Lisp.
- deleted 6y ago[deleted]
- skybrian 6y agoTermination is relevant if you never run the program, because the point is to prove that something exists by writing the program. In languages like Agda or Idris, you can prove things exist by compiling the program, not running it. It doesn't matter if it takes a million years to run, so long as you have a guarantee it won't loop forever. For ordinary programs that we run because we want the result, if you want a guarantee that it will finish then you need something like real-time programming, because it's not enough to know that it terminates. You want to know that it will meet a deadline.
- earthboundkid 6y agoI assume this is in reference to https://news.ycombinator.com/item?id=25006619 https://news.ycombinator.com/item?id=25006619?
- ceronman 6y agoI think Starlark (formerly known as Skylark) [1] is a practical example of a Turing Incomplete language. As far as I know, this language doesn't allow recursion or even while loops. Only Python like for loops over bounded collections are allowed. The language is very similar to Python so it's extremely easy to learn for many people. This language is used as a configuration language for the Bazel build system [2]. Ensuring that scripts will run is a very nice property for configuration languages, giving a nice balance between flexibility and sanity. I would love to have a similar configuration language but based on Clojure instead of Python. [1] https://docs.bazel.build/versions/master/skylark/language.html https://docs.bazel.build/versions/master/skylark/language.ht... [2] https://bazel.build/ https://bazel.build/
- laurentlb 6y agoRegarding Starlark, there's a discussion on this topic: https://github.com/bazelbuild/starlark/issues/97 https://github.com/bazelbuild/starlark/issues/97 (note that Neil, the author of the blog post, commented there too) My experience working on build systems and Bazel is that recursion is rarely useful (and most of the use-cases are for things that should be discouraged). Interestingly, Meson advertizes "non-Turing complete DSL" a feature on their front-page.
- 6gvONxR4sf7o 6y agoI think turing incomplete languages are the future, because every property you care about of a program that you will write is reasonably efficient to reason about. Otherwise your teammates aren't going to be very happy that you're writing it that way. This defines some subset of computable functions that has some real nice properties. Eventually I expect us to gain more and more understanding of where that boundary lies, defining humans-give-a-shit-about-these-programs-space. Over time, I expect our tools will slowly gain the ability to automatically check the things that we care about and restrict us from doing it in ways that get too hairy. I expect that that future is a very long way off.