Skip to main content

Module method_context

Module method_context 

Source
Expand description

Shared per-method context for trait-impl R wrapper generation.

Parallels r_class_formatter::MethodContext (used by the 6 inherent-impl class generators) so the 5 trait generators (env/s3/s4/s7/r6) build .Call() invocations and method preludes the same way instead of each hand-rolling its own version. See audit/2026-07-03-dogfooding-macros-codegen.md finding #1: the trait path previously shared nothing above DotCallBuilder, which caused a substring-corruption bug in the receiver-ptr extraction (S4/S7/R6) and a silent 3-of-6-step prelude omission (missing precondition_checks / match_arg_prelude) relative to inherent methods.

Re-exportsΒ§

use super::TraitMethod; πŸ”’
use super::trait_method_body_lines; πŸ”’
use crate::miniextendr_impl::ClassSystem; πŸ”’

StructsΒ§

TraitMethodContext πŸ”’
Pre-computed context for a trait method, mirroring MethodContext (r_class_formatter.rs) for inherent-impl methods. Holds the C wrapper name, R formals (with defaults), and .Call() argument string so all 5 trait generators build calls identically.

FunctionsΒ§

class_ref πŸ”’
How the trait wrappers of class_system name the class of type_ident: its R name, which a class = "..." rename on the type’s impl block sets, resolved when the wrappers are written (#2266, class_ref_for). Used for every R object the trait impl attaches to or wraps in (S3 method suffixes and registrations, the Class$Trait namespace, the S4 method signature, the S7 class object, a Self return). Rust-side names (C symbols, the S7 and S4 flat member names) and the @rdname page keep the Rust identifier.
s7_trait_member_access πŸ”’
How R code reaches an S7 trait static or const: attr(Type, "Trait")$member, also the topic alias of its documentation block. The trait namespace is an attribute of the class object, and Type$Trait$member does not reach it: an S7 class object is a function, and S7’s $ method stops on any S7 object that is not a list or an environment (β€œCan’t get S7 properties with $”).
trait_namespace_env πŸ”’
The trait namespace environment, Class$Trait, of Env, S3, R6 and vctrs classes; its members are trait_namespace_targets.
trait_namespace_env_var πŸ”’
The local environment variable S7 trait wrappers assign members into before attaching it to the class object via attr(). One owner so trait_namespace_target’s S7 arm and the generator’s new.env / attr() lines can’t drift apart.
trait_namespace_symbol πŸ”’
trait_namespace_target in R code position (the left of <-, the argument of attr()). A non-syntactic member (an operator r_name, #1475) is backtick-quoted: Type$Trait$[[, or Type_Trait_[[ `` for S4. Roxygen @name keeps the bare trait_namespace_target spelling.
trait_namespace_target πŸ”’
R-visible assignment target for a trait member (method or const) placed in the per-class trait namespace β€” the single owner of the namespace-shape policy the 5 generators previously hand-rolled independently (audit 2026-07-03-dogfooding-macros-codegen.md finding #1; #1141). member is the R-facing method/const name.