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

Remove list types and list initialization syntax #2235

Merged
merged 25 commits into from
Mar 11, 2024

Conversation

cmnrd
Copy link
Collaborator

@cmnrd cmnrd commented Mar 7, 2024

This PR implements another major step towards completing #1492. In addition to the built-in type time, LF would handle fixed-sized and dynamically sized lists/arrays specially. This required additional logic in our "type system" as well as dedicated syntax for initializing such list types. For instance, it was possible to write the following (in the C target):

state foo: int[3](1, 2, 3)
state bar time[](1 ms, 2 ms, 3ms)

We also implemented this syntax for other targets, but it never worked all that well and it clashed with principles of the other target languages. Therefore, we decided in #1492 to drop this style of initialization. In addition, #1580 deprecated the (...) initializer syntax in favor of target language expressions. So in C, we can write now:

state foo: int[3] = {1, 2, 3}

This PR follows up and removes the deprecated syntax and performs additional cleanup. Concretely, it makes the following changes:

  • Simplify/update the grammar rules.
  • Disable parenthesis-based initialization for all targets except C++
  • Drop LF-native support for lists and arrays. We fully rely on the target type system now.
  • Due to the previous point, we cannot support time lists anymore. Thus, the rule for the time array type time[] is removed. However, this can be easily replaced with the target time type, e.g., in C: state foo: interval_t[] = { 1ms, 2ms, 3ms}.
  • Rename the array spec syntax rule to clearly describe it as C-style. This is to allow later addition of other array types, like for Rust which uses [i32, 4].
  • Drop support for the c-style array notation from the C++ and the Rust target. We simply use the native types in these languages instead (e.g., std::vector<>, std::array<> for C++).
  • Update test cases that still used the old initializer syntax.

Fixes #1675
Fixes #2056
Fixes #2202

@cmnrd cmnrd added enhancement Enhancement of existing feature language Related to the syntax and semantics of LF labels Mar 7, 2024
Copy link
Member

@lhstrh lhstrh left a comment

Choose a reason for hiding this comment

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

This looks great! It sure has simplified a few things.

@cmnrd cmnrd mentioned this pull request Mar 11, 2024
@cmnrd cmnrd force-pushed the remove-list-initialization branch from 2115aa2 to 0b767c4 Compare March 11, 2024 12:20
@cmnrd cmnrd added this pull request to the merge queue Mar 11, 2024
Merged via the queue into master with commit e2ed34e Mar 11, 2024
24 checks passed
@cmnrd cmnrd deleted the remove-list-initialization branch March 11, 2024 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement of existing feature language Related to the syntax and semantics of LF
Projects
None yet
2 participants