Skip to content

Commit

Permalink
Merge pull request #48 from vasily-kirichenko/update-ProvidedTypes-fi…
Browse files Browse the repository at this point in the history
…x-memory-leak

update ProvidedTypes form FSharp.Data
  • Loading branch information
vasily-kirichenko committed Dec 12, 2014
2 parents adfc9cf + 5809fe1 commit f81cb93
Show file tree
Hide file tree
Showing 8 changed files with 470 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/FSharp.Configuration/AppSettingsProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module FSharp.Configuration.AppSettingsTypeProvider
#nowarn "57"

open FSharp.Configuration.Helper
open Samples.FSharp.ProvidedTypes
open ProviderImplementation.ProvidedTypes
open System
open System.Configuration
open System.Collections.Generic
Expand Down
26 changes: 13 additions & 13 deletions src/FSharp.Configuration/ConfigTypeProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

open FSharp.Configuration.Helper
open Microsoft.FSharp.Core.CompilerServices
open Samples.FSharp.ProvidedTypes
open System
open ProviderImplementation.ProvidedTypes

[<TypeProvider>]
type public FSharpConfigurationProvider(cfg: TypeProviderConfig) as this =
inherit TypeProviderForNamespaces()
let context = new Context(this, cfg)
do this.AddNamespace (
rootNamespace,
[ AppSettingsTypeProvider.typedAppSettings context
ResXProvider.typedResources context
YamlConfigTypeProvider.typedYamlConfig context
IniFileProvider.typedIniFile context ])
interface IDisposable with
member __.Dispose() = dispose context
type FSharpConfigurationProvider(cfg: TypeProviderConfig) as this =
class
inherit TypeProviderForNamespaces()
let context = new Context(this, cfg)
do this.AddNamespace (
rootNamespace,
[ AppSettingsTypeProvider.typedAppSettings context
ResXProvider.typedResources context
YamlConfigTypeProvider.typedYamlConfig context
IniFileProvider.typedIniFile context ])
do this.Disposing.Add (fun _ -> dispose context)
end

[<TypeProviderAssembly>]
do ()
2 changes: 1 addition & 1 deletion src/FSharp.Configuration/IniFileProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module Parser =
// | Setting (setting, s) -> printfn "Success %A, %A" setting s
// | x -> printfn "Error: %A" x

open Samples.FSharp.ProvidedTypes
open ProviderImplementation.ProvidedTypes
open System.Collections.Generic
open System
open System.Globalization
Expand Down
417 changes: 371 additions & 46 deletions src/FSharp.Configuration/ProvidedTypes.fs

Large diffs are not rendered by default.

100 changes: 81 additions & 19 deletions src/FSharp.Configuration/ProvidedTypes.fsi
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
// Copyright (c) Microsoft Corporation 2005-2012.
// Based on code developed for the F# 3.0 Beta release of March 2012,
// Copyright (c) Microsoft Corporation 2005-2012.
// This sample code is provided "as is" without warranty of any kind.
// We disclaim all warranties, either express or implied, including the
// warranties of merchantability and fitness for a particular purpose.

// This file contains a set of helper types and methods for providing types in an implementation
// of ITypeProvider.
//
// This code is a sample for use in conjunction with the F# 3.0 Developer Preview release of September 2011.

namespace Samples.FSharp.ProvidedTypes
// This code has been modified and is appropriate for use in conjunction with the F# 3.0, F# 3.1, and F# 3.1.1 releases


namespace ProviderImplementation.ProvidedTypes

open System
open System.Reflection
open System.Linq.Expressions
open Microsoft.FSharp.Core.CompilerServices

/// Represents an erased provided parameter
type internal ProvidedParameter =
type ProvidedParameter =
inherit System.Reflection.ParameterInfo
new : parameterName: string * parameterType: Type * ?isOut:bool * ?optionalValue:obj -> ProvidedParameter
member IsParamArray : bool with get,set

/// Represents an erased provided constructor.
type internal ProvidedConstructor =
type ProvidedConstructor =
inherit System.Reflection.ConstructorInfo

/// Create a new provided constructor. It is not initially associated with any specific provided type definition.
Expand All @@ -43,20 +45,23 @@ type internal ProvidedConstructor =
/// Set the quotation used to compute the implementation of invocations of this constructor.
member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set

/// FSharp.Data addition: this method is used by Debug.fs
member internal GetInvokeCodeInternal : bool -> (Quotations.Expr [] -> Quotations.Expr)

/// Set the target and arguments of the base constructor call. Only used for generated types.
member BaseConstructorCall : (Quotations.Expr list -> ConstructorInfo * Quotations.Expr list) with set

