@@ -4383,62 +4383,9 @@ and GenGenericParams cenv eenv tps =
43834383and GenGenericArgs m ( tyenv : TypeReprEnv ) tps =
43844384 tps |> DropErasedTypars |> List.map ( fun c -> ( mkILTyvarTy tyenv.[ c, m]))
43854385
4386- and GenMethodForLambda cenv mgbuf eenv ( entryPointInfo , cloinfo , eenvinner , body , isLocalTypeFunc , m ) =
4387- let g = cenv.g
4388- let ilCloBody = CodeGenMethodForExpr cenv mgbuf ( SPAlways, entryPointInfo, cloinfo.cloName, eenvinner, 1 , body, Return)
4389- let ilCloTypeRef = cloinfo.cloSpec.TypeRef
4390- let cloTypeDefs =
4391- if isLocalTypeFunc then
4392-
4393- // Work out the contract type and generate a class with an abstract method for this type
4394- let ( ilContractGenericParams , ilContractMethTyargs , ilContractTySpec : ILTypeSpec , ilContractFormalRetTy ) = GenNamedLocalTypeFuncContractInfo cenv eenv m cloinfo
4395- let ilContractTypeRef = ilContractTySpec.TypeRef
4396- let ilContractTy = mkILFormalBoxedTy ilContractTypeRef ilContractGenericParams
4397- let ilContractCtor = mkILNonGenericEmptyCtor None g.ilg.typ_ Object
4398-
4399- let ilContractMeths = [ ilContractCtor; mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, ilContractMethTyargs, [], mkILReturn ilContractFormalRetTy, MethodBody.Abstract) ]
4400- let ilContractTypeDef =
4401- ILTypeDef( name = ilContractTypeRef.Name,
4402- layout = ILTypeDefLayout.Auto,
4403- attributes = enum 0 ,
4404- genericParams = ilContractGenericParams,
4405- customAttrs = mkILCustomAttrs [ mkCompilationMappingAttr g ( int SourceConstructFlags.Closure) ],
4406- fields = emptyILFields,
4407- events= emptyILEvents,
4408- properties = emptyILProperties,
4409- methods= mkILMethods ilContractMeths,
4410- methodImpls= emptyILMethodImpls,
4411- nestedTypes= emptyILTypeDefs,
4412- implements = [],
4413- extends= Some g.ilg.typ_ Object,
4414- securityDecls= emptyILSecurityDecls)
4415-
4416- // the contract type is an abstract type and not sealed
4417- let ilContractTypeDef =
4418- ilContractTypeDef
4419- .WithAbstract( true )
4420- .WithAccess( ComputeTypeAccess ilContractTypeRef true )
4421- .WithSerializable( true )
4422- .WithSpecialName( true )
4423- .WithLayout( ILTypeDefLayout.Auto)
4424- .WithInitSemantics( ILTypeInit.BeforeField)
4425- .WithEncoding( ILDefaultPInvokeEncoding.Auto)
4426-
4427- mgbuf.AddTypeDef( ilContractTypeRef, ilContractTypeDef, false , false , None)
4428-
4429- let ilCtorBody = mkILMethodBody ( true , [], 8 , nonBranchingInstrsToCode ( mkCallBaseConstructor( ilContractTy, [])), None )
4430- let cloMethods = [ mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn ( cloinfo.cloILFormalRetTy), MethodBody.IL ilCloBody) ]
4431- let cloTypeDefs = GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCtorBody, cloMethods, [], ilContractTy, [])
4432- cloTypeDefs
4433-
4434- else
4435- GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCloBody, [], [], g.ilg.typ_ Object, [])
4436- CountClosure()
4437- for cloTypeDef in cloTypeDefs do
4438- mgbuf.AddTypeDef( ilCloTypeRef, cloTypeDef, false , false , None)
4439-
44404386/// Generate the closure class for a function
44414387and GenLambdaClosure cenv ( cgbuf : CodeGenBuffer ) eenv isLocalTypeFunc selfv expr =
4388+ let g = cenv.g
44424389 match expr with
44434390 | Expr.Lambda (_, _, _, _, _, m, _)
44444391 | Expr.TyLambda (_, _, _, m, _) ->
@@ -4450,7 +4397,57 @@ and GenLambdaClosure cenv (cgbuf: CodeGenBuffer) eenv isLocalTypeFunc selfv expr
44504397 | Some v -> [( v, BranchCallClosure ( cloinfo.cloArityInfo))]
44514398 | _ -> []
44524399
4453- GenMethodForLambda cenv cgbuf.mgbuf eenv ( entryPointInfo, cloinfo, eenvinner, body, isLocalTypeFunc, m)
4400+ let ilCloBody = CodeGenMethodForExpr cenv cgbuf.mgbuf ( SPAlways, entryPointInfo, cloinfo.cloName, eenvinner, 1 , body, Return)
4401+ let ilCloTypeRef = cloinfo.cloSpec.TypeRef
4402+ let cloTypeDefs =
4403+ if isLocalTypeFunc then
4404+
4405+ // Work out the contract type and generate a class with an abstract method for this type
4406+ let ( ilContractGenericParams , ilContractMethTyargs , ilContractTySpec : ILTypeSpec , ilContractFormalRetTy ) = GenNamedLocalTypeFuncContractInfo cenv eenv m cloinfo
4407+ let ilContractTypeRef = ilContractTySpec.TypeRef
4408+ let ilContractTy = mkILFormalBoxedTy ilContractTypeRef ilContractGenericParams
4409+ let ilContractCtor = mkILNonGenericEmptyCtor None g.ilg.typ_ Object
4410+
4411+ let ilContractMeths = [ ilContractCtor; mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, ilContractMethTyargs, [], mkILReturn ilContractFormalRetTy, MethodBody.Abstract) ]
4412+ let ilContractTypeDef =
4413+ ILTypeDef( name = ilContractTypeRef.Name,
4414+ layout = ILTypeDefLayout.Auto,
4415+ attributes = enum 0 ,
4416+ genericParams = ilContractGenericParams,
4417+ customAttrs = mkILCustomAttrs [ mkCompilationMappingAttr g ( int SourceConstructFlags.Closure) ],
4418+ fields = emptyILFields,
4419+ events= emptyILEvents,
4420+ properties = emptyILProperties,
4421+ methods= mkILMethods ilContractMeths,
4422+ methodImpls= emptyILMethodImpls,
4423+ nestedTypes= emptyILTypeDefs,
4424+ implements = [],
4425+ extends= Some g.ilg.typ_ Object,
4426+ securityDecls= emptyILSecurityDecls)
4427+
4428+ // the contract type is an abstract type and not sealed
4429+ let ilContractTypeDef =
4430+ ilContractTypeDef
4431+ .WithAbstract( true )
4432+ .WithAccess( ComputeTypeAccess ilContractTypeRef true )
4433+ .WithSerializable( true )
4434+ .WithSpecialName( true )
4435+ .WithLayout( ILTypeDefLayout.Auto)
4436+ .WithInitSemantics( ILTypeInit.BeforeField)
4437+ .WithEncoding( ILDefaultPInvokeEncoding.Auto)
4438+
4439+ cgbuf.mgbuf.AddTypeDef( ilContractTypeRef, ilContractTypeDef, false , false , None)
4440+
4441+ let ilCtorBody = mkILMethodBody ( true , [], 8 , nonBranchingInstrsToCode ( mkCallBaseConstructor( ilContractTy, [])), None )
4442+ let cloMethods = [ mkILGenericVirtualMethod( " DirectInvoke" , ILMemberAccess.Assembly, cloinfo.localTypeFuncDirectILGenericParams, [], mkILReturn ( cloinfo.cloILFormalRetTy), MethodBody.IL ilCloBody) ]
4443+ let cloTypeDefs = GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCtorBody, cloMethods, [], ilContractTy, [])
4444+ cloTypeDefs
4445+
4446+ else
4447+ GenClosureTypeDefs cenv ( ilCloTypeRef, cloinfo.cloILGenericParams, [], cloinfo.cloILFreeVars, cloinfo.ilCloLambdas, ilCloBody, [], [], g.ilg.typ_ Object, [])
4448+ CountClosure()
4449+ for cloTypeDef in cloTypeDefs do
4450+ cgbuf.mgbuf.AddTypeDef( ilCloTypeRef, cloTypeDef, false , false , None)
44544451 cloinfo, m
44554452
44564453 | _ -> failwith " GenLambda: not a lambda"
0 commit comments