Skip to content

Commit 707e712

Browse files
authored
fix 4604 - assembly level attributes aren't returned by FCS (#4611)
* fix 4604 * fix build * fix attributes of F# assemblies
1 parent a6b72a4 commit 707e712

File tree

9 files changed

+67
-47
lines changed

9 files changed

+67
-47
lines changed

src/fsharp/CompileOps.fs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2096,7 +2096,7 @@ type IRawFSharpAssemblyData =
20962096
abstract GetInternalsVisibleToAttributes : ILGlobals -> string list
20972097
/// The raw IL module definition in the assembly, if any. This is not present for cross-project references
20982098
/// in the language service
2099-
abstract TryGetRawILModule : unit -> ILModuleDef option
2099+
abstract TryGetILModuleDef : unit -> ILModuleDef option
21002100
/// The raw F# signature data in the assembly, if any
21012101
abstract GetRawFSharpSignatureData : range * ilShortAssemName: string * fileName: string -> (string * byte[]) list
21022102
/// The raw F# optimization data in the assembly, if any
@@ -2334,9 +2334,6 @@ type TcConfigBuilder =
23342334
isInvalidationSupported : bool
23352335

23362336
/// used to log sqm data
2337-
mutable sqmSessionGuid : System.Guid option
2338-
mutable sqmNumOfSourceFiles : int
2339-
sqmSessionStartedTime : int64
23402337
23412338
/// if true - every expression in quotations will be augmented with full debug info (filename, location in file)
23422339
mutable emitDebugInfoInQuotations : bool
@@ -2484,9 +2481,6 @@ type TcConfigBuilder =
24842481
noDebugData = false
24852482
isInteractive = false
24862483
isInvalidationSupported = false
2487-
sqmSessionGuid = None
2488-
sqmNumOfSourceFiles = 0
2489-
sqmSessionStartedTime = System.DateTime.UtcNow.Ticks
24902484
emitDebugInfoInQuotations = false
24912485
exename = None
24922486
copyFSharpCore = CopyFSharpCoreFlag.No
@@ -2955,9 +2949,6 @@ type TcConfig private (data : TcConfigBuilder, validate:bool) =
29552949
member x.isInteractive = data.isInteractive
29562950
member x.isInvalidationSupported = data.isInvalidationSupported
29572951
member x.emitDebugInfoInQuotations = data.emitDebugInfoInQuotations
2958-
member x.sqmSessionGuid = data.sqmSessionGuid
2959-
member x.sqmNumOfSourceFiles = data.sqmNumOfSourceFiles
2960-
member x.sqmSessionStartedTime = data.sqmSessionStartedTime
29612952
member x.copyFSharpCore = data.copyFSharpCore
29622953
member x.shadowCopyReferences = data.shadowCopyReferences
29632954
member x.tryGetMetadataSnapshot = data.tryGetMetadataSnapshot
@@ -3834,7 +3825,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR
38343825
interface IRawFSharpAssemblyData with
38353826
member __.GetAutoOpenAttributes(ilg) = GetAutoOpenAttributes ilg ilModule
38363827
member __.GetInternalsVisibleToAttributes(ilg) = GetInternalsVisibleToAttributes ilg ilModule
3837-
member __.TryGetRawILModule() = Some ilModule
3828+
member __.TryGetILModuleDef() = Some ilModule
38383829
member __.GetRawFSharpSignatureData(m, ilShortAssemName, filename) =
38393830
let resources = ilModule.Resources.AsList
38403831
let sigDataReaders =
@@ -4102,6 +4093,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
41024093
FileName = Some fileName
41034094
MemberSignatureEquality = (fun ty1 ty2 -> Tastops.typeEquivAux EraseAll g ty1 ty2)
41044095
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
4096+
TryGetILModuleDef = (fun () -> Some ilModule)
41054097
TypeForwarders = Map.empty }
41064098

41074099
let ccu = CcuThunk.Create(ilShortAssemName, ccuData)
@@ -4404,8 +4396,8 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44044396
member tcImports.PrepareToImportReferencedILAssembly (ctok, m, filename, dllinfo:ImportedBinary) =
44054397
CheckDisposed()
44064398
let tcConfig = tcConfigP.Get(ctok)
4407-
assert dllinfo.RawMetadata.TryGetRawILModule().IsSome
4408-
let ilModule = dllinfo.RawMetadata.TryGetRawILModule().Value
4399+
assert dllinfo.RawMetadata.TryGetILModuleDef().IsSome
4400+
let ilModule = dllinfo.RawMetadata.TryGetILModuleDef().Value
44094401
let ilScopeRef = dllinfo.ILScopeRef
44104402
let aref =
44114403
match ilScopeRef with
@@ -4453,7 +4445,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44534445
let ccuRawDataAndInfos =
44544446
ilModule.GetRawFSharpSignatureData(m, ilShortAssemName, filename)
44554447
|> List.map (fun (ccuName, sigDataReader) ->
4456-
let data = GetSignatureData (filename, ilScopeRef, ilModule.TryGetRawILModule(), sigDataReader)
4448+
let data = GetSignatureData (filename, ilScopeRef, ilModule.TryGetILModuleDef(), sigDataReader)
44574449

44584450
let optDatas = Map.ofList optDataReaders
44594451

@@ -4478,6 +4470,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44784470
IsProviderGenerated = false
44794471
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
44804472
#endif
4473+
TryGetILModuleDef = ilModule.TryGetILModuleDef
44814474
UsesFSharp20PlusQuotations = minfo.usesQuotations
44824475
MemberSignatureEquality= (fun ty1 ty2 -> Tastops.typeEquivAux EraseAll (tcImports.GetTcGlobals()) ty1 ty2)
44834476
TypeForwarders = ImportILAssemblyTypeForwarders(tcImports.GetImportMap, m, ilModule.GetRawTypeForwarders()) }
@@ -4491,7 +4484,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44914484
if verbose then dprintf "*** no optimization data for CCU %s, was DLL compiled with --no-optimization-data??\n" ccuName
44924485
None
44934486
| Some info ->
4494-
let data = GetOptimizationData (filename, ilScopeRef, ilModule.TryGetRawILModule(), info)
4487+
let data = GetOptimizationData (filename, ilScopeRef, ilModule.TryGetILModuleDef(), info)
44954488
let res = data.OptionalFixup(fun nm -> availableToOptionalCcu(tcImports.FindCcu(ctok, m, nm, lookupOnly=false)))
44964489
if verbose then dprintf "found optimization data for CCU %s\n" ccuName
44974490
Some res)
@@ -4508,7 +4501,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
45084501
ILScopeRef = ilScopeRef }
45094502
let phase2() =
45104503
#if !NO_EXTENSIONTYPING
4511-
match ilModule.TryGetRawILModule() with
4504+
match ilModule.TryGetILModuleDef() with
45124505
| None -> () // no type providers can be used without a real IL Module present
45134506
| Some ilModule ->
45144507
ccuinfo.TypeProviders <- tcImports.ImportTypeProviderExtensions (ctok, tcConfig, filename, ilScopeRef, ilModule.ManifestOfAssembly.CustomAttrs.AsList, ccu.Contents, invalidateCcu, m)
@@ -5376,6 +5369,7 @@ let GetInitialTcState(m, ccuName, tcConfig:TcConfig, tcGlobals, tcImports:TcImpo
53765369
IsProviderGenerated = false
53775370
ImportProvidedType = (fun ty -> Import.ImportProvidedType (tcImports.GetImportMap()) m ty)
53785371
#endif
5372+
TryGetILModuleDef = (fun () -> None)
53795373
FileName=None
53805374
Stamp = newStamp()
53815375
QualifiedName= None

src/fsharp/CompileOps.fsi

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ type IRawFSharpAssemblyData =
145145
abstract GetInternalsVisibleToAttributes: ILGlobals -> string list
146146
/// The raw IL module definition in the assembly, if any. This is not present for cross-project references
147147
/// in the language service
148-
abstract TryGetRawILModule: unit -> ILModuleDef option
148+
abstract TryGetILModuleDef: unit -> ILModuleDef option
149149
abstract HasAnyFSharpSignatureDataAttribute: bool
150150
abstract HasMatchingFSharpSignatureDataAttribute: ILGlobals -> bool
151151
/// The raw F# signature data in the assembly, if any
@@ -355,9 +355,6 @@ type TcConfigBuilder =
355355
/// If true, indicates all type checking and code generation is in the context of fsi.exe
356356
isInteractive: bool
357357
isInvalidationSupported: bool
358-
mutable sqmSessionGuid: System.Guid option
359-
mutable sqmNumOfSourceFiles: int
360-
sqmSessionStartedTime: int64
361358
mutable emitDebugInfoInQuotations: bool
362359
mutable exename: string option
363360
mutable copyFSharpCore: CopyFSharpCoreFlag
@@ -524,9 +521,6 @@ type TcConfig =
524521
/// File system query based on TcConfig settings
525522
member MakePathAbsolute: string -> string
526523

527-
member sqmSessionGuid: System.Guid option
528-
member sqmNumOfSourceFiles: int
529-
member sqmSessionStartedTime: int64
530524
member copyFSharpCore: CopyFSharpCoreFlag
531525
member shadowCopyReferences: bool
532526
static member Create: TcConfigBuilder * validate: bool -> TcConfig

src/fsharp/CompileOptions.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -851,16 +851,16 @@ let testFlag tcConfigB =
851851
let vsSpecificFlags (tcConfigB: TcConfigBuilder) =
852852
[ CompilerOption("vserrors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.VSErrors), None, None)
853853
CompilerOption("validate-type-providers", tagNone, OptionUnit (id), None, None) // preserved for compatibility's sake, no longer has any effect
854-
CompilerOption("LCID", tagInt, OptionInt (fun _n -> ()), None, None)
854+
CompilerOption("LCID", tagInt, OptionInt ignore, None, None)
855855
CompilerOption("flaterrors", tagNone, OptionUnit (fun () -> tcConfigB.flatErrors <- true), None, None)
856-
CompilerOption("sqmsessionguid", tagNone, OptionString (fun s -> tcConfigB.sqmSessionGuid <- try System.Guid(s) |> Some with e -> None), None, None)
856+
CompilerOption("sqmsessionguid", tagNone, OptionString ignore, None, None)
857857
CompilerOption("gccerrors", tagNone, OptionUnit (fun () -> tcConfigB.errorStyle <- ErrorStyle.GccErrors), None, None)
858858
CompilerOption("exename", tagNone, OptionString (fun s -> tcConfigB.exename <- Some(s)), None, None)
859859
CompilerOption("maxerrors", tagInt, OptionInt (fun n -> tcConfigB.maxErrors <- n), None, None) ]
860860

861861
let internalFlags (tcConfigB:TcConfigBuilder) =
862862
[
863-
CompilerOption("stamps", tagNone, OptionUnit (fun () -> ()), Some(InternalCommandLineOption("--stamps", rangeCmdArgs)), None)
863+
CompilerOption("stamps", tagNone, OptionUnit ignore, Some(InternalCommandLineOption("--stamps", rangeCmdArgs)), None)
864864
CompilerOption("ranges", tagNone, OptionSet Tastops.DebugPrint.layoutRanges, Some(InternalCommandLineOption("--ranges", rangeCmdArgs)), None)
865865
CompilerOption("terms" , tagNone, OptionUnit (fun () -> tcConfigB.showTerms <- true), Some(InternalCommandLineOption("--terms", rangeCmdArgs)), None)
866866
CompilerOption("termsfile" , tagNone, OptionUnit (fun () -> tcConfigB.writeTermsToFiles <- true), Some(InternalCommandLineOption("--termsfile", rangeCmdArgs)), None)

src/fsharp/fsc.fs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,6 @@ type DisposablesTracker() =
168168
try i.Dispose() with _ -> ()
169169

170170

171-
//----------------------------------------------------------------------------
172-
// TypeCheck, AdjustForScriptCompile
173-
//----------------------------------------------------------------------------
174-
175171
let TypeCheck (ctok, tcConfig, tcImports, tcGlobals, errorLogger:ErrorLogger, assemblyName, niceNameGen, tcEnv0, inputs, exiter: Exiter) =
176172
try
177173
if isNil inputs then error(Error(FSComp.SR.fscNoImplementationFiles(), Range.rangeStartup))
@@ -1346,7 +1342,7 @@ module StaticLinker =
13461342
| ResolvedCcu ccu -> Some ccu
13471343
| UnresolvedCcu(_ccuName) -> None
13481344

1349-
let modul = dllInfo.RawMetadata.TryGetRawILModule().Value
1345+
let modul = dllInfo.RawMetadata.TryGetILModuleDef().Value
13501346
yield (ccu, dllInfo.ILScopeRef, modul), (ilAssemRef.Name, provAssemStaticLinkInfo)
13511347
| None -> () ]
13521348

@@ -1714,7 +1710,6 @@ let main0(ctok, argv, legacyReferenceResolver, bannerAlreadyPrinted, reduceMemor
17141710
delayForFlagsLogger.ForwardDelayedDiagnostics(tcConfigB)
17151711
exiter.Exit 1
17161712

1717-
tcConfigB.sqmNumOfSourceFiles <- sourceFiles.Length
17181713
tcConfigB.conditionalCompilationDefines <- "COMPILED" :: tcConfigB.conditionalCompilationDefines
17191714
displayBannerIfNeeded tcConfigB
17201715

@@ -1823,10 +1818,12 @@ let main0(ctok, argv, legacyReferenceResolver, bannerAlreadyPrinted, reduceMemor
18231818

18241819
Args (ctok, tcGlobals, tcImports, frameworkTcImports, tcState.Ccu, typedAssembly, topAttrs, tcConfig, outfile, pdbfile, assemblyName, errorLogger, exiter)
18251820

1826-
let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, generatedCcu, typedImplFiles, topAttrs, tcConfig: TcConfig, outfile, pdbfile, assemblyName, errorLogger, exiter: Exiter)) =
1821+
let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, generatedCcu: CcuThunk, typedImplFiles, topAttrs, tcConfig: TcConfig, outfile, pdbfile, assemblyName, errorLogger, exiter: Exiter)) =
18271822

18281823
if tcConfig.typeCheckOnly then exiter.Exit 0
18291824

1825+
generatedCcu.Contents.SetAttribs(generatedCcu.Contents.Attribs @ topAttrs.assemblyAttrs)
1826+
18301827
use unwindPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.CodeGen
18311828
let signingInfo = ValidateKeySigningAttributes (tcConfig, tcGlobals, topAttrs)
18321829

@@ -1872,7 +1869,8 @@ let main1(Args (ctok, tcGlobals, tcImports: TcImports, frameworkTcImports, gener
18721869
Args (ctok, tcConfig, tcImports, frameworkTcImports, tcGlobals, errorLogger, generatedCcu, outfile, typedImplFiles, topAttrs, pdbfile, assemblyName, assemVerFromAttrib, signingInfo, exiter)
18731870

18741871

1875-
// set up typecheck for given AST without parsing any command line parameters
1872+
// This is for the compile-from-AST feature of FCS.
1873+
// TODO: consider removing this feature from FCS, which as far as I know is not used by anyone.
18761874
let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName, target, outfile, pdbFile, dllReferences, noframework, exiter, errorLoggerProvider: ErrorLoggerProvider, inputs : ParsedInput list) =
18771875

18781876
let tryGetMetadataSnapshot = (fun _ -> None)
@@ -1893,7 +1891,6 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName,
18931891
| None -> OptionSwitch.Off)
18941892
SetTailcallSwitch tcConfigB OptionSwitch.On
18951893
tcConfigB.target <- target
1896-
tcConfigB.sqmNumOfSourceFiles <- 1
18971894

