Skip to content

Fix cache check #525

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 4 commits into from
Mar 16, 2025
Merged

Fix cache check #525

merged 4 commits into from
Mar 16, 2025

Conversation

ratmice
Copy link
Collaborator

@ratmice ratmice commented Mar 16, 2025

I think this should run the cache check,

E.g. at least the following subset of .buildbot.sh now caught a bug where the pretty printer
was emitting a non-whitespace change, and we had to add a comma.

#! /bin/sh

set -e
export RUSTFLAGS="--cfg grmtools_extra_checks"
root=`pwd`
cd $root/lrlex/examples/calc_manual_lex
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
# Touching these files shouldn't invalidate the cache (via --cfg grmtools_extra_checks)
touch src/main.rs && CACHE_EXPECTED=y cargo build
cd $root/lrpar/examples/calc_actions
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
touch src/main.rs && CACHE_EXPECTED=y cargo build
cd $root/lrpar/examples/calc_ast
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
touch src/main.rs && CACHE_EXPECTED=y cargo build
cd $root/lrpar/examples/calc_parsetree
echo -n "2 + 3 * 4" | cargo run --package nimbleparse -- src/calc.l src/calc.y -
echo "2 + 3 * 4" | cargo run | grep "Result: 14"
touch src/main.rs && CACHE_EXPECTED=y cargo build
cd $root/lrpar/examples/clone_param
echo -n "1+++" | cargo run --package nimbleparse -- src/param.l src/param.y -
cd $root/lrpar/examples/start_states
echo -n "/* /* commented out */ */ uncommented text /* */" | cargo run --package nimbleparse -- src/comment.l src/comment.y -
cd $root

@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

With these changes, I think that #513 should consistently fail.

@@ -47,7 +47,7 @@ impl quote::ToTokens for YaccKind {
tokens.extend(match *self {
YaccKind::Grmtools => quote!(::cfgrammar::yacc::YaccKind::Grmtools),
YaccKind::Original(action_kind) => {
quote!(::cfgrammar::yacc::YaccKind::Original(#action_kind))
quote!(::cfgrammar::yacc::YaccKind::Original(#action_kind,))
Copy link
Collaborator Author

@ratmice ratmice Mar 16, 2025

Choose a reason for hiding this comment

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

I think perhaps it is best to attempt to do something less fragile here.

My thoughts are instead of emitting the cache module,
emit a constant string in the hopes that the pretty printer will ignore the string.

E.g. so go from // CACHE INFORMATION ... to const CACHE_INFORMATION: &str = "..."
abandoning cache_module unless we do want to keep 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.

Fixed by 8e32c81 and subsequent commits...

@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

Might want to sqaush out the a08fbdb change?

@@ -865,7 +865,7 @@ where
})
.collect::<Vec<_>>();
let rule_map_len = rule_map.len();
quote! {
let cache_info = quote! {
#[allow(unused)]
mod _cache_information_ {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We may want to do something else here, as we no longer actually compile this code
as we change it it could perhaps start to contain syntax errors, etc.

We could emit both the cache_info module, and the module text within that constant string.
Or we could just emit a formatted string more like the original comment.

Copy link
Member

Choose a reason for hiding this comment

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

Don't we just want to output the information in one place? Perhaps I've misunderstood!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I guess i'm saying:

this emits a strong:

const CACHE_INFO: &str = "#[allow(unused)] mod _cache_information_ {...

But because we never actually compile mod _cache_information_ anymore, it is just embedded in that string,
so it is both confusing, and we could make a change that would cause mod _cache_information_ to not actually compile but not notice.

I basically just did the minimal change to check that embedding it as a string works as a proof of concept.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be fixed in a687505

@ltratt
Copy link
Member

ltratt commented Mar 16, 2025

Shouldn't we remove mod _cache_information then?

// This declaration can be affected by the pretty printer.
// But we would hope the actual cache string is not.
#[allow(unused)]
const CACHE_INFO: &str = #cache;
Copy link
Collaborator Author

@ratmice ratmice Mar 16, 2025

Choose a reason for hiding this comment

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

Looks like we can name this const _: &str = #cache.

I thought this wasn't a valid constant declaration, but it looks like it is now.

Edit it was allowed in: RFC 2562

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 allows us to get rid of #[allow(unused)]

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 by 3b860ca

@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

So, I think this is much less fragile now than trying to rely on the whitespace hack.
Probably ready for review.

@ltratt
Copy link
Member

ltratt commented Mar 16, 2025

Please squash.

ratmice added 3 commits March 16, 2025 11:14
This ran into a known cargo footgun where if you emit rerun-if-changed
you are responsible for emitting all the rerun-if-changed directives that
otherwise would be implied by cargo.
The cache check only runs if the output grammar is newer.
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

Squashed.

@ltratt ltratt added this pull request to the merge queue Mar 16, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 16, 2025
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

Sorry, I really need to figure out how to configure my editor so it can conditionally automatically run rustfmt or not depending upon which directory I'm editing.

Because I have some projects that don't use it.

Will need a squash

@ltratt
Copy link
Member

ltratt commented Mar 16, 2025

Please squash.

This should make the cache more robust to changes
that are caused by the pretty printer.
@ratmice
Copy link
Collaborator Author

ratmice commented Mar 16, 2025

Squashed.

@ltratt ltratt added this pull request to the merge queue Mar 16, 2025
Merged via the queue into softdevteam:master with commit 6ec4291 Mar 16, 2025
2 checks passed
@ratmice ratmice deleted the fix_cache_check branch March 16, 2025 22:08
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.

2 participants