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

Reducing helper methods in Standard.Base.Meta #12031

Merged
merged 37 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
d2ce49c
Moving @Builtin_Method definitions outside of Meta
JaroslavTulach Jan 9, 2025
a18693e
Merge remote-tracking branch 'origin/develop' into wip/jtulach/MetaHe…
JaroslavTulach Jan 13, 2025
531ecdf
Moving Meta_Helpers into Internal namespace
JaroslavTulach Jan 13, 2025
4ae769b
Reverting changes in tests. Meta.is_a has to work.
JaroslavTulach Jan 13, 2025
9770c1a
Adjustiments to call Meta.is_a even it is not builtin
JaroslavTulach Jan 13, 2025
17fdff4
Dispatch on non-associated type continues to prefer virtual method on…
JaroslavTulach Jan 13, 2025
0c074ac
Making constructors of Meta types private reveals issues in checking …
JaroslavTulach Jan 13, 2025
4ef7d8b
Type is always public even it has no public constructors
JaroslavTulach Jan 13, 2025
fd5d2af
Meta.Constructor can be converted to qualified accessor Function
JaroslavTulach Jan 13, 2025
ab9287f
Merging with develop
JaroslavTulach Jan 13, 2025
b4f4483
Getting the Base_Tests to compile
JaroslavTulach Jan 13, 2025
2eef96b
All Base_Tests are passing again
JaroslavTulach Jan 13, 2025
530f3af
Note in changelog
JaroslavTulach Jan 14, 2025
b4116c8
Merge remote-tracking branch 'origin/develop' into wip/jtulach/MetaHe…
JaroslavTulach Jan 14, 2025
30e5005
Merging with latest develop that includes #12052
JaroslavTulach Jan 15, 2025
d426ab3
Type.Atom... yields Meta.AtomConstructor
JaroslavTulach Jan 15, 2025
7aacc66
Enforcing runtime type checks with inline signatures
JaroslavTulach Jan 15, 2025
3516a2d
More inline signatures
JaroslavTulach Jan 17, 2025
47f8e34
Fixing inline signatures to let test/Base_Tests pass
JaroslavTulach Jan 17, 2025
11eafee
Moving (most of) Instrumentor from public API
JaroslavTulach Jan 20, 2025
5331e49
Removing Meta.get_source_location and replacing it with Standard.Base…
JaroslavTulach Jan 20, 2025
5ff29d1
Fixing Meta.meta Panic . name
JaroslavTulach Jan 20, 2025
8c6ddd6
Single builtin to get Meta's kind of a value
JaroslavTulach Jan 20, 2025
110d9d4
No need for UnresolvedXyz in the Types list
JaroslavTulach Jan 20, 2025
6eab870
Merge remote-tracking branch 'origin/develop' into wip/jtulach/MetaHe…
JaroslavTulach Jan 21, 2025
5716344
Meta signature test
JaroslavTulach Jan 21, 2025
dc5d820
Robust when --in-project distribution/lib/Standard/Base/0.0.0-dev/
JaroslavTulach Jan 21, 2025
2f78b17
Moving value_for_uuid into Runtime
JaroslavTulach Jan 21, 2025
33bdcbd
Merge remote-tracking branch 'origin/develop' into wip/jtulach/MetaHe…
JaroslavTulach Jan 21, 2025
67fcec2
Tests accessing Instrumentor need to run with --disable-private-check
JaroslavTulach Jan 22, 2025
2f8d126
Moving the signature snapshot into its own file
JaroslavTulach Jan 22, 2025
e776053
Adjusting micro's Meta to match current builtins
JaroslavTulach Jan 22, 2025
4daed89
Better resolution of a conflict in changelog
JaroslavTulach Jan 22, 2025
a394c4e
Any value can be converted .to Meta.Type
JaroslavTulach Jan 22, 2025
57d19a7
Generate conversion methods into signature files
JaroslavTulach Jan 22, 2025
ba13b0d
Use value.to Meta.Type . qualified_name to obtain qualified type name…
JaroslavTulach Jan 22, 2025
90d2e2a
Fixing indentation of documentation
JaroslavTulach Jan 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@

- [Allow using `/` to access files inside a directory reached through a data
link.][11926]
- [Reducing helper methods in `Standard.Base.Meta`.][12031]
- [Added Table.Offset][12071]

[11926]: https://github.com/enso-org/enso/pull/11926
[12031]: https://github.com/enso-org/enso/pull/12031
[12071]: https://github.com/enso-org/enso/pull/12071

