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

IO capability & compiler plugin #140

Merged
merged 14 commits into from
May 22, 2024
Merged

IO capability & compiler plugin #140

merged 14 commits into from
May 22, 2024

Conversation

adamw
Copy link
Member

@adamw adamw commented May 15, 2024

No description provided.

doc/io.md Outdated
[application errors](basics/error-handling.md))

Quite importantly, the **absence** of `using IO` specifies that the method has **no** I/O side effects (however, it
might still block the thread, e.g. when using a channel, or have other side effects, such as throwing exceptions).
Copy link
Member

@kciesielski kciesielski May 16, 2024

Choose a reason for hiding this comment

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

or have other side effects, such as throwing exceptions

or interact with randomness and system time?

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, I don't think that would count as IO :)

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking if it's worth mentioning here as 'other side effects'.

Copy link
Member Author

Choose a reason for hiding this comment

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

ah yes, good idea :)

application (e.g. in the `main` method), or when integrating with third-party libraries. Otherwise, the capability
should be passed as an implicit parameter. Such an ideal scenario might not possible, but there's still value in `IO`
tracking: by looking up the usages of `IO.unsafe` it's possible to quickly find the "roots" where the `IO` capability
is introduced. For example:
Copy link
Member

Choose a reason for hiding this comment

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

Are there cases when it won't be in some kind of main method which puts together all the modules?

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 was thinking e.g. of callbacks when integrating with reactive-streams or such?

doc/io.md Outdated
## The requireIO compiler plugin

Ox provides a compiler plugin, which verifies at compile-time that the `IO` capability is present when invoking any
methods from the JDK or Java libraries that specify to throw an `java.io.IOException`.
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider including java.sql.SQLException? JDBC methods throw it instead of IOException for communication errors, and it's part of the JDK. On the other hand, users probably interact with libraries that, even if wrapping JDBC, don't necessarily throw raw SQLException. I saw some signs of this happening here and there in ScalikeJDBC, but that may not be enough to justify the idea :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah good idea, the list is already extensible, we could easily provide a good default.

adamw added 2 commits May 21, 2024 19:04
# Conflicts:
#	core/src/main/scala/ox/channels/SourceCompanionIOOps.scala
#	core/src/test/scala/ox/channels/SourceCompanionIOOpsTest.scala
#	core/src/test/scala/ox/channels/SourceIOOpsTest.scala
#	doc/channels/io.md
@adamw adamw merged commit 2ab7377 into master May 22, 2024
5 checks passed
@adamw adamw deleted the plugin branch May 22, 2024 06:33
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.

2 participants