onflow / cadence

Cadence, the resource-oriented smart contract programming language 🏃‍♂️
https://cadence-lang.org
Apache License 2.0
534 stars 138 forks source link

Avoid conversion from `StaticType` to `sema.Type` during runtime sub-type checking #3691

Open SupunS opened 1 day ago

SupunS commented 1 day ago

Issue to be solved

In Interpreter.IsSubType(...) function, both the sub-type and the super-type gets converted from StaticType to sema.Type (see below). This adds an unnecessary overhead.

https://github.com/onflow/cadence/blob/b09231fe0216ecb024fbfc909f213bed53a2d3bb/interpreter/interpreter.go#L4066 https://github.com/onflow/cadence/blob/b09231fe0216ecb024fbfc909f213bed53a2d3bb/interpreter/interpreter.go#L4039

Suggested Solution

Having a separate sub-type checking implementation for runtime (static types) could eliminate this overhead. We could define the sub-typing rules in some declarative format, and then generate the two implementations from that, to make them consistent/in-sync.