-
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
Fix migrating values with empty intersection type #3138
Fix migrating values with empty intersection type #3138
Conversation
Cadence Benchstat comparisonThis branch with compared with the base branch onflow:master commit f605ce8 Collapsed results for better readability
|
intersectionSuperType := typedSuperType.LegacyType //nolint:staticcheck | ||
|
||
switch intersectionSuperType { | ||
case nil, AnyResourceType, AnyStructType, AnyType: |
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.
Integrated handling for no legacy type, see diff in description
case nil: | ||
// An intersection type `{Us}` is a subtype of an intersection type `{Vs}` / `{Vs}` / `{Vs}`: | ||
// when `Vs` is a subset of `Us`. | ||
|
||
return typedSuperType.EffectiveIntersectionSet(). | ||
IsSubsetOf(typedSubType.EffectiveIntersectionSet()) |
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.
Integrated rule for no legacy type. Same as commented out code at top
if intersectionSuperType != nil && | ||
!IsSubType(intersectionSubtype, intersectionSuperType) { |
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.
Added support for no legacy type
if intersectionSuperType != nil && | ||
!IsSubType(intersectionSubtype, intersectionSuperType) { |
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.
Added support for no legacy type
if intersectionSuperType != nil && | ||
!IsSubType(typedSubType, intersectionSuperType) { |
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.
Added support for no legacy type
|
||
intersectionSubType := typedSubType.LegacyType //nolint:staticcheck | ||
switch intersectionSubType { | ||
case nil, AnyResourceType, AnyStructType, AnyType: |
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.
Integrated rule for no legacy type
// `Us` and `Ws` do *not* have to be subsets: | ||
// The owner may freely restrict and unrestrict. | ||
|
||
return intersectionSubType == intersectionSuperType |
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.
Both intersectionSubType
and intersectionSuperType
are non-nil here
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3138 +/- ##
==========================================
- Coverage 80.60% 80.53% -0.07%
==========================================
Files 381 381
Lines 92456 92616 +160
==========================================
+ Hits 74520 74585 +65
- Misses 15235 15327 +92
- Partials 2701 2704 +3
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Work towards #3096
Description
Migrated values may have empty intersection types, as they originally were restricted types, i.e. they have a legacy type.
Creating empty intersection types without (correctly) defensively panics, but prevents migrating values.
Removing the panic and only accepting empty intersection types is not enough: The resulting sema intersection type is then used for various purposes during the migration, e.g. subtype checking when inserting into a dictionary, performing the appropriate transfer (copy or move), etc.
Bring back the legacy type in
sema.IntersectionType
, just like it already exists ininterpreter.StaticIntersectionType
, and restore the subtyping rules which were removed in #2596 (see https://github.com/onflow/cadence/pull/2596/files#diff-c01765841e64b85306258f5ee4daff2bdc5b9e9e107167f55a6dba4162e8bdb8).The subtyping rules for Cadence 1.0 intersection type got integrated into the restored rules.
Because this is hard to review, I prepared a diff of the original subtyping rules for restricted types (taken from #2596) and the new subtying rules for intersection types of this PR:
master
branchFiles changed
in the Github PR explorer