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

Type alias syntax & semantics #591

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Type alias syntax & semantics #591

wants to merge 10 commits into from

Conversation

Kronos3
Copy link
Collaborator

@Kronos3 Kronos3 commented Feb 3, 2025

Part of #113. This finishes up some changes made in #549 for syntax & semantics implementation. It adds a test to generate a struct that references a type alias.

No C++ code is generated yet for type aliases. In model elements that use type aliases, the type aliases are converted to their underlying types before generating C++ code.

@Kronos3 Kronos3 mentioned this pull request Feb 3, 2025
6 tasks
@bocchino
Copy link
Collaborator

bocchino commented Feb 4, 2025

It looks like you need to regenerate the trace info for the native build. See the instructions here: https://github.com/nasa/fpp/tree/main/compiler#building-native-binaries.

@bocchino bocchino self-requested a review February 5, 2025 17:37
Copy link
Collaborator

@bocchino bocchino left a comment

Choose a reason for hiding this comment

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

Looks good! As discussed, let's separate out the removal of "built-in types," because removing those requires changes to F Prime. For now let's move forward with the syntax, semantics, and code generation of type aliases, without removing built-in types.

@bocchino
Copy link
Collaborator

Another issue I see is that the code generator is generating an empty TypesAc.cpp file. I think we should suppress the generation of this file. Does that require any changes to the CppDoc framework?

@Kronos3
Copy link
Collaborator Author

Kronos3 commented Feb 10, 2025

@bocchino You may need to do the trace updates again, I can't install GraalVM for Java11 since the only version available from Homebrew is jdk23 and the SDKMAN/official installation method seems to only have 17, 21, and 23.

We may also want to consider updating the Java version or putting the trace updates in CI

@Kronos3 Kronos3 requested a review from bocchino February 11, 2025 02:14
@@ -345,8 +365,11 @@ object Type {
}

/** Check for type identity */
def areIdentical(t1: Type, t2: Type): Boolean = {
def areIdentical(t1Aliased: Type, t2Aliased: Type): Boolean = {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change doesn't conform to the spec. The spec says that an alias type is identical to itself, not to its underlying type. See here: https://nasa.github.io/fpp/fpp-spec.html#Type-Checking_Identical-Types.

override def defAliasTypeAnnotatedNode(a: Analysis, node: Ast.Annotated[AstNode[Ast.DefAliasType]]) = {
val (_, node1, _) = node
val data = node1.data
for {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This for...yield can be simplified to a call to typeNameNode.

@@ -136,7 +136,9 @@ case class CppWriterState(
for {
fileName <- sym match {
case _: Symbol.AbsType =>
if isBuiltInType(name) then None else Some(name)
if isBuiltInType(name) then None else Some(name)
// TODO(tumbar) Compute the includes for alias types
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we resolve this TODO before merging this PR? I think we just need to and add TypeAc to the filename pattern.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Or is the issue that we're not generating code for alias types, so we can't generate the include header? If so, can the comment be clearer?

@@ -16,6 +17,10 @@ case class TypeCppWriter(
override def absType(s: CppWriterState, t: Type.AbsType) =
s.writeSymbol(Symbol.AbsType(t.node))

override def aliasType(s: CppWriterState, t: Type.AliasType) =
// TODO(tumbar) Keep the aliased type name in codegen
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please clarify that we're doing it this way for now because we're not generating the type alias code.

@@ -3,6 +3,6 @@ package fpp.compiler.util
/** The compiler version */
object Version {

val v = "[unknown version]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please revert this change. This is a glitch in the way the installer works -- if you abort the installation, it can corrupt this file.

@@ -1,6 +1,7 @@
#!/bin/sh -e

fpp_to_cpp=../../../../../../bin/fpp-to-cpp
fprime_gcc=../../../../../../scripts/fprime-gcc
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch!

@bocchino bocchino changed the title Type alias syntax & codegen Type alias syntax & semantics Feb 11, 2025
@bocchino
Copy link
Collaborator

We may also want to consider updating the Java version or putting the trace updates in CI

Noted. The trace updates are supposed to be in CI, but they have never worked, and instead of wrangling CI I have just updated them manually. @LeStarch do you see any issue with updating the FPP Java environment from Java 11 to Java 17? We would need to do this in the GitHub actions.

Copy link
Collaborator

@bocchino bocchino left a comment

Choose a reason for hiding this comment

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

Looks good, I added some comments.

We also discussed adding a few tests for type aliases to the ScalaTest tests. Can we do that in this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants