Skip to content

Commit

Permalink
Final step removing the Problem_Behavior publishing. (#10461)
Browse files Browse the repository at this point in the history
- Remove publishing the constructors.
- Fix any missed use in libs.
- Alter tests to generally use auto-scoped calls.
- `on_incomparable` to `on_problems`.
  • Loading branch information
jdunkerley authored Jul 5, 2024
1 parent 2124cd0 commit c2c4b95
Show file tree
Hide file tree
Showing 41 changed files with 304 additions and 292 deletions.
23 changes: 11 additions & 12 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Array.enso
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ type Array
elements, returning an an `Ordering` if the two elements are comparable
or `Nothing` if they are not. If set to `Nothing` (the default argument),
`Ordering.compare _ _` method will be used.
- on_incomparable: A `Problem_Behavior` specifying what should happen if
two incomparable values are encountered.
- on_problems: A `Problem_Behavior` specifying what should happen if two
incomparable values are encountered.

By default, elements are sorted in ascending order.

Expand Down Expand Up @@ -121,10 +121,9 @@ type Array
for the default comparator, which is always the first group.

Additionally, an `Incomparable_Values` dataflow error will be returned
if the `on_incomparable` parameter is set to `Problem_Behavior.Report_Error`,
or a warning attached if the `on_incomparable` parameter is set to
`Problem_Behavior.Report_Warning` in case of encountering incomparable
values.
if the `on_problems` parameter is set to `Report_Error`, or a warning
attached if the `on_problems` parameter is set to `Report_Warning` in
case of encountering incomparable values.

It takes equal advantage of ascending and descending runs in the array,
making it much simpler to merge two or more sorted arrays: simply
Expand All @@ -147,8 +146,8 @@ type Array

[My_Type.Value 'hello', 1].to_array.sort == [1, My_Type.Value 'hello'].to_array
sort : Sort_Direction -> (Any -> Any)|Nothing -> (Any -> Any -> (Ordering|Nothing))|Nothing -> Problem_Behavior -> Vector Any ! Incomparable_Values
sort self (order = Sort_Direction.Ascending) on=Nothing by=Nothing on_incomparable:Problem_Behavior=..Ignore =
Array_Like_Helpers.sort self order on by on_incomparable
sort self (order = Sort_Direction.Ascending) on=Nothing by=Nothing on_problems:Problem_Behavior=..Ignore =
Array_Like_Helpers.sort self order on by on_problems

## ALIAS first, head, last, limit, sample, slice, tail, top, keep
GROUP Selections
Expand Down Expand Up @@ -390,7 +389,7 @@ type Array
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -429,7 +428,7 @@ type Array
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -676,7 +675,7 @@ type Array
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -899,7 +898,7 @@ type Array
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down
23 changes: 11 additions & 12 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ type Vector a
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -728,7 +728,7 @@ type Vector a
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -782,7 +782,7 @@ type Vector a
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -1024,7 +1024,7 @@ type Vector a
Errors that are thrown when executing the supplied function are wrapped
in `Map_Error`, which contains the index at which the error occurred.

In the `Problem_Behavior.Report_Warning` case, only `MAX_MAP_WARNINGS`
In the `Report_Warning` case, only `MAX_MAP_WARNINGS`
warnings are attached to result values. After that, the warnings are
dropped, but a count of the additional warnings is attached in an
`Additional_Warnings` warning.
Expand Down Expand Up @@ -1121,8 +1121,8 @@ type Vector a
elements, returning an an `Ordering` if the two elements are comparable
or `Nothing` if they are not. If set to `Nothing` (the default argument),
`Ordering.compare _ _` method will be used.
- on_incomparable: A `Problem_Behavior` specifying what should happen if
two incomparable values are encountered.
- on_problems: A `Problem_Behavior` specifying what should happen if two
incomparable values are encountered.

By default, elements are sorted in ascending order.

Expand Down Expand Up @@ -1157,10 +1157,9 @@ type Vector a
for the default comparator, which is always the first group.

Additionally, an `Incomparable_Values` dataflow error will be returned
if the `on_incomparable` parameter is set to `Problem_Behavior.Report_Error`,
or a warning attached if the `on_incomparable` parameter is set to
`Problem_Behavior.Report_Warning` in case of encountering incomparable
values.
if the `on_problems` parameter is set to `Report_Error`, or a warning
attached if the `on_problems` parameter is set to `Report_Warning` in
case of encountering incomparable values.

It takes equal advantage of ascending and descending runs in the array,
making it much simpler to merge two or more sorted arrays: simply
Expand All @@ -1183,8 +1182,8 @@ type Vector a

[My_Type.Value 'hello', 1].sort == [1, My_Type.Value 'hello']
sort : Sort_Direction -> (Any -> Any)|Nothing -> (Any -> Any -> (Ordering|Nothing))|Nothing -> Problem_Behavior -> Vector Any ! Incomparable_Values
sort self (order = Sort_Direction.Ascending) on=Nothing by=Nothing on_incomparable:Problem_Behavior=..Ignore =
Array_Like_Helpers.sort self order on by on_incomparable
sort self (order = Sort_Direction.Ascending) on=Nothing by=Nothing on_problems:Problem_Behavior=..Ignore =
Array_Like_Helpers.sort self order on by on_problems

## ALIAS deduplicate, unique
GROUP Selections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,3 @@ type Problem_Behavior
warnings = Warning.get_all result . map .value
cleared_result = Warning.set result []
self.attach_problems_after cleared_result warnings

## PRIVATE
Returns a mapping of Problem_Behavior constructors to an integer.
Used for sending the number to Java, rather than sending the atom.
to_number self = case self of
Problem_Behavior.Ignore -> 0
Problem_Behavior.Report_Warning -> 1
Problem_Behavior.Report_Error -> 2
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,20 @@ check_start_valid start length function =
if used_start < 0 || used_start > length then Error.throw (Index_Out_Of_Bounds.Error start length+1) else
function used_start

sort vector order on by on_incomparable =
sort vector order on by on_problems:Problem_Behavior =
comps = case on == Nothing of
True -> vector.map it-> Comparable.from it
False -> vector.map it-> Comparable.from (on it)
compare_funcs = comps.map (it-> it.compare)
vector.sort_builtin order.to_sign comps compare_funcs by on on_incomparable.to_number
vector.sort_builtin order.to_sign comps compare_funcs by on (on_problems_to_number on_problems)

## PRIVATE
Returns a mapping of Problem_Behavior constructors to an integer.
Used for sending the number to Java, rather than sending the atom.
private on_problems_to_number on_problems:Problem_Behavior = case on_problems of
Problem_Behavior.Ignore -> 0
Problem_Behavior.Report_Warning -> 1
Problem_Behavior.Report_Error -> 2

distinct vector on =
Vector.build builder->
Expand Down
1 change: 0 additions & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ from project.Data.Range.Extensions export all
from project.Data.Statistics.Extensions export all
from project.Data.Text.Extensions export all
from project.Data.Text.Regex export regex
from project.Errors.Problem_Behavior.Problem_Behavior export all
from project.Function export all
from project.Meta.Enso_Project export enso_project
from project.Network.Extensions export all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,7 @@ type DB_Table
their layout in memory. Database tables may not impose a deterministic
ordering. If the table defines a primary key, it is used to by default
to ensure deterministic ordering. That can be overridden by specifying
a different ordering using `Table.order_by`. If no primary key was
a different ordering using `Table.sort`. If no primary key was
defined nor any ordering was specified explicitly by the user, the
order of columns is undefined and the operation will fail, reporting a
`Undefined_Column_Order` problem and returning an empty table.
Expand Down Expand Up @@ -1526,7 +1526,7 @@ type DB_Table
their layout in memory. Database tables may not impose a deterministic
ordering. If the table defines a primary key, it is used to by default
to ensure deterministic ordering. That can be overridden by specifying
a different ordering using `Table.order_by`. If no primary key was
a different ordering using `Table.sort`. If no primary key was
defined nor any ordering was specified explicitly by the user, the
order of columns is undefined and the operation will fail, reporting a
`Undefined_Column_Order` problem and returning an empty table.
Expand Down Expand Up @@ -1729,7 +1729,7 @@ type DB_Table
their layout in memory. Database tables may not impose a deterministic
ordering. If the table defines a primary key, it is used to by default
to ensure deterministic ordering. That can be overridden by specifying
a different ordering using `Table.order_by`. If no primary key was
a different ordering using `Table.sort`. If no primary key was
defined nor any ordering was specified explicitly by the user, the
order of columns is undefined and the operation will fail, reporting a
`Undefined_Column_Order` problem and returning an empty table.
Expand Down
4 changes: 2 additions & 2 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ type Table
their layout in memory. Database tables may not impose a deterministic
ordering. If the table defines a primary key, it is used to by default
to ensure deterministic ordering. That can be overridden by specifying
a different ordering using `Table.order_by`. If no primary key was
a different ordering using `Table.sort`. If no primary key was
defined nor any ordering was specified explicitly by the user, the
order of columns is undefined and the operation will fail, reporting a
`Undefined_Column_Order` problem and returning an empty table.
Expand Down Expand Up @@ -3177,7 +3177,7 @@ concat_columns column_set all_tables result_type result_row_count needs_cast on_
storage_builder.appendNulls null_row_count
_ : Integer ->
column = parent_table.at i
converted = if needs_cast then column.cast result_type on_problems=Report_Error else column
converted = if needs_cast then column.cast result_type on_problems=..Report_Error else column
storage = converted.java_column.getStorage
storage_builder.appendBulkStorage storage
sealed_storage = storage_builder.seal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1188,7 +1188,7 @@ public void testShouldQuoteValuesContainingTheCommentSymbol() {
suite =
Test.specify "should quote values containing the comment symbol if comments are enabled" <|
format = Delimited_Format.Delimited ',' . with_comments
table.write file format on_problems=Report_Error . should_succeed
table.write file format on_problems=..Report_Error . should_succeed
expected_text_2 = normalize_lines <| \"""
"#",B
b,
Expand Down
14 changes: 7 additions & 7 deletions test/Base_Tests/src/Data/Ordering_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,8 @@ add_specs suite_builder =
expect_no_warns [[1]].sort

group_builder.specify "should produce warnings when sorting nested vectors" <|
expect_incomparable_warn [1] [2] <| [[1], [2]].sort on_incomparable=Problem_Behavior.Report_Warning . should_equal [[1], [2]]
expect_incomparable_warn [2] [1] <| [[2], [1]].sort on_incomparable=Problem_Behavior.Report_Warning . should_equal [[2], [1]]
expect_incomparable_warn [1] [2] <| [[1], [2]].sort on_problems=..Report_Warning . should_equal [[1], [2]]
expect_incomparable_warn [2] [1] <| [[2], [1]].sort on_problems=..Report_Warning . should_equal [[2], [1]]

group_builder.specify "should be able to sort primitive values in atoms" pending=topo_sort_pending <|
[Ord.Value Nothing, Ord.Value 20, Ord.Value 10].sort . should_equal [Ord.Value 10, Ord.Value 20, Ord.Value Nothing]
Expand All @@ -186,13 +186,13 @@ add_specs suite_builder =
[(UPair.Value 1 2), (UPair.Value 3 4)].sort . should_fail_with Incomparable_Values

group_builder.specify "should attach warning when trying to sort incomparable values" <|
expect_incomparable_warn Nothing Number.nan <| [Nothing, Number.nan].sort on_incomparable=Problem_Behavior.Report_Warning
expect_incomparable_warn 1 "hello" <| [1, "hello"].sort on_incomparable=Problem_Behavior.Report_Warning
expect_incomparable_warn Nothing Number.nan <| [Nothing, Number.nan].sort on_problems=..Report_Warning
expect_incomparable_warn 1 "hello" <| [1, "hello"].sort on_problems=..Report_Warning

group_builder.specify "should respect previous warnings on a vector" <|
Problems.expect_warning "my_warn" <| (Warning.attach "my_warn" [3, 2]) . sort
Problems.expect_warning "my_warn" <| (Warning.attach "my_warn" [3, Number.nan]) . sort
expect_incomparable_warn 3 Number.nan <| (Warning.attach "my_warn" [3, Number.nan]) . sort on_incomparable=Problem_Behavior.Report_Warning
expect_incomparable_warn 3 Number.nan <| (Warning.attach "my_warn" [3, Number.nan]) . sort on_problems=..Report_Warning

group_builder.specify "should respect previous warnings on vectors" pending="https://github.com/enso-org/enso/issues/6070" <|
Problems.expect_warning "my_warn" <| [3, Warning.attach "my_warn" 2].sort
Expand All @@ -216,13 +216,13 @@ add_specs suite_builder =

group_builder.specify "should produce warning when sorting types with different comparators" <|
[Ord.Value 1, 1].sort . should_equal [1, Ord.Value 1]
sorted = [Ord.Value 1, 1].sort on_incomparable=Problem_Behavior.Report_Warning
sorted = [Ord.Value 1, 1].sort on_problems=..Report_Warning
Warning.get_all sorted . at 0 . value . starts_with "Different comparators" . should_be_true

group_builder.specify "should merge groups of values with custom comparators based on the comparators FQN" <|
[Ord.Value 1, My_Type.Value 1].sort . should_equal [My_Type.Value 1, Ord.Value 1]
[My_Type.Value 1, Ord.Value 1].sort . should_equal [My_Type.Value 1, Ord.Value 1]
sorted = [Ord.Value 1, My_Type.Value 1].sort on_incomparable=Problem_Behavior.Report_Warning
sorted = [Ord.Value 1, My_Type.Value 1].sort on_problems=..Report_Warning
Warning.get_all sorted . at 0 . value . starts_with "Different comparators" . should_be_true

group_builder.specify "should be stable when sorting values with different comparators" <|
Expand Down
Loading

0 comments on commit c2c4b95

Please sign in to comment.