Skip to main content

class_param_binding_hash

Function class_param_binding_hash 

Source
pub fn class_param_binding_hash(class_sym: &Symbol<'_>) -> u64
Expand description

Task 2’s class_param_binding_hash (parallel to vj-codegen::mangle::param_binding_hash, which this cannot literally reuse: that function reads sym.parameters(), whose own doc/SAFETY comment — quoted in dedup.rs::template_key_of — says its count “is 0 for non-instances”, so it is populated only on an Instance-kind symbol, never a ClassType). A specialized class’s bound parameters are instead real Parameter/TypeParameter members of the class’s OWN scope (slang::ast::ParameterBuilder::createParam adds them there at specialization time, verified against vendor/source/ast/symbols/ClassSymbols.cpp), so this walks class_sym.members() directly and hashes each one’s (name(), parameter_value()) — parameter_value() is documented to print “its value or target type”, which is exactly what distinguishes a parameter int W = 8 binding from a parameter type T = int one without this function needing two different code paths for value vs. type parameters. A plain (non-generic) class has no Parameter/TypeParameter members at all, so this returns the same fixed empty-input hash for every one of them — harmless, since ClassTemplateKey.definition already tells two different plain classes apart on its own.

Deterministic (fixed-key DefaultHasher, not HashMap’s per-process- randomized RandomState) for the same reason template_key_of is: a candidate-bucketing filter must hash the same input to the same output across independent elaborate()-style runs.