diff --git a/compiler/compactc.ss b/compiler/compactc.ss index cfd6571c5..dc7f8e461 100755 --- a/compiler/compactc.ss +++ b/compiler/compactc.ss @@ -82,6 +82,13 @@ The following flags, if present, affect the compiler's behavior as follows: --trace-passes causes the compiler to print tracing information that is generally useful only to compiler developers. + + --analyzed-ir causes the compiler to also write compiler/analyzed-ir.sexp + into the target directory: the analyzed program in the compiler's own + intermediate-language vocabulary, with each ledger operation and emit + expanded to its Impact VM instructions. An SDK in any language can + execute circuits from it. The format follows the intermediate language, + so it can change between compiler versions. ")) (usage " ... ") @@ -100,6 +107,7 @@ The following flags, if present, affect the compiler's behavior as follows: [(--compact-path) (string search-list)] [(--trace-search)] [(--trace-passes)] + [(--analyzed-ir)] [(--feature-zkir-v3)]) (string source-pathname) (string target-directory-pathname)) @@ -109,6 +117,7 @@ The following flags, if present, affect the compiler's behavior as follows: [skip-zk ?--skip-zk] [no-communications-commitment ?--no-communications-commitment] [feature-zkir-v3 ?--feature-zkir-v3] + [write-analyzed-ir ?--analyzed-ir] [compact-path (if ?--compact-path (split-search-path search-list) (compact-path))] [trace-search ?--trace-search]) (when source-root (register-source-root! source-root)) diff --git a/compiler/config-params.ss b/compiler/config-params.ss index ecae20589..e5f06812b 100644 --- a/compiler/config-params.ss +++ b/compiler/config-params.ss @@ -41,4 +41,7 @@ ; feature flags (export-parameter feature-zkir-v3 #f) + + ; extra output + (export-parameter write-analyzed-ir #f) ) diff --git a/compiler/langs.ss b/compiler/langs.ss index 86766fefc..47fd3e971 100644 --- a/compiler/langs.ss +++ b/compiler/langs.ss @@ -41,6 +41,7 @@ Lnodisclose unparse-Lnodisclose Lnodisclose-pretty-formats Lnoserialize unparse-Lnoserialize Lnoserialize-pretty-formats Lloweredemit unparse-Lloweredemit Lloweredemit-pretty-formats Lloweredemit-Export-Type-Definition? + Lanalyzed unparse-Lanalyzed Lanalyzed-pretty-formats Ltypescript unparse-Ltypescript Ltypescript-pretty-formats Ltypescript-ADT-Op? Ltypescript-ADT-Runtime-Op? Lposttypescript unparse-Lposttypescript Lposttypescript-pretty-formats Lnoenums unparse-Lnoenums Lnoenums-pretty-formats @@ -500,6 +501,18 @@ (lambda (x p wr) (fprintf p "~a~s.~s" (id-prefix) (id-sym x) (id-uniq x))))) + (define (artifact-sexp? x) + (or (null? x) + (boolean? x) + (number? x) + (symbol? x) + (string? x) + (bytevector? x) + (id? x) + (and (pair? x) + (artifact-sexp? (car x)) + (artifact-sexp? (cdr x))))) + (define-language/pretty Lexpanded (extends Lpreexpand) (terminals (+ (len (len))) @@ -917,6 +930,104 @@ (+ (emit src event-version event-tag len expr vm-code) => (emit event-version event-tag expr)))) + (define-language/pretty Lanalyzed (extends Lloweredemit) + (terminals + (- (boolean (pure-dcl nominal)) + (string (mesg opaque-type file discloses sugar))) + (+ (boolean (pure-dcl nominal exported-flag pure-flag proof-flag)) + (string (mesg opaque-type file discloses sugar compiler-version-value language-version-value runtime-version-value native-function)) + (artifact-sexp (artifact-sexp artifact-sexp*)))) + (Program (p) + (- (program src (contract-type* ...) ((export-name* name*) ...) pelt* ...)) + (+ (analyzed-ir compiler-version-value language-version-value runtime-version-value (artifact-sexp* ...) (type* ...) pelt* ...) => + (analyzed-ir + (compiler-version compiler-version-value) + (language-version language-version-value) + (runtime-version runtime-version-value) + (exports artifact-sexp* ...) + (contract-types type* ...) + pelt* ...))) + (Circuit-Definition (cdefn) + (- (circuit src function-name (arg* ...) type expr)) + (+ (circuit src function-name exported-flag pure-flag proof-flag (arg* ...) type expr) => + (circuit function-name + (exported exported-flag) + (pure pure-flag) + (proof proof-flag) + (arg* ...) + type + expr))) + (Native-Declaration (ndecl) + (- (native src function-name native-entry (arg* ...) type)) + (+ (native src function-name native-function artifact-sexp (type* ...) (arg* ...) type) => + (native function-name + (entry native-function artifact-sexp) + (type-arguments type* ...) + (arg* ...) + type))) + (Public-Ledger-Binding (public-binding) + (- (src ledger-field-name (path-index* ...) type)) + (+ (src ledger-field-name (path-index* ...) exported-flag type) => + (ledger-field-name + (path-index* ...) + (exported exported-flag) + type))) + (Public-Ledger-Array (pl-array) + (- (public-ledger-array pl-array-elt ...)) + (+ (public-ledger-array pl-array-elt ...) => + (public-ledger-array pl-array-elt ...))) + (Tuple-Argument (tuple-arg) + (- (single src expr)) + (+ (single src expr) => (single expr))) + (Map-Argument (map-arg) + (- (expr type type^)) + (+ (expr type type^) => (expr type type^))) + (Function (fun) + (- (fref src function-name)) + (+ (fref src function-name) => (fref function-name))) + (Expression (expr index) + (- (quote src datum) + (var-ref src var-name) + (tuple-slice src type expr kindex len) + (vector-ref src type expr index) + (vector-slice src type expr index len) + (bytes-ref src type expr index) + (bytes-slice src type expr index len) + (< src bits expr1 expr2) + (<= src bits expr1 expr2) + (> src bits expr1 expr2) + (>= src bits expr1 expr2) + (== src type expr1 expr2) + (!= src type expr1 expr2) + (map src len fun map-arg map-arg* ...) + (fold src len fun (expr0 type0) map-arg map-arg* ...) + (emit src event-version event-tag len expr vm-code) + (public-ledger src ledger-field-name (maybe sugar) (path-elt ...) src^ adt-op expr* ...) + (return src expr)) + (+ (quote src datum) => (quote datum) + (var-ref src var-name) => (var-ref var-name) + (tuple-slice src type expr kindex len) => (tuple-slice type expr kindex len) + (vector-ref src type expr index) => (vector-ref type expr index) + (vector-slice src type expr index len) => (vector-slice type expr index len) + (bytes-ref src type expr index) => (bytes-ref type expr index) + (bytes-slice src type expr index len) => (bytes-slice type expr index len) + (< src bits expr1 expr2) => (< bits expr1 expr2) + (<= src bits expr1 expr2) => (<= bits expr1 expr2) + (> src bits expr1 expr2) => (> bits expr1 expr2) + (>= src bits expr1 expr2) => (>= bits expr1 expr2) + (== src type expr1 expr2) => (== type expr1 expr2) + (!= src type expr1 expr2) => (!= type expr1 expr2) + (map src len fun map-arg map-arg* ...) => (map len fun map-arg map-arg* ...) + (fold src len fun (expr0 type0) map-arg map-arg* ...) => + (fold len fun (expr0 type0) map-arg map-arg* ...) + (emit src event-version event-tag len expr (artifact-sexp* ...)) => + (emit event-version event-tag len expr (instructions artifact-sexp* ...)) + (public-ledger src ledger-field-name op-class (path-elt* ...) ledger-op type (artifact-sexp* ...) expr* ...) => + (public-ledger ledger-field-name op-class (path-elt* ...) ledger-op type + (instructions artifact-sexp* ...) + expr* ...) + (return src expr) => (return expr)))) + (define-language/pretty Ltypescript (extends Lloweredemit) (terminals (- (id (name var-name function-name ledger-field-name))) diff --git a/compiler/passes.ss b/compiler/passes.ss index fc6db8081..d4aabd4fe 100644 --- a/compiler/passes.ss +++ b/compiler/passes.ss @@ -33,6 +33,7 @@ (frontend-passes) (analysis-passes) (save-contract-info-passes) + (save-analyzed-ir-passes) (typescript-passes) (circuit-passes) (zkir-passes) @@ -145,6 +146,10 @@ (with-target-ports '((contract-info.json . "compiler/contract-info.json")) (run-passes save-contract-info-passes analyzed-ir proof-circuit-name*)) + (when (write-analyzed-ir) + (with-target-ports + '((analyzed-ir.sexp . "compiler/analyzed-ir.sexp")) + (run-passes save-analyzed-ir-passes analyzed-ir proof-circuit-name*))) (with-target-ports (map (lambda (sym) (cons sym (format "zkir/~a.zkir" sym))) proof-circuit-name*) diff --git a/compiler/save-analyzed-ir-passes.ss b/compiler/save-analyzed-ir-passes.ss new file mode 100644 index 000000000..72fbbcd2e --- /dev/null +++ b/compiler/save-analyzed-ir-passes.ss @@ -0,0 +1,36 @@ +;;; This file is part of Compact. +;;; Copyright (C) 2025 Midnight Foundation +;;; SPDX-License-Identifier: Apache-2.0 +;;; Licensed under the Apache License, Version 2.0 (the "License"); +;;; you may not use this file except in compliance with the License. +;;; You may obtain a copy of the License at +;;; +;;; http://www.apache.org/licenses/LICENSE-2.0 +;;; +;;; Unless required by applicable law or agreed to in writing, software +;;; distributed under the License is distributed on an "AS IS" BASIS, +;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;;; See the License for the specific language governing permissions and +;;; limitations under the License. + +#!chezscheme + +(library (save-analyzed-ir-passes) + (export save-analyzed-ir-passes) + (import (except (chezscheme) errorf) + (utils) + (nanopass) + (langs) + (vm) + (compiler-version) + (language-version) + (runtime-version) + (pass-helpers)) + + (include "save-analyzed-ir-passes/extract-analyzed-ir.ss") + + (include "save-analyzed-ir-passes/save-analyzed-ir.ss") + + (define-passes save-analyzed-ir-passes + (save-analyzed-ir Lloweredemit)) +) diff --git a/compiler/save-analyzed-ir-passes/extract-analyzed-ir.ss b/compiler/save-analyzed-ir-passes/extract-analyzed-ir.ss new file mode 100644 index 000000000..e94d0220d --- /dev/null +++ b/compiler/save-analyzed-ir-passes/extract-analyzed-ir.ss @@ -0,0 +1,184 @@ +;;; This file is part of Compact. +;;; Copyright (C) 2025 Midnight Foundation +;;; SPDX-License-Identifier: Apache-2.0 +;;; Licensed under the Apache License, Version 2.0 (the "License"); +;;; you may not use this file except in compliance with the License. +;;; You may obtain a copy of the License at +;;; +;;; http://www.apache.org/licenses/LICENSE-2.0 +;;; +;;; Unless required by applicable law or agreed to in writing, software +;;; distributed under the License is distributed on an "AS IS" BASIS, +;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;;; See the License for the specific language governing permissions and +;;; limitations under the License. + +#!chezscheme + +(define-pass extract-analyzed-ir : Lloweredemit (ir proof-circuit-name*) -> Lanalyzed () + (definitions + (define (fail what x) (internal-errorf 'save-analyzed-ir "unsupported ~a: ~s" what x)) + + (define (native-type-argument* native-entry arg* type) + (let ([seen (make-hashtable symbol-hash eq?)]) + (fold-right + (lambda (maybe-type-param type acc) + (if (and maybe-type-param (not (hashtable-contains? seen maybe-type-param))) + (begin + (hashtable-set! seen maybe-type-param #t) + (cons (Type type) acc)) + acc)) + '() + (native-entry-maybe-type-param* native-entry) + (append (map (lambda (arg) + (nanopass-case (Lloweredemit Argument) arg + [(,var-name ,type) type])) + arg*) + (list type))))) + + (define (render-type type) (unparse-Lanalyzed (Type type))) + (define (render-expr expr) (unparse-Lanalyzed (Expr expr))) + + (define (rendered? value) (and (pair? value) (symbol? (car value)))) + + (define (vm-value->sexp value) + (cond + [(or (integer? value) (boolean? value) (string? value)) value] + [(and (pair? value) (not (rendered? value))) (map vm-value->sexp value)] + [(rendered? value) value] + [(null? value) '()] + [(VMop? value) + (VMop-case value + [(VMstack) '(stack)] + [(VMvoid) '(void)] + [(VMalign value bytes) `(align ,value ,bytes)] + [(VM+ x y) `(+ ,(vm-value->sexp x) ,(vm-value->sexp y))] + [(VMvalue->int x) `(value->int ,(vm-value->sexp x))] + [(VMnull x) `(null ,(render-type x))] + [(VMmax-sizeof x) `(max-sizeof ,(render-type x))] + [(VMleaf-hash x) `(leaf-hash ,(vm-value->sexp x))] + [(VMcoin-commit coin recipient) + `(coin-commit ,(vm-value->sexp coin) ,(vm-value->sexp recipient))] + [(VMaligned-concat value*) `(aligned-concat ,@(map vm-value->sexp value*))] + [(VMstate-value-null) '(state-value null)] + [(VMstate-value-cell value) `(state-value cell ,(vm-value->sexp value))] + [(VMstate-value-ADT value type) + `(state-value ADT ,(vm-value->sexp value) ,(render-type type))] + [(VMstate-value-array value*) `(state-value array ,@(map vm-value->sexp value*))] + [(VMstate-value-map key* value*) + `(state-value map ,@(map (lambda (key value) `(,(vm-value->sexp key) ,(vm-value->sexp value))) key* value*))] + [(VMstate-value-merkle-tree nat key* value*) + `(state-value merkle-tree ,nat + ,@(map (lambda (key value) `(,(vm-value->sexp key) ,(vm-value->sexp value))) key* value*))] + [else (fail "VM value" value)])] + [else (render-expr value)])) + + (define (vm-suppressed? value) + (and (VMop? value) (VMop-case value [(VMsuppress) #t] [else #f]))) + + (define (vminstr->sexp instruction) + (let ([arg* (vminstr-arg* instruction)]) + (if (ormap (lambda (arg) (vm-suppressed? (cdr arg))) arg*) + #f + (let ([rendered + `(,(string->symbol (vminstr-op instruction)) + ,@(map (lambda (arg) `(,(string->symbol (car arg)) ,(vm-value->sexp (cdr arg)))) arg*))]) + (if (and (eq? (car rendered) 'ins) + (member '(n (void)) (cdr rendered))) + #f + rendered))))) + + (define (instructions->sexp instruction*) + (fold-right + (lambda (instruction acc) (let ([sexp (vminstr->sexp instruction)]) (if sexp (cons sexp acc) acc))) + '() + instruction*)) + + (define (expand-ops src path-elt* adt-formal* adt-arg* var-name* expr* vm-code) + (instructions->sexp + (expand-vm-code src + (map (lambda (path-elt) + (nanopass-case (Lloweredemit Path-Element) path-elt + [,path-index (VMalign path-index 1)] + [(,src ,type ,expr) (render-expr expr)])) + path-elt*) + #f + (append (map cons adt-formal* adt-arg*) + (map (lambda (var-name expr) (cons (id-sym var-name) (render-expr expr))) var-name* expr*)) + (vm-code-code vm-code)))) + + (define (expand-emit src event-version event-tag expr vm-code) + (instructions->sexp + (expand-vm-code src #f #f + (list (cons 'emit-version event-version) + (cons 'emit-tag event-tag) + (cons 'emit-payload (unparse-Lanalyzed expr))) + (vm-code-code vm-code))))) + + (Type : Type (type) -> Type ()) + + (Argument : Argument (arg) -> Argument ()) + + (Path-Element : Path-Element (path-elt) -> Path-Element ()) + + (ADT-Op-Class : ADT-Op-Class (op-class) -> ADT-Op-Class ()) + + (Expr : Expression (expr) -> Expression () + [(emit ,src ,event-version ,event-tag ,len ,[expr] ,vm-code) + `(emit ,src ,event-version ,event-tag ,len ,expr + (,(expand-emit src event-version event-tag expr vm-code) ...))] + [(public-ledger ,src ,ledger-field-name ,sugar (,path-elt* ...) ,src^ ,adt-op ,expr* ...) + (nanopass-case (Lloweredemit ADT-Op) adt-op + [(,ledger-op ,op-class (,adt-name (,adt-formal* ,adt-arg*) ...) + ((,var-name* ,type*) ...) ,type ,vm-code) + `(public-ledger ,src ,ledger-field-name ,(ADT-Op-Class op-class) + (,(map Path-Element path-elt*) ...) ,ledger-op ,(Type type) + (,(expand-ops src path-elt* adt-formal* adt-arg* var-name* expr* vm-code) ...) + ,(map Expr expr*) ...)])]) + + (Pelt : Program-Element (pelt proof-id*) -> Program-Element () + [(circuit ,src ,function-name (,arg* ...) ,type ,expr) + `(circuit ,src ,function-name + ,(id-exported? function-name) + ,(id-pure? function-name) + ,(and (memq function-name proof-id*) #t) + (,(map Argument arg*) ...) + ,(Type type) + ,(Expr expr))] + [(native ,src ,function-name ,native-entry (,arg* ...) ,type) + `(native ,src ,function-name + ,(native-entry-function native-entry) + ,(native-entry-class native-entry) + (,(native-type-argument* native-entry arg* type) ...) + (,(map Argument arg*) ...) + ,(Type type))]) + + (Public-Ledger-Binding + : Public-Ledger-Binding (binding) -> Public-Ledger-Binding () + [(,src ,ledger-field-name (,path-index* ...) ,[type]) + `(,src ,ledger-field-name (,path-index* ...) + ,(id-exported? ledger-field-name) + ,type)]) + + (Program : Program (ir) -> Program () + [(program ,src (,contract-type* ...) + ((,export-name* ,name*) ...) ,pelt* ...) + (let* ([proof-id* + (fold-left + (lambda (acc export-name name) + (if (memq export-name proof-circuit-name*) + (cons name acc) + acc)) + '() + export-name* + name*)] + [export* (map cons export-name* name*)]) + `(analyzed-ir + ,compiler-version-string + ,language-version-string + ,runtime-version-string + (,export* ...) + (,(map Type contract-type*) ...) + ,(map (lambda (pelt) (Pelt pelt proof-id*)) pelt*) ...))]) + + (Program ir)) diff --git a/compiler/save-analyzed-ir-passes/save-analyzed-ir.ss b/compiler/save-analyzed-ir-passes/save-analyzed-ir.ss new file mode 100644 index 000000000..e37a9a42a --- /dev/null +++ b/compiler/save-analyzed-ir-passes/save-analyzed-ir.ss @@ -0,0 +1,26 @@ +;;; This file is part of Compact. +;;; Copyright (C) 2025 Midnight Foundation +;;; SPDX-License-Identifier: Apache-2.0 +;;; Licensed under the Apache License, Version 2.0 (the "License"); +;;; you may not use this file except in compliance with the License. +;;; You may obtain a copy of the License at +;;; +;;; http://www.apache.org/licenses/LICENSE-2.0 +;;; +;;; Unless required by applicable law or agreed to in writing, software +;;; distributed under the License is distributed on an "AS IS" BASIS, +;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;;; See the License for the specific language governing permissions and +;;; limitations under the License. + +#!chezscheme + +(define (save-analyzed-ir ir proof-circuit-name*) + (let ([op (get-target-port 'analyzed-ir.sexp)]) + ;; Parentheses only: brackets are a Chez pretty-printing style, and a + ;; non-Scheme reader should not need to treat them as paren synonyms. + (parameterize ([print-brackets #f]) + (pretty-print + (unparse-Lanalyzed (extract-analyzed-ir ir proof-circuit-name*)) + op))) + ir) diff --git a/compiler/test.ss b/compiler/test.ss index 27e5215b7..122e77f39 100644 --- a/compiler/test.ss +++ b/compiler/test.ss @@ -339,7 +339,10 @@ groups than for single tests. (reverse feedback*))) (define (go source-fn target-fn okay?* code) (fluid-let ([successes '()] [positive-feedback* '()] [negative-feedback* '()] [condition-recorded? #f]) - (parameterize ([id-counter 0] [warning-conditions '()]) + ;; The analyzed-IR pass runs only behind its flag, so a group named + ;; for it turns the flag on and no other group pays for the file. + (parameterize ([id-counter 0] [warning-conditions '()] + [write-analyzed-ir (eq? pass-name 'save-analyzed-ir)]) (let-values ([(result pretty-formats) (parameterize ([pending-conditions '()]) (guard (c [else (values @@ -92463,5 +92466,183 @@ groups than for single tests. ) ) +;;; The analyzed-IR artifact. The pass runs only behind --analyzed-ir, and the +;;; harness turns the flag on for this group. +(run-tests save-analyzed-ir + (test-group + ((create-file "Registry.compact" + '( + "module Registry {" + " import CompactStandardLibrary;" + "" + " export ledger members: Set;" + " export ledger count: Counter;" + "" + " export circuit add(m: T): [] {" + " members.insert(disclose(m));" + " count.increment(1);" + " }" + "" + " export pure circuit atLeast(need: Uint<8>, have: Uint<8>): Boolean {" + " return have >= need;" + " }" + "}" + )) + (succeeds)) + ((create-file "testfile.compact" + '( + "pragma language_version >= 0.23;" + "import CompactStandardLibrary;" + "import Registry> prefix reg_;" + "" + "export { reg_add, reg_atLeast };" + "" + "export ledger digest: Bytes<32>;" + "export ledger vault: QualifiedShieldedCoinInfo;" + "" + "export circuit record(x: Field): [] {" + " digest = disclose(persistentHash(x));" + "}" + "" + "export circuit stash(coin: ShieldedCoinInfo," + " r: Either): [] {" + " vault.writeCoin(disclose(coin), disclose(r));" + "}" + "" + "export circuit pause(): [] {" + " emit(Paused {});" + "}" + )) + ; A generic module, imported under a prefix and re-exported selectively, so + ; the export names differ from the circuits' own names. The artifact + ; carries what the printed forms do not: the versions, the export table, + ; the exported/pure/proof flags, a ledger field's exported flag, the type + ; argument a generic native takes before its value, each operation's class, + ; and the expanded Impact VM instructions for both a ledger operation and + ; an emit. reg_add is the case that needs the export table: its proof flag + ; cannot be found by comparing its own name against the proving set. + ; writeCoin is the case that needs the class: the runtime checks the coin + ; commitment before it runs the instructions, so the check is not one of + ; them. + ; WARNING: Do not replace this wholesale...maintain the structure of the + ; first two lines to avoid hard-coding specific version strings into the test + (output-file "compiler/testdir/testfile/compiler/analyzed-ir.sexp" + `( + ,(format "(analyzed-ir (compiler-version ~s) (language-version ~s)" + compiler-version-string language-version-string) + ,(format " (runtime-version ~s)" runtime-version-string) + " (exports (digest . %digest.0) (pause . %pause.1)" + " (record . %record.2) (reg_add . %add.3)" + " (reg_atLeast . %atLeast.4) (stash . %stash.5)" + " (vault . %vault.6))" + " (contract-types)" + " (kernel-declaration (%kernel.7 () (exported #f) (Kernel)))" + " (public-ledger-declaration" + " (public-ledger-array" + " (%members.8 (0) (exported #f) (Set (tbytes 32)))" + " (%count.9 (1) (exported #f) (Counter))" + " (%digest.0 (2) (exported #t) (__compact_Cell (tbytes 32)))" + " (%vault.6" + " (3)" + " (exported #t)" + " (__compact_Cell" + " (tstruct QualifiedShieldedCoinInfo (nonce (tbytes 32))" + " (color (tbytes 32))" + " (value (tunsigned 340282366920938463463374607431768211455))" + " (mt_index (tunsigned 18446744073709551615))))))" + " (constructor () (tuple)))" + " (native %persistentHash.10" + " (entry \"__compactRuntime.persistentHash\" circuit)" + " (type-arguments (tfield (field-native)))" + " ((%value.11 (tfield (field-native)))) (tbytes 32))" + " (circuit %add.3 (exported #t) (pure #f) (proof #t)" + " ((%m.12 (tbytes 32))) (ttuple)" + " (seq (public-ledger %members.8 update (0) insert (ttuple)" + " (instructions (idx (cached #f) (pushPath #t) (path ((align 0 1))))" + " (push" + " (storage #f)" + " (value (state-value cell (var-ref %m.12))))" + " (push (storage #t) (value (state-value null)))" + " (ins (cached #f) (n 1)) (ins (cached #t) (n 1)))" + " (var-ref %m.12))" + " (let* (((%tmp.13 (tunsigned 65535)) (safe-cast" + " (tunsigned 65535)" + " (tunsigned 1)" + " '1)))" + " (public-ledger %count.9 update (1) increment (ttuple)" + " (instructions" + " (idx (cached #f) (pushPath #t) (path ((align 1 1))))" + " (addi (immediate (value->int (var-ref %tmp.13))))" + " (ins (cached #t) (n 1)))" + " (var-ref %tmp.13)))" + " (return (tuple))))" + " (circuit %atLeast.4 (exported #t) (pure #t) (proof #f)" + " ((%need.14 (tunsigned 255)) (%have.15 (tunsigned 255)))" + " (tboolean)" + " (return (>= 8 (var-ref %have.15) (var-ref %need.14))))" + " (circuit %record.2 (exported #t) (pure #f) (proof #t)" + " ((%x.16 (tfield (field-native)))) (ttuple)" + " (seq (let* (((%tmp.17 (tbytes 32)) (call" + " %persistentHash.10" + " (var-ref %x.16))))" + " (public-ledger %digest.0 write (2) write (ttuple)" + " (instructions" + " (push (storage #f) (value (state-value cell (align 2 1))))" + " (push" + " (storage #t)" + " (value (state-value cell (var-ref %tmp.17))))" + " (ins (cached #f) (n 1)))" + " (var-ref %tmp.17)))" + " (return (tuple))))" + " (circuit %stash.5 (exported #t) (pure #f) (proof #t)" + " ((%coin.18" + " (tstruct" + " ShieldedCoinInfo" + " (nonce (tbytes 32))" + " (color (tbytes 32))" + " (value" + " (tunsigned 340282366920938463463374607431768211455))))" + " (%r.19" + " (tstruct" + " Either" + " (is_left (tboolean))" + " (left (tstruct ZswapCoinPublicKey (bytes (tbytes 32))))" + " (right (tstruct ContractAddress (bytes (tbytes 32)))))))" + " (ttuple)" + " (seq (public-ledger %vault.6 (update-with-coin-check 0 1) (3) writeCoin" + " (ttuple)" + " (instructions (push (storage #f) (value (state-value cell (align 3 1))))" + " (dup (n 3))" + " (push" + " (storage #f)" + " (value" + " (state-value" + " cell" + " (coin-commit (var-ref %coin.18) (var-ref %r.19)))))" + " (idx (cached #t) (pushPath #f) (path ((align 1 1) (stack))))" + " (push" + " (storage #f)" + " (value (state-value cell (var-ref %coin.18))))" + " (swap (n 0)) (concat (cached #t) (n 91))" + " (ins (cached #f) (n 1)))" + " (var-ref %coin.18) (var-ref %r.19))" + " (return (tuple))))" + " (circuit %pause.1 (exported #t) (pure #f) (proof #t) () (ttuple)" + " (seq (emit 1 8 0 '#vu8()" + " (instructions" + " (push" + " (storage #f)" + " (value" + " (state-value" + " array" + " (state-value cell (align 1 4))" + " (state-value cell (align 8 1))" + " (state-value cell '#vu8()))))" + " (log)))" + " (return (tuple)))))" + )) + )) +) + (run-javascript) ) diff --git a/tests-e2e/src/resources/compiler_man_page.txt b/tests-e2e/src/resources/compiler_man_page.txt index db59a6041..3e5934f32 100644 --- a/tests-e2e/src/resources/compiler_man_page.txt +++ b/tests-e2e/src/resources/compiler_man_page.txt @@ -56,3 +56,10 @@ The following flags, if present, affect the compiler's behavior as follows: --trace-passes causes the compiler to print tracing information that is generally useful only to compiler developers. + + --analyzed-ir causes the compiler to also write compiler/analyzed-ir.sexp + into the target directory: the analyzed program in the compiler's own + intermediate-language vocabulary, with each ledger operation and emit + expanded to its Impact VM instructions. An SDK in any language can + execute circuits from it. The format follows the intermediate language, + so it can change between compiler versions.