Skip to content

Add guard statement - #4432

Merged
turbolent merged 23 commits into
masterfrom
bastian/guard-statement
Apr 9, 2026
Merged

turbolent merged 23 commits into
masterfrom
bastian/guard-statement

Conversation

@turbolent

Copy link
Copy Markdown
Member

Description

Implement FLIP 355: Cadence Guard Statement


  • 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

@turbolent turbolent self-assigned this Feb 6, 2026
@github-actions

github-actions Bot commented Feb 6, 2026 •

Copy link
Copy Markdown

Dependency Review

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

Snapshot Warnings

⚠️: No snapshots were found for the head SHA f203b4f.
Ensure that dependencies are being submitted on PR branches and consider enabling retry-on-snapshot-warnings. See the documentation for more information and troubleshooting advice.

Scanned Files

None

@github-actions

github-actions Bot commented Feb 6, 2026 •

Copy link
Copy Markdown

Benchstat comparison

  • Base branch: onflow:master
  • Base commit: 3471aa7
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.29µs ± 0%1.24µs ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-481.8ns ± 0%78.6ns ± 0%~(p=1.000 n=1+1)
ByteSliceToByteArrayValue-41.05µs ± 0%0.96µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4129µs ± 0%129µs ± 0%~(p=1.000 n=1+1)
CompileTime-438.4µs ± 0%38.0µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4408µs ± 0%392µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-4235µs ± 0%225µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-43.45µs ± 0%3.33µs ± 0%~(p=1.000 n=1+1)
Emit-44.56ms ± 0%4.51ms ± 0%~(p=1.000 n=1+1)
EnumTransfer-41.38µs ± 0%1.27µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ExportType/composite_type-4273ns ± 0%272ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-477.8ns ± 0%77.7ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
FTTransfer-4160µs ± 0%157µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-4621µs ± 0%644µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-422.8µs ± 0%22.9µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ImperativeFib-424.9µs ± 0%25.8µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewCompilerNewVM-448.6µs ± 0%51.6µs ± 0%~(p=1.000 n=1+1)
ImperativeFibNewVM-428.0µs ± 0%28.8µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
InterpretRecursionFib-42.29ms ± 0%2.31ms ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
InterpreterFTTransfer-4129µs ± 0%130µs ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-422.8µs ± 0%24.7µs ± 0%~(p=1.000 n=1+1)
InterpreterNewStruct-465.5µs ± 0%70.7µs ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-445.1µs ± 0%45.0µs ± 0%~(p=1.000 n=1+1)
MethodCall/interface_method_call-463.3µs ± 0%64.0µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
NewInterpreter/new_interpreter-4854ns ± 0%881ns ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4326ns ± 0%328ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
NewResource-4105µs ± 0%105µs ± 0%~(p=1.000 n=1+1)
NewStruct-443.4µs ± 0%45.7µs ± 0%~(p=1.000 n=1+1)
NewStructRaw-43.02µs ± 0%3.31µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/parser goos:linux goarch:amd64
ParseArray-45.68ms ± 0%5.72ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-48.58ms ± 0%8.51ms ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-4918µs ± 0%955µs ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-4162µs ± 0%167µs ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/Without_memory_metering-4123µs ± 0%116µs ± 0%~(p=1.000 n=1+1)
ParseInfix-45.08µs ± 0%5.03µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-42.18ns ± 0%2.19ns ± 0%~(p=1.000 n=1+1)
QualifiedIdentifierCreation/Three_levels-479.8ns ± 0%81.4ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-41.54ms ± 0%1.63ms ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4778µs ± 0%759µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4647µs ± 0%600µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4712µs ± 0%711µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.79ms ± 0%2.66ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-410.4ms ± 0%9.9ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-415.4µs ± 0%14.8µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-442.0µs ± 0%41.5µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-4235ns ± 0%218ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/composites-4100ns ± 0%90ns ± 0%~(p=1.000 n=1+1)
SuperTypeInference/integers-4321ns ± 0%317ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-464.2ns ± 0%59.9ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ByteArrayTransfer-41.08kB ± 0%1.06kB ± 0%~(p=1.000 n=1+1)
ByteArrayValueToByteSlice-432.0B ± 0%32.0B ± 0%~(all equal)
ByteSliceToByteArrayValue-4854B ± 0%853B ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-482.9kB ± 0%82.9kB ± 0%~(p=1.000 n=1+1)
CompileTime-416.9kB ± 0%16.9kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4144kB ± 0%144kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-475.5kB ± 0%75.3kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-42.47kB ± 0%2.46kB ± 0%~(p=1.000 n=1+1)
Emit-41.50MB ± 0%1.50MB ± 0%~(p=1.000 n=1+1)
EnumTransfer-4828B ± 0%881B ± 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-443.7kB ± 0%43.7kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-4226kB ± 0%226kB ± 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.41kB ± 0%5.41kB ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-425.8kB ± 0%25.8kB ± 0%~(all equal)
ImperativeFibNewVM-48.10kB ± 0%8.10kB ± 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-442.0kB ± 0%42.0kB ± 0%~(p=1.000 n=1+1)
InterpreterImperativeFib-48.29kB ± 0%8.29kB ± 0%~(all equal)
InterpreterNewStruct-424.8kB ± 0%24.9kB ± 0%~(p=1.000 n=1+1)
MethodCall/concrete_type_method_call-410.2kB ± 0%10.2kB ± 0%~(all equal)
MethodCall/interface_method_call-417.1kB ± 0%17.1kB ± 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-444.0kB ± 0%44.0kB ± 0%~(all equal)
NewStruct-413.4kB ± 0%13.5kB ± 0%~(p=1.000 n=1+1)
NewStructRaw-41.70kB ± 0%1.81kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/parser goos:linux goarch:amd64
ParseArray-42.68MB ± 0%2.66MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-44.13MB ± 0%4.13MB ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-4214kB ± 0%214kB ± 0%~(p=1.000 n=1+1)
ParseFungibleToken/With_memory_metering-430.3kB ± 0%30.3kB ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-430.3kB ± 0%30.3kB ± 0%~(p=1.000 n=1+1)
ParseInfix-41.92kB ± 0%1.92kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-40.00B 0.00B ~(all equal)
QualifiedIdentifierCreation/Three_levels-464.0B ± 0%64.0B ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-4283kB ± 0%283kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransfer-4241kB ± 0%242kB ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4165kB ± 0%165kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4188kB ± 0%188kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.76MB ± 0%1.76MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-46.99MB ± 0%6.98MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-48.09kB ± 0%8.08kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-413.4kB ± 0%13.4kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-472.0B ± 0%72.0B ± 0%~(all equal)
SuperTypeInference/composites-40.00B 0.00B ~(all equal)
SuperTypeInference/integers-40.00B 0.00B ~(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/interpreter goos:linux goarch:amd64
ByteArrayTransfer-47.00 ± 0%7.00 ± 0%~(all equal)
ByteArrayValueToByteSlice-41.00 ± 0%1.00 ± 0%~(all equal)
ByteSliceToByteArrayValue-45.00 ± 0%5.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/compiler goos:linux goarch:amd64
CompileFungibleTokenTransferTransaction-4576 ± 0%576 ± 0%~(all equal)
CompileTime-4209 ± 0%209 ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.25k ± 0%2.25k ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
ContractImport-41.29k ± 0%1.29k ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
EMVAddressTransfer-429.0 ± 0%29.0 ± 0%~(all equal)
Emit-440.0k ± 0%40.0k ± 0%~(all equal)
EnumTransfer-413.0 ± 0%13.0 ± 0%~(all equal)
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.40k ± 0%1.40k ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
FlowTokenContract-43.58k ± 0%3.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-4266 ± 0%266 ± 0%~(all equal)
ImperativeFibNewCompilerNewVM-4473 ± 0%473 ± 0%~(all equal)
ImperativeFibNewVM-4308 ± 0%308 ± 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-4916 ± 0%916 ± 0%~(all equal)
InterpreterImperativeFib-4175 ± 0%175 ± 0%~(all equal)
InterpreterNewStruct-4418 ± 0%418 ± 0%~(all equal)
MethodCall/concrete_type_method_call-4354 ± 0%354 ± 0%~(all equal)
MethodCall/interface_method_call-4464 ± 0%464 ± 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-4951 ± 0%951 ± 0%~(all equal)
NewStruct-4388 ± 0%388 ± 0%~(all equal)
NewStructRaw-430.0 ± 0%30.0 ± 0%~(all equal)
pkg:github.com/onflow/cadence/parser goos:linux goarch:amd64
ParseArray-459.6k ± 0%59.6k ± 0%~(p=1.000 n=1+1)
ParseDeploy/byte_array-489.4k ± 0%89.4k ± 0%~(p=1.000 n=1+1)
ParseDeploy/decode_hex-464.0 ± 0%64.0 ± 0%~(all equal)
ParseFungibleToken/With_memory_metering-4786 ± 0%786 ± 0%~(all equal)
ParseFungibleToken/Without_memory_metering-4786 ± 0%786 ± 0%~(all equal)
ParseInfix-448.0 ± 0%48.0 ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
QualifiedIdentifierCreation/One_level-40.00 0.00 ~(all equal)
QualifiedIdentifierCreation/Three_levels-42.00 ± 0%2.00 ± 0%~(all equal)
pkg:github.com/onflow/cadence/bbq/vm/test goos:linux goarch:amd64
RecursionFib-415.8k ± 0%15.8k ± 0%~(all equal)
RuntimeFungibleTokenTransfer-44.09k ± 0%4.09k ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-43.08k ± 0%3.08k ± 0%~(all equal)
RuntimeFungibleTokenTransferVM-43.61k ± 0%3.61k ± 0%~(all equal)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-4129k ± 0%129k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-4114 ± 0%114 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4426 ± 0%426 ± 0%~(all equal)
pkg:github.com/onflow/cadence/sema goos:linux goarch:amd64
SuperTypeInference/arrays-43.00 ± 0%3.00 ± 0%~(all equal)
SuperTypeInference/composites-40.00 0.00 ~(all equal)
SuperTypeInference/integers-40.00 0.00 ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@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.

👏 👏

Comment thread interpreter/guard_test.go Resolved
Comment thread interpreter/interpreter_statement.go Resolved
Comment thread bbq/compiler/compiler.go Resolved
Comment thread bbq/compiler/compiler.go Resolved
@turbolent
turbolent requested a review from SupunS April 9, 2026 17:27

@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.

LGTM!

@turbolent
turbolent merged commit ddc3463 into master Apr 9, 2026
16 of 17 checks passed
@turbolent
turbolent deleted the bastian/guard-statement branch April 9, 2026 17:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址