I'm working on writing a compiler and one feature of this compiler is that it automatically generates GetHashCode(), Equals(object), and Equals({this value type}) methods for value types. Right now the Equals({this value type}) implementation basically generates il equivalent to the il generated by this c#:
public bool Equals(ThisType o)
{
return Field1 == o.Field1 && Field2 == o.Field2 && Field3 == o.Field3;//etc
}
My compiler pushes all of these objects on to the stack and then begins comparing and "and"ing them together. This causes the method's .maxstack to become large very quickly. Is there a penalty for this? If so, at what point should I start pushing values into locals?
Thanks.