From 07ca3b9af81437e191d2535e4548c36593a741b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Wed, 13 Jul 2022 21:31:41 -0700 Subject: [PATCH 1/7] refactor stdlib enums to be simple composite values, reuse values for all interpreters --- runtime/convertValues.go | 22 +-- runtime/convertValues_test.go | 2 +- runtime/interpreter/accountkey.go | 2 +- runtime/interpreter/interpreter.go | 37 +++-- runtime/interpreter/simplecompositevalue.go | 6 +- runtime/interpreter/value.go | 4 +- runtime/interpreter/value_test.go | 6 +- runtime/resourcedictionary_test.go | 4 +- runtime/runtime.go | 19 +-- runtime/stdlib/bls.go | 24 +-- runtime/stdlib/crypto.go | 27 ++-- runtime/stdlib/hashalgorithm.go | 159 ++++++++++---------- runtime/stdlib/publickey.go | 2 +- runtime/stdlib/rlp.go | 24 +-- runtime/stdlib/signaturealgorithm.go | 41 +++-- runtime/test-export-json-deterministic.txt | 2 +- 16 files changed, 206 insertions(+), 175 deletions(-) diff --git a/runtime/convertValues.go b/runtime/convertValues.go index 64732d91de..b3da41ad5f 100644 --- a/runtime/convertValues.go +++ b/runtime/convertValues.go @@ -1373,7 +1373,7 @@ func importCompositeValue( fieldTypes []cadence.Field, fieldValues []cadence.Value, ) ( - *interpreter.CompositeValue, + interpreter.Value, error, ) { var fields []interpreter.CompositeField @@ -1424,12 +1424,12 @@ func importCompositeValue( case sema.HashAlgorithmType: // HashAlgorithmType has a dedicated constructor // (e.g. it has host functions) - return importHashAlgorithm(inter, fields) + return importHashAlgorithm(fields) case sema.SignatureAlgorithmType: // SignatureAlgorithmType has a dedicated constructor // (e.g. it has host functions) - return importSignatureAlgorithm(inter, fields) + return importSignatureAlgorithm(fields) default: return nil, errors.NewDefaultUserError( @@ -1460,7 +1460,7 @@ func importPublicKey( ) { var publicKeyValue *interpreter.ArrayValue - var signAlgoValue *interpreter.CompositeValue + var signAlgoValue *interpreter.SimpleCompositeValue ty := sema.PublicKeyType @@ -1480,7 +1480,7 @@ func importPublicKey( publicKeyValue = arrayValue case sema.PublicKeySignAlgoField: - compositeValue, ok := field.Value.(*interpreter.CompositeValue) + compositeValue, ok := field.Value.(*interpreter.SimpleCompositeValue) if !ok { return nil, errors.NewDefaultUserError( "cannot import value of type '%s'. invalid value for field '%s': %v", @@ -1528,10 +1528,9 @@ func importPublicKey( } func importHashAlgorithm( - inter *interpreter.Interpreter, fields []interpreter.CompositeField, ) ( - *interpreter.CompositeValue, + interpreter.MemberAccessibleValue, error, ) { @@ -1570,14 +1569,14 @@ func importHashAlgorithm( ) } - return stdlib.NewHashAlgorithmCase(inter, uint8(rawValue)), nil + // TODO: return existing + return stdlib.NewHashAlgorithmCase(rawValue), nil } func importSignatureAlgorithm( - inter *interpreter.Interpreter, fields []interpreter.CompositeField, ) ( - *interpreter.CompositeValue, + interpreter.MemberAccessibleValue, error, ) { @@ -1616,5 +1615,6 @@ func importSignatureAlgorithm( ) } - return stdlib.NewSignatureAlgorithmCase(inter, uint8(rawValue)), nil + // TODO: return existing + return stdlib.NewSignatureAlgorithmCase(rawValue), nil } diff --git a/runtime/convertValues_test.go b/runtime/convertValues_test.go index 0a5af98bd5..94565b7347 100644 --- a/runtime/convertValues_test.go +++ b/runtime/convertValues_test.go @@ -407,7 +407,7 @@ func TestExportValue(t *testing.T) { return nil }, ), - stdlib.NewHashAlgorithmCase(inter, 1), + stdlib.NewHashAlgorithmCase(1), interpreter.NewUnmeteredUFix64ValueWithInteger(10), false, ) diff --git a/runtime/interpreter/accountkey.go b/runtime/interpreter/accountkey.go index d529f42eb8..3330f68768 100644 --- a/runtime/interpreter/accountkey.go +++ b/runtime/interpreter/accountkey.go @@ -37,7 +37,7 @@ func NewAccountKeyValue( inter *Interpreter, keyIndex IntValue, publicKey *CompositeValue, - hashAlgo *CompositeValue, + hashAlgo Value, weight UFix64Value, isRevoked BoolValue, ) *SimpleCompositeValue { diff --git a/runtime/interpreter/interpreter.go b/runtime/interpreter/interpreter.go index 163b18cca1..4e6338a09e 100644 --- a/runtime/interpreter/interpreter.go +++ b/runtime/interpreter/interpreter.go @@ -237,7 +237,7 @@ type SignatureVerificationHandlerFunc func( signature *ArrayValue, signedData *ArrayValue, domainSeparationTag *StringValue, - hashAlgorithm *CompositeValue, + hashAlgorithm *SimpleCompositeValue, publicKey MemberAccessibleValue, ) BoolValue @@ -1850,7 +1850,10 @@ func (interpreter *Interpreter) declareEnumConstructor( intType := sema.IntType enumCases := declaration.Members.EnumCases() - caseValues := make([]*CompositeValue, len(enumCases)) + caseValues := make([]struct { + Value MemberAccessibleValue + RawValue IntegerValue + }, len(enumCases)) constructorNestedVariables := map[string]*Variable{} @@ -1861,7 +1864,7 @@ func (interpreter *Interpreter) declareEnumConstructor( NewIntValueFromInt64(interpreter, int64(i)), intType, compositeType.EnumRawType, - ) + ).(IntegerValue) caseValueFields := []CompositeField{ { @@ -1881,7 +1884,13 @@ func (interpreter *Interpreter) declareEnumConstructor( caseValueFields, common.Address{}, ) - caseValues[i] = caseValue + caseValues[i] = struct { + Value MemberAccessibleValue + RawValue IntegerValue + }{ + Value: caseValue, + RawValue: rawValue, + } constructorNestedVariables[enumCase.Identifier.Identifier] = NewVariableWithValue(interpreter, caseValue) @@ -1902,27 +1911,29 @@ func (interpreter *Interpreter) declareEnumConstructor( } func EnumConstructorFunction( - inter *Interpreter, + gauge common.MemoryGauge, getLocationRange func() LocationRange, enumType *sema.CompositeType, - caseValues []*CompositeValue, + cases []struct { + Value MemberAccessibleValue + RawValue IntegerValue + }, nestedVariables map[string]*Variable, ) *HostFunctionValue { // Prepare a lookup table based on the big-endian byte representation - lookupTable := make(map[string]*CompositeValue) + lookupTable := make(map[string]Value, len(cases)) - for _, caseValue := range caseValues { - rawValue := caseValue.GetField(inter, getLocationRange, sema.EnumRawValueFieldName) - rawValueBigEndianBytes := rawValue.(IntegerValue).ToBigEndianBytes() - lookupTable[string(rawValueBigEndianBytes)] = caseValue + for _, c := range cases { + rawValueBigEndianBytes := c.RawValue.ToBigEndianBytes() + lookupTable[string(rawValueBigEndianBytes)] = c.Value } // Prepare the constructor function which performs a lookup in the lookup table constructor := NewHostFunctionValue( - inter, + gauge, func(invocation Invocation) Value { rawValue, ok := invocation.Arguments[0].(IntegerValue) if !ok { @@ -1933,7 +1944,7 @@ func EnumConstructorFunction( caseValue, ok := lookupTable[string(rawValueArgumentBigEndianBytes)] if !ok { - return NewNilValue(inter) + return NewNilValue(gauge) } return NewSomeValueNonCopying(invocation.Interpreter, caseValue) diff --git a/runtime/interpreter/simplecompositevalue.go b/runtime/interpreter/simplecompositevalue.go index d1f69d37a9..0f48eb6ff5 100644 --- a/runtime/interpreter/simplecompositevalue.go +++ b/runtime/interpreter/simplecompositevalue.go @@ -46,7 +46,7 @@ var _ Value = &SimpleCompositeValue{} var _ MemberAccessibleValue = &SimpleCompositeValue{} func NewSimpleCompositeValue( - inter *Interpreter, + gauge common.MemoryGauge, typeID sema.TypeID, staticType StaticType, fieldNames []string, @@ -56,8 +56,8 @@ func NewSimpleCompositeValue( stringer func(common.MemoryGauge, SeenReferences) string, ) *SimpleCompositeValue { - common.UseMemory(inter, common.SimpleCompositeValueBaseMemoryUsage) - common.UseMemory(inter, common.NewSimpleCompositeMemoryUsage(len(fields)+len(computedFields))) + common.UseMemory(gauge, common.SimpleCompositeValueBaseMemoryUsage) + common.UseMemory(gauge, common.NewSimpleCompositeMemoryUsage(len(fields)+len(computedFields))) return &SimpleCompositeValue{ TypeID: typeID, diff --git a/runtime/interpreter/value.go b/runtime/interpreter/value.go index 173b020253..1d2d116311 100644 --- a/runtime/interpreter/value.go +++ b/runtime/interpreter/value.go @@ -18495,7 +18495,7 @@ func NewPublicKeyValue( interpreter *Interpreter, getLocationRange func() LocationRange, publicKey *ArrayValue, - signAlgo *CompositeValue, + signAlgo Value, validatePublicKey PublicKeyValidationHandlerFunc, ) *CompositeValue { @@ -18584,7 +18584,7 @@ var publicKeyVerifyFunction = NewUnmeteredHostFunctionValue( panic(errors.NewUnreachableError()) } - hashAlgo, ok := invocation.Arguments[3].(*CompositeValue) + hashAlgo, ok := invocation.Arguments[3].(*SimpleCompositeValue) if !ok { panic(errors.NewUnreachableError()) } diff --git a/runtime/interpreter/value_test.go b/runtime/interpreter/value_test.go index da657dc80d..8a850ade48 100644 --- a/runtime/interpreter/value_test.go +++ b/runtime/interpreter/value_test.go @@ -3272,8 +3272,7 @@ func TestPublicKeyValue(t *testing.T) { ) sigAlgo := stdlib.NewSignatureAlgorithmCase( - inter, - sema.SignatureAlgorithmECDSA_secp256k1.RawValue(), + UInt8Value(sema.SignatureAlgorithmECDSA_secp256k1.RawValue()), ) key := NewPublicKeyValue( @@ -3325,8 +3324,7 @@ func TestPublicKeyValue(t *testing.T) { ) sigAlgo := stdlib.NewSignatureAlgorithmCase( - inter, - sema.SignatureAlgorithmECDSA_secp256k1.RawValue(), + UInt8Value(sema.SignatureAlgorithmECDSA_secp256k1.RawValue()), ) assert.PanicsWithError(t, diff --git a/runtime/resourcedictionary_test.go b/runtime/resourcedictionary_test.go index 30912acabd..40b2bddbc5 100644 --- a/runtime/resourcedictionary_test.go +++ b/runtime/resourcedictionary_test.go @@ -966,10 +966,10 @@ func TestRuntimeSResourceDictionaryValues_Destruction(t *testing.T) { assert.Equal(t, []string{ - `"destroying R"`, - "1", `"destroying R"`, "2", + `"destroying R"`, + "1", }, loggedMessages, ) diff --git a/runtime/runtime.go b/runtime/runtime.go index 2eb642fb6d..9b924624a5 100644 --- a/runtime/runtime.go +++ b/runtime/runtime.go @@ -1396,7 +1396,7 @@ func (r *interpreterRuntime) newInterpreter( signature *interpreter.ArrayValue, signedData *interpreter.ArrayValue, domainSeparationTag *interpreter.StringValue, - hashAlgorithm *interpreter.CompositeValue, + hashAlgorithm *interpreter.SimpleCompositeValue, publicKey interpreter.MemberAccessibleValue, ) interpreter.BoolValue { return verifySignature( @@ -3592,7 +3592,7 @@ func NewPublicKeyFromValue( return nil, runtimeErrors.NewUnexpectedError("sign algorithm is not set") } - signAlgoValue, ok := signAlgoField.(*interpreter.CompositeValue) + signAlgoValue, ok := signAlgoField.(*interpreter.SimpleCompositeValue) if !ok { return nil, runtimeErrors.NewUnexpectedError( "sign algorithm does not belong to type: %s", @@ -3600,7 +3600,7 @@ func NewPublicKeyFromValue( ) } - rawValue := signAlgoValue.GetField(inter, getLocationRange, sema.EnumRawValueFieldName) + rawValue := signAlgoValue.GetMember(inter, getLocationRange, sema.EnumRawValueFieldName) if rawValue == nil { return nil, runtimeErrors.NewDefaultUserError("sign algorithm raw value is not set") } @@ -3633,8 +3633,7 @@ func NewPublicKeyValue( publicKey.PublicKey, ), stdlib.NewSignatureAlgorithmCase( - inter, - publicKey.SignAlgo.RawValue(), + interpreter.UInt8Value(publicKey.SignAlgo.RawValue()), ), func( inter *interpreter.Interpreter, @@ -3661,7 +3660,9 @@ func NewAccountKeyValue( accountKey.PublicKey, validatePublicKey, ), - stdlib.NewHashAlgorithmCase(inter, accountKey.HashAlgo.RawValue()), + stdlib.NewHashAlgorithmCase( + interpreter.UInt8Value(accountKey.HashAlgo.RawValue()), + ), interpreter.NewUFix64ValueWithInteger( inter, func() uint64 { return uint64(accountKey.Weight) @@ -3676,9 +3677,9 @@ func NewHashAlgorithmFromValue( getLocationRange func() interpreter.LocationRange, value interpreter.Value, ) HashAlgorithm { - hashAlgoValue := value.(*interpreter.CompositeValue) + hashAlgoValue := value.(*interpreter.SimpleCompositeValue) - rawValue := hashAlgoValue.GetField(inter, getLocationRange, sema.EnumRawValueFieldName) + rawValue := hashAlgoValue.GetMember(inter, getLocationRange, sema.EnumRawValueFieldName) if rawValue == nil { panic("cannot find hash algorithm raw value") } @@ -3834,7 +3835,7 @@ func verifySignature( signatureValue *interpreter.ArrayValue, signedDataValue *interpreter.ArrayValue, domainSeparationTagValue *interpreter.StringValue, - hashAlgorithmValue *interpreter.CompositeValue, + hashAlgorithmValue *interpreter.SimpleCompositeValue, publicKeyValue interpreter.MemberAccessibleValue, runtimeInterface Interface, ) interpreter.BoolValue { diff --git a/runtime/stdlib/bls.go b/runtime/stdlib/bls.go index 186874a88d..3795444597 100644 --- a/runtime/stdlib/bls.go +++ b/runtime/stdlib/bls.go @@ -166,20 +166,22 @@ var blsContractFields = map[string]interpreter.Value{ blsAggregateSignaturesFunctionName: blsAggregateSignaturesFunction, } +var blsContractValue = interpreter.NewSimpleCompositeValue( + nil, + blsContractType.ID(), + blsContractStaticType, + nil, + blsContractFields, + nil, + nil, + nil, +) + var blsContract = StandardLibraryValue{ Name: "BLS", Type: blsContractType, - ValueFactory: func(inter *interpreter.Interpreter) interpreter.Value { - return interpreter.NewSimpleCompositeValue( - inter, - blsContractType.ID(), - blsContractStaticType, - nil, - blsContractFields, - nil, - nil, - nil, - ) + ValueFactory: func(_ *interpreter.Interpreter) interpreter.Value { + return blsContractValue }, Kind: common.DeclarationKindContract, } diff --git a/runtime/stdlib/crypto.go b/runtime/stdlib/crypto.go index 401f83b424..15747c2558 100644 --- a/runtime/stdlib/crypto.go +++ b/runtime/stdlib/crypto.go @@ -132,32 +132,37 @@ func cryptoAlgorithmEnumConstructorType( return constructorType } -type enumCaseConstructor func( - inter *interpreter.Interpreter, - rawValue uint8, -) *interpreter.CompositeValue +type enumCaseConstructor func(rawValue interpreter.UInt8Value) interpreter.MemberAccessibleValue func cryptoAlgorithmEnumValue( - inter *interpreter.Interpreter, enumType *sema.CompositeType, enumCases []sema.CryptoAlgorithm, caseConstructor enumCaseConstructor, ) interpreter.Value { caseCount := len(enumCases) - caseValues := make([]*interpreter.CompositeValue, caseCount) + caseValues := make([]struct { + Value interpreter.MemberAccessibleValue + RawValue interpreter.IntegerValue + }, caseCount) constructorNestedVariables := map[string]*interpreter.Variable{} for i, enumCase := range enumCases { - rawValue := enumCase.RawValue() - caseValue := caseConstructor(inter, rawValue) - caseValues[i] = caseValue + rawValue := interpreter.UInt8Value(enumCase.RawValue()) + caseValue := caseConstructor(rawValue) + caseValues[i] = struct { + Value interpreter.MemberAccessibleValue + RawValue interpreter.IntegerValue + }{ + Value: caseValue, + RawValue: rawValue, + } constructorNestedVariables[enumCase.Name()] = - interpreter.NewVariableWithValue(inter, caseValue) + interpreter.NewVariableWithValue(nil, caseValue) } return interpreter.EnumConstructorFunction( - inter, + nil, interpreter.ReturnEmptyLocationRange, enumType, caseValues, diff --git a/runtime/stdlib/hashalgorithm.go b/runtime/stdlib/hashalgorithm.go index 54659a3b53..8ab633519e 100644 --- a/runtime/stdlib/hashalgorithm.go +++ b/runtime/stdlib/hashalgorithm.go @@ -25,85 +25,89 @@ import ( "github.com/onflow/cadence/runtime/sema" ) -var hashAlgorithmFunctions = map[string]interpreter.FunctionValue{ - sema.HashAlgorithmTypeHashFunctionName: hashAlgorithmHashFunction, - sema.HashAlgorithmTypeHashWithTagFunctionName: hashAlgorithmHashWithTagFunction, +var hashAlgorithmTypeID = sema.HashAlgorithmType.ID() +var hashAlgorithmStaticType interpreter.StaticType = interpreter.CompositeStaticType{ + QualifiedIdentifier: sema.HashAlgorithmType.Identifier, + TypeID: hashAlgorithmTypeID, } -func NewHashAlgorithmCase(inter *interpreter.Interpreter, rawValue uint8) *interpreter.CompositeValue { - return interpreter.NewEnumCaseValue( - inter, - interpreter.ReturnEmptyLocationRange, - sema.HashAlgorithmType, - interpreter.NewUInt8Value(inter, func() uint8 { - return rawValue - }), - hashAlgorithmFunctions, +func NewHashAlgorithmCase(rawValue interpreter.UInt8Value) interpreter.MemberAccessibleValue { + + value := interpreter.NewSimpleCompositeValue( + nil, + sema.HashAlgorithmType.ID(), + hashAlgorithmStaticType, + []string{sema.EnumRawValueFieldName}, + nil, + nil, + nil, + nil, ) + value.Fields = map[string]interpreter.Value{ + sema.EnumRawValueFieldName: rawValue, + sema.HashAlgorithmTypeHashFunctionName: hashAlgorithmHashFunction(value), + sema.HashAlgorithmTypeHashWithTagFunctionName: hashAlgorithmHashWithTagFunction(value), + } + return value } -var hashAlgorithmHashFunction = interpreter.NewUnmeteredHostFunctionValue( - func(invocation interpreter.Invocation) interpreter.Value { - dataValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) - if !ok { - panic(errors.NewUnreachableError()) - } - hashAlgoValue := invocation.Self - - inter := invocation.Interpreter - - getLocationRange := invocation.GetLocationRange - - inter.ExpectType( - hashAlgoValue, - sema.HashAlgorithmType, - getLocationRange, - ) - - return inter.HashHandler( - inter, - getLocationRange, - dataValue, - nil, - hashAlgoValue, - ) - }, - sema.HashAlgorithmTypeHashFunctionType, -) +func hashAlgorithmHashFunction(hashAlgoValue interpreter.MemberAccessibleValue) *interpreter.HostFunctionValue { + return interpreter.NewUnmeteredHostFunctionValue( + func(invocation interpreter.Invocation) interpreter.Value { + dataValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) + if !ok { + panic(errors.NewUnreachableError()) + } + + inter := invocation.Interpreter + + getLocationRange := invocation.GetLocationRange + + return inter.HashHandler( + inter, + getLocationRange, + dataValue, + nil, + hashAlgoValue, + ) + }, + sema.HashAlgorithmTypeHashFunctionType, + ) +} -var hashAlgorithmHashWithTagFunction = interpreter.NewUnmeteredHostFunctionValue( - func(invocation interpreter.Invocation) interpreter.Value { - dataValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) - if !ok { - panic(errors.NewUnreachableError()) - } - - tagValue, ok := invocation.Arguments[1].(*interpreter.StringValue) - if !ok { - panic(errors.NewUnreachableError()) - } - - hashAlgoValue := invocation.Self - - inter := invocation.Interpreter - - getLocationRange := invocation.GetLocationRange - - inter.ExpectType( - hashAlgoValue, - sema.HashAlgorithmType, - getLocationRange, - ) - - return inter.HashHandler( - inter, - getLocationRange, - dataValue, - tagValue, - hashAlgoValue, - ) - }, - sema.HashAlgorithmTypeHashWithTagFunctionType, +func hashAlgorithmHashWithTagFunction(hashAlgoValue interpreter.MemberAccessibleValue) *interpreter.HostFunctionValue { + return interpreter.NewUnmeteredHostFunctionValue( + func(invocation interpreter.Invocation) interpreter.Value { + dataValue, ok := invocation.Arguments[0].(*interpreter.ArrayValue) + if !ok { + panic(errors.NewUnreachableError()) + } + + tagValue, ok := invocation.Arguments[1].(*interpreter.StringValue) + if !ok { + panic(errors.NewUnreachableError()) + } + + inter := invocation.Interpreter + + getLocationRange := invocation.GetLocationRange + + return inter.HashHandler( + inter, + getLocationRange, + dataValue, + tagValue, + hashAlgoValue, + ) + }, + sema.HashAlgorithmTypeHashWithTagFunctionType, + ) +} + +var hashAlgorithmConstructorValue = cryptoAlgorithmEnumValue( + sema.HashAlgorithmType, + sema.HashAlgorithms, + NewHashAlgorithmCase, ) var hashAlgorithmConstructor = StandardLibraryValue{ @@ -112,13 +116,8 @@ var hashAlgorithmConstructor = StandardLibraryValue{ sema.HashAlgorithmType, sema.HashAlgorithms, ), - ValueFactory: func(inter *interpreter.Interpreter) interpreter.Value { - return cryptoAlgorithmEnumValue( - inter, - sema.HashAlgorithmType, - sema.HashAlgorithms, - NewHashAlgorithmCase, - ) + ValueFactory: func(_ *interpreter.Interpreter) interpreter.Value { + return hashAlgorithmConstructorValue }, Kind: common.DeclarationKindEnum, } diff --git a/runtime/stdlib/publickey.go b/runtime/stdlib/publickey.go index 309a3d73a5..8967fd238a 100644 --- a/runtime/stdlib/publickey.go +++ b/runtime/stdlib/publickey.go @@ -52,7 +52,7 @@ var publicKeyConstructor = NewStandardLibraryFunction( panic(errors.NewUnreachableError()) } - signAlgo, ok := invocation.Arguments[1].(*interpreter.CompositeValue) + signAlgo, ok := invocation.Arguments[1].(*interpreter.SimpleCompositeValue) if !ok { panic(errors.NewUnreachableError()) } diff --git a/runtime/stdlib/rlp.go b/runtime/stdlib/rlp.go index 70aed46400..272c1020cc 100644 --- a/runtime/stdlib/rlp.go +++ b/runtime/stdlib/rlp.go @@ -229,20 +229,22 @@ var rlpContractFields = map[string]interpreter.Value{ rlpDecodeStringFunctionName: rlpDecodeStringFunction, } +var rlpContractValue = interpreter.NewSimpleCompositeValue( + nil, + rlpContractType.ID(), + rlpContractStaticType, + nil, + rlpContractFields, + nil, + nil, + nil, +) + var rlpContract = StandardLibraryValue{ Name: "RLP", Type: rlpContractType, - ValueFactory: func(inter *interpreter.Interpreter) interpreter.Value { - return interpreter.NewSimpleCompositeValue( - inter, - rlpContractType.ID(), - rlpContractStaticType, - nil, - rlpContractFields, - nil, - nil, - nil, - ) + ValueFactory: func(_ *interpreter.Interpreter) interpreter.Value { + return rlpContractValue }, Kind: common.DeclarationKindContract, } diff --git a/runtime/stdlib/signaturealgorithm.go b/runtime/stdlib/signaturealgorithm.go index 7a95f10455..6d12c3bfa3 100644 --- a/runtime/stdlib/signaturealgorithm.go +++ b/runtime/stdlib/signaturealgorithm.go @@ -24,18 +24,36 @@ import ( "github.com/onflow/cadence/runtime/sema" ) -func NewSignatureAlgorithmCase(inter *interpreter.Interpreter, rawValue uint8) *interpreter.CompositeValue { - return interpreter.NewEnumCaseValue( - inter, - interpreter.ReturnEmptyLocationRange, - sema.SignatureAlgorithmType, - interpreter.NewUInt8Value(inter, func() uint8 { - return rawValue - }), +var signatureAlgorithmTypeID = sema.SignatureAlgorithmType.ID() +var signatureAlgorithmStaticType interpreter.StaticType = interpreter.CompositeStaticType{ + QualifiedIdentifier: sema.SignatureAlgorithmType.Identifier, + TypeID: signatureAlgorithmTypeID, +} + +func NewSignatureAlgorithmCase(rawValue interpreter.UInt8Value) interpreter.MemberAccessibleValue { + + fields := map[string]interpreter.Value{ + sema.EnumRawValueFieldName: rawValue, + } + + return interpreter.NewSimpleCompositeValue( + nil, + sema.SignatureAlgorithmType.ID(), + signatureAlgorithmStaticType, + []string{sema.EnumRawValueFieldName}, + fields, + nil, + nil, nil, ) } +var signatureAlgorithmConstructorValue = cryptoAlgorithmEnumValue( + sema.SignatureAlgorithmType, + sema.SignatureAlgorithms, + NewSignatureAlgorithmCase, +) + var signatureAlgorithmConstructor = StandardLibraryValue{ Name: sema.SignatureAlgorithmTypeName, Type: cryptoAlgorithmEnumConstructorType( @@ -43,12 +61,7 @@ var signatureAlgorithmConstructor = StandardLibraryValue{ sema.SignatureAlgorithms, ), ValueFactory: func(inter *interpreter.Interpreter) interpreter.Value { - return cryptoAlgorithmEnumValue( - inter, - sema.SignatureAlgorithmType, - sema.SignatureAlgorithms, - NewSignatureAlgorithmCase, - ) + return signatureAlgorithmConstructorValue }, Kind: common.DeclarationKindEnum, } diff --git a/runtime/test-export-json-deterministic.txt b/runtime/test-export-json-deterministic.txt index 4229b3416c..941b3d974c 100644 --- a/runtime/test-export-json-deterministic.txt +++ b/runtime/test-export-json-deterministic.txt @@ -1 +1 @@ -{"type":"Event","value":{"id":"S.test.Foo","fields":[{"name":"bar","value":{"type":"Int","value":"2"}},{"name":"aaa","value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"1"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"a"}},{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":""}},{"key":{"type":"Int","value":"7"},"value":{"type":"String","value":"b"}},{"key":{"type":"Int","value":"2"},"value":{"type":"String","value":"a"}}]}},{"key":{"type":"Int","value":"2"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"b"}},{"key":{"type":"Int","value":"7"},"value":{"type":"String","value":"d"}},{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":"c"}}]}},{"key":{"type":"Int","value":"0"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"2"},"value":{"type":"String","value":"c"}},{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"c"}},{"key":{"type":"Int","value":"0"},"value":{"type":"String","value":"a"}},{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":"a"}}]}}]}}]}} +{"type":"Event","value":{"id":"S.test.Foo","fields":[{"name":"bar","value":{"type":"Int","value":"2"}},{"name":"aaa","value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"0"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"0"},"value":{"type":"String","value":"a"}},{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":"a"}},{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"c"}},{"key":{"type":"Int","value":"2"},"value":{"type":"String","value":"c"}}]}},{"key":{"type":"Int","value":"2"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":"c"}},{"key":{"type":"Int","value":"7"},"value":{"type":"String","value":"d"}},{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"b"}}]}},{"key":{"type":"Int","value":"1"},"value":{"type":"Dictionary","value":[{"key":{"type":"Int","value":"7"},"value":{"type":"String","value":"b"}},{"key":{"type":"Int","value":"1"},"value":{"type":"String","value":""}},{"key":{"type":"Int","value":"2"},"value":{"type":"String","value":"a"}},{"key":{"type":"Int","value":"3"},"value":{"type":"String","value":"a"}}]}}]}}]}} From ef769070da746aa2227f0cc9574423f0b1b0d574 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 22 Jul 2022 14:37:38 -0700 Subject: [PATCH 2/7] Add meeting notes for July 22, 2022 --- meetings/2022-07-22.md | 106 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 meetings/2022-07-22.md diff --git a/meetings/2022-07-22.md b/meetings/2022-07-22.md new file mode 100644 index 0000000000..1fda9cf08e --- /dev/null +++ b/meetings/2022-07-22.md @@ -0,0 +1,106 @@ + +# July 22, 2022 + +## External Mutability + +- FLIP that prevents external mutation was approved, implemented, and released in Secure Cadence: + [https://github.com/onflow/flow/pull/703](https://github.com/onflow/flow/pull/703) +- Open problems: + - Composites were not covered by the FLIP, only arrays and dictionaries + - Externally taking a reference to a field can circumvent the external mutability restriction +- New FLIP: [https://github.com/onflow/flow/pull/1056](https://github.com/onflow/flow/pull/1056) + - Purity/mutability modifier for functions + - Automatic analysis to determine if function has side-effects + +### Condition can currently have side effects: +- https://github.com/onflow/cadence/issues/1805 +- Might be used for underhanded code: Post-condition might perform mutation. Example: FT withdrawal +- Might be solved by purity FLIP +- Can a pure function emit events? + - Does affect on-chain state, but is not observable +- Are other side-effecting functons like debugging logging allowed? +- "Pure" vs "no side-effects" + - "Pure" usually means no side-effects at all + - Have to be pragmatic +- Alternatives: + - Prevent calls in general + - Run-time errors if there are side-effects + +## Remove deprecated key API +- We currently have two key management APIs: + - `AuthAccount.addPublicKey`/`AuthAccount.removePublicKey`: + - Low-level, accepts encoded key as byte array + - Deprecated a year ago + - [`AuthAccount.keys.add`](https://docs.onflow.org/cadence/language/accounts/#add-account-keys)/`AuthAccount.keys.remove` + - High-level, accepts key as object (`PublicKey`) + - Added a year ago +- We attempted to remove the deprecated in the Secure Cadence release + - Rolled back, as it will break client applications if they use SDK which uses deprecated API +- Also: Events that are emitted when a key is added is inconsistent, depends on which API is used: https://github.com/onflow/cadence/issues/1796 +- Do we have metrics on how many SDKs are still using the deprecated API? +- Actionables: + - Add deprecation annotation to developer tooling + - Pragma, e.g. `#deprecated` + - Comment, e.g. `@deprecated` + - Add support in VS Code, render as ~~addPublicKey~~ + +## Interface default methods +- https://github.com/onflow/cadence/pull/1076 +- Proposed for NFT metadata standard +- Helps with preventing breakage in ecosystem +- Avoid copy/paste and boilerplate, making code reusable +- Does not help with FT/NFT rewrite proposal +- Useful for utility/convenience functions, reducing boilerplate +- Open Questions: + - Security implications? + - Related: + - Post-conditions with side-effects + - Mutability + - Restrict to pure functions? Potentially too restrictive, e.g. couldn’t provide + - Maybe allow opt out of mutating functions. But could also be used to opt-out of a fix + - Examples? + - Trust relationship problem + - Already have this problem with contract updates + - Modification of default implementation + - Would be useful to provide utility functions, like FT transfer + - It should not be possible to perform malicious code, as the same could be done in a non-default function +- Not a breaking change, could merge and ship before Stable Cadence +- When there is a conflict, e.g multiple interfaces provide default implementation: + - No "winner" is selected by default + - Instead, the user is required to provide an implementation +- Follow up feature: Interface requirements + - Declaration site: `CI1: CI2` + - Use-site would still have to explicitly declare conformance for all interfaces: `C: CI1, CI2` + +## Storage Querying/Iteration API +- https://github.com/onflow/cadence/issues/208 +- Finally added technical foundation a couple months ago: + Account storage data is now stored in [atree](https://github.com/onflow/atree) values + (atree is Cadence's storage layer) +- Issue lays out proposal for adding API to iterate over account paths/values +- Outstanding issues: + - Accounts may store a lot of data. Pagination iteration? Iterator, cursor, enumerator + - Concrete API proposal +- First use-case: Developer tools like the Emulator and Playground +- Need to show wallet developers how they can render information to users +- Mutability not necessarily a problem: Run script against block. + - Problem: data availability + - Might be solved in future by "historic" data node +- Storage Layer: + - Iteration over dictionary changes when mutated + - Keys are hashed +- Start with MVP +- Stages: + - 1. Even useful if pagination problem is not solved yet + - 2. Pagination for larger accounts + - 3. Support for handling mutation +- Also useful for e.g. dictionary, keys. Might be too large + - Keys on demand + - E.g. useful to pick a random key + +## Organisational + +- Should we move this meeting so it is not on a Friday evening for folks in Europe? + - Not Friday, not Monday + - Tuesday is best + - Same time (8am PT) From 03004466c23640f13d8f5fef93aa6c85672ef97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Fri, 22 Jul 2022 19:07:39 -0700 Subject: [PATCH 3/7] optimize elaboration --- runtime/compiler/compiler.go | 2 +- runtime/interpreter/interpreter_expression.go | 28 +-- runtime/interpreter/interpreter_statement.go | 30 ++-- runtime/sema/check_array_expression.go | 8 +- runtime/sema/check_assignment.go | 7 +- runtime/sema/check_binary_expression.go | 8 +- runtime/sema/check_casting_expression.go | 20 ++- runtime/sema/check_dictionary_expression.go | 7 +- runtime/sema/check_expression.go | 6 +- runtime/sema/check_invocation_expression.go | 18 +- runtime/sema/check_return_statement.go | 7 +- runtime/sema/check_swap.go | 7 +- runtime/sema/check_variable_declaration.go | 17 +- runtime/sema/elaboration.go | 164 ++++++++++-------- runtime/tests/checker/conditions_test.go | 3 +- runtime/tests/checker/genericfunction_test.go | 12 +- 16 files changed, 201 insertions(+), 143 deletions(-) diff --git a/runtime/compiler/compiler.go b/runtime/compiler/compiler.go index 0b23e80c83..287d8bd42f 100644 --- a/runtime/compiler/compiler.go +++ b/runtime/compiler/compiler.go @@ -105,7 +105,7 @@ func (compiler *Compiler) VisitVariableDeclaration(declaration *ast.VariableDecl // TODO: second value identifier := declaration.Identifier.Identifier - targetType := compiler.Checker.Elaboration.VariableDeclarationTargetTypes[declaration] + targetType := compiler.Checker.Elaboration.VariableDeclarationTypes[declaration].TargetType valType := compileValueType(targetType) local := compiler.declareLocal(identifier, valType) exp := declaration.Value.Accept(compiler).(ir.Expr) diff --git a/runtime/interpreter/interpreter_expression.go b/runtime/interpreter/interpreter_expression.go index 46171e63c3..e9cb9fba22 100644 --- a/runtime/interpreter/interpreter_expression.go +++ b/runtime/interpreter/interpreter_expression.go @@ -91,8 +91,9 @@ func (interpreter *Interpreter) indexExpressionGetterSetter(indexExpression *ast elaboration := interpreter.Program.Elaboration - indexedType := elaboration.IndexExpressionIndexedTypes[indexExpression] - indexingType := elaboration.IndexExpressionIndexingTypes[indexExpression] + indexExpressionTypes := elaboration.IndexExpressionTypes[indexExpression] + indexedType := indexExpressionTypes.IndexedType + indexingType := indexExpressionTypes.IndexingType transferredIndexingValue := interpreter.transferAndConvert( interpreter.evalExpression(indexExpression.IndexingExpression), @@ -428,8 +429,9 @@ func (interpreter *Interpreter) VisitBinaryExpression(expression *ast.BinaryExpr value := rightValue() - rightType := interpreter.Program.Elaboration.BinaryExpressionRightTypes[expression] - resultType := interpreter.Program.Elaboration.BinaryExpressionResultTypes[expression] + binaryExpressionTypes := interpreter.Program.Elaboration.BinaryExpressionTypes[expression] + rightType := binaryExpressionTypes.RightType + resultType := binaryExpressionTypes.ResultType // NOTE: important to convert both any and optional return interpreter.ConvertAndBox(getLocationRange, value, rightType, resultType) @@ -650,8 +652,9 @@ func (interpreter *Interpreter) VisitStringExpression(expression *ast.StringExpr func (interpreter *Interpreter) VisitArrayExpression(expression *ast.ArrayExpression) ast.Repr { values := interpreter.visitExpressionsNonCopying(expression.Values) - argumentTypes := interpreter.Program.Elaboration.ArrayExpressionArgumentTypes[expression] - arrayType := interpreter.Program.Elaboration.ArrayExpressionArrayType[expression] + arrayExpressionTypes := interpreter.Program.Elaboration.ArrayExpressionTypes[expression] + argumentTypes := arrayExpressionTypes.ArgumentTypes + arrayType := arrayExpressionTypes.ArrayType elementType := arrayType.ElementType(false) copies := make([]Value, len(values)) @@ -679,8 +682,9 @@ func (interpreter *Interpreter) VisitArrayExpression(expression *ast.ArrayExpres func (interpreter *Interpreter) VisitDictionaryExpression(expression *ast.DictionaryExpression) ast.Repr { values := interpreter.visitEntries(expression.Entries) - entryTypes := interpreter.Program.Elaboration.DictionaryExpressionEntryTypes[expression] - dictionaryType := interpreter.Program.Elaboration.DictionaryExpressionType[expression] + dictionaryExpressionTypes := interpreter.Program.Elaboration.DictionaryExpressionTypes[expression] + entryTypes := dictionaryExpressionTypes.EntryTypes + dictionaryType := dictionaryExpressionTypes.DictionaryType var keyValuePairs []Value @@ -806,9 +810,11 @@ func (interpreter *Interpreter) VisitInvocationExpression(invocationExpression * elaboration := interpreter.Program.Elaboration - typeParameterTypes := elaboration.InvocationExpressionTypeArguments[invocationExpression] - argumentTypes := elaboration.InvocationExpressionArgumentTypes[invocationExpression] - parameterTypes := elaboration.InvocationExpressionParameterTypes[invocationExpression] + invocationExpressionTypes := elaboration.InvocationExpressionTypes[invocationExpression] + + typeParameterTypes := invocationExpressionTypes.TypeArguments + argumentTypes := invocationExpressionTypes.ArgumentTypes + parameterTypes := invocationExpressionTypes.TypeParameterTypes line := invocationExpression.StartPosition().Line diff --git a/runtime/interpreter/interpreter_statement.go b/runtime/interpreter/interpreter_statement.go index 8b7b943c14..4044bd27fe 100644 --- a/runtime/interpreter/interpreter_statement.go +++ b/runtime/interpreter/interpreter_statement.go @@ -73,8 +73,9 @@ func (interpreter *Interpreter) VisitReturnStatement(statement *ast.ReturnStatem } else { value = interpreter.evalExpression(statement.Expression) - valueType := interpreter.Program.Elaboration.ReturnStatementValueTypes[statement] - returnType := interpreter.Program.Elaboration.ReturnStatementReturnTypes[statement] + returnStatementTypes := interpreter.Program.Elaboration.ReturnStatementTypes[statement] + valueType := returnStatementTypes.ValueType + returnType := returnStatementTypes.ReturnType getLocationRange := locationRangeGetter(interpreter, interpreter.Location, statement.Expression) @@ -149,10 +150,11 @@ func (interpreter *Interpreter) visitIfStatementWithVariableDeclaration( panic(errors.NewUnreachableError()) } - valueType := interpreter.Program.Elaboration.VariableDeclarationValueTypes[declaration] + variableDeclarationTypes := interpreter.Program.Elaboration.VariableDeclarationTypes[declaration] + valueType := variableDeclarationTypes.ValueType if declaration.SecondValue != nil { - secondValueType := interpreter.Program.Elaboration.VariableDeclarationSecondValueTypes[declaration] + secondValueType := variableDeclarationTypes.SecondValueType interpreter.visitAssignment( declaration.Transfer.Operation, @@ -167,7 +169,7 @@ func (interpreter *Interpreter) visitIfStatementWithVariableDeclaration( var result any if someValue, ok := value.(*SomeValue); ok { - targetType := interpreter.Program.Elaboration.VariableDeclarationTargetTypes[declaration] + targetType := variableDeclarationTypes.TargetType getLocationRange := locationRangeGetter(interpreter, interpreter.Location, declaration.Value) innerValue := someValue.InnerValue(interpreter, getLocationRange) transferredUnwrappedValue := interpreter.transferAndConvert( @@ -416,9 +418,10 @@ func (interpreter *Interpreter) visitVariableDeclaration( valueCallback func(identifier string, value Value), ) { - targetType := interpreter.Program.Elaboration.VariableDeclarationTargetTypes[declaration] - valueType := interpreter.Program.Elaboration.VariableDeclarationValueTypes[declaration] - secondValueType := interpreter.Program.Elaboration.VariableDeclarationSecondValueTypes[declaration] + variableDeclarationTypes := interpreter.Program.Elaboration.VariableDeclarationTypes[declaration] + targetType := variableDeclarationTypes.TargetType + valueType := variableDeclarationTypes.ValueType + secondValueType := variableDeclarationTypes.SecondValueType // NOTE: It is *REQUIRED* that the getter for the value is used // instead of just evaluating value expression, @@ -465,8 +468,9 @@ func (interpreter *Interpreter) visitVariableDeclaration( } func (interpreter *Interpreter) VisitAssignmentStatement(assignment *ast.AssignmentStatement) ast.Repr { - targetType := interpreter.Program.Elaboration.AssignmentStatementTargetTypes[assignment] - valueType := interpreter.Program.Elaboration.AssignmentStatementValueTypes[assignment] + assignmentStatementTypes := interpreter.Program.Elaboration.AssignmentStatementTypes[assignment] + targetType := assignmentStatementTypes.TargetType + valueType := assignmentStatementTypes.ValueType target := assignment.Target value := assignment.Value @@ -482,9 +486,9 @@ func (interpreter *Interpreter) VisitAssignmentStatement(assignment *ast.Assignm } func (interpreter *Interpreter) VisitSwapStatement(swap *ast.SwapStatement) ast.Repr { - - leftType := interpreter.Program.Elaboration.SwapStatementLeftTypes[swap] - rightType := interpreter.Program.Elaboration.SwapStatementRightTypes[swap] + swapStatementTypes := interpreter.Program.Elaboration.SwapStatementTypes[swap] + leftType := swapStatementTypes.LeftType + rightType := swapStatementTypes.RightType const allowMissing = false diff --git a/runtime/sema/check_array_expression.go b/runtime/sema/check_array_expression.go index b980cef77b..8f0fb5b7c0 100644 --- a/runtime/sema/check_array_expression.go +++ b/runtime/sema/check_array_expression.go @@ -73,8 +73,6 @@ func (checker *Checker) VisitArrayExpression(expression *ast.ArrayExpression) as checker.checkResourceMoveOperation(value, valueType) } - checker.Elaboration.ArrayExpressionArgumentTypes[expression] = argumentTypes - if elementType == nil { // Contextually expected type is not available. // Therefore, find the least common supertype of the elements. @@ -96,7 +94,11 @@ func (checker *Checker) VisitArrayExpression(expression *ast.ArrayExpression) as } } - checker.Elaboration.ArrayExpressionArrayType[expression] = resultType + checker.Elaboration.ArrayExpressionTypes[expression] = + ArrayExpressionTypes{ + ArgumentTypes: argumentTypes, + ArrayType: resultType, + } return resultType } diff --git a/runtime/sema/check_assignment.go b/runtime/sema/check_assignment.go index 7afe1cc5f1..87b3f4bc49 100644 --- a/runtime/sema/check_assignment.go +++ b/runtime/sema/check_assignment.go @@ -32,8 +32,11 @@ func (checker *Checker) VisitAssignmentStatement(assignment *ast.AssignmentState false, ) - checker.Elaboration.AssignmentStatementValueTypes[assignment] = valueType - checker.Elaboration.AssignmentStatementTargetTypes[assignment] = targetType + checker.Elaboration.AssignmentStatementTypes[assignment] = + AssignmentStatementTypes{ + ValueType: valueType, + TargetType: targetType, + } return nil } diff --git a/runtime/sema/check_binary_expression.go b/runtime/sema/check_binary_expression.go index 32b7e6bc93..402a964c7a 100644 --- a/runtime/sema/check_binary_expression.go +++ b/runtime/sema/check_binary_expression.go @@ -29,9 +29,11 @@ func (checker *Checker) VisitBinaryExpression(expression *ast.BinaryExpression) var leftType, rightType, resultType Type defer func() { elaboration := checker.Elaboration - elaboration.BinaryExpressionLeftTypes[expression] = leftType - elaboration.BinaryExpressionRightTypes[expression] = rightType - elaboration.BinaryExpressionResultTypes[expression] = resultType + elaboration.BinaryExpressionTypes[expression] = BinaryExpressionTypes{ + LeftType: leftType, + RightType: rightType, + ResultType: resultType, + } }() // The left-hand side is always evaluated. diff --git a/runtime/sema/check_casting_expression.go b/runtime/sema/check_casting_expression.go index ea3123601d..4253662724 100644 --- a/runtime/sema/check_casting_expression.go +++ b/runtime/sema/check_casting_expression.go @@ -125,10 +125,11 @@ func (checker *Checker) VisitCastingExpression(expression *ast.CastingExpression }, ) } else if checker.extendedElaboration { - checker.Elaboration.RuntimeCastTypes[expression] = struct { - Left Type - Right Type - }{Left: leftHandType, Right: rightHandType} + checker.Elaboration.RuntimeCastTypes[expression] = + RuntimeCastTypes{ + Left: leftHandType, + Right: rightHandType, + } } } @@ -144,11 +145,12 @@ func (checker *Checker) VisitCastingExpression(expression *ast.CastingExpression // Then, it is not possible to determine whether the target type is redundant. // Therefore, don't check for redundant casts, if there are errors. if checker.extendedElaboration && !hasErrors { - checker.Elaboration.StaticCastTypes[expression] = CastType{ - ExprActualType: exprActualType, - TargetType: rightHandType, - ExpectedType: checker.expectedType, - } + checker.Elaboration.StaticCastTypes[expression] = + CastTypes{ + ExprActualType: exprActualType, + TargetType: rightHandType, + ExpectedType: checker.expectedType, + } } return rightHandType diff --git a/runtime/sema/check_dictionary_expression.go b/runtime/sema/check_dictionary_expression.go index af7b8fbd1b..6327ffebf1 100644 --- a/runtime/sema/check_dictionary_expression.go +++ b/runtime/sema/check_dictionary_expression.go @@ -96,8 +96,11 @@ func (checker *Checker) VisitDictionaryExpression(expression *ast.DictionaryExpr ValueType: valueType, } - checker.Elaboration.DictionaryExpressionEntryTypes[expression] = entryTypes - checker.Elaboration.DictionaryExpressionType[expression] = dictionaryType + checker.Elaboration.DictionaryExpressionTypes[expression] = + DictionaryExpressionTypes{ + EntryTypes: entryTypes, + DictionaryType: dictionaryType, + } return dictionaryType } diff --git a/runtime/sema/check_expression.go b/runtime/sema/check_expression.go index 76d4bd67d4..f029c4b3df 100644 --- a/runtime/sema/check_expression.go +++ b/runtime/sema/check_expression.go @@ -291,8 +291,10 @@ func (checker *Checker) visitIndexExpression( checker.checkUnusedExpressionResourceLoss(elementType, targetExpression) - checker.Elaboration.IndexExpressionIndexedTypes[indexExpression] = indexedType - checker.Elaboration.IndexExpressionIndexingTypes[indexExpression] = indexingType + checker.Elaboration.IndexExpressionTypes[indexExpression] = IndexExpressionTypes{ + IndexedType: indexedType, + IndexingType: indexingType, + } return elementType } diff --git a/runtime/sema/check_invocation_expression.go b/runtime/sema/check_invocation_expression.go index 7fa8c8b6dc..77b18abcb0 100644 --- a/runtime/sema/check_invocation_expression.go +++ b/runtime/sema/check_invocation_expression.go @@ -80,9 +80,6 @@ func (checker *Checker) checkInvocationExpression(invocationExpression *ast.Invo } var argumentTypes []Type - defer func() { - checker.Elaboration.InvocationExpressionArgumentTypes[invocationExpression] = argumentTypes - }() functionType, ok := expressionType.(*FunctionType) if !ok { @@ -102,7 +99,11 @@ func (checker *Checker) checkInvocationExpression(invocationExpression *ast.Invo argumentTypes = append(argumentTypes, argumentType) } - checker.Elaboration.InvocationExpressionReturnTypes[invocationExpression] = checker.expectedType + checker.Elaboration.InvocationExpressionTypes[invocationExpression] = + InvocationExpressionTypes{ + ArgumentTypes: argumentTypes, + ReturnType: checker.expectedType, + } return InvalidType } @@ -482,9 +483,12 @@ func (checker *Checker) checkInvocation( // Save types in the elaboration - checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] = typeArguments - checker.Elaboration.InvocationExpressionParameterTypes[invocationExpression] = parameterTypes - checker.Elaboration.InvocationExpressionReturnTypes[invocationExpression] = returnType + checker.Elaboration.InvocationExpressionTypes[invocationExpression] = InvocationExpressionTypes{ + TypeArguments: typeArguments, + TypeParameterTypes: parameterTypes, + ReturnType: returnType, + ArgumentTypes: argumentTypes, + } return argumentTypes, returnType } diff --git a/runtime/sema/check_return_statement.go b/runtime/sema/check_return_statement.go index 1ed39a24c5..78d7faf9e6 100644 --- a/runtime/sema/check_return_statement.go +++ b/runtime/sema/check_return_statement.go @@ -55,8 +55,11 @@ func (checker *Checker) VisitReturnStatement(statement *ast.ReturnStatement) ast valueType := checker.VisitExpression(statement.Expression, returnType) - checker.Elaboration.ReturnStatementValueTypes[statement] = valueType - checker.Elaboration.ReturnStatementReturnTypes[statement] = returnType + checker.Elaboration.ReturnStatementTypes[statement] = + ReturnStatementTypes{ + ValueType: valueType, + ReturnType: returnType, + } if returnType == VoidType { return nil diff --git a/runtime/sema/check_swap.go b/runtime/sema/check_swap.go index 5e899595fc..0d92eca00b 100644 --- a/runtime/sema/check_swap.go +++ b/runtime/sema/check_swap.go @@ -28,8 +28,11 @@ func (checker *Checker) VisitSwapStatement(swap *ast.SwapStatement) ast.Repr { leftType := checker.VisitExpression(swap.Left, nil) rightType := checker.VisitExpression(swap.Right, nil) - checker.Elaboration.SwapStatementLeftTypes[swap] = leftType - checker.Elaboration.SwapStatementRightTypes[swap] = rightType + checker.Elaboration.SwapStatementTypes[swap] = + SwapStatementTypes{ + LeftType: leftType, + RightType: rightType, + } lhsValid := checker.checkSwapStatementExpression(swap.Left, leftType, common.OperandSideLeft) rhsValid := checker.checkSwapStatementExpression(swap.Right, rightType, common.OperandSideRight) diff --git a/runtime/sema/check_variable_declaration.go b/runtime/sema/check_variable_declaration.go index e53e79952a..dadf68e0c7 100644 --- a/runtime/sema/check_variable_declaration.go +++ b/runtime/sema/check_variable_declaration.go @@ -61,8 +61,6 @@ func (checker *Checker) visitVariableDeclaration(declaration *ast.VariableDeclar valueType := checker.VisitExpression(declaration.Value, expectedValueType) - checker.Elaboration.VariableDeclarationValueTypes[declaration] = valueType - if isOptionalBinding { optionalType, isOptional := valueType.(*OptionalType) @@ -85,8 +83,6 @@ func (checker *Checker) visitVariableDeclaration(declaration *ast.VariableDeclar declarationType = valueType } - checker.Elaboration.VariableDeclarationTargetTypes[declaration] = declarationType - checker.checkTransfer(declaration.Transfer, declarationType) // The variable declaration might have a second transfer and second expression. @@ -98,6 +94,8 @@ func (checker *Checker) visitVariableDeclaration(declaration *ast.VariableDeclar // This is only valid for resources, i.e. the declaration type, first value type, // and the second value type must be resource types, and all transfers must be moves. + var secondValueType Type + if declaration.SecondTransfer == nil { if declaration.SecondValue != nil { panic(errors.NewUnreachableError()) @@ -158,21 +156,26 @@ func (checker *Checker) visitVariableDeclaration(declaration *ast.VariableDeclar // NOTE: already performs resource invalidation - _, secondValueType := checker.checkAssignment( + _, secondValueType = checker.checkAssignment( declaration.Value, declaration.SecondValue, declaration.SecondTransfer, true, ) - checker.Elaboration.VariableDeclarationSecondValueTypes[declaration] = secondValueType - if valueIsResource { checker.elaborateNestedResourceMoveExpression(declaration.Value) } } } + checker.Elaboration.VariableDeclarationTypes[declaration] = + VariableDeclarationTypes{ + TargetType: declarationType, + ValueType: valueType, + SecondValueType: secondValueType, + } + // Finally, declare the variable in the current value activation identifier := declaration.Identifier.Identifier diff --git a/runtime/sema/elaboration.go b/runtime/sema/elaboration.go index 3c8d798309..b16ecb7055 100644 --- a/runtime/sema/elaboration.go +++ b/runtime/sema/elaboration.go @@ -31,49 +31,91 @@ type MemberInfo struct { AccessedType Type } -type CastType struct { +type CastTypes struct { ExprActualType Type TargetType Type ExpectedType Type } +type RuntimeCastTypes struct { + Left Type + Right Type +} + +type ReturnStatementTypes struct { + ValueType Type + ReturnType Type +} + +type BinaryExpressionTypes struct { + ResultType Type + LeftType Type + RightType Type +} + +type VariableDeclarationTypes struct { + ValueType Type + SecondValueType Type + TargetType Type +} + +type AssignmentStatementTypes struct { + ValueType Type + TargetType Type +} + +type InvocationExpressionTypes struct { + ArgumentTypes []Type + TypeParameterTypes []Type + ReturnType Type + TypeArguments *TypeParameterTypeOrderedMap +} + +type ArrayExpressionTypes struct { + ArgumentTypes []Type + ArrayType ArrayType +} + +type DictionaryExpressionTypes struct { + DictionaryType *DictionaryType + EntryTypes []DictionaryEntryType +} + +type SwapStatementTypes struct { + LeftType Type + RightType Type +} + +type IndexExpressionTypes struct { + IndexedType ValueIndexableType + IndexingType Type +} + type Elaboration struct { - lock *sync.RWMutex - FunctionDeclarationFunctionTypes map[*ast.FunctionDeclaration]*FunctionType - VariableDeclarationValueTypes map[*ast.VariableDeclaration]Type - VariableDeclarationSecondValueTypes map[*ast.VariableDeclaration]Type - VariableDeclarationTargetTypes map[*ast.VariableDeclaration]Type - AssignmentStatementValueTypes map[*ast.AssignmentStatement]Type - AssignmentStatementTargetTypes map[*ast.AssignmentStatement]Type - CompositeDeclarationTypes map[*ast.CompositeDeclaration]*CompositeType - CompositeTypeDeclarations map[*CompositeType]*ast.CompositeDeclaration - InterfaceDeclarationTypes map[*ast.InterfaceDeclaration]*InterfaceType - InterfaceTypeDeclarations map[*InterfaceType]*ast.InterfaceDeclaration - ConstructorFunctionTypes map[*ast.SpecialFunctionDeclaration]*FunctionType - FunctionExpressionFunctionType map[*ast.FunctionExpression]*FunctionType - InvocationExpressionArgumentTypes map[*ast.InvocationExpression][]Type - InvocationExpressionParameterTypes map[*ast.InvocationExpression][]Type - InvocationExpressionReturnTypes map[*ast.InvocationExpression]Type - InvocationExpressionTypeArguments map[*ast.InvocationExpression]*TypeParameterTypeOrderedMap - CastingStaticValueTypes map[*ast.CastingExpression]Type - CastingTargetTypes map[*ast.CastingExpression]Type - ReturnStatementValueTypes map[*ast.ReturnStatement]Type - ReturnStatementReturnTypes map[*ast.ReturnStatement]Type - BinaryExpressionResultTypes map[*ast.BinaryExpression]Type - BinaryExpressionLeftTypes map[*ast.BinaryExpression]Type - BinaryExpressionRightTypes map[*ast.BinaryExpression]Type - MemberExpressionMemberInfos map[*ast.MemberExpression]MemberInfo - MemberExpressionExpectedTypes map[*ast.MemberExpression]Type - ArrayExpressionArgumentTypes map[*ast.ArrayExpression][]Type - ArrayExpressionArrayType map[*ast.ArrayExpression]ArrayType - DictionaryExpressionType map[*ast.DictionaryExpression]*DictionaryType - DictionaryExpressionEntryTypes map[*ast.DictionaryExpression][]DictionaryEntryType - IntegerExpressionType map[*ast.IntegerExpression]Type - StringExpressionType map[*ast.StringExpression]Type - FixedPointExpression map[*ast.FixedPointExpression]Type - TransactionDeclarationTypes map[*ast.TransactionDeclaration]*TransactionType - SwapStatementLeftTypes map[*ast.SwapStatement]Type - SwapStatementRightTypes map[*ast.SwapStatement]Type + lock *sync.RWMutex + FunctionDeclarationFunctionTypes map[*ast.FunctionDeclaration]*FunctionType + VariableDeclarationTypes map[*ast.VariableDeclaration]VariableDeclarationTypes + AssignmentStatementTypes map[*ast.AssignmentStatement]AssignmentStatementTypes + CompositeDeclarationTypes map[*ast.CompositeDeclaration]*CompositeType + CompositeTypeDeclarations map[*CompositeType]*ast.CompositeDeclaration + InterfaceDeclarationTypes map[*ast.InterfaceDeclaration]*InterfaceType + InterfaceTypeDeclarations map[*InterfaceType]*ast.InterfaceDeclaration + ConstructorFunctionTypes map[*ast.SpecialFunctionDeclaration]*FunctionType + FunctionExpressionFunctionType map[*ast.FunctionExpression]*FunctionType + InvocationExpressionTypes map[*ast.InvocationExpression]InvocationExpressionTypes + CastingStaticValueTypes map[*ast.CastingExpression]Type + CastingTargetTypes map[*ast.CastingExpression]Type + ReturnStatementTypes map[*ast.ReturnStatement]ReturnStatementTypes + BinaryExpressionTypes map[*ast.BinaryExpression]BinaryExpressionTypes + MemberExpressionMemberInfos map[*ast.MemberExpression]MemberInfo + MemberExpressionExpectedTypes map[*ast.MemberExpression]Type + ArrayExpressionTypes map[*ast.ArrayExpression]ArrayExpressionTypes + DictionaryExpressionTypes map[*ast.DictionaryExpression]DictionaryExpressionTypes + IntegerExpressionType map[*ast.IntegerExpression]Type + StringExpressionType map[*ast.StringExpression]Type + FixedPointExpression map[*ast.FixedPointExpression]Type + TransactionDeclarationTypes map[*ast.TransactionDeclaration]*TransactionType + SwapStatementTypes map[*ast.SwapStatement]SwapStatementTypes // IsNestedResourceMoveExpression indicates if the access the index or member expression // is implicitly moving a resource out of the container, e.g. in a shift or swap statement. IsNestedResourceMoveExpression map[ast.Expression]struct{} @@ -92,18 +134,14 @@ type Elaboration struct { EffectivePredeclaredTypes map[string]TypeDeclaration isChecking bool ReferenceExpressionBorrowTypes map[*ast.ReferenceExpression]Type - IndexExpressionIndexedTypes map[*ast.IndexExpression]ValueIndexableType - IndexExpressionIndexingTypes map[*ast.IndexExpression]Type + IndexExpressionTypes map[*ast.IndexExpression]IndexExpressionTypes ForceExpressionTypes map[*ast.ForceExpression]Type - StaticCastTypes map[*ast.CastingExpression]CastType + StaticCastTypes map[*ast.CastingExpression]CastTypes NumberConversionArgumentTypes map[ast.Expression]struct { Type Type Range ast.Range } - RuntimeCastTypes map[*ast.CastingExpression]struct { - Left Type - Right Type - } + RuntimeCastTypes map[*ast.CastingExpression]RuntimeCastTypes } func NewElaboration(gauge common.MemoryGauge, extendedElaboration bool) *Elaboration { @@ -111,40 +149,28 @@ func NewElaboration(gauge common.MemoryGauge, extendedElaboration bool) *Elabora elaboration := &Elaboration{ lock: new(sync.RWMutex), FunctionDeclarationFunctionTypes: map[*ast.FunctionDeclaration]*FunctionType{}, - VariableDeclarationValueTypes: map[*ast.VariableDeclaration]Type{}, - VariableDeclarationSecondValueTypes: map[*ast.VariableDeclaration]Type{}, - VariableDeclarationTargetTypes: map[*ast.VariableDeclaration]Type{}, - AssignmentStatementValueTypes: map[*ast.AssignmentStatement]Type{}, - AssignmentStatementTargetTypes: map[*ast.AssignmentStatement]Type{}, + VariableDeclarationTypes: map[*ast.VariableDeclaration]VariableDeclarationTypes{}, + AssignmentStatementTypes: map[*ast.AssignmentStatement]AssignmentStatementTypes{}, CompositeDeclarationTypes: map[*ast.CompositeDeclaration]*CompositeType{}, CompositeTypeDeclarations: map[*CompositeType]*ast.CompositeDeclaration{}, InterfaceDeclarationTypes: map[*ast.InterfaceDeclaration]*InterfaceType{}, InterfaceTypeDeclarations: map[*InterfaceType]*ast.InterfaceDeclaration{}, ConstructorFunctionTypes: map[*ast.SpecialFunctionDeclaration]*FunctionType{}, FunctionExpressionFunctionType: map[*ast.FunctionExpression]*FunctionType{}, - InvocationExpressionArgumentTypes: map[*ast.InvocationExpression][]Type{}, - InvocationExpressionParameterTypes: map[*ast.InvocationExpression][]Type{}, - InvocationExpressionReturnTypes: map[*ast.InvocationExpression]Type{}, - InvocationExpressionTypeArguments: map[*ast.InvocationExpression]*TypeParameterTypeOrderedMap{}, + InvocationExpressionTypes: map[*ast.InvocationExpression]InvocationExpressionTypes{}, CastingStaticValueTypes: map[*ast.CastingExpression]Type{}, CastingTargetTypes: map[*ast.CastingExpression]Type{}, - ReturnStatementValueTypes: map[*ast.ReturnStatement]Type{}, - ReturnStatementReturnTypes: map[*ast.ReturnStatement]Type{}, - BinaryExpressionResultTypes: map[*ast.BinaryExpression]Type{}, - BinaryExpressionLeftTypes: map[*ast.BinaryExpression]Type{}, - BinaryExpressionRightTypes: map[*ast.BinaryExpression]Type{}, + ReturnStatementTypes: map[*ast.ReturnStatement]ReturnStatementTypes{}, + BinaryExpressionTypes: map[*ast.BinaryExpression]BinaryExpressionTypes{}, MemberExpressionMemberInfos: map[*ast.MemberExpression]MemberInfo{}, MemberExpressionExpectedTypes: map[*ast.MemberExpression]Type{}, - ArrayExpressionArgumentTypes: map[*ast.ArrayExpression][]Type{}, - ArrayExpressionArrayType: map[*ast.ArrayExpression]ArrayType{}, - DictionaryExpressionType: map[*ast.DictionaryExpression]*DictionaryType{}, - DictionaryExpressionEntryTypes: map[*ast.DictionaryExpression][]DictionaryEntryType{}, + ArrayExpressionTypes: map[*ast.ArrayExpression]ArrayExpressionTypes{}, + DictionaryExpressionTypes: map[*ast.DictionaryExpression]DictionaryExpressionTypes{}, IntegerExpressionType: map[*ast.IntegerExpression]Type{}, StringExpressionType: map[*ast.StringExpression]Type{}, FixedPointExpression: map[*ast.FixedPointExpression]Type{}, TransactionDeclarationTypes: map[*ast.TransactionDeclaration]*TransactionType{}, - SwapStatementLeftTypes: map[*ast.SwapStatement]Type{}, - SwapStatementRightTypes: map[*ast.SwapStatement]Type{}, + SwapStatementTypes: map[*ast.SwapStatement]SwapStatementTypes{}, IsNestedResourceMoveExpression: map[ast.Expression]struct{}{}, CompositeNestedDeclarations: map[*ast.CompositeDeclaration]map[string]ast.Declaration{}, InterfaceNestedDeclarations: map[*ast.InterfaceDeclaration]map[string]ast.Declaration{}, @@ -159,16 +185,12 @@ func NewElaboration(gauge common.MemoryGauge, extendedElaboration bool) *Elabora EffectivePredeclaredValues: map[string]ValueDeclaration{}, EffectivePredeclaredTypes: map[string]TypeDeclaration{}, ReferenceExpressionBorrowTypes: map[*ast.ReferenceExpression]Type{}, - IndexExpressionIndexedTypes: map[*ast.IndexExpression]ValueIndexableType{}, - IndexExpressionIndexingTypes: map[*ast.IndexExpression]Type{}, + IndexExpressionTypes: map[*ast.IndexExpression]IndexExpressionTypes{}, } if extendedElaboration { elaboration.ForceExpressionTypes = map[*ast.ForceExpression]Type{} - elaboration.StaticCastTypes = map[*ast.CastingExpression]CastType{} - elaboration.RuntimeCastTypes = map[*ast.CastingExpression]struct { - Left Type - Right Type - }{} + elaboration.StaticCastTypes = map[*ast.CastingExpression]CastTypes{} + elaboration.RuntimeCastTypes = map[*ast.CastingExpression]RuntimeCastTypes{} elaboration.NumberConversionArgumentTypes = map[ast.Expression]struct { Type Type Range ast.Range diff --git a/runtime/tests/checker/conditions_test.go b/runtime/tests/checker/conditions_test.go index 0fbde104a1..b23ca8bcab 100644 --- a/runtime/tests/checker/conditions_test.go +++ b/runtime/tests/checker/conditions_test.go @@ -110,8 +110,7 @@ func TestCheckFunctionPostConditionWithBefore(t *testing.T) { require.NoError(t, err) - assert.Len(t, checker.Elaboration.VariableDeclarationValueTypes, 1) - assert.Len(t, checker.Elaboration.VariableDeclarationTargetTypes, 1) + assert.Len(t, checker.Elaboration.VariableDeclarationTypes, 1) } func TestCheckFunctionPostConditionWithBeforeNotDeclaredUse(t *testing.T) { diff --git a/runtime/tests/checker/genericfunction_test.go b/runtime/tests/checker/genericfunction_test.go index 5409b3d0db..ed9754890d 100644 --- a/runtime/tests/checker/genericfunction_test.go +++ b/runtime/tests/checker/genericfunction_test.go @@ -162,7 +162,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeArguments := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeArguments := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeArguments.Get(typeParameter) require.True(t, present, "could not find type argument for parameter %#+v", typeParameter) @@ -212,7 +212,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeArguments := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeArguments := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeArguments.Get(typeParameter) require.True(t, present, "could not find type argument for type parameter %#+v", typeParameter) @@ -385,7 +385,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeParameterTypes := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeParameterTypes := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeParameterTypes.Get(typeParameter) require.True(t, present, "could not find type argument for type parameter %#+v", typeParameter) @@ -509,7 +509,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeArguments := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeArguments := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeArguments.Get(typeParameter) require.True(t, present, "could not find type argument for type parameter %#+v", typeParameter) @@ -568,7 +568,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeArguments := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeArguments := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeArguments.Get(typeParameter) require.True(t, present, "could not find type argument for type parameter %#+v", typeParameter) @@ -613,7 +613,7 @@ func TestCheckGenericFunction(t *testing.T) { require.IsType(t, &ast.InvocationExpression{}, variableDeclaration.Value) invocationExpression := variableDeclaration.Value.(*ast.InvocationExpression) - typeArguments := checker.Elaboration.InvocationExpressionTypeArguments[invocationExpression] + typeArguments := checker.Elaboration.InvocationExpressionTypes[invocationExpression].TypeArguments ty, present := typeArguments.Get(typeParameter) require.True(t, present, "could not find type argument for type parameter %#+v", typeParameter) From 7a610d7b257403a0955a79565ec554d6817a56a0 Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Tue, 2 Aug 2022 14:08:46 -0700 Subject: [PATCH 4/7] Fix batch scipt tool --- tools/batch-script/address_provider.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/batch-script/address_provider.go b/tools/batch-script/address_provider.go index cad8637700..4716f77705 100644 --- a/tools/batch-script/address_provider.go +++ b/tools/batch-script/address_provider.go @@ -83,7 +83,7 @@ func InitAddressProvider( ctx, referenceBlockID, []byte(accountStorageUsageScript), - []cadence.Value{cadence.NewMeteredAddress(address)}, + []cadence.Value{cadence.NewAddress(address)}, ) if err == nil { return true, nil From d9ecebe079b2196d0a6333f099732d031bbd3bfc Mon Sep 17 00:00:00 2001 From: Supun Setunga Date: Fri, 5 Aug 2022 14:04:14 -0700 Subject: [PATCH 5/7] Add tools to the build --- Makefile | 10 +++++++++- tools/docgen/Makefile | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tools/docgen/Makefile diff --git a/Makefile b/Makefile index 20c43c885b..fe8e57b2fd 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,15 @@ build: GOARCH=wasm GOOS=js go build -o ./runtime/cmd/parse/parse.wasm ./runtime/cmd/parse go build -o ./runtime/cmd/check/check ./runtime/cmd/check go build -o ./runtime/cmd/main/main ./runtime/cmd/main - cd ./languageserver && make build + (cd ./languageserver && make build && cd -) + make build-tools + +.PHONY: build-tools +build-tools: + (cd ./tools/analysis && go build . && cd -) + (cd ./tools/batch-script && go build . && cd -) + (cd ./tools/constructorcheck && make plugin && cd -) + (cd ./tools/docgen && make build && cd -) .PHONY: lint-github-actions lint-github-actions: build-linter diff --git a/tools/docgen/Makefile b/tools/docgen/Makefile new file mode 100644 index 0000000000..9a012fb715 --- /dev/null +++ b/tools/docgen/Makefile @@ -0,0 +1,9 @@ +.PHONY: build +build: + go build . + +.PHONY: test +test: + # test all packages + GO111MODULE=on go test -parallel 8 ./... + From e740ca34fe558a35f298ed702cebc3c394e6dabb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Mon, 15 Aug 2022 13:59:57 -0700 Subject: [PATCH 6/7] v0.25.0 --- npm-packages/cadence-docgen/package.json | 2 +- npm-packages/cadence-parser/package.json | 2 +- version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-packages/cadence-docgen/package.json b/npm-packages/cadence-docgen/package.json index dd2f3d93b6..0ccbf9ccca 100644 --- a/npm-packages/cadence-docgen/package.json +++ b/npm-packages/cadence-docgen/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-docgen", - "version": "0.24.1", + "version": "0.25.0", "description": "The Cadence Dcoument Generator", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index eb51f46b4d..99114513a4 100644 --- a/npm-packages/cadence-parser/package.json +++ b/npm-packages/cadence-parser/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-parser", - "version": "0.24.1", + "version": "0.25.0", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/version.go b/version.go index 7a350dbe6d..23d9b7b196 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package cadence -const Version = "v0.24.1" +const Version = "v0.25.0" From 7d5fb4f5b77162cc3e13ae35b5265437e4a49500 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 16 Aug 2022 14:23:08 -0700 Subject: [PATCH 7/7] Revert "v0.25.0" This reverts commit e740ca34fe558a35f298ed702cebc3c394e6dabb. --- npm-packages/cadence-docgen/package.json | 2 +- npm-packages/cadence-parser/package.json | 2 +- version.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/npm-packages/cadence-docgen/package.json b/npm-packages/cadence-docgen/package.json index 0ccbf9ccca..dd2f3d93b6 100644 --- a/npm-packages/cadence-docgen/package.json +++ b/npm-packages/cadence-docgen/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-docgen", - "version": "0.25.0", + "version": "0.24.1", "description": "The Cadence Dcoument Generator", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/npm-packages/cadence-parser/package.json b/npm-packages/cadence-parser/package.json index 99114513a4..eb51f46b4d 100644 --- a/npm-packages/cadence-parser/package.json +++ b/npm-packages/cadence-parser/package.json @@ -1,6 +1,6 @@ { "name": "@onflow/cadence-parser", - "version": "0.25.0", + "version": "0.24.1", "description": "The Cadence parser", "homepage": "https://github.com/onflow/cadence", "repository": { diff --git a/version.go b/version.go index 23d9b7b196..7a350dbe6d 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package cadence -const Version = "v0.25.0" +const Version = "v0.24.1"