Fix various issues around close/1 and stream realiasing #2818
+380
−164
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #2806, namely the following issues I spotted around
close/1
and'$set_stream_options'
(which can currently be accessed throughopen(stream(S), _, _, NewOptions)
); in order:current_output(S), close(S).
would partially closeuser_output
if it was previously set to a stream other thanStdout
open(stream(S), ..., [alias(new_alias)])
would leave thestream_aliases
map unsynchronized with the new option, causing issues whenclose(S)
was calledopen(stream(S), ..., [alias(user_output)]), close(S)
would overrideuser_output
and partially close it, makingwrite(user_output, hello)
fail unexpectedlyset_output(S), write(user_output, hello)
would not writehello
intoS
To fix these issues and prevent similar one from appearing, I have encapsulated accesses to
machine.indices.stream
andmachine.indices.stream_aliases
behind a few methods and made direct accesses illegal in 0cf46d3 (the biggest commit of the bunch).The only remaining pain point is that
options_mut()
can be used to break the relationship betweenstream.options().get_alias()
andmachine.indices.stream_aliases
. There's no easy way to enforce this statically other than changing the API for constructing new streams. I chose to lessen the complexity of this PR and instead leave a warning on the affected methods.I took care to address each issue in a different commit.