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

analyze: use a common namespace for all local and global PointerIds #1164

Merged
merged 11 commits into from
Dec 2, 2024

Conversation

spernsteiner
Copy link
Collaborator

Currently, each function has its own namespace for local PointerIds: PointerId::local(3) in function f is distinct from PointerId::local(3) in function g. This creates some problems for pointee type inference*. This branch puts all functions' local PointerIds into a common namespace, with each function occupying a different range in that space. This means each PointerId is now globally unique, and code that is analyzing one function can mention PointerIds from a different function without ambiguity.

Most analyses still only look at a single function; these use a sparse PointerTable that has entries only for global PointerIds (that is, PointerIds in the range allocated for globals) and for the local PointerIds of the current function. Any analyses that need to consider cross-function local PointerIds can use a single large GlobalPointerTable instead.


* The specific issue is this: the allocation in lighttpd's buffer_init is not initialized inside that function, so correctly inferring the type requires unifying type variables interprocedurally. The type variables for the pointee analysis are tracked in a VarTable, which contains LTys. We'd like to track variables from all functions in one big VarTable, so that we can unify variables that originated in different functions. However, LTys may contain local PointerIds, so a shared VarTable could mix up local PointerIds from different functions/namespaces, producing nonsensical results. The fix being applied here is to put all PointerIds into a single namespace, so all type variables can be tracked in a common VarTable, and there is no longer an obstacle to unifying type variables from different functions.

@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids branch from 5854a95 to 01598e1 Compare November 26, 2024 23:01
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids-base branch from 1726a71 to 4a634a7 Compare November 26, 2024 23:01
@spernsteiner spernsteiner changed the base branch from analyze-merged-pointer-ids-base to master November 26, 2024 23:01
@spernsteiner spernsteiner changed the base branch from master to analyze-merged-pointer-ids-base November 26, 2024 23:02
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids-base branch from 4a634a7 to ca0d95e Compare November 26, 2024 23:20
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids branch from 01598e1 to e4e4d46 Compare November 26, 2024 23:20
c2rust-analyze/src/context.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/context.rs Outdated Show resolved Hide resolved
c2rust-analyze/src/equiv.rs Outdated Show resolved Hide resolved
#[derive(Clone, Debug)]
pub struct NextLocalPointerId(u32);

impl NextLocalPointerId {
pub fn new() -> NextLocalPointerId {
pub fn _new() -> NextLocalPointerId {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why the rename?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The function is currently unused, but I've left it in place for completeness of the API (NextGlobalPointerId has a fn new(), so the local version should too) and in case it's needed again in the future. To suppress the dead code warning, I prefer a leading underscore rather than #[allow(dead_code)] because it makes it more likely that anyone who starts using the function in the future will also remember to un-suppress the warning.

c2rust-analyze/src/pointer_id.rs Show resolved Hide resolved
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids-base branch from ca0d95e to 5830b4f Compare December 2, 2024 19:11
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids branch from b68e568 to 53d1014 Compare December 2, 2024 19:11
@spernsteiner spernsteiner changed the base branch from analyze-merged-pointer-ids-base to master December 2, 2024 19:12
@spernsteiner spernsteiner force-pushed the analyze-merged-pointer-ids branch from 53d1014 to 2149fa6 Compare December 2, 2024 19:13
@spernsteiner spernsteiner merged commit ee4b3cc into master Dec 2, 2024
9 checks passed
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