Skip to content

All languages: Use shared FileSystem library and minor regex performance improvement. #14321

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

Merged
merged 10 commits into from
Sep 28, 2023

Conversation

aschackmull
Copy link
Contributor

This switches C++, Go, Java, JavaScript, Python, and QL to the shared FileSystem library as a followup to #12289.

I've also made a small performance tweak to the regex matching that extracts base name, stem, and extension from absolute file paths by reusing the same regex instead of calculating the same match 3 times.

Fixes https://github.com/github/codeql-c-team/issues/1598 and https://github.com/github/codeql-go-team/issues/325

Copy link
Contributor

@owen-mc owen-mc left a comment

Choose a reason for hiding this comment

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

Go 👍🏻

@@ -11,11 +11,15 @@ signature module InputSig {
/**
* Gets the absolute path of this container.
*
* Typically `containerparent(result, this)`.
* Typically `folders(this, result) or files(this, result)`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that we are touching this file anyway, could we make the three user-facing classes Container, Folder, and File final through final aliases, make the existing classes private and add an Impl suffix to the name, and make ContainerImpl and ContainerImpl::getUrl abstract?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That causes the need for all sorts of cascading changes throughout the Java class hierarchy. And maybe also for the some of the other languages. So I'm not going to try to fit that into this PR.

Copy link
Contributor

@yoff yoff left a comment

Choose a reason for hiding this comment

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

Looks fine from the Python side. Just a few questions to make sure I understand the refactor.

)
}
class Container extends Impl::Container {
Container getParent() { result = this.getParentContainer() }
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we have an extra class predicate here that we should clean up (users should just use getParentContainer instead)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I didn't want to change things so I just left it in.

Copy link
Contributor

Choose a reason for hiding this comment

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

That is fine, we can clean it up later :-)

}

Container getParentContainer() { this = result.getAChildContainer() }
override Container getParentContainer() { result = super.getParentContainer() }
Copy link
Contributor

Choose a reason for hiding this comment

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

This is needed in order to cast the result?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's used elsewhere to implement a signature so the exact return type is needed.

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

C++ 👍

@yoff
Copy link
Contributor

yoff commented Sep 27, 2023

C++ 👍

Looks like C++ might need updated test expectations.

@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

C++ 👍

Looks like C++ might need updated test expectations.

Mmm, I must have mis-clicked when looking at the test regressions. I didn't see that. I'd actually like to know why this changes. This seems somewhat suspect.

@aschackmull
Copy link
Contributor Author

C++ 👍

Looks like C++ might need updated test expectations.

Mmm, I must have mis-clicked when looking at the test regressions. I didn't see that. I'd actually like to know why this changes. This seems somewhat suspect.

Previously C++ didn't have a getURL override, but rather used getLocation for these classes. Now it inherits getURL from the shared library, which takes precedence over getLocation, so the url of the folder / ends up as folder:/// instead of file://:0:0:0:0. I'm not sure what's preferable. At least the updated behaviour will match the other languages and it seems that the previous behaviour was C++ being the odd one out.

@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

C++ 👍

Looks like C++ might need updated test expectations.

Mmm, I must have mis-clicked when looking at the test regressions. I didn't see that. I'd actually like to know why this changes. This seems somewhat suspect.

Previously C++ didn't have a getURL override, but rather used getLocation for these classes. Now it inherits getURL from the shared library, which takes precedence over getLocation, so the url of the folder / ends up as folder:/// instead of file://:0:0:0:0. I'm not sure what's preferable. At least the updated behaviour will match the other languages and it seems that the previous behaviour was C++ being the odd one out.

Looking at the test, I think folder:/// is actually more correct. However, the getURL we had was also removed purposefully in 5fdfd98

@aschackmull
Copy link
Contributor Author

However, the getURL we had was also removed purposefully in 5fdfd98

That's not the sha in which it was deprecated, though, that predates the move-to-public. But one of the very first PRs in this repo is relevant in this context: #3

@aschackmull
Copy link
Contributor Author

Maybe Container simply shouldn't be Locatable.

@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

However, the getURL we had was also removed purposefully in 5fdfd98

That's not the sha in which it was deprecated, though, that predates the move-to-public.

Yup.

So, I'm happy with just accepting the test change. I do think we maybe should consider deprecating/removing getURL wholesale.

@aschackmull aschackmull added the depends on internal PR This PR should only be merged in sync with an internal Semmle PR label Sep 27, 2023
@aschackmull
Copy link
Contributor Author

I do think we maybe should consider deprecating/removing getURL wholesale.

Or the opposite. Remove Folder from Locatable. Currently C++ is the odd one out here, all other languages don't have locations for folders.

@jketema
Copy link
Contributor

jketema commented Sep 27, 2023

I do think we maybe should consider deprecating/removing getURL wholesale.

Or the opposite. Remove Folder from Locatable. Currently C++ is the odd one out here, all other languages don't have locations for folders.

That also makes sense. I don't have any particular preference here.

@aschackmull
Copy link
Contributor Author

That also makes sense. I don't have any particular preference here.

In any case, I think that's best handled as follow-up.

@jketema
Copy link
Contributor

jketema commented Sep 28, 2023

That also makes sense. I don't have any particular preference here.

In any case, I think that's best handled as follow-up.

Agreed.

@aschackmull aschackmull merged commit 5feb2f7 into github:main Sep 28, 2023
@aschackmull aschackmull deleted the shared/filesystem branch September 28, 2023 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C# C++ depends on internal PR This PR should only be merged in sync with an internal Semmle PR Go Java JS no-change-note-required This PR does not need a change note Python QL-for-QL Ruby
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants