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

feat(decider): Use streams instead of options [LNG-277] #106

Merged
merged 1 commit into from
Nov 7, 2023

Conversation

InversionSpaces
Copy link
Contributor

In the next aqua release options will become immutable. Streams should be used instead.

Copy link

linear bot commented Nov 7, 2023

LNG-277 Prohibit mutating options

Right now it is possible to define options just like streams and mutate them:

maybe_value: ?string
...
maybe_value <<- value

It is documented in docs and used a lot in aqua code.

But option implicitly canonicalized on return, making them immutable:

func create_option() -> ?string:
  option: ?string
  option <<- "value"
  <- option

o <- create_option()
o <<- "new value" -- Error here

Also if a function accepts an option, it is prohibited to mutate it:

func use_option(option: ?string):
  option <<- "default value" -- Error here

Moreover, there is no guarantee that option will actually contain at most one element (bc under the hood it is an array or a stream), except that for immutable options compiler will reject non-zero index access:

func use_option():
  option: ?string
  a = option[10] -- OK, which is strange

func use_option(option: ?string):
  a = option[10] -- Error here

Also, streams are implicitly convertable (canonicalized) to options, so popular usage pattern is supported by them:

func create_option() -> ?string:
  option: *string
  option <<- "value"
  <- option

Everything described above makes options inconsistent data type, complicating compiler and aqua code. This is why it seems better to:

  • prohibit creating options with o: ?type syntax
  • prohibit mutating options everywhere

Copy link
Collaborator

@kmd-fl kmd-fl left a comment

Choose a reason for hiding this comment

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

Now the code looks more confusing :c

@InversionSpaces InversionSpaces merged commit 9e92d8f into main Nov 7, 2023
6 checks passed
@InversionSpaces InversionSpaces deleted the feat/stream-options-LNG-277 branch November 7, 2023 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants