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: add panic builtin function #757

Merged
merged 4 commits into from
Jan 8, 2025
Merged

feat: add panic builtin function #757

merged 4 commits into from
Jan 8, 2025

Conversation

ss2165
Copy link
Member

@ss2165 ss2165 commented Jan 7, 2025

Closes #756

@ss2165 ss2165 requested a review from a team as a code owner January 7, 2025 14:45
@ss2165 ss2165 requested review from qartik and mark-koch and removed request for qartik January 7, 2025 14:45
@codecov-commenter
Copy link

codecov-commenter commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 95.34884% with 2 lines in your changes missing coverage. Please review.

Project coverage is 92.97%. Comparing base (9ad02bb) to head (9093522).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
guppylang/std/_internal/checker.py 92.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #757      +/-   ##
==========================================
- Coverage   93.00%   92.97%   -0.04%     
==========================================
  Files          71       71              
  Lines        8178     8222      +44     
==========================================
+ Hits         7606     7644      +38     
- Misses        572      578       +6     

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


vals = [ExprSynthesizer(self.ctx).synthesize(val)[0] for val in rest]
node = PanicExpr(msg.value, vals)
return with_loc(self.node, node), NoneType()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should panic be generic over the type it returns? This would require also implementing check to infer the return type.

Imo the proper way to implement this would be to use a bottom return type like Python's Never or NoReturn for panic, but that's too much for this PR

Copy link
Member Author

Choose a reason for hiding this comment

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

I couldn't think of a good reason for panic returning anything other than None, do you think it is important?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For example, it's currently not possible to make the type checker understand that panics are an early exit. So, say you want to implement Option.unwrap yourself, then you still need to explicitly return something in the error case:

def unwrap(opt: Option[T]) -> T:
    match opt:
        case Some(x): return x
        case Nothing: return panic("Is None")

guppylang/std/_internal/checker.py Outdated Show resolved Hide resolved
guppylang/std/_internal/checker.py Outdated Show resolved Hide resolved
@ss2165 ss2165 requested a review from mark-koch January 8, 2025 10:48
@ss2165
Copy link
Member Author

ss2165 commented Jan 8, 2025

@mark-koch thanks for the fix! Feel free to approve if you are happy with the rest

@ss2165 ss2165 added this pull request to the merge queue Jan 8, 2025
@ss2165 ss2165 removed this pull request from the merge queue due to a manual request Jan 8, 2025
@ss2165 ss2165 enabled auto-merge January 8, 2025 10:56
@ss2165 ss2165 added this pull request to the merge queue Jan 8, 2025
Merged via the queue into main with commit 4ae3032 Jan 8, 2025
3 checks passed
@ss2165 ss2165 deleted the ss/panic branch January 8, 2025 11:01
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.

stdlib function for panicking
3 participants