#### Enso Language & Runtime
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Data.enso
Original file line number Diff line number Diff line change
Expand Up @@ -460,4 +460,4 @@ download (uri:(URI | Text)=(Missing_Argument.throw "uri")) file:Writable_File (m
type Raw_Response
## PRIVATE
get_dropdown_options : Vector Option
get_dropdown_options = [Option "Raw HTTP Response" (Meta.get_qualified_type_name Raw_Response)]
get_dropdown_options = [Option "Raw HTTP Response" (Raw_Response.to Meta.Type . qualified_name)]
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ key_widget dict:Dictionary -> Widget =

## PRIVATE
key_value_widget -> Widget =
fqn = Meta.get_qualified_type_name Pair . take (..Before_Last '.')
fqn = Pair.to Meta.Type . qualified_name . take (..Before_Last '.')
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
default = 'pair "key" Nothing'
pair = Option "Pair" fqn+".pair" [["first", make_all_selector], ["second", make_all_selector]]
item_editor = Single_Choice display=..Always values=[pair]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ make_enso object =
## PRIVATE
key_value_widget : Widget
key_value_widget =
fqn = Meta.get_qualified_type_name Pair . take (..Before_Last '.')
fqn = Pair.to Meta.Type . qualified_name . take (..Before_Last '.')
default = 'pair "key" Nothing'
pair = Option "Pair" fqn+".pair" [["first", Text_Input], ["second", make_all_selector]]
item_editor = Single_Choice display=..Always values=[pair]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Any.to_js_object self =
0.up_to field_names.length . map i-> builder.append [field_names.at i, fs.at i . to_js_object]
JS_Object.from_pairs pairs
_ : Meta.Constructor ->
type_name = Meta.get_qualified_type_name self . split '.' . at -2
type_name = self.to Meta.Type . qualified_name . split '.' . at -2
JS_Object.from_pairs [["type", type_name], ["constructor", m.name]]
_ -> Error.throw ("Cannot convert " + self.to_text + " to JSON")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,6 @@ type Locale
widget_options : Vector Option
widget_options = Locale.predefined_locale_fields.map field_name->
display_string = field_name.replace '_' ' ' . to_case (if field_name.length == 2 then Case.Upper else Case.Title)
fqn = Meta.get_qualified_type_name Locale
fqn = Locale.to Meta.Type . qualified_name
code_string = fqn + "." + field_name
Option display_string code_string
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Encoding
## PRIVATE
Gets the default drop down option for Encoding.
default_widget display:Display=..When_Modified -> Widget =
fqn = Meta.get_qualified_type_name Encoding
fqn = Encoding.to Meta.Type . qualified_name
values = [Option "UTF-8" fqn+".utf_8", Option "ASCII" fqn+".ascii", Option "UTF-16LE" fqn+".utf_16_le", Option "UTF-16BE" fqn+".utf_16_be", Option "UTF-32LE" fqn+".utf_32_le", Option "UTF-32BE" fqn+".utf_32_be", Option "Windows-1250" fqn+".windows_1250", Option "Windows-1251" fqn+".windows_1251", Option "Windows-1252" fqn+".windows_1252", Option "Windows-1253" fqn+".windows_1253", Option "Windows-1254" fqn+".windows_1254", Option "Windows-1255" fqn+".windows_1255", Option "Windows-1256" fqn+".windows_1256", Option "Windows-1257" fqn+".windows_1257", Option "Windows-1258" fqn+".windows_1258"]
Single_Choice values=values display=display

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ ensure_duration object ~action =
_ : Period -> Error.throw (Time_Error.Error "Cannot use Period as a parameter")
x ->
Error.throw Illegal_Argument.Error <|
"Expected Duration type, got: " + (Meta.get_qualified_type_name x)
"Expected Duration type, got: " + (x.to Meta.Type . qualified_name)

## Represents the amount of time between two points in time.
@Builtin_Type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ensure_period object ~action error_msg="Cannot use Duration as a parameter" =
Error.throw (Time_Error.Error error_msg)
x ->
Error.throw Illegal_Argument.Error <|
"Expected Period type, got: " + (Meta.get_qualified_type_name x)
"Expected Period type, got: " + (x.to Meta.Type . qualified_name)

## A date-based amount of time in the ISO-8601 calendar system, such as
'2 years, 3 months and 4 days'.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type XML_Format

## PRIVATE
get_dropdown_options : Vector Option
get_dropdown_options = [Option "XML" (Meta.get_qualified_type_name XML_Format)]
get_dropdown_options = [Option "XML" (XML_Format.to Meta.Type . qualified_name)]

## PRIVATE
get_name_patterns -> Vector File_Name_Pattern =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
private

import project.Any.Any
import project.Data.Text.Text
import project.Function.Function
import project.Meta
import project.Internal.Meta_Helpers
import project.Data.Vector.Vector
import project.Nothing.Nothing
import project.Runtime.Managed_Resource.Managed_Resource

## PRIVATE
ADVANCED

Builder to create instrumentation for a function
type Instrumentor
Copy link
Member Author

@JaroslavTulach JaroslavTulach Jan 20, 2025

Choose a reason for hiding this comment

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

Instrumentor is a nice concept, but probably not something we want to expose from a public API. It is still fine to have it and test it, but making private and moving the Instrumentor_Spec into test/Base_Internal_Tests.

Y.js+Insight (as being worked on by @4e6) should be the future of instrumentation and it doesn't need the Meta_Helpers.instrumentor_builtin as it is using GraalVM Insight directly.

private Value impl

## PRIVATE
ADVANCED

Registers callback to be executed at the begining of node/expression
execution. The callback `fn` gets UUID of the node/expression that is
being executed and can return `Nothing` to continue regular execution
or anything else to skip the execution and just return given value.

Arguments:
- fn: The callback function accepting UUID.
on_enter self (fn : Text -> Any | Nothing) =
new = Meta_Helpers.instrumentor_builtin "onEnter" [ self.impl, fn ]
Instrumentor.Value new

## PRIVATE
ADVANCED

Registers callback to be executed when a node/expression evaluation
is over. The callback `fn` gets UUID and the computed value (or value
of `expression` if specified). Usually
the value is _cached_ and returned from `on_enter` callback next time
the same expression is evaluated.

> Example
Specify `expression` to _"inline evaluate"_ it.
see_a_b uuid:Text ~result =
if uuid == "expected-uuid" then
IO.println "evalutated to "+result.to_text

Meta.meta .fn . instrument . on_return fn=see_a_b expression="a+b" . activate

Arguments:
- fn: The callback function accepting UUID and computed value
- expression: Expression to evaluate on_return - by default Nothing -
e.g. to provide the return value of the function
on_return self (fn : Text -> Any -> Nothing) expression:(Text | Nothing)=Nothing =
new = Meta_Helpers.instrumentor_builtin "onReturn" [ self.impl, fn, expression ]
Instrumentor.Value new

## PRIVATE
ADVANCED

Registers callback to be executed when a node/expression representing function is about to be called.
The callback `fn` shall accept three arguments. The UUID to identify the expression, the function to be
invoked and the arguments to pass to the function. The callback can return `Nothing`
(in such case the function gets executed with provided arguments) or some other value,
which is then returned instead of calling the function.

Arguments:
- fn: The callback function accepting UUID and function value
on_call self (fn : Text -> Function -> Vector Any -> Any | Nothing) =
new = Meta_Helpers.instrumentor_builtin "onCall" [ self.impl, fn ]
Instrumentor.Value new

## PRIVATE
ADVANCED

Activates configured instrumentor. Returns managed resource to
deactivate the instrumentor later.

Arguments:
- value: The value of the atom in the meta representation.
activate self =
finalize_instrumentor impl = Meta_Helpers.instrumentor_builtin "deactivate" [ impl ]
create action = (Meta_Helpers.instrumentor_builtin action [ self.impl, finalize_instrumentor ]) : Managed_Resource
create "activate"


## ADVANCED
GROUP Metadata
ICON metadata

Starts building an instrumentation for a given node
Meta.Unresolved_Symbol.instrument self -> Instrumentor = Instrumentor.Value (Meta_Helpers.instrumentor_builtin "newBuilder" [ self.impl ])
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
private

get_atom_constructor_builtin atom = @Builtin_Method "Meta.get_atom_constructor"
get_atom_fields_builtin atom = @Builtin_Method "Meta.get_atom_fields"
get_type_constructors_builtin typ factory = @Builtin_Method "Meta.get_type_constructors"
get_type_methods_builtin typ = @Builtin_Method "Meta.get_type_methods"
get_polyglot_language_builtin value = @Builtin_Method "Meta.get_polyglot_language"
create_unresolved_symbol_builtin name symbol = @Builtin_Method "Meta.create_unresolved_symbol"
get_unresolved_symbol_name_builtin symbol = @Builtin_Method "Meta.get_unresolved_symbol_name"
get_constructor_fields_builtin atom_constructor = @Builtin_Method "Meta.get_constructor_fields"
get_constructor_name_builtin atom_constructor = @Builtin_Method "Meta.get_constructor_name"
new_atom_builtin constructor fields = @Builtin_Method "Meta.new_atom"
atom_with_hole_builtin factory = @Builtin_Method "Meta.atom_with_hole_builtin"
is_same_object_builtin value_1 value_2 = @Builtin_Method "Meta.is_same_object"
is_a_builtin value typ = @Builtin_Method "Meta.is_a"
type_of_builtin value = @Builtin_Method "Meta.type_of"
get_annotation_builtin target method parameter_name = @Builtin_Method "Meta.get_annotation"
find_atom_constructor_builtin value = @Builtin_Method "Meta.find_atom_constructor"
get_kind_builtin value = @Builtin_Method "Meta.get_kind_builtin"
simple_type_name_builtin value = @Builtin_Method "Meta.simple_name_builtin"
get_qualified_type_name_builtin value = @Builtin_Method "Meta.get_qualified_type_name"
get_short_type_name_builtin typ = @Builtin_Method "Meta.get_short_type_name"
get_constructor_declaring_type_builtin constructor = @Builtin_Method "Meta.get_constructor_declaring_type"
instrumentor_builtin op args = @Builtin_Method "Meta.instrumentor_builtin"
find_type_by_qualified_name_builtin fqn = @Builtin_Method "Meta.find_type_by_qualified_name"
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ polyglot java import org.slf4j.LoggerFactory
`from Standard.Base.Logging import all`.
Any.log_message : Text -> Log_Level -> Any
Any.log_message self ~message:Text level:Log_Level=Log_Level.Info =
type_name = Meta.get_qualified_type_name self
type_name = self.to Meta.Type . qualified_name
logger = LoggerFactory.getLogger type_name
case level of
Log_Level.Finest -> logger.trace message
Expand Down
Loading
Loading