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

Decorate values with arbitrary warnings #3248

Merged
merged 23 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
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
4 changes: 4 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import project.Meta
import project.Meta.Enso_Project
import project.Polyglot.Java
import project.Runtime.Extensions
import project.System.Environment
import project.System.File
import project.Data.Text.Regex.Mode as Regex_Mode
import project.Warning

from Standard.Builtins import Nothing, Number, Integer, Any, True, False, Cons, Boolean, Arithmetic_Error

Expand All @@ -37,8 +39,10 @@ export project.Data.Ordering.Sort_Order
export project.Data.Vector
export project.Math
export project.Meta
export project.System.Environment
export project.System.File
export project.Data.Text.Regex.Mode as Regex_Mode
export project.Warning

from project.Data.Any.Extensions export all
from project.Data.Array.Extensions export all
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type Source_Location
end = this.end_column.to_text
row + ":" + start + "-" + end
False ->
start_line + '-' + end_line
start_line.to_text + '-' + end_line.to_text
cwd = File.current_directory
file = this.file.absolute
formatted_file = case file.is_child_of cwd of
Expand Down
69 changes: 69 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Warning.enso
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from Standard.Base import all

## A representation of a dataflow warning attached to a value.
type Warning
## PRIVATE

The constructor to wrap primitive warnings.
type Warning prim_warning

## UNSTABLE

Returns the warning value – usually its explanation or other contents.
value : Any
value = Prim_Warning.get_value this.prim_warning

## UNSTABLE
ADVANCED

A stack trace for the original warning creation.
origin : Vector.Vector Stack_Trace_Element
origin = Prim_Warning.get_origin this.prim_warning

## UNSTABLE
ADVANCED

A list of locations where the warning was reassigned in the order of
latest-first.

Warnings are reassigned whenever they interract with specific language
elements:
- When pattern matching, the warnings of the scrutinee will be reassigned
to the `case` expression result.
- When calling a method, warnings assigned to `this` will be reassigned to
the method return value.
- When calling a polyglot function or method, warnings assigned to any
arguments will be accumulated in the return value.
- The standard library methods reassign warnings such that their dataflow
nature is preserved.
reassignments : Vector.Vector Stack_Trace_Element
reassignments =
Vector.Vector (Prim_Warning.get_reassignments this.prim_warning) . map r->
loc = case Polyglot.has_source_location r of
False -> Nothing
True -> Source_Location (Polyglot.get_source_location r)
Stack_Trace_Element (Polyglot.get_executable_name r) loc

## UNSTABLE

Attaches a new warning to the value.
attach : Any -> Any -> Any
attach warning value =
origin = Runtime.get_stack_trace
Prim_Warning.attach value warning (origin.drop_start 1)

## UNSTABLE

Gets all the warnings attached to the given value. Warnings are returned in the
reverse-chronological order with respect to their attachment time.
get_all : Any -> Vector.Vector Warning
get_all value =
Vector.Vector (Prim_Warning.get_all value) . map Warning

## UNSTABLE
ADVANCED

Sets a new list of warnings for the given value. Any warnings already present
in `value` will be lost.
set warnings value =
Prim_Warning.set value (warnings.map .prim_warning).to_array
51 changes: 34 additions & 17 deletions distribution/lib/Standard/Test/0.0.0-dev/src/Main.enso
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,14 @@ import Standard.Builtins
2*3 . should_equal 6
Suite.run_main : Any -> Nothing
Suite.run_main ~specs =
r = this.run specs
r = this.run specs here.config_from_env
code = if r.is_fail then 1 else 0
System.exit code

config_from_env =
only_group_regexp = Environment.get "TEST_ONLY_GROUP"
Suite_Config only_group_regexp

## Creates a new test group, desribing properties of the object
described by `this`.

Expand All @@ -42,9 +46,9 @@ Suite.run_main ~specs =
2+3 . should_equal 5
Test.specify "should define multiplication" <|
2*3 . should_equal 6
Suite.run : Any -> Any
Suite.run ~specs =
r = State.run Suite (Suite Nil) <|
Suite.run : Any -> Suite_Config -> Any
Suite.run ~specs config =
r = State.run Suite (Suite config Nil) <|
specs
State.get Suite
r
Expand All @@ -67,18 +71,20 @@ Suite.run ~specs =
Test.group "Number" <| Nothing
group : Text -> Any -> (Text | Nothing) -> Nothing
group name ~behaviors pending=Nothing =
case pending of
Nothing ->
r = State.run Spec (Spec name Nil) <|
behaviors
State.get Spec
r.print_report
suite = State.get Suite
new_suite = Suite (Cons r suite.specs)
State.put Suite new_suite
reason ->
IO.print_err ("[PENDING] " + name)
IO.print_err (" Reason: " + reason)
config = State.get Suite . config
if config.should_run_group name then
case pending of
Nothing ->
r = State.run Spec (Spec name Nil) <|
behaviors
State.get Spec
r.print_report
suite = State.get Suite
new_suite = Suite suite.config (Cons r suite.specs)
State.put Suite new_suite
reason ->
IO.print_err ("[PENDING] " + name)
IO.print_err (" Reason: " + reason)

## Specifies a single behavior, described by `this`.

Expand Down Expand Up @@ -435,13 +441,24 @@ Spec.print_report =
IO.print_err (" - [PENDING] " + behavior.name)
IO.print_err (" Reason: " + reason)

## PRVATE
type Suite_Config
type Suite_Config only_group_regexp

should_run_group name =
regexp = this.only_group_regexp
case regexp of
Text -> name.matches regexp . catch (_->True)
_ -> True


## PRIVATE

The top-level entry point for a test suite.

Arguments:
- specs: The specs contained within the test suite.
type Suite specs
type Suite config specs

## PRIVATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.oracle.truffle.api.debug.DebuggerTags;
import com.oracle.truffle.api.instrumentation.ProvidedTags;
import com.oracle.truffle.api.instrumentation.StandardTags;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.nodes.RootNode;
import org.enso.distribution.DistributionManager;
import org.enso.distribution.Environment;
Expand Down Expand Up @@ -58,6 +59,12 @@
})
public final class Language extends TruffleLanguage<Context> {
private IdExecutionInstrument idExecutionInstrument;
private static final LanguageReference<Language> REFERENCE =
LanguageReference.create(Language.class);

public static Language get(Node node) {
return REFERENCE.get(node);
}

/**
* Creates a new Enso context.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ public Stateful invokeDynamicSymbol(
schema,
defaultsExecutionMode,
argumentsExecutionMode,
isTail);
isTail,
thisArgumentPosition);
} else {
throw new RuntimeException("Currying without `this` argument is not yet supported.");
}
Expand Down
Loading