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

feat: allow range with two arguments and bound #3679

Merged
merged 42 commits into from
Dec 24, 2023

Conversation

DanielSchiavini
Copy link
Contributor

@DanielSchiavini DanielSchiavini commented Nov 30, 2023

Fixes #3678

What I did

  • Add support for range with 2 arguments
  • Adds test coverage for touched code
  • Add new range format to documentation

How I did it

  • Updated codegen to utilize the new arguments
  • Updated semantic analysis to handle new cases

How to verify it

Tests are included

Commit message

Allow range(x, y, bound=N)

Description for the changelog

Add support for range with start/end runtime arguments as long as a bound argument is given.

Cute Animal Picture

image

vyper/codegen/stmt.py Fixed Show fixed Hide fixed
tests/functional/syntax/test_for_range.py Fixed Show fixed Hide fixed
vyper/semantics/analysis/local.py Fixed Show fixed Hide fixed
@codecov-commenter
Copy link

codecov-commenter commented Dec 1, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (2e41873) 83.92% compared to head (224808e) 83.97%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3679      +/-   ##
==========================================
+ Coverage   83.92%   83.97%   +0.05%     
==========================================
  Files          92       92              
  Lines       13065    13044      -21     
  Branches     2934     2928       -6     
==========================================
- Hits        10965    10954      -11     
+ Misses       1666     1661       -5     
+ Partials      434      429       -5     

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

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

looks nice! nice refactoring of that range functionality too. left a couple comments, i think we also want to clarify the behavior of the bounds check in the docs (i.e., end - start <= bound as opposed to, for instance, end <= bound).

@charles-cooper
Copy link
Member

tests need to be updated to use the new tx_failed() fixture!

else:
arg1 = self.stmt.iter.args[1]
rounds = self._get_range_const_value(arg1.right)
raise InvalidOperation("Invalid number of arguments to range()")
Copy link
Member

Choose a reason for hiding this comment

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

this should be a panic really

Copy link
Member

@charles-cooper charles-cooper left a comment

Choose a reason for hiding this comment

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

thanks!

@charles-cooper charles-cooper enabled auto-merge (squash) December 24, 2023 15:43
@charles-cooper charles-cooper merged commit 5319cfb into vyperlang:master Dec 24, 2023
84 checks passed
@DanielSchiavini DanielSchiavini deleted the 3768/range_bound branch December 26, 2023 07:08
charles-cooper added a commit to charles-cooper/vyper that referenced this pull request Dec 27, 2023
- allow range where both start and end arguments are variables, so long
  as a bound is supplied

- ban range expressions of the form `range(x, x + N)` since the new form
  is cleaner and supersedes it.

- also do a bit of refactoring of the codegen for range

---------

Co-authored-by: Charles Cooper <cooper.charles.m@gmail.com>
DanielSchiavini added a commit to DanielSchiavini/vyper-plugin that referenced this pull request Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

allow range(x, y, bound=N)
3 participants