Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Make DateTimeFormatInfo and DateTimeParse more linker friendly. #298

Merged
merged 1 commit into from
Jun 6, 2019

Conversation

baulig
Copy link

@baulig baulig commented Jun 5, 2019

The goal is to allow the linker to remove some of the globalization code
that is conditional to GlobalizationMode.Invariant.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies. One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

In this particular case, we do not want to access the JapaneseCalendar and
TaiwanCalendar types from methods that could not (currently) be linked out.

The DateTimeFormatInfo.PopulateSpecialTokenHashTable() method does not
explicitly reference any of those, but it is quite big so we benefit from
having the non-invariant pieces in a separate method which can then be removed.

The goal is to allow the linker to remove some of the globalization code
that is conditional to `GlobalizationMode.Invariant`.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies.  One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

In this particular case, we do not want to access the `JapaneseCalendar` and
`TaiwanCalendar` types from methods that could not (currently) be linked out.

The `DateTimeFormatInfo.PopulateSpecialTokenHashTable()` method does not
explicitly reference any of those, but it is quite big so we benefit from
having the non-invariant pieces in a separate method which can then be removed.
@baulig baulig self-assigned this Jun 5, 2019
baulig pushed a commit to baulig/mono that referenced this pull request Jun 5, 2019
See mono/corefx#298 for a description of the
technique that we're using here to make it more linker friendly.
baulig pushed a commit to baulig/linker that referenced this pull request Jun 5, 2019
This requires mono/corefx#298 and
mono/mono#14825.

We are using the same techinique as previously employed in
dotnet#590 to dynamically remove
the `System.Reflection.Emit` code.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies.  One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

After this has been done in the BCL, we need to explicitly tell the linker
to turn those method bodies into stubs when `--exclude-feature globalization`.

Ideally, we would want to use `MethodAction.ConvertToStub` instead of `ConvertToThrow`
here, but we'd have to extend the code rewriter first to support methods with
arbitrary return types and parameters.
marek-safar pushed a commit to dotnet/linker that referenced this pull request Jun 6, 2019
This requires mono/corefx#298 and
mono/mono#14825.

We are using the same techinique as previously employed in
#590 to dynamically remove
the `System.Reflection.Emit` code.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies.  One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

After this has been done in the BCL, we need to explicitly tell the linker
to turn those method bodies into stubs when `--exclude-feature globalization`.

Ideally, we would want to use `MethodAction.ConvertToStub` instead of `ConvertToThrow`
here, but we'd have to extend the code rewriter first to support methods with
arbitrary return types and parameters.
marek-safar pushed a commit to mono/mono that referenced this pull request Jun 6, 2019
See mono/corefx#298 for a description of the
technique that we're using here to make it more linker friendly.
@marek-safar marek-safar merged commit d855425 into mono:master Jun 6, 2019
@baulig baulig deleted the work-japanese-calendar branch June 6, 2019 17:44
baulig pushed a commit to baulig/mono that referenced this pull request Jun 6, 2019
baulig pushed a commit to baulig/linker that referenced this pull request Jun 6, 2019
This requires mono/corefx#298 and
mono/mono#14825.

We are using the same techinique as previously employed in
dotnet#590 to dynamically remove
the `System.Reflection.Emit` code.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies.  One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

After this has been done in the BCL, we need to explicitly tell the linker
to turn those method bodies into stubs when `--exclude-feature globalization`.

Ideally, we would want to use `MethodAction.ConvertToStub` instead of `ConvertToThrow`
here, but we'd have to extend the code rewriter first to support methods with
arbitrary return types and parameters.

(cherry picked from commit 3eca6ad)
baulig pushed a commit to mono/mono that referenced this pull request Jun 7, 2019
tkapin pushed a commit to tkapin/runtime that referenced this pull request Jan 31, 2023
This requires mono/corefx#298 and
mono/mono#14825.

We are using the same techinique as previously employed in
dotnet/linker#590 to dynamically remove
the `System.Reflection.Emit` code.

Since the linker does not currently support dead code elimination, it cannot
break down any conditionals inside method bodies.  One trick that we use to
work around this is to move those conditional pieces into separate methods;
then we can give the linker a list of those methods and tell it to replace
their bodies with exceptions.

After this has been done in the BCL, we need to explicitly tell the linker
to turn those method bodies into stubs when `--exclude-feature globalization`.

Ideally, we would want to use `MethodAction.ConvertToStub` instead of `ConvertToThrow`
here, but we'd have to extend the code rewriter first to support methods with
arbitrary return types and parameters.


Commit migrated from dotnet/linker@3eca6ad
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants