-
Notifications
You must be signed in to change notification settings - Fork 137
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
Concretize the definition of Primitive type #2962
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## feature/stable-cadence #2962 +/- ##
==========================================================
- Coverage 80.11% 80.07% -0.04%
==========================================================
Files 348 348
Lines 81870 81915 +45
==========================================================
+ Hits 65590 65594 +4
- Misses 13958 13998 +40
- Partials 2322 2323 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
runtime/sema/gen/main.go
Outdated
@@ -1583,12 +1584,14 @@ func simpleTypeLiteral(ty *typeDecl) dst.Expr { | |||
//} | |||
|
|||
isResource := ty.compositeKind == common.CompositeKindResource | |||
_, isPrimitive := sema.GeneratedPrimitiveSimpleTypes[ty.typeName] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to how other "kind"s are indicated through conformances in declarations of built-in types which produce Go code, like if a type is storable via conforming to the Storable
type (also, Equatable
, Comparable
, etc), we might consider introducing a Primitive
type in the code generator (which later then also could be introduced "properly" in the type checker.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7b3805c.
runtime/sema/simple_type.go
Outdated
@@ -25,6 +25,10 @@ import ( | |||
"github.com/onflow/cadence/runtime/common" | |||
) | |||
|
|||
var GeneratedPrimitiveSimpleTypes = map[string]bool{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As commented above, maybe consider replacing this with a notion of Primitive
in the code generator. It's difficult to see that a side-table determines additional properties of a type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 7b3805c.
runtime/sema/type.go
Outdated
@@ -669,6 +674,10 @@ func (t *OptionalType) IsResourceType() bool { | |||
return t.Type.IsResourceType() | |||
} | |||
|
|||
func (t *OptionalType) IsPrimitiveType() bool { | |||
return false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add a test case here and for the other uncovered functions below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What sort of test would make sense here? We are not using this IsPrimitiveType
function anywhere. Is there a place where we could use it and then that would automatically lead to coverage?
e2ab9ed
to
61e79f1
Compare
Closes #2929
Description
This PR concretizes the definition of Primitive type by introducing a
IsPrimitiveType
function onsema.Type
.The following types have been marked as primitive:
Number
typesCharacter
Bool
String
Address
Path
Void
Optional<T>
- ifT
is primitivemaster
branchFiles changed
in the Github PR explorer