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

Commit707e712

Browse files
authored
fix 4604 - assembly level attributes aren't returned by FCS (dotnet#4611)
* fix 4604* fix build* fix attributes of F# assemblies
1 parenta6b72a4 commit707e712

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
abstractGetInternalsVisibleToAttributes :ILGlobals->stringlist
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-
abstractTryGetRawILModule :unit->ILModuleDefoption
2099+
abstractTryGetILModuleDef :unit->ILModuleDefoption
21002100
/// The raw F# signature data in the assembly, if any
21012101
abstractGetRawFSharpSignatureData :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
memberx.isInteractive= data.isInteractive
29562950
memberx.isInvalidationSupported= data.isInvalidationSupported
29572951
memberx.emitDebugInfoInQuotations= data.emitDebugInfoInQuotations
2958-
memberx.sqmSessionGuid= data.sqmSessionGuid
2959-
memberx.sqmNumOfSourceFiles= data.sqmNumOfSourceFiles
2960-
memberx.sqmSessionStartedTime= data.sqmSessionStartedTime
29612952
memberx.copyFSharpCore= data.copyFSharpCore
29622953
memberx.shadowCopyReferences= data.shadowCopyReferences
29632954
memberx.tryGetMetadataSnapshot= data.tryGetMetadataSnapshot
@@ -3834,7 +3825,7 @@ type RawFSharpAssemblyDataBackedByFileOnDisk (ilModule: ILModuleDef, ilAssemblyR
38343825
interface IRawFSharpAssemblyDatawith
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
letresources= ilModule.Resources.AsList
38403831
letsigDataReaders=
@@ -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
letccu= CcuThunk.Create(ilShortAssemName, ccuData)
@@ -4404,8 +4396,8 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44044396
membertcImports.PrepareToImportReferencedILAssembly(ctok,m,filename,dllinfo:ImportedBinary)=
44054397
CheckDisposed()
44064398
lettcConfig= tcConfigP.Get(ctok)
4407-
assert dllinfo.RawMetadata.TryGetRawILModule().IsSome
4408-
letilModule= dllinfo.RawMetadata.TryGetRawILModule().Value
4399+
assert dllinfo.RawMetadata.TryGetILModuleDef().IsSome
4400+
letilModule= dllinfo.RawMetadata.TryGetILModuleDef().Value
44094401
letilScopeRef= dllinfo.ILScopeRef
44104402
letaref=
44114403
match ilScopeRefwith
@@ -4453,7 +4445,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
44534445
letccuRawDataAndInfos=
44544446
ilModule.GetRawFSharpSignatureData(m, ilShortAssemName, filename)
44554447
|> List.map(fun(ccuName,sigDataReader)->
4456-
letdata= GetSignatureData(filename, ilScopeRef, ilModule.TryGetRawILModule(), sigDataReader)
4448+
letdata= GetSignatureData(filename, ilScopeRef, ilModule.TryGetILModuleDef(), sigDataReader)
44574449

44584450
letoptDatas= 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 verbosethen dprintf"*** no optimization data for CCU%s, was DLL compiled with --no-optimization-data??\n" ccuName
44924485
None
44934486
| Some info->
4494-
letdata= GetOptimizationData(filename, ilScopeRef, ilModule.TryGetRawILModule(), info)
4487+
letdata= GetOptimizationData(filename, ilScopeRef, ilModule.TryGetILModuleDef(), info)
44954488
letres= data.OptionalFixup(fun nm-> availableToOptionalCcu(tcImports.FindCcu(ctok, m, nm, lookupOnly=false)))
44964489
if verbosethen 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
letphase2()=
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
abstractGetInternalsVisibleToAttributes:ILGlobals->stringlist
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-
abstractTryGetRawILModule:unit->ILModuleDefoption
148+
abstractTryGetILModuleDef:unit->ILModuleDefoption
149149
abstractHasAnyFSharpSignatureDataAttribute:bool
150150
abstractHasMatchingFSharpSignatureDataAttribute: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
letvsSpecificFlags(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, OptionIntignore, 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)|> Somewith e-> None), None, None)
856+
CompilerOption("sqmsessionguid", tagNone, OptionStringignore, 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
letinternalFlags(tcConfigB:TcConfigBuilder)=
862862
[
863-
CompilerOption("stamps", tagNone, OptionUnit(fun()->()), Some(InternalCommandLineOption("--stamps", rangeCmdArgs)), None)
863+
CompilerOption("stamps", tagNone, OptionUnitignore, 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
letTypeCheck(ctok,tcConfig,tcImports,tcGlobals,errorLogger:ErrorLogger,assemblyName,niceNameGen,tcEnv0,inputs,exiter:Exiter)=
176172
try
177173
if isNil inputsthen error(Error(FSComp.SR.fscNoImplementationFiles(), Range.rangeStartup))
@@ -1346,7 +1342,7 @@ module StaticLinker =
13461342
| ResolvedCcu ccu-> Some ccu
13471343
| UnresolvedCcu(_ccuName)-> None
13481344

1349-
letmodul= dllInfo.RawMetadata.TryGetRawILModule().Value
1345+
letmodul= 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.Exit1
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-
letmain1(Args(ctok,tcGlobals,tcImports:TcImports,frameworkTcImports,generatedCcu,typedImplFiles,topAttrs,tcConfig:TcConfig,outfile,pdbfile,assemblyName,errorLogger,exiter:Exiter))=
1821+
letmain1(Args(ctok,tcGlobals,tcImports:TcImports,frameworkTcImports,generatedCcu:CcuThunk,typedImplFiles,topAttrs,tcConfig:TcConfig,outfile,pdbfile,assemblyName,errorLogger,exiter:Exiter))=
18271822

18281823
if tcConfig.typeCheckOnlythen exiter.Exit0
18291824

1825+
generatedCcu.Contents.SetAttribs(generatedCcu.Contents.Attribs@ topAttrs.assemblyAttrs)
1826+
18301827
use unwindPhase= PushThreadBuildPhaseUntilUnwind BuildPhase.CodeGen
18311828
letsigningInfo= 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
letmain1OfAst(ctok,legacyReferenceResolver,reduceMemoryUsage,assemblyName,target,outfile,pdbFile,dllReferences,noframework,exiter,errorLoggerProvider:ErrorLoggerProvider,inputs:ParsedInput list)=
18771875

18781876
lettryGetMetadataSnapshot=(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
leterrorLogger= 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
letgeneratedCcu= tcState.Ccu
1930+
generatedCcu.Contents.SetAttribs(generatedCcu.Contents.Attribs@ topAttrs.assemblyAttrs)
19331931

19341932
use unwindPhase= PushThreadBuildPhaseUntilUnwind(BuildPhase.CodeGen)
19351933
letsigningInfo= ValidateKeySigningAttributes(tcConfig, tcGlobals, topAttrs)
@@ -1972,7 +1970,7 @@ let main2a(Args (ctok, tcConfig, tcImports, frameworkTcImports: TcImports, tcGlo
19721970
letmetadataVersion=
19731971
match tcConfig.metadataVersionwith
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
letoptimizedImpls,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-
letImportILAssembly(amap:(unit-> ImportMap),m,auxModuleLoader,sref,sourceDir,filename,ilModule:ILModuleDef,invalidateCcu:IEvent<string>)=
556+
letImportILAssembly(amap:(unit-> ImportMap),m,auxModuleLoader,ilScopeRef,sourceDir,filename,ilModule:ILModuleDef,invalidateCcu:IEvent<string>)=
557557
invalidateCcu|> ignore
558558
letaref=
559-
matchsrefwith
559+
matchilScopeRefwith
560560
| ILScopeRef.Assembly aref-> aref
561561
|_-> error(InternalError("ImportILAssembly: cannot reference .NET netmodules directly, reference the containing assembly instead",m))
562562
letnm= 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= Somesref.QualifiedName
573-
Contents= NewCcuContentssref m nm mty
574-
ILScopeRef=sref
572+
QualifiedName= SomeilScopeRef.QualifiedName
573+
Contents= NewCcuContentsilScopeRef 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.Manifestwith
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 IRawFSharpAssemblyDatawith
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 topAttribswith
2177-
| None-> makeReadOnlyCollection[]
2178-
| Some tA->
2179-
tA.assemblyAttrs
2180-
|> List.map(fun a-> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)))|> makeReadOnlyCollection
2176+
[match optViewedCcuwith
2177+
| Some ccu->
2178+
match ccu.TryGetILModuleDef()with
2179+
| Some ilModule->
2180+
match ilModule.Manifestwith
2181+
| None->()
2182+
| Some manifest->
2183+
for ain AttribInfosOfIL cenv.g cenv.amap cenv.thisCcu.ILScopeRef range0 manifest.CustomAttrsdo
2184+
yield FSharpAttribute(cenv, a)
2185+
| None->
2186+
// If no module is available, then look in the CCU contents.
2187+
if ccu.IsFSharpthen
2188+
for ain ccu.Contents.Attribsdo
2189+
yield FSharpAttribute(cenv, FSAttribInfo(cenv.g, a))
2190+
| None->
2191+
match topAttribswith
2192+
| None->()
2193+
| Some tA->for ain tA.assemblyAttrsdoyield FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a))]
2194+
|> makeReadOnlyCollection
21812195

21822196
member__.FindEntityByPath path=
21832197
let inlinefindNested name=function

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp