@@ -2204,18 +2204,23 @@ module GeneralizationHelpers =
2204
2204
// ComputeInlineFlag
2205
2205
//-------------------------------------------------------------------------
2206
2206
2207
- let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable m =
2207
+ let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable hasNoCompilerInliningAttribute m =
2208
2208
let inlineFlag =
2209
+ let isCtorOrAbstractSlot =
2210
+ match memFlagsOption with
2211
+ | None -> false
2212
+ | Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
2213
+
2209
2214
// Mutable values may never be inlined
2210
2215
// Constructors may never be inlined
2211
2216
// Calls to virtual/abstract slots may never be inlined
2212
- if isMutable ||
2213
- (match memFlagsOption with
2214
- | None -> false
2215
- | Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl)
2216
- then ValInline.Never
2217
- elif isInline then ValInline.Always
2218
- else ValInline.Optional
2217
+ // Values marked with NoCompilerInliningAttribute may never be inlined
2218
+ if isMutable || isCtorOrAbstractSlot || hasNoCompilerInliningAttribute then
2219
+ ValInline.Never
2220
+ elif isInline then
2221
+ ValInline.Always
2222
+ else
2223
+ ValInline.Optional
2219
2224
2220
2225
if isInline && (inlineFlag <> ValInline.Always) then
2221
2226
errorR(Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
@@ -10281,8 +10286,9 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
10281
10286
retAttribs, valAttribs, valSynData
10282
10287
10283
10288
let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
10289
+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute valAttribs
10284
10290
10285
- let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable mBinding
10291
+ let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
10286
10292
10287
10293
let argAttribs =
10288
10294
spatsL |> List.map (SynInfo.InferSynArgInfoFromSimplePats >> List.map (SynInfo.AttribsOfArgData >> TcAttrs AttributeTargets.Parameter false))
@@ -11403,8 +11409,9 @@ and AnalyzeAndMakeAndPublishRecursiveValue
11403
11409
11404
11410
// Allocate the type inference variable for the inferred type
11405
11411
let ty = NewInferenceType g
11412
+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute bindingAttribs
11406
11413
11407
- let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable mBinding
11414
+ let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
11408
11415
11409
11416
if isMutable then errorR(Error(FSComp.SR.tcOnlyRecordFieldsAndSimpleLetCanBeMutable(), mBinding))
11410
11417
@@ -12020,6 +12027,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
12020
12027
12021
12028
let attrs = TcAttributes cenv env attrTgt synAttrs
12022
12029
let newOk = if canInferTypars then NewTyparsOK else NoNewTypars
12030
+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
12023
12031
12024
12032
let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
12025
12033
let denv = env.DisplayEnv
@@ -12028,7 +12036,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
12028
12036
12029
12037
let (ValSpecResult (altActualParent, memberInfoOpt, id, enclosingDeclaredTypars, declaredTypars, ty, prelimValReprInfo, declKind)) = valSpecResult
12030
12038
12031
- let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag m
12039
+ let inlineFlag = ComputeInlineFlag (memberInfoOpt |> Option.map (fun (PrelimMemberInfo(memberInfo, _, _)) -> memberInfo.MemberFlags)) isInline mutableFlag hasNoCompilerInliningAttribute m
12032
12040
12033
12041
let freeInType = freeInTypeLeftToRight g false ty
12034
12042
0 commit comments