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 bindings by declare blocks #724

Open
treiher opened this issue Aug 9, 2021 · 1 comment
Open

Replace bindings by declare blocks #724

treiher opened this issue Aug 9, 2021 · 1 comment
Labels
architectural decision Discussion of design decision specification Related to specification package (e.g., specification parsing)

Comments

@treiher
Copy link
Collaborator

treiher commented Aug 9, 2021

Context and Problem Statement

In #701 the introduction of declare blocks is proposed. Declare blocks provide a similar functionality as the already existing bindings. It could be beneficial to replace bindings by declare blocks.

Example

Without binding or declare block
      state X is
         [...]
         Hash : Opaque;
         Query : P::Query
      begin
         [...]
         Hash := Hash = Get_Hash (Transcript_Hash).Data;
         Query = P::Query'(Tag => P::Hash, Length => Hash'Size, Data => Hash);
         Channel'Write (P::Message'(Tag => P::Request, Length => Query'Size, Payload => Query));
With binding
      state X is
         [...]
      begin
         [...]
         Channel'Write (P::Message'(Tag => P::Request, Length => Query'Size, Payload => Query)
                           where Query = P::Query'(Tag => P::Hash, Length => Hash'Size, Data => Hash)
                              where Hash = Get_Hash (Transcript_Hash).Data);
With declare block
      state X is
         [...]
      begin
         [...]
         declare
            Hash : Opaque = Get_Hash (Transcript_Hash).Data;
            Query : P::Query := P::Query'(Tag => P::Hash, Length => Hash'Size, Data => Hash);
         begin
            Channel'Write (P::Message'(Tag => P::Request, Length => Query'Size, Payload => Query));
         end;

Considered Options

O1 Replace bindings by declare blocks

+ Keep DSL smaller by preventing two ways to do essentially the same thing
+ Declare blocks are probably easier readable than bindings as type of variable is stated explicitly
+ Less implementation and maintenance effort (validation and code generation easier to implement for declare blocks than bindings as no type inference is needed)

O2 Keep bindings as well as declare blocks

+ Bindings are easier to write (as bindings are less verbose than declare blocks)

Decision Outcome

O1

@treiher treiher added specification Related to specification package (e.g., specification parsing) architectural decision Discussion of design decision labels Aug 9, 2021
@treiher treiher added this to To do in RecordFlux Future via automation Aug 9, 2021
@sttaft
Copy link

sttaft commented Aug 11, 2021

Bindings are perhaps easier to write, but they could be harder to read. In the example above, the definition of "Hash" via the "where" clause was not readily visible to me on a first reading. These are analogous to "let" statements, but the "where" clause comes at the end rather than at the beginning as in a "let" clause. Furthermore, Ada/SPARK generally requires definition before use, and having the "where" clause at the end violates that. More commonly, as in SQL, a "where" clause (or "when" clause in Ada/SPARK) acts as a filter rather than as a definition.

@senier senier moved this from To do to Long-term in RecordFlux Future Aug 24, 2022
treiher added a commit that referenced this issue Jan 2, 2023
treiher added a commit that referenced this issue Jan 3, 2023
treiher added a commit that referenced this issue Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architectural decision Discussion of design decision specification Related to specification package (e.g., specification parsing)
Projects
No open projects
Development

No branches or pull requests

2 participants