Skip to content

[uikit] Use a code-first approach to app-level debugging options#13747

Closed
spouliot wants to merge 1 commit intodotnet:mainfrom
spouliot:app-properties
Closed

[uikit] Use a code-first approach to app-level debugging options#13747
spouliot wants to merge 1 commit intodotnet:mainfrom
spouliot:app-properties

Conversation

@spouliot
Copy link
Copy Markdown
Contributor

Change CheckForIllegalCrossThreadCalls and CheckForEventAndDelegateMismatches
from fields to properties.

This has two main benefits:

  1. Setting them inside code (and part of the templates) makes the
    features easier to discover and easier to tweak the conditions to enable
    or disable them. No extra arguments hidden in project files :)

  2. This allows the linker to remove the properties (when disabled) since
    they are not set from the static constructor (like the current fields)

Note: this is a draft, what's missing are

  1. update all templates (ideally including MAUI ones in a different PR)

  2. update the linker code to detect the properties (if never set) to
    remove the feature. No more settings would be needed

Change `CheckForIllegalCrossThreadCalls` and `CheckForEventAndDelegateMismatches`
from fields to properties.

This has two main benefits:

1. Setting them inside code (and part of the templates) makes the
features easier to discover and easier to tweak the conditions to enable
or disable them. No extra arguments hidden in project files :)

2. This allows the linker to remove the properties (when disabled) since
they are not set from the static constructor (like the current fields)

Note: this is a draft, what's missing are

1. update all templates (ideally including MAUI ones in a different PR)

2. update the linker code to detect the properties (if never set) to
remove the feature. No more settings would be needed
@@ -1,5 +1,12 @@
using iOSApp1;

#if DEBUG
Copy link
Copy Markdown
Member

@rolfbjarne rolfbjarne Jan 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can skip updating templates if:

  • We have a private check_for... field we set when we generate our unmanaged main function (or somehow set this value during build time) - and set it to true for debug builds and false otherwise.
  • In the linker detect if the public CheckFor... setter has been preserved. If not, we can treat the getter as a constant value (because we'll know what we set the private field to).
  • Then we'll run the dead code eliminator in the linker and remove the corresponding code paths.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, removing the fields (or properties) is easy (many ways) at least if they are not set from the .cctor. But the savings(of two fields) are very minimal since the rest of the logic is already removed. It's mostly a nice side effect :-)

However this keeps the features (and logic) into the magic/unseen land, which is bad for feature discovery. Even when documented a feature is only useful if you know about it (and for .net it won't be the old mtouch additional arguments to override them). Having the templates makes them obvious, at least more than finding the new (was it added) correct msbuild syntax.

@rolfbjarne
Copy link
Copy Markdown
Member

It's too late to get this change in .NET, so I've created an issue for it for the next time we can break the API: #15428

@rolfbjarne rolfbjarne closed this Jul 8, 2022
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.

2 participants