-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/eval: Simplify how the lifecycle of ports are tracked.
The lifecycle of a port is often tied to the execution of a form - for example, in "echo > out", port 1 is redirected to a file that should be closed when the form finishes execution. Previously, this is tracked with the following scheme: - The port field has two fields - closeFile and closeChan - indicating whether the file and chan components should be closed when the form finishes execution. - However, a port could be used in multiple forms: for example, in { echo foo; echo bar } > out The same port 1 is used for both echo commands, but the file in it should only be closed when the overall form finishes execution. - To handle this correct, the idea of "forking" a port is introduced - the forked ports always have their closeFile and closeChan set to false. Similarly, when a Frame gets "forked", all its ports are forked as well. This commit switches to a different approach based on the observation that there are only two places that care about closeFile and closeChan: pipelineOp.exec and redirOp.exec, and they are very close in the call frame (with only formOp.exec between them). So instead of embedding the ownership information to the port struct, track it in a separate formOwnedPort struct, and thread a *[]formOwnedPort as an additional argument of pipelineOp.exec, formOp.exec and redirOp.exec. This allows us to get rid of concept of "forking" a port. The Frame.Fork method still exists because it needs to make a shallow copy of the ports slice, but the implementation is now simpler.
- Loading branch information
Showing
6 changed files
with
65 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters