diff --git a/compiler/compactc.ss b/compiler/compactc.ss index cfd6571c5..b6e2cb6b8 100755 --- a/compiler/compactc.ss +++ b/compiler/compactc.ss @@ -82,6 +82,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 writes compiler/analyzed-ir.sexp in the target directory. + It contains the analyzed program, with ledger operations and emits expanded + into Impact VM instructions. Its format can change between compiler versions. ")) (usage " ... ") @@ -100,6 +104,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 +114,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..cc05b0f71 100644 --- a/compiler/config-params.ss +++ b/compiler/config-params.ss @@ -41,4 +41,6 @@ ; feature flags (export-parameter feature-zkir-v3 #f) + + (export-parameter write-analyzed-ir #f) ) 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..c64d7d58a --- /dev/null +++ b/compiler/save-analyzed-ir-passes/extract-analyzed-ir.ss @@ -0,0 +1,289 @@ +;;; 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*) -> * (sexp) + (definitions + (define (fail what x) (internal-errorf 'save-analyzed-ir "unsupported ~a: ~s" what x)) + + (define (id->sym i) (string->symbol (format "~a" i))) + + ;; Scan the result because a type parameter can occur there without appearing in an argument. + (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 (a) + (nanopass-case (Lloweredemit Argument) a + [(,var-name ,type) type])) + arg*) + (list type))))) + + (define (Ftype ftype) (unparse-Lloweredemit ftype)) + (define (Type type) (unparse-Lloweredemit type)) + (define (Arg arg) (unparse-Lloweredemit arg)) + + (define (rendered? v) (and (pair? v) (symbol? (car v)))) + + (define (vm-value->sexp v) + (cond + [(or (integer? v) (boolean? v) (string? v)) v] + [(and (pair? v) (not (rendered? v))) (map vm-value->sexp v)] + [(rendered? v) v] + [(null? v) '()] + [(VMop? v) + (VMop-case v + [(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))] + ;; These operands are IR types, so expression serialization does not apply. + [(VMnull x) `(null ,(Type x))] + [(VMmax-sizeof x) `(max-sizeof ,(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 x*) `(aligned-concat ,@(map vm-value->sexp x*))] + [(VMstate-value-null) '(state-value null)] + [(VMstate-value-cell val) `(state-value cell ,(vm-value->sexp val))] + ;; Keep the type because it determines whether the value needs a cell. + [(VMstate-value-ADT val type) `(state-value ADT ,(vm-value->sexp val) ,(Type type))] + [(VMstate-value-array val*) `(state-value array ,@(map vm-value->sexp val*))] + [(VMstate-value-map key* val*) + `(state-value map ,@(map (lambda (k v) `(,(vm-value->sexp k) ,(vm-value->sexp v))) key* val*))] + [(VMstate-value-merkle-tree nat key* val*) + `(state-value merkle-tree ,nat + ,@(map (lambda (k v) `(,(vm-value->sexp k) ,(vm-value->sexp v))) key* val*))] + [else (fail "VM value" v)])] + [else (Expr v)])) + + (define (vm-suppressed? v) + (and (VMop? v) (VMop-case v [(VMsuppress) #t] [else #f]))) + + (define (vminstr->sexp vi) + (let ([args (vminstr-arg* vi)]) + (if (ormap (lambda (a) (vm-suppressed? (cdr a))) args) + #f + (let ([rendered + `(,(string->symbol (vminstr-op vi)) + ,@(map (lambda (a) `(,(string->symbol (car a)) ,(vm-value->sexp (cdr a)))) args))]) + ;; An ins with (void) has no runtime effect. + (if (and (eq? (car rendered) 'ins) + (member '(n (void)) (cdr rendered))) + #f + rendered))))) + + (define (instructions->sexp vminstr*) + (fold-right + (lambda (vi acc) (let ([s (vminstr->sexp vi)]) (if s (cons s acc) acc))) + '() + vminstr*)) + + (define (expand-ops src path-elt* adt-formal* adt-arg* var-name* expr* vm-code) + (instructions->sexp + (expand-vm-code src + (map (lambda (pe) + (nanopass-case (Lloweredemit Path-Element) pe + [,path-index (VMalign path-index 1)] + [(,src ,type ,expr) (Expr expr)])) + path-elt*) + #f + (append (map cons adt-formal* adt-arg*) + (map (lambda (vn ex) (cons (id-sym vn) (Expr ex))) var-name* expr*)) + (vm-code-code vm-code))))) + + (OpClass : ADT-Op-Class (op-class) -> * (sexp) + [,ledger-op-class ledger-op-class] + [(,ledger-op-class ,nat ,nat^) `(,ledger-op-class ,nat ,nat^)] + [else (fail "operation class" op-class)]) + + (TupleArg : Tuple-Argument (ta) -> * (sexp) + [(single ,src ,expr) `(single ,(Expr expr))] + [(spread ,src ,nat ,expr) `(spread ,nat ,(Expr expr))]) + + (MapArg : Map-Argument (ma) -> * (sexp) + [(,expr ,type ,type^) `(,(Expr expr) ,(Type type) ,(Type type^))]) + + (Fun : Function (fun) -> * (sexp) + [(fref ,src ,function-name) `(fref ,(id->sym function-name))] + [(circuit ,src (,arg* ...) ,type ,expr) + `(circuit ,(map Arg arg*) ,(Type type) ,(Expr expr))]) + + (Expr : Expression (expr) -> * (sexp) + [(quote ,src ,datum) `(quote ,datum)] + [(var-ref ,src ,var-name) `(var-ref ,(id->sym var-name))] + [(default ,src ,type) `(default ,(Type type))] + [(if ,src ,expr0 ,expr1 ,expr2) + `(if ,(Expr expr0) ,(Expr expr1) ,(Expr expr2))] + [(elt-ref ,src ,expr ,elt-name ,nat) `(elt-ref ,(Expr expr) ,elt-name ,nat)] + [(enum-ref ,src ,type ,elt-name) `(enum-ref ,(Type type) ,elt-name)] + [(tuple ,src ,tuple-arg* ...) `(tuple ,@(map TupleArg tuple-arg*))] + [(vector ,src ,tuple-arg* ...) `(vector ,@(map TupleArg tuple-arg*))] + [(tuple-ref ,src ,expr ,kindex) `(tuple-ref ,(Expr expr) ,kindex)] + [(tuple-slice ,src ,type ,expr ,kindex ,len) + `(tuple-slice ,(Type type) ,(Expr expr) ,kindex ,len)] + [(vector-ref ,src ,type ,expr ,index) + `(vector-ref ,(Type type) ,(Expr expr) ,(Expr index))] + [(vector-slice ,src ,type ,expr ,index ,len) + `(vector-slice ,(Type type) ,(Expr expr) ,(Expr index) ,len)] + [(bytes-ref ,src ,type ,expr ,index) + `(bytes-ref ,(Type type) ,(Expr expr) ,(Expr index))] + [(bytes-slice ,src ,type ,expr ,index ,len) + `(bytes-slice ,(Type type) ,(Expr expr) ,(Expr index) ,len)] + [(+ ,src ,type ,expr1 ,expr2) `(+ ,(Type type) ,(Expr expr1) ,(Expr expr2))] + [(- ,src ,type ,expr1 ,expr2) `(- ,(Type type) ,(Expr expr1) ,(Expr expr2))] + [(* ,src ,type ,expr1 ,expr2) `(* ,(Type type) ,(Expr expr1) ,(Expr expr2))] + [(< ,src ,bits ,expr1 ,expr2) `(< ,bits ,(Expr expr1) ,(Expr expr2))] + [(<= ,src ,bits ,expr1 ,expr2) `(<= ,bits ,(Expr expr1) ,(Expr expr2))] + [(> ,src ,bits ,expr1 ,expr2) `(> ,bits ,(Expr expr1) ,(Expr expr2))] + [(>= ,src ,bits ,expr1 ,expr2) `(>= ,bits ,(Expr expr1) ,(Expr expr2))] + [(== ,src ,type ,expr1 ,expr2) `(== ,(Type type) ,(Expr expr1) ,(Expr expr2))] + [(!= ,src ,type ,expr1 ,expr2) `(!= ,(Type type) ,(Expr expr1) ,(Expr expr2))] + [(map ,src ,len ,fun ,map-arg ,map-arg* ...) + `(map ,len ,(Fun fun) ,@(map MapArg (cons map-arg map-arg*)))] + [(fold ,src ,len ,fun (,expr0 ,type0) ,map-arg ,map-arg* ...) + `(fold ,len ,(Fun fun) (,(Expr expr0) ,(Type type0)) + ,@(map MapArg (cons map-arg map-arg*)))] + [(call ,src ,function-name ,expr* ...) + `(call ,(id->sym function-name) ,@(map Expr expr*))] + [(new ,src ,type ,expr* ...) + `(new ,(Type type) ,@(map Expr expr*))] + [(seq ,src ,expr* ... ,expr) + `(seq ,@(map Expr expr*) ,(Expr expr))] + [(let* ,src ([,local* ,expr*] ...) ,expr) + `(let* ,(map (lambda (l e) `(,(Arg l) ,(Expr e))) local* expr*) + ,(Expr expr))] + [(assert ,src ,expr ,mesg) `(assert ,(Expr expr) ,mesg)] + [(field->bytes ,src ,len ,ftype ,expr) + `(field->bytes ,len ,(Ftype ftype) ,(Expr expr))] + [(cast-from-bytes ,src ,type ,len ,expr) + `(cast-from-bytes ,(Type type) ,len ,(Expr expr))] + [(vector->bytes ,src ,len ,expr) `(vector->bytes ,len ,(Expr expr))] + [(bytes->vector ,src ,len ,expr) `(bytes->vector ,len ,(Expr expr))] + [(cast-from-enum ,src ,type ,type^ ,expr) + `(cast-from-enum ,(Type type) ,(Type type^) ,(Expr expr))] + [(cast-to-enum ,src ,type ,type^ ,expr) + `(cast-to-enum ,(Type type) ,(Type type^) ,(Expr expr))] + [(cast-to-field ,src ,ftype ,type ,expr) + `(cast-to-field ,(Ftype ftype) ,(Type type) ,(Expr expr))] + [(cast-from-field ,src ,nat ,ftype ,expr) + `(cast-from-field ,nat ,(Ftype ftype) ,(Expr expr))] + [(safe-cast ,src ,type ,type^ ,expr) + `(safe-cast ,(Type type) ,(Type type^) ,(Expr expr))] + [(downcast-unsigned ,src ,nat2 ,nat1 ,expr) + `(downcast-unsigned ,nat2 ,nat1 ,(Expr expr))] + [(contract-call ,src ,elt-name (,expr ,type) ,expr* ...) + `(contract-call ,elt-name (,(Expr expr) ,(Type type)) + ,@(map Expr expr*))] + [(emit ,src ,event-version ,event-tag ,len ,expr ,vm-code) + `(emit ,event-version ,event-tag ,len ,(Expr expr) + (instructions + ,@(instructions->sexp + (expand-vm-code src #f #f + `((emit-version . ,event-version) + (emit-tag . ,event-tag) + (emit-payload . ,(Expr expr))) + (vm-code-code 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 ,(id->sym ledger-field-name) + ,(OpClass op-class) + ,(map (lambda (pe) + (nanopass-case (Lloweredemit Path-Element) pe + [,path-index path-index] + [(,src ,type ,expr) `(,(Type type) ,(Expr expr))])) + path-elt*) + ,ledger-op + ,(Type type) + (instructions ,@(expand-ops src path-elt* adt-formal* adt-arg* var-name* expr* vm-code)) + ,@(map Expr expr*))])] + [(return ,src ,expr) `(return ,(Expr expr))] + [else (fail "expression" (unparse-Lloweredemit expr))]) + + (Pelt : Program-Element (pelt proof-id*) -> * (sexp) + [(circuit ,src ,function-name (,arg* ...) ,type ,expr) + `(circuit ,(id->sym function-name) + (exported ,(id-exported? function-name)) + (pure ,(id-pure? function-name)) + (proof ,(and (memq function-name proof-id*) #t)) + ,(map Arg arg*) + ,(Type type) + ,(Expr expr))] + [(native ,src ,function-name ,native-entry (,arg* ...) ,type) + `(native ,(id->sym function-name) + (entry ,(native-entry-function native-entry) ,(native-entry-class native-entry)) + (type-arguments ,@(native-type-argument* native-entry arg* type)) + ,(map Arg arg*) + ,(Type type))] + [(witness ,src ,function-name (,arg* ...) ,type) + `(witness ,(id->sym function-name) ,(map Arg arg*) ,(Type type))] + [(kernel-declaration ,public-binding) + `(kernel-declaration ,(Binding public-binding))] + [(public-ledger-declaration ,pl-array ,lconstructor) + `(public-ledger-declaration + ,(PlArray pl-array) + ,(nanopass-case (Lloweredemit Ledger-Constructor) lconstructor + [(constructor ,src (,arg* ...) ,expr) + `(constructor ,(map Arg arg*) ,(Expr expr))]))] + [(export-typedef ,src ,type-name (,tvar-name* ...) ,type) + `(export-typedef ,type-name ,tvar-name* ,(Type type))] + [else (fail "program element" (unparse-Lloweredemit pelt))]) + + (Binding : Public-Ledger-Binding (pb) -> * (sexp) + [(,src ,ledger-field-name (,path-index* ...) ,type) + `(,(id->sym ledger-field-name) + ,path-index* + (exported ,(id-exported? ledger-field-name)) + ,(Type type))]) + + (PlArray : Public-Ledger-Array (pl-array) -> * (sexp) + [(public-ledger-array ,pl-array-elt* ...) + `(public-ledger-array + ,@(map (lambda (elt) + (nanopass-case (Lloweredemit Public-Ledger-Array-Element) elt + [,pl-array (PlArray pl-array)] + [,public-binding (Binding public-binding)])) + pl-array-elt*))]) + + (Program : Program (ir) -> * (sexp) + [(program ,src (,contract-type* ...) ((,export-name* ,name*) ...) ,pelt* ...) + ;; Resolve proof export names through the export table because selective exports can rename circuits. + ;; Keep the id records because id-uniq assigns numbers on first print. + (let ([proof-id* + (fold-left + (lambda (acc export-name name) + (if (memq export-name proof-circuit-name*) (cons name acc) acc)) + '() + export-name* + name*)]) + `(analyzed-ir + (compiler-version ,compiler-version-string) + (language-version ,language-version-string) + (runtime-version ,runtime-version-string) + (exports ,@(map (lambda (en n) `(,en . ,(id->sym n))) export-name* name*)) + (contract-types ,@(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..0dbc77d64 --- /dev/null +++ b/compiler/save-analyzed-ir-passes/save-analyzed-ir.ss @@ -0,0 +1,22 @@ +;;; 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)]) + (parameterize ([print-brackets #f]) + (pretty-print (extract-analyzed-ir ir proof-circuit-name*) op))) + ir) diff --git a/compiler/test.ss b/compiler/test.ss index 27e5215b7..a82a6966a 100644 --- a/compiler/test.ss +++ b/compiler/test.ss @@ -339,7 +339,8 @@ 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 '()]) + (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 +92464,169 @@ groups than for single tests. ) ) +(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 {});" + "}" + )) + ; Keep the version lines dynamic because version strings change. + (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.5) (pause . %pause.6)" + " (record . %record.3) (reg_add . %add.4)" + " (reg_atLeast . %atLeast.1) (stash . %stash.2)" + " (vault . %vault.0))" + " (contract-types)" + " (kernel-declaration (%kernel.18 () (exported #f) (Kernel)))" + " (public-ledger-declaration" + " (public-ledger-array" + " (%members.14 (0) (exported #f) (Set (tbytes 32)))" + " (%count.16 (1) (exported #f) (Counter))" + " (%digest.5 (2) (exported #t) (__compact_Cell (tbytes 32)))" + " (%vault.0" + " (3)" + " (exported #t)" + " (__compact_Cell" + " (tstruct QualifiedShieldedCoinInfo (nonce (tbytes 32))" + " (color (tbytes 32))" + " (value (tunsigned 340282366920938463463374607431768211455))" + " (mt_index (tunsigned 18446744073709551615))))))" + " (constructor () (tuple)))" + " (native %persistentHash.11" + " (entry \"__compactRuntime.persistentHash\" circuit)" + " (type-arguments (tfield (field-native)))" + " ((%value.19 (tfield (field-native)))) (tbytes 32))" + " (circuit %add.4 (exported #t) (pure #f) (proof #t)" + " ((%m.15 (tbytes 32))) (ttuple)" + " (seq (public-ledger %members.14 update (0) insert (ttuple)" + " (instructions (idx (cached #f) (pushPath #t) (path ((align 0 1))))" + " (push" + " (storage #f)" + " (value (state-value cell (var-ref %m.15))))" + " (push (storage #t) (value (state-value null)))" + " (ins (cached #f) (n 1)) (ins (cached #t) (n 1)))" + " (var-ref %m.15))" + " (let* (((%tmp.17 (tunsigned 65535)) (safe-cast" + " (tunsigned 65535)" + " (tunsigned 1)" + " '1)))" + " (public-ledger %count.16 update (1) increment (ttuple)" + " (instructions" + " (idx (cached #f) (pushPath #t) (path ((align 1 1))))" + " (addi (immediate (value->int (var-ref %tmp.17))))" + " (ins (cached #t) (n 1)))" + " (var-ref %tmp.17)))" + " (return (tuple))))" + " (circuit %atLeast.1 (exported #t) (pure #t) (proof #f)" + " ((%need.10 (tunsigned 255)) (%have.9 (tunsigned 255)))" + " (tboolean)" + " (return (>= 8 (var-ref %have.9) (var-ref %need.10))))" + " (circuit %record.3 (exported #t) (pure #f) (proof #t)" + " ((%x.12 (tfield (field-native)))) (ttuple)" + " (seq (let* (((%tmp.13 (tbytes 32)) (call" + " %persistentHash.11" + " (var-ref %x.12))))" + " (public-ledger %digest.5 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.13))))" + " (ins (cached #f) (n 1)))" + " (var-ref %tmp.13)))" + " (return (tuple))))" + " (circuit %stash.2 (exported #t) (pure #f) (proof #t)" + " ((%coin.7" + " (tstruct" + " ShieldedCoinInfo" + " (nonce (tbytes 32))" + " (color (tbytes 32))" + " (value" + " (tunsigned 340282366920938463463374607431768211455))))" + " (%r.8" + " (tstruct" + " Either" + " (is_left (tboolean))" + " (left (tstruct ZswapCoinPublicKey (bytes (tbytes 32))))" + " (right (tstruct ContractAddress (bytes (tbytes 32)))))))" + " (ttuple)" + " (seq (public-ledger %vault.0 (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.7) (var-ref %r.8)))))" + " (idx (cached #t) (pushPath #f) (path ((align 1 1) (stack))))" + " (push" + " (storage #f)" + " (value (state-value cell (var-ref %coin.7))))" + " (swap (n 0)) (concat (cached #t) (n 91))" + " (ins (cached #f) (n 1)))" + " (var-ref %coin.7) (var-ref %r.8))" + " (return (tuple))))" + " (circuit %pause.6 (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..46c071e7f 100644 --- a/tests-e2e/src/resources/compiler_man_page.txt +++ b/tests-e2e/src/resources/compiler_man_page.txt @@ -56,3 +56,7 @@ 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 writes compiler/analyzed-ir.sexp in the target directory. + It contains the analyzed program, with ledger operations and emits expanded + into Impact VM instructions. Its format can change between compiler versions.