From 5b9644421dcf01be018d4bcc1a643151b98872a9 Mon Sep 17 00:00:00 2001 From: Pavel Marek Date: Mon, 4 Nov 2024 19:06:17 +0100 Subject: [PATCH] No_Wrap is an uniquely constructible builtin --- .../Base/0.0.0-dev/src/Data/Statistics.enso | 8 ++-- .../Base/0.0.0-dev/src/Data/Vector.enso | 1 + .../Base/0.0.0-dev/src/Network/HTTP.enso | 4 +- .../Standard/Base/0.0.0-dev/src/Warning.enso | 2 +- .../src/Internal/DDL_Transaction.enso | 4 +- .../0.0.0-dev/src/Internal/IR/Context.enso | 4 +- .../Upload/Helpers/Argument_Checks.enso | 4 +- .../Internal/Upload/Helpers/SQL_Helpers.enso | 2 +- .../0.0.0-dev/src/Take_Drop_Helpers.enso | 2 +- .../Standard/Table/0.0.0-dev/src/Column.enso | 4 +- .../Table/0.0.0-dev/src/Data_Formatter.enso | 8 ++-- .../src/Internal/Aggregate_Column_Helper.enso | 4 +- .../0.0.0-dev/src/Internal/Java_Problems.enso | 2 +- .../0.0.0-dev/src/Internal/Join_Helpers.enso | 4 +- .../src/Internal/Lookup_Helpers.enso | 2 +- .../0.0.0-dev/src/Internal/Table_Helpers.enso | 2 +- .../0.0.0-dev/src/Internal/Table_Ref.enso | 4 +- .../src/Internal/Value_Type_Helpers.enso | 2 +- .../Standard/Table/0.0.0-dev/src/Table.enso | 12 +++--- .../node/expression/builtin/error/NoWrap.java | 15 ++++++- .../interpreter/runtime/builtin/Builtins.java | 8 ++-- .../data/vector/VectorFromFunctionNode.java | 43 ++++++++----------- test/Base_Tests/src/Data/Vector_Spec.enso | 32 +++++++------- 23 files changed, 89 insertions(+), 84 deletions(-) diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso index 162010f525e9..c4336db1bd45 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Statistics.enso @@ -190,7 +190,7 @@ type Statistic compute_bulk : Vector -> Vector Statistic -> Vector Any compute_bulk data statistics:Vector=[Statistic.Count, Statistic.Sum] = resolved_stats = statistics.map (r-> r:Statistic) - moment_order = resolved_stats.map on_problems=No_Wrap .order + moment_order = resolved_stats.map on_problems=No_Wrap.Value .order has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum) has_product = resolved_stats.any (s-> s == Statistic.Product) max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max @@ -202,7 +202,7 @@ type Statistic Error.throw (Illegal_Argument.Error ("Can only compute " + stat.to_text + " on numerical data sets.")) if max_moment_order > 0 && counter.moments.is_nothing then report_error resolved_stats else - resolved_stats.map on_problems=No_Wrap statistic-> case statistic of + resolved_stats.map on_problems=No_Wrap.Value statistic-> case statistic of Statistic.Covariance series -> check_if_empty counter.count <| calculate_correlation_statistics data series . covariance Statistic.Pearson series -> check_if_empty counter.count <| calculate_correlation_statistics data series . pearsonCorrelation Statistic.R_Squared series -> check_if_empty counter.count <| calculate_correlation_statistics data series . rSquared @@ -229,7 +229,7 @@ type Statistic running_bulk data statistics=[Statistic.Count, Statistic.Sum] = resolved_stats = statistics.map (r-> r:Statistic) check_running_support resolved_stats <| - moment_order = resolved_stats.map on_problems=No_Wrap .order + moment_order = resolved_stats.map on_problems=No_Wrap.Value .order has_min_max = resolved_stats.any (s-> s == Statistic.Minimum || s == Statistic.Maximum) has_product = resolved_stats.any (s-> s == Statistic.Product) max_moment_order = moment_order.filter (v-> v != Nothing) . fold 0 .max @@ -241,7 +241,7 @@ type Statistic data.fold counter current->value-> result = compute_fold current value - row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap s-> case s of + row = Panic.rethrow_wrapped_if_error <| resolved_stats.map on_problems=No_Wrap.Value s-> case s of Statistic.Maximum -> if result.count == 0 then Nothing else result.maximum Statistic.Minimum -> if result.count == 0 then Nothing else result.minimum _ -> result.compute s diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso index 27c9bed4382a..55919fd0f765 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Data/Vector.enso @@ -1550,6 +1550,7 @@ type Map_Error Indicates that a method should not wrap thrown errors in `Map_Error`. @Builtin_Type type No_Wrap + Value ## PRIVATE Wrapped_Error.from (that : Map_Error) = Wrapped_Error.Value that that.inner_error diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso index 5d8575906eed..778e5d1b86d1 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Network/HTTP.enso @@ -128,7 +128,7 @@ type HTTP boundary = body_publisher_and_boundary.second boundary_header_list = if boundary.is_nothing then [] else [Header.multipart_form_data boundary] all_headers = headers + boundary_header_list - mapped_headers = all_headers.map on_problems=No_Wrap .to_java_pair + mapped_headers = all_headers.map on_problems=No_Wrap.Value .to_java_pair response = Response.Value (EnsoSecretHelper.makeRequest self.internal_http_client builder req.uri.to_java_representation mapped_headers) if error_on_failure_code.not || response.code.is_success then response else @@ -186,7 +186,7 @@ type HTTP ## PRIVATE parse_headers : Vector (Header | Pair Text Text) -> Vector Header parse_headers headers = - headers . map on_problems=No_Wrap h-> case h of + headers . map on_problems=No_Wrap.Value h-> case h of _ : Vector -> Header.new (h.at 0) (h.at 1) _ : Pair -> Header.new (h.at 0) (h.at 1) _ : Function -> h:Header diff --git a/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso b/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso index 213aec0af397..b2c8ffd9ad70 100644 --- a/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso +++ b/distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso @@ -296,7 +296,7 @@ set_array value warnings = @Builtin_Method "Warning.set_array" map_attached_warnings_helper : (Any -> Maybe Any) -> Any -> Integer -> Any map_attached_warnings_helper mapper value frames_to_drop = warnings = Warning.get_all value - mapped_warnings = warnings.map on_problems=No_Wrap warning-> + mapped_warnings = warnings.map on_problems=No_Wrap.Value warning-> case mapper warning.value of Maybe.Some new_payload -> self_call_name = "Warning.map_attached_warnings_helper" diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso index 024952786c5f..e44085b868b5 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/DDL_Transaction.enso @@ -71,7 +71,7 @@ run_transaction_with_tables connection (tables : Vector Transactional_Table_Desc ## PRIVATE private create_tables_inside_transaction connection (tables : Vector Transactional_Table_Description) (callback : Vector DB_Table -> Any) -> Any = connection.jdbc_connection.run_within_transaction <| - created = tables.map on_problems=No_Wrap t-> t.create connection + created = tables.map on_problems=No_Wrap.Value t-> t.create connection created.if_not_error <| result = callback created @@ -89,7 +89,7 @@ private create_tables_outside_transaction connection (tables : Vector Transactio Panic.throw caught_panic Panic.catch Any handler=handle_panic <| - created = tables.map on_problems=No_Wrap t-> + created = tables.map on_problems=No_Wrap.Value t-> table = t.create connection # We only register a table for cleanup if it was successfully created. table.if_not_error <| diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso index 64d9796edc02..a703af4eb084 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/IR/Context.enso @@ -162,8 +162,8 @@ type Context rewrite_internal_column column = Internal_Column.Value column.name column.sql_type_reference (SQL_Expression.Column alias column.name) - new_columns = column_lists.map on_problems=No_Wrap columns-> - columns.map on_problems=No_Wrap rewrite_internal_column + new_columns = column_lists.map on_problems=No_Wrap.Value columns-> + columns.map on_problems=No_Wrap.Value rewrite_internal_column encapsulated_columns = column_lists.flat_map columns-> columns.map column-> [column.name, column.expression] diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso index 39f523a50959..ef5741eab8fb 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/Argument_Checks.enso @@ -34,7 +34,7 @@ check_target_table_for_update target_table ~action = case target_table of resolve_primary_key structure primary_key = case primary_key of Nothing -> Nothing _ : Vector -> if primary_key.is_empty then Nothing else - validated = primary_key.map on_problems=No_Wrap key-> + validated = primary_key.map on_problems=No_Wrap.Value key-> if key.is_a Text then key else Error.throw (Illegal_Argument.Error ("Primary key must be a vector of column names, instead got a " + (Meta.type_of key . to_display_text))) validated.if_not_error <| @@ -74,6 +74,6 @@ check_update_arguments_structure_match source_table target_table key_columns upd if missing_target_key_columns.not_empty then Error.throw (Missing_Input_Columns.Error missing_target_key_columns.to_vector "the target table") else if (update_action != Update_Action.Insert) && key_columns.is_empty then Error.throw (Illegal_Argument.Error "For the `update_action = "+update_action.to_text+"`, the `key_columns` must be specified to define how to match the records.") else # Verify type matching - problems = source_table.columns.flat_map on_problems=No_Wrap check_source_column + problems = source_table.columns.flat_map on_problems=No_Wrap.Value check_source_column problems.if_not_error <| on_problems.attach_problems_before problems action diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso index 96262569d69d..07eddec1d993 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Internal/Upload/Helpers/SQL_Helpers.enso @@ -30,7 +30,7 @@ make_batched_insert_template connection table_name column_names = prepare_create_table_statement : Connection -> Text -> Vector Column_Description -> Vector Text -> Boolean -> Problem_Behavior -> SQL_Statement prepare_create_table_statement connection table_name columns primary_key temporary on_problems:Problem_Behavior = type_mapping = connection.dialect.get_type_mapping - column_descriptors = columns.map on_problems=No_Wrap def-> + column_descriptors = columns.map on_problems=No_Wrap.Value def-> sql_type = type_mapping.value_type_to_sql def.value_type on_problems sql_type_text = type_mapping.sql_type_to_text sql_type Create_Column_Descriptor.Value def.name sql_type_text def.constraints diff --git a/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso b/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso index d6a86236e77c..f7da4f0842da 100644 --- a/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso +++ b/distribution/lib/Standard/Database/0.0.0-dev/src/Take_Drop_Helpers.enso @@ -31,7 +31,7 @@ take_drop_helper take_drop table selector:(Index_Sub_Range | Range | Integer) = row_column_name = table.make_temp_column_name table_with_row_number = table.add_row_number name=row_column_name from=0 - subqueries = ranges.map on_problems=No_Wrap range-> + subqueries = ranges.map on_problems=No_Wrap.Value range-> generate_subquery table_with_row_number row_column_name range combined = subqueries.reduce (a-> b-> a.union b) combined.remove_columns row_column_name diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso index 88138269b922..82cac218ae30 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Column.enso @@ -2101,7 +2101,7 @@ type Column map : (Any -> Any) -> Boolean -> Value_Type | Auto -> Column ! Invalid_Value_Type map self function skip_nothing=True expected_value_type=Auto = new_fn = if skip_nothing then (x-> if x.is_nothing then Nothing else function x) else function - new_st = self.to_vector.map on_problems=No_Wrap new_fn + new_st = self.to_vector.map on_problems=No_Wrap.Value new_fn Column.from_vector self.name new_st value_type=expected_value_type ## ALIAS combine, join by row position, merge @@ -2149,7 +2149,7 @@ type Column function x y False -> function new_name = naming_helper.binary_operation_name "x" self that - vec = self.to_vector.zip on_problems=No_Wrap that.to_vector new_fn + vec = self.to_vector.zip on_problems=No_Wrap.Value that.to_vector new_fn Column.from_vector new_name vec value_type=expected_value_type ## GROUP Standard.Base.Metadata diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso index 08cc1d265c32..688800759837 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Data_Formatter.enso @@ -129,7 +129,7 @@ type Data_Formatter vector = case formats of v : Vector -> v singleton -> [singleton] - converted = vector.map on_problems=No_Wrap elem-> + converted = vector.map on_problems=No_Wrap.Value elem-> ## Ensure the element is a `Date_Time_Formatter` or is converted to it. We need to convert _each_ element - we cannot perform a 'bulk' conversion like `vector : Vector Date_Time_Formatter` because of erasure. checked = elem : Date_Time_Formatter @@ -216,17 +216,17 @@ type Data_Formatter ## PRIVATE make_date_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - DateParser.new (self.date_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + DateParser.new (self.date_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_date_time_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + DateTimeParser.new (self.datetime_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_time_of_day_parser self = self.wrap_base_parser <| Panic.catch JException handler=(caught_panic-> Error.throw (Illegal_Argument.Error caught_panic.payload.getMessage)) <| - TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap .get_java_formatter_for_parsing) + TimeOfDayParser.new (self.time_formats.map on_problems=No_Wrap.Value .get_java_formatter_for_parsing) ## PRIVATE make_identity_parser self = self.wrap_base_parser IdentityParser.new diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso index f5c86cd080ee..cd2cb464453c 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Aggregate_Column_Helper.enso @@ -67,7 +67,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi assert (resolved_keys.contains Nothing . not) problem_builder = Problem_Builder.new error_on_missing_columns=error_on_missing_columns columns = if old_style then group_by else keys+aggregates - valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not + valid_resolved_aggregate_columns = columns.map on_problems=No_Wrap.Value (resolve_aggregate table problem_builder) . filter x-> x.is_nothing.not # Grouping Key key_columns = resolved_keys.map .column @@ -80,7 +80,7 @@ prepare_aggregate_columns naming_helper group_by aggregates table error_on_missi The second pass resolves the default names, ensuring that they do not clash with the user-specified names (ensuring that user-specified names take precedence). - pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap c-> if c.as == "" then "" else + pass_1 = valid_resolved_aggregate_columns.map on_problems=No_Wrap.Value c-> if c.as == "" then "" else # Verify if the user-provided name is valid and if not, throw an error. naming_helper.ensure_name_is_valid c.as <| unique.make_unique c.as diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso index d9f05baef9cb..f7ee48006933 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Java_Problems.enso @@ -88,7 +88,7 @@ unpack_problem_summary problem_summary = ## TODO [RW, GT] In the next iterations we will want to remove `translate_problem` in favour of constructing Enso problem instances directly in Java code. To do so, we will need https://github.com/enso-org/enso/issues/7797 - parsed = problems_array . map on_problems=No_Wrap translate_problem + parsed = problems_array . map on_problems=No_Wrap.Value translate_problem if count == parsed.length then parsed else parsed + [Additional_Warnings.Error (count - parsed.length)] diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso index de49a7dc7051..6e5372fd6cf3 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Join_Helpers.enso @@ -43,7 +43,7 @@ type Join_Condition_Resolver is_nothing column = case column of Nothing -> True _ -> False - conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap condition-> (condition:Join_Condition) + conditions_vector = Vector.unify_vector_or_element conditions . map on_problems=No_Wrap.Value condition-> (condition:Join_Condition) handle_equals left_selector right_selector = left = resolve_left left_selector right = resolve_right right_selector @@ -52,7 +52,7 @@ type Join_Condition_Resolver if left.name == right.name then redundant_names.append right.name self.make_equals problem_builder left right - converted = conditions_vector.map on_problems=No_Wrap condition-> case condition of + converted = conditions_vector.map on_problems=No_Wrap.Value condition-> case condition of Join_Condition.Equals left_selector right_selector -> right_resovled = if right_selector == "" then left_selector else right_selector handle_equals left_selector right_resovled diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso index 1f09b59273ed..8ec79d4fee96 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Lookup_Helpers.enso @@ -51,7 +51,7 @@ prepare_columns_for_lookup base_table lookup_table key_columns_selector add_new_ problems_to_add = Builder.new key_columns.if_not_error <| lookup_table_key_columns.if_not_error <| key_set = Hashset.from_vector key_columns - my_updated_columns = base_table.columns.map on_problems=No_Wrap base_column-> + my_updated_columns = base_table.columns.map on_problems=No_Wrap.Value base_column-> base_column_name = base_column.name is_key = key_set.contains base_column_name case is_key of diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso index 56d9111cefa3..f1fe3b385506 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Helpers.enso @@ -582,5 +582,5 @@ replace_columns_with_transformed_columns : Table -> Text | Integer | Regex | Vec replace_columns_with_transformed_columns table selectors transformer error_on_missing_columns=True on_problems:Problem_Behavior=..Report_Warning = internal_columns = table.columns_helper.select_columns selectors Case_Sensitivity.Default reorder=False error_on_missing_columns=error_on_missing_columns on_problems=on_problems columns = internal_columns.map table.columns_helper.make_column - new_columns = columns.map on_problems=No_Wrap transformer + new_columns = columns.map on_problems=No_Wrap.Value transformer replace_columns_with_columns table columns new_columns diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso index c365843e6a3b..76c49093e5c5 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Table_Ref.enso @@ -103,6 +103,6 @@ check_is_in_values operation_name values = Error.throw (Illegal_Argument.Error message) _ -> v case values of - _ : Vector -> values.map on_problems=No_Wrap check_value - _ : Array -> values.map on_problems=No_Wrap check_value + _ : Vector -> values.map on_problems=No_Wrap.Value check_value + _ : Array -> values.map on_problems=No_Wrap.Value check_value _ -> check_value values diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso index 92a030e128d3..8bcdbb60339e 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Internal/Value_Type_Helpers.enso @@ -273,7 +273,7 @@ check_binary_boolean_op arg1 arg2 ~action = - action: the action to run if the arguments are compatible. check_multi_argument_comparable_op column arg_or_args ~action = args = Vector.unify_vector_or_element arg_or_args - checked = args.map on_problems=No_Wrap arg-> + checked = args.map on_problems=No_Wrap.Value arg-> Value_Type.expect_comparable column arg <| True checked.if_not_error <| diff --git a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso index 9fd946da0195..e7c5bcd222ff 100644 --- a/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso +++ b/distribution/lib/Standard/Table/0.0.0-dev/src/Table.enso @@ -140,7 +140,7 @@ type Table new columns = invalid_input_shape = Error.throw (Illegal_Argument.Error "Each column must be represented by a pair whose first element is the column name and the second element is a vector of elements that will constitute that column, or an existing column.") - cols = columns.map on_problems=No_Wrap c-> + cols = columns.map on_problems=No_Wrap.Value c-> case c of v : Vector -> if v.length != 2 then invalid_input_shape else @@ -1512,7 +1512,7 @@ type Table False -> Dictionary.from_vector <| selected_columns.map c-> [c.name, True] - new_columns = self.columns.map on_problems=No_Wrap column-> if selected_column_names.contains_key column.name . not then column else + new_columns = self.columns.map on_problems=No_Wrap.Value column-> if selected_column_names.contains_key column.name . not then column else Value_Type.expect_text column <| storage = column.java_column.getStorage new_storage = Java_Problems.with_problem_aggregator on_problems java_problem_aggregator-> @@ -2732,10 +2732,10 @@ type Table merge self lookup_table:Table key_columns:(Vector (Integer | Text | Regex) | Text | Integer | Regex) add_new_columns:Boolean=False allow_unmatched_rows:Boolean=True on_problems:Problem_Behavior=..Report_Warning = lookup_columns = Lookup_Helpers.prepare_columns_for_lookup self lookup_table key_columns add_new_columns allow_unmatched_rows on_problems - java_descriptions = lookup_columns.map make_java_lookup_column_description on_problems=No_Wrap + java_descriptions = lookup_columns.map make_java_lookup_column_description on_problems=No_Wrap.Value keys = lookup_columns.filter .is_key - java_keys = keys.map on_problems=No_Wrap key_column-> + java_keys = keys.map on_problems=No_Wrap.Value key_column-> Java_Join_Equals.new key_column.base_column.java_column key_column.lookup_column.java_column handle_java_errors ~action = @@ -3205,7 +3205,7 @@ type Table normalize_group_by input = case input of Aggregate_Column.Group_By c _ -> c _ : Aggregate_Column -> Error.throw (Illegal_Argument.Error "Only Aggregate_Column.Group_By can be used for cross_tab group_by clause.") - _ : Vector -> input.map on_problems=No_Wrap normalize_group_by + _ : Vector -> input.map on_problems=No_Wrap.Value normalize_group_by _ -> input ## validate the name and group_by columns @@ -3217,7 +3217,7 @@ type Table grouping = columns_helper.select_columns_helper (normalize_group_by group_by) Case_Sensitivity.Default True problem_builder ## Validate the values - resolved_values = Vector.unify_vector_or_element values . map on_problems=No_Wrap (Aggregate_Column_Helper.resolve_aggregate self problem_builder) + resolved_values = Vector.unify_vector_or_element values . map on_problems=No_Wrap.Value (Aggregate_Column_Helper.resolve_aggregate self problem_builder) is_group_by c = case c of Aggregate_Column.Group_By _ _ -> True _ -> False diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java index 78a8a52f03c0..be2bc664e33e 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/error/NoWrap.java @@ -1,9 +1,20 @@ package org.enso.interpreter.node.expression.builtin.error; +import java.util.List; import org.enso.interpreter.dsl.BuiltinType; import org.enso.interpreter.node.expression.builtin.Builtin; +import org.enso.interpreter.node.expression.builtin.UniquelyConstructibleBuiltin; @BuiltinType(name = "Standard.Base.Data.Vector.No_Wrap") -public class NoWrap extends Builtin { - // Empty on purpose - does not have any constructors +public class NoWrap extends UniquelyConstructibleBuiltin { + + @Override + protected String getConstructorName() { + return "Value"; + } + + @Override + protected List getConstructorParamNames() { + return List.of(); + } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java index 5aadffd2f243..6698287f16da 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/builtin/Builtins.java @@ -120,7 +120,7 @@ public static class Debug { private final Builtin timeOfDay; private final Builtin timeZone; private final Builtin warning; - private final Builtin noWrap; + private final NoWrap noWrap; private final ProblemBehavior problemBehavior; private final AdditionalWarnings additionalWarnings; @@ -174,7 +174,7 @@ public Builtins(EnsoContext context) { timeOfDay = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeOfDay.class); timeZone = builtins.get(org.enso.interpreter.node.expression.builtin.date.TimeZone.class); warning = builtins.get(Warning.class); - noWrap = builtins.get(NoWrap.class); + noWrap = getBuiltinType(NoWrap.class); problemBehavior = getBuiltinType(ProblemBehavior.class); additionalWarnings = getBuiltinType(AdditionalWarnings.class); @@ -617,8 +617,8 @@ public ProblemBehavior problemBehavior() { } /** Returns the {@code No_Wrap} atom constructor. */ - public Type noWrap() { - return noWrap.getType(); + public NoWrap noWrap() { + return noWrap; } /** Returns the {@code Additional_Warnings} atom constructor. */ diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java index 7831a2d28867..28ce6bb60134 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/data/vector/VectorFromFunctionNode.java @@ -10,6 +10,7 @@ import com.oracle.truffle.api.profiles.BranchProfile; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.callable.dispatch.InvokeFunctionNode; +import org.enso.interpreter.node.expression.builtin.error.NoWrap; import org.enso.interpreter.node.expression.builtin.error.ProblemBehavior; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.callable.function.Function; @@ -50,12 +51,11 @@ Object doItCached( State state, long length, Function func, - Object onProblemsAtom, - @Cached("onProblemsAtom") Object onProblemsAtomCached, + Atom onProblemsAtom, + @Cached("onProblemsAtom") Atom onProblemsAtomCached, @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, @Shared @Cached("build()") AppendWarningNode appendWarningNode, @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, @Shared @Cached BranchProfile errorEncounteredProfile, @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { return doIt( @@ -65,7 +65,6 @@ Object doItCached( func, onProblemsAtomCached, warnsLib, - typesLib, invokeFunctionNode, appendWarningNode, errorEncounteredProfile, @@ -78,11 +77,10 @@ Object doItUncached( State state, long length, Function func, - Object onProblemsAtom, + Atom onProblemsAtom, @Shared @Cached("buildWithArity(1)") InvokeFunctionNode invokeFunctionNode, @Shared @Cached("build()") AppendWarningNode appendWarningNode, @Shared @CachedLibrary(limit = "3") WarningsLibrary warnsLib, - @Shared @CachedLibrary(limit = "3") TypesLibrary typesLib, @Shared @Cached BranchProfile errorEncounteredProfile, @Shared @Cached HasContextEnabledNode hasContextEnabledNode) { return doIt( @@ -92,7 +90,6 @@ Object doItUncached( func, onProblemsAtom, warnsLib, - typesLib, invokeFunctionNode, appendWarningNode, errorEncounteredProfile, @@ -104,15 +101,14 @@ private Object doIt( State state, long length, Function func, - Object onProblemsAtom, + Atom onProblemsAtom, WarningsLibrary warnsLib, - TypesLibrary typesLib, InvokeFunctionNode invokeFunctionNode, AppendWarningNode appendWarningNode, BranchProfile errorEncounteredProfile, HasContextEnabledNode hasContextEnabledNode) { var ctx = EnsoContext.get(this); - var onProblems = processOnProblemsArg(onProblemsAtom, typesLib); + var onProblems = processOnProblemsArg(onProblemsAtom); var len = Math.toIntExact(length); var nothing = ctx.getNothing(); var target = ArrayBuilder.newBuilder(len); @@ -158,24 +154,17 @@ private Object doIt( } } - private OnProblems processOnProblemsArg(Object onProblems, TypesLibrary typesLib) { + private OnProblems processOnProblemsArg(Atom onProblems) { var ctx = EnsoContext.get(this); var problemBehaviorBuiltin = ctx.getBuiltins().problemBehavior(); var noWrapBuiltin = ctx.getBuiltins().noWrap(); - if (onProblems instanceof Atom onProblemsAtom) { - if (isIgnore(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.IGNORE; - } else if (isReportError(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.REPORT_ERROR; - } else if (isReportWarning(onProblemsAtom, problemBehaviorBuiltin)) { - return OnProblems.REPORT_WARNING; - } - } - if (!typesLib.hasType(onProblems)) { - throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); - } - var onProblemsType = typesLib.getType(onProblems); - if (onProblemsType == noWrapBuiltin) { + if (isIgnore(onProblems, problemBehaviorBuiltin)) { + return OnProblems.IGNORE; + } else if (isReportError(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_ERROR; + } else if (isReportWarning(onProblems, problemBehaviorBuiltin)) { + return OnProblems.REPORT_WARNING; + } else if (isNoWrap(onProblems, noWrapBuiltin)) { return OnProblems.NO_WRAP; } throw makeTypeError(problemBehaviorBuiltin.getType(), onProblems, "onProblems"); @@ -200,6 +189,10 @@ private static boolean isIgnore(Atom onProblems, ProblemBehavior problemBehavior return onProblems.getConstructor() == problemBehaviorBuiltin.getIgnore(); } + private static boolean isNoWrap(Atom onProblems, NoWrap noWrapBuiltin) { + return onProblems.getConstructor() == noWrapBuiltin.getUniqueConstructor(); + } + private enum OnProblems { IGNORE, REPORT_ERROR, diff --git a/test/Base_Tests/src/Data/Vector_Spec.enso b/test/Base_Tests/src/Data/Vector_Spec.enso index fca7f5bbf0b2..b2fd0e678be6 100644 --- a/test/Base_Tests/src/Data/Vector_Spec.enso +++ b/test/Base_Tests/src/Data/Vector_Spec.enso @@ -388,7 +388,7 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> group_builder.specify "should allow map on_problems=No_Wrap, returning a new vector" <| vec = alter [1, 2, 3, 4] - mapped = vec.map on_problems=No_Wrap x-> x * x + mapped = vec.map on_problems=No_Wrap.Value x-> x * x vec.to_text.should_equal "[1, 2, 3, 4]" mapped.to_text.should_equal "[1, 4, 9, 16]" @@ -800,11 +800,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [] . zip [4, 5, 6] (+) . should_equal [] group_builder.specify "should zip elements with zip on_problems=No_Wrap" <| - alter [1, 2, 3] . zip on_problems=No_Wrap [] (+) . should_equal [] - alter [1, 2, 3] . zip on_problems=No_Wrap [4] (+) . should_equal [5] - alter [1, 2, 3] . zip on_problems=No_Wrap [4, 5, 6] (+) . should_equal [5, 7, 9] - alter [1, 2, 3] . zip on_problems=No_Wrap [4, 5, 6, 7] (+) . should_equal [5, 7, 9] - alter [] . zip on_problems=No_Wrap [4, 5, 6] (+) . should_equal [] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [] (+) . should_equal [] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4] (+) . should_equal [5] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4, 5, 6] (+) . should_equal [5, 7, 9] + alter [1, 2, 3] . zip on_problems=No_Wrap.Value [4, 5, 6, 7] (+) . should_equal [5, 7, 9] + alter [] . zip on_problems=No_Wrap.Value [4, 5, 6] (+) . should_equal [] group_builder.specify "should flat_map elements" <| alter [1, 2, 3] . flat_map (_ -> []) . should_equal [] @@ -814,11 +814,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [0, 0, 0] . flat_map (i -> [i]) . should_equal [0, 0, 0] group_builder.specify "should flat_map elements with flat_map on_problems=No_Wrap" <| - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> []) . should_equal [] - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> [0, 1]) . should_equal [0, 1, 0, 1, 0, 1] - alter [1, 2, 3] . flat_map on_problems=No_Wrap (_ -> [0, [1]]) . should_equal [0, [1], 0, [1], 0, [1]] - alter [0, 1, 0] . flat_map on_problems=No_Wrap (i -> if i == 1 then [1, 1] else [i]) . should_equal [0, 1, 1, 0] - alter [0, 0, 0] . flat_map on_problems=No_Wrap (i -> [i]) . should_equal [0, 0, 0] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> []) . should_equal [] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> [0, 1]) . should_equal [0, 1, 0, 1, 0, 1] + alter [1, 2, 3] . flat_map on_problems=No_Wrap.Value (_ -> [0, [1]]) . should_equal [0, [1], 0, [1], 0, [1]] + alter [0, 1, 0] . flat_map on_problems=No_Wrap.Value (i -> if i == 1 then [1, 1] else [i]) . should_equal [0, 1, 1, 0] + alter [0, 0, 0] . flat_map on_problems=No_Wrap.Value (i -> [i]) . should_equal [0, 0, 0] group_builder.specify "should allow inserting elements" <| alter [2, 3] . insert . should_equal [2, 3, Nothing] @@ -909,11 +909,11 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> alter [10, 20, 30, 40] . map map_fun . should_fail_with (Map_Error.Error 2 (My_Error.Error 30)) unwrap_errors=False group_builder.specify "an error thrown inside map on_problems=No_Wrap should be caught as a My_Error" <| - alter [10, 20, 30, 40] . map on_problems=No_Wrap map_fun . should_fail_with My_Error + alter [10, 20, 30, 40] . map on_problems=No_Wrap.Value map_fun . should_fail_with My_Error group_builder.specify "an error thrown inside map_with_index on_problems=No_Wrap should be caught as a My_Error" <| map_with_index_fun _ a = if a == 30 then Error.throw (My_Error.Error a) else a+1 - alter [10, 20, 30, 40] . map_with_index on_problems=No_Wrap map_with_index_fun . should_fail_with My_Error + alter [10, 20, 30, 40] . map_with_index on_problems=No_Wrap.Value map_with_index_fun . should_fail_with My_Error group_builder.specify "an error thrown inside map and caught (without error parameter) should be caught as a Map_Error" <| alter [10, 20, 30, 40] . map map_fun . catch . should_equal (Map_Error.Error 2 (My_Error.Error 30)) @@ -971,16 +971,16 @@ type_spec suite_builder name alter = suite_builder.group name group_builder-> Warning.get_all result wrap_errors=True . map .value . should_equal expected_warnings group_builder.specify "map on_problems=No_Wrap does not do error wrapping" <| - alter [10, 20, 30, 40] . map on_problems=No_Wrap map_fun . catch . should_equal (My_Error.Error 30) + alter [10, 20, 30, 40] . map on_problems=No_Wrap.Value map_fun . catch . should_equal (My_Error.Error 30) group_builder.specify "zip on_problems=No_Wrap does not do error wrapping" <| zip_fun a _ = if a == 30 then Error.throw (My_Error.Error a) else a+1 arr = alter [10, 20, 30, 40] - arr . zip on_problems=No_Wrap arr zip_fun . catch . should_equal (My_Error.Error 30) + arr . zip on_problems=No_Wrap.Value arr zip_fun . catch . should_equal (My_Error.Error 30) group_builder.specify "flat_map on_problems=No_Wrap does not do error wrapping" <| vec = alter [1, 2, 0, 3] - vec.flat_map on_problems=No_Wrap (n-> Error.throw (My_Error.Error n)) . catch . should_equal (My_Error.Error 1) + vec.flat_map on_problems=No_Wrap.Value (n-> Error.throw (My_Error.Error n)) . catch . should_equal (My_Error.Error 1) group_builder.specify "can transpose a vector of vectors" <| mat = alter [alter [0, 1, 2], alter [3, 4, 5], alter [6, 7, 8]]