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

Tidy Standard.Base part 5 of n ... (hopefully the end...) #3929

Merged
merged 48 commits into from
Dec 2, 2022

Conversation

jdunkerley
Copy link
Member

@jdunkerley jdunkerley commented Nov 29, 2022

Pull Request Description

  • Moved Any, Error and Panic to Standard.Base.
  • Separated Json and Range extensions into own modules.
  • Tidied Case, Case_Sensitivity, Encoding, Matching, Regex_Matcher, Span, Text_Matcher, Text_Ordering and Text_Sub_Range in Standard.Base.Data.Text.
  • Tidied Standard.Base.Data.Text.Extensions and stopped it re-exporting anything.
  • Tidied Regex_Mode. Renamed Option to Regex_Option and added type to export.
  • Tidied up Regex space.
  • Tidied up Meta space.
  • Remove Matching from export.
  • Moved Standard.Base.Data.Boolean to Standard.Base.Boolean.

Additional Work

  • Removed Standard.Table dependency on Standard.Visualization by moving default_visualization to be an extension method.
  • Removed remaining dubious constructor exports in Standard.Database.
  • Completed changes for Standard.Database in line with design in ticket.

Important Notes

  • Moved to_json and to_default_visualization_data from base types to extension methods.

Checklist

Please include the following checklist in your PR:

  • The documentation has been updated if necessary.
  • All code conforms to the
    Scala,
    Java,
    and
    Rust
    style guides.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed: Enso GUI was tested when built using BOTH
      ./run ide build and ./run ide watch.

@jdunkerley jdunkerley changed the title Tidy Standard.Base part 4 of n ... Tidy Standard.Base part 5 of n ... (hopefully the end...) Nov 29, 2022
@jdunkerley jdunkerley added the CI: No changelog needed Do not require a changelog entry for this PR. label Nov 29, 2022
@jdunkerley jdunkerley force-pushed the wip/jd/base-tidy-5 branch 4 times, most recently from 46aac45 to 8f3dbd7 Compare December 1, 2022 17:29
@jdunkerley jdunkerley marked this pull request as ready for review December 1, 2022 18:18
- Standard.Base.Network.Http.put_json
- Standard.Base.Network.Http.head
- Standard.Base.Network.Http.options
- Standard.Base.Network.HTTP.HTTP.new
Copy link
Member

Choose a reason for hiding this comment

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

These are the component groups visible in component browsers! Yeah, simplifying the Web part is probably good 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.

A start at tidying Web API. Will design and expand over next month or two.

distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso Outdated Show resolved Hide resolved
distribution/lib/Standard/Base/0.0.0-dev/src/Any.enso Outdated Show resolved Hide resolved
> Example
Convert a vector to JSON.
[1, 2, 3, 4].to_json
Any.to_json : Json
Copy link
Member

Choose a reason for hiding this comment

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

Moving these extension methods from Json.enso to Json/Extensions.enso helps with with imports somehow, right? How the imports looked and will look once this PR is integrated?

Copy link
Member Author

Choose a reason for hiding this comment

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

from Standard.Base import alll brings it in, and will be the general way for users.
Within Standard.Base or being explicit import Standard.Base.Data.Json.Extensions adds the to_json support in.

I imagine we will replace to_json with a Json.from method and use to Json. With the exception of Text we have less and less extension methods.

Copy link
Member

Choose a reason for hiding this comment

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

I really like that we are getting a more explicit way to import the extension methods (by importing this separate module). It feels a lot cleaner (although I appreciate auto-importing them in the from Standard.Base import all also makes sense).

@@ -19,7 +19,7 @@ polyglot java import org.enso.base.ObjectComparator
Otherwise can support a custom fallback comparator.
new : Nothing | (Any -> Any -> Ordering) -> ObjectComparator
new custom_comparator=Nothing =
comparator_to_java cmp x y = handle_incomparable_value (cmp x y . to_sign)
comparator_to_java cmp x y = Incomparable_Values_Error.handle_errors (cmp x y . to_sign)
Copy link
Member

Choose a reason for hiding this comment

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

I'd like to point out that various compare_to methods throw different Error. Shouldn't all compare failures result into the same Incomparable_Values_Error?

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 that would be a fair step but out of scope for this PR.

test/Tests/src/Semantic/Meta_Spec.enso Outdated Show resolved Hide resolved
Copy link
Collaborator

@hubertp hubertp left a comment

Choose a reason for hiding this comment

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

:shipit:

@@ -310,9 +312,9 @@ into_helper fmt json = case fmt of
_ ->
Copy link
Member

Choose a reason for hiding this comment

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

This into_helper may need to be revisited in some future - I think the way it (ab)uses the atoms to create the formats will be violating our up-coming type system.

# TODO Dubious constructor export
from project.Data.Text.Matching.No_Matches_Found import all
from project.Data.Text.Matching.No_Matches_Found export all
from project.Data.Boolean import Boolean, True, False
Copy link
Member

Choose a reason for hiding this comment

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

Makes me think if we should have a Standard.Core covering the most primitive types, essentially replacing the micro-distribution.

Then in proper Standard.Base we could do from Standard.Core import all instead. And ofc we'd re-export Core in Base, so that regular users would just use Base.

Comment on lines 73 to +74
scheme : Text ! Nothing
scheme self = Internal.handle_nothing self.internal_uri.getScheme
scheme self = handle_nothing self.internal_uri.getScheme
Copy link
Member

Choose a reason for hiding this comment

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

This may not be for this PR, but IMO this API needs to be revisited.

