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

Update interface of revertibleRandom #2976

Merged
merged 6 commits into from
Dec 11, 2023

Conversation

darkdrag00nv2
Copy link
Contributor

Work towards #2712

For previous discussions, please check - #2943

Description

  1. Introduced a new type FixedSizeUnsignedInteger
  2. Update the interface of the revertibleRandom function to fun revertibleRandom<T: FixedSizeUnsignedInteger>([modulo: T]): T

Note that updating the interface is a breaking change as the existing usage of the function such as below fails.

let rand1 = revertibleRandom()  // error: cannot infer type parameter: `T`

Noteworthy Points

  1. Updating the interface is a breaking change as pointed out in the description and also the issue Update revertibleRandom interface (FLIP 120) #2712 (comment)
  2. Since we don't support type inference of function arguments, we will run into the same issues as the InclusiveRange constructor function: Fix incorrect type inference for InclusiveRange #2886

Basically:

let r = revertibleRandom<Int8>(0) // checker error, type mismatch - expected: Int8, Found - Int
let r = revertibleRandom<Int8>(Int8(0)) // success
  1. The modulo operation hasn't been implemented in this PR. It'll be done in a future PR based on the discussion on the issue.

  • 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

Copy link

codecov bot commented Dec 11, 2023

Codecov Report

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

Comparison is base (0de878b) 80.12% compared to head (901bb55) 80.15%.

Files Patch % Lines
runtime/stdlib/random.go 95.90% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2976      +/-   ##
==========================================
+ Coverage   80.12%   80.15%   +0.02%     
==========================================
  Files         348      348              
  Lines       81796    81925     +129     
==========================================
+ Hits        65537    65663     +126     
- Misses      13939    13942       +3     
  Partials     2320     2320              
Flag Coverage Δ
unittests 80.15% <96.55%> (+0.02%) ⬆️

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

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

@SupunS SupunS self-assigned this Dec 11, 2023
@SupunS SupunS added Language Breaking Change Breaks Cadence contracts deployed on Mainnet Improvement labels Dec 11, 2023
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!

@SupunS SupunS merged commit 3946910 into onflow:master Dec 11, 2023
11 of 14 checks passed
@darkdrag00nv2 darkdrag00nv2 deleted the revertible_random branch December 12, 2023 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Improvement Language Breaking Change Breaks Cadence contracts deployed on Mainnet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants