Skip to content

Commit

Permalink
Simplified, more robust resolution of type references in quotations
Browse files Browse the repository at this point in the history
commit d18cc8e011b81cbf3256ec42da74015aff67c3ee
Author: latkin <latkin@microsoft.com>
Date:   Fri Jan 16 15:37:44 2015 -0800

    Reverting test tag changes

commit b3e2b3078bcd23b4373ed51c2471c027d4f2320c
Merge: 481890d d2c5d18
Author: latkin <latkin@microsoft.com>
Date:   Fri Jan 16 14:57:16 2015 -0800

    Merge branch 'quotation-type-refs' of https://git01.codeplex.com/forks/dsyme/cleanup into quotformat

commit d2c5d185f2e193e0515483476cf60e14bd261c53
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Jan 12 19:11:31 2015 +0000

    fix problem with profile47, moving CAs to assembly instead of module

commit d1d4f76a8499005d7061de9180750db5675be7d5
Merge: dea089f 51d7b62
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Jan 12 17:32:41 2015 +0000

    Merge branch 'fsharp4' of https://git01.codeplex.com/visualfsharp into quotation-type-refs

commit dea089f2eed6a339ab130e321cf30de37a117904
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Dec 8 18:38:23 2014 +0000

    get profile 78 compiling

commit b55f6632e5ff3b3b682525bad8cf8ec722820cfb
Merge: 4c3e6b8 e8d7469
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Dec 8 18:21:10 2014 +0000

    Merge branch 'fsharp4' of https://git01.codeplex.com/visualfsharp into quotation-type-refs

commit 4c3e6b800f85ef060d50c902e158cf78922fbc03
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Dec 8 18:06:15 2014 +0000

    updates to keep error for F# 2.0+ quotations static linking

commit 50c3d6530fb4230ccd80d85c8d1a694908c18d14
Author: Don Syme <dsyme@microsoft.com>
Date:   Mon Oct 13 17:55:30 2014 +0100

    updates from code review

commit bc8671b27f9e895e35157efeba646d7065c074ac
Author: Don Syme <dsyme@microsoft.com>
Date:   Thu Oct 9 12:46:23 2014 +0100

    minor renaming for clarification

commit 9dfa9c8fda186b908663e99c889de81f3cb6f90e
Author: Don Syme <dsyme@microsoft.com>
Date:   Thu Oct 9 12:40:21 2014 +0100

    add tests for static linking libraries using quotations, make resource names unique

commit 33ce7699c2ba8a6158b60a337a296bf60276ede4
Author: Don Syme <dsyme@microsoft.com>
Date:   Wed Oct 8 18:49:10 2014 +0100

    Simplified, more robust resolution of type references in quotations
  • Loading branch information
dsyme authored and latkin committed Jan 16, 2015
1 parent 481890d commit 640db00
Show file tree
Hide file tree
Showing 28 changed files with 540 additions and 293 deletions.
28 changes: 18 additions & 10 deletions src/absil/ilreflect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ type cenv =
// [] ,name -> name
// [ns] ,name -> ns+name
// [ns;typeA;typeB],name -> ns+typeA+typeB+name
let getTRefType (cenv:cenv) (tref:ILTypeRef) =
let convTypeRefAux (cenv:cenv) (tref:ILTypeRef) =

// If an inner nested type's name contains a space, the proper encoding is "\+" on both sides - otherwise,
// we use "+"
Expand Down Expand Up @@ -355,11 +355,11 @@ let getTRefType (cenv:cenv) (tref:ILTypeRef) =
let asmName = convAssemblyRef asmref
FileSystem.AssemblyLoad(asmName)
let typT = assembly.GetType(qualifiedName)
typT |> nonNull "GetTRefType"
typT |> nonNull "convTypeRefAux"
| ILScopeRef.Module _
| ILScopeRef.Local _ ->
let typT = Type.GetType(qualifiedName,true)
typT |> nonNull "GetTRefType"
typT |> nonNull "convTypeRefAux"



Expand Down Expand Up @@ -425,11 +425,11 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
#endif
emEnv

let envGetTypT cenv emEnv preferCreated (tref:ILTypeRef) =
let convTypeRef cenv emEnv preferCreated (tref:ILTypeRef) =
match Zmap.tryFind tref emEnv.emTypMap with
| Some (_typT,_typB,_typeDef,Some createdTyp) when preferCreated -> createdTyp |> nonNull "envGetTypT: null create type table?"
| Some (typT,_typB,_typeDef,_) -> typT |> nonNull "envGetTypT: null type table?"
| None -> getTRefType cenv tref
| Some (_typT,_typB,_typeDef,Some createdTyp) when preferCreated -> createdTyp |> nonNull "convTypeRef: null create type table?"
| Some (typT,_typB,_typeDef,_) -> typT |> nonNull "convTypeRef: null type table?"
| None -> convTypeRefAux cenv tref

let envBindConsRef emEnv (mref:ILMethodRef) consB =
{emEnv with emConsMap = Zmap.add mref consB emEnv.emConsMap}
Expand Down Expand Up @@ -512,7 +512,7 @@ let convCallConv (Callconv (hasThis,basic)) =
//----------------------------------------------------------------------------

let rec convTypeSpec cenv emEnv preferCreated (tspec:ILTypeSpec) =
let typT = envGetTypT cenv emEnv preferCreated tspec.TypeRef
let typT = convTypeRef cenv emEnv preferCreated tspec.TypeRef
let tyargs = ILList.map (convTypeAux cenv emEnv preferCreated) tspec.GenericArgs
match ILList.isEmpty tyargs,typT.IsGenericType with
| _ ,true -> typT.MakeGenericType(ILList.toArray tyargs) |> nonNull "convTypeSpec: generic"
Expand Down Expand Up @@ -565,12 +565,20 @@ and convTypeAux cenv emEnv preferCreated typ =
/// Uses TypeBuilder/TypeBuilderInstantiation for emitted types
let convType cenv emEnv typ = convTypeAux cenv emEnv false typ

// Used for ldtoken
let convTypeOrTypeDef cenv emEnv typ =
match typ with
// represents an uninstantiated "TypeDef" or "TypeRef"
| ILType.Boxed tspec when tspec.GenericArgs.IsEmpty -> convTypeRef cenv emEnv false tspec.TypeRef
| _ -> convType cenv emEnv typ

let convTypes cenv emEnv (typs:ILTypes) = ILList.map (convType cenv emEnv) typs

let convTypesToArray cenv emEnv (typs:ILTypes) = convTypes cenv emEnv typs |> ILList.toArray

/// Uses the .CreateType() for emitted type (if available)
let convCreatedType cenv emEnv typ = convTypeAux cenv emEnv true typ
let convCreatedTypeRef cenv emEnv typ = convTypeRef cenv emEnv true typ


