-
Notifications
You must be signed in to change notification settings - Fork 138
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
Type Checking for attachment uses #2099
Type Checking for attachment uses #2099
Conversation
…nce into sainati/attachments-check-add-remove
…nce into sainati/attachments-check-add-remove
…hments-check-add-remove
…nce into sainati/attachments-check-add-remove
…nce into sainati/attachments-check-add-remove
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.
Great work!
Reviewed everything except sema/type.go
, need to review the new subtyping rules in detail.
…nce into sainati/attachments-check-add-remove
…sainati/attachments-check-add-remove
Codecov Report
@@ Coverage Diff @@
## feature/attachments #2099 +/- ##
=======================================================
+ Coverage 77.65% 77.75% +0.09%
=======================================================
Files 310 312 +2
Lines 65899 66251 +352
=======================================================
+ Hits 51176 51513 +337
- Misses 12936 12948 +12
- Partials 1787 1790 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:feature/attachments commit 8747c50 Collapsed results for better readability
|
@dsainati1 Points 5 and 6 in the description are not part of the PR anymore, right? |
Ah yea good point |
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.
Again, really great work on this PR! 👏
I reviewed the remaining code, especially sema/type.go
and IsSubType
in particular. If you wan we can maybe have another (short) review session to discuss the remaining points.
runtime/sema/type.go
Outdated
case *InterfaceType: | ||
switch typedInnerSubType := typedSubType.Type.(type) { | ||
case *CompositeType: | ||
return typedInnerSubType.ExplicitInterfaceConformanceSet().Contains(typedInnerSuperType) | ||
// An interface type is a supertype of a restricted type if the restricted set contains | ||
// that explicit interface type. Once interfaces can conform to interfaces, this should instead | ||
// check that at least one value in the restriction set is a subtype of the interface supertype | ||
case *RestrictedType: | ||
return typedInnerSubType.RestrictionSet().Contains(typedInnerSuperType) | ||
} |
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.
The implementation ignores the restricted type (T
in &T{Us}
), does it need to be checked too?
runtime/sema/type.go
Outdated
case *InterfaceType: | ||
switch typedInnerSubType := typedSubType.Type.(type) { | ||
case *CompositeType: | ||
return typedInnerSubType.ExplicitInterfaceConformanceSet().Contains(typedInnerSuperType) | ||
// An interface type is a supertype of a restricted type if the restricted set contains | ||
// that explicit interface type. Once interfaces can conform to interfaces, this should instead | ||
// check that at least one value in the restriction set is a subtype of the interface supertype | ||
case *RestrictedType: | ||
return typedInnerSubType.RestrictionSet().Contains(typedInnerSuperType) | ||
} |
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.
Instead of adding this special rule to the subtype checking, maybe this can be a separate function that can be used where needed? (Where is it needed?)
case *RestrictedType: | ||
return typedSubType.RestrictionSet().Contains(typedSuperType) |
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.
Same as above: Maybe this can be a separate function that is only used for this purpose.
The IsSubType
function is already very complex, and so far assumes / could rely on the fact that interfaces only appear in restricted types. I'm worried the rules / this function becomes incomplete.
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.
Co-authored-by: Bastian Müller <bastian@axiomzen.co>
…low/cadence into sainati/attachments-check-add-remove
…into sainati/attachments-check-add-remove
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.
Great work! 👏
Just some more suggestions for improving the comments even further, but finally ready to go! 🎉
Sorry this too so long, but this PR touches a lot of pieces
Part of #357 and #2061
This adds type checking for the uses of attachment types. In particular:
attach A() to v
, which requires its first expression to be an attachment constructor for whichv
is a valid composite base typeremove A from v
, which requires its first expression to be an attachment name for whichv
is a valid composite base typev[A]
, which requires its indexing expression to be an attachment name for whichv
is a valid composite base type, and returns a value of type&A?
AnyStructAttachment
andAnyResourceAttachment
, which are the supertypes of all struct and resource attachments respectively. These are subtypes ofAnyStruct
andAnyResource
as well.master
branchFiles changed
in the Github PR explorer