Skip to content

Commit ff078e9

Browse files
authored
Add entity.DeclaringEntity to F# Compiler Service (#4633)
* Add DeclaringEntity * extend tests to cover namespaces * extend tests to cover namespaces * build on Mono 5.10 * bump FCS version * various comments and debugging improvements * code review
1 parent 8388cf5 commit ff078e9

28 files changed

+906
-647
lines changed

fcs/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ which does things like:
6060
You can push the packages if you have permissions, either automatically using ``build Release`` or manually
6161

6262
set APIKEY=...
63-
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.22.0.2.nupkg %APIKEY% -Source https://nuget.org
64-
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.MSBuild.v12.22.0.2.nupkg %APIKEY% -Source https://nuget.org
65-
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.ProjectCracker.22.0.2.nupkg %APIKEY% -Source https://nuget.org
63+
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.22.0.3.nupkg %APIKEY% -Source https://nuget.org
64+
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.MSBuild.v12.22.0.3.nupkg %APIKEY% -Source https://nuget.org
65+
..\fsharp\.nuget\nuget.exe push %HOMEDRIVE%%HOMEPATH%\Downloads\FSharp.Compiler.Service.ProjectCracker.22.0.3.nupkg %APIKEY% -Source https://nuget.org
6666

6767

6868
### Use of Paket and FAKE

fcs/RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 22.0.3
2+
* [Add entity.DeclaringEntity](https://github.com/Microsoft/visualfsharp/pull/4633), [FCS feature request](https://github.com/fsharp/FSharp.Compiler.Service/issues/830)
3+
14
#### 22.0.2
25
* Use correct version number in DLLs (needed until https://github.com/Microsoft/visualfsharp/issues/3113 is fixed)
36

fcs/fcs.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
44
<PropertyGroup>
55

6-
<VersionPrefix>22.0.2</VersionPrefix>
6+
<VersionPrefix>22.0.3</VersionPrefix>
77
<OtherFlags>--version:$(VersionPrefix)</OtherFlags>
88
<!-- FSharp.Compiler.Tools is currently only used to get a working FSI.EXE to execute some scripts during the build -->
99
<!-- The LKG FSI.EXE requires MSBuild 15 to be installed, which is painful -->

src/absil/il.fs

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ type ILAssemblyRef(data) =
408408

409409
ILAssemblyRef.Create(aname.Name,None,publicKey,retargetable,version,locale)
410410

411-
412-
413411
member aref.QualifiedName =
414412
let b = new System.Text.StringBuilder(100)
415413
let add (s:string) = (b.Append(s) |> ignore)
@@ -478,13 +476,6 @@ type ILScopeRef =
478476
member x.AssemblyRef = match x with ILScopeRef.Assembly x -> x | _ -> failwith "not an assembly reference"
479477

480478
member scoref.QualifiedName =
481-
match scoref with
482-
| ILScopeRef.Local -> ""
483-
| ILScopeRef.Module mref -> "module "^mref.Name
484-
| ILScopeRef.Assembly aref when aref.Name = "mscorlib" -> ""
485-
| ILScopeRef.Assembly aref -> aref.QualifiedName
486-
487-
member scoref.QualifiedNameWithNoShortPrimaryAssembly =
488479
match scoref with
489480
| ILScopeRef.Local -> ""
490481
| ILScopeRef.Module mref -> "module "+mref.Name
@@ -602,18 +593,12 @@ type ILTypeRef =
602593
member tref.BasicQualifiedName =
603594
(String.concat "+" (tref.Enclosing @ [ tref.Name ] )).Replace(",", @"\,")
604595

605-
member tref.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic) =
606-
let sco = tref.Scope.QualifiedNameWithNoShortPrimaryAssembly
607-
if sco = "" then basic else String.concat ", " [basic;sco]
608-
609-
member tref.QualifiedNameWithNoShortPrimaryAssembly =
610-
tref.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(tref.BasicQualifiedName)
611-
612-
member tref.QualifiedName =
613-
let basic = tref.BasicQualifiedName
596+
member tref.AddQualifiedNameExtension(basic) =
614597
let sco = tref.Scope.QualifiedName
615598
if sco = "" then basic else String.concat ", " [basic;sco]
616599

600+
member tref.QualifiedName =
601+
tref.AddQualifiedNameExtension(tref.BasicQualifiedName)
617602

618603
override x.ToString() = x.FullName
619604

@@ -624,22 +609,30 @@ and
624609
{ tspecTypeRef: ILTypeRef;
625610
/// The type instantiation if the type is generic.
626611
tspecInst: ILGenericArgs }
612+
627613
member x.TypeRef=x.tspecTypeRef
614+
628615
member x.Scope=x.TypeRef.Scope
616+
629617
member x.Enclosing=x.TypeRef.Enclosing
618+
630619
member x.Name=x.TypeRef.Name
620+
631621
member x.GenericArgs=x.tspecInst
622+
632623
static member Create(tref,inst) = { tspecTypeRef =tref; tspecInst=inst }
624+
633625
override x.ToString() = x.TypeRef.ToString() + if isNil x.GenericArgs then "" else "<...>"
626+
634627
member x.BasicQualifiedName =
635628
let tc = x.TypeRef.BasicQualifiedName
636629
if isNil x.GenericArgs then
637630
tc
638631
else
639-
tc + "[" + String.concat "," (x.GenericArgs |> List.map (fun arg -> "[" + arg.QualifiedNameWithNoShortPrimaryAssembly + "]")) + "]"
632+
tc + "[" + String.concat "," (x.GenericArgs |> List.map (fun arg -> "[" + arg.QualifiedName + "]")) + "]"
640633

641-
member x.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic) =
642-
x.TypeRef.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic)
634+
member x.AddQualifiedNameExtension(basic) =
635+
x.TypeRef.AddQualifiedNameExtension(basic)
643636

644637
member x.FullName=x.TypeRef.FullName
645638

@@ -666,19 +659,19 @@ and [<RequireQualifiedAccess; StructuralEquality; StructuralComparison>]
666659
| ILType.Byref _ty -> failwith "unexpected byref type"
667660
| ILType.FunctionPointer _mref -> failwith "unexpected function pointer type"
668661

669-
member x.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic) =
662+
member x.AddQualifiedNameExtension(basic) =
670663
match x with
671664
| ILType.TypeVar _n -> basic
672-
| ILType.Modified(_,_ty1,ty2) -> ty2.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic)
673-
| ILType.Array (ILArrayShape(_s),ty) -> ty.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic)
674-
| ILType.Value tr | ILType.Boxed tr -> tr.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(basic)
665+
| ILType.Modified(_,_ty1,ty2) -> ty2.AddQualifiedNameExtension(basic)
666+
| ILType.Array (ILArrayShape(_s),ty) -> ty.AddQualifiedNameExtension(basic)
667+
| ILType.Value tr | ILType.Boxed tr -> tr.AddQualifiedNameExtension(basic)
675668
| ILType.Void -> failwith "void"
676669
| ILType.Ptr _ty -> failwith "unexpected pointer type"
677670
| ILType.Byref _ty -> failwith "unexpected byref type"
678671
| ILType.FunctionPointer _mref -> failwith "unexpected function pointer type"
679672

680-
member x.QualifiedNameWithNoShortPrimaryAssembly =
681-
x.AddQualifiedNameExtensionWithNoShortPrimaryAssembly(x.BasicQualifiedName)
673+
member x.QualifiedName =
674+
x.AddQualifiedNameExtension(x.BasicQualifiedName)
682675

683676
member x.TypeSpec =
684677
match x with
@@ -3301,7 +3294,7 @@ let rec encodeCustomAttrElemType x =
33013294
| ILType.Boxed tspec when tspec.Name = tname_String -> [| et_STRING |]
33023295
| ILType.Boxed tspec when tspec.Name = tname_Object -> [| 0x51uy |]
33033296
| ILType.Boxed tspec when tspec.Name = tname_Type -> [| 0x50uy |]
3304-
| ILType.Value tspec -> Array.append [| 0x55uy |] (encodeCustomAttrString tspec.TypeRef.QualifiedNameWithNoShortPrimaryAssembly)
3297+
| ILType.Value tspec -> Array.append [| 0x55uy |] (encodeCustomAttrString tspec.TypeRef.QualifiedName)
33053298
| ILType.Array (shape, elemType) when shape = ILArrayShape.SingleDimensional ->
33063299
Array.append [| et_SZARRAY |] (encodeCustomAttrElemType elemType)
33073300
| _ -> failwith "encodeCustomAttrElemType: unrecognized custom element type"
@@ -3372,8 +3365,8 @@ let rec encodeCustomAttrPrimValue ilg c =
33723365
| ILAttribElem.UInt64 x -> u64AsBytes x
33733366
| ILAttribElem.Single x -> ieee32AsBytes x
33743367
| ILAttribElem.Double x -> ieee64AsBytes x
3375-
| ILAttribElem.Type (Some ty) -> encodeCustomAttrString ty.QualifiedNameWithNoShortPrimaryAssembly
3376-
| ILAttribElem.TypeRef (Some tref) -> encodeCustomAttrString tref.QualifiedNameWithNoShortPrimaryAssembly
3368+
| ILAttribElem.Type (Some ty) -> encodeCustomAttrString ty.QualifiedName
3369+
| ILAttribElem.TypeRef (Some tref) -> encodeCustomAttrString tref.QualifiedName
33773370
| ILAttribElem.Array (_,elems) ->
33783371
[| yield! i32AsBytes elems.Length; for elem in elems do yield! encodeCustomAttrPrimValue ilg elem |]
33793372

@@ -3427,7 +3420,7 @@ let mkPermissionSet (ilg: ILGlobals) (action,attributes: list<(ILTypeRef * (stri
34273420
[| yield (byte '.');
34283421
yield! z_unsigned_int attributes.Length;
34293422
for (tref:ILTypeRef,props) in attributes do
3430-
yield! encodeCustomAttrString tref.QualifiedNameWithNoShortPrimaryAssembly
3423+
yield! encodeCustomAttrString tref.QualifiedName
34313424
let bytes =
34323425
[| yield! z_unsigned_int props.Length;
34333426
for (nm,typ,value) in props do

src/absil/il.fsi

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,26 +184,32 @@ type ILTypeRef =
184184

185185
member QualifiedName: string
186186

187-
#if !NO_EXTENSIONTYPING
188-
member QualifiedNameWithNoShortPrimaryAssembly: string
189-
#endif
190-
191187
interface System.IComparable
192188
193189
/// Type specs and types.
194190
[<Sealed>]
195191
type ILTypeSpec =
192+
/// Create an ILTypeSpec.
196193
static member Create: typeRef:ILTypeRef * instantiation:ILGenericArgs -> ILTypeSpec
197194

198195
/// Which type is being referred to?
199196
member TypeRef: ILTypeRef
200197

201198
/// The type instantiation if the type is generic, otherwise empty
202199
member GenericArgs: ILGenericArgs
200+
201+
/// Where is the type, i.e. is it in this module, in another module in this assembly or in another assembly?
203202
member Scope: ILScopeRef
203+
204+
/// The list of enclosing type names for a nested type. If non-nil then the first of these also contains the namespace.
204205
member Enclosing: string list
206+
207+
/// The name of the type. This also contains the namespace if Enclosing is empty.
205208
member Name: string
209+
210+
/// The name of the type in the assembly using the '.' notation for nested types.
206211
member FullName: string
212+
207213
interface System.IComparable
208214

209215
and
@@ -244,13 +250,20 @@ and
244250
ILType
245251

246252
member TypeSpec: ILTypeSpec
253+
247254
member Boxity: ILBoxity
255+
248256
member TypeRef: ILTypeRef
257+
249258
member IsNominal: bool
259+
250260
member GenericArgs: ILGenericArgs
261+
251262
member IsTyvar: bool
263+
252264
member BasicQualifiedName: string
253-
member QualifiedNameWithNoShortPrimaryAssembly: string
265+
266+
member QualifiedName: string
254267

255268
and [<StructuralEquality; StructuralComparison>]
256269
ILCallingSignature =
@@ -271,13 +284,21 @@ type ILMethodRef =
271284
static member Create: enclosingTypeRef: ILTypeRef * callingConv: ILCallingConv * name: string * genericArity: int * argTypes: ILTypes * returnType: ILType -> ILMethodRef
272285

273286
member DeclaringTypeRef: ILTypeRef
287+
274288
member CallingConv: ILCallingConv
289+
275290
member Name: string
291+
276292
member GenericArity: int
293+
277294
member ArgCount: int
295+
278296
member ArgTypes: ILTypes
297+
279298
member ReturnType: ILType
299+
280300
member CallingSignature: ILCallingSignature
301+
281302
interface System.IComparable
282303
283304
/// Formal identities of fields.
@@ -295,13 +316,21 @@ type ILMethodSpec =
295316
static member Create: ILType * ILMethodRef * ILGenericArgs -> ILMethodSpec
296317

297318
member MethodRef: ILMethodRef
319+
298320
member DeclaringType: ILType
321+
299322
member GenericArgs: ILGenericArgs
323+
300324
member CallingConv: ILCallingConv
325+
301326
member GenericArity: int
327+
302328
member Name: string
329+
303330
member FormalArgTypes: ILTypes
331+
304332
member FormalReturnType: ILType
333+
305334
interface System.IComparable
306335
307336
/// Field specs. The data given for a ldfld, stfld etc. instruction.
@@ -311,8 +340,11 @@ type ILFieldSpec =
311340
DeclaringType: ILType }
312341

313342
member DeclaringTypeRef: ILTypeRef
343+
314344
member Name: string
345+
315346
member FormalType: ILType
347+
316348
member ActualType: ILType
317349

318350
/// ILCode labels. In structured code each code label refers to a basic block somewhere in the code of the method.

0 commit comments

Comments
 (0)