-
Notifications
You must be signed in to change notification settings - Fork 128
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
Add option to the XML input to rewrite methods to throw / stubs. #555
Conversation
When using `feature=<feature>` to conditionalize a `<method>`, there is now a new `action=<action>` attribute (which currently allows `throw` and `stub`). You can use it like this: <type fullname="System.RuntimeType"> <method name="MakeTypeBuilderInstantiation" action="throw" feature="sre" /> </type> Then you run the linker with `--exclude-feature sre` and that method will be rewritten into a throw. This is intended for scenarios where that method would otherwise bring in types that we want to exclude.
Turns out that we can actually do without this, by using constants. |
I am not sure this is the best approach as it does not compose well. From what I can see you'd like to force explicit removal of some block of code. By coincidence, the method already exists in the descriptor but what if does not? You'd need to add it there which means it would be always persisted which is not what you actually want. |
The problem that I'm trying to solve is that some method must be forcibly turned into a stub:
This is the last remaining "link" to the So the idea is that when you pass Do you have any suggestions how to best achieve that? |
Right, good point. In this particular example, adding that method to the preserve list does not matter because it is always referenced from already always preserved code. But it means that my approach won't work in the general sense, so having it in XML is probably not such a good idea. I'm going to close this again, but let's discuss alternative solutions for this. |
FYI, I added something very similar to this in our UnityLinker a year or so ago. It does almost what you want. Here are some examples
We never really ended up using this ability. If you wanted to take this approach and tweak it it wouldn't cause us any issues. It sounds like you'd want to add a If you are interested let me know and I can move our code & tests to support this out of UnityLinker and into monolinker and toss it on a branch for you. |
@mrvoorhe That's really awesome - that you so much for sharing this with me! I'm very interested in a solution that does not cause any problems for you guys and if you already have this in your code and tests for it, then I think it would be awesome to get this into monolinker, so we can build on top of it. However, I would need some way of making this feature conditional - the method should only be stubbed if the Could we do something like the following with it:
Ideally, the |
When the linker is ran with It sounds like what you want to do is a little different. You want to process the xml element only if the feature is excluded. It feels like we might want a new xml attribute. Something like
Not the best name in the world but hopefully it gets the idea across. Can you pin down an XML syntax for this and get buy in from @marek-safar ? It will be a little bit of work for me to move our code to a branch. I'm happy to do it, but I'd like to make sure there is buy in on the general approach before I go through it. |
When using
feature=<feature>
to conditionalize a<method>
, there is now a newaction=<action>
attribute (which currently allowsthrow
andstub
).You can use it like this:
Then you run the linker with
--exclude-feature sre
and that method will be rewritteninto a throw. This is intended for scenarios where that method would otherwise bring
in types that we want to exclude.