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

Replace IOContexts with execution env and contexts #6171

Merged
merged 11 commits into from
Apr 6, 2023

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Apr 2, 2023

Pull Request Description

As per design, IOContexts controlled via type signatures are going away. They are replaced by explicit Context.if_enabled runtime checks that will be added to particular method implementations.

production/development IOPermissions are replaced with live and design execution enviornment. Currently, the live env has a hardcoded list of allowed contexts i.e. Input and Output.

Important Notes

As per design PR-55. Closes #6129. Closes #6131.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • The documentation has been updated, if necessary.
  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • [ x All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

@hubertp hubertp force-pushed the wip/hubert/6129-runtime-context branch from 7bc7cce to 009c3f2 Compare April 2, 2023 21:25
}

@CompilerDirectives.TruffleBoundary
public ExecutionEnvironment withContextEnabled(Atom context) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we strive for making this function working on fast path?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I would have to refactor pretty much any call to map i.e. almost every line in that method, to make native image build happy. I would say that kind of defeats the purpose?

Copy link
Member

@JaroslavTulach JaroslavTulach Apr 4, 2023

Choose a reason for hiding this comment

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

What's your purpose? Is the purpose to run Enso fast? Well, in such case that's not happening as soon as somebody uses withContextEnabled - that's always going to be slow.

refactor pretty much any call to map

Possibly using HashMap for storage of two values (Input, Output) wasn't good idea to begin with?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fine, replaced by two arrays that emulate the map. The reason why I don't hardcode those in fields is that I'm trying to be generic enough in preparation for potential future Context values.

Copy link
Collaborator Author

@hubertp hubertp Apr 4, 2023

Choose a reason for hiding this comment

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

It is also a big overkill given that currently we only have Input and Output. So if you feel strongly about it, I could just go back to storing those in fields.

Copy link
Member

Choose a reason for hiding this comment

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

I am assuming that withContextEnabled/withContextDisabled operations are going to be spread all around the codebase possibly included inside of .map lambdas processing large data structures and we want to make them fast in order to avoid slowing down the rest of the interpreter. Is such assumption a false expectation? As I am seeing a disagreement and I don't understand what are its roots...

replaced by two arrays that emulate the map

The code is now less readable, but at least it doesn't need to be behind @TruffleBoundary. However I cannot judge how well it partially evaluates without looking at IGV graphs. Btw. what do we want to see in IGV when we look at withContextEnabled?

  • when already enabled - a single field/bit check to verify the context is already enabled
  • when disabled - more work - field write and switching the State to a new configuration (possibly also a costly allocation of the new configuration)

trying to be generic enough in preparation for potential future Context values.

Generic code can't be as fast as code that handles/speculates on fixed set of values.

... if you feel strongly ...

Maybe we could change one of our benchmarks to use withContextEnabled few million of times and compare it to a benchmark without context manipulation? Then we all would have something measurable to know how to feel about this matter.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will file a separate ticket to investigate if this becomes a perf issue.

@hubertp
Copy link
Collaborator Author

hubertp commented Apr 3, 2023

@jdunkerley added a CLI option --execution-environment, as requested. Part of #6131.

@hubertp hubertp force-pushed the wip/hubert/6129-runtime-context branch from e550579 to ad3b1bb Compare April 3, 2023 13:28
@hubertp hubertp added the CI: Clean build required CI runners will be cleaned before and after this PR is built. label Apr 3, 2023
engine/runner/src/main/scala/org/enso/runner/Main.scala Outdated Show resolved Hide resolved
.getBuiltins()
.error()
.makeUnimplemnted("execution environment mismatch");
throw new PanicException(error, this);
Copy link
Member

Choose a reason for hiding this comment

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

I really doubt a Panic is what we want! I don't even understand what's the purpose of specifying environment name in the is_enabled check. Environments are supposed to be a set of contexts. All the user wants is to take a context and check if it is currently enabled. E.g. Context.Input.is_enabled.

Copy link
Collaborator Author

@hubertp hubertp Apr 4, 2023

Choose a reason for hiding this comment

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

This isn't really specified well in the design doc. Nor is the usage of the environment name so if you feel strongly about it, probably worth bringing up with that doc's authors.

Copy link
Member

Choose a reason for hiding this comment

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

At least for the moment - there is no intention to specify anything other than the current context when calling this function.

If we find a need to use this we can revisit.

Copy link
Member

Choose a reason for hiding this comment

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

At least for the moment - there is no intention to specify anything other than the current context when calling this function.

