Skip to content

Commit 812bf3d

Browse files
authored
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
1 parent 324bf38 commit 812bf3d

20 files changed

+125
-33
lines changed

src/Compiler/Checking/CheckExpressions.fs

+33-31
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,12 @@ let CheckRequiredProperties (g:TcGlobals) (env: TcEnv) (cenv: TcFileState) (minf
12101210
let details = NicePrint.multiLineStringOfPropInfos g cenv.amap mMethExpr env.DisplayEnv missingProps
12111211
errorR(Error(FSComp.SR.tcMissingRequiredMembers details, mMethExpr))
12121212

1213+
let private HasMethodImplNoInliningAttribute g attrs =
1214+
match TryFindFSharpAttribute g g.attrib_MethodImplAttribute attrs with
1215+
// NO_INLINING = 8
1216+
| Some (Attrib(_, _, [ AttribInt32Arg flags ], _, _, _, _)) -> (flags &&& 0x8) <> 0x0
1217+
| _ -> false
1218+
12131219
let MakeAndPublishVal (cenv: cenv) env (altActualParent, inSig, declKind, valRecInfo, vscheme, attrs, xmlDoc, konst, isGeneratedEventVal) =
12141220

12151221
let g = cenv.g
@@ -1258,16 +1264,10 @@ let MakeAndPublishVal (cenv: cenv) env (altActualParent, inSig, declKind, valRec
12581264
errorR(Error(FSComp.SR.tcDllImportStubsCannotBeInlined(), m))
12591265
ValInline.Never
12601266
else
1261-
let implflags =
1262-
match TryFindFSharpAttribute g g.attrib_MethodImplAttribute attrs with
1263-
| Some (Attrib(_, _, [ AttribInt32Arg flags ], _, _, _, _)) -> flags
1264-
| _ -> 0x0
1265-
// MethodImplOptions.NoInlining = 0x8
1266-
let NO_INLINING = 0x8
1267-
if (implflags &&& NO_INLINING) <> 0x0 then
1268-
ValInline.Never
1269-
else
1270-
inlineFlag
1267+
if HasMethodImplNoInliningAttribute g attrs
1268+
then ValInline.Never
1269+
else inlineFlag
1270+
12711271

12721272
// CompiledName not allowed on virtual/abstract/override members
12731273
let compiledNameAttrib = TryFindFSharpStringAttribute g g.attrib_CompiledNameAttribute attrs
@@ -2205,26 +2205,32 @@ module GeneralizationHelpers =
22052205
// ComputeInlineFlag
22062206
//-------------------------------------------------------------------------
22072207

2208-
let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable hasNoCompilerInliningAttribute m =
2209-
let inlineFlag =
2210-
let isCtorOrAbstractSlot =
2211-
match memFlagsOption with
2212-
| None -> false
2213-
| Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
2208+
let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable g attrs m =
2209+
let hasNoCompilerInliningAttribute() = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
2210+
let isCtorOrAbstractSlot() =
2211+
match memFlagsOption with
2212+
| None -> false
2213+
| Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
22142214

2215+
let inlineFlag, reportIncorrectInlineKeywordUsage =
22152216
// Mutable values may never be inlined
22162217
// Constructors may never be inlined
22172218
// Calls to virtual/abstract slots may never be inlined
2218-
// Values marked with NoCompilerInliningAttribute may never be inlined
2219-
if isMutable || isCtorOrAbstractSlot || hasNoCompilerInliningAttribute then
2220-
ValInline.Never
2219+
// Values marked with NoCompilerInliningAttribute or [<MethodImpl(MethodImplOptions.NoInlining)>] may never be inlined
2220+
if isMutable || isCtorOrAbstractSlot() || hasNoCompilerInliningAttribute() then
2221+
ValInline.Never, errorR
2222+
elif HasMethodImplNoInliningAttribute g attrs then
2223+
ValInline.Never,
2224+
if g.langVersion.SupportsFeature LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction
2225+
then warning
2226+
else ignore
22212227
elif isInline then
2222-
ValInline.Always
2228+
ValInline.Always, ignore
22232229
else
2224-
ValInline.Optional
2230+
ValInline.Optional, ignore
22252231

22262232
if isInline && (inlineFlag <> ValInline.Always) then
2227-
errorR(Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
2233+
reportIncorrectInlineKeywordUsage (Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
22282234

22292235
inlineFlag
22302236

@@ -10278,10 +10284,8 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
1027810284
SynValData(valMf, SynValInfo(args, SynArgInfo({Attributes=rotRetSynAttrs; Range=mHead} :: attrs, opt, retId)), valId)
1027910285
retAttribs, valAttribs, valSynData
1028010286

10281-
let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
10282-
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute valAttribs
10283-
10284-
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
10287+
let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
10288+
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable g valAttribs mBinding
1028510289

1028610290
let argAttribs =
1028710291
spatsL |> List.map (SynInfo.InferSynArgInfoFromSimplePats >> List.map (SynInfo.AttribsOfArgData >> TcAttrs AttributeTargets.Parameter false))
@@ -11414,10 +11418,9 @@ and AnalyzeAndMakeAndPublishRecursiveValue
1141411418
let bindingAttribs = TcAttributes cenv env attrTgt bindingSynAttribs
1141511419

1141611420
// Allocate the type inference variable for the inferred type
11417-
let ty = NewInferenceType g
11418-
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute bindingAttribs
11421+
let ty = NewInferenceType g
1141911422

11420-
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
11423+
let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable g bindingAttribs mBinding
1142111424

1142211425
if isMutable then errorR(Error(FSComp.SR.tcOnlyRecordFieldsAndSimpleLetCanBeMutable(), mBinding))
1142311426

@@ -12033,7 +12036,6 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
1203312036

1203412037
let attrs = TcAttributes cenv env attrTgt synAttrs
1203512038
let newOk = if canInferTypars then NewTyparsOK else NoNewTypars
12036-
let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
1203712039

1203812040
let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
1203912041
let denv = env.DisplayEnv
@@ -12042,7 +12044,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
1204212044

1204312045
let (ValSpecResult (altActualParent, memberInfoOpt, id, enclosingDeclaredTypars, declaredTypars, ty, prelimValReprInfo, declKind)) = valSpecResult
1204412046

12045-
let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag hasNoCompilerInliningAttribute m
12047+
let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag g attrs m
1204612048

1204712049
let freeInType = freeInTypeLeftToRight g false ty
1204812050

src/Compiler/FSComp.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,7 @@ featureLowercaseDUWhenRequireQualifiedAccess,"Allow lowercase DU when RequireQua
15581558
featureMatchNotAllowedForUnionCaseWithNoData,"Pattern match discard is not allowed for union case that takes no data."
15591559
featureCSharpExtensionAttributeNotRequired,"Allow implicit Extension attribute on declaring types, modules"
15601560
featureErrorForNonVirtualMembersOverrides,"Raises errors for non-virtual members overrides"
1561+
featureWarningWhenInliningMethodImplNoInlineMarkedFunction,"Raises warnings when 'let inline ... =' is used together with [<MethodImpl(MethodImplOptions.NoInlining)>] attribute. Function is not getting inlined."
15611562
featureArithmeticInLiterals,"Allow arithmetic and logical operations in literals"
15621563
3353,fsiInvalidDirective,"Invalid directive '#%s %s'"
15631564
3354,tcNotAFunctionButIndexerNamedIndexingNotYetEnabled,"This value supports indexing, e.g. '%s.[index]'. The syntax '%s[index]' requires /langversion:preview. See https://aka.ms/fsharp-index-notation."

src/Compiler/Facilities/LanguageFeatures.fs

+5-2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ type LanguageFeature =
5757
| MatchNotAllowedForUnionCaseWithNoData
5858
| CSharpExtensionAttributeNotRequired
5959
| ErrorForNonVirtualMembersOverrides
60+
| WarningWhenInliningMethodImplNoInlineMarkedFunction
6061
| EscapeDotnetFormattableStrings
6162
| ArithmeticInLiterals
6263

@@ -132,6 +133,7 @@ type LanguageVersion(versionText) =
132133
LanguageFeature.MatchNotAllowedForUnionCaseWithNoData, previewVersion
133134
LanguageFeature.CSharpExtensionAttributeNotRequired, previewVersion
134135
LanguageFeature.ErrorForNonVirtualMembersOverrides, previewVersion
136+
LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction, previewVersion
135137
LanguageFeature.EscapeDotnetFormattableStrings, previewVersion
136138
LanguageFeature.ArithmeticInLiterals, previewVersion
137139

@@ -242,8 +244,9 @@ type LanguageVersion(versionText) =
242244
| LanguageFeature.InterfacesWithAbstractStaticMembers -> FSComp.SR.featureInterfacesWithAbstractStaticMembers ()
243245
| LanguageFeature.SelfTypeConstraints -> FSComp.SR.featureSelfTypeConstraints ()
244246
| LanguageFeature.MatchNotAllowedForUnionCaseWithNoData -> FSComp.SR.featureMatchNotAllowedForUnionCaseWithNoData ()
245-
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
246-
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
247+
| LanguageFeature.CSharpExtensionAttributeNotRequired -> FSComp.SR.featureCSharpExtensionAttributeNotRequired ()
248+
| LanguageFeature.ErrorForNonVirtualMembersOverrides -> FSComp.SR.featureErrorForNonVirtualMembersOverrides ()
249+
| LanguageFeature.WarningWhenInliningMethodImplNoInlineMarkedFunction -> FSComp.SR.featureWarningWhenInliningMethodImplNoInlineMarkedFunction ()
247250
| LanguageFeature.EscapeDotnetFormattableStrings -> FSComp.SR.featureEscapeBracesInFormattableString ()
248251
| LanguageFeature.ArithmeticInLiterals -> FSComp.SR.featureArithmeticInLiterals ()
249252

src/Compiler/Facilities/LanguageFeatures.fsi

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ type LanguageFeature =
4747
| MatchNotAllowedForUnionCaseWithNoData
4848
| CSharpExtensionAttributeNotRequired
4949
| ErrorForNonVirtualMembersOverrides
50+
| WarningWhenInliningMethodImplNoInlineMarkedFunction
5051
| EscapeDotnetFormattableStrings
5152
| ArithmeticInLiterals
5253

src/Compiler/xlf/FSComp.txt.cs.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">reprezentace struktury aktivních vzorů</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">zástupný znak ve smyčce for</target>

src/Compiler/xlf/FSComp.txt.de.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">Strukturdarstellung für aktive Muster</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">Platzhalter in for-Schleife</target>

src/Compiler/xlf/FSComp.txt.es.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">representación de struct para modelos activos</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">carácter comodín en bucle for</target>

src/Compiler/xlf/FSComp.txt.fr.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">représentation de structure pour les modèles actifs</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">caractère générique dans une boucle for</target>

src/Compiler/xlf/FSComp.txt.it.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">rappresentazione struct per criteri attivi</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">carattere jolly nel ciclo for</target>

src/Compiler/xlf/FSComp.txt.ja.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">アクティブなパターンの構造体表現</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">for ループのワイルド カード</target>

src/Compiler/xlf/FSComp.txt.ko.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">활성 패턴에 대한 구조체 표현</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">for 루프의 와일드카드</target>

src/Compiler/xlf/FSComp.txt.pl.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">reprezentacja struktury aktywnych wzorców</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">symbol wieloznaczny w pętli for</target>

src/Compiler/xlf/FSComp.txt.pt-BR.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">representação estrutural para padrões ativos</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">curinga para loop</target>

src/Compiler/xlf/FSComp.txt.ru.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">представление структуры для активных шаблонов</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">подстановочный знак в цикле for</target>

src/Compiler/xlf/FSComp.txt.tr.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">etkin desenler için yapı gösterimi</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">for döngüsünde joker karakter</target>

src/Compiler/xlf/FSComp.txt.zh-Hans.xlf

+5
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,11 @@
337337
<target state="translated">活动模式的结构表示形式</target>
338338
<note />
339339
</trans-unit>
340+
<trans-unit id="featureWarningWhenInliningMethodImplNoInlineMarkedFunction">
341+
<source>Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</source>
342+
<target state="new">Raises warnings when 'let inline ... =' is used together with [&lt;MethodImpl(MethodImplOptions.NoInlining)&gt;] attribute. Function is not getting inlined.</target>
343+
<note />
344+
</trans-unit>
340345
<trans-unit id="featureWildCardInForLoop">
341346
<source>wild card in for loop</source>
342347
<target state="translated">for 循环中的通配符</target>

0 commit comments

Comments
 (0)