Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit640db00

Browse files
dsymelatkin
authored andcommitted
Simplified, more robust resolution of type references in quotations
commit d18cc8e011b81cbf3256ec42da74015aff67c3eeAuthor: latkin <latkin@microsoft.com>Date: Fri Jan 16 15:37:44 2015 -0800 Reverting test tag changescommit b3e2b3078bcd23b4373ed51c2471c027d4f2320cMerge:481890d d2c5d18Author: latkin <latkin@microsoft.com>Date: Fri Jan 16 14:57:16 2015 -0800 Merge branch 'quotation-type-refs' ofhttps://git01.codeplex.com/forks/dsyme/cleanup into quotformatcommit d2c5d185f2e193e0515483476cf60e14bd261c53Author: Don Syme <dsyme@microsoft.com>Date: Mon Jan 12 19:11:31 2015 +0000 fix problem with profile47, moving CAs to assembly instead of modulecommit d1d4f76a8499005d7061de9180750db5675be7d5Merge: dea089f51d7b62Author: Don Syme <dsyme@microsoft.com>Date: Mon Jan 12 17:32:41 2015 +0000 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/visualfsharp into quotation-type-refscommit dea089f2eed6a339ab130e321cf30de37a117904Author: Don Syme <dsyme@microsoft.com>Date: Mon Dec 8 18:38:23 2014 +0000 get profile 78 compilingcommit b55f6632e5ff3b3b682525bad8cf8ec722820cfbMerge: 4c3e6b8e8d7469Author: Don Syme <dsyme@microsoft.com>Date: Mon Dec 8 18:21:10 2014 +0000 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/visualfsharp into quotation-type-refscommit 4c3e6b800f85ef060d50c902e158cf78922fbc03Author: Don Syme <dsyme@microsoft.com>Date: Mon Dec 8 18:06:15 2014 +0000 updates to keep error for F# 2.0+ quotations static linkingcommit 50c3d6530fb4230ccd80d85c8d1a694908c18d14Author: Don Syme <dsyme@microsoft.com>Date: Mon Oct 13 17:55:30 2014 +0100 updates from code reviewcommit bc8671b27f9e895e35157efeba646d7065c074acAuthor: Don Syme <dsyme@microsoft.com>Date: Thu Oct 9 12:46:23 2014 +0100 minor renaming for clarificationcommit 9dfa9c8fda186b908663e99c889de81f3cb6f90eAuthor: 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 uniquecommit 33ce7699c2ba8a6158b60a337a296bf60276ede4Author: Don Syme <dsyme@microsoft.com>Date: Wed Oct 8 18:49:10 2014 +0100 Simplified, more robust resolution of type references in quotations
1 parent481890d commit640db00

File tree

28 files changed

+540
-293
lines changed

28 files changed

+540
-293
lines changed

‎src/absil/ilreflect.fs‎

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ type cenv =
323323
// [] ,name -> name
324324
// [ns] ,name -> ns+name
325325
// [ns;typeA;typeB],name -> ns+typeA+typeB+name
326-
letgetTRefType(cenv:cenv)(tref:ILTypeRef)=
326+
letconvTypeRefAux(cenv:cenv)(tref:ILTypeRef)=
327327

328328
// If an inner nested type's name contains a space, the proper encoding is "\+" on both sides - otherwise,
329329
// we use "+"
@@ -355,11 +355,11 @@ let getTRefType (cenv:cenv) (tref:ILTypeRef) =
355355
letasmName= convAssemblyRef asmref
356356
FileSystem.AssemblyLoad(asmName)
357357
lettypT= assembly.GetType(qualifiedName)
358-
typT|> nonNull"GetTRefType"
358+
typT|> nonNull"convTypeRefAux"
359359
| ILScopeRef.Module_
360360
| ILScopeRef.Local_->
361361
lettypT= Type.GetType(qualifiedName,true)
362-
typT|> nonNull"GetTRefType"
362+
typT|> nonNull"convTypeRefAux"
363363

364364

365365

@@ -425,11 +425,11 @@ let envUpdateCreatedTypeRef emEnv (tref:ILTypeRef) =
425425
#endif
426426
emEnv
427427

428-
letenvGetTypT cenv emEnv preferCreated(tref:ILTypeRef)=
428+
letconvTypeRef cenv emEnv preferCreated(tref:ILTypeRef)=
429429
match Zmap.tryFind tref emEnv.emTypMapwith
430-
| Some(_typT,_typB,_typeDef,Some createdTyp)when preferCreated-> createdTyp|> nonNull"envGetTypT: null create type table?"
431-
| Some(typT,_typB,_typeDef,_)-> typT|> nonNull"envGetTypT: null type table?"
432-
| None->getTRefType cenv tref
430+
| Some(_typT,_typB,_typeDef,Some createdTyp)when preferCreated-> createdTyp|> nonNull"convTypeRef: null create type table?"
431+
| Some(typT,_typB,_typeDef,_)-> typT|> nonNull"convTypeRef: null type table?"
432+
| None->convTypeRefAux cenv tref
433433

434434
letenvBindConsRef emEnv(mref:ILMethodRef)consB=
435435
{emEnvwith emConsMap= Zmap.add mref consB emEnv.emConsMap}
@@ -512,7 +512,7 @@ let convCallConv (Callconv (hasThis,basic)) =
512512
//----------------------------------------------------------------------------
513513

514514
let recconvTypeSpec cenv emEnv preferCreated(tspec:ILTypeSpec)=
515-
lettypT=envGetTypT cenv emEnv preferCreated tspec.TypeRef
515+
lettypT=convTypeRef cenv emEnv preferCreated tspec.TypeRef
516516
lettyargs= ILList.map(convTypeAux cenv emEnv preferCreated) tspec.GenericArgs
517517
match ILList.isEmpty tyargs,typT.IsGenericTypewith
518518
|_,true-> typT.MakeGenericType(ILList.toArray tyargs)|> nonNull"convTypeSpec: generic"
@@ -565,12 +565,20 @@ and convTypeAux cenv emEnv preferCreated typ =
565565
/// Uses TypeBuilder/TypeBuilderInstantiation for emitted types
566566
letconvType cenv emEnv typ= convTypeAux cenv emEnvfalse typ
567567

568+
// Used for ldtoken
569+
letconvTypeOrTypeDef cenv emEnv typ=
570+
match typwith
571+
// represents an uninstantiated "TypeDef" or "TypeRef"
572+
| ILType.Boxed tspecwhen tspec.GenericArgs.IsEmpty-> convTypeRef cenv emEnvfalse tspec.TypeRef
573+
|_-> convType cenv emEnv typ
574+
568575
letconvTypes cenv emEnv(typs:ILTypes)= ILList.map(convType cenv emEnv) typs
569576

570577
letconvTypesToArray cenv emEnv(typs:ILTypes)= convTypes cenv emEnv typs|> ILList.toArray
571578

572579
/// Uses the .CreateType() for emitted type (if available)
573580
letconvCreatedType cenv emEnv typ= convTypeAux cenv emEnvtrue typ
581+
letconvCreatedTypeRef cenv emEnv typ= convTypeRef cenv emEnvtrue typ
574582

575583

576584
//----------------------------------------------------------------------------
@@ -1050,7 +1058,7 @@ let rec emitInstr cenv (modB : ModuleBuilder) emEnv (ilG:ILGenerator) instr =
10501058
| I_ldstr s-> ilG.EmitAndLog(OpCodes.Ldstr,s)
10511059
| I_isinst typ-> ilG.EmitAndLog(OpCodes.Isinst,convType cenv emEnv typ)
10521060
| I_castclass typ-> ilG.EmitAndLog(OpCodes.Castclass,convType cenv emEnv typ)
1053-
| I_ldtoken(ILToken.ILType typ)-> ilG.EmitAndLog(OpCodes.Ldtoken,convType cenv emEnv typ)
1061+
| I_ldtoken(ILToken.ILType typ)-> ilG.EmitAndLog(OpCodes.Ldtoken,convTypeOrTypeDef cenv emEnv typ)
10541062
| I_ldtoken(ILToken.ILMethod mspec)-> ilG.EmitAndLog(OpCodes.Ldtoken,convMethodSpec cenv emEnv mspec)
10551063
| I_ldtoken(ILToken.ILField fspec)-> ilG.EmitAndLog(OpCodes.Ldtoken,convFieldSpec cenv emEnv fspec)
10561064
| I_ldvirtftn mspec-> ilG.EmitAndLog(OpCodes.Ldvirtftn,convMethodSpec cenv emEnv mspec)
@@ -2006,7 +2014,7 @@ let emitModuleFragment (ilg, emEnv, asmB : AssemblyBuilder, modB : ModuleBuilder
20062014
// The emEnv stores (typT:Type) for each tref.
20072015
// Once the emitted type is created this typT is updated to ensure it is the Type proper.
20082016
// So Type lookup will return the proper Type not TypeBuilder.
2009-
letLookupTypeRef emEnv tref=Zmap.tryFind tref emEnv.emTypMap|> Option.map(function(_typ,_,_,Some createdTyp)-> createdTyp|(typ,_,_,None)-> typ)
2017+
letLookupTypeRefcenvemEnv tref=convCreatedTypeRef cenv emEnv tref
20102018
letLookupType cenv emEnv typ= convCreatedType cenv emEnv typ
20112019

20122020
// Lookups of ILFieldRef and MethodRef may require a similar non-Builder-fixup post Type-creation.

‎src/fsharp/FSComp.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ fscTooManyErrors,"Exiting - too many errors"
11441144
2002,fscNoImplementationFiles,"No implementation files specified"
11451145
2003,fscBadAssemblyVersion,"An %s specified version '%s', but this value is invalid and has been ignored"
11461146
2004,fscTwoResourceManifests,"Conflicting options specified: 'win32manifest' and 'win32res'. Only one of these can be used."
1147-
2005,fscQuotationLiteralsStaticLinking,"The code in assembly '%s' makes uses of quotation literals. Static linking may not include components that make use of quotation literals."
1148-
2006,fscQuotationLiteralsStaticLinking0,"Code in this assembly makes uses of quotation literals. Static linking may not include components that make use of quotation literals."
1147+
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."
1148+
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."
11491149
2007,fscStaticLinkingNoEXE,"Static linking may not include a .EXE"
11501150
2008,fscStaticLinkingNoMixedDLL,"Static linking may not include a mixed managed/unmanaged DLL"
11511151
2009,fscIgnoringMixedWhenLinking,"Ignoring mixed managed/unmanaged assembly '%s' during static linking"

‎src/fsharp/FSharp.Core.Unittests/SurfaceArea.4.0.fs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,7 @@ Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr C
32623262
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr Coerce(Microsoft.FSharp.Quotations.FSharpExpr, System.Type)
32633263
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr DefaultValue(System.Type)
32643264
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[])
3265+
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr Deserialize40(System.Type, System.Type[], System.Type[], Microsoft.FSharp.Quotations.FSharpExpr[], Byte[])
32653266
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldGet(Microsoft.FSharp.Quotations.FSharpExpr, System.Reflection.FieldInfo)
32663267
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldGet(System.Reflection.FieldInfo)
32673268
Microsoft.FSharp.Quotations.FSharpExpr: Microsoft.FSharp.Quotations.FSharpExpr FieldSet(Microsoft.FSharp.Quotations.FSharpExpr, System.Reflection.FieldInfo, Microsoft.FSharp.Quotations.FSharpExpr)

‎src/fsharp/FSharp.Core/prim-types.fs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,19 @@ namespace Microsoft.FSharp.Core
259259
[<Sealed>]
260260
typeCompilationMappingAttribute(sourceConstructFlags:SourceConstructFlags,
261261
variantNumber:int,
262-
sequenceNumber:int)=
262+
sequenceNumber:int,
263+
resourceName:string,
264+
typeDefinitions:System.Type[])=
263265
inherit System.Attribute()
264266
memberx.SourceConstructFlags= sourceConstructFlags
265267
memberx.SequenceNumber= sequenceNumber
266268
memberx.VariantNumber= variantNumber
267269
new(sourceConstructFlags)= CompilationMappingAttribute(sourceConstructFlags,0,0)
268270
new(sourceConstructFlags,sequenceNumber)= CompilationMappingAttribute(sourceConstructFlags,0,sequenceNumber)
271+
new(sourceConstructFlags,variantNumber,sequenceNumber)= CompilationMappingAttribute(sourceConstructFlags,variantNumber,sequenceNumber,null,null)
272+
new(resourceName, typeDefinitions)= CompilationMappingAttribute(SourceConstructFlags.None,0,0,resourceName, typeDefinitions)
273+
memberx.TypeDefinitions= typeDefinitions
274+
memberx.ResourceName= resourceName
269275

270276
[<AttributeUsage(AttributeTargets.All,AllowMultiple=false)>]
271277
[<Sealed>]

‎src/fsharp/FSharp.Core/prim-types.fsi‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,15 @@ namespace Microsoft.FSharp.Core
547547
/// <returns>CompilationMappingAttribute</returns>
548548
new: sourceConstructFlags:SourceConstructFlags* variantNumber: int* sequenceNumber: int-> CompilationMappingAttribute
549549

550+
/// <summary>Creates an instance of the attribute</summary>
551+
/// <param name="typeDefinitions">Indicates the type definitions needed to resolve the source construct.</param>
552+
/// <returns>CompilationMappingAttribute</returns>
553+
new: resourceName:string* typeDefinitions:System.Type[]-> CompilationMappingAttribute
554+
/// <summary>Indicates the resource the source construct relates to</summary>
555+
memberResourceName:string
556+
/// <summary>Indicates the type definitions needed to resolve the source construct</summary>
557+
memberTypeDefinitions:System.Type[]
558+
550559
/// <summary>This attribute is inserted automatically by the F# compiler to tag
551560
/// methods which are given the 'CompiledName' attribute. It is not intended
552561
/// for use from user code.</summary>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp