Skip to content

Commit

Permalink
Merge pull request #3744 from onflow/bastian/sync-compiler
Browse files Browse the repository at this point in the history
[Compiler] Sync with master
  • Loading branch information
SupunS authored Jan 29, 2025
2 parents 4703a34 + 44406d4 commit 3a904fd
Show file tree
Hide file tree
Showing 186 changed files with 20,003 additions and 16,296 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'v**'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'v**'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'v**'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/compatibility-check-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ on:
required: true
type: string
secrets:
FLOWDIVER_API_KEY:
FIND_API_AUTH:
required: true

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ inputs.base-branch || github.run_id }}-${{ inputs.chain }}
Expand Down Expand Up @@ -62,10 +62,10 @@ jobs:
- name: Download contracts
if: ${{ steps.restore-cached-contracts.outputs.cache-hit != 'true' }}
env:
FLOWDIVER_API_KEY: ${{ secrets.FLOWDIVER_API_KEY }}
FIND_API_AUTH: ${{ secrets.FIND_API_AUTH }}
working-directory: ./tools/get-contracts
run: |
go run . --chain=${{ inputs.chain }} --apiKey="$FLOWDIVER_API_KEY" > ../../tmp/contracts.csv
go run . -chain=${{ inputs.chain }} -auth="$FIND_API_AUTH" > ../../tmp/contracts.csv
- name: Cache Contracts
id: cache-contracts
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/compatibility-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ on:
- 'v**'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ inputs.base || github.run_id }}
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
current-branch: ${{ needs.setup.outputs.branch }}
chain: mainnet
secrets:
FLOWDIVER_API_KEY: ${{ secrets.FLOWDIVER_API_KEY }}
FIND_API_AUTH: ${{ secrets.FIND_API_AUTH }}

testnet:
needs: setup
Expand All @@ -77,4 +77,4 @@ jobs:
current-branch: ${{ needs.setup.outputs.branch }}
chain: testnet
secrets:
FLOWDIVER_API_KEY: ${{ secrets.FLOWDIVER_API_KEY }}
FIND_API_AUTH: ${{ secrets.FIND_API_AUTH }}
2 changes: 1 addition & 1 deletion .github/workflows/downstream.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ on:
- 'v**'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/get-contracts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ on:
required: true
type: string
secrets:
FLOWDIVER_API_KEY:
FIND_API_AUTH:
required: true

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.run_id }}-${{ inputs.chain }}
Expand All @@ -37,10 +37,10 @@ jobs:

- name: Download contracts
env:
FLOWDIVER_API_KEY: ${{ secrets.FLOWDIVER_API_KEY }}
FIND_API_AUTH: ${{ secrets.FIND_API_AUTH }}
working-directory: ./tools/get-contracts
run: |
go run . --chain=${{ inputs.chain }} --apiKey="$FLOWDIVER_API_KEY" > ../../tmp/contracts.csv
go run . -chain=${{ inputs.chain }} -auth="$FIND_API_AUTH" > ../../tmp/contracts.csv
# Upload

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ on:
default: 'master'

env:
GO_VERSION: '1.22'
GO_VERSION: '1.23'

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
Expand Down
36 changes: 26 additions & 10 deletions bbq/vm/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,44 @@ func MustConvertStoredValue(gauge common.MemoryGauge, storage interpreter.Storag
}

func ReadStored(
gauge common.MemoryGauge,
storage interpreter.Storage,
config *Config,
address common.Address,
domain string,
identifier string,
) Value {
accountStorage := storage.GetStorageMap(address, domain, false)
storage := config.Storage

storageDomain, _ := common.StorageDomainFromIdentifier(domain)

accountStorage := storage.GetDomainStorageMap(
config.interpreter(),
address,
storageDomain,
false,
)
if accountStorage == nil {
return nil
}

referenced := accountStorage.ReadValue(gauge, interpreter.StringStorageMapKey(identifier))
referenced := accountStorage.ReadValue(config.MemoryGauge, interpreter.StringStorageMapKey(identifier))
return InterpreterValueToVMValue(storage, referenced)
}

func WriteStored(
config *Config,
storageAddress common.Address,
domain string,
domain common.StorageDomain,
key interpreter.StorageMapKey,
value Value,
) (existed bool) {
accountStorage := config.Storage.GetStorageMap(storageAddress, domain, true)

inter := config.interpreter()

accountStorage := config.Storage.GetDomainStorageMap(inter, storageAddress, domain, true)
interValue := VMValueToInterpreterValue(config, value)

return accountStorage.WriteValue(
config.interpreter(),
inter,
key,
interValue,
)
Expand All @@ -90,12 +101,17 @@ func RemoveReferencedSlab(storage interpreter.Storage, storable atree.Storable)
}

func StoredValueExists(
storage interpreter.Storage,
config *Config,
storageAddress common.Address,
domain string,
domain common.StorageDomain,
identifier interpreter.StorageMapKey,
) bool {
accountStorage := storage.GetStorageMap(storageAddress, domain, false)
accountStorage := config.Storage.GetDomainStorageMap(
config.interpreter(),
storageAddress,
domain,
false,
)
if accountStorage == nil {
return false
}
Expand Down
13 changes: 8 additions & 5 deletions bbq/vm/value_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/onflow/cadence/errors"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
)

type AccountIDGenerator interface {
Expand Down Expand Up @@ -143,8 +142,7 @@ func getCapability(
// Read stored capability, if any

readValue := ReadStored(
config.MemoryGauge,
config.Storage,
config,
address,
domain,
identifier,
Expand Down Expand Up @@ -339,7 +337,7 @@ func storeCapabilityController(
existed := WriteStored(
config,
address,
stdlib.CapabilityControllerStorageDomain,
common.StorageDomainCapabilityController,
storageMapKey,
controller,
)
Expand Down Expand Up @@ -376,7 +374,12 @@ func recordStorageCapabilityController(

storageMapKey := interpreter.StringStorageMapKey(identifier)

accountStorage := config.Storage.GetStorageMap(address, stdlib.PathCapabilityStorageDomain, true)
accountStorage := config.Storage.GetDomainStorageMap(
config.interpreter(),
address,
common.StorageDomainPathCapability,
true,
)

referenced := accountStorage.ReadValue(config.MemoryGauge, interpreter.StringStorageMapKey(identifier))
readValue := InterpreterValueToVMValue(config.Storage, referenced)
Expand Down
8 changes: 5 additions & 3 deletions bbq/vm/value_account_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,17 @@ func init() {
}

domain := path.Domain.Identifier()
storageDomain, _ := common.StorageDomainFromIdentifier(domain)

identifier := path.Identifier

// Prevent an overwrite

storageMapKey := interpreter.StringStorageMapKey(identifier)
if StoredValueExists(
config.Storage,
config,
accountAddress,
domain,
storageDomain,
storageMapKey,
) {
panic(interpreter.OverwriteError{
Expand All @@ -174,7 +176,7 @@ func init() {
WriteStored(
config,
accountAddress,
domain,
storageDomain,
storageMapKey,
capabilityValue,
)
Expand Down
3 changes: 2 additions & 1 deletion bbq/vm/value_account_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,11 @@ func init() {

// Write new value

storageDomain, _ := common.StorageDomainFromIdentifier(domain)
WriteStored(
config,
address,
domain,
storageDomain,
interpreter.StringStorageMapKey(identifier),
value,
)
Expand Down
8 changes: 6 additions & 2 deletions bbq/vm/value_capability.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
"github.com/onflow/cadence/format"
"github.com/onflow/cadence/interpreter"
"github.com/onflow/cadence/sema"
"github.com/onflow/cadence/stdlib"
)

// members
Expand Down Expand Up @@ -210,7 +209,12 @@ func getCapabilityController(

storageMapKey := interpreter.Uint64StorageMapKey(capabilityID)

accountStorage := config.Storage.GetStorageMap(address, stdlib.CapabilityControllerStorageDomain, false)
accountStorage := config.Storage.GetDomainStorageMap(
config.interpreter(),
address,
common.StorageDomainCapabilityController,
false,
)
if accountStorage == nil {
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions bbq/vm/value_storage_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,11 @@ func (v *StorageReferenceValue) StaticType(config *Config) StaticType {
}

func (v *StorageReferenceValue) dereference(config *Config) (*Value, error) {
memoryGauge := config.MemoryGauge
address := v.TargetStorageAddress
domain := v.TargetPath.Domain.Identifier()
identifier := v.TargetPath.Identifier

vmReferencedValue := ReadStored(memoryGauge, config.Storage, address, domain, identifier)
vmReferencedValue := ReadStored(config, address, domain, identifier)
if vmReferencedValue == nil {
return nil, nil
}
Expand Down
82 changes: 82 additions & 0 deletions benchmarks/binarytrees.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

access(all)
struct Tree {
access(all)
var left: Tree?

access(all)
var right: Tree?

init(left: Tree?, right: Tree?) {
self.left = left
self.right = right
}

access(all)
fun nodeCount(): Int {
return 1
+ (self.left?.nodeCount() ?? 0)
+ (self.right?.nodeCount() ?? 0)
}

access(all)
fun clear() {
if (self.left != nil) {
self.left?.clear()
self.left = nil
self.right?.clear()
self.right = nil
}
}
}

access(all)
fun newTree(depth: Int): Tree {
if depth == 0 {
return Tree(left: nil, right: nil)
}
return Tree(
left: newTree(depth: depth - 1),
right: newTree(depth: depth - 1)
)
}

access(all)
fun stretch(_ depth: Int) {
log("stretch tree of depth \(depth), check: \(count(depth))")
}

access(all)
fun count(_ depth: Int): Int {
let t = newTree(depth: depth)
let c = t.nodeCount()
t.clear()
return c
}

access(all)
fun run(_ n: Int) {
let minDepth = 4
let maxDepth = minDepth + 2 > n ? minDepth + 2 : n
let stretchDepth = maxDepth + 1

stretch(stretchDepth)
let longLivedTree = newTree(depth: maxDepth)

for depth in InclusiveRange(minDepth, maxDepth, step: 2) {
let iterations = 1 << (maxDepth - depth + minDepth)
var sum = 0
for _ in InclusiveRange(1, iterations, step: 1) {
sum = sum + count(depth)
}
log("\(iterations), trees of depth \(depth), check: \(sum)")
}
let count = longLivedTree.nodeCount()
longLivedTree.clear()
log("long lived tree of depth \(maxDepth), check: \(count)")
}

access(all)
fun main() {
run(10)
}
Loading

0 comments on commit 3a904fd

Please sign in to comment.