I highly doubt what we want to do here is to throw Nothing. Apart from some control flow, I doubt we want to throw Nothing ever - once it is caught somewhere down the dataflow, it's impossible to tell what it originated from or what it means. It's also rather unclear for the user to see 'Nothing' was thrown. If it was a convention we used across all stdlib and users were used to it (it kind of used to be) then maybe it would be ok, but in just a few places, it is a source of confusion IMO.

IMO we should either throw some more meaningful error like Missing_Field or something. But ideally, I'd just return Nothing as a value instead, making the type not Text ! Nothing but Text | Nothing.

What do you think @jdunkerley ?

Also, I'm not saying to adapt it in this PR (let's merge it ASAP), but I think may be worth noting so that we revisit it in the near future.

Comment on lines +390 to +404
## PRIVATE

Utility method for running an action with Java exceptions mapping.
handle_java_exceptions file ~action =
Panic.catch IOException action caught_panic->
File_Error.wrap_io_exception file caught_panic.payload.cause

## PRIVATE

Converts a Java `IOException` into its Enso counterpart.
wrap_io_exception file io_exception =
if io_exception.is_a NoSuchFileException then Error.throw (File_Error.Not_Found file) else
if io_exception.is_a FileAlreadyExistsException then Error.throw (File_Error.Already_Exists file) else
if io_exception.is_a AccessDeniedException then Error.throw (File_Error.IO_Error file "You do not have permission to access the file") else
Error.throw (File_Error.IO_Error file "An IO error has occurred: "+io_exception.to_text)
Copy link
Member

Choose a reason for hiding this comment

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

With all that logic, this file is growing pretty fast. It's already quite large.

Maybe we should not keep all basic errors in a single file. What about sorting them into smaller modules 'thematically' and then possibly re-exporting through Common for easier importing?

I think it would be more manageable, as such big files are a bit of a pain.

Comment on lines 30 to +35
> Example
Convert a success code to a corresponding number.

import Standard.Base.System.Process.Exit_Code
import Standard.Base.System.Process.Exit_Code.Exit_Code

example_to_number = Exit_Code.Exit_Success.to_number
example_to_number = Exit_Code.Success.to_number
Copy link
Member

Choose a reason for hiding this comment

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

Makes me remember that we used to have plans to have an automatic compilation of Examples.

I think it is something worth considering soon-ish so that we can assure that the examples provided in the docs are correct.

IMO likely this may not take much more time than manually making sure all of them work - and before an official release we definitely should make sure the examples are correct - giving incorrect examples to the users is going to be extremely annoying for them. And given so many refactors I'm almost sure there are other examples which are broken, however careful we would be it's hard to keep track of all.

Copy link
Member Author

Choose a reason for hiding this comment

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

agree need to validate examples - yes picking them out and building them automagically seems right to me.

@@ -106,7 +106,7 @@ type Warning
> Example
Detach warnings of a specific type.

result = Warning.detach_selected_warnings value (_.is_a Illegal_State_Error)
result = Warning.detach_selected_warnings value (_.is_a Illegal_State)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
result = Warning.detach_selected_warnings value (_.is_a Illegal_State)
result = Warning.detach_selected_warnings value (_.is_a Illegal_State.Error)

While I'd expect is_a to work the way you expect too, I don't think that is the case currently.

I run an example check:

from Standard.Base import all

type Foo
    Bar x

main =
    y = Foo.Bar 42
    IO.println <| y.is_a Foo
    IO.println <| y.is_a Foo.Bar

and it gives back

False
True

We'd probably both expect both to be True, but currently that is not the case.

I think we need to revisit how is_a works, along with how Panic.catch, Error.catch and Panic.recover filtering also works.

cc: @hubertp @JaroslavTulach as I'm not sure who would be scheduling the fixes to these?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was broken before Illegal_State_Error is the type as well. I agree we should review is_a and catch.
Ideally would be able to pass both as you say.

@@ -52,5 +52,5 @@ number_input = Error.unimplemented "This function should not be called."
column_1 = ["name", "Enso"]
column_2 = ["stars", 5000]
table = Table.new [column_1, column_2]
table_input = Error.unimplemented "This function should not be called."
table_input = Unimplemented.throw "This function should not be called."
Copy link
Member

Choose a reason for hiding this comment

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

Only now noticed it. I understand that it is supposed to allow easy access to the examples.

But will the component browser somehow know to not insert these fake functions into nodes? I guess it will just insert them. Won't this be weird and confusing?

Comment on lines -839 to 842
# TODO Dubious constructor export
from project.Data.Text.Regex.Engine.Default.Option import all
from project.Data.Text.Regex.Engine.Default.Option export all

## Options specific to the `Default` regular expression engine.
type Option
Copy link
Member

Choose a reason for hiding this comment

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

Do you think maybe it would be worth re-exporting the global Regex_Options in this Option type? So that we could mark that all options - both engine specific and global can be accessed through it?

(not sure though as it may cause confusion that the global ones are of different type, so there are pros and cons to this)

Copy link
Member Author

Choose a reason for hiding this comment

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

The Regex design is not the final one - we are going to redo it in due course.
Hopefully the lower level engine will never be exposed to end users!

Copy link
Member

@radeusgd radeusgd left a comment

Choose a reason for hiding this comment

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

Awesome!

@jdunkerley jdunkerley added the CI: Ready to merge This PR is eligible for automatic merge label Dec 2, 2022
@mergify mergify bot merged commit 0ad70c6 into develop Dec 2, 2022
@mergify mergify bot deleted the wip/jd/base-tidy-5 branch December 2, 2022 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants