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

Optimize sequence comprehension 'Head #1115

Closed
Tracked by #908
jklmnn opened this issue Jul 22, 2022 · 1 comment · Fixed by #1128
Closed
Tracked by #908

Optimize sequence comprehension 'Head #1115

jklmnn opened this issue Jul 22, 2022 · 1 comment · Fixed by #1128
Assignees
Labels
generator Related to generator package (SPARK code generation)

Comments

@jklmnn
Copy link
Member

jklmnn commented Jul 22, 2022

Sequence comprehensions can be used to filter list elements. To get the first element of a specific type the current implementation looks as follows:

New_Seq := [for E in List if E.Type = Type1 => E];
First_Elem := New_Seq'Head;

The problem with that implementation is that it creates a new list where searching through the existing list would be sufficient. To optimize this particular behaviour the following expression will be optimized to only do a search until an element is found and return that element:

First_Elem := [for E in List if E.Type = Type1 => E]'Head;
@jklmnn jklmnn added the generator Related to generator package (SPARK code generation) label Jul 22, 2022
@jklmnn jklmnn self-assigned this Jul 22, 2022
jklmnn added a commit that referenced this issue Jul 25, 2022
jklmnn added a commit that referenced this issue Jul 25, 2022
jklmnn added a commit that referenced this issue Jul 25, 2022
@jklmnn
Copy link
Member Author

jklmnn commented Jul 27, 2022

The basic code generation for this feature seems to work. The generated code compiles. Both accessing the complete element and accessing a field of an element works. However arrays with scalar elements still generate broken code.

jklmnn added a commit that referenced this issue Jul 27, 2022
jklmnn added a commit that referenced this issue Aug 1, 2022
jklmnn added a commit that referenced this issue Aug 2, 2022
jklmnn added a commit that referenced this issue Aug 5, 2022
jklmnn added a commit that referenced this issue Aug 15, 2022
jklmnn added a commit that referenced this issue Aug 16, 2022
jklmnn added a commit that referenced this issue Aug 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
generator Related to generator package (SPARK code generation)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant