Skip to content

Commit b8a0665

Browse files
authored
Merge pull request #6404 from KevinRansom/ILVersionInfoAsStruct
Making ILVersionInfo a struct (#6392)
2 parents c594473 + 132af3e commit b8a0665

File tree

10 files changed

+100
-82
lines changed

10 files changed

+100
-82
lines changed

src/absil/il.fs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,16 @@ let sha1HashInt64 s = SHA1.sha1HashInt64 s
319319
//
320320
// --------------------------------------------------------------------
321321

322-
type ILVersionInfo = uint16 * uint16 * uint16 * uint16
322+
[<Struct>]
323+
type ILVersionInfo =
324+
325+
val Major: uint16
326+
val Minor: uint16
327+
val Build: uint16
328+
val Revision: uint16
329+
330+
new(major, minor, build, revision) =
331+
{ Major = major; Minor = minor; Build = build; Revision = revision }
323332

324333
type Locale = string
325334

@@ -410,7 +419,7 @@ type ILAssemblyRef(data) =
410419
let version =
411420
match aname.Version with
412421
| null -> None
413-
| v -> Some (uint16 v.Major, uint16 v.Minor, uint16 v.Build, uint16 v.Revision)
422+
| v -> Some (ILVersionInfo (uint16 v.Major, uint16 v.Minor, uint16 v.Build, uint16 v.Revision))
414423

415424
let retargetable = aname.Flags = System.Reflection.AssemblyNameFlags.Retargetable
416425

@@ -423,15 +432,15 @@ type ILAssemblyRef(data) =
423432
add(aref.Name)
424433
match aref.Version with
425434
| None -> ()
426-
| Some (a, b, c, d) ->
435+
| Some (version) ->
427436
add ", Version="
428-
add (string (int a))
437+
add (string (int version.Major))
429438
add "."
430-
add (string (int b))
439+
add (string (int version.Minor))
431440
add "."
432-
add (string (int c))
441+
add (string (int version.Build))
433442
add "."
434-
add (string (int d))
443+
add (string (int version.Revision))
435444
add ", Culture="
436445
match aref.Locale with
437446
| None -> add "neutral"
@@ -3559,7 +3568,7 @@ let et_MVAR = 0x1Euy
35593568
let et_CMOD_REQD = 0x1Fuy
35603569
let et_CMOD_OPT = 0x20uy
35613570

3562-
let formatILVersion ((a, b, c, d):ILVersionInfo) = sprintf "%d.%d.%d.%d" (int a) (int b) (int c) (int d)
3571+
let formatILVersion (version: ILVersionInfo) = sprintf "%d.%d.%d.%d" (int version.Major) (int version.Minor) (int version.Build) (int version.Revision)
35633572

35643573
let encodeCustomAttrString s =
35653574
let arr = string_as_utf8_bytes s
@@ -4249,17 +4258,17 @@ let parseILVersion (vstr : string) =
42494258
let zero32 n = if n < 0 then 0us else uint16(n)
42504259
// since the minor revision will be -1 if none is specified, we need to truncate to 0 to not break existing code
42514260
let minorRevision = if version.Revision = -1 then 0us else uint16(version.MinorRevision)
4252-
(zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision)
4261+
ILVersionInfo(zero32 version.Major, zero32 version.Minor, zero32 version.Build, minorRevision)
42534262

42544263

4255-
let compareILVersions (a1, a2, a3, a4) ((b1, b2, b3, b4) : ILVersionInfo) =
4256-
let c = compare a1 b1
4264+
let compareILVersions (version1 : ILVersionInfo) (version2 : ILVersionInfo) =
4265+
let c = compare version1.Major version2.Major
42574266
if c <> 0 then c else
4258-
let c = compare a2 b2
4267+
let c = compare version1.Minor version2.Minor
42594268
if c <> 0 then c else
4260-
let c = compare a3 b3
4269+
let c = compare version1.Build version2.Build
42614270
if c <> 0 then c else
4262-
let c = compare a4 b4
4271+
let c = compare version1.Revision version2.Revision
42634272
if c <> 0 then c else
42644273
0
42654274

src/absil/il.fsi

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,15 @@ type PublicKey =
5353
member KeyToken: byte[]
5454
static member KeyAsToken: byte[] -> PublicKey
5555

56-
type ILVersionInfo = uint16 * uint16 * uint16 * uint16
56+
[<Struct>]
57+
type ILVersionInfo =
58+
59+
val Major: uint16
60+
val Minor: uint16
61+
val Build: uint16
62+
val Revision: uint16
63+
64+
new : major: uint16 * minor: uint16 * build: uint16 * revision: uint16 -> ILVersionInfo
5765

5866
[<Sealed>]
5967
type ILAssemblyRef =

src/absil/ilprint.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -982,15 +982,15 @@ and goutput_lambdas env os lambdas =
982982
and goutput_tdefs contents enc env os (td: ILTypeDefs) =
983983
List.iter (goutput_tdef enc env contents os) td.AsList
984984

985-
let output_ver os (a,b,c,d) =
985+
let output_ver os (version: ILVersionInfo) =
986986
output_string os " .ver "
987-
output_u16 os a
987+
output_u16 os version.Major
988988
output_string os " : "
989-
output_u16 os b
989+
output_u16 os version.Minor
990990
output_string os " : "
991-
output_u16 os c
991+
output_u16 os version.Build
992992
output_string os " : "
993-
output_u16 os d
993+
output_u16 os version.Revision
994994

995995
let output_locale os s = output_string os " .Locale "; output_qstring os s
996996

src/absil/ilread.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ and seekReadAssemblyManifest (ctxt: ILMetadataReader) pectxt idx =
16671667
AuxModuleHashAlgorithm=hash
16681668
SecurityDeclsStored= ctxt.securityDeclsReader_Assembly
16691669
PublicKey= pubkey
1670-
Version= Some (v1, v2, v3, v4)
1670+
Version= Some (ILVersionInfo (v1, v2, v3, v4))
16711671
Locale= readStringHeapOption ctxt localeIdx
16721672
CustomAttrsStored = ctxt.customAttrsReader_Assembly
16731673
MetadataIndex = idx
@@ -1700,12 +1700,12 @@ and seekReadAssemblyRefUncached ctxtH idx =
17001700
| Some blob -> Some (if (flags &&& 0x0001) <> 0x0 then PublicKey blob else PublicKeyToken blob)
17011701

17021702
ILAssemblyRef.Create
1703-
(name=nm,
1704-
hash=readBlobHeapOption ctxt hashValueIdx,
1705-
publicKey=publicKey,
1706-
retargetable=((flags &&& 0x0100) <> 0x0),
1707-
version=Some(v1, v2, v3, v4),
1708-
locale=readStringHeapOption ctxt localeIdx)
1703+
(name = nm,
1704+
hash = readBlobHeapOption ctxt hashValueIdx,
1705+
publicKey = publicKey,
1706+
retargetable = ((flags &&& 0x0100) <> 0x0),
1707+
version = Some (ILVersionInfo (v1, v2, v3, v4)),
1708+
locale = readStringHeapOption ctxt localeIdx)
17091709

17101710
and seekReadModuleRef (ctxt: ILMetadataReader) mdv idx =
17111711
let (nameIdx) = seekReadModuleRefRow ctxt mdv idx

src/absil/ilreflect.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,8 @@ let convAssemblyRef (aref: ILAssemblyRef) =
310310
| None -> ()
311311
| Some (PublicKey bytes) -> asmName.SetPublicKey(bytes)
312312
| Some (PublicKeyToken bytes) -> asmName.SetPublicKeyToken(bytes))
313-
let setVersion (major, minor, build, rev) =
314-
asmName.Version <- System.Version (int32 major, int32 minor, int32 build, int32 rev)
313+
let setVersion (version: ILVersionInfo) =
314+
asmName.Version <- System.Version (int32 version.Major, int32 version.Minor, int32 version.Build, int32 version.Revision)
315315
Option.iter setVersion aref.Version
316316
// asmName.ProcessorArchitecture <- System.Reflection.ProcessorArchitecture.MSIL
317317
#if !FX_RESHAPED_GLOBALIZATION

src/absil/ilwrite.fs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,10 @@ let rec GetIdxForTypeDef cenv key =
709709

710710
let rec GetAssemblyRefAsRow cenv (aref: ILAssemblyRef) =
711711
AssemblyRefRow
712-
((match aref.Version with None -> 0us | Some (x, _, _, _) -> x),
713-
(match aref.Version with None -> 0us | Some (_, y, _, _) -> y),
714-
(match aref.Version with None -> 0us | Some (_, _, z, _) -> z),
715-
(match aref.Version with None -> 0us | Some (_, _, _, w) -> w),
712+
((match aref.Version with None -> 0us | Some (version) -> version.Major),
713+
(match aref.Version with None -> 0us | Some (version) -> version.Minor),
714+
(match aref.Version with None -> 0us | Some (version) -> version.Build),
715+
(match aref.Version with None -> 0us | Some (version) -> version.Revision),
716716
((match aref.PublicKey with Some (PublicKey _) -> 0x0001 | _ -> 0x0000)
717717
||| (if aref.Retargetable then 0x0100 else 0x0000)),
718718
BlobIndex (match aref.PublicKey with
@@ -2822,10 +2822,10 @@ and GenExportedTypesPass3 cenv (ce: ILExportedTypesAndForwarders) =
28222822
and GetManifsetAsAssemblyRow cenv m =
28232823
UnsharedRow
28242824
[|ULong m.AuxModuleHashAlgorithm
2825-
UShort (match m.Version with None -> 0us | Some (x, _, _, _) -> x)
2826-
UShort (match m.Version with None -> 0us | Some (_, y, _, _) -> y)
2827-
UShort (match m.Version with None -> 0us | Some (_, _, z, _) -> z)
2828-
UShort (match m.Version with None -> 0us | Some (_, _, _, w) -> w)
2825+
UShort (match m.Version with None -> 0us | Some (version) -> version.Major)
2826+
UShort (match m.Version with None -> 0us | Some (version) -> version.Minor)
2827+
UShort (match m.Version with None -> 0us | Some (version) -> version.Build)
2828+
UShort (match m.Version with None -> 0us | Some (version) -> version.Revision)
28292829
ULong
28302830
( (match m.AssemblyLongevity with
28312831
| ILAssemblyLongevity.Unspecified -> 0x0000
@@ -3091,9 +3091,8 @@ let writeILMetadataAndCode (generatePdb, desiredMetadataVersion, ilg, emitTailca
30913091

30923092
let (mdtableVersionMajor, mdtableVersionMinor) = metadataSchemaVersionSupportedByCLRVersion desiredMetadataVersion
30933093

3094-
let version =
3095-
let (a, b, c, _) = desiredMetadataVersion
3096-
System.Text.Encoding.UTF8.GetBytes (sprintf "v%d.%d.%d" a b c)
3094+
let version =
3095+
System.Text.Encoding.UTF8.GetBytes (sprintf "v%d.%d.%d" desiredMetadataVersion.Major desiredMetadataVersion.Minor desiredMetadataVersion.Build)
30973096

30983097

30993098
let paddedVersionLength = align 0x4 (Array.length version)
@@ -3634,7 +3633,7 @@ let writeBinaryAndReportMappings (outfile,
36343633
| ILScopeRef.Module(_) -> failwith "Expected mscorlib to be ILScopeRef.Assembly was ILScopeRef.Module"
36353634
| ILScopeRef.Assembly(aref) ->
36363635
match aref.Version with
3637-
| Some (2us, _, _, _) -> parseILVersion "2.0.50727.0"
3636+
| Some (version) when version.Major = 2us -> parseILVersion "2.0.50727.0"
36383637
| Some v -> v
36393638
| None -> failwith "Expected msorlib to have a version number"
36403639

src/fsharp/TastOps.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7004,13 +7004,13 @@ let tnames_SignatureDataVersionAttr = splitILTypeName tname_SignatureDataVersion
70047004

70057005
let tref_SignatureDataVersionAttr () = mkILTyRef(IlxSettings.ilxFsharpCoreLibScopeRef (), tname_SignatureDataVersionAttr)
70067006

7007-
let mkSignatureDataVersionAttr (g: TcGlobals) ((v1, v2, v3, _) : ILVersionInfo) =
7007+
let mkSignatureDataVersionAttr (g: TcGlobals) (version: ILVersionInfo) =
70087008
mkILCustomAttribute g.ilg
70097009
(tref_SignatureDataVersionAttr(),
70107010
[g.ilg.typ_Int32;g.ilg.typ_Int32;g.ilg.typ_Int32],
7011-
[ILAttribElem.Int32 (int32 v1)
7012-
ILAttribElem.Int32 (int32 v2)
7013-
ILAttribElem.Int32 (int32 v3)], [])
7011+
[ILAttribElem.Int32 (int32 version.Major)
7012+
ILAttribElem.Int32 (int32 version.Minor)
7013+
ILAttribElem.Int32 (int32 version.Build)], [])
70147014

70157015
let tname_AutoOpenAttr = FSharpLib.Core + ".AutoOpenAttribute"
70167016

@@ -7040,11 +7040,11 @@ let TryFindInternalsVisibleToAttr ilg cattr =
70407040
else
70417041
None
70427042

7043-
let IsMatchingSignatureDataVersionAttr ilg ((v1, v2, v3, _) : ILVersionInfo) cattr =
7043+
let IsMatchingSignatureDataVersionAttr ilg (version: ILVersionInfo) cattr =
70447044
IsSignatureDataVersionAttr cattr &&
70457045
match decodeILAttribData ilg cattr with
7046-
| [ILAttribElem.Int32 u1; ILAttribElem.Int32 u2;ILAttribElem.Int32 u3 ], _ ->
7047-
(v1 = uint16 u1) && (v2 = uint16 u2) && (v3 = uint16 u3)
7046+
| [ILAttribElem.Int32 u1; ILAttribElem.Int32 u2;ILAttribElem.Int32 u3 ], _ ->
7047+
(version.Major = uint16 u1) && (version.Minor = uint16 u2) && (version.Build = uint16 u3)
70487048
| _ ->
70497049
warning(Failure(FSComp.SR.tastUnexpectedDecodeOfInterfaceDataVersionAttribute()))
70507050
false

src/fsharp/TastPickle.fs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ let p_ILPublicKey x st =
903903
| PublicKey b -> p_byte 0 st; p_bytes b st
904904
| PublicKeyToken b -> p_byte 1 st; p_bytes b st
905905

906-
let p_ILVersion x st = p_tup4 p_uint16 p_uint16 p_uint16 p_uint16 x st
906+
let p_ILVersion (x: ILVersionInfo) st = p_tup4 p_uint16 p_uint16 p_uint16 p_uint16 (x.Major, x.Minor, x.Build, x.Revision) st
907907

908908
let p_ILModuleRef (x: ILModuleRef) st =
909909
p_tup3 p_string p_bool (p_option p_bytes) (x.Name, x.HasMetadata, x.Hash) st
@@ -926,7 +926,9 @@ let u_ILPublicKey st =
926926
| 1 -> u_bytes st |> PublicKeyToken
927927
| _ -> ufailwith st "u_ILPublicKey"
928928

929-
let u_ILVersion st = u_tup4 u_uint16 u_uint16 u_uint16 u_uint16 st
929+
let u_ILVersion st =
930+
let (major, minor, build, revision) = u_tup4 u_uint16 u_uint16 u_uint16 u_uint16 st
931+
ILVersionInfo(major, minor, build, revision)
930932

931933
let u_ILModuleRef st =
932934
let (a, b, c) = u_tup3 u_string u_bool (u_option u_bytes) st

src/fsharp/fsc.fs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -533,18 +533,18 @@ module VersionResourceFormat =
533533
for child in children do
534534
yield! child |]
535535

536-
let Version((v1, v2, v3, v4):ILVersionInfo) =
536+
let Version(version: ILVersionInfo) =
537537
[| // DWORD dwFileVersionMS
538538
// Specifies the most significant 32 bits of the file's binary
539539
// version number. This member is used with dwFileVersionLS to form a 64-bit value used
540540
// for numeric comparisons.
541-
yield! i32 (int32 v1 <<< 16 ||| int32 v2)
541+
yield! i32 (int32 version.Major <<< 16 ||| int32 version.Minor)
542542

543543
// DWORD dwFileVersionLS
544544
// Specifies the least significant 32 bits of the file's binary
545545
// version number. This member is used with dwFileVersionMS to form a 64-bit value used
546546
// for numeric comparisons.
547-
yield! i32 (int32 v3 <<< 16 ||| int32 v4)
547+
yield! i32 (int32 version.Build <<< 16 ||| int32 version.Revision)
548548
|]
549549

550550
let String(string, value) =
@@ -824,7 +824,7 @@ module MainModuleBuilder =
824824

825825
let productVersion findStringAttr (fileVersion: ILVersionInfo) =
826826
let attrName = "System.Reflection.AssemblyInformationalVersionAttribute"
827-
let toDotted (v1, v2, v3, v4) = sprintf "%d.%d.%d.%d" v1 v2 v3 v4
827+
let toDotted (version: ILVersionInfo) = sprintf "%d.%d.%d.%d" version.Major version.Minor version.Build version.Revision
828828
match findStringAttr attrName with
829829
| None | Some "" -> fileVersion |> toDotted
830830
| Some (AttributeHelpers.ILVersion(v)) -> v |> toDotted
@@ -840,7 +840,7 @@ module MainModuleBuilder =
840840
|> Seq.takeWhile ((<>) 0us)
841841
|> Seq.toList
842842
match validParts @ [0us; 0us; 0us; 0us] with
843-
| major :: minor :: build :: rev :: _ -> (major, minor, build, rev)
843+
| major :: minor :: build :: rev :: _ -> ILVersionInfo(major, minor, build, rev)
844844
| x -> failwithf "error converting product version '%s' to binary, tried '%A' " version x
845845

846846

@@ -986,8 +986,8 @@ module MainModuleBuilder =
986986
// specify the major language, and the high-order 6 bits specify the sublanguage.
987987
// For a table of valid identifiers see Language Identifiers. //
988988
// see e.g. http://msdn.microsoft.com/en-us/library/aa912040.aspx 0000 is neutral and 04b0(hex)=1252(dec) is the code page.
989-
[ ("000004b0", [ yield ("Assembly Version", (let v1, v2, v3, v4 = assemblyVersion in sprintf "%d.%d.%d.%d" v1 v2 v3 v4))
990-
yield ("FileVersion", (let v1, v2, v3, v4 = fileVersionInfo in sprintf "%d.%d.%d.%d" v1 v2 v3 v4))
989+
[ ("000004b0", [ yield ("Assembly Version", (sprintf "%d.%d.%d.%d" assemblyVersion.Major assemblyVersion.Minor assemblyVersion.Build assemblyVersion.Revision))
990+
yield ("FileVersion", (sprintf "%d.%d.%d.%d" fileVersionInfo.Major fileVersionInfo.Minor fileVersionInfo.Build fileVersionInfo.Revision))
991991
yield ("ProductVersion", productVersionString)
992992
match tcConfig.outputFile with
993993
| Some f -> yield ("OriginalFilename", Path.GetFileName(f))

0 commit comments

Comments
 (0)