Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

Closes #3114

Description

This PR adds support for importing Attachment values and AttachmentType types in the Cadence runtime, addressing issue #3114 which identified that while attachments could be exported, they could not be imported.

The implementation follows the existing pattern used for other composite types (Struct, Resource, Event, etc.) by leveraging the fact that AttachmentType already implements the CompositeType interface.

Changes

runtime/convertTypes.go

  • Added *cadence.AttachmentType to the type switch in ImportType() so attachment types are routed through the existing importCompositeType() function

runtime/convertValues.go

  • Added cadence.Attachment case to the value switch in importValue() to handle attachment value imports via importCompositeValue()

runtime/convertValues_test.go

  • Added TestRuntimeImportAttachmentValue: Tests importing attachment values with fields
  • Added TestRuntimeImportAttachmentType: Tests importing attachment types directly
  • Added TestRuntimeImportTypeValueOfAttachmentType: Tests importing TypeValues containing attachment types

Review Focus

  1. Correctness of delegation: The implementation relies on existing composite type import infrastructure. Verify that importCompositeValue() correctly handles attachment-specific concerns.

  2. Test coverage: Tests cover basic scenarios but use TestLocation for simplicity. Consider whether additional integration tests with real contract locations are needed.

  3. Edge cases: Verify there are no attachment-specific edge cases (e.g., attachment base type handling, attachment inheritance) that need special consideration beyond what the existing composite type logic provides.


Link to Devin run: https://app.devin.ai/sessions/1b6b7a027cc6487fbe1d7c3b87cc60e1
Requested by: [email protected]


  • 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

- Add AttachmentType to ImportType function in runtime/convertTypes.go
- Add Attachment value import case in runtime/convertValues.go importValue method
- Add comprehensive tests for importing attachment values and types
- Add test for importing TypeValue of AttachmentType

Closes #3114
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@github-actions
Copy link

Benchstat comparison

  • Base branch: onflow:master
  • Base commit: 21639ee
Results

old.txtnew.txt
time/opdelta
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4414µs ± 0%423µs ± 0%~(p=1.000 n=1+1)
ExportType/composite_type-4267ns ± 0%264ns ± 0%~(p=1.000 n=1+1)
ExportType/simple_type-478.1ns ± 0%77.9ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-420.8µs ± 0%20.8µs ± 0%~(p=1.000 n=1+1)
InterpretRecursionFib-42.21ms ± 0%2.11ms ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-41.05µs ± 0%1.04µs ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_sub-interpreter-4324ns ± 0%324ns ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4587µs ± 0%592µs ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4647µs ± 0%630µs ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-42.79ms ± 0%2.66ms ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-412.5ms ± 0%12.6ms ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-415.0µs ± 0%14.8µs ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-429.9µs ± 0%31.1µs ± 0%~(p=1.000 n=1+1)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-464.1ns ± 0%65.6ns ± 0%~(p=1.000 n=1+1)
 
alloc/opdelta
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-4152kB ± 0%152kB ± 0%~(p=1.000 n=1+1)
ExportType/composite_type-4120B ± 0%120B ± 0%~(all equal)
ExportType/simple_type-40.00B 0.00B ~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ImperativeFib-48.30kB ± 0%8.30kB ± 0%~(all equal)
InterpretRecursionFib-41.19MB ± 0%1.19MB ± 0%~(p=1.000 n=1+1)
NewInterpreter/new_interpreter-4976B ± 0%976B ± 0%~(all equal)
NewInterpreter/new_sub-interpreter-4232B ± 0%232B ± 0%~(all equal)
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-4156kB ± 0%156kB ± 0%~(p=1.000 n=1+1)
RuntimeFungibleTokenTransferVM-4174kB ± 0%174kB ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-41.77MB ± 0%1.76MB ± 0%~(p=1.000 n=1+1)
RuntimeResourceTracking-49.27MB ± 0%9.26MB ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-47.99kB ± 0%7.99kB ± 0%~(p=1.000 n=1+1)
RuntimeVMInvokeContractImperativeFib-410.3kB ± 0%10.3kB ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-448.0B ± 0%48.0B ± 0%~(all equal)
 
allocs/opdelta
pkg:github.com/onflow/cadence/runtime goos:linux goarch:amd64
ContractFunctionInvocation-42.47k ± 0%2.47k ± 0%~(all equal)
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/interpreter goos:linux goarch:amd64
ImperativeFib-4176 ± 0%176 ± 0%~(all equal)
InterpretRecursionFib-417.7k ± 0%17.7k ± 0%~(all equal)
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/runtime goos:linux goarch:amd64
RuntimeFungibleTokenTransferInterpreter-42.93k ± 0%2.93k ± 0%~(all equal)
RuntimeFungibleTokenTransferVM-43.06k ± 0%3.06k ± 0%~(p=1.000 n=1+1)
RuntimeResourceDictionaryValues-436.7k ± 0%36.7k ± 0%~(all equal)
RuntimeResourceTracking-4159k ± 0%159k ± 0%~(p=1.000 n=1+1)
RuntimeScriptNoop-4113 ± 0%113 ± 0%~(all equal)
RuntimeVMInvokeContractImperativeFib-4213 ± 0%213 ± 0%~(all equal)
pkg:github.com/onflow/cadence/interpreter goos:linux goarch:amd64
ValueIsSubtypeOfSemaType-41.00 ± 0%1.00 ± 0%~(all equal)
 

@devin-ai-integration
Copy link
Contributor Author

Closing due to inactivity for more than 30 days. Configure here.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime needs to support importing Attachment and TypeValue of AttachmentType

1 participant