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

Reflection free code gen #12960

Merged
merged 24 commits into from
Aug 22, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge main
dsyme committed Jul 11, 2022
commit 3138bbb8d2268fe44923e5268ee032b41ca3bf1b
48 changes: 27 additions & 21 deletions src/Compiler/CodeGen/IlxGen.fs
Original file line number Diff line number Diff line change
@@ -288,11 +288,11 @@ type IlxGenOptions =
/// storage, even though 'it' is not logically mutable
isInteractiveItExpr: bool

/// Suppress ToString emit
useReflectionFreeCodeGen: bool
/// Suppress ToString emit
useReflectionFreeCodeGen: bool

/// Whenever possible, use callvirt instead of call
alwaysCallVirt: bool
/// Whenever possible, use callvirt instead of call
alwaysCallVirt: bool
}

/// Compilation environment for compiling a fragment of an assembly
@@ -10322,15 +10322,8 @@ and GenToStringMethod cenv eenv ilThisTy m =

/// Generate a ToString/get_Message method that calls 'sprintf "%A"'
and GenPrintingMethod cenv eenv methName ilThisTy m =
let g = cenv.g
[ if not g.useReflectionFreeCodeGen then
match (eenv.valsInScope.TryFind g.sprintf_vref.Deref,
eenv.valsInScope.TryFind g.new_format_vref.Deref) with
| Some(Lazy(Method(_, _, sprintfMethSpec, _, _, _, _, _, _, _, _, _))), Some(Lazy(Method(_, _, newFormatMethSpec, _, _, _, _, _, _, _, _, _))) ->
// The type returned by the 'sprintf' call
let funcTy = EraseClosures.mkILFuncTy cenv.ilxPubCloEnv ilThisTy g.ilg.typ_String

[
let g = cenv.g
[ if not g.useReflectionFreeCodeGen then
match (eenv.valsInScope.TryFind g.sprintf_vref.Deref, eenv.valsInScope.TryFind g.new_format_vref.Deref) with
| Some (Lazy (Method (_, _, sprintfMethSpec, _, _, _, _, _, _, _, _, _))),
Some (Lazy (Method (_, _, newFormatMethSpec, _, _, _, _, _, _, _, _, _))) ->
@@ -10573,14 +10566,27 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon: Tycon) =

let reprAccess = ComputeMemberAccess hiddenRepr

// DebugDisplayAttribute gets copied to the subtypes generated as part of DU compilation
let debugDisplayAttrs, normalAttrs = tycon.Attribs |> List.partition (IsMatchingFSharpAttribute g g.attrib_DebuggerDisplayAttribute)
let securityAttrs, normalAttrs = normalAttrs |> List.partition (fun a -> IsSecurityAttribute g cenv.amap cenv.casApplied a m)
let generateDebugDisplayAttribute =
not g.useReflectionFreeCodeGen &&
not g.compilingFSharpCore &&
tycon.IsUnionTycon &&
isNil debugDisplayAttrs
// DebugDisplayAttribute gets copied to the subtypes generated as part of DU compilation
let debugDisplayAttrs, normalAttrs = tycon.Attribs |> List.partition (IsMatchingFSharpAttribute g g.attrib_DebuggerDisplayAttribute)
let securityAttrs, normalAttrs = normalAttrs |> List.partition (fun a -> IsSecurityAttribute g cenv.amap cenv.casApplied a m)
let generateDebugDisplayAttribute =
not g.useReflectionFreeCodeGen &&
not g.compilingFSharpCore &&
tycon.IsUnionTycon &&
isNil debugDisplayAttrs

let ilTypeDefKind =
match tyconRepr with
| TFSharpObjectRepr o ->
match o.fsobjmodel_kind with
| TFSharpClass -> ILTypeDefKind.Class
| TFSharpStruct -> ILTypeDefKind.ValueType
| TFSharpInterface -> ILTypeDefKind.Interface
| TFSharpEnum -> ILTypeDefKind.Enum
| TFSharpDelegate _ -> ILTypeDefKind.Delegate
| TFSharpRecdRepr _
| TFSharpUnionRepr _ when tycon.IsStructOrEnumTycon -> ILTypeDefKind.ValueType
| _ -> ILTypeDefKind.Class

let requiresExtraField =
let isEmptyStruct =
9 changes: 5 additions & 4 deletions src/FSharp.Build/FSharp.Build.fsproj
Original file line number Diff line number Diff line change
@@ -4,14 +4,15 @@

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TargetFramework Condition="'$(Configuration)' != 'Proto'">netstandard2.0</TargetFramework>
<TargetFrameworks Condition="'$(Configuration)' == 'Proto'">netstandard2.0</TargetFrameworks>
<AssemblyName>FSharp.Build</AssemblyName>
<NoWarn>$(NoWarn);75</NoWarn> <!-- InternalCommandLineOption -->
<AllowCrossTargeting>true</AllowCrossTargeting>
<DefineConstants>$(DefineConstants);LOCALIZATION_FSBUILD</DefineConstants>
<NoWarn>NU1701;FS0075</NoWarn>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<LangVersion>6.0</LangVersion> <!-- FSharp.Build may run in Visual Studio with older FSharp.Cores so don't use unshipped features -->
<LangVersion>5.0</LangVersion> <!-- FSharp.Build may run in Visual Studio with older FSharp.Cores so don't use unshipped features -->
</PropertyGroup>

<ItemGroup>
@@ -57,10 +58,10 @@
The FSharp.Build built here may be loaded directly into a shipped Visual Studio, to that end, we cannot
rely on new API's just being added to FSharp.Core.
-->
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreShippedPackageVersionValue)" IncludeAssets="compile" ExcludeAssets="all" PrivateAssets="all" />
<PackageReference Include="FSharp.Core" Version="$(FSharpCoreShippedPackageVersionValue)" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' != 'Proto'">
<ItemGroup Condition="'$(Configuration)' != 'Proto'">
<ProjectReference Include="$(MSBuildThisFileDirectory)..\FSharp.Core\FSharp.Core.fsproj" />
</ItemGroup>

You are viewing a condensed version of this merge commit. You can view the full changes here.