/// Set a flag indicating that the constructor acts like an F# implicit constructor, so the
/// parameters of the constructor become fields and can be accessed using Expr.GlobalVar with the
/// same name.
member IsImplicitCtor : bool with set
member IsImplicitCtor : bool with get,set

/// Add definition location information to the provided constructor.
member AddDefinitionLocation : line:int * column:int * filePath:string -> unit
member IsTypeInitializer : bool with get,set

type internal ProvidedMethod =
type ProvidedMethod =
inherit System.Reflection.MethodInfo

/// Create a new provided method. It is not initially associated with any specific provided type definition.
Expand Down Expand Up @@ -86,14 +91,19 @@ type internal ProvidedMethod =
/// Set the quotation used to compute the implementation of invocations of this method.
member InvokeCode : (Quotations.Expr list -> Quotations.Expr) with set

/// FSharp.Data addition: this method is used by Debug.fs
member internal GetInvokeCodeInternal : bool -> (Quotations.Expr [] -> Quotations.Expr)

/// Add definition location information to the provided type definition.
member AddDefinitionLocation : line:int * column:int * filePath:string -> unit

/// Add a custom attribute to the provided method definition.
member AddCustomAttribute : CustomAttributeData -> unit



/// Represents an erased provided property.
type internal ProvidedProperty =
type ProvidedProperty =
inherit System.Reflection.PropertyInfo

/// Create a new provided type. It is not initially associated with any specific provided type definition.
Expand All @@ -113,6 +123,7 @@ type internal ProvidedProperty =
member AddXmlDocComputed : xmlDocFunction: (unit -> string) -> unit
/// Get or set a flag indicating if the property is static.
/// FSharp.Data addition: the getter is used by Debug.fs
member IsStatic : bool with get,set

/// Set the quotation used to compute the implementation of gets of this property.
Expand All @@ -124,8 +135,11 @@ type internal ProvidedProperty =
/// Add definition location information to the provided type definition.
member AddDefinitionLocation : line:int * column:int * filePath:string -> unit

/// Add a custom attribute to the provided property definition.
member AddCustomAttribute : CustomAttributeData -> unit

/// Represents an erased provided property.
type internal ProvidedEvent =
type ProvidedEvent =
inherit System.Reflection.EventInfo

/// Create a new provided type. It is not initially associated with any specific provided type definition.
Expand Down Expand Up @@ -154,7 +168,7 @@ type internal ProvidedEvent =
member AddDefinitionLocation : line:int * column:int * filePath:string -> unit

/// Represents an erased provided field.
type internal ProvidedLiteralField =
type ProvidedLiteralField =
inherit System.Reflection.FieldInfo

/// Create a new provided field. It is not initially associated with any specific provided type definition.
Expand All @@ -177,7 +191,7 @@ type internal ProvidedLiteralField =
member AddDefinitionLocation : line:int * column:int * filePath:string -> unit

/// Represents an erased provided field.
type internal ProvidedField =
type ProvidedField =
inherit System.Reflection.FieldInfo

/// Create a new provided field. It is not initially associated with any specific provided type definition.
Expand All @@ -201,17 +215,42 @@ type internal ProvidedField =

member SetFieldAttributes : attributes : FieldAttributes -> unit

/// FSharp.Data addition: SymbolKind is used by AssemblyReplacer.fs
/// Represents the type constructor in a provided symbol type.
[<NoComparison>]
type SymbolKind =
| SDArray
| Array of int
| Pointer
| ByRef
| Generic of System.Type
| FSharpTypeAbbreviation of (System.Reflection.Assembly * string * string[])

/// FSharp.Data addition: ProvidedSymbolType is used by AssemblyReplacer.fs
/// Represents an array or other symbolic type involving a provided type as the argument.
/// See the type provider spec for the methods that must be implemented.
/// Note that the type provider specification does not require us to implement pointer-equality for provided types.
[<Class>]
type ProvidedSymbolType =
inherit System.Type

/// Returns the kind of this symbolic type
member Kind : SymbolKind
/// Return the provided types used as arguments of this symbolic type
member Args : list<System.Type>


/// Provides symbolic provided types
[<Class>]
type internal ProvidedTypeBuilder =
type ProvidedTypeBuilder =
/// Like typ.MakeGenericType, but will also work with unit-annotated types
static member MakeGenericType: genericTypeDefinition: System.Type * genericArguments: System.Type list -> System.Type
/// Like methodInfo.MakeGenericMethod, but will also work with unit-annotated types and provided types
static member MakeGenericMethod: genericMethodDefinition: System.Reflection.MethodInfo * genericArguments: System.Type list -> MethodInfo

/// Helps create erased provided unit-of-measure annotations.
[<Class>]
type internal ProvidedMeasureBuilder =
type ProvidedMeasureBuilder =

