Skip to content

save-analysis: don't leak information about constructor ids #33398

Closed
@aochagavia

Description

@aochagavia

Note: the paths in this issue assume that #33370 is merged

Problem

external_data::StructData contains a ctor_id field that represents the Id of the struct constructor. However, this adds no value to the client of the API, since decl_id is enough to identify a struct.

Currently, some type references contain a ref_id that corresponds to the ctor_id of the type, instead of the decl_id. This forces clients of the API to keep a hashtable mapping from ctor_id to decl_id in case they want to get the original struct declaration.

Note: I have observed this only in tuple structs. It seems like normal structs don't even have a valid ctor_id

Example

Imagine you want to get all references to MyStruct in the following program:

struct MyStruct; // decl_id: 1, ctor_id: 2
fn main() {
    let x = foo();
}

fn foo() -> MyStruct { // Here, the reference to MyStruct has ref_id: 1
    MyStruct // Here, the reference to MyStruct has ref_id: 2 (the constructor)
}

Ideally, both references should have ref_id = 1

Solution

Remove the ctor_id field and modify the save code in such a way that references always point to a decl_id instead of a ctor_id.

cc @nrc do you think this makes sense?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions