Skip to content

Commit

Permalink
Compile ProcessImportedType in IDataContractSurrogate for unityaot
Browse files Browse the repository at this point in the history
The `IDataContractSurrogate` interface is part of the public API of
.NET 4.7.1. In has a method named `ProcessImportedType`, which was not
compiled into the unityaot profile.

The `ProcessImportedType` method uses types `CodeTypeDeclaration` and
`CodeCompileUnit` as parameters. Both of these types are pretty large,
and we don't want to compile them into the unityaot profile.

So in order to compile the `ProcessImportedType` method method, add
empty `CodeTypeDeclaration` and `CodeCompileUnit` types in unityaot (the
profile stubber will fill these in properly). This change allows the
unstripped unityaot profile work correctly with IL2CPP.

It is difficult for the profile stubber to handle this case, because
the code in `SurrogateProviderAdapter` is in a facade assembly, which
the profile stubber currently ignores.
  • Loading branch information
Josh Peterson committed May 20, 2019
1 parent a69e92f commit 0e66d19
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#if !NO_CODEDOM
#if !NO_CODEDOM || UNITY_AOT
using System.CodeDom;
#endif
using System.Collections.ObjectModel;
Expand Down Expand Up @@ -73,7 +73,7 @@ public Type GetReferencedTypeOnImport(string typeName, string typeNamespace, obj
throw NotImplemented.ByDesign;
}

#if !NO_CODEDOM
#if !NO_CODEDOM || UNITY_AOT
public CodeTypeDeclaration ProcessImportedType(CodeTypeDeclaration typeDeclaration, CodeCompileUnit compileUnit)
{
throw NotImplemented.ByDesign;
Expand Down
7 changes: 7 additions & 0 deletions mcs/class/System/System.CodeDom/CodeCompileUnit.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if UNITY_AOT

public class CodeCompileUnit
{
}

#endif
7 changes: 7 additions & 0 deletions mcs/class/System/System.CodeDom/CodeTypeDeclaration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#if UNITY_AOT

public class CodeTypeDeclaration
{
}

#endif
2 changes: 2 additions & 0 deletions mcs/class/System/unityaot_System.dll.sources
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
../System.Web/System.Web/HttpUtility.cs
../System.Web/System.Web.Util/Helpers.cs
../System.Web/System.Web.Util/HttpEncoder.cs
System.CodeDom/CodeCompileUnit.cs
System.CodeDom/CodeTypeDeclaration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public interface IDataContractSurrogate
object GetCustomDataToExport(Type clrType, Type dataContractType);
void GetKnownCustomDataTypes(Collection<Type> customDataTypes);
Type GetReferencedTypeOnImport(string typeName, string typeNamespace, object customData);
#if !NO_CODEDOM
#if !NO_CODEDOM || UNITY_AOT
CodeTypeDeclaration ProcessImportedType(CodeTypeDeclaration typeDeclaration, CodeCompileUnit compileUnit);
#endif
}
Expand Down Expand Up @@ -70,11 +70,11 @@ internal static Type GetReferencedTypeOnImport(IDataContractSurrogate surrogate,
return null;
return surrogate.GetReferencedTypeOnImport(typeName, typeNamespace, customData);
}
#if !NO_CODEDOM
#if !NO_CODEDOM || UNITY_AOT
internal static CodeTypeDeclaration ProcessImportedType(IDataContractSurrogate surrogate, CodeTypeDeclaration typeDeclaration, CodeCompileUnit compileUnit)
{
return surrogate.ProcessImportedType(typeDeclaration, compileUnit);
}
#endif
}
}
}

0 comments on commit 0e66d19

Please sign in to comment.