This PR Removes the need for ‘TypeContext’ from slicec-cs. It’s purely refactoring; there should be no changes to the logic. We used this enum for 2 purposes:
Purpose 1
cs_type_string would change the mapping of sequences and dictionaries based on this field.
Now, instead of 1 function which matches 3 possible TypeContexts, we have 3 separate functions:
cs_type_string(… TypeContext::Field) -> field_type_string cs_type_string(… TypeContext::IncomingParam) -> incoming_type_string cs_type_string(… TypeContext::OutgoingParam) -> outgoing_type_string
incoming_type_string and outgoing_type_string just delegate to field_type_string, for types other than seuqence or dictionary.
Purpose 2
Various parameter-code used it to tell whether we were on the dispatch side or not.
Now, we just pass a bool named is_dispatch which we already had in some functions anyways.
IncomingParam -> false, OutgoingParam -> true
Usually these matches matched TypeContext::Field to unreachable!.
This change lets us remove all these dead branches.
Additionally, in encoding.rs we used TypeContext to tell whether we generated for fields or parameters.
Instead of TypeContext, these functions now also take a bool: is_outgoing_paramOutgoingParam -> true and Field -> false.
Because this is all encoding code, we never encounter IncomingParam.
This PR Removes the need for ‘TypeContext’ from
slicec-cs
. It’s purely refactoring; there should be no changes to the logic. We used this enum for 2 purposes:Purpose 1
cs_type_string
would change the mapping of sequences and dictionaries based on this field. Now, instead of 1 function which matches 3 possible TypeContexts, we have 3 separate functions:cs_type_string(… TypeContext::Field) -> field_type_string
cs_type_string(… TypeContext::IncomingParam) -> incoming_type_string
cs_type_string(… TypeContext::OutgoingParam) -> outgoing_type_string
incoming_type_string
andoutgoing_type_string
just delegate tofield_type_string
, for types other than seuqence or dictionary.Purpose 2
Various parameter-code used it to tell whether we were on the dispatch side or not.
Now, we just pass a bool named
is_dispatch
which we already had in some functions anyways.IncomingParam -> false
,OutgoingParam -> true
Usually these matches matchedTypeContext::Field
tounreachable!
. This change lets us remove all these dead branches.Additionally, in
encoding.rs
we usedTypeContext
to tell whether we generated for fields or parameters. Instead of TypeContext, these functions now also take a bool:is_outgoing_param
OutgoingParam -> true
andField -> false
. Because this is all encoding code, we never encounterIncomingParam
.