//----------------------------------------------------------------------------
Expand Down Expand Up @@ -1050,7 +1058,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
| I_ldstr s -> ilG.EmitAndLog(OpCodes.Ldstr ,s)
| I_isinst typ -> ilG.EmitAndLog(OpCodes.Isinst ,convType cenv emEnv typ)
| I_castclass typ -> ilG.EmitAndLog(OpCodes.Castclass,convType cenv emEnv typ)
| I_ldtoken (ILToken.ILType typ) -> ilG.EmitAndLog(OpCodes.Ldtoken ,convType cenv emEnv typ)
| I_ldtoken (ILToken.ILType typ) -> ilG.EmitAndLog(OpCodes.Ldtoken ,convTypeOrTypeDef cenv emEnv typ)
| I_ldtoken (ILToken.ILMethod mspec) -> ilG.EmitAndLog(OpCodes.Ldtoken ,convMethodSpec cenv emEnv mspec)
| I_ldtoken (ILToken.ILField fspec) -> ilG.EmitAndLog(OpCodes.Ldtoken ,convFieldSpec cenv emEnv fspec)
| I_ldvirtftn mspec -> ilG.EmitAndLog(OpCodes.Ldvirtftn,convMethodSpec cenv emEnv mspec)
Expand Down Expand Up @@ -2006,7 +2014,7 @@ let emitModuleFragment (ilg, emEnv, asmB : AssemblyBuilder, modB : ModuleBuilder
// The emEnv stores (typT:Type) for each tref.
// Once the emitted type is created this typT is updated to ensure it is the Type proper.
// So Type lookup will return the proper Type not TypeBuilder.
let LookupTypeRef emEnv tref = Zmap.tryFind tref emEnv.emTypMap |> Option.map (function (_typ,_,_,Some createdTyp) -> createdTyp | (typ,_,_,None) -> typ)
let LookupTypeRef cenv emEnv tref = convCreatedTypeRef cenv emEnv tref
let LookupType cenv emEnv typ = convCreatedType cenv emEnv typ

// Lookups of ILFieldRef and MethodRef may require a similar non-Builder-fixup post Type-creation.
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/FSComp.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1144,8 +1144,8 @@ fscTooManyErrors,"Exiting - too many errors"
2002,fscNoImplementationFiles,"No implementation files specified"
2003,fscBadAssemblyVersion,"An %s specified version '%s', but this value is invalid and has been ignored"
2004,fscTwoResourceManifests,"Conflicting options specified: 'win32manifest' and 'win32res'. Only one of these can be used."
2005,fscQuotationLiteralsStaticLinking,"The code in assembly '%s' makes uses of quotation literals. Static linking may not include components that make use of quotation literals."
2006,fscQuotationLiteralsStaticLinking0,"Code in this assembly makes uses of quotation literals. Static linking may not include components that make use of quotation literals."
2005,fscQuotationLiteralsStaticLinking,"The code in assembly '%s' makes uses of quotation literals. Static linking may not include components that make use of quotation literals unless all assemblies are compiled with at least F# 4.0."
2006,fscQuotationLiteralsStaticLinking0,"Code in this assembly makes uses of quotation literals. Static linking may not include components that make use of quotation literals unless all assemblies are compiled with at least F# 4.0."
2007,fscStaticLinkingNoEXE,"Static linking may not include a .EXE"
2008,fscStaticLinkingNoMixedDLL,"Static linking may not include a mixed managed/unmanaged DLL"
2009,fscIgnoringMixedWhenLinking,"Ignoring mixed managed/unmanaged assembly '%s' during static linking"
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3262,6 +3262,7 @@ Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr C
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr Coerce(Microsoft.FSharp.Quotations.FSharpExpr, System.Type)
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr DefaultValue(System.Type)
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr Deserialize(System.Type, Microsoft.FSharp.Collections.FSharpList`1[System.Type], Microsoft.FSharp.Collections.FSharpList`1[Microsoft.FSharp.Quotations.FSharpExpr], Byte[])
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr Deserialize40(System.Type, System.Type[], System.Type[], Microsoft.FSharp.Quotations.FSharpExpr[], Byte[])
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldGet(Microsoft.FSharp.Quotations.FSharpExpr, System.Reflection.FieldInfo)
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldGet(System.Reflection.FieldInfo)
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldSet(Microsoft.FSharp.Quotations.FSharpExpr, System.Reflection.FieldInfo, Microsoft.FSharp.Quotations.FSharpExpr)
Expand Down
8 changes: 7 additions & 1 deletion src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,19 @@ namespace Microsoft.FSharp.Core
[<Sealed>]
type CompilationMappingAttribute(sourceConstructFlags:SourceConstructFlags,
variantNumber:int,
sequenceNumber:int) =
sequenceNumber:int,
resourceName:string,
typeDefinitions:System.Type[]) =
inherit System.Attribute()
member x.SourceConstructFlags = sourceConstructFlags
member x.SequenceNumber = sequenceNumber
member x.VariantNumber = variantNumber
new(sourceConstructFlags) = CompilationMappingAttribute(sourceConstructFlags,0,0)
new(sourceConstructFlags,sequenceNumber) = CompilationMappingAttribute(sourceConstructFlags,0,sequenceNumber)
new(sourceConstructFlags,variantNumber,sequenceNumber) = CompilationMappingAttribute(sourceConstructFlags,variantNumber,sequenceNumber,null,null)
new(resourceName, typeDefinitions) = CompilationMappingAttribute(SourceConstructFlags.None,0,0,resourceName, typeDefinitions)
member x.TypeDefinitions = typeDefinitions
member x.ResourceName = resourceName

[<AttributeUsage(AttributeTargets.All,AllowMultiple=false)>]
[<Sealed>]
Expand Down
9 changes: 9 additions & 0 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,15 @@ namespace Microsoft.FSharp.Core
/// <returns>CompilationMappingAttribute</returns>
new : sourceConstructFlags:SourceConstructFlags * variantNumber : int * sequenceNumber : int -> CompilationMappingAttribute

/// <summary>Creates an instance of the attribute</summary>
/// <param name="typeDefinitions">Indicates the type definitions needed to resolve the source construct.</param>
/// <returns>CompilationMappingAttribute</returns>
new : resourceName:string * typeDefinitions:System.Type[] -> CompilationMappingAttribute
/// <summary>Indicates the resource the source construct relates to</summary>
member ResourceName : string
/// <summary>Indicates the type definitions needed to resolve the source construct</summary>
member TypeDefinitions : System.Type[]

/// <summary>This attribute is inserted automatically by the F# compiler to tag
/// methods which are given the 'CompiledName' attribute. It is not intended
/// for use from user code.</summary>
Expand Down
Loading

0 comments on commit 640db00

Please sign in to comment.