Skip to content

Commit

Permalink
Merge branch 'master' of github.com:onflow/cadence into sainati/error…
Browse files Browse the repository at this point in the history
…-positioning
  • Loading branch information
dsainati1 committed Jul 19, 2023
2 parents 6d689b2 + 24ca444 commit 291d81c
Show file tree
Hide file tree
Showing 85 changed files with 2,449 additions and 692 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ jobs:
benchmark:
name: Performance regression check
runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
- name: Set benchmark repetitions
# reducing repetition will speed up execution,
# but will be more inaccurate at detecting change
run: echo "::set-output name=benchmark_repetitions::7"
run: echo "benchmark_repetitions=7" >> "$GITHUB_OUTPUT"
id: settings

- name: Install dependencies
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/compatibility-check-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ name: BackwardCompatibilityCheckTemplate
on:
workflow_call:
inputs:
repo:
required: true
type: string
default: onflow/cadence
current-branch:
required: true
type: string
Expand Down Expand Up @@ -72,12 +76,18 @@ jobs:
path: tmp/contracts.csv
key: ${{ steps.cache-key-generator.outputs.cache-key }}-contracts

- name: Configure permissions
if: github.repository != 'onflow/cadence'
run: |
echo "GOPRIVATE=github.com/${{ inputs.repo }}" >> "$GITHUB_ENV"
git config --global url."https://${{ github.actor }}:${{ github.token }}@github.com".insteadOf "https://github.com"
# Check contracts using current branch

- name: Check contracts using ${{ inputs.current-branch }}
working-directory: ./tools/compatibility-check
run: |
GOPROXY=direct go get github.com/onflow/cadence@${{ inputs.current-branch }}
GOPROXY=direct go mod edit -replace github.com/onflow/cadence=github.com/${{ inputs.repo }}@${{ inputs.current-branch }}
go mod tidy
go run ./cmd/check_contracts/main.go ../../tmp/contracts.csv ../../tmp/output-new.txt
Expand All @@ -86,7 +96,7 @@ jobs:
- name: Check contracts using ${{ inputs.base-branch }}
working-directory: ./tools/compatibility-check
run: |
GOPROXY=direct go get github.com/onflow/cadence@${{ inputs.base-branch }}
GOPROXY=direct go mod edit -replace github.com/onflow/cadence=github.com/${{ inputs.repo }}@${{ inputs.base-branch }}
go mod tidy
go run ./cmd/check_contracts/main.go ../../tmp/contracts.csv ../../tmp/output-old.txt
Expand All @@ -103,6 +113,5 @@ jobs:
# Check Diff

- name: Check diff
working-directory: ./tools/compatibility-check
run: |
go run ./cmd/check_diff/main.go ../../tmp/output-old.txt ../../tmp/output-new.txt
diff -u --color ./tmp/output-old.txt ./tmp/output-new.txt
8 changes: 7 additions & 1 deletion .github/workflows/compatibility-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: BackwardCompatibilityCheck
on:
workflow_dispatch:
inputs:
repo:
description: Repository (defaults to 'onflow/cadence')
branch:
description: 'Current branch/tag'
required: true
Expand Down Expand Up @@ -32,6 +34,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
# Map step output to the job output, so that next job can use these values.
repo: ${{ steps.setup.outputs.repo }}
branch: ${{ steps.setup.outputs.branch }}
base: ${{ steps.setup.outputs.base }}
steps:
Expand All @@ -44,19 +47,21 @@ jobs:
# instead of the branch name, since 'go get' command does not support all kinds of branch names.
#
# Here there also is a limitation that we can't use the 'merge-branch' because it is not visible to 'go get'.
# So the workflow will not work across forks.
run: |
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
echo "repo=`(echo "${{ github.event.pull_request.head.repo.full_name }}")`" >> $GITHUB_OUTPUT
echo "branch=`(echo "${{ github.event.pull_request.head.sha }}")`" >> $GITHUB_OUTPUT
echo "base=`(echo "${{ github.base_ref }}")`" >> $GITHUB_OUTPUT
else
echo "repo=`(echo "${{ inputs.repo || 'onflow/cadence' }}")`" >> $GITHUB_OUTPUT
echo "branch=`(echo "${{ inputs.branch }}")`" >> $GITHUB_OUTPUT
echo "base=`(echo "${{ inputs.base }}")`" >> $GITHUB_OUTPUT
fi
mainnet:
needs: setup
uses: ./.github/workflows/compatibility-check-template.yml
with:
repo: ${{ needs.setup.outputs.repo }}
base-branch: ${{ needs.setup.outputs.base }}
current-branch: ${{ needs.setup.outputs.branch }}
chain: flow-mainnet
Expand All @@ -66,6 +71,7 @@ jobs:
needs: setup
uses: ./.github/workflows/compatibility-check-template.yml
with:
repo: ${{ needs.setup.outputs.repo }}
base-branch: ${{ needs.setup.outputs.base }}
current-branch: ${{ needs.setup.outputs.branch }}
chain: flow-testnet
Expand Down
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Bastian Müller <bastian@turbolent.com> <bastian@axiomzen.co>
Bastian Müller <bastian@turbolent.com> <bastian@dapperlabs.com>
2 changes: 1 addition & 1 deletion npm-packages/cadence-parser/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@onflow/cadence-parser",
"version": "0.39.12",
"version": "0.39.14",
"description": "The Cadence parser",
"homepage": "https://github.com/onflow/cadence",
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions runtime/account_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2361,7 +2361,7 @@ func TestGetAuthAccount(t *testing.T) {

errs := checker.RequireCheckerErrors(t, err, 1)

assert.IsType(t, &sema.ArgumentCountError{}, errs[0])
assert.IsType(t, &sema.InsufficientArgumentsError{}, errs[0])
})

