Skip to content

Improve assertions for instructions by introducing "pretty" instructions - #4423

Merged
turbolent merged 34 commits into
masterfrom
bastian/pretty-instructions
Feb 10, 2026
Merged

turbolent merged 34 commits into
masterfrom
bastian/pretty-instructions

Conversation

@turbolent

@turbolent turbolent commented Jan 28, 2026 •

Copy link
Copy Markdown
Member

Description

Currently the tests for the compiler assert that the compiler generates specific instructions, and instructions use indices for types, constants, locals, etc. That makes the assertions brittle, as changes in the way that the compiler allocates types, constant, locals, etc. in a different order "physically" breaks the tests, though semantically nothing changes.

Add (automatically generated) "pretty" equivalents for all instruction types, where the operands are not indices, but specific Go types (e.g. a type operand is a bbq.StaticType instead of a uint16).

Finally, refactor the tests to assert pretty instructions. There are a lot of changes, but given we did not change anything in the compiler code, the new code cannot be incorrect as it must re-assert what was already previously asserted.

I verified the changed by using git diff --word-diff --word-diff-regex='.' -- bbq/compiler/compiler_test.go while making the changes.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@github-actions

github-actions Bot commented Jan 28, 2026 •

Copy link
Copy Markdown

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions

github-actions Bot commented Jan 28, 2026 •

Copy link
Copy Markdown

Benchstat comparison

  • Base branch: onflow:master
  • Base commit: 8f2f949
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4129µs ± 0%135µs ± 0%~(p=1.000 n=1+1)
CompileTime-435.6µs ± 0%38.3µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4427µs ± 0%425µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-4239µs ± 0%227µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-44.69ms ± 0%4.74ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4274ns ± 0%268ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-478.1ns ± 0%78.4ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-4179µs ± 0%171µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-422.7µs ± 0%23.5µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-424.5µs ± 0%24.8µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewCompilerNewVM-448.5µs ± 0%50.4µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-428.3µs ± 0%27.9µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-42.26ms ± 0%2.33ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4150µs ± 0%151µs ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-423.8µs ± 0%23.2µs ± 0%~(p=1.000 n=1+1)
InterpreterNewStruct-472.0µs ± 0%67.3µs ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-442.6µs ± 0%44.1µs ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-466.5µs ± 0%66.8µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4929ns ± 0%905ns ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4325ns ± 0%331ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4105µs ± 0%102µs ± 0%~(p=1.000 n=1+1)
NewStruct-442.5µs ± 0%44.3µs ± 0%~(p=1.000 n=1+1)
NewStructRaw-43.93µs ± 0%3.80µs ± 0%~(p=1.000 n=1+1)
RecursionFib-41.49ms ± 0%1.41ms ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4805µs ± 0%809µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4655µs ± 0%655µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4714µs ± 0%737µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.69ms ± 0%2.94ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-411.6ms ± 0%12.6ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-416.2µs ± 0%16.2µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-441.4µs ± 0%43.0µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-462.4ns ± 0%61.9ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-481.9kB ± 0%81.9kB ± 0%~(p=1.000 n=1+1)
CompileTime-416.6kB ± 0%16.6kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4153kB ± 0%152kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-480.4kB ± 0%80.0kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-41.50MB ± 0%1.51MB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4120B ± 0%120B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-453.4kB ± 0%53.3kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-48.30kB ± 0%8.30kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-45.34kB ± 0%5.34kB ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-425.7kB ± 0%25.7kB ± 0%~(all equal)
ImperativeFibNewVM-48.07kB ± 0%8.07kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-41.19MB ± 0%1.19MB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-450.7kB ± 0%50.7kB ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-48.29kB ± 0%8.29kB ± 0%~(all equal)
InterpreterNewStruct-424.6kB ± 0%24.5kB ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-410.2kB ± 0%10.1kB ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-417.7kB ± 0%17.7kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4232B ± 0%232B ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-443.3kB ± 0%43.3kB ± 0%~(p=1.000 n=1+1)
NewStruct-413.0kB ± 0%13.1kB ± 0%~(p=1.000 n=1+1)
NewStructRaw-42.58kB ± 0%2.58kB ± 0%~(p=1.000 n=1+1)
RecursionFib-4244kB ± 0%244kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4247kB ± 0%247kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4170kB ± 0%171kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4192kB ± 0%192kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.76MB ± 0%1.77MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-48.58MB ± 0%8.60MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-48.06kB ± 0%8.07kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-413.3kB ± 0%13.3kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-432.0B ± 0%32.0B ± 0%~(all equal)
 
allocs/opdelta
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4559 ± 0%559 ± 0%~(all equal)
CompileTime-4202 ± 0%202 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.47k ± 0%2.47k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-41.30k ± 0%1.30k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
Emit-440.0k ± 0%40.0k ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-43.00 ± 0%3.00 ± 0%~(all equal)
ExportType/simple_type-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-41.58k ± 0%1.58k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-4176 ± 0%176 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-4262 ± 0%262 ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-4470 ± 0%470 ± 0%~(all equal)
ImperativeFibNewVM-4306 ± 0%306 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-417.7k ± 0%17.7k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-41.11k ± 0%1.11k ± 0%~(all equal)
InterpreterImperativeFib-4175 ± 0%175 ± 0%~(all equal)
InterpreterNewStruct-4418 ± 0%418 ± 0%~(all equal)
MethodCall/concrete_type_method_call-4334 ± 0%334 ± 0%~(all equal)
MethodCall/interface_method_call-4494 ± 0%494 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-415.0 ± 0%15.0 ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-44.00 ± 0%4.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4919 ± 0%919 ± 0%~(all equal)
NewStruct-4364 ± 0%364 ± 0%~(all equal)
NewStructRaw-438.0 ± 0%38.0 ± 0%~(all equal)
RecursionFib-413.4k ± 0%13.4k ± 0%~(all equal)
RuntimeFungibleTokenTransfer-44.28k ± 0%4.28k ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-43.27k ± 0%3.27k ± 0%~(all equal)
RuntimeFungibleTokenTransferVM-43.72k ± 0%3.72k ± 0%~(all equal)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-4144k ± 0%144k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-4114 ± 0%114 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4424 ± 0%424 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@turbolent
turbolent marked this pull request as ready for review January 30, 2026 20:06

@SupunS SupunS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea!

Comment thread bbq/opcode/instructions.go Resolved
Comment thread bbq/opcode/print_test.go Resolved
turbolent and others added 2 commits February 10, 2026 09:53
Co-authored-by: Supun Setunga <supun.setunga@gmail.com>
@turbolent
turbolent enabled auto-merge February 10, 2026 18:06
@turbolent
turbolent merged commit 08fcd1f into master Feb 10, 2026
17 checks passed
@turbolent
turbolent deleted the bastian/pretty-instructions branch February 10, 2026 18:15
@codecov

codecov Bot commented Feb 10, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址