cadence icon indicating copy to clipboard operation
cadence copied to clipboard

Compiler Milestone X

Open turbolent opened this issue 9 months ago • 1 comments

Functionality that needs to be implemented to match parity with the interpreter. For now, an unprioritized laundry list

Features

  • [ ] Value injection for specific locations (compiler, VM, VM environment; e.g. for EVM) @turbolent
  • [ ] Contract deployment / Account.Contracts functions
  • [ ] Interface imports (for Account.contracts.borrow, neds Config.GetContractValue)
  • [ ] Crypto contract ?
  • [ ] Storage iteration for broken contracts
  • [ ] InclusiveRange
  • [ ] Support import aliases in compiler
  • [ ] #4028
  • [ ] Contract recovery

Safety

  • [ ] Swap of resources in index expression (move target out while evaluating index) @turbolent
    • https://github.com/onflow/cadence-internal/pull/182

Unused features

  • [ ] Resource owner change
  • [ ] atree storage/health validation

Debugging

  • [ ] Emit trace instructions
  • [ ] Visualize control flow (jumps) in printed byte code

Optimization

  • [ ] Similar to static-types^, bypass encoding-decoding of constants
  • [ ] Add "resource-ness" (flag) to the static-type. Might need a state migration. (maybe not needed for the initial version)
    • Move resource-ness from instruction to static type (currently instructions have resource-nes operand)
  • Peephole optimizations
  • [ ] Avoid encoding/decoding of constants
  • [ ] When encoding/decoding constants, use LEB128
  • [ ] Remove duplicate transfers that gets added from move-operator (https://github.com/onflow/cadence/pull/3938)
  • [ ] Make NativeFunctionValue, CompiledFunctionValue, and other large types pointer types
  • [ ] Metering (computation and memory), avoid call to FVM each time (see https://github.com/onflow/cadence/issues/3992)
    • VM environment directly metering VS going through runtime.Interface / ExternalInterface is ca 25%!
  • [ ] Conversion between static and sema types
    • Avoid?
    • Cache? See https://github.com/onflow/cadence/issues/3992
  • [ ] Reusing the VM (vm.NewVM call, need to make linking result reusable, ensure no values are used concurrently)
  • [ ] Avoid constructing function values, e.g. newAccountKeysValue -> newAccountKeysAddFunction
  • [ ] Cache linking results from VM. But cannot include interpreter values

Testing

  • [ ] All runtime tests work with compiler/VM
  • [ ] Execution results match for X period of time
  • [ ] Import confusion of desugared code

Technical Debt

  • [ ] Unify interpreter and VM host/native functions (currently lots of duplication, mostly argument extraction)
  • [ ] Complete environment
  • [ ] Defensively copy arguments when invoking native functions
  • [ ] Skip compilation for codes that were not type checked
  • [ ] Enable position assertion, once position info is available in https://github.com/onflow/cadence/blob/d34ba56665b9b19f99cc1e95d2311f8825afe388/interpreter/resources_test.go#L1729-L1744
    • Depends on https://github.com/onflow/cadence/pull/3938
  • [ ] Cleanup location range
  • [ ] Handle native functions properly in invokeExternally ? https://github.com/onflow/cadence/pull/3982#discussion_r2112874627
  • [ ] Improve globals in compiler/VM, see https://flow-foundation.slack.com/archives/C07RZKJH679/p1748550298070419
  • [ ] Generate empty initializer and enum lookup function in desugar instead of compiler
  • [ ] Reuse VM in VM environment
  • [ ] replace TestFTTransfer and TestInterpreterFTTransfer with runtime tests that uses UseVM
  • [ ] https://github.com/onflow/cadence/issues/4048

turbolent avatar Feb 27 '25 19:02 turbolent

Next milestones:

enable 3rd book-keeping function NFT support

j1010001 avatar May 30 '25 17:05 j1010001

replace TestFTTransfer and TestInterpreterFTTransfer with runtime tests that uses UseVM

Removing this item, since the intention of the two tests TestFTTransfer and TestInterpreterFTTransfer (and their benchmark counterparts) was to purely test the vm/interpreter by isolating them from the runtime environment.

SupunS avatar Jul 17 '25 17:07 SupunS