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

Commit0bea66a

Browse files
auduchinokKevinRansom
authored andcommitted
Always emit conditional attributes in FCS (dotnet#6004)
* Always emit conditional attributes in FCS (fixesdotnet#3890)* Add test* Cleanup test* Add internal compiler switch, emit conditional method calls* Update test* Make noConditionalErasure lowercase
1 parent2b2a641 commit0bea66a

File tree

6 files changed

+53
-16
lines changed

6 files changed

+53
-16
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,6 +2356,8 @@ type TcConfigBuilder =
23562356
mutable tryGetMetadataSnapshot:ILReaderTryGetMetadataSnapshot
23572357

23582358
mutable internalTestSpanStackReferring:bool
2359+
2360+
mutable noConditionalErasure:bool
23592361
}
23602362

23612363
static memberInitial=
@@ -2493,6 +2495,7 @@ type TcConfigBuilder =
24932495
shadowCopyReferences=false
24942496
tryGetMetadataSnapshot=(fun _-> None)
24952497
internalTestSpanStackReferring=false
2498+
noConditionalErasure=false
24962499
}
24972500

24982501
static memberCreateNew(legacyReferenceResolver,defaultFSharpBinariesDir,reduceMemoryUsage,implicitIncludeDir,
@@ -2954,6 +2957,8 @@ type TcConfig private (data : TcConfigBuilder, validate:bool) =
29542957
memberx.shadowCopyReferences= data.shadowCopyReferences
29552958
memberx.tryGetMetadataSnapshot= data.tryGetMetadataSnapshot
29562959
memberx.internalTestSpanStackReferring= data.internalTestSpanStackReferring
2960+
memberx.noConditionalErasure= data.noConditionalErasure
2961+
29572962
static memberCreate(builder,validate)=
29582963
use unwindBuildPhase= PushThreadBuildPhaseUntilUnwind BuildPhase.Parameter
29592964
TcConfig(builder, validate)
@@ -5447,9 +5452,12 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig:TcConfig, tcImports:Tc
54475452
if Zset.contains qualNameOfFile tcState.tcsRootImplsthen
54485453
errorR(Error(FSComp.SR.buildImplementationAlreadyGivenDetail(qualNameOfFile.Text), m))
54495454

5455+
letconditionalDefines=
5456+
if tcConfig.noConditionalErasurethen Noneelse Some(tcConfig.conditionalCompilationDefines)
5457+
54505458
// Typecheck the signature file
54515459
let!(tcEnv,sigFileType,createsGeneratedProvidedTypes)=
5452-
TypeCheckOneSigFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors,tcConfig.conditionalCompilationDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcState.tcsTcSigEnv file
5460+
TypeCheckOneSigFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors,conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcState.tcsTcSigEnv file
54535461

54545462
letrootSigs= Zmap.add qualNameOfFile sigFileType tcState.tcsRootSigs
54555463

@@ -5484,9 +5492,12 @@ let TypeCheckOneInputEventually (checkForErrors, tcConfig:TcConfig, tcImports:Tc
54845492

54855493
lettcImplEnv= tcState.tcsTcImplEnv
54865494

5495+
letconditionalDefines=
5496+
if tcConfig.noConditionalErasurethen Noneelse Some(tcConfig.conditionalCompilationDefines)
5497+
54875498
// Typecheck the implementation file
54885499
let!topAttrs,implFile,_implFileHiddenType,tcEnvAtEnd,createsGeneratedProvidedTypes=
5489-
TypeCheckOneImplFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors,tcConfig.conditionalCompilationDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
5500+
TypeCheckOneImplFile(tcGlobals, tcState.tcsNiceNameGen, amap, tcState.tcsCcu, checkForErrors,conditionalDefines, tcSink, tcConfig.internalTestSpanStackReferring) tcImplEnv rootSigOpt file
54905501

54915502
lethadSig= rootSigOpt.IsSome
54925503
letimplFileSigType= SigTypeOfImplFile implFile

‎src/fsharp/CompileOps.fsi‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ type TcConfigBuilder =
367367

368368
/// if true - 'let mutable x = Span.Empty', the value 'x' is a stack referring span. Used for internal testing purposes only until we get true stack spans.
369369
mutable internalTestSpanStackReferring:bool
370+
371+
/// Prevent erasure of conditional attributes and methods so tooling is able analyse them.
372+
mutable noConditionalErasure:bool
370373
}
371374

372375
static memberInitial:TcConfigBuilder

‎src/fsharp/CompileOptions.fs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -848,16 +848,17 @@ let testFlag tcConfigB =
848848
| str-> warning(Error(FSComp.SR.optsUnknownArgumentToTheTestSwitch(str),rangeCmdArgs))), None,
849849
None)
850850

851-
//not shown in fsc.exe help, no warning on use, motivation is for use fromVS
852-
letvsSpecificFlags(tcConfigB:TcConfigBuilder)=
851+
//Not shown in fsc.exe help, no warning on use, motivation is for use fromtooling.
852+
leteditorSpecificFlags(tcConfigB:TcConfigBuilder)=
853853
[ CompilerOption("vserrors", tagNone, OptionUnit(fun()-> tcConfigB.errorStyle<- ErrorStyle.VSErrors), None, None)
854854
CompilerOption("validate-type-providers", tagNone, OptionUnit(id), None, None)// preserved for compatibility's sake, no longer has any effect
855855
CompilerOption("LCID", tagInt, OptionInt ignore, None, None)
856856
CompilerOption("flaterrors", tagNone, OptionUnit(fun()-> tcConfigB.flatErrors<-true), None, None)
857857
CompilerOption("sqmsessionguid", tagNone, OptionString ignore, None, None)
858858
CompilerOption("gccerrors", tagNone, OptionUnit(fun()-> tcConfigB.errorStyle<- ErrorStyle.GccErrors), None, None)
859859
CompilerOption("exename", tagNone, OptionString(fun s-> tcConfigB.exename<- Some(s)), None, None)
860-
CompilerOption("maxerrors", tagInt, OptionInt(fun n-> tcConfigB.maxErrors<- n), None, None)]
860+
CompilerOption("maxerrors", tagInt, OptionInt(fun n-> tcConfigB.maxErrors<- n), None, None)
861+
CompilerOption("noconditionalerasure", tagNone, OptionUnit(fun()-> tcConfigB.noConditionalErasure<-true), None, None)]
861862

862863
letinternalFlags(tcConfigB:TcConfigBuilder)=
863864
[
@@ -896,7 +897,7 @@ let internalFlags (tcConfigB:TcConfigBuilder) =
896897
CompilerOption("alwayscallvirt",tagNone,OptionSwitch(callVirtSwitch tcConfigB),Some(InternalCommandLineOption("alwayscallvirt",rangeCmdArgs)), None)
897898
CompilerOption("nodebugdata",tagNone, OptionUnit(fun()-> tcConfigB.noDebugData<-true),Some(InternalCommandLineOption("--nodebugdata",rangeCmdArgs)), None)
898899
testFlag tcConfigB]@
899-
vsSpecificFlags tcConfigB@
900+
editorSpecificFlags tcConfigB@
900901
[ CompilerOption("jit", tagNone, OptionSwitch(jitoptimizeSwitch tcConfigB), Some(InternalCommandLineOption("jit", rangeCmdArgs)), None)
901902
CompilerOption("localoptimize", tagNone, OptionSwitch(localoptimizeSwitch tcConfigB),Some(InternalCommandLineOption("localoptimize", rangeCmdArgs)), None)
902903
CompilerOption("splitting", tagNone, OptionSwitch(splittingSwitch tcConfigB),Some(InternalCommandLineOption("splitting", rangeCmdArgs)), None)

‎src/fsharp/TypeChecker.fs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,8 +504,8 @@ type cenv =
504504
/// Used to resolve names
505505
nameResolver: NameResolver
506506

507-
/// The set of active conditional defines
508-
conditionalDefines: string list
507+
/// The set of active conditional defines. The value is None when conditional erasure is disabled in tooling.
508+
conditionalDefines: string list option
509509

510510
isInternalTestSpanStackReferring: bool
511511
}
@@ -3004,8 +3004,8 @@ let BuildPossiblyConditionalMethodCall cenv env isMutable m isProp minfo valUseF
30043004

30053005
let conditionalCallDefineOpt = TryFindMethInfoStringAttribute cenv.g m cenv.g.attrib_ConditionalAttribute minfo
30063006

3007-
match conditionalCallDefineOpt with
3008-
| Some dwhen not (List.contains dcenv.conditionalDefines) ->
3007+
match conditionalCallDefineOpt, cenv.conditionalDefines with
3008+
| Some d, Some defineswhen not (List.contains ddefines) ->
30093009

30103010
// Methods marked with 'Conditional' must return 'unit'
30113011
UnifyTypes cenv env m cenv.g.unit_ty (minfo.GetFSharpReturnTy(cenv.amap, m, minst))
@@ -10828,11 +10828,10 @@ and TcAttribute canFail cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
1082810828

1082910829
let conditionalCallDefineOpt = TryFindTyconRefStringAttribute cenv.g mAttr cenv.g.attrib_ConditionalAttribute tcref
1083010830

10831-
match conditionalCallDefineOpt with
10832-
| Some dwhen not (List.contains dcenv.conditionalDefines) ->
10831+
match conditionalCallDefineOpt, cenv.conditionalDefines with
10832+
| Some d, Some defineswhen not (List.contains ddefines) ->
1083310833
[], false
1083410834
| _ ->
10835-
1083610835
// REVIEW: take notice of inherited?
1083710836
let validOn, _inherited =
1083810837
let validOnDefault = 0x7fff

‎src/fsharp/TypeChecker.fsi‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ val EmptyTopAttrs : TopAttribs
3939
valCombineTopAttrs:TopAttribs->TopAttribs->TopAttribs
4040

4141
valTypeCheckOneImplFile:
42-
TcGlobals* NiceNameGenerator* ImportMap* CcuThunk*(unit-> bool)* ConditionalDefines* NameResolution.TcResultsSink* bool
42+
TcGlobals* NiceNameGenerator* ImportMap* CcuThunk*(unit-> bool)* ConditionalDefinesoption* NameResolution.TcResultsSink* bool
4343
-> TcEnv
4444
-> Tast.ModuleOrNamespaceType option
4545
-> ParsedImplFileInput
4646
-> Eventually<TopAttribs* Tast.TypedImplFile* ModuleOrNamespaceType* TcEnv* bool>
4747

4848
valTypeCheckOneSigFile:
49-
TcGlobals* NiceNameGenerator* ImportMap* CcuThunk*(unit-> bool)* ConditionalDefines* NameResolution.TcResultsSink* bool
49+
TcGlobals* NiceNameGenerator* ImportMap* CcuThunk*(unit-> bool)* ConditionalDefinesoption* NameResolution.TcResultsSink* bool
5050
-> TcEnv
5151
-> ParsedSigFileInput
5252
-> Eventually<TcEnv* ModuleOrNamespaceType* bool>

‎tests/service/Symbols.fs‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,27 @@ module Mod2 =
100100
mod1val1.XmlDocSig|> shouldEqual"P:Mod1.val1"
101101
mod2func2.XmlDocSig|> shouldEqual"M:Mod1.Mod2.func2"
102102

103-
103+
104+
moduleAttributes=
105+
[<Test>]
106+
let``Emit conditional attributes``()=
107+
letsource="""
108+
open System
109+
open System.Diagnostics
110+
111+
[<Conditional("Bar")>]
112+
type FooAttribute() =
113+
inherit Attribute()
114+
115+
[<Foo>]
116+
let x = 123
117+
"""
118+
letfileName,options= mkTestFileAndOptions source[|"--noconditionalerasure"|]
119+
let_,checkResults= parseAndCheckFile fileName source options
120+
121+
checkResults.GetAllUsesOfAllSymbolsInFile()
122+
|> Async.RunSynchronously
123+
|> Array.tryFind(fun su-> su.Symbol.DisplayName="x")
124+
|> Option.orElseWith(fun _-> failwith"Could not get symbol")
125+
|> Option.map(fun su-> su.Symbol:?> FSharpMemberOrFunctionOrValue)
126+
|> Option.iter(fun symbol-> symbol.Attributes.Count|> shouldEqual1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp