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

Introduce InclusiveRange<T: Integer> type #2523

Merged
merged 88 commits into from
Oct 19, 2023

Conversation

darkdrag00nv2
Copy link
Contributor

@darkdrag00nv2 darkdrag00nv2 commented Jun 1, 2023

Work towards #2482
Work towards onflow/flips#96
Work towards onflow/developer-grants#179

Description

Adds a new InclusiveRange<T: Integer> type to Cadence.

Implemented the following:

  1. Constructor to create the Range
  2. Member variables and functions for the type
  3. Conversion to CompositeValue for easy support for transfer, encoding and decoding

Support for looping inside for-in will be added in a separate PR.


  • Targeted PR against master branch
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work
  • Code follows the standards mentioned here
  • Updated relevant documentation
  • Re-reviewed Files changed in the Github PR explorer
  • Added appropriate labels

@darkdrag00nv2 darkdrag00nv2 force-pushed the range_type branch 2 times, most recently from 03b7e50 to fd72061 Compare June 9, 2023 21:36
@codecov
Copy link

codecov bot commented Jun 17, 2023

Codecov Report

Attention: 136 lines in your changes are missing coverage. Please review.

Comparison is base (edf547b) 79.38% compared to head (4445c56) 79.62%.

❗ Current head 4445c56 differs from pull request most recent head 1ca3adc. Consider uploading reports for the commit 1ca3adc to get more accurate results

Additional details and impacted files
@@                  Coverage Diff                   @@
##           feature/range-type    #2523      +/-   ##
======================================================
+ Coverage               79.38%   79.62%   +0.24%     
======================================================
  Files                     333      336       +3     
  Lines                   78748    79713     +965     
======================================================
+ Hits                    62514    63475     +961     
+ Misses                  13928    13871      -57     
- Partials                 2306     2367      +61     
Flag Coverage Δ
unittests 79.62% <85.93%> (+0.24%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
encoding/ccf/decode.go 65.59% <100.00%> (+1.59%) ⬆️
encoding/ccf/traverse_value.go 98.33% <100.00%> (ø)
encoding/json/decode.go 88.85% <100.00%> (+0.26%) ⬆️
encoding/json/encode.go 95.16% <100.00%> (+0.12%) ⬆️
runtime/common/memorykind_string.go 40.00% <ø> (ø)
runtime/common/metering.go 92.32% <ø> (ø)
runtime/convertTypes.go 87.86% <100.00%> (+0.24%) ⬆️
runtime/sema/errors.go 93.16% <100.00%> (+0.01%) ⬆️
runtime/sema/type_tags.go 94.91% <100.00%> (ø)
runtime/stdlib/builtin.go 100.00% <100.00%> (ø)
... and 17 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@darkdrag00nv2 darkdrag00nv2 changed the title Introduce Range<T: Integer> type Introduce InclusiveRange<T: Integer> type Jun 19, 2023
@darkdrag00nv2 darkdrag00nv2 force-pushed the range_type branch 2 times, most recently from dc8d242 to 5b05232 Compare June 25, 2023 19:38
@turbolent turbolent self-assigned this Jun 28, 2023
@turbolent turbolent assigned SupunS and unassigned turbolent Jun 28, 2023
@darkdrag00nv2 darkdrag00nv2 marked this pull request as ready for review June 29, 2023 16:50
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

runtime/format/range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
Copy link
Contributor

@dsainati1 dsainati1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make a feature/range-type branch that includes all the Range changes, so we can put them in one place them merge them to master together?

@darkdrag00nv2
Copy link
Contributor Author

@dsainati1 So I don't have the access to do that. Can you please create one for me? I'll target this PR on that branch after that. Thanks!

@SupunS SupunS changed the base branch from master to feature/range-type July 6, 2023 14:58
@SupunS
Copy link
Member

SupunS commented Jul 6, 2023

@darkdrag00nv2 created a new branch feature/range-type and changed the base to it.

runtime/convertTypes.go Show resolved Hide resolved
runtime/convertTypes.go Show resolved Hide resolved
runtime/interpreter/decode.go Show resolved Hide resolved
runtime/interpreter/statictype.go Show resolved Hide resolved
runtime/interpreter/interpreter.go Outdated Show resolved Hide resolved
runtime/stdlib/range.go Outdated Show resolved Hide resolved
runtime/stdlib/range.go Outdated Show resolved Hide resolved
runtime/sema/type_tags.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/stdlib/range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
@darkdrag00nv2
Copy link
Contributor Author

Incorporated half of the suggestions. A few of them are remaining.

runtime/interpreter/interpreter.go Outdated Show resolved Hide resolved
runtime/interpreter/value_range.go Outdated Show resolved Hide resolved
runtime/sema/type.go Outdated Show resolved Hide resolved
@darkdrag00nv2
Copy link
Contributor Author

@SupunS @dsainati1 This is ready for another round of review. Thanks!

@darkdrag00nv2 darkdrag00nv2 requested a review from dsainati1 July 31, 2023 16:24
@turbolent
Copy link
Member

The small integer cache was still not thread-safe and caused data races to be reported (https://github.com/onflow/cadence/actions/runs/6398301138/job/17368137493?pr=2523#step:6:58), so I improved it in 1af52af

Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage is updated now and should be helpful.

runtime/interpreter/value.go Show resolved Hide resolved
Copy link
Member

@turbolent turbolent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! 👏👏

I think we should get this merged in the current state, and then then potentially remaining work (e.g. making ranges storable) can be addressed in a follow-up PR.

Could you please have a final look @SupunS @dsainati1 ?

runtime/runtime_test.go Outdated Show resolved Hide resolved
Copy link
Member

@SupunS SupunS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be good to merge in the current state 👍

@darkdrag00nv2 Can you maybe create separate issues for the remaining work / tech-debt, so they won't fall through the cracks

runtime/interpreter/value_range.go Show resolved Hide resolved
runtime/program_params_validation_test.go Show resolved Hide resolved
runtime/sema/type.go Show resolved Hide resolved
@darkdrag00nv2
Copy link
Contributor Author

@SupunS

Can you maybe create separate issues for the remaining work / tech-debt, so they won't fall through the cracks

Filed #2871 and #2870.

@darkdrag00nv2
Copy link
Contributor Author

@SupunS Lets merge? I'll send follow-up PRs post that on the fixes and future features such as for-in loop support.

@SupunS
Copy link
Member

SupunS commented Oct 18, 2023

@darkdrag00nv2 Can you please create issues for any remaining open discussions (e.g: #2523 (comment), #2523 (comment)) and resolve those? Then we can merge the PR.

There is a PR restriction that is enforced on this repo, which blocks merging until all conversations are resolved

@darkdrag00nv2
Copy link
Contributor Author

@SupunS Thanks, Filed all the issues.

@SupunS SupunS merged commit e523180 into onflow:feature/range-type Oct 19, 2023
7 of 9 checks passed
@darkdrag00nv2 darkdrag00nv2 deleted the range_type branch October 19, 2023 16:30
fxamacker added a commit to onflow/ccf that referenced this pull request Oct 23, 2024
This update corresponds to Cadence PR 2523 and subsequent changes to inclusiverange and inclusiverange-type:
onflow/cadence#2523

This change does not affect CCF Codec because it 
was already implemented and deployed in CCF codec.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants