Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Concretize the definition of Primitive type #2962

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions runtime/sema/account_capability_controller.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/any_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var AnyType = &SimpleType{
IsResource: false,
// `Any` is never a valid type in user programs
Storable: true,
Primitive: false,
Equatable: false,
Comparable: false,
// `Any` is never a valid type in user programs
Expand Down
2 changes: 2 additions & 0 deletions runtime/sema/anyattachment_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var AnyResourceAttachmentType = &SimpleType{
TypeID: AnyResourceAttachmentTypeName,
TypeTag: AnyResourceAttachmentTypeTag,
IsResource: true,
Primitive: false,
// The actual storability of a value is checked at run-time
Storable: true,
Equatable: false,
Expand All @@ -45,6 +46,7 @@ var AnyStructAttachmentType = &SimpleType{
TypeID: AnyStructAttachmentTypeName,
TypeTag: AnyStructAttachmentTypeTag,
IsResource: false,
Primitive: false,
// The actual storability of a value is checked at run-time
Storable: true,
Equatable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/anyresource_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var AnyResourceType = &SimpleType{
TypeID: "AnyResource",
TypeTag: AnyResourceTypeTag,
IsResource: true,
Primitive: false,
// The actual storability of a value is checked at run-time
Storable: true,
Equatable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/anystruct_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var AnyStructType = &SimpleType{
IsResource: false,
// The actual storability of a value is checked at run-time
Storable: true,
Primitive: false,
Equatable: false,
Comparable: false,
Exportable: true,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/block.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/bool_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var BoolType = &SimpleType{
TypeTag: BoolTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: true,
Exportable: true,
Expand Down
2 changes: 1 addition & 1 deletion runtime/sema/character.cdc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

access(all)
struct Character: Storable, Equatable, Comparable, Exportable, Importable {
struct Character: Storable, Primitive, Equatable, Comparable, Exportable, Importable {

/// The byte array of the UTF-8 encoding.
access(all)
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/character.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/deployedcontract.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions runtime/sema/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
fullTypeName string
compositeKind common.CompositeKind
storable bool
primitive bool
equatable bool
exportable bool
comparable bool
Expand Down Expand Up @@ -524,6 +525,15 @@
}
typeDecl.storable = true

case "Primitive":
if !generateSimpleType {
panic(fmt.Errorf(
"composite types cannot be explicitly marked as primitive: %s",
g.currentTypeID(),
))

Check warning on line 533 in runtime/sema/gen/main.go

View check run for this annotation

Codecov / codecov/patch

runtime/sema/gen/main.go#L530-L533

Added lines #L530 - L533 were not covered by tests
}
typeDecl.primitive = true

case "Equatable":
if !generateSimpleType {
panic(fmt.Errorf(
Expand Down Expand Up @@ -1576,6 +1586,7 @@
// tag: TestTypeTag,
// IsResource: true,
// Storable: false,
// Primitive: false,
// Equatable: false,
// Comparable: false,
// Exportable: false,
Expand All @@ -1590,6 +1601,7 @@
goKeyValue("TypeTag", typeTagVarIdent(ty.fullTypeName)),
goKeyValue("IsResource", goBoolLit(isResource)),
goKeyValue("Storable", goBoolLit(ty.storable)),
goKeyValue("Primitive", goBoolLit(ty.primitive)),
goKeyValue("Equatable", goBoolLit(ty.equatable)),
goKeyValue("Comparable", goBoolLit(ty.comparable)),
goKeyValue("Exportable", goBoolLit(ty.exportable)),
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/comparable/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/docstrings/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/equatable/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/exportable/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/fields/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/functions/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/importable/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/member_accessible/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions runtime/sema/gen/testdata/primitive/helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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 primitive

import "github.com/onflow/cadence/runtime/sema"

var TestTypeTag sema.TypeTag
1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/primitive/test.cdc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
access(all) struct Test: Primitive {}
39 changes: 39 additions & 0 deletions runtime/sema/gen/testdata/primitive/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/simple_resource/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/simple_struct/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/gen/testdata/storable/test.golden.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/hashable_struct.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/invalid_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var InvalidType = &SimpleType{
TypeTag: InvalidTypeTag,
IsResource: false,
Storable: false,
Primitive: false,
Equatable: false,
Comparable: false,
Exportable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/meta_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var MetaType = &SimpleType{
TypeTag: MetaTypeTag,
IsResource: false,
Storable: true,
Primitive: false,
Equatable: true,
Comparable: false,
Exportable: true,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/never_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var NeverType = &SimpleType{
TypeTag: NeverTypeTag,
IsResource: false,
Storable: false,
Primitive: false,
Equatable: false,
Comparable: false,
Exportable: false,
Expand Down
5 changes: 5 additions & 0 deletions runtime/sema/path_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var PathType = &SimpleType{
TypeTag: PathTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: false,
Exportable: true,
Expand All @@ -42,6 +43,7 @@ var StoragePathType = &SimpleType{
TypeTag: StoragePathTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: false,
Exportable: true,
Expand All @@ -58,6 +60,7 @@ var CapabilityPathType = &SimpleType{
TypeTag: CapabilityPathTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: false,
Exportable: true,
Expand All @@ -74,6 +77,7 @@ var PublicPathType = &SimpleType{
TypeTag: PublicPathTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: false,
Exportable: true,
Expand All @@ -90,6 +94,7 @@ var PrivatePathType = &SimpleType{
TypeTag: PrivatePathTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: false,
Exportable: true,
Expand Down
5 changes: 5 additions & 0 deletions runtime/sema/simple_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
Equatable bool
Comparable bool
Storable bool
Primitive bool
IsResource bool
ContainFields bool
}
Expand Down Expand Up @@ -82,6 +83,10 @@
return t.IsResource
}

func (t *SimpleType) IsPrimitiveType() bool {
return t.Primitive

Check warning on line 87 in runtime/sema/simple_type.go

View check run for this annotation

Codecov / codecov/patch

runtime/sema/simple_type.go#L86-L87

Added lines #L86 - L87 were not covered by tests
}

func (t *SimpleType) IsInvalidType() bool {
return t == InvalidType
}
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/storable_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ var StorableType = &SimpleType{
// for e.g. parameters, return types, fields, etc.
IsResource: false,
Storable: true,
Primitive: false,
Equatable: false,
Comparable: false,
Exportable: false,
Expand Down
1 change: 1 addition & 0 deletions runtime/sema/storage_capability_controller.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions runtime/sema/string_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var StringType = &SimpleType{
TypeTag: StringTypeTag,
IsResource: false,
Storable: true,
Primitive: true,
Equatable: true,
Comparable: true,
Exportable: true,
Expand Down
Loading
Loading