quil-lang / quilc

The optimizing Quil compiler.
Apache License 2.0
460 stars 72 forks source link

Consider splitting frontend code into its own subsystem #758

Open braised-babbage opened 3 years ago

braised-babbage commented 3 years ago

cl-quil currently contains a mix of stuff, ranging from AST definitions to very specific functionality which may only be of interest to the compiler proper. This limits our ability to have tools which i) depend on basic aspects of the quil language, ii) are used in the bowels of the compiler, and iii) are not under the management of the cl-quil system.

Concretely, I'm thinking of the qvm here. We currently don't use it in the compiler, but we might want to, as mentioned by ECP. And contrary to my initial intuition, we do see some performance improvements, at least on tests (e.g. if we use the unitary-qvm as the implementation of make-matrix-from-quil, which gets called a lot in the compressor, then on my machine the TEST-LOGICAL-MATRIX-SANITY test run time goes from about 30 seconds to about 6).

It would be possible to factor out some of the cl-quil code into something like a cl-quil/frontend. This would contain AST & parser stuff, the gate protocol, and the clifford & analysis modules. More or less whatever qvm uses. There'd also be a cl-quil.frontend package that the main cl-quil package uses, and e.g. the qvm or other such tools could use just that.