未验证 提交 812bf3dc 编写于 作者: T Tomas Grosup 提交者: GitHub

Fix a broken debug assertion that kicked in whenever building Fsharp.Core (#14435)

* Fix a broken debug assertion that kicked in whenever building Fsharp.Core in Debug
* HasMethodImplNoInliningAttribute unification
上级 324bf38d
......@@ -1210,6 +1210,12 @@ let CheckRequiredProperties (g:TcGlobals) (env: TcEnv) (cenv: TcFileState) (minf
let details = NicePrint.multiLineStringOfPropInfos g cenv.amap mMethExpr env.DisplayEnv missingProps
errorR(Error(FSComp.SR.tcMissingRequiredMembers details, mMethExpr))
let private HasMethodImplNoInliningAttribute g attrs =
match TryFindFSharpAttribute g g.attrib_MethodImplAttribute attrs with
// NO_INLINING = 8
| Some (Attrib(_, _, [ AttribInt32Arg flags ], _, _, _, _)) -> (flags &&& 0x8) <> 0x0
| _ -> false
let MakeAndPublishVal (cenv: cenv) env (altActualParent, inSig, declKind, valRecInfo, vscheme, attrs, xmlDoc, konst, isGeneratedEventVal) =
let g = cenv.g
......@@ -1258,16 +1264,10 @@ let MakeAndPublishVal (cenv: cenv) env (altActualParent, inSig, declKind, valRec
errorR(Error(FSComp.SR.tcDllImportStubsCannotBeInlined(), m))
ValInline.Never
else
let implflags =
match TryFindFSharpAttribute g g.attrib_MethodImplAttribute attrs with
| Some (Attrib(_, _, [ AttribInt32Arg flags ], _, _, _, _)) -> flags
| _ -> 0x0
// MethodImplOptions.NoInlining = 0x8
let NO_INLINING = 0x8
if (implflags &&& NO_INLINING) <> 0x0 then
ValInline.Never
else
inlineFlag
if HasMethodImplNoInliningAttribute g attrs
then ValInline.Never
else inlineFlag
// CompiledName not allowed on virtual/abstract/override members
let compiledNameAttrib = TryFindFSharpStringAttribute g g.attrib_CompiledNameAttribute attrs
......@@ -2205,26 +2205,32 @@ module GeneralizationHelpers =
// ComputeInlineFlag
//-------------------------------------------------------------------------
let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable hasNoCompilerInliningAttribute m =
let inlineFlag =
let isCtorOrAbstractSlot =
match memFlagsOption with
| None -> false
| Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable g attrs m =
let hasNoCompilerInliningAttribute() = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
let isCtorOrAbstractSlot() =
match memFlagsOption with
| None -> false
| Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
let inlineFlag, reportIncorrectInlineKeywordUsage =
// Mutable values may never be inlined
// Constructors may never be inlined
// Calls to virtual/abstract slots may never be inlined
// Values marked with NoCompilerInliningAttribute may never be inlined
if isMutable || isCtorOrAbstractSlot || hasNoCompilerInliningAttribute then
ValInline.Never
// Values marked with NoCompilerInliningAttribute or [<MethodImpl(MethodImplOptions.NoInlining)>] may never be inlined
if isMutable || isCtorOrAbstractSlot() || hasNoCompilerInliningAttribute() then
ValInline.Never, errorR
elif HasMethodImplNoInliningAttribute g attrs then
ValInline.Never,
if g.langVersion.SupportsFeature LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction
then warning
else ignore
elif isInline then
ValInline.Always
ValInline.Always, ignore
else
ValInline.Optional
ValInline.Optional, ignore
if isInline && (inlineFlag <> ValInline.Always) then
errorR(Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
reportIncorrectInlineKeywordUsage (Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
inlineFlag
......@@ -10278,10 +10284,8 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
SynValData(valMf, SynValInfo(args, SynArgInfo({Attributes=rotRetSynAttrs; Range=mHead} :: attrs, opt, retId)), valId)
retAttribs, valAttribs, valSynData
let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute valAttribs
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable g valAttribs mBinding
let argAttribs =
spatsL |> List.map (SynInfo.InferSynArgInfoFromSimplePats >> List.map (SynInfo.AttribsOfArgData >> TcAttrs AttributeTargets.Parameter false))
......@@ -11414,10 +11418,9 @@ and AnalyzeAndMakeAndPublishRecursiveValue
let bindingAttribs = TcAttributes cenv env attrTgt bindingSynAttribs
// Allocate the type inference variable for the inferred type
let ty = NewInferenceType g
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute bindingAttribs
let ty = NewInferenceType g
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable g bindingAttribs mBinding
if isMutable then errorR(Error(FSComp.SR.tcOnlyRecordFieldsAndSimpleLetCanBeMutable(), mBinding))
......@@ -12033,7 +12036,6 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
let attrs = TcAttributes cenv env attrTgt synAttrs
let newOk = if canInferTypars then NewTyparsOK else NoNewTypars
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
let denv = env.DisplayEnv
......@@ -12042,7 +12044,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
let (ValSpecResult (altActualParent, memberInfoOpt, id, enclosingDeclaredTypars, declaredTypars, ty, prelimValReprInfo, declKind)) = valSpecResult
let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag hasNoCompilerInliningAttribute m
let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag g attrs m
let freeInType = freeInTypeLeftToRight g false ty
......
......@@ -1558,6 +1558,7 @@ featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQua
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute on declaring types, modules"
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined."
featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals"
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."
......
......@@ -57,6 +57,7 @@ type LanguageFeature =
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides
| WarningWhenInliningMethodImplNoInlineMarkedFunction
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals
......@@ -132,6 +133,7 @@ type LanguageVersion(versionText) =
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, previewVersion
LanguageFeature.CSharpExtensionAttributeNotRequired, previewVersion
LanguageFeature.ErrorForNonVirtualMembersOverrides, previewVersion
LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction, previewVersion
LanguageFeature.EscapeDotnetFormattableStrings, previewVersion
LanguageFeature.ArithmeticInLiterals, previewVersion
......@@ -242,8 +244,9 @@ type LanguageVersion(versionText) =
| LanguageFeature.InterfacesWithAbstractStaticMembers -> FSComp.SR.featureInterfacesWithAbstractStaticMembers ()
| LanguageFeature.SelfTypeConstraints -> FSComp.SR.featureSelfTypeConstraints ()
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
| LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction -> FSComp.SR.featureWarningWhenInliningMethodImplNoInlineMarkedFunction ()
| LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString ()
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
......
......@@ -47,6 +47,7 @@ type LanguageFeature =
| MatchNotAllowedForUnionCaseWithNoData
| CSharpExtensionAttributeNotRequired
| ErrorForNonVirtualMembersOverrides
| WarningWhenInliningMethodImplNoInlineMarkedFunction
| EscapeDotnetFormattableStrings
| ArithmeticInLiterals
......
......@@ -337,6 +337,11 @@
<target state="translated">reprezentace struktury aktivních vzorů</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">zástupný znak ve smyčce for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">Strukturdarstellung für aktive Muster</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">Platzhalter in for-Schleife</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">representación de struct para modelos activos</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">carácter comodín en bucle for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">représentation de structure pour les modèles actifs</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">caractère générique dans une boucle for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">rappresentazione struct per criteri attivi</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">carattere jolly nel ciclo for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">アクティブなパターンの構造体表現</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">for ループのワイルド カード</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">활성 패턴에 대한 구조체 표현</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">for 루프의 와일드카드</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">reprezentacja struktury aktywnych wzorców</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">symbol wieloznaczny w pętli for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">representação estrutural para padrões ativos</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">curinga para loop</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">представление структуры для активных шаблонов</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">подстановочный знак в цикле for</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">etkin desenler için yapı gösterimi</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">for döngüsünde joker karakter</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">活动模式的结构表示形式</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">for 循环中的通配符</target>
......
......@@ -337,6 +337,11 @@
<target state="translated">現用模式的結構表示法</target>
<note />
</trans-unit>
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
<note />
</trans-unit>
<trans-unit id="featureWildCardInForLoop">
<source>wild card in for loop</source>
<target state="translated">for 迴圈中的萬用字元</target>
......
module M
[<System.Runtime.CompilerServices.MethodImplAttribute(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)>]
let inline getUnit (f : unit -> unit) = f()
\ No newline at end of file
......@@ -33,6 +33,20 @@ module MethodImplAttribute =
let ``NoInlining_fs`` compilation =
compilation
|> verifyCompilation
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"MethodImplAttribute.NoInlining_InlineKeyword.fs"|])>]
let ``NoInlining_fs with inline keyword => should warn in preview version`` compilation =
compilation
|> withLangVersionPreview
|> typecheck
|> withSingleDiagnostic (Warning 3151, Line 2, Col 1, Line 3, Col 38, "This member, function or value declaration may not be declared 'inline'")
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"MethodImplAttribute.NoInlining_InlineKeyword.fs"|])>]
let ``NoInlining_fs with inline keyword => should not warn in F# 7 or older`` compilation =
compilation
|> withLangVersion70
|> typecheck
|> withDiagnostics []
// SOURCE=MethodImplAttribute.AggressiveInlining.fs SCFLAGS="-a -g --optimize-" COMPILE_ONLY=1 POSTCMD="..\\CompareIL.cmd MethodImplAttribute.AggressiveInlining.dll" # MethodImplAttribute.AggressiveInlining.fs
[<Theory; Directory(__SOURCE_DIRECTORY__, Includes=[|"MethodImplAttribute.AggressiveInlining.fs"|])>]
......
......@@ -391,6 +391,9 @@ module rec Compiler =
let withLangVersion70 (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--langversion:7.0" ] "withLangVersion70 is only supported on F#" cUnit
let withLangVersion80 (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--langversion:8.0" ] "withLangVersion80 is only supported on F#" cUnit
let withLangVersionPreview (cUnit: CompilationUnit) : CompilationUnit =
withOptionsHelper [ "--langversion:preview" ] "withLangVersionPreview is only supported on F#" cUnit
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册