Skip to content

Distinguish unsafe and extern - #55

Merged
davidlattimore merged 5 commits into
cackle-rs:mainfrom
XSpielinbox:distinguish-unsafe
May 18, 2026
Merged

Distinguish unsafe and extern#55
davidlattimore merged 5 commits into
cackle-rs:mainfrom
XSpielinbox:distinguish-unsafe

Conversation

@XSpielinbox

@XSpielinbox XSpielinbox commented May 13, 2026

Copy link
Copy Markdown
Contributor

Builds on #49, so should be merged afterwards.

This creates a new permission to track extern usage, in particular extern blocks and extern functions, but deliberately not extern crates.
Packages will likely require unsafe permission as well.

There are no tests yet.

The CI is failing as it unfortunately fails to parse the new config field before checking the version of the config file format.

Comment thread cackle.toml Outdated
@@ -1,5 +1,5 @@
[common]
version = 2
version = 3

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To avoid the CI failure, how about leaving our config file at version 2 until at least after the next release? Version 2 should presumably mean that allow_unsafe implies allow_extern.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I tried that before. The CI nevertheless fails.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If it fails with version = 2, then we should probably fix that. The whole idea of the versioning is that users can opt in to new behaviour on their own schedule. Why does it fail?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Because as stated in the description regardless of the version #[serde(deny_unknown_fields)], denies parsing of the new field before the other logic to check the version gets executed. This is definitely not good and I tried to look into it, but I could not find a good solution on how to fix that.

Comment thread src/extern_checker.rs

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Are we now reading and tokenising every file twice now? Once for checking for unsafe and once for checking for extern?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that is indeed correct and not ideal. I split it to keep it as separate and easy to understand as possible for now. But it could also be merged, once it has been confirmed that this code in general is correct and useful.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh, right, sorry. I meant completely revert the changes to cackle.toml, so the new fields wouldn't be set

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I have reverted both now, but that does not help either as then the tests are failing. I don't really understand where you want to go with this.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

From the failure, it looks like the tests are failing because they're saying that the "extern" permission is needed. When I was suggesting reverting the changes to cackle.toml, I meant just the cackle.toml for cackle itself, not the one for the test.

I suspect we also need to make it so that if a config has version=2, then we copy the value from allow_unsafe to allow_extern. That way a version 2 config will still work with a newer version of cackle, which I think is important.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, I changed it to only revert the main cackle.toml.

I will try to add this fallback for version 2 tomorrow.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is the change I made now what you had in mind?

Comment thread src/unsafe_checker.rs
@XSpielinbox
XSpielinbox force-pushed the distinguish-unsafe branch 2 times, most recently from e0ec1cf to 4eeabff Compare May 14, 2026 19:33
@XSpielinbox
XSpielinbox force-pushed the distinguish-unsafe branch from 4eeabff to 6897b9b Compare May 15, 2026 09:52
@davidlattimore
davidlattimore merged commit d49cd2b into cackle-rs:main May 18, 2026
3 checks passed
@XSpielinbox
XSpielinbox deleted the distinguish-unsafe branch May 18, 2026 10:27
davidlattimore pushed a commit that referenced this pull request May 18, 2026
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