Skip to content

Add throw #7346

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

Merged
merged 17 commits into from
Mar 25, 2025
Merged

Add throw #7346

merged 17 commits into from
Mar 25, 2025

Conversation

aspeddro
Copy link
Contributor

Deprecate raise and rename references.

Close #7113

Deprecate `raise` and rename references
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we add @@deprecated to this module?

It has the same content as https://github.com/rescript-lang/rescript/blob/master/runtime/Stdlib_Error.res

Copy link
Member

Choose a reason for hiding this comment

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

it doesn't have exactly the same content though, Error is missing the definition of a JS exception that today is catched with Exn.Error(obj), but I agree the current situation is not ideal, maybe we could merge the two?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will explore this in another PR

Copy link
Member

@tsnobip tsnobip left a comment

Choose a reason for hiding this comment

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

thanks for doing this @aspeddro, I think that's a nice improvement. I'm just not sure if we should also deprecate raise, having both without any explanation feels a bit weird to me. I'm also not sure about what we should do for Stdlib.Exn module, but I'd advise to keep this work for another PR to avoid bikeshedding on this topic.

@@ -1,5 +1,6 @@
/* Exceptions */
external raise: exn => 'a = "%raise"
Copy link
Member

Choose a reason for hiding this comment

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

should we deprecate raise or keep both for now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will remove

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@aspeddro
Copy link
Contributor Author

We can add to deprecated attribute?

raise has been renamed to throw to align with JavaScript vocabulary. Please use throw.

@@ -100,6 +100,7 @@ async function main() {
external import: 'a => promise<'a> = "%import"

let panic = Error.panic
let throw = Error.throw
Copy link
Member

Choose a reason for hiding this comment

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

This is not zero-cost (causes a $$throw function to be emitted in Stdlib.js). I am afraid we need to repeat the external definition here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

}
```
*/
external throw: Error.t => 'a = "%raise"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I add the external here or just leave it in the Stdlib_Error.res module?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@aspeddro
Copy link
Contributor Author

CHANGELOG updated

@aspeddro aspeddro requested a review from cknitt March 20, 2025 19:16
@cknitt
Copy link
Member

cknitt commented Mar 21, 2025

@aspeddro did you see my comment?

Should I add the external here or just leave it in the Stdlib_Error.res module?

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

@aspeddro
Copy link
Contributor Author

@aspeddro did you see my comment?

Should I add the external here or just leave it in the Stdlib_Error.res module?

Maybe clearer to add it in Pervasives on top of the deprecated raise instead?

Yes, I will adjust

@fhammerschmidt
Copy link
Member

Should we also have a throws decorator as an alias to raises in reanalyze?

@cristianoc
Copy link
Collaborator

Should we also have a throws decorator as an alias to raises in reanalyze?

Good idea.

@@ -1,6 +1,6 @@
/**
Since [others] depend on this file, its public mli files **should not
export types** introduced here, otherwise it would cause
export types** introduced here, otherwise it would cause
Copy link
Member

Choose a reason for hiding this comment

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

This whole comment is obsolete and should be removed as there is no others folder anymore (leftover from the old stdlib build procedure).

Or actually, there should be a module-level doc comment (/***) instead explaining what the Pervasives module is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment removed a36b71d

@cknitt cknitt merged commit 6654cb2 into rescript-lang:master Mar 25, 2025
20 checks passed
fhammerschmidt pushed a commit that referenced this pull request Apr 4, 2025
* Add `throw`

Deprecate `raise` and rename references

* remove raise from Pervasives_mini.res

* convert to external and add deprecated attr

* restore tests/gentype_tests/typescript-react-example/package-lock.json

* update analysis output

* update CHANGELOG.md

* move `throw` to Pervasives.res

* Update runtime/Pervasives.res

Co-authored-by: Christoph Knittel <[email protected]>

* Update runtime/Pervasives.res

Co-authored-by: Christoph Knittel <[email protected]>

* Update runtime/Pervasives.res

Co-authored-by: Christoph Knittel <[email protected]>

* Update runtime/Stdlib_Error.resi

Co-authored-by: Christoph Knittel <[email protected]>

* Update runtime/Stdlib_Error.resi

Co-authored-by: Christoph Knittel <[email protected]>

* Update runtime/Stdlib_Error.resi

Co-authored-by: Christoph Knittel <[email protected]>

* update Stdlib_Bool and Stdlib_Char

* remove comment

---------

Co-authored-by: Christoph Knittel <[email protected]>
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.

raise -> throw
5 participants