[Pitch] Protocol Macros

Something I definitely thought about but don't have the best answer to. IIRC the declarations that are passed into the macro implementations are completely detached from their parent context, which definitely makes these macros near impossible to implement exactly as currently proposes.

Specifically, the Decodable, Encodable, and Sendable protocols all need information about their stored variables to check that all stored variables on the type conform to the protocol as well. This information is entirely missing with the existing way in which macros are invoked.

In order to "recreate" these protocols using this proposal we'd need some kind of API that allows macro implementations to looks up information about a given type. For example:

struct TypeSyntaxInfo {
    struct TypeInheritanceInfo {
        let type: TypeSyntax
        let genericWhereClause: GenericWhereClauseSyntax?
        ...
    }

    var inheritances: [TypeInheritanceInfo]
    ...
}

extension MacroExpansionContext {
    func information(for type: TypeSyntax) -> TypeSyntaxInfo?
}

Or perhaps something akin to what's proposed here. In this way we would be able to get the inheritance information for each of the stored variables on the conforming type.

I haven't looked too deep into the exact point where macros are invoked by the compiler so it's entirely possible that compiler wouldn't have gather enough information to be able to supply the macro with this additional context, but this piece feels like it should be its own pitch given that querying the macro environment for additional information about provided types has much broader utility than just to this specific use case.