Obviously! Specifying anything else makes no sense. At least I cannot envision the use-case.

I'd say: One doesn't care about the environment. One only wants to find out if a Context is_enabled "right now". Nothing else makes sense.


@BuiltinMethod(
type = "Runtime",
name = "current_execution_environment",
Copy link
Member

Choose a reason for hiding this comment

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

This method shall not exists from my API designer perspective as it bypasses the Context. I assume @jdunkerley wants the method to do production/non-production property configuration, but we should offer other means for that - not this method.

Copy link
Collaborator Author

@hubertp hubertp Apr 4, 2023

Choose a reason for hiding this comment

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

We agreed that Execution_Environment is really an alias for Text and I believe I'm following the design doc so I don't really understand the comment.

Copy link
Member

Choose a reason for hiding this comment

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

I won't be using this for configuration - from the libs perspective I don't expect this to be used.

Copy link
Member

Choose a reason for hiding this comment

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

There is a story about magical strings. I have a feeling the returned textual value has the potential to provide "magical" insights into something that should rather be hidden.

...I don't expect this to be used.

Personally I'd rather not expose such API, especially if there is no use-case for it.

}

@CompilerDirectives.TruffleBoundary
public ExecutionEnvironment withContextEnabled(Atom context) {
Copy link
Member

@JaroslavTulach JaroslavTulach Apr 4, 2023

Choose a reason for hiding this comment

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

What's your purpose? Is the purpose to run Enso fast? Well, in such case that's not happening as soon as somebody uses withContextEnabled - that's always going to be slow.

refactor pretty much any call to map

Possibly using HashMap for storage of two values (Input, Output) wasn't good idea to begin with?

@hubertp hubertp force-pushed the wip/hubert/6129-runtime-context branch from a667c50 to 065462d Compare April 4, 2023 10:31
@hubertp hubertp requested a review from radeusgd April 4, 2023 10:39
Copy link
Member

@jdunkerley jdunkerley left a comment

Choose a reason for hiding this comment

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

Couple of nit pics

engine/runner/src/main/scala/org/enso/runner/Main.scala Outdated Show resolved Hide resolved

@BuiltinMethod(
type = "Runtime",
name = "current_execution_environment",
Copy link
Member

Choose a reason for hiding this comment

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

I won't be using this for configuration - from the libs perspective I don't expect this to be used.

.getBuiltins()
.error()
.makeUnimplemnted("execution environment mismatch");
throw new PanicException(error, this);
Copy link
Member

Choose a reason for hiding this comment

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

At least for the moment - there is no intention to specify anything other than the current context when calling this function.

If we find a need to use this we can revisit.

@hubertp hubertp force-pushed the wip/hubert/6129-runtime-context branch from 065462d to a4b267b Compare April 5, 2023 09:22
@hubertp hubertp added the CI: Ready to merge This PR is eligible for automatic merge label Apr 5, 2023
hubertp added 9 commits April 6, 2023 12:29
As per design, IOContexts controlled via type signatures are going away.
They are replaced by explicit `Context.if_enabled` runtime checks that
will be added to particular method implementations.

`production`/`development` `IOPermissions` are replaced with `live` and
`design` execution enviornment. Currently, the `live` env has a
hardcoded list of allowed contexts i.e. `Input` and `Output`.
Added a fix for #6131 to allow for some testing.
Changed the default execution env to `live` since that is probably what
we want for CLI anyway.
Got rid of `TruffleBoundary` annotations by using straight arrays that
emulate map.
@hubertp hubertp force-pushed the wip/hubert/6129-runtime-context branch from 7fb8813 to 9b5c12b Compare April 6, 2023 10:29
@mergify mergify bot merged commit 3cce3b3 into develop Apr 6, 2023
@mergify mergify bot deleted the wip/hubert/6129-runtime-context branch April 6, 2023 15:47
MichaelMauderer pushed a commit that referenced this pull request Apr 25, 2023
As per design, IOContexts controlled via type signatures are going away. They are replaced by explicit `Context.if_enabled` runtime checks that will be added to particular method implementations.

`production`/`development` `IOPermissions` are replaced with `live` and `design` execution enviornment. Currently, the `live` env has a hardcoded list of allowed contexts i.e. `Input` and `Output`.

# Important Notes
As per design PR-55. Closes #6129. Closes #6131.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: Clean build required CI runners will be cleaned before and after this PR is built. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

CLI option to control execution environment Introduce Runtime.Context and methods to manipulate it
5 participants