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

Rewrite file-sniffer analysis #412

Merged
merged 7 commits into from
Jan 30, 2024
Merged

Conversation

angelikatyborska
Copy link
Member

@angelikatyborska angelikatyborska commented Nov 25, 2023

Resolves #407

Originally this PR was called:

Rewrite file-sniffer analysis (assert_call should also find calls in function heads)

After a deep dive, I realized that assert_call is already capable of finding calls in function heads.

I have initially made a wrong assumption. I thought that the Kernel module alone is implicitly imported into each new module. That is only partially correct. The Kernel.SpecialForms module is also implicitly imported, with some important differences:

  • You cannot modify or opt out of importing Kernel.SpecialForms, whereas you can modify Kernel imports by making them explicit and passing :only/:except options
  • In the AST, usages of Kernel functions can be distinguished from local calls, but usages of Kernel.SpecialForms macros cannot. They look exactly like usages of local function/macros.

I was also confused which module provides which macro, I thought <<>> and :: comes from Kernel, but it coems from Kernel.SpecialForms

TL;DR: we can use assert_call called_fn name: :<<>> to check for calls of special forms with no problems and no modifications necessary. It is not allowed to overwrite those special forms anyway, so you won't have a conflicting local function.

Related PR: exercism/website-copy#2306

@angelikatyborska angelikatyborska changed the title Rewrite file-sniffer analysis (assert_call should also find calls in function heads) Rewrite file-sniffer analysis Dec 26, 2023
@angelikatyborska angelikatyborska marked this pull request as ready for review December 26, 2023 12:34
@angelikatyborska
Copy link
Member Author

@jiegillet could you review this one?

Copy link
Contributor

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

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

Wonderful, it's nice to see that assert_call was already powerful enough to handle that, thank you for adding the new tests to highlight the behavior.

Sorry that I took so long to review, I still thought that assert_call needed to change, and I was slowly gathering motivation to deep dive back into it, but it seems I never had enough haha. I'm glad you reminded me :)

The code looks great, I just left a suggestion to add a test or two, but it's just a formality.

end
]
end

test_exercise_analysis "doesn't use pattern matching",
comments: [Constants.file_sniffer_use_pattern_matching()] do
test_exercise_analysis "doesn't use <<>> nor ::",
Copy link
Contributor

Choose a reason for hiding this comment

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

The comment should be triggered if the solution only uses one of the forms right? Should we add tests to check that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a test with just <<>> but I don't think I can add a test with just ::. It's used for defining binary sizes, so you can't really use it without using the binary special form...

@jiegillet
Copy link
Contributor

GitHub doesn't seem to let me re-run the external tests, I can't find the button, I don't know why.

@angelikatyborska
Copy link
Member Author

I can't find the button, I don't know why.

You can only rerun the tests if the latest test run isn't too old... I think maybe 2 or 4 weeks.

@angelikatyborska angelikatyborska merged commit e3e7768 into main Jan 30, 2024
6 checks passed
@angelikatyborska angelikatyborska deleted the rewrite-file-sniffer-analyzer branch January 30, 2024 05:35
@jiegillet
Copy link
Contributor

Ah that makes sense :)

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.

file-sniffer analyzer should allow string representation for type_from_binary
2 participants