t.Run("too many args", func(t *testing.T) {
Expand All @@ -2388,7 +2388,7 @@ func TestGetAuthAccount(t *testing.T) {
)
errs := checker.RequireCheckerErrors(t, err, 1)

assert.IsType(t, &sema.ArgumentCountError{}, errs[0])
assert.IsType(t, &sema.ExcessiveArgumentsError{}, errs[0])
})

t.Run("transaction", func(t *testing.T) {
Expand Down
10 changes: 7 additions & 3 deletions runtime/ast/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package ast
import (
"encoding/json"

"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/errors"
)

Expand Down Expand Up @@ -58,9 +59,12 @@ var BasicAccesses = []Access{
AccessPublicSettable,
}

var AllAccesses = append(BasicAccesses[:],
AccessContract,
AccessAccount,
var AllAccesses = common.Concat(
BasicAccesses,
[]Access{
AccessContract,
AccessAccount,
},
)

func (a Access) Keyword() string {
Expand Down
36 changes: 36 additions & 0 deletions runtime/common/concat.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Cadence - The resource-oriented smart contract programming language
*
* Copyright Dapper Labs, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package common

func Concat[T any](slices ...[]T) []T {
var length int

for _, slice := range slices {
length += len(slice)
}

result := make([]T, length)

var offset int
for _, slice := range slices {
offset += copy(result[offset:], slice)
}

return result
}
13 changes: 13 additions & 0 deletions runtime/interpreter/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -975,3 +975,16 @@ func (AccountLinkingForbiddenError) IsUserError() {}
func (e AccountLinkingForbiddenError) Error() string {
return "account linking is not allowed"
}

// RecursiveTransferError
type RecursiveTransferError struct {
LocationRange
}

var _ errors.UserError = RecursiveTransferError{}

func (RecursiveTransferError) IsUserError() {}

func (RecursiveTransferError) Error() string {
return "recursive transfer of value"
}
17 changes: 11 additions & 6 deletions runtime/interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,12 +423,15 @@ func (interpreter *Interpreter) InvokeExternally(

if argumentCount != parameterCount {

// if the function has defined optional parameters,
// then the provided arguments must be equal to or greater than
// the number of required parameters.
if functionType.RequiredArgumentCount == nil ||
argumentCount < *functionType.RequiredArgumentCount {
if argumentCount < functionType.Arity.MinCount(parameterCount) {
return nil, ArgumentCountError{
ParameterCount: parameterCount,
ArgumentCount: argumentCount,
}
}

maxCount := functionType.Arity.MaxCount(parameterCount)
if maxCount != nil && argumentCount > *maxCount {
return nil, ArgumentCountError{
ParameterCount: parameterCount,
ArgumentCount: argumentCount,
Expand Down Expand Up @@ -1065,7 +1068,6 @@ func (interpreter *Interpreter) declareNonEnumCompositeValue(
ReturnTypeAnnotation: sema.TypeAnnotation{
Type: compositeType,
},
RequiredArgumentCount: nil,
}

var initializerFunction FunctionValue
Expand Down Expand Up @@ -1690,6 +1692,7 @@ func (interpreter *Interpreter) transferAndConvert(
atree.Address{},
false,
nil,
nil,
)

result := interpreter.ConvertAndBox(
Expand Down Expand Up @@ -3863,6 +3866,7 @@ func (interpreter *Interpreter) authAccountSaveFunction(addressValue AddressValu
atree.Address(address),
true,
nil,
nil,
)

// Write new value
Expand Down Expand Up @@ -3986,6 +3990,7 @@ func (interpreter *Interpreter) authAccountReadFunction(addressValue AddressValu
atree.Address{},
false,
nil,
nil,
)

// Remove the value from storage,
Expand Down
22 changes: 22 additions & 0 deletions runtime/interpreter/interpreter_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -1155,6 +1155,12 @@ func (interpreter *Interpreter) VisitReferenceExpression(referenceExpression *as

interpreter.maybeTrackReferencedResourceKindedValue(result)

// There are four potential cases:
// 1) Target type is optional, actual value is also optional (nil/SomeValue)
// 2) Target type is optional, actual value is non-optional
// 3) Target type is non-optional, actual value is optional (SomeValue)
// 4) Target type is non-optional, actual value is non-optional

switch typ := borrowType.(type) {
case *sema.OptionalType:
innerBorrowType, ok := typ.Type.(*sema.ReferenceType)
Expand All @@ -1165,6 +1171,7 @@ func (interpreter *Interpreter) VisitReferenceExpression(referenceExpression *as

switch result := result.(type) {
case *SomeValue:
// Case (1):
// References to optionals are transformed into optional references,
// so move the *SomeValue out to the reference itself

Expand All @@ -1190,6 +1197,7 @@ func (interpreter *Interpreter) VisitReferenceExpression(referenceExpression *as
return Nil

default:
// Case (2):
// If the referenced value is non-optional,
// but the target type is optional,
// then box the reference properly
Expand All @@ -1212,8 +1220,21 @@ func (interpreter *Interpreter) VisitReferenceExpression(referenceExpression *as
}

case *sema.ReferenceType:
// Case (3): target type is non-optional, actual value is optional.
// Unwrap the optional and add it to reference tracking.
if someValue, ok := result.(*SomeValue); ok {
locationRange := LocationRange{
Location: interpreter.Location,
HasPosition: referenceExpression.Expression,
}
innerValue := someValue.InnerValue(interpreter, locationRange)
interpreter.maybeTrackReferencedResourceKindedValue(innerValue)
}

// Case (4): target type is non-optional, actual value is also non-optional
return NewEphemeralReferenceValue(interpreter, typ.Authorized, result, typ.Type)
}

panic(errors.NewUnreachableError())
}

Expand Down Expand Up @@ -1310,6 +1331,7 @@ func (interpreter *Interpreter) VisitAttachExpression(attachExpression *ast.Atta
atree.Address{},
false,
nil,
nil,
).(*CompositeValue)

// we enforce this in the checker
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter_invocation.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func (interpreter *Interpreter) invokeFunctionValue(
atree.Address{},
false,
nil,
nil,
)
}
}
Expand Down
1 change: 1 addition & 0 deletions runtime/interpreter/interpreter_statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ func (interpreter *Interpreter) VisitForStatement(statement *ast.ForStatement) S
atree.Address{},
false,
nil,
nil,
)

iterable, ok := transferredValue.(IterableValue)
Expand Down
16 changes: 16 additions & 0 deletions runtime/interpreter/location.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,22 @@ type LocationRange struct {
ast.HasPosition
}

var _ ast.HasPosition = LocationRange{}

func (r LocationRange) StartPosition() ast.Position {
if r.HasPosition == nil {
return ast.EmptyPosition
}
return r.HasPosition.StartPosition()
}

func (r LocationRange) EndPosition(memoryGauge common.MemoryGauge) ast.Position {
if r.HasPosition == nil {
return ast.EmptyPosition
}
return r.HasPosition.EndPosition(memoryGauge)
}

func (r LocationRange) ImportLocation() common.Location {
return r.Location
}
Expand Down
Loading

0 comments on commit 291d81c

Please sign in to comment.