/// The ProvidedMeasureBuilder for building measures.
static member Default : ProvidedMeasureBuilder
Expand All @@ -237,7 +276,7 @@ type internal ProvidedMeasureBuilder =


/// Represents a provided static parameter.
type internal ProvidedStaticParameter =
type ProvidedStaticParameter =
inherit System.Reflection.ParameterInfo
new : parameterName: string * parameterType:Type * ?parameterDefaultValue:obj -> ProvidedStaticParameter

Expand All @@ -248,7 +287,7 @@ type internal ProvidedStaticParameter =
member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit

/// Represents a provided type definition.
type internal ProvidedTypeDefinition =
type ProvidedTypeDefinition =
inherit System.Type

/// Create a new provided type definition in a namespace.
Expand Down Expand Up @@ -278,6 +317,9 @@ type internal ProvidedTypeDefinition =
/// Set the base type to a lazily evaluated value
member SetBaseTypeDelayed : Lazy<Type option> -> unit

/// Set underlying type for generated enums
member SetEnumUnderlyingType : Type -> unit

/// Add XML documentation information to this provided constructor, where the computation of the documentation is delayed until necessary.
/// The documentation is only computed once.
member AddXmlDocDelayed : xmlDocFunction: (unit -> string) -> unit
Expand Down Expand Up @@ -322,8 +364,20 @@ type internal ProvidedTypeDefinition =
[<Experimental("SuppressRelocation is a workaround and likely to be removed")>]
member SuppressRelocation : bool with get,set

/// FSharp.Data addition: this method is used by Debug.fs
member MakeParametricType : name:string * args:obj[] -> ProvidedTypeDefinition

/// Add a custom attribute to the provided type definition.
member AddCustomAttribute : CustomAttributeData -> unit

/// FSharp.Data addition: this method is used by Debug.fs and QuotationBuilder.fs
/// Emulate the F# type provider type erasure mechanism to get the
/// actual (erased) type. We erase ProvidedTypes to their base type
/// and we erase array of provided type to array of base type. In the
/// case of generics all the generic type arguments are also recursively
/// replaced with the erased-to types
static member EraseType : t:Type -> Type

/// A provided generated assembly
type ProvidedAssembly =
new : assemblyFileName:string -> ProvidedAssembly
Expand Down Expand Up @@ -351,13 +405,17 @@ type ProvidedAssembly =
type TypeProviderForNamespaces =

/// Initializes a type provider to provide the types in the given namespace.
internal new : namespaceName:string * types: ProvidedTypeDefinition list -> TypeProviderForNamespaces
new : namespaceName:string * types: ProvidedTypeDefinition list -> TypeProviderForNamespaces

/// Initializes a type provider
internal new : unit -> TypeProviderForNamespaces
new : unit -> TypeProviderForNamespaces

/// Add a namespace of provided types.
member internal AddNamespace : namespaceName:string * types: ProvidedTypeDefinition list -> unit
member AddNamespace : namespaceName:string * types: ProvidedTypeDefinition list -> unit

/// FSharp.Data addition: this method is used by Debug.fs
/// Get all namespace with their provided types.
member Namespaces : (string * ProvidedTypeDefinition list) seq with get

/// Invalidate the information provided by the provider
member Invalidate : unit -> unit
Expand All @@ -372,6 +430,10 @@ type TypeProviderForNamespaces =
member RegisterProbingFolder : folder : string -> unit
/// Registers location of RuntimeAssembly (from TypeProviderConfig) as probing folder
member RegisterRuntimeAssemblyLocationAsProbingFolder : cfg : Core.CompilerServices.TypeProviderConfig -> unit

#endif

[<CLIEvent>]
member Disposing : IEvent<EventHandler,EventArgs>

interface ITypeProvider
2 changes: 1 addition & 1 deletion src/FSharp.Configuration/ResXProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
open System
open System.IO
open System.Reflection
open Samples.FSharp.ProvidedTypes
open ProviderImplementation.ProvidedTypes
open FSharp.Configuration.Helper
open System.Resources
open System.ComponentModel.Design
Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Configuration/TypeProviders.Helper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module internal FSharp.Configuration.Helper

open System
open System.IO
open Samples.FSharp.ProvidedTypes
open ProviderImplementation.ProvidedTypes
open Microsoft.FSharp.Core.CompilerServices
open Microsoft.FSharp.Core.Printf

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Configuration/YamlConfigProvider.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#nowarn "57"

open System.Reflection
open Samples.FSharp.ProvidedTypes
open ProviderImplementation.ProvidedTypes
open System
open System.IO
open SharpYaml.Serialization
Expand Down

0 comments on commit f81cb93

Please sign in to comment.