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

Code generation for functions in sessions #650

Closed
7 tasks done
treiher opened this issue Apr 29, 2021 · 2 comments · Fixed by #672
Closed
7 tasks done

Code generation for functions in sessions #650

treiher opened this issue Apr 29, 2021 · 2 comments · Fixed by #672
Assignees
Labels
architectural decision Discussion of design decision generator Related to generator package (SPARK code generation)

Comments

@treiher
Copy link
Collaborator

treiher commented Apr 29, 2021

Context and Problem Statement

Functions enable the execution of externally defined code in the session state machine. For each function declaration in the session specification a formal procedure declaration is added to the corresponding generic session package. The return type and parameters of a function are represented by the first and subsequent parameters of the generated procedure declaration. The set of allowed parameter and return types has a high impact on the code generation. Scalar types as parameters and return type are essential and simple to support. Further potential parameter and return types will be described in the following.

Considered Options

O1 Opaque type as parameter

+ Required to allow externally defined operations on byte arrays (e.g., encryption/decryption)
Copying potentially necessary when represented by Ada array

O2 Opaque type as return value

Not representable by single out parameter if length of array is not fixed

O3 Message or sequence represented by context

External function depends on generated code
Incompatible to potential C binding
Generic message/sequence packages need to be instantiated externally and passed into generic session package to allow use of type in formal subprogram declarations
Sequence contexts and message contexts representing function parameters would need to be copied before passing them as argument, as sequence context must be writeable to allow iterating over sequence

O4 Message represented by Ada record

Each message context used as parameter or return type needs a corresponding record type and both must be transformable into the other.

+ Required for complex return values
Restricted to messages with fixed size

Decision Outcome

O1 and O4.

For now support will be added for:

  • Scalars as parameter and return types
  • Opaque as parameter type
  • Specific message types as return types (messages with fixed size consisting of opaque and scalar types)

For message types the following functionality needs to be added:

  • Detection and size determination of messages with fixed size
  • Generation of record type for messages with fixed size consisting of opaque and scalar types
  • Generation of transformations of message contexts and records into the other
  • Support for messages with bounded size and no optional fields

Future work:

  • Support for messages as parameter types
  • Support for messages containing sequences
@treiher treiher added the generator Related to generator package (SPARK code generation) label Apr 29, 2021
@treiher treiher self-assigned this Apr 30, 2021
@treiher
Copy link
Collaborator Author

treiher commented May 7, 2021

O4 also requires an instantiation of (some) message types used in a function. Opaque as a parameter type will require to use a buffer type in the generated subprogram. This buffer type is provided by a generic package, which leads to the issue described in #659.

@treiher
Copy link
Collaborator Author

treiher commented May 18, 2021

The current restriction to fixed-size messages is too limited for the intended use case. For the TLS record layer we need to support messages with variable-sized opaque fields. It should be possible to loosen the restrictions and also support messages with bounded message size (no opaque field size depends on Message'Size) and no optional fields.

treiher added a commit that referenced this issue May 26, 2021
treiher added a commit that referenced this issue May 26, 2021
Remove the direct access to the byte representation of sequence fields
and add getter functions for opaque fields.

Ref. #292, #650
treiher added a commit that referenced this issue May 26, 2021
Definite messages are messages with a bounded size and no optional
fields.

Ref. #292, #650
treiher added a commit that referenced this issue May 27, 2021
treiher added a commit that referenced this issue May 27, 2021
Remove the direct access to the byte representation of sequence fields
and add getter functions for opaque fields.

Ref. #292, #650
treiher added a commit that referenced this issue May 27, 2021
Definite messages are messages with a bounded size and no optional
fields.

Ref. #292, #650
treiher added a commit that referenced this issue Jun 8, 2021
treiher added a commit that referenced this issue Jun 8, 2021
Remove the direct access to the byte representation of sequence fields
and add getter functions for opaque fields.

Ref. #292, #650
treiher added a commit that referenced this issue Jun 8, 2021
Definite messages are messages with a bounded size and no optional
fields.

Ref. #292, #650
isaahzorgh pushed a commit that referenced this issue Jun 29, 2021
Remove the direct access to the byte representation of sequence fields
and add getter functions for opaque fields.

Ref. #292, #650
isaahzorgh pushed a commit that referenced this issue Jun 29, 2021
Definite messages are messages with a bounded size and no optional
fields.

Ref. #292, #650
@treiher treiher added the architectural decision Discussion of design decision label Jul 12, 2021
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 generator Related to generator package (SPARK code generation)
Projects
None yet
1 participant