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

FileConfig cleanups #978

Merged
merged 34 commits into from
Mar 2, 2022
Merged

FileConfig cleanups #978

merged 34 commits into from
Mar 2, 2022

Conversation

cmnrd
Copy link
Collaborator

@cmnrd cmnrd commented Feb 25, 2022

This PR cleans up FileConfig which currently seems to mix a variety of concerns. Despite some other simplifications and cleanups, it factors out functions that are purely related to file system access to a new static class FileUtils.

Note that this branch is based on #971 and hence include it's changes. The diff should clear up once #971 is merged.

@cmnrd cmnrd marked this pull request as ready for review February 25, 2022 16:14
edwardalee
edwardalee previously approved these changes Feb 25, 2022
Copy link
Collaborator

@edwardalee edwardalee left a comment

Choose a reason for hiding this comment

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

I did not check this thoroughly, but on a spot check, all looked good to me. It's a big improvement! Except that it looks like there is a compile error with packaging Epoch... Also, this seems to be causing test failures with serialization (again, they look like compile errors).

@edwardalee edwardalee dismissed their stale review February 25, 2022 17:01

I didn't notice the test failures. These need to be fixed before merging.

@cmnrd cmnrd added this to the 0.1.0 milestone Feb 28, 2022
@cmnrd
Copy link
Collaborator Author

cmnrd commented Feb 28, 2022

As far as I can see, this should be ready to be merged. I also added this PR to the 0.1.0 milestone. Given that there are no major concerns by reviewers, we should be able to merge this for 0.1.0.

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.

I think it's a sensible choice to factor out all the static methods of FileConfig into a separate FileUtil class. There are some methods that ended up in CUtil, however, which seem out of place there.

* @param directory String representation of the director to search in.
* @return A Java file or null if not found
*/
public static Path findFile(String fileName, Path directory) {
Copy link
Member

Choose a reason for hiding this comment

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

Why was this moved to CUtil? I don't see what's C-specific about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The method is only used by the C generator and the file lookup strategy seems to be very specific to the assumptions that the C generator makes.

Copy link
Member

Choose a reason for hiding this comment

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

What assumptions are those? The employed strategy seems rather generic.

* version do not accidentally get executed.
* @param fileConfig
*/
public static void deleteBinFiles(FileConfig fileConfig) {
Copy link
Member

Choose a reason for hiding this comment

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

This, too, doesn't look C-specific to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also this function is only used by the C-generator. Honestly, I don't quite understand what it does, but it seems to make various assumptions as to where files are placed and how they are named. Hence, I figure it will not be easily applicable to other targets. I also don't quite understand why it is needed since we have methods for cleaning up the entire bin dir.

Copy link
Member

Choose a reason for hiding this comment

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

So the function is "quarantined" here with the eventual goal of eliminating it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Also see my comment in the main thread. I don't know the C Generator well enough to understand what this method does, why it is needed, and whether it can be eliminated. I only know that the other generators don't use it ;)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This method implements a simple functionality that all targets should implement: If a code generation or compilation fails for a program Foo.lf, then there should be no binary file bin/Foo. If there is, it is a bug. If the other targets don't implement this, then it is a bug.

@cmnrd
Copy link
Collaborator Author

cmnrd commented Mar 2, 2022

My goal is to make FileConfig and FileUtil classes focus on one specific task each. FileConfig provides details about where certain files should be located and is meant to configure the generators. FileUtil provides generic static methods for file system access (including access to files and directories in jars or bundles). By generic FS access I mean operations like writing a file, deleting a file/directory or copying a file/directory.

The two methods in CUtil don't fit the scope of either of those classes. They are not configuration related, and they don't provide generic filesystem access. Instead, they implement very specific algorithms. These algorithms are intervened with the code generation process (delete bin in fact analysis the resource contents and deletes files where it assumes the generator has placed them, findFile makes assumptions as to where the source files for the compilation are located). Therefore, I argue that the methods should be placed in GeneratorUtils or a similar class. However, since they are only used in C and I currently don't see that they would be useful for other targets I placed them in CUtil. I might be wrong though and if people feel GeneratorUtils would be the better place, I am happy to move it over there.

@lhstrh
Copy link
Member

lhstrh commented Mar 2, 2022

My goal is to make FileConfig and FileUtil classes focus on one specific task each. FileConfig provides details about where certain files should be located and is meant to configure the generators. FileUtil provides generic static methods for file system access (including access to files and directories in jars or bundles). By generic FS access I mean operations like writing a file, deleting a file/directory or copying a file/directory.

Yes, I'm fully on board with this.

The two methods in CUtil don't fit the scope of either of those classes. They are not configuration related, and they don't provide generic filesystem access. Instead, they implement very specific algorithms. These algorithms are intervened with the code generation process (delete bin in fact analysis the resource contents and deletes files where it assumes the generator has placed them, findFile makes assumptions as to where the source files for the compilation are located). Therefore, I argue that the methods should be placed in GeneratorUtils or a similar class. However, since they are only used in C and I currently don't see that they would be useful for other targets I placed them in CUtil. I might be wrong though and if people feel GeneratorUtils would be the better place, I am happy to move it over there.

I understand. We can leave them in CUtil for now. I believe that the findFile method implements the policy all code generators should use for locating files that are either imported or listed in the files target property. If they don't, we should bring all targets in alignment, and if they do we have a case of code duplication. We might create an issue for this and move on?

@cmnrd
Copy link
Collaborator Author

cmnrd commented Mar 2, 2022

I understand. We can leave them in CUtil for now. I believe that the findFile method implements the policy all code generators should use for locating files that are either imported or listed in the files target property. If they don't, we should bring all targets in alignment, and if they do we have a case of code duplication. We might create an issue for this and move on?

I think currently we don't support the files property outside the C-based targets. I am not sure how useful it would be for the other targets. For C++, it only adds redundancy but no new functionality. But yes, we can and should discuss this elsewhere.

@cmnrd cmnrd merged commit c2633ee into master Mar 2, 2022
@cmnrd cmnrd deleted the fileconfig-cleanup branch March 2, 2022 08:18
cmnrd added a commit that referenced this pull request Mar 3, 2022
This change reverts a small part of #978 in order to fix the broken error
reporting in Epoch.

closes #994
@cmnrd cmnrd mentioned this pull request Mar 3, 2022
cmnrd added a commit that referenced this pull request Mar 3, 2022
This change reverts a small part of #978 in order to fix the broken error
reporting in Epoch.

closes #994
@lhstrh lhstrh added the refactoring Code quality enhancement label Mar 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Code quality enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants