Skip to content

Commit b03949c

Browse files
authored
Merge pull request #10919 from cartermp/cp-stackoverflowfix-will
Cherry Pick into 16.9 - Stack-overflow fix (#10868)
2 parents 2b2c847 + 725739d commit b03949c

File tree

10 files changed

+152
-140
lines changed

10 files changed

+152
-140
lines changed

src/fsharp/IlxGen.fs

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,7 @@ and GenObjectMethod cenv eenvinner (cgbuf: CodeGenBuffer) useMethodImpl tmethod
43714371
GenGenericParams cenv eenvUnderTypars methTyparsOfOverridingMethod,
43724372
ilParamsOfOverridingMethod,
43734373
ilReturnOfOverridingMethod,
4374-
MethodBody.IL ilMethodBody)
4374+
MethodBody.IL (lazy ilMethodBody))
43754375
// fixup attributes to generate a method impl
43764376
let mdef = if useMethodImpl then fixupMethodImplFlags mdef else mdef
43774377
let mdef = fixupVirtualSlotFlags mdef
@@ -4473,20 +4473,20 @@ and GenSequenceExpr
44734473
CG.EmitInstr cgbuf (pop ilCloAllFreeVars.Length) (Push [ilCloRetTyInner]) (I_newobj (formalClospec.Constructor, None))
44744474
GenSequel cenv eenv.cloc cgbuf Return),
44754475
m)
4476-
mkILNonGenericVirtualMethod("GetFreshEnumerator", ILMemberAccess.Public, [], mkILReturn ilCloEnumeratorTy, MethodBody.IL mbody)
4476+
mkILNonGenericVirtualMethod("GetFreshEnumerator", ILMemberAccess.Public, [], mkILReturn ilCloEnumeratorTy, MethodBody.IL (lazy mbody))
44774477
|> AddNonUserCompilerGeneratedAttribs g
44784478

44794479
let closeMethod =
44804480
// Note: We suppress the first sequence point in the body of this method since it is the initial state machine jump
44814481
let spReq = SPSuppress
44824482
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (spReq, [], "Close", eenvinner, 1, closeExpr, discardAndReturnVoid)
4483-
mkILNonGenericVirtualMethod("Close", ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL ilCode)
4483+
mkILNonGenericVirtualMethod("Close", ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL (lazy ilCode))
44844484

44854485
let checkCloseMethod =
44864486
// Note: We suppress the first sequence point in the body of this method since it is the initial state machine jump
44874487
let spReq = SPSuppress
44884488
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (spReq, [], "get_CheckClose", eenvinner, 1, checkCloseExpr, Return)
4489-
mkILNonGenericVirtualMethod("get_CheckClose", ILMemberAccess.Public, [], mkILReturn g.ilg.typ_Bool, MethodBody.IL ilCode)
4489+
mkILNonGenericVirtualMethod("get_CheckClose", ILMemberAccess.Public, [], mkILReturn g.ilg.typ_Bool, MethodBody.IL (lazy ilCode))
44904490

44914491
let generateNextMethod =
44924492
// Note: We suppress the first sequence point in the body of this method since it is the initial state machine jump
@@ -4495,12 +4495,12 @@ and GenSequenceExpr
44954495
let eenvinner = eenvinner |> AddStorageForLocalVals g [ (nextEnumeratorValRef.Deref, Arg 1) ]
44964496
let ilParams = [mkILParamNamed("next", ILType.Byref ilCloEnumerableTy)]
44974497
let ilReturn = mkILReturn g.ilg.typ_Int32
4498-
let ilCode = MethodBody.IL (CodeGenMethodForExpr cenv cgbuf.mgbuf (spReq, [], "GenerateNext", eenvinner, 2, generateNextExpr, Return))
4498+
let ilCode = MethodBody.IL (lazy (CodeGenMethodForExpr cenv cgbuf.mgbuf (spReq, [], "GenerateNext", eenvinner, 2, generateNextExpr, Return)))
44994499
mkILNonGenericVirtualMethod("GenerateNext", ILMemberAccess.Public, ilParams, ilReturn, ilCode)
45004500

45014501
let lastGeneratedMethod =
45024502
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], "get_LastGenerated", eenvinner, 1, exprForValRef m currvref, Return)
4503-
mkILNonGenericVirtualMethod("get_LastGenerated", ILMemberAccess.Public, [], mkILReturn ilCloSeqElemTy, MethodBody.IL ilCode)
4503+
mkILNonGenericVirtualMethod("get_LastGenerated", ILMemberAccess.Public, [], mkILReturn ilCloSeqElemTy, MethodBody.IL (lazy ilCode))
45044504
|> AddNonUserCompilerGeneratedAttribs g
45054505

45064506
let ilCtorBody =
@@ -4543,7 +4543,7 @@ and GenClosureTypeDefs cenv (tref: ILTypeRef, ilGenParams, attrs, ilCloAllFreeVa
45434543
let fspec = mkILFieldSpec (cloSpec.GetStaticFieldSpec().FieldRef, cloTy)
45444544
let ctorSpec = mkILMethSpecForMethRefInTy (cloSpec.Constructor.MethodRef, cloTy, [])
45454545
let ilCode = mkILMethodBody (true, [], 8, nonBranchingInstrsToCode ([ I_newobj (ctorSpec, None); mkNormalStsfld fspec ]), None)
4546-
let cctor = mkILClassCtor (MethodBody.IL ilCode)
4546+
let cctor = mkILClassCtor (MethodBody.IL (lazy ilCode))
45474547
let ilFieldDef = mkILStaticField(fspec.Name, fspec.FormalType, None, None, ILMemberAccess.Assembly).WithInitOnly(true)
45484548
(cctor :: mdefs), [ ilFieldDef ]
45494549
else
@@ -4642,7 +4642,7 @@ and GenLambdaClosure cenv (cgbuf: CodeGenBuffer) eenv isLocalTypeFunc thisVars e
46424642
cgbuf.mgbuf.AddTypeDef(ilContractTypeRef, ilContractTypeDef, false, false, None)
46434643

46444644
let ilCtorBody = mkILMethodBody (true, [], 8, nonBranchingInstrsToCode (mkCallBaseConstructor(ilContractTy, [])), None )
4645-
let cloMethods = [ mkILGenericVirtualMethod("DirectInvoke", ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn (cloinfo.ilCloFormalReturnTy), MethodBody.IL ilCloBody) ]
4645+
let cloMethods = [ mkILGenericVirtualMethod("DirectInvoke", ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn (cloinfo.ilCloFormalReturnTy), MethodBody.IL(lazy ilCloBody)) ]
46464646
let cloTypeDefs = GenClosureTypeDefs cenv (ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.ilCloAllFreeVars, cloinfo.ilCloLambdas, ilCtorBody, cloMethods, [], ilContractTy, [], Some cloinfo.cloSpec)
46474647
cloTypeDefs
46484648

@@ -5039,7 +5039,7 @@ and GenDelegateExpr cenv cgbuf eenvouter expr (TObjExprMethod((TSlotSig(_, deleg
50395039
ILMemberAccess.Assembly,
50405040
ilDelegeeParams,
50415041
ilDelegeeRet,
5042-
MethodBody.IL ilMethodBody)
5042+
MethodBody.IL(lazy ilMethodBody))
50435043
let delegeeCtorMeth = mkILSimpleStorageCtor(None, Some g.ilg.typ_Object.TypeSpec, ilDelegeeTyInner, [], [], ILMemberAccess.Assembly)
50445044
let ilCtorBody = delegeeCtorMeth.MethodBody
50455045

@@ -5616,8 +5616,7 @@ and GenBindingAfterDebugPoint cenv cgbuf eenv sp (TBind(vspec, rhsExpr, _)) star
56165616

56175617
CommitStartScope cgbuf startScopeMarkOpt
56185618

5619-
// if we have any expression recursion depth, we should delay the generation of a method to prevent stack overflows
5620-
let generator = if cenv.exprRecursionDepth > 0 then DelayGenMethodForBinding else GenMethodForBinding
5619+
let generator = GenMethodForBinding
56215620
let hasWitnessEntry = cenv.g.generateWitnesses && not witnessInfos.IsEmpty
56225621

56235622
generator cenv cgbuf.mgbuf eenv (vspec, mspec, hasWitnessEntry, false, access, ctps, mtps, [], curriedArgInfos, paramInfos, argTys, retInfo, topValInfo, methLambdaCtorThisValOpt, methLambdaBaseValOpt, methLambdaTypars, methLambdaVars, methLambdaBody, methLambdaBodyTy)
@@ -5645,7 +5644,8 @@ and GenBindingAfterDebugPoint cenv cgbuf eenv sp (TBind(vspec, rhsExpr, _)) star
56455644
cgbuf.mgbuf.AddOrMergePropertyDef(ilGetterMethSpec.MethodRef.DeclaringTypeRef, ilPropDef, m)
56465645

56475646
let ilMethodDef =
5648-
let ilMethodBody = MethodBody.IL(CodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], ilGetterMethSpec.Name, eenv, 0, rhsExpr, Return))
5647+
let ilCode = CodeGenMethodForExpr cenv cgbuf.mgbuf (SPSuppress, [], ilGetterMethSpec.Name, eenv, 0, rhsExpr, Return)
5648+
let ilMethodBody = MethodBody.IL(lazy ilCode)
56495649
(mkILStaticMethod ([], ilGetterMethSpec.Name, access, [], mkILReturn ilTy, ilMethodBody)).WithSpecialName
56505650
|> AddNonUserCompilerGeneratedAttribs g
56515651

@@ -6188,10 +6188,20 @@ and GenMethodForBinding
61886188
else
61896189
body
61906190

6191-
let ilCode = CodeGenMethodForExpr cenv mgbuf (SPAlways, tailCallInfo, mspec.Name, eenvForMeth, 0, bodyExpr, sequel)
6191+
let ilCodeLazy = lazy CodeGenMethodForExpr cenv mgbuf (SPAlways, tailCallInfo, mspec.Name, eenvForMeth, 0, bodyExpr, sequel)
61926192

61936193
// This is the main code generation for most methods
6194-
false, MethodBody.IL ilCode, false
6194+
false, MethodBody.IL(ilCodeLazy), false
6195+
6196+
match ilMethodBody with
6197+
| MethodBody.IL(ilCodeLazy) ->
6198+
if cenv.exprRecursionDepth > 0 then
6199+
cenv.delayedGenMethods.Enqueue(fun _ -> ilCodeLazy.Force() |> ignore)
6200+
else
6201+
// Eagerly codegen if we are not in an expression depth.
6202+
ilCodeLazy.Force() |> ignore
6203+
| _ ->
6204+
()
61956205

61966206
// Do not generate DllImport attributes into the code - they are implicit from the P/Invoke
61976207
let attrs =
@@ -6396,7 +6406,7 @@ and GenPInvokeMethod (nm, dll, namedArgs) =
63966406

63976407
let hasPreserveSigNamedArg = decoder.FindBool "PreserveSig" true
63986408
hasPreserveSigNamedArg,
6399-
MethodBody.PInvoke
6409+
let pinvoke =
64006410
{ Where=mkSimpleModRef dll
64016411
Name=decoder.FindString "EntryPoint" nm
64026412
CallingConv=
@@ -6417,7 +6427,8 @@ and GenPInvokeMethod (nm, dll, namedArgs) =
64176427
NoMangle= decoder.FindBool "ExactSpelling" false
64186428
LastError= decoder.FindBool "SetLastError" false
64196429
ThrowOnUnmappableChar= if (decoder.FindBool "ThrowOnUnmappableChar" false) then PInvokeThrowOnUnmappableChar.Enabled else PInvokeThrowOnUnmappableChar.UseAssembly
6420-
CharBestFit=if (decoder.FindBool "BestFitMapping" false) then PInvokeCharBestFit.Enabled else PInvokeCharBestFit.UseAssembly }
6430+
CharBestFit=if (decoder.FindBool "BestFitMapping" false) then PInvokeCharBestFit.Enabled else PInvokeCharBestFit.UseAssembly } : PInvokeMethod
6431+
MethodBody.PInvoke(lazy pinvoke)
64216432

64226433
and GenBindings cenv cgbuf eenv binds = List.iter (GenBinding cenv cgbuf eenv) binds
64236434

@@ -7033,7 +7044,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: TypedI
70337044
// This adds the explicit init of the .cctor to the explicit entry point main method
70347045
mgbuf.AddExplicitInitToSpecificMethodDef((fun md -> md.IsEntryPoint), tref, fspec, GenPossibleILSourceMarker cenv m, feefee, seqpt))
70357046

7036-
let cctorMethDef = mkILClassCtor (MethodBody.IL topCode)
7047+
let cctorMethDef = mkILClassCtor (MethodBody.IL (lazy topCode))
70377048
mgbuf.AddMethodDef(initClassTy.TypeRef, cctorMethDef)
70387049

70397050
// Final file, implicit entry point. We generate no .cctor.
@@ -7048,7 +7059,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: TypedI
70487059

70497060
// generate main@
70507061
let ilMainMethodDef =
7051-
let mdef = mkILNonGenericStaticMethod(mainMethName, ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL topCode)
7062+
let mdef = mkILNonGenericStaticMethod(mainMethName, ILMemberAccess.Public, [], mkILReturn ILType.Void, MethodBody.IL (lazy topCode))
70527063
mdef.With(isEntryPoint= true, customAttrs = ilAttrs)
70537064

70547065
mgbuf.AddMethodDef(initClassTy.TypeRef, ilMainMethodDef)
@@ -7058,7 +7069,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: TypedI
70587069
| None ->
70597070
if doesSomething then
70607071
// Add the cctor
7061-
let cctorMethDef = mkILClassCtor (MethodBody.IL topCode)
7072+
let cctorMethDef = mkILClassCtor (MethodBody.IL (lazy topCode))
70627073
mgbuf.AddMethodDef(initClassTy.TypeRef, cctorMethDef)
70637074

70647075
// Commit the directed initializations

src/fsharp/absil/il.fs

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,28 +1547,18 @@ type ILMethodVirtualInfo =
15471547

15481548
[<RequireQualifiedAccess>]
15491549
type MethodBody =
1550-
| IL of ILMethodBody
1551-
| PInvoke of PInvokeMethod (* platform invoke to native *)
1550+
| IL of Lazy<ILMethodBody>
1551+
| PInvoke of Lazy<PInvokeMethod> (* platform invoke to native *)
15521552
| Abstract
15531553
| Native
15541554
| NotAvailable
15551555

1556-
type ILLazyMethodBody =
1557-
| ILLazyMethodBody of Lazy<MethodBody >
1558-
1559-
member x.Contents = let (ILLazyMethodBody mb) = x in mb.Force()
1560-
static member NotAvailable = ILLazyMethodBody (notlazy MethodBody.NotAvailable)
1561-
15621556
[<RequireQualifiedAccess>]
15631557
type MethodCodeKind =
15641558
| IL
15651559
| Native
15661560
| Runtime
15671561

1568-
let mkMethBodyAux mb = ILLazyMethodBody (notlazy mb)
1569-
1570-
let mkMethBodyLazyAux mb = ILLazyMethodBody mb
1571-
15721562
let typesOfILParams (ps: ILParameters) : ILTypes = ps |> List.map (fun p -> p.Type)
15731563

15741564
[<StructuralEquality; StructuralComparison>]
@@ -1624,13 +1614,15 @@ let NoMetadataIdx = -1
16241614

16251615
[<NoComparison; NoEquality>]
16261616
type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: MethodImplAttributes, callingConv: ILCallingConv,
1627-
parameters: ILParameters, ret: ILReturn, body: ILLazyMethodBody, isEntryPoint: bool, genericParams: ILGenericParameterDefs,
1617+
parameters: ILParameters, ret: ILReturn, body: Lazy<MethodBody>, isEntryPoint: bool, genericParams: ILGenericParameterDefs,
16281618
securityDeclsStored: ILSecurityDeclsStored, customAttrsStored: ILAttributesStored, metadataIndex: int32) =
16291619

16301620
new (name, attributes, implAttributes, callingConv, parameters, ret, body, isEntryPoint, genericParams, securityDecls, customAttrs) =
16311621
ILMethodDef (name, attributes, implAttributes, callingConv, parameters, ret, body, isEntryPoint, genericParams,
16321622
storeILSecurityDecls securityDecls, storeILCustomAttrs customAttrs, NoMetadataIdx)
16331623

1624+
member private _.LazyBody = body
1625+
16341626
// The captured data - remember the object will be as large as the data captured by these members
16351627
member _.Name = name
16361628

@@ -1644,7 +1636,7 @@ type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: Me
16441636

16451637
member _.Return = ret
16461638

1647-
member _.Body = body
1639+
member _.Body = body.Value
16481640

16491641
member _.SecurityDeclsStored = securityDeclsStored
16501642

@@ -1658,7 +1650,7 @@ type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: Me
16581650

16591651
member x.With (?name: string, ?attributes: MethodAttributes, ?implAttributes: MethodImplAttributes,
16601652
?callingConv: ILCallingConv, ?parameters: ILParameters, ?ret: ILReturn,
1661-
?body: ILLazyMethodBody, ?securityDecls: ILSecurityDecls, ?isEntryPoint: bool,
1653+
?body: Lazy<MethodBody>, ?securityDecls: ILSecurityDecls, ?isEntryPoint: bool,
16621654
?genericParams: ILGenericParameterDefs, ?customAttrs: ILAttributes) =
16631655

16641656
ILMethodDef (name = defaultArg name x.Name,
@@ -1667,7 +1659,7 @@ type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: Me
16671659
callingConv = defaultArg callingConv x.CallingConv,
16681660
parameters = defaultArg parameters x.Parameters,
16691661
ret = defaultArg ret x.Return,
1670-
body = defaultArg body x.Body,
1662+
body = defaultArg body x.LazyBody,
16711663
securityDecls = (match securityDecls with None -> x.SecurityDecls | Some attrs -> attrs),
16721664
isEntryPoint = defaultArg isEntryPoint x.IsEntryPoint,
16731665
genericParams = defaultArg genericParams x.GenericParams,
@@ -1680,15 +1672,15 @@ type ILMethodDef (name: string, attributes: MethodAttributes, implAttributes: Me
16801672
member x.ParameterTypes = typesOfILParams x.Parameters
16811673

16821674
member md.Code =
1683-
match md.Body.Contents with
1684-
| MethodBody.IL il-> Some il.Code
1675+
match md.Body with
1676+
| MethodBody.IL il-> Some il.Value.Code
16851677
| _ -> None
16861678

1687-
member x.IsIL = match x.Body.Contents with | MethodBody.IL _ -> true | _ -> false
1679+
member x.IsIL = match x.Body with | MethodBody.IL _ -> true | _ -> false
16881680

1689-
member x.Locals = match x.Body.Contents with | MethodBody.IL il -> il.Locals | _ -> []
1681+
member x.Locals = match x.Body with | MethodBody.IL il -> il.Value.Locals | _ -> []
16901682

1691-
member x.MethodBody = match x.Body.Contents with MethodBody.IL il -> il | _ -> failwith "not IL"
1683+
member x.MethodBody = match x.Body with MethodBody.IL il -> il.Value | _ -> failwith "not IL"
16921684

16931685
member x.SourceMarker = x.MethodBody.SourceMarker
16941686

@@ -2938,19 +2930,21 @@ let mkILMethodBody (initlocals, locals, maxstack, code, tag) : ILMethodBody =
29382930
Code= code
29392931
SourceMarker=tag }
29402932

2941-
let mkMethodBody (zeroinit, locals, maxstack, code, tag) = MethodBody.IL (mkILMethodBody (zeroinit, locals, maxstack, code, tag))
2933+
let mkMethodBody (zeroinit, locals, maxstack, code, tag) =
2934+
let ilCode = mkILMethodBody (zeroinit, locals, maxstack, code, tag)
2935+
MethodBody.IL (lazy ilCode)
29422936

29432937
// --------------------------------------------------------------------
29442938
// Make a constructor
29452939
// --------------------------------------------------------------------
29462940

29472941
let mkILVoidReturn = mkILReturn ILType.Void
29482942

2949-
let methBodyNotAvailable = mkMethBodyAux MethodBody.NotAvailable
2943+
let methBodyNotAvailable = notlazy MethodBody.NotAvailable
29502944

2951-
let methBodyAbstract = mkMethBodyAux MethodBody.Abstract
2945+
let methBodyAbstract = notlazy MethodBody.Abstract
29522946

2953-
let methBodyNative = mkMethBodyAux MethodBody.Native
2947+
let methBodyNative = notlazy MethodBody.Native
29542948

29552949
let mkILCtor (access, args, impl) =
29562950
ILMethodDef(name=".ctor",
@@ -2959,7 +2953,7 @@ let mkILCtor (access, args, impl) =
29592953
callingConv=ILCallingConv.Instance,
29602954
parameters = args,
29612955
ret= mkILVoidReturn,
2962-
body= mkMethBodyAux impl,
2956+
body= notlazy impl,
29632957
securityDecls=emptyILSecurityDecls,
29642958
isEntryPoint=false,
29652959
genericParams=mkILEmptyGenericParams,
@@ -3008,7 +3002,7 @@ let mkILStaticMethod (genparams, nm, access, args, ret, impl) =
30083002
securityDecls=emptyILSecurityDecls,
30093003
isEntryPoint=false,
30103004
customAttrs = emptyILCustomAttrs,
3011-
body= mkMethBodyAux impl)
3005+
body= notlazy impl)
30123006

30133007
let mkILNonGenericStaticMethod (nm, access, args, ret, impl) =
30143008
mkILStaticMethod (mkILEmptyGenericParams, nm, access, args, ret, impl)
@@ -3024,7 +3018,7 @@ let mkILClassCtor impl =
30243018
isEntryPoint=false,
30253019
securityDecls=emptyILSecurityDecls,
30263020
customAttrs=emptyILCustomAttrs,
3027-
body= mkMethBodyAux impl)
3021+
body= notlazy impl)
30283022

30293023
// --------------------------------------------------------------------
30303024
// Make a virtual method, where the overriding is simply the default
@@ -3048,7 +3042,7 @@ let mkILGenericVirtualMethod (nm, access, genparams, actual_args, actual_ret, im
30483042
isEntryPoint=false,
30493043
securityDecls=emptyILSecurityDecls,
30503044
customAttrs = emptyILCustomAttrs,
3051-
body= mkMethBodyAux impl)
3045+
body= notlazy impl)
30523046

30533047
let mkILNonGenericVirtualMethod (nm, access, args, ret, impl) =
30543048
mkILGenericVirtualMethod (nm, access, mkILEmptyGenericParams, args, ret, impl)
@@ -3064,7 +3058,7 @@ let mkILGenericNonVirtualMethod (nm, access, genparams, actual_args, actual_ret,
30643058
isEntryPoint=false,
30653059
securityDecls=emptyILSecurityDecls,
30663060
customAttrs = emptyILCustomAttrs,
3067-
body= mkMethBodyAux impl)
3061+
body= notlazy impl)
30683062

30693063
let mkILNonGenericInstanceMethod (nm, access, args, ret, impl) =
30703064
mkILGenericNonVirtualMethod (nm, access, mkILEmptyGenericParams, args, ret, impl)
@@ -3080,11 +3074,12 @@ let ilmbody_code2code f (il: ILMethodBody) =
30803074

30813075
let mdef_code2code f (md: ILMethodDef) =
30823076
let il =
3083-
match md.Body.Contents with
3077+
match md.Body with
30843078
| MethodBody.IL il-> il
30853079
| _ -> failwith "mdef_code2code - method not IL"
3086-
let b = MethodBody.IL (ilmbody_code2code f il)
3087-
md.With(body = mkMethBodyAux b)
3080+
let ilCode = ilmbody_code2code f il.Value
3081+
let b = MethodBody.IL (notlazy ilCode)
3082+
md.With(body = notlazy b)
30883083

30893084
let prependInstrsToCode (instrs: ILInstr list) (c2: ILCode) =
30903085
let instrs = Array.ofList instrs
@@ -4170,14 +4165,14 @@ and refs_of_local s loc = refs_of_typ s loc.Type
41704165

41714166
and refs_of_mbody s x =
41724167
match x with
4173-
| MethodBody.IL il -> refs_of_ilmbody s il
4174-
| MethodBody.PInvoke (attr) -> refs_of_modref s attr.Where
4168+
| MethodBody.IL il -> refs_of_ilmbody s il.Value
4169+
| MethodBody.PInvoke (attr) -> refs_of_modref s attr.Value.Where
41754170
| _ -> ()
41764171

41774172
and refs_of_mdef s (md: ILMethodDef) =
41784173
List.iter (refs_of_param s) md.Parameters
41794174
refs_of_return s md.Return
4180-
refs_of_mbody s md.Body.Contents
4175+
refs_of_mbody s md.Body
41814176
refs_of_custom_attrs s md.CustomAttrs
41824177
refs_of_genparams s md.GenericParams
41834178

0 commit comments

Comments
 (0)