@@ -2353,9 +2353,7 @@ and CodeGenMethodForExpr cenv mgbuf (spReq, entryPointInfo, methodName, eenv, al
23532353 CodeGenMethod cenv mgbuf ( entryPointInfo, methodName, eenv, alreadyUsedArgs,
23542354 ( fun cgbuf eenv -> GenExpr cenv cgbuf eenv spReq expr0 sequel0),
23552355 expr0.Range)
2356- code
2357-
2358-
2356+ code
23592357
23602358//--------------------------------------------------------------------------
23612359// Generate sequels
@@ -4305,9 +4303,65 @@ and GenGenericParams cenv eenv tps =
43054303and GenGenericArgs m ( tyenv : TypeReprEnv ) tps =
43064304 tps |> DropErasedTypars |> List.map ( fun c -> ( mkILTyvarTy tyenv.[ c, m]))
43074305
4306+ and DelayGenMethodForLambda cenv mgbuf eenv args =
4307+ cenv.delayedGenMethods.Enqueue( fun cenv -> GenMethodForLambda cenv mgbuf eenv args)
4308+
4309+ and GenMethodForLambda cenv mgbuf eenv ( entryPointInfo , cloinfo , eenvinner , body , isLocalTypeFunc , m ) =
4310+ let g = cenv.g
4311+ let ilCloBody = CodeGenMethodForExpr cenv mgbuf ( SPAlways, entryPointInfo, cloinfo.cloName, eenvinner, 1 , body, Return)
4312+ let ilCloTypeRef = cloinfo.cloSpec.TypeRef
4313+ let cloTypeDefs =
4314+ if isLocalTypeFunc then
4315+
4316+ // Work out the contract type and generate a class with an abstract method for this type
4317+ let ( ilContractGenericParams , ilContractMethTyargs , ilContractTySpec : ILTypeSpec , ilContractFormalRetTy ) = GenNamedLocalTypeFuncContractInfo cenv eenv m cloinfo
4318+ let ilContractTypeRef = ilContractTySpec.TypeRef
4319+ let ilContractTy = mkILFormalBoxedTy ilContractTypeRef ilContractGenericParams
4320+ let ilContractCtor = mkILNonGenericEmptyCtor None g.ilg.typ_ Object
4321+
4322+ let ilContractMeths = [ ilContractCtor; mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, ilContractMethTyargs, [], mkILReturn ilContractFormalRetTy, MethodBody.Abstract) ]
4323+ let ilContractTypeDef =
4324+ ILTypeDef( name = ilContractTypeRef.Name,
4325+ layout = ILTypeDefLayout.Auto,
4326+ attributes = enum 0 ,
4327+ genericParams = ilContractGenericParams,
4328+ customAttrs = mkILCustomAttrs [ mkCompilationMappingAttr g ( int SourceConstructFlags.Closure) ],
4329+ fields = emptyILFields,
4330+ events= emptyILEvents,
4331+ properties = emptyILProperties,
4332+ methods= mkILMethods ilContractMeths,
4333+ methodImpls= emptyILMethodImpls,
4334+ nestedTypes= emptyILTypeDefs,
4335+ implements = [],
4336+ extends= Some g.ilg.typ_ Object,
4337+ securityDecls= emptyILSecurityDecls)
4338+
4339+ // the contract type is an abstract type and not sealed
4340+ let ilContractTypeDef =
4341+ ilContractTypeDef
4342+ .WithAbstract( true )
4343+ .WithAccess( ComputeTypeAccess ilContractTypeRef true )
4344+ .WithSerializable( true )
4345+ .WithSpecialName( true )
4346+ .WithLayout( ILTypeDefLayout.Auto)
4347+ .WithInitSemantics( ILTypeInit.BeforeField)
4348+ .WithEncoding( ILDefaultPInvokeEncoding.Auto)
4349+
4350+ mgbuf.AddTypeDef( ilContractTypeRef, ilContractTypeDef, false , false , None)
4351+
4352+ let ilCtorBody = mkILMethodBody ( true , [], 8 , nonBranchingInstrsToCode ( mkCallBaseConstructor( ilContractTy, [])), None )
4353+ let cloMethods = [ mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn ( cloinfo.cloILFormalRetTy), MethodBody.IL ilCloBody) ]
4354+ let cloTypeDefs = GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCtorBody, cloMethods, [], ilContractTy, [])
4355+ cloTypeDefs
4356+
4357+ else
4358+ GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCloBody, [], [], g.ilg.typ_ Object, [])
4359+ CountClosure()
4360+ for cloTypeDef in cloTypeDefs do
4361+ mgbuf.AddTypeDef( ilCloTypeRef, cloTypeDef, false , false , None)
4362+
43084363/// Generate the closure class for a function
43094364and GenLambdaClosure cenv ( cgbuf : CodeGenBuffer ) eenv isLocalTypeFunc selfv expr =
4310- let g = cenv.g
43114365 match expr with
43124366 | Expr.Lambda (_, _, _, _, _, m, _)
43134367 | Expr.TyLambda (_, _, _, m, _) ->
@@ -4319,57 +4373,7 @@ and GenLambdaClosure cenv (cgbuf: CodeGenBuffer) eenv isLocalTypeFunc selfv expr
43194373 | Some v -> [( v, BranchCallClosure ( cloinfo.cloArityInfo))]
43204374 | _ -> []
43214375
4322- let ilCloBody = CodeGenMethodForExpr cenv cgbuf.mgbuf ( SPAlways, entryPointInfo, cloinfo.cloName, eenvinner, 1 , body, Return)
4323- let ilCloTypeRef = cloinfo.cloSpec.TypeRef
4324- let cloTypeDefs =
4325- if isLocalTypeFunc then
4326-
4327- // Work out the contract type and generate a class with an abstract method for this type
4328- let ( ilContractGenericParams , ilContractMethTyargs , ilContractTySpec : ILTypeSpec , ilContractFormalRetTy ) = GenNamedLocalTypeFuncContractInfo cenv eenv m cloinfo
4329- let ilContractTypeRef = ilContractTySpec.TypeRef
4330- let ilContractTy = mkILFormalBoxedTy ilContractTypeRef ilContractGenericParams
4331- let ilContractCtor = mkILNonGenericEmptyCtor None g.ilg.typ_ Object
4332-
4333- let ilContractMeths = [ ilContractCtor; mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, ilContractMethTyargs, [], mkILReturn ilContractFormalRetTy, MethodBody.Abstract) ]
4334- let ilContractTypeDef =
4335- ILTypeDef( name = ilContractTypeRef.Name,
4336- layout = ILTypeDefLayout.Auto,
4337- attributes = enum 0 ,
4338- genericParams = ilContractGenericParams,
4339- customAttrs = mkILCustomAttrs [ mkCompilationMappingAttr g ( int SourceConstructFlags.Closure) ],
4340- fields = emptyILFields,
4341- events= emptyILEvents,
4342- properties = emptyILProperties,
4343- methods= mkILMethods ilContractMeths,
4344- methodImpls= emptyILMethodImpls,
4345- nestedTypes= emptyILTypeDefs,
4346- implements = [],
4347- extends= Some g.ilg.typ_ Object,
4348- securityDecls= emptyILSecurityDecls)
4349-
4350- // the contract type is an abstract type and not sealed
4351- let ilContractTypeDef =
4352- ilContractTypeDef
4353- .WithAbstract( true )
4354- .WithAccess( ComputeTypeAccess ilContractTypeRef true )
4355- .WithSerializable( true )
4356- .WithSpecialName( true )
4357- .WithLayout( ILTypeDefLayout.Auto)
4358- .WithInitSemantics( ILTypeInit.BeforeField)
4359- .WithEncoding( ILDefaultPInvokeEncoding.Auto)
4360-
4361- cgbuf.mgbuf.AddTypeDef( ilContractTypeRef, ilContractTypeDef, false , false , None)
4362-
4363- let ilCtorBody = mkILMethodBody ( true , [], 8 , nonBranchingInstrsToCode ( mkCallBaseConstructor( ilContractTy, [])), None )
4364- let cloMethods = [ mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn ( cloinfo.cloILFormalRetTy), MethodBody.IL ilCloBody) ]
4365- let cloTypeDefs = GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCtorBody, cloMethods, [], ilContractTy, [])
4366- cloTypeDefs
4367-
4368- else
4369- GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCloBody, [], [], g.ilg.typ_ Object, [])
4370- CountClosure()
4371- for cloTypeDef in cloTypeDefs do
4372- cgbuf.mgbuf.AddTypeDef( ilCloTypeRef, cloTypeDef, false , false , None)
4376+ DelayGenMethodForLambda cenv cgbuf.mgbuf eenv ( entryPointInfo, cloinfo, eenvinner, body, isLocalTypeFunc, m)
43734377 cloinfo, m
43744378
43754379 | _ -> failwith " GenLambda: not a lambda"
0 commit comments