Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The register-protocol optimization is not enabled when the interpreter is enabled #21782

Open
rolfbjarne opened this issue Dec 9, 2024 · 1 comment · May be fixed by #21786
Open

The register-protocol optimization is not enabled when the interpreter is enabled #21782

rolfbjarne opened this issue Dec 9, 2024 · 1 comment · May be fixed by #21786
Labels
regression The issue or pull request is a regression
Milestone

Comments

@rolfbjarne
Copy link
Member

See:

RegisterProtocols = (app.Registrar == RegistrarMode.Static || app.Registrar == RegistrarMode.ManagedStatic) && !app.UseInterpreter;

The register-protocol optimization is used to determine whether static interface constructors from the managed-static registrar are trimmed away or not:

bool ProcessProtocolInterfaceStaticConstructor (MethodDefinition method)
{
// The static cctor in protocol interfaces exists only to preserve the protocol's members, for inspection by the registrar(s).
// If we're registering protocols, then we don't need to preserve protocol members, because the registrar
// already knows everything about it => we can remove the static cctor.
if (!(method.DeclaringType.IsInterface && method.DeclaringType.IsInterface && method.IsStatic && method.IsConstructor && method.HasBody))
return false;
if (Optimizations.RegisterProtocols != true) {
Driver.Log (4, "Did not optimize static constructor in the protocol interface {0}: the 'register-protocols' optimization is disabled.", method.DeclaringType.FullName);
return false;
}

and this is required to get smaller apps + not reference frameworks unnecessarily (see #21002).

The current workaround is to add this to the csproj:

<PropertyGroup>
	<MtouchExtraArgs>--optimize:register-protocols</MtouchExtraArgs>
</PropertyGroup>
@rolfbjarne rolfbjarne added the regression The issue or pull request is a regression label Dec 9, 2024
@rolfbjarne rolfbjarne added this to the Future milestone Dec 9, 2024
@rolfbjarne
Copy link
Member Author

Potential fix:

The register-protocol optimization is required to be able to remove the static interface constructors (because otherwise the removed static constructors are needed at runtime), so the only other option is to apply the register-protocol optimization even when the interpreter is enabled. At the moment I can't see any reason why this shouldn't work.

rolfbjarne added a commit that referenced this issue Dec 9, 2024
…er is enabled. Fixes #21782.

In .NET we don't support loading assemblies at runtime (from outside the app
bundle), which means that we should also be able to enable the
register-protocol optimization when the interpreter is enabled (because we
know all the relevant assemblies at built time).

Fixes #21782.
rolfbjarne added a commit that referenced this issue Dec 20, 2024
…er is enabled. Fixes #21782.

In .NET we don't support loading assemblies at runtime (from outside the app
bundle), which means that we should also be able to enable the
register-protocol optimization when the interpreter is enabled (because we
know all the relevant assemblies at built time).

Fixes #21782.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression The issue or pull request is a regression
Projects
None yet
1 participant