Skip to content

Conversation

@stakx
Copy link
Member

@stakx stakx commented Jan 24, 2026

This PR is one of the last preliminary code refactoring towards #663. Its goal is to pull together all logic related to the copying of argument & return values into / out of IInvocation done by MethodWithInvocationGenerator and InvocationTypeGenerator.

In the case of MethodWithInvocationGenerator, that logic is currently spread out over three classes: MethodWithInvocationGenerator itself, plus ReferencesToObjectArrayExpression and GeneratorUtil (which are both classes used exclusively, and only once each, by the former). This PR concentrates all of that logic in a single helper type, MethodWithInvocationGenerator.ArgumentsMarshaller.

In the case of InvocationTypeGenerator, the logic is already completely in that class. This PR refactors it into a second helper type InvocationTypeGenerator.ArgumentsMarshaller for consistency.

The terms "copy in", "copy out", and "marshalling" are borrowed from remoting, since DynamicProxy creates something quite like a remoting boundary around each intercepted method. See also ECMA-335 I.12.5 and I.8.2.1.1 for more on these terms.

stakx added 6 commits January 23, 2026 18:36
... for `GeneratorUtil.CopyOutAndRefParameters`, so that this method
does not need to dig the arguments array out of the invocation instance.
... by composing simpler node types in `CopyIn` instead. While this
requires more allocations, it highlights the similarities between `Copy-
In` and `CopyOut`, resulting in a cleaner interface.

The newly introduced node type `ConvertArgumentToObjectExpression` may
seem redundant right now (given the more general `ConvertExpression`),
but it will allow us later to introduce conversions that are specific to
copying arguments into & out of `IInvocation`.
@stakx stakx added this to the v6.0.0 milestone Jan 24, 2026
@stakx stakx self-assigned this Jan 24, 2026
stakx added 2 commits January 24, 2026 13:04
... as the counterpart to `ConvertArgumentToObjectExpression`. For now,
this is just a simplified version of `ConvertExpression`, but it gives
us a place to add arguments-specific marshalling logic later on.
@stakx stakx force-pushed the arguments-marshaller branch from 8f9f7ac to eed779d Compare January 24, 2026 12:08
stakx added 6 commits January 24, 2026 19:55
Using a sparse dictionary instead of a non-sparse plain array for track-
ing mutable by-ref parameters is likely only more efficient for methods
with a large number of parameters.

While we're at it, prevent unnecessary allocations for parameter-less
methods.
@stakx stakx changed the title Introduce ArgumentsMarshaller helper for MethodWithInvocationGenerator Introduce ArgumentsMarshaller helpers for MethodWithInvocationGenerator and InvocationTypeGenerator Jan 24, 2026
@stakx stakx merged commit 02cce94 into castleproject:master Jan 24, 2026
4 checks passed
@stakx stakx deleted the arguments-marshaller branch January 24, 2026 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant