+
Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

feat(playground): display the control flow graph in the playground #2969

Merged
merged 7 commits into from
Aug 8, 2022

Conversation

leops
Copy link
Contributor

@leops leops commented Jul 29, 2022

Summary

This PR add a new "Control Flow Graph" tab in the playground displaying the control flow graph for the currently selected function (the function that contains either the cursor or the start of the current selection) using mermaid.js

In order to extract the CFG from the analyzer I introduced a concept of "matcher layer" that can wrap an existing query matcher and intercept incoming query matches from the visitors. Calling the analyzer through the existing analyze entry point simply uses an empty layer function, this is all statically dispatched so it should all get inlined and come out as zero-cost in the end.

@leops leops requested a review from xunilrj as a code owner July 29, 2022 14:39
@leops leops requested a review from a team July 29, 2022 14:39
@leops leops temporarily deployed to aws July 29, 2022 14:40 Inactive
@github-actions
Copy link

github-actions bot commented Jul 29, 2022

@leops leops force-pushed the feature/playground-cfg branch from 7e04b70 to 22da9ff Compare July 29, 2022 14:56
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jul 29, 2022

Deploying with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6bd0a60
Status: ✅  Deploy successful!
Preview URL: https://76b8fda2.tools-8rn.pages.dev
Branch Preview URL: https://feature-playground-cfg.tools-8rn.pages.dev

View logs

@leops leops temporarily deployed to aws July 29, 2022 14:56 Inactive
@ematipico
Copy link
Contributor

The new tab can't been seen on mobile

@leops leops force-pushed the feature/playground-cfg branch from 22da9ff to b1e9417 Compare August 1, 2022 09:06
@leops leops temporarily deployed to aws August 1, 2022 09:06 Inactive
self.inner.find_rule(group, rule)
}

fn match_query(&mut self, params: MatchQueryParams<L>) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How does this function differ from match_query of QueryMatcher?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The MatcherLayer struct is an "adapter type" that implements the QueryMatcher trait on top of another, generic type also implementing this trait. It's similar to Iterator adapters like Inspect<T> that implements the iterator trait by calling through to the underlying T: Iterator object, then passing the items returned by next to the provided callback (the difference is that MatcherLayer calls the layer callback function before calling the implementation of match_query for the underlying matcher type)

@leops leops temporarily deployed to aws August 2, 2022 07:55 Inactive
@leops leops force-pushed the feature/playground-cfg branch from d80c81f to e5a0e4b Compare August 2, 2022 08:45
@leops leops temporarily deployed to aws August 2, 2022 08:45 Inactive
@ematipico
Copy link
Contributor

@leops could you check why the deployment on CloudFlare fails? Hopefully it's their fault

@@ -54,7 +60,7 @@ where
}

let mut analyzer = Analyzer::new(
build_registry(&filter),
MatcherLayer::new(build_registry(&filter), matcher_layer),
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be an option to add this functionality instead on Analyzer as inspect?

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 would work, but in the end the rome_js_analyze library would probably still need to expose two functions since the internal Analyzer is not part of the public API

@leops leops temporarily deployed to aws August 3, 2022 09:43 Inactive
@leops leops force-pushed the feature/playground-cfg branch from 76f5ac4 to bffc514 Compare August 3, 2022 09:49
@leops leops temporarily deployed to aws August 3, 2022 09:49 Inactive
@leops leops force-pushed the feature/playground-cfg branch from bffc514 to bfd185e Compare August 3, 2022 15:13
@leops leops temporarily deployed to aws August 3, 2022 15:13 Inactive
Copy link
Contributor

@ematipico ematipico 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 we have to do something with the build process (or the upload of static files). The playground is not able to load the iframe:

Screenshot 2022-08-04 at 12 46 13

@leops
Copy link
Contributor Author

leops commented Aug 4, 2022

I think we have to do something with the build process (or the upload of static files). The playground is not able to load the iframe:

Ah I think it's an issue with the temporary deployment (it tries to load the content page for the iframe at play.rome.tools/mermaid.html when it should be play.rome.tools/10cc478/mermaid.html), it would correctly on the main playground deployment but I'll try to fix it so it works in PRs too

@ematipico ematipico added the A-Website Area: website and documentation label Aug 4, 2022
@ematipico ematipico added this to the 0.9.0 milestone Aug 4, 2022
@leops leops force-pushed the feature/playground-cfg branch from 5065d24 to 3290451 Compare August 8, 2022 07:25
@leops leops temporarily deployed to aws August 8, 2022 07:25 Inactive
@leops leops temporarily deployed to aws August 8, 2022 07:39 Inactive
@leops
Copy link
Contributor Author

leops commented Aug 8, 2022

The CI check is failing on false positives for the noUnusedVariables rule introduced in the latest release, but this seems like an unrelated issue and this PR could be merged anyway ?

@ematipico
Copy link
Contributor

The CI check is failing on false positives for the noUnusedVariables rule introduced in the latest release, but this seems like an unrelated issue and this PR could be merged anyway ?

I don't mind merging the PR

@leops leops requested a review from ematipico August 8, 2022 09:43
@ematipico ematipico merged commit 407074d into main Aug 8, 2022
@ematipico ematipico deleted the feature/playground-cfg branch August 8, 2022 11:15
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 10, 2022
IWANABETHATGUY pushed a commit to IWANABETHATGUY/tools that referenced this pull request Aug 22, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Website Area: website and documentation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载