18981895
let errorLogger = errorLoggerProvider.CreateErrorLoggerUpToMaxErrors (tcConfigB, exiter)
18991896

@@ -1930,6 +1927,7 @@ let main1OfAst (ctok, legacyReferenceResolver, reduceMemoryUsage, assemblyName,
19301927
TypeCheck(ctok, tcConfig, tcImports, tcGlobals, errorLogger, assemblyName, NiceNameGenerator(), tcEnv0, inputs,exiter)
19311928

19321929
let generatedCcu = tcState.Ccu
1930+
generatedCcu.Contents.SetAttribs(generatedCcu.Contents.Attribs @ topAttrs.assemblyAttrs)
19331931

19341932
use unwindPhase = PushThreadBuildPhaseUntilUnwind (BuildPhase.CodeGen)
19351933
let signingInfo = ValidateKeySigningAttributes (tcConfig, tcGlobals, topAttrs)
@@ -1972,7 +1970,7 @@ let main2a(Args (ctok, tcConfig, tcImports, frameworkTcImports: TcImports, tcGlo
19721970
let metadataVersion =
19731971
match tcConfig.metadataVersion with
19741972
| Some v -> v
1975-
| _ -> match (frameworkTcImports.DllTable.TryFind tcConfig.primaryAssembly.Name) with | Some ib -> ib.RawMetadata.TryGetRawILModule().Value.MetadataVersion | _ -> ""
1973+
| _ -> match (frameworkTcImports.DllTable.TryFind tcConfig.primaryAssembly.Name) with | Some ib -> ib.RawMetadata.TryGetILModuleDef().Value.MetadataVersion | _ -> ""
19761974
let optimizedImpls, optimizationData, _ = ApplyAllOptimizations (tcConfig, tcGlobals, (LightweightTcValForUsingInBuildMethodCall tcGlobals), outfile, importMap, false, optEnv0, generatedCcu, typedImplFiles)
19771975

19781976
AbortOnError(errorLogger, exiter)

src/fsharp/import.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -553,10 +553,10 @@ let ImportILAssemblyTypeForwarders (amap, m, exportedTypes:ILExportedTypesAndFor
553553

554554

555555
/// Import an IL assembly as a new TAST CCU
556-
let ImportILAssembly(amap:(unit -> ImportMap),m,auxModuleLoader,sref,sourceDir,filename,ilModule:ILModuleDef,invalidateCcu:IEvent<string>) =
556+
let ImportILAssembly(amap:(unit -> ImportMap), m, auxModuleLoader, ilScopeRef, sourceDir, filename, ilModule:ILModuleDef, invalidateCcu:IEvent<string>) =
557557
invalidateCcu |> ignore
558558
let aref =
559-
match sref with
559+
match ilScopeRef with
560560
| ILScopeRef.Assembly aref -> aref
561561
| _ -> error(InternalError("ImportILAssembly: cannot reference .NET netmodules directly, reference the containing assembly instead",m))
562562
let nm = aref.Name
@@ -569,13 +569,14 @@ let ImportILAssembly(amap:(unit -> ImportMap),m,auxModuleLoader,sref,sourceDir,f
569569
IsProviderGenerated = false
570570
ImportProvidedType = (fun ty -> ImportProvidedType (amap()) m ty)
571571
#endif
572-
QualifiedName= Some sref.QualifiedName
573-
Contents = NewCcuContents sref m nm mty
574-
ILScopeRef = sref
572+
QualifiedName= Some ilScopeRef.QualifiedName
573+
Contents = NewCcuContents ilScopeRef m nm mty
574+
ILScopeRef = ilScopeRef
575575
Stamp = newStamp()
576576
SourceCodeDirectory = sourceDir // note: not an accurate value, but IL assemblies don't give us this information in any attributes.
577577
FileName = filename
578578
MemberSignatureEquality= (fun ty1 ty2 -> Tastops.typeEquivAux EraseAll (amap()).g ty1 ty2)
579+
TryGetILModuleDef = (fun () -> Some ilModule)
579580
TypeForwarders =
580581
(match ilModule.Manifest with
581582
| None -> Map.empty

src/fsharp/service/IncrementalBuild.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1176,7 +1176,7 @@ type RawFSharpAssemblyDataBackedByLanguageService (tcConfig, tcGlobals, tcState:
11761176
interface IRawFSharpAssemblyData with
11771177
member __.GetAutoOpenAttributes(_ilg) = autoOpenAttrs
11781178
member __.GetInternalsVisibleToAttributes(_ilg) = ivtAttrs
1179-
member __.TryGetRawILModule() = None
1179+
member __.TryGetILModuleDef() = None
11801180
member __.GetRawFSharpSignatureData(_m, _ilShortAssemName, _filename) = sigData
11811181
member __.GetRawFSharpOptimizationData(_m, _ilShortAssemName, _filename) = [ ]
11821182
member __.GetRawTypeForwarders() = mkILExportedTypes [] // TODO: cross-project references with type forwarders

src/fsharp/symbols/Symbols.fs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2173,11 +2173,25 @@ and FSharpAssemblySignature private (cenv, topAttribs: TypeChecker.TopAttribs op
21732173
loop mtyp |> makeReadOnlyCollection
21742174

21752175
member __.Attributes =
2176-
match topAttribs with
2177-
| None -> makeReadOnlyCollection []
2178-
| Some tA ->
2179-
tA.assemblyAttrs
2180-
|> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))) |> makeReadOnlyCollection
2176+
[ match optViewedCcu with
2177+
| Some ccu ->
2178+
match ccu.TryGetILModuleDef() with
2179+
| Some ilModule ->
2180+
match ilModule.Manifest with
2181+
| None -> ()
2182+
| Some manifest ->
2183+
for a in AttribInfosOfIL cenv.g cenv.amap cenv.thisCcu.ILScopeRef range0 manifest.CustomAttrs do
2184+
yield FSharpAttribute(cenv, a)
2185+
| None ->
2186+
// If no module is available, then look in the CCU contents.
2187+
if ccu.IsFSharp then
2188+
for a in ccu.Contents.Attribs do
2189+
yield FSharpAttribute(cenv, FSAttribInfo (cenv.g, a))
2190+
| None ->
2191+
match topAttribs with
2192+
| None -> ()
2193+
| Some tA -> for a in tA.assemblyAttrs do yield FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)) ]
2194+
|> makeReadOnlyCollection
21812195

21822196
member __.FindEntityByPath path =
21832197
let inline findNested name = function

0 commit comments

Comments
 (0)