enso/distribution/lib/Standard/Base/0.0.0-dev/src/Runtime.enso
Hubert Plociniczak 3379ce51f2
Report failed name resolutions in type signatures (#4030)
Compiler performed name resolution of literals in type signatures but would silently fail to report any problems.
This meant that wrong names or forgotten imports would sneak in to stdlib.

This change introduces 2 main changes:
1) failed name resolutions are appended in `TypeNames` pass
2) `GatherDiagnostics` pass also collects and reports failures from type
signatures IR

Updated stdlib so that it passes given the correct gatekeepers in place.
2023-01-09 10:35:36 +00:00

128 lines
3.8 KiB
Plaintext

import project.Any.Any
import project.Data.Array.Array
import project.Data.Text.Text
import project.Data.Vector.Vector
import project.Nothing.Nothing
import project.Polyglot
import project.Runtime.Source_Location.Source_Location
from project.Data.Index_Sub_Range.Index_Sub_Range import First, Last
## Utilities for interacting with the runtime.
## PRIVATE
Returns a raw representation of the current execution stack trace.
You probably want `Runtime.get_stack_trace` instead.
primitive_get_stack_trace : Array
primitive_get_stack_trace = @Builtin_Method "Runtime.primitive_get_stack_trace"
## ADVANCED
UNSTABLE
Returns the execution stack trace of its call site. The ordering of the
resulting vector is such that the top stack frame is the first element.
get_stack_trace : Vector Stack_Trace_Element
get_stack_trace =
prim_stack = primitive_get_stack_trace
stack_with_prims = Vector.from_polyglot_array prim_stack
# (First 2) drops the `Runtime.primitive_get_stack_trace` frame and this one
# (Last 1) drops the `org.graalvm.polyglot.Value<Function>.execute` frame
stack = stack_with_prims.drop (First 2) . drop (Last 1)
stack.map wrap_primitive_stack_trace_element
## ADVANCED
Suggests that the runtime perform garbage collection.
It is not _guaranteed_ to perform garbage collection, but in practice
will _usually_ begin a garbage collection cycle.
> Example
Ask for the runtime to collect garbage.
Runtime.gc
gc : Nothing
gc = @Builtin_Method "Runtime.gc"
## ADVANCED
Executes the provided action without allowing it to inline.
Arguments:
- action: The computation to be executed.
This is particularly useful when writing benchmarks and
performance-critical code where you need to prevent inlining from
occurring.
> Example
Print something to the console without it being inlined.
Runtime.no_inline <| IO.println "Hi!"
no_inline : Any -> Any
no_inline ~action = @Builtin_Method "Runtime.no_inline"
## ADVANCED
UNSTABLE
Applies the following function to the given argument, without allowing
them to inline.
Arguments:
- function: The one-argument function to call.
- arg: The single argument for the function.
This is particularly useful to avoid constant folding in benchmarks.
> Example
Print something to the console without it being inlined.
Runtime.no_inline_with_arg IO.println "Hi!"
no_inline_with_arg : Any -> Any
no_inline_with_arg function arg = @Builtin_Method "Runtime.no_inline_with_arg"
## PRIVATE
Converts a primitive stack trace element into the regular one.
wrap_primitive_stack_trace_element el =
loc = if Polyglot.has_source_location el then Source_Location.Value (Polyglot.get_source_location el) else Nothing
name = Polyglot.get_executable_name el
Stack_Trace_Element.Value name loc
## ADVANCED
UNSTABLE
Represents a single stack frame in an Enso stack trace.
type Stack_Trace_Element
## PRIVATE
Value name source_location
## ADVANCED
Types indicating allowed IO operations
type IO_Permissions
Input
Output
## ADVANCED
UNSTABLE
Allows an action in the `Input` context to be performed in the given `env`,
regardless of the Env configuration.
This can be used to enable certain nodes to run their actions in the
interactive mode, even if the configuration forbids it.
allow_input_in : Text -> Any -> Any
allow_input_in env ~action = @Builtin_Method "Runtime.allow_input_in"
## ADVANCED
UNSTABLE
Allows an action in the `Output` context to be performed in the given `env`,
regardless of the Env configuration.
This can be used to enable certain nodes to run their actions in the
interactive mode, even if the configuration forbids it.
allow_output_in : Text -> Any -> Any
allow_output_in env ~action = @Builtin_Method "Runtime.allow_output_in"