Skip to content

Proposal: use &'db in tracked struct declaration for return_ref #582

Open
@nikomatsakis

Description

@nikomatsakis

Salsa currently supports the #[return_ref] declaration to tag fields whose values are expensive to clone:

#[salsa::tracked]
pub struct SymFunctionSignature<'db> {
    source: SymFunction<'db>,

    #[return_ref]
    pub generics: Vec<SymGeneric<'db>>,

    #[return_ref]
    pub inputs: Vec<SymLocalVariable<'db>>,

    pub output: SymTy<'db>,
}

This is fine but kinda annoying in its own way. I was wondering if we should write instead:

pub inputs: &'db Vec<SymLocalVariable<'db>>

but have that be treated specially such that when you create the struct, we "peel off" the &'db and replace it with Vec<SymLocalVariable<'db>>. The idea is that you are declaring the field type as it will be returned to you via an accessor, instead of the field type as it will be created -- and since we never support &'db field types, we can instead make it require an owned value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bikeshed 🚴‍♀️Debating API details and the likerfcActive discussion about a possible future feature

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions