@@ -2204,18 +2204,23 @@ module GeneralizationHelpers =
22042204// ComputeInlineFlag
22052205//-------------------------------------------------------------------------
22062206
2207- let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable m =
2207+ let ComputeInlineFlag (memFlagsOption: SynMemberFlags option) isInline isMutable hasNoCompilerInliningAttribute m =
22082208 let inlineFlag =
2209+ let isCtorOrAbstractSlot =
2210+ match memFlagsOption with
2211+ | None -> false
2212+ | Some x -> (x.MemberKind = SynMemberKind.Constructor) || x.IsDispatchSlot || x.IsOverrideOrExplicitImpl
2213+
22092214 // Mutable values may never be inlined
22102215 // Constructors may never be inlined
22112216 // 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
22192224
22202225 if isInline && (inlineFlag <> ValInline.Always) then
22212226 errorR(Error(FSComp.SR.tcThisValueMayNotBeInlined(), m))
@@ -10281,8 +10286,9 @@ and TcNormalizedBinding declKind (cenv: cenv) env tpenv overallTy safeThisValOpt
1028110286 retAttribs, valAttribs, valSynData
1028210287
1028310288 let isVolatile = HasFSharpAttribute g g.attrib_VolatileFieldAttribute valAttribs
10289+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute valAttribs
1028410290
10285- let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable mBinding
10291+ let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
1028610292
1028710293 let argAttribs =
1028810294 spatsL |> List.map (SynInfo.InferSynArgInfoFromSimplePats >> List.map (SynInfo.AttribsOfArgData >> TcAttrs AttributeTargets.Parameter false))
@@ -11403,8 +11409,9 @@ and AnalyzeAndMakeAndPublishRecursiveValue
1140311409
1140411410 // Allocate the type inference variable for the inferred type
1140511411 let ty = NewInferenceType g
11412+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute bindingAttribs
1140611413
11407- let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable mBinding
11414+ let inlineFlag = ComputeInlineFlag memberFlagsOpt isInline isMutable hasNoCompilerInliningAttribute mBinding
1140811415
1140911416 if isMutable then errorR(Error(FSComp.SR.tcOnlyRecordFieldsAndSimpleLetCanBeMutable(), mBinding))
1141011417
@@ -12020,6 +12027,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
1202012027
1202112028 let attrs = TcAttributes cenv env attrTgt synAttrs
1202212029 let newOk = if canInferTypars then NewTyparsOK else NoNewTypars
12030+ let hasNoCompilerInliningAttribute = HasFSharpAttribute g g.attrib_NoCompilerInliningAttribute attrs
1202312031
1202412032 let valinfos, tpenv = TcValSpec cenv env declKind newOk containerInfo memFlagsOpt None tpenv synValSig attrs
1202512033 let denv = env.DisplayEnv
@@ -12028,7 +12036,7 @@ let TcAndPublishValSpec (cenv: cenv, env, containerInfo: ContainerInfo, declKind
1202812036
1202912037 let (ValSpecResult (altActualParent, memberInfoOpt, id, enclosingDeclaredTypars, declaredTypars, ty, prelimValReprInfo, declKind)) = valSpecResult
1203012038
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
1203212040
1203312041 let freeInType = freeInTypeLeftToRight g false ty
1203412042
0 commit comments