-
Notifications
You must be signed in to change notification settings - Fork 140
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
Add runtime subtype check using static types #1487
Conversation
…/dynamic-type-checking
…/dynamic-type-checking
Codecov Report
@@ Coverage Diff @@
## master #1487 +/- ##
==========================================
+ Coverage 73.01% 74.40% +1.39%
==========================================
Files 288 289 +1
Lines 39786 55677 +15891
==========================================
+ Hits 29048 41425 +12377
- Misses 9263 12755 +3492
- Partials 1475 1497 +22
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:master commit bf002e9 Results
|
82f809f
to
ac76f7c
Compare
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.
This makes sense to me. Am I correct in understanding that this removes the need to meter dynamic types?
Yes, correct. In the long run, might be able to remove dynamic types completely. |
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 here @SupunS!
Notes from our review discussion:
-
The reference dynamic type contains the type of the referenced ("inner" type)
- This is not to be confused with the borrowed type
- As we are now using the reference static type for dynamic type checking we need to include the referenced type there
- To get the referenced type of a storage reference value, it needs to dereference, which requires to access to storage
- Because of this we need to pass the interpreter to
Value.StaticType
- Add test for casting storage ref to an invalid type #1243 was added as a test case before
-
It is OK to pass
nil
toValue.StaticType
if the value is not a storage reference- OK for run-time checks in arithmetic operations, never references
- OK in tests
-
The dynamic subtype checking function
Interpreter.IsSubType
was renamed toIsSubTypeOfSemaType
- It used to use dynamic type for first argument, now uses static type
- Most of the old dynamic subtype checking function was a "duplicate" of the sema subtype checking function and can be removed now, by delegating to the sema subtype checking function
- However, we need to keep logic for reference types, which uses run-time information (referenced type / "inner" type, see above)
- The reference type may be nested in an optional type, so we need to handle optionals
- TODO: we might have to add cases for other containers (arrays, dictionaries, etc.) too
I have some suggestions / improvements for this PR which I will open in a separate PR.
Once merged, we can also discuss follow-up clean ups:
- We should be able to remove the deprecated dynamic type checking function (
DeprecatedIsSubType
) now, as it is not used anymore - We should be able to remove the dynamic type hierarchy (
DynamicType
) now- However, the argument import checks importability of the value (dynamic type, not static type)
- Value importability is mostly the same as static importability (
sema.Type.IsImportable
), but there are some cases where it depends on the value (e.g. for capabilities the domain matters)
Opened the two follow-up PRs: |
Thank you, @turbolent for the review! 🙏
I'll open a separate PR adding tests to verify this + any changes needed |
Closes #1217
Description
This PR uses static-types for run-time subtype check in place of dynamic-types, for better performance.
The speed gains are mostly from the type-checking of collections.
Assumptions/Rationale:
To Be Done:
Optimizations:
Tasks:
master
branchFiles changed
in the Github PR explorer