Skip to content

Make unmodular code generation a bit more unmodular#4233

Draft
balacij wants to merge 4 commits intomainfrom
unmodularCG
Draft

Make unmodular code generation a bit more unmodular#4233
balacij wants to merge 4 commits intomainfrom
unmodularCG

Conversation

@balacij
Copy link
Collaborator

@balacij balacij commented Jun 22, 2025

Contributes to #1999, #3247, #3512

Not quite ready to merge yet, but, this PR makes the Unmodular code generation choice a bit more unmodular by removing the generated function calls in favour of inlining them.

Three Four Five major issues:

  1. Code comments are completely removed from the unmodular option -- the comments that previously went above the function declarations.
  2. Code needs to be tidied.
  3. ODE-related things are untested.
  4. GProc-generating code is untouched.
  5. I have not tested generating derived inputs yet.

I'm also not quite sure yet how we should integrate this in the options. Should these changes go under Unmodular? SuperUnmodular? SpaghettiMonster? I currently have it editing Unmodular.

@smiths
Copy link
Collaborator

smiths commented Jun 23, 2025

@balacij, this change should be helpful when we return to the human-readable code paper.

@JacquesCarette
Copy link
Owner

We want as broad a choice of "code families" as possible. So we should have ways to tune things, hopefully with somewhat fine-grained precision. So these changes should not remove previous possibilities, but augment them.

So we need sub-choices of Unmodular.

-- | Program implementation options.
data ImplementationType = Library -- ^ Generated code does not include Controller.
| Program -- ^ Generated code includes Controller.
deriving Eq
Copy link
Owner

Choose a reason for hiding this comment

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

We've tended to avoid deriving Eq (even though in this case it is completely harmless) to emphasize a pattern-matching style over a "boolean" style. Why do you need Eq?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can actually remove this now -- I previously was avoiding a very small case statement in genMainFunc but I've since changed it back to a case statement.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 5fd7f57

| otherwise = [genInputFormat Pub, genInputDerived Pub, genInputConstraints Pub]

modFuncs :: OOProg r => [GenState (Maybe (SMethod r))]
modFuncs = map (fmap Just) $ concatMap genModFuncs (modules g)
Copy link
Owner

Choose a reason for hiding this comment

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

This is an odd piece of code -- it deserves a comment!

return 0;
}

double func_t_flight(InputParameters &inParams) {
Copy link
Owner

Choose a reason for hiding this comment

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

while I'm completely fine with the logging of the inline version being much less verbose, we shouldn't lose quite so much logging. Issue six?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Issue six indeed!


};

/** \brief Calculates flight duration: the time when the projectile lands (s)
Copy link
Owner

Choose a reason for hiding this comment

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

When comments are turned on, I think a version of these comments should go above the inlined code.

double p_land = func_p_land(v_launch, theta, g);
double d_offset = func_d_offset(p_target, p_land);
string s = func_s(p_target, epsilon, d_offset);
// flight duration: the time when the projectile lands (s)
Copy link
Owner

Choose a reason for hiding this comment

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

Why have the comments started appearing here? [Don't get me wrong, this is a great option to have!] But we should have a version without them too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When comments are turned on, I think a version of these comments should go above the inlined code.

These are meant to be the inlined code comments. It's just a weaker variation of the ones that would go above the function-generating counterpart. I don't think we want the full commentary, do we?

Copy link
Owner

Choose a reason for hiding this comment

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

Correct, not full commentary, thus my "a version of".

data Comments = CommentFunc -- ^ Function/method-level comments.
| CommentClass -- ^ Class-level comments.
| CommentMod -- ^ File/Module-level comments.
| CommentVarDecls -- ^ Variable declarations comments.
Copy link
Owner

Choose a reason for hiding this comment

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

Nice addition!

@balacij balacij marked this pull request as draft July 18, 2025 21:59
@balacij
Copy link
Collaborator Author

balacij commented Jul 18, 2025

Converting to Draft because it needs to:

  1. Be more careful. It should continue to generate functions for function-typed things.
  2. Be split up.
  3. Support GProc.
  4. Get tested.

@balacij
Copy link
Collaborator Author

balacij commented Jul 31, 2025

@JacquesCarette and I discussed this in our meeting yesterday. Paraphrasing our discussion:

  • We want to move away from the "modular"/"unmodular" designations (as it is ambiguous/fuzzy).
  • We want more concrete terminology captured/used/invoked when describing what kind of architecture.
  • For example straight-line program could be an example (informally: just assignments, no ifs/fors/whiles) of a program we generate.
  • Rationale: The story we would tell (in the paper) starts with the most "unmodular" version and shows how we can generate "more modular" versions (embracing the fuzzy wording here) through knowledge capture.

    Begin with the straight-line program, if we wanted to make it more readable, what would we do? Basically showing off Drasil's generation options and how we can gradually build "larger and larger" programs that describes more.

    Least verbose projectile to Most verbose projectile

  • Side effect of the discussion: The responsibility of depth of knowledge capture can vary about the desired artifacts. For example, not all components of the SRS are strictly necessary to describe a program -- everything can be "junk" -- or, an entirely different SRS format can be used (a heavily stripped down variant of the SmithEtAl template). How slim down can an SRS get and still generate (reasonable) runnable code?

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.

3 participants