diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index ba843ca702c..75c4390c7f4 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -110,6 +110,7 @@ ### Improved * Nullness warning FS3261 on dotted method or property access (e.g. `x.Member`) now underlines the receiver expression and includes the member name and (when known) the binding name in the message. ([Issue #19658](https://github.com/dotnet/fsharp/issues/19658), [PR #19814](https://github.com/dotnet/fsharp/pull/19814)) +* Direct delegate construction ([PR ##19993](https://github.com/dotnet/fsharp/pull/19993)) ### Changed diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index 90c1aa2faa6..1775f5ba65e 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -6,4 +6,6 @@ ### Fixed -### Changed \ No newline at end of file +### Changed + +* Direct delegate construction ([PR ##19993](https://github.com/dotnet/fsharp/pull/19993)) \ No newline at end of file diff --git a/src/Compiler/CodeGen/IlxGen.Delegates.fs b/src/Compiler/CodeGen/IlxGen.Delegates.fs new file mode 100644 index 00000000000..858f61c6821 --- /dev/null +++ b/src/Compiler/CodeGen/IlxGen.Delegates.fs @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. + +/// Helpers for delegate construction in the ILX generator +[] +module internal FSharp.Compiler.IlxGenDelegates + +open Internal.Utilities.Collections + +open FSharp.Compiler +open FSharp.Compiler.AbstractIL.IL +open FSharp.Compiler.TypedTree +open FSharp.Compiler.TypedTreeBasics +open FSharp.Compiler.TypedTreeOps + +/// A delegate target that can potentially be forwarded to directly, without an intermediate closure +[] +type DirectDelegateForwardingTargetCandidate = + /// A known F# value: a module-level function or a member + | FSharpVal of vref: ValRef * valUseFlags: ValUseFlag * tyargs: TypeInst * leadingArgs: Expr list + /// A direct IL method call (e.g. a BCL method) + | ILMethod of + isVirtual: bool * + isStruct: bool * + isCtor: bool * + valUseFlags: ValUseFlag * + ilMethRef: ILMethodRef * + enclTypeInst: TypeInst * + methInst: TypeInst * + leadingArgs: Expr list + | Other + +let classifyForwardingTarget g (invokeParams: Val list) expr = + // The trailing arguments of the call must be exactly the delegate's Invoke parameters, forwarded + // verbatim and in order. The remaining leading arguments (e.g. an instance receiver) are returned + // for the consumer to handle. + let matchForwarding (args: Expr list) = + let numLeading = args.Length - invokeParams.Length + + if numLeading >= 0 then + let leadingArgs, forwardedArgs = List.splitAt numLeading args + + if + List.forall2 + (fun (a: Expr) (tv: Val) -> + match stripDebugPoints a with + | Expr.Val(avref, _, _) -> valRefEq g avref (mkLocalValRef tv) + | _ -> false) + forwardedArgs + invokeParams + then + ValueSome leadingArgs + else + ValueNone + else + ValueNone + + match stripDebugPoints expr with + | Expr.App(Expr.Val(vref, valUseFlags, _), _, tyargs, args, _) -> + match matchForwarding args with + | ValueSome leadingArgs -> DirectDelegateForwardingTargetCandidate.FSharpVal(vref, valUseFlags, tyargs, leadingArgs) + | ValueNone -> DirectDelegateForwardingTargetCandidate.Other + | Expr.Op(TOp.ILCall(isVirtual, _, isStruct, isCtor, valUseFlag, _, _, ilMethRef, enclTypeInst, methInst, _), _, args, _) -> + match matchForwarding args with + | ValueSome leadingArgs -> + DirectDelegateForwardingTargetCandidate.ILMethod(isVirtual, isStruct, isCtor, valUseFlag, ilMethRef, enclTypeInst, methInst, leadingArgs) + | ValueNone -> DirectDelegateForwardingTargetCandidate.Other + | _ -> DirectDelegateForwardingTargetCandidate.Other + +/// For an instance method the single leading argument is the receiver; a static method or module function +/// must have no leading arguments (otherwise it is a partial application). +let private receiverShapeOk (leadingArgs: Expr list) takesInstanceArg = + if takesInstanceArg then + match leadingArgs with + | [ _ ] -> true + | _ -> false + else + List.isEmpty leadingArgs + +/// The receiver is hoisted to the delegate-construction site, so a direct delegate is only sound when it can +/// be evaluated there exactly once and as the Target: +/// - A closure built from an explicit eta-lambda (e.g. `fun a -> recv.M a`) re-evaluates the receiver on +/// every Invoke; evaluating it once instead is observable unless it is side-effect free (a non-mutable +/// value, a constant, a pure field read). +/// - It must not reference the delegate's own Invoke parameters, which only exist inside the delegee method. +/// ExprHasEffect short-circuits before the freeInExpr allocation, so disqualified delegates skip the traversal. +let private receiverBindable g (invokeParams: Val list) (leadingArgs: Expr list) = + match leadingArgs with + | [ recv ] -> + let recvFreeLocals = (freeInExpr CollectLocals recv).FreeLocals + + not (Optimizer.ExprHasEffect g recv) + && (not (invokeParams |> List.exists (fun tv -> Zset.contains tv recvFreeLocals))) + | _ -> true + +/// An F# value target can be pointed at directly only when the call needs no witnesses and is not a +/// constructor / base / self-init call, when the receiver shape is right, and when the receiver can be safely +/// hoisted to the construction site. Only the witness fact is passed in (it needs the IlxGen environment); the +/// newobj / super-init / self-init / instance-receiver facts are derived here from the member's call info, and +/// the base-call flag from valUseFlags. +let fsharpValDirectlyBindable g (invokeParams: Val list) (leadingArgs: Expr list) (vrefM: ValRef) (valUseFlags: ValUseFlag) hasWitnesses = + let _, _, newobj, isSuperInit, isSelfInit, takesInstanceArg, _, _ = + GetMemberCallInfo g (vrefM, valUseFlags) + + not hasWitnesses + && not newobj + && not isSuperInit + && not isSelfInit + && not valUseFlags.IsVSlotDirectCall + && receiverShapeOk leadingArgs takesInstanceArg + && receiverBindable g invokeParams leadingArgs + +/// An IL method target can be pointed at directly only when it is not a constructor / base / constrained call, +/// when the receiver shape is right, when the receiver is not a value type (boxing is not yet implemented), and +/// when the receiver can be safely hoisted to the construction site. The instance-receiver flag is derived here +/// from ilMethRef and the base/constrained-call flags from valUseFlag. +let ilMethodDirectlyBindable + g + (invokeParams: Val list) + (leadingArgs: Expr list) + (ilMethRef: ILMethodRef) + isStruct + (valUseFlag: ValUseFlag) + isCtor + = + let takesInstanceArg = ilMethRef.CallingConv.IsInstance + + not isCtor + && not valUseFlag.IsVSlotDirectCall + && not valUseFlag.IsPossibleConstrainedCall + && receiverShapeOk leadingArgs takesInstanceArg + && not (takesInstanceArg && isStruct) + && receiverBindable g invokeParams leadingArgs + +/// Confirm the target's IL signature is compatible with the delegate's Invoke. The type checker has already +/// verified the delegate is built from a compatible function shape and the forwarding match pins the arity, +/// so this is the residual check: +/// - parameter *count* matches (essentially a sanity check). Parameter IL *types* are deliberately not +/// compared: a value-type parameter is exact by construction (a widening/boxing argument would not be a +/// verbatim Val and so would not have matched), and for reference-type parameters the CLR's delegate +/// relaxation permits contravariance, so an exact comparison would only produce false negatives. +/// - for a non-generic target, the return type matches exactly. This is the one IL mismatch the recognizer +/// cannot see and the CLR will not relax: notably an F# 'unit' return compiled to 'void' versus a delegate +/// whose Invoke returns 'Unit'. For a generic target the return is written in terms of type variables, so +/// no exact comparison is meaningful. +let signatureMatches + (ilDelegeeParams: ILParameter list) + (ilDelegeeRet: ILReturn) + (ilEnclArgTys: ILType list) + (ilMethArgTys: ILType list) + (targetMspec: ILMethodSpec) + = + let arityMatches = targetMspec.FormalArgTypes.Length = ilDelegeeParams.Length + + let returnMatches = + if List.isEmpty ilEnclArgTys && List.isEmpty ilMethArgTys then + ilDelegeeRet.Type = targetMspec.FormalReturnType + else + true + + arityMatches && returnMatches + +/// Package the receiver (if any) with the virtual-call flag for the consumer to emit. +let receiverInfo (leadingArgs: Expr list) virtualCall = + match leadingArgs with + | [ recv ] -> Some(recv, virtualCall) + | _ -> None diff --git a/src/Compiler/CodeGen/IlxGen.fs b/src/Compiler/CodeGen/IlxGen.fs index 9d56c2cec68..fda1a18a440 100644 --- a/src/Compiler/CodeGen/IlxGen.fs +++ b/src/Compiler/CodeGen/IlxGen.fs @@ -7462,108 +7462,224 @@ and GenDelegateExpr cenv cgbuf eenvouter expr (TObjExprMethod(slotsig, _attribs, let ilDelegeeParams, ilDelegeeRet = GenActualSlotsig m cenv envForDelegeeUnderTypars slotsig methTyparsOfOverridingMethod tmvs - let envForDelegeeMeth = - AddStorageForLocalVals g (List.mapi (fun i v -> (v, Arg(i + numthis))) tmvs) envForDelegeeUnderTypars + // Direct delegate construction: when the delegate body is a saturated, transparent forwarding call to a + // known static method, module-level function, or instance method, point the delegate straight at that + // method instead of generating an intermediate closure class. Anything that does not match exactly + // falls back to the closure path below. + let directDelegateTarget = + if not (g.langVersion.SupportsFeature LanguageFeature.DirectDelegateConstruction) then + None + elif + not cenv.options.localOptimizationsEnabled + && tmvs |> List.exists (fun v -> not v.IsCompilerGenerated) + then + // Eta-expanded delegate in an unoptimized build: the Invoke parameters are the user's own lambda + // variables, so keep the closure to preserve their names for debugging. Non-eta delegates (whose + // parameters are synthesized by BuildNewDelegateExpr) are always made direct; eta-expanded ones + // are made direct only in optimized builds, where debuggability is not a concern and the + // forwarding call survives to here. + None + else + match classifyForwardingTarget g tmvs body with + | DirectDelegateForwardingTargetCandidate.FSharpVal(vref, valUseFlags, tyargs, leadingArgs) -> + match StorageForValRef m vref eenvouter with + | Method(valReprInfo, vrefM, mspec, _, _, ctps, _, _, _, _, _, _) -> + let _, witnessInfos, _, _, _ = + GetValReprTypeInCompiledForm g valReprInfo ctps.Length vrefM.Type m - let ilMethodBody = - CodeGenMethodForExpr - cenv - cgbuf.mgbuf - ([], - delegeeMethName, - envForDelegeeMeth, - 1, - None, - body, - (if slotSigHasVoidReturnTy slotsig then - discardAndReturnVoid - else - Return)) + let hasWitnesses = ComputeGenerateWitnesses g eenvouter && not witnessInfos.IsEmpty - let delegeeInvokeMeth = - (if useStaticClosure then - mkILNonGenericStaticMethod - else - mkILNonGenericInstanceMethod) ( - delegeeMethName, - ILMemberAccess.Assembly, - ilDelegeeParams, - ilDelegeeRet, - MethodBody.IL(InterruptibleLazy.FromValue ilMethodBody) - ) + if fsharpValDirectlyBindable g tmvs leadingArgs vrefM valUseFlags hasWitnesses then + let _, virtualCall, _, _, _, takesInstanceArg, _, _ = + GetMemberCallInfo g (vrefM, valUseFlags) - let delegeeCtorMeth = - mkILSimpleStorageCtor (Some g.ilg.typ_Object.TypeSpec, ilDelegeeTyInner, [], [], ILMemberAccess.Assembly, None, eenvouter.imports) + let ilTyArgs = GenTypeArgs cenv m eenvouter.tyenv tyargs - let ilCtorBody = delegeeCtorMeth.MethodBody + let numEnclILTypeArgs = + if vrefM.MemberInfo.IsSome && not vrefM.IsExtensionMember then + List.length (vrefM.MemberApparentEntity.Typars |> DropErasedTypars) + else + 0 - let ilCloLambdas = Lambdas_return ilCtxtDelTy + if ilTyArgs.Length < numEnclILTypeArgs then + None + else + let ilEnclArgTys, ilMethArgTys = List.splitAt numEnclILTypeArgs ilTyArgs + let boxity = mspec.DeclaringType.Boxity + let targetMspec = mkILMethSpec (mspec.MethodRef, boxity, ilEnclArgTys, ilMethArgTys) - let cloTypeDefs = - (if useStaticClosure then - GenStaticDelegateClosureTypeDefs - else - GenClosureTypeDefs) - cenv - (ilDelegeeTypeRef, - ilDelegeeGenericParams, - [], - ilCloAllFreeVars, - ilCloLambdas, - ilCtorBody, - [ delegeeInvokeMeth ], - [], - g.ilg.typ_Object, - [], - None) + if takesInstanceArg <> targetMspec.MethodRef.CallingConv.IsInstance then + None + elif takesInstanceArg && boxity.IsAsValue then + // value-type receivers not handled + None + elif signatureMatches ilDelegeeParams ilDelegeeRet ilEnclArgTys ilMethArgTys targetMspec then + Some(targetMspec, receiverInfo leadingArgs virtualCall) + else + None + else + None + | _ -> None - for cloTypeDef in cloTypeDefs do - cgbuf.mgbuf.AddTypeDef(ilDelegeeTypeRef, cloTypeDef, false, false, None) + | DirectDelegateForwardingTargetCandidate.ILMethod(isVirtual, isStruct, isCtor, valUseFlag, ilMethRef, enclTypeInst, methInst, leadingArgs) -> + if ilMethodDirectlyBindable g tmvs leadingArgs ilMethRef isStruct valUseFlag isCtor then + let ilEnclArgTys = GenTypeArgs cenv m eenvouter.tyenv enclTypeInst + let ilMethArgTys = GenTypeArgs cenv m eenvouter.tyenv methInst + let boxity = if isStruct then AsValue else AsObject + let targetMspec = mkILMethSpec (ilMethRef, boxity, ilEnclArgTys, ilMethArgTys) + + // Unlike the F# case we cannot compare parameter/return IL types here: the target's + // types come from imported metadata, whose assembly scope refs differ from the + // compiler-generated delegee types (e.g. `System.Int32, System.Runtime` vs the bare + // primary-assembly form), so structural equality reports false negatives for the very + // primitives that always match. The forwarding match already pins the arity, and the + // type checker has verified the call is well-typed, so element compatibility holds by + // construction; an arity check is the sound guard (matching the generic case). + if targetMspec.FormalArgTypes.Length = ilDelegeeParams.Length then + Some(targetMspec, receiverInfo leadingArgs isVirtual) + else + None + else + None - CountClosure() + | DirectDelegateForwardingTargetCandidate.Other -> None - // Push the constructor for the delegee - let ctxtGenericArgsForDelegee = GenGenericArgs m eenvouter.tyenv cloFreeTyvars + match directDelegateTarget with + | Some(targetMspec, receiverInfo) -> + match receiverInfo with + | None -> + // Static target: the delegate carries a null receiver. + GenUnit cenv eenvouter m cgbuf + CG.EmitInstr cgbuf (pop 0) (Push [ g.ilg.typ_IntPtr ]) (I_ldftn targetMspec) + | Some(receiverExpr, isVirtual) -> + // Instance target: evaluate the receiver as the delegate's target object. + GenExpr cenv cgbuf eenvouter receiverExpr Continue + + if isVirtual then + // dup the receiver and bind the function pointer to its runtime type's override. + CG.EmitInstr cgbuf (pop 0) (Push [ targetMspec.DeclaringType ]) AI_dup + CG.EmitInstr cgbuf (pop 1) (Push [ g.ilg.typ_IntPtr ]) (I_ldvirtftn targetMspec) + else + CG.EmitInstr cgbuf (pop 0) (Push [ g.ilg.typ_IntPtr ]) (I_ldftn targetMspec) - if useStaticClosure then - GenUnit cenv eenvouter m cgbuf - else - let ilxCloSpec = - IlxClosureSpec.Create(IlxClosureRef(ilDelegeeTypeRef, ilCloLambdas, ilCloAllFreeVars), ctxtGenericArgsForDelegee, false) + // newobj Delegate::.ctor(object, native int) + let ilDelegeeCtorMethOuter = + mkCtorMethSpecForDelegate g.ilg (ilCtxtDelTy, useUIntPtrForDelegateCtor) - GenWitnessArgsFromWitnessInfos cenv cgbuf eenvouter m cloWitnessInfos + CG.EmitInstr cgbuf (pop 2) (Push [ ilCtxtDelTy ]) (I_newobj(ilDelegeeCtorMethOuter, None)) + GenSequel cenv eenvouter.cloc cgbuf sequel - for fv in cloFreeVars do - GenGetFreeVarForClosure cenv cgbuf eenvouter m fv + | None -> + let envForDelegeeMeth = + AddStorageForLocalVals g (List.mapi (fun i v -> (v, Arg(i + numthis))) tmvs) envForDelegeeUnderTypars - CG.EmitInstr - cgbuf - (pop ilCloAllFreeVars.Length) - (Push [ EraseClosures.mkTyOfLambdas cenv.ilxPubCloEnv ilCloLambdas ]) - (I_newobj(ilxCloSpec.Constructor, None)) + let ilMethodBody = + CodeGenMethodForExpr + cenv + cgbuf.mgbuf + ([], + delegeeMethName, + envForDelegeeMeth, + 1, + None, + body, + (if slotSigHasVoidReturnTy slotsig then + discardAndReturnVoid + else + Return)) + + let delegeeInvokeMeth = + (if useStaticClosure then + mkILNonGenericStaticMethod + else + mkILNonGenericInstanceMethod) ( + delegeeMethName, + ILMemberAccess.Assembly, + ilDelegeeParams, + ilDelegeeRet, + MethodBody.IL(InterruptibleLazy.FromValue ilMethodBody) + ) - // Push the function pointer to the Invoke method of the delegee - let ilDelegeeTyOuter = mkILBoxedTy ilDelegeeTypeRef ctxtGenericArgsForDelegee + let delegeeCtorMeth = + mkILSimpleStorageCtor ( + Some g.ilg.typ_Object.TypeSpec, + ilDelegeeTyInner, + [], + [], + ILMemberAccess.Assembly, + None, + eenvouter.imports + ) - let ilDelegeeInvokeMethOuter = - (if useStaticClosure then - mkILNonGenericStaticMethSpecInTy - else - mkILNonGenericInstanceMethSpecInTy) ( - ilDelegeeTyOuter, - "Invoke", - typesOfILParams ilDelegeeParams, - ilDelegeeRet.Type - ) + let ilCtorBody = delegeeCtorMeth.MethodBody - CG.EmitInstr cgbuf (pop 0) (Push [ g.ilg.typ_IntPtr ]) (I_ldftn ilDelegeeInvokeMethOuter) + let ilCloLambdas = Lambdas_return ilCtxtDelTy - // Instantiate the delegate - let ilDelegeeCtorMethOuter = - mkCtorMethSpecForDelegate g.ilg (ilCtxtDelTy, useUIntPtrForDelegateCtor) + let cloTypeDefs = + (if useStaticClosure then + GenStaticDelegateClosureTypeDefs + else + GenClosureTypeDefs) + cenv + (ilDelegeeTypeRef, + ilDelegeeGenericParams, + [], + ilCloAllFreeVars, + ilCloLambdas, + ilCtorBody, + [ delegeeInvokeMeth ], + [], + g.ilg.typ_Object, + [], + None) - CG.EmitInstr cgbuf (pop 2) (Push [ ilCtxtDelTy ]) (I_newobj(ilDelegeeCtorMethOuter, None)) - GenSequel cenv eenvouter.cloc cgbuf sequel + for cloTypeDef in cloTypeDefs do + cgbuf.mgbuf.AddTypeDef(ilDelegeeTypeRef, cloTypeDef, false, false, None) + + CountClosure() + + // Push the constructor for the delegee + let ctxtGenericArgsForDelegee = GenGenericArgs m eenvouter.tyenv cloFreeTyvars + + if useStaticClosure then + GenUnit cenv eenvouter m cgbuf + else + let ilxCloSpec = + IlxClosureSpec.Create(IlxClosureRef(ilDelegeeTypeRef, ilCloLambdas, ilCloAllFreeVars), ctxtGenericArgsForDelegee, false) + + GenWitnessArgsFromWitnessInfos cenv cgbuf eenvouter m cloWitnessInfos + + for fv in cloFreeVars do + GenGetFreeVarForClosure cenv cgbuf eenvouter m fv + + CG.EmitInstr + cgbuf + (pop ilCloAllFreeVars.Length) + (Push [ EraseClosures.mkTyOfLambdas cenv.ilxPubCloEnv ilCloLambdas ]) + (I_newobj(ilxCloSpec.Constructor, None)) + + // Push the function pointer to the Invoke method of the delegee + let ilDelegeeTyOuter = mkILBoxedTy ilDelegeeTypeRef ctxtGenericArgsForDelegee + + let ilDelegeeInvokeMethOuter = + (if useStaticClosure then + mkILNonGenericStaticMethSpecInTy + else + mkILNonGenericInstanceMethSpecInTy) ( + ilDelegeeTyOuter, + "Invoke", + typesOfILParams ilDelegeeParams, + ilDelegeeRet.Type + ) + + CG.EmitInstr cgbuf (pop 0) (Push [ g.ilg.typ_IntPtr ]) (I_ldftn ilDelegeeInvokeMethOuter) + + // Instantiate the delegate + let ilDelegeeCtorMethOuter = + mkCtorMethSpecForDelegate g.ilg (ilCtxtDelTy, useUIntPtrForDelegateCtor) + + CG.EmitInstr cgbuf (pop 2) (Push [ ilCtxtDelTy ]) (I_newobj(ilDelegeeCtorMethOuter, None)) + GenSequel cenv eenvouter.cloc cgbuf sequel /// Used to search FSharp.Core implementations of "^T : ^T" and decide whether the conditional activates and ExprIsTraitCall expr = diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index d29b5d3dde7..54132f2b406 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1822,3 +1822,4 @@ featurePreprocessorElif,"#elif preprocessor directive" 3889,tastNamespaceAndTypeWithSameNameInAssembly,"The namespace '%s' clashes with the type '%s'." featureExceptionFieldSerializationSupport,"emit GetObjectData and field-restoring deserialization constructor for exception types" featureErrorOnMissingSignatureAttribute,"error (rather than warning) when an enforced compiler-semantic attribute is present in the .fs but missing from the .fsi" +featureDirectDelegateConstruction,"construct delegates that point directly at the target method, avoiding an intermediate closure" diff --git a/src/Compiler/FSharp.Compiler.Service.fsproj b/src/Compiler/FSharp.Compiler.Service.fsproj index 5510af6b3f6..50492504777 100644 --- a/src/Compiler/FSharp.Compiler.Service.fsproj +++ b/src/Compiler/FSharp.Compiler.Service.fsproj @@ -442,6 +442,7 @@ + diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index da4ef690311..04f0e89dcfc 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -110,6 +110,7 @@ type LanguageFeature = | PreprocessorElif | ExceptionFieldSerializationSupport | ErrorOnMissingSignatureAttribute + | DirectDelegateConstruction /// LanguageVersion management type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) = @@ -263,6 +264,7 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) LanguageFeature.MethodOverloadsCache, previewVersion // Performance optimization for overload resolution LanguageFeature.ImplicitDIMCoverage, languageVersion110 LanguageFeature.ErrorOnMissingSignatureAttribute, previewVersion // Opt-in: turn FS3888 from warning into error + LanguageFeature.DirectDelegateConstruction, previewVersion ] static let defaultLanguageVersion = LanguageVersion("default") @@ -459,6 +461,7 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) | LanguageFeature.PreprocessorElif -> FSComp.SR.featurePreprocessorElif () | LanguageFeature.ExceptionFieldSerializationSupport -> FSComp.SR.featureExceptionFieldSerializationSupport () | LanguageFeature.ErrorOnMissingSignatureAttribute -> FSComp.SR.featureErrorOnMissingSignatureAttribute () + | LanguageFeature.DirectDelegateConstruction -> FSComp.SR.featureDirectDelegateConstruction () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 5ba352191af..51c41a951c9 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -101,6 +101,7 @@ type LanguageFeature = | PreprocessorElif | ExceptionFieldSerializationSupport | ErrorOnMissingSignatureAttribute + | DirectDelegateConstruction /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 3ea52c5b169..7ed8ac66b89 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding vzor discard ve vazbě použití diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index f9fc62909ef..d6313dda61c 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding Das Verwerfen des verwendeten Musters ist verbindlich. diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index eca7c688eed..10d4c46c8a6 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding descartar enlace de patrón en uso diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 0922cee5acd..2687a44b909 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding annuler le modèle dans la liaison d’utilisation diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index d39f0a33a85..7f955c5add6 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding rimuovi criterio nell'utilizzo dell'associazione diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 6f4969e8148..f65cdf8b0cf 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding 使用バインドでパターンを破棄する diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index fb488a6c240..fe21f373d13 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding 사용 중인 패턴 바인딩 무시 diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 2720c59fc22..47b24cf0213 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding odrzuć wzorzec w powiązaniu użycia diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 8fc5566545f..ef601ecc0a6 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding descartar o padrão em uso de associação diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 16eb9766b81..59779a48068 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding шаблон отмены в привязке использования diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index da5fd475a81..6a8ba91016c 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding kullanım bağlamasında deseni at diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index c43aa519603..16ab595ccfa 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding 放弃使用绑定模式 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index d287b294184..960719ebb8b 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -362,6 +362,11 @@ Deprecate places where 'seq' can be omitted + + construct delegates that point directly at the target method, avoiding an intermediate closure + construct delegates that point directly at the target method, avoiding an intermediate closure + + discard pattern in use binding 捨棄使用繫結中的模式 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs new file mode 100644 index 00000000000..c53cbdbec35 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs @@ -0,0 +1,47 @@ +module DelegateCustomType + +open System + +// Custom, F#-declared delegate types exercise construction with delegates defined in the *compiled* assembly +// (local scope, unlike imported BCL Func/Action) and with Invoke signatures the Func/Action tests do not +// cover: a multi-argument (tupled) signature, a generic delegate, and a byref parameter. (F# forbids curried +// delegate signatures — FS0950 — so every F# delegate has a single tupled Invoke parameter group.) Targets +// are [] so the optimized path genuinely emits the direct form rather than inlining the +// target away (no inline-race). + +type DTupled = delegate of int * int -> int +type DGen<'T> = delegate of 'T -> 'T +type DByref = delegate of byref -> unit + +[] +let acc (x: int) (y: int) : int = x + y + +[] +let ident (x: 'T) : 'T = x + +type C() = + [] + member _.M (x: int) (y: int) : int = x * y + +// Tupled-signature custom delegate: Invoke(int, int). +// 28. non-eta module function, custom delegate +let tupledNonEta () = DTupled(acc) +// 14. eta module function, custom delegate +let tupledEta () = DTupled(fun a b -> acc a b) + +// Instance member through a custom delegate: the receiver becomes the delegate's Target. +// 29. non-eta instance member, custom delegate +let instanceNonEta (c: C) = DTupled(c.M) +// 15. eta instance member, custom delegate +let instanceEta (c: C) = DTupled(fun a b -> c.M a b) + +// Generic custom delegate instantiated at int: Invoke(int):int over the generic target. +// 30. non-eta generic method, generic custom delegate +let genNonEta () = DGen(ident) +// 16. eta generic method, generic custom delegate +let genEta () = DGen(fun x -> ident x) + +// byref-parameter custom delegate: the body mutates through the byref, so it is not a transparent forwarding +// call and stays a closure. Documents that a byref Invoke parameter does not break the recognizer. +// 51. byref-parameter delegate (mutating body) +let byrefMutate () = DByref(fun x -> x <- x + 1) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..ebf7fcb3ce1 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,351 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public DTupled + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance int32 Invoke(int32 A_1, int32 A_2) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32 A_1, + int32 A_2, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance int32 EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DGen`1 + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance !T Invoke(!T A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(!T A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance !T EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DByref + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance void Invoke(int32& A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32& A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance void EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 M(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: mul + IL_0003: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname tupledEta@30 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::acc(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname instanceEta@36 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C c + .method public specialname rtspecialname instance void .ctor(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/instanceEta@36::c + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/instanceEta@36::c + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::M(int32, + int32) + IL_000d: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname genEta@42 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly::ident(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname byrefMutate@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32& x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldobj [runtime]System.Int32 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stobj [runtime]System.Int32 + IL_000e: ret + } + + } + + .method public static int32 acc(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static !!T ident(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + .method public static class assembly/DTupled tupledNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::acc(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled tupledEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/tupledEta@30::Invoke(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceNonEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::M(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/instanceEta@36::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/instanceEta@36::Invoke(int32, + int32) + IL_000c: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class assembly/DGen`1 genNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly::ident(!!0) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DGen`1 genEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/genEta@42::Invoke(int32) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DByref byrefMutate() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/byrefMutate@47::Invoke(int32&) + IL_0007: newobj instance void assembly/DByref::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..0441b15c935 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOff.il.bsl @@ -0,0 +1,417 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public DTupled + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance int32 Invoke(int32 A_1, int32 A_2) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32 A_1, + int32 A_2, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance int32 EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DGen`1 + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance !T Invoke(!T A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(!T A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance !T EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DByref + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance void Invoke(int32& A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32& A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance void EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 M(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: mul + IL_0003: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname tupledNonEta@28 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::acc(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname tupledEta@30 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::acc(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname instanceNonEta@34 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C c + .method public specialname rtspecialname instance void .ctor(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/instanceNonEta@34::c + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/instanceNonEta@34::c + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::M(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname instanceEta@36 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C c + .method public specialname rtspecialname instance void .ctor(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/instanceEta@36::c + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/instanceEta@36::c + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::M(int32, + int32) + IL_000d: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname genNonEta@40 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 delegateArg0) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly::ident(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname genEta@42 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly::ident(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname byrefMutate@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32& x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldobj [runtime]System.Int32 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stobj [runtime]System.Int32 + IL_000e: ret + } + + } + + .method public static int32 acc(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static !!T ident(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + .method public static class assembly/DTupled tupledNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/tupledNonEta@28::Invoke(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled tupledEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/tupledEta@30::Invoke(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceNonEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/instanceNonEta@34::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/instanceNonEta@34::Invoke(int32, + int32) + IL_000c: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class assembly/DTupled instanceEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/instanceEta@36::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/instanceEta@36::Invoke(int32, + int32) + IL_000c: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class assembly/DGen`1 genNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/genNonEta@40::Invoke(int32) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DGen`1 genEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/genEta@42::Invoke(int32) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DByref byrefMutate() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/byrefMutate@47::Invoke(int32&) + IL_0007: newobj instance void assembly/DByref::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..2b9e0be2d12 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,285 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public DTupled + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance int32 Invoke(int32 A_1, int32 A_2) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32 A_1, + int32 A_2, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance int32 EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DGen`1 + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance !T Invoke(!T A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(!T A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance !T EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DByref + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance void Invoke(int32& A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32& A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance void EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 M(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: mul + IL_0003: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname byrefMutate@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32& x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldobj [runtime]System.Int32 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stobj [runtime]System.Int32 + IL_000e: ret + } + + } + + .method public static int32 acc(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static !!T ident(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + .method public static class assembly/DTupled tupledNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::acc(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled tupledEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::acc(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceNonEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::M(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::M(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DGen`1 genNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly::ident(!!0) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DGen`1 genEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly::ident(!!0) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DByref byrefMutate() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/byrefMutate@47::Invoke(int32&) + IL_0007: newobj instance void assembly/DByref::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..0441b15c935 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateCustomType.fs.OptimizeOn.il.bsl @@ -0,0 +1,417 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable sealed nested public DTupled + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance int32 Invoke(int32 A_1, int32 A_2) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32 A_1, + int32 A_2, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance int32 EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DGen`1 + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance !T Invoke(!T A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(!T A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance !T EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable sealed nested public DByref + extends [runtime]System.MulticastDelegate + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig specialname rtspecialname instance void .ctor(object 'object', native int 'method') runtime managed + { + } + + .method public hidebysig strict virtual instance void Invoke(int32& A_1) runtime managed + { + } + + .method public hidebysig strict virtual + instance class [runtime]System.IAsyncResult + BeginInvoke(int32& A_1, + class [runtime]System.AsyncCallback callback, + object objects) runtime managed + { + } + + .method public hidebysig strict virtual instance void EndInvoke(class [runtime]System.IAsyncResult result) runtime managed + { + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 M(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: mul + IL_0003: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname tupledNonEta@28 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::acc(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname tupledEta@30 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::acc(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname instanceNonEta@34 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C c + .method public specialname rtspecialname instance void .ctor(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/instanceNonEta@34::c + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/instanceNonEta@34::c + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::M(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname instanceEta@36 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C c + .method public specialname rtspecialname instance void .ctor(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/instanceEta@36::c + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/instanceEta@36::c + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::M(int32, + int32) + IL_000d: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname genNonEta@40 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 delegateArg0) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly::ident(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname genEta@42 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly::ident(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname byrefMutate@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32& x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.0 + IL_0002: ldobj [runtime]System.Int32 + IL_0007: ldc.i4.1 + IL_0008: add + IL_0009: stobj [runtime]System.Int32 + IL_000e: ret + } + + } + + .method public static int32 acc(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static !!T ident(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + .method public static class assembly/DTupled tupledNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/tupledNonEta@28::Invoke(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled tupledEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/tupledEta@30::Invoke(int32, + int32) + IL_0007: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DTupled instanceNonEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/instanceNonEta@34::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/instanceNonEta@34::Invoke(int32, + int32) + IL_000c: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class assembly/DTupled instanceEta(class assembly/C c) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/instanceEta@36::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/instanceEta@36::Invoke(int32, + int32) + IL_000c: newobj instance void assembly/DTupled::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class assembly/DGen`1 genNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/genNonEta@40::Invoke(int32) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DGen`1 genEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/genEta@42::Invoke(int32) + IL_0007: newobj instance void class assembly/DGen`1::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class assembly/DByref byrefMutate() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/byrefMutate@47::Invoke(int32&) + IL_0007: newobj instance void assembly/DByref::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs new file mode 100644 index 00000000000..b21ed6be396 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs @@ -0,0 +1,19 @@ +module DelegateExtensionMethod + +open System +open System.Runtime.CompilerServices + +type Holder() = + class + end + +[] +type HolderExtensions = + [] + static member Combine (h: Holder, x: int, y: int) : int = x + y + +// An extension member compiles to a static method whose first parameter is the receiver, so using it as a +// delegate target binds that receiver as a leading argument - a partial application, which has no closed +// direct-delegate form. A closure must remain regardless of langversion. +// 50. extension member (receiver is a leading static arg) +let extensionEta (h: Holder) = Func(fun a b -> h.Combine(a, b)) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..66377f64db4 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + } + + .class auto ansi serializable nested public HolderExtensions + extends [runtime]System.Object + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 Combine(class assembly/Holder h, + int32 x, + int32 y) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname extensionEta@19 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/extensionEta@19::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/extensionEta@19::h + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call int32 assembly/HolderExtensions::Combine(class assembly/Holder, + int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 extensionEta(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/extensionEta@19::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/extensionEta@19::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..bdc4971648a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + } + + .class auto ansi serializable nested public HolderExtensions + extends [runtime]System.Object + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 Combine(class assembly/Holder h, + int32 x, + int32 y) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname extensionEta@19 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/extensionEta@19::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/extensionEta@19::h + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call int32 assembly/HolderExtensions::Combine(class assembly/Holder, + int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 extensionEta(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/extensionEta@19::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/extensionEta@19::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..66377f64db4 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + } + + .class auto ansi serializable nested public HolderExtensions + extends [runtime]System.Object + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 Combine(class assembly/Holder h, + int32 x, + int32 y) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname extensionEta@19 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/extensionEta@19::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/extensionEta@19::h + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call int32 assembly/HolderExtensions::Combine(class assembly/Holder, + int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 extensionEta(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/extensionEta@19::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/extensionEta@19::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..bdc4971648a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateExtensionMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + } + + .class auto ansi serializable nested public HolderExtensions + extends [runtime]System.Object + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 Combine(class assembly/Holder h, + int32 x, + int32 y) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.ExtensionAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname extensionEta@19 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/extensionEta@19::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/extensionEta@19::h + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call int32 assembly/HolderExtensions::Combine(class assembly/Holder, + int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 extensionEta(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/extensionEta@19::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/extensionEta@19::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs new file mode 100644 index 00000000000..535bee3d582 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs @@ -0,0 +1,13 @@ +module DelegateGenericInstanceMethod + +open System + +type C() = + member _.IMc<'T> (x: 'T) (y: 'T) : unit = () + member _.IMt<'T> (x: 'T, y: 'T) : unit = () + +// 5. eta generic instance method (curried application) +let case5_etaCurried (o: C) = Action(fun a b -> o.IMc a b) + +// 35. eta generic instance method, tupled application +let case35_etaTupled (o: C) = Action(fun a b -> o.IMt(a, b)) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..12696733399 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,179 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void IMc(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void IMt(!!T x, !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case5_etaCurried@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case5_etaCurried@10::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case5_etaCurried@10::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::IMc(!!0, + !!0) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case35_etaTupled@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case35_etaTupled@13::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case35_etaTupled@13::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::IMt(!!0, + !!0) + IL_000d: nop + IL_000e: ret + } + + } + + .method public static class [runtime]System.Action`2 case5_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case5_etaCurried@10::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case5_etaCurried@10::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case35_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case35_etaTupled@13::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case35_etaTupled@13::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..12696733399 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,179 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void IMc(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void IMt(!!T x, !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case5_etaCurried@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case5_etaCurried@10::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case5_etaCurried@10::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::IMc(!!0, + !!0) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case35_etaTupled@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case35_etaTupled@13::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case35_etaTupled@13::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::IMt(!!0, + !!0) + IL_000d: nop + IL_000e: ret + } + + } + + .method public static class [runtime]System.Action`2 case5_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case5_etaCurried@10::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case5_etaCurried@10::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case35_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case35_etaTupled@13::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case35_etaTupled@13::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..74be77228f1 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void IMc(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void IMt(!!T x, !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case5_etaCurried@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case35_etaTupled@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case5_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case5_etaCurried@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case35_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case35_etaTupled@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..74be77228f1 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericInstanceMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,139 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance void IMc(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void IMt(!!T x, !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case5_etaCurried@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case35_etaTupled@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case5_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case5_etaCurried@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case35_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case35_etaTupled@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs new file mode 100644 index 00000000000..a4e30bdaf08 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs @@ -0,0 +1,16 @@ +module DelegateGenericStaticMethod + +open System + +type G<'U> = + static member SMc<'T> (x: 'T) (y: 'T) : unit = () + static member SMt<'T> (x: 'T, y: 'T) : unit = () + +// 19. non-eta generic static method (generic type + generic method) +let case19_nonEta () = Action(G.SMc) + +// 3. eta generic static method (curried application) +let case3_etaCurried () = Action(fun a b -> G.SMc a b) + +// 33. eta generic static method, tupled application +let case33_etaTupled () = Action(fun a b -> G.SMt(a, b)) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..39cb26442a6 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,152 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public G`1 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void SMc(!!T x, + !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void SMt(!!T x, + !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case3_etaCurried@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void class assembly/G`1::SMc(!!0, + !!0) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case33_etaTupled@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void class assembly/G`1::SMt(!!0, + !!0) + IL_0007: nop + IL_0008: ret + } + + } + + .method public static class [runtime]System.Action`2 case19_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void class assembly/G`1::SMc(!!0, + !!0) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case3_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case3_etaCurried@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case33_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case33_etaTupled@16::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..52f0ce42863 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,171 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public G`1 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void SMc(!!T x, + !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void SMt(!!T x, + !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case19_nonEta@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void class assembly/G`1::SMc(!!0, + !!0) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case3_etaCurried@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void class assembly/G`1::SMc(!!0, + !!0) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case33_etaTupled@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void class assembly/G`1::SMt(!!0, + !!0) + IL_0007: nop + IL_0008: ret + } + + } + + .method public static class [runtime]System.Action`2 case19_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case19_nonEta@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case3_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case3_etaCurried@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case33_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case33_etaTupled@16::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..b3e611b286a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,156 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public G`1 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void SMc(!!T x, + !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void SMt(!!T x, + !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case19_nonEta@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case3_etaCurried@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case33_etaTupled@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case19_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case19_nonEta@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case3_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case3_etaCurried@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case33_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case33_etaTupled@16::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..97f8c55b9dc --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateGenericStaticMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,156 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public G`1 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void SMc(!!T x, + !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void SMt(!!T x, + !!T y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case19_nonEta@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case3_etaCurried@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case33_etaTupled@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case19_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case19_nonEta@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case3_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case3_etaCurried@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case33_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case33_etaTupled@16::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs new file mode 100644 index 00000000000..5be6e249aff --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs @@ -0,0 +1,16 @@ +module DelegateILMethod + +open System +open System.Text + +// IL (BCL) method targets are compiled as TOp.ILCall rather than an F# value application. They are made +// direct only when the eta-expanded forwarding call survives to codegen, i.e. in optimized builds; in +// unoptimized builds the eta form keeps a closure (matching the F# eta policy). See DelegateNonInlinable +// for the F#-value equivalent. + +// 12. eta IL/BCL static method (System.Math.Max). +let ilStaticEta () = Func(fun a b -> Math.Max(a, b)) + +// 13. eta IL/BCL instance method (StringBuilder.Append(string)) on a reference type. The receiver is a +// parameter, evaluated at the construction site and carried as the delegate's Target. +let ilInstanceEta (sb: StringBuilder) = Func(fun s -> sb.Append(s)) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..12ffd3cce34 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,127 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname ilStaticEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 [runtime]System.Math::Max(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname ilInstanceEta@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [runtime]System.Text.StringBuilder sb + .method public specialname rtspecialname instance void .ctor(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance class [runtime]System.Text.StringBuilder Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0006: ldarg.1 + IL_0007: callvirt instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(string) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Func`3 ilStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/ilStaticEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 ilInstanceEta(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/ilInstanceEta@16::.ctor(class [runtime]System.Text.StringBuilder) + IL_0006: ldftn instance class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..718255efb91 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,127 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname ilStaticEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 [runtime]System.Math::Max(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname ilInstanceEta@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [runtime]System.Text.StringBuilder sb + .method public specialname rtspecialname instance void .ctor(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance class [runtime]System.Text.StringBuilder Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0006: ldarg.1 + IL_0007: callvirt instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(string) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Func`3 ilStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/ilStaticEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 ilInstanceEta(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/ilInstanceEta@16::.ctor(class [runtime]System.Text.StringBuilder) + IL_0006: ldftn instance class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..ef4e95130a2 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,78 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .method public static class [runtime]System.Func`3 ilStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 [runtime]System.Math::Max(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 ilInstanceEta(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(string) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..718255efb91 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateILMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,127 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname ilStaticEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 [runtime]System.Math::Max(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname ilInstanceEta@16 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [runtime]System.Text.StringBuilder sb + .method public specialname rtspecialname instance void .ctor(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance class [runtime]System.Text.StringBuilder Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::sb + IL_0006: ldarg.1 + IL_0007: callvirt instance class [runtime]System.Text.StringBuilder [runtime]System.Text.StringBuilder::Append(string) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Func`3 ilStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/ilStaticEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 ilInstanceEta(class [runtime]System.Text.StringBuilder sb) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/ilInstanceEta@16::.ctor(class [runtime]System.Text.StringBuilder) + IL_0006: ldftn instance class [runtime]System.Text.StringBuilder assembly/ilInstanceEta@16::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs new file mode 100644 index 00000000000..76c6c53e334 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs @@ -0,0 +1,21 @@ +module DelegateInstanceMethod + +open System + +type C(k: int) = + member _.AddC (x: int) (y: int) : unit = ignore k + member _.AddT (x: int, y: int) : unit = ignore k + abstract V : int -> int -> unit + default _.V (x: int) (y: int) : unit = ignore k + +// 20. non-eta instance method +let case20_nonEta (o: C) = Action(o.AddC) + +// 4. eta instance method (curried application) +let case4_etaCurried (o: C) = Action(fun a b -> o.AddC a b) + +// 34. eta instance method, tupled application +let case34_etaTupled (o: C) = Action(fun a b -> o.AddT(a, b)) + +// 21. non-eta virtual instance method: a direct delegate must use ldvirtftn (with dup) to preserve dispatch +let case21_virtual (o: C) = Action(o.V) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..876f6a1aaee --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,228 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance void AddC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + .method public hidebysig instance void AddT(int32 x, int32 y) cil managed + { + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + .method public hidebysig virtual instance void V(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case4_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case4_etaCurried@15::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case4_etaCurried@15::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::AddC(int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case34_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case34_etaTupled@18::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case34_etaTupled@18::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::AddT(int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .method public static class [runtime]System.Action`2 case20_nonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance void assembly/C::AddC(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case4_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case4_etaCurried@15::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case4_etaCurried@15::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case34_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case34_etaTupled@18::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case34_etaTupled@18::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case21_virtual(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: dup + IL_0002: ldvirtftn instance void assembly/C::V(int32, + int32) + IL_0008: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000d: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..a9c6bfae607 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,295 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance void AddC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + .method public hidebysig instance void AddT(int32 x, int32 y) cil managed + { + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + .method public hidebysig virtual instance void V(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/C::k + IL_0006: stloc.0 + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case20_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case20_nonEta@12::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case20_nonEta@12::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::AddC(int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case4_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case4_etaCurried@15::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case4_etaCurried@15::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::AddC(int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case34_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case34_etaTupled@18::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case34_etaTupled@18::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance void assembly/C::AddT(int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case21_virtual@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case21_virtual@21::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case21_virtual@21::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: tail. + IL_000a: callvirt instance void assembly/C::V(int32, + int32) + IL_000f: ret + } + + } + + .method public static class [runtime]System.Action`2 case20_nonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case20_nonEta@12::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case20_nonEta@12::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case4_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case4_etaCurried@15::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case4_etaCurried@15::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case34_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case34_etaTupled@18::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case34_etaTupled@18::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 case21_virtual(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case21_virtual@21::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case21_virtual@21::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..0395005c4a6 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,190 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance void AddC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void AddT(int32 x, int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig virtual instance void V(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case20_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case4_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case34_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case20_nonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case20_nonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case4_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case4_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case34_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case34_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case21_virtual(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: dup + IL_0002: ldvirtftn instance void assembly/C::V(int32, + int32) + IL_0008: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000d: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..b3569cf1a24 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateInstanceMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,223 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance void AddC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig instance void AddT(int32 x, int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public hidebysig virtual instance void V(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case20_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case4_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case34_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname case21_virtual@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/case21_virtual@21::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/case21_virtual@21::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: tail. + IL_000a: callvirt instance void assembly/C::V(int32, + int32) + IL_000f: ret + } + + } + + .method public static class [runtime]System.Action`2 case20_nonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case20_nonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case4_etaCurried(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case4_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case34_etaTupled(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case34_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case21_virtual(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/case21_virtual@21::.ctor(class assembly/C) + IL_0006: ldftn instance void assembly/case21_virtual@21::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs new file mode 100644 index 00000000000..8e550999ddf --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs @@ -0,0 +1,20 @@ +module DelegateKnownFunction + +open System + +// known F# functions compiled as methods +let handlerCurried (x: int) (y: int) : unit = () +let handlerTupled (x: int, y: int) : unit = () +let handler3 (x: int) (y: int) (z: int) : unit = () + +// 17. non-eta module function +let case17_nonEta () = Action(handlerCurried) + +// 1. eta module function (curried application) +let case1_etaCurried () = Action(fun a b -> handlerCurried a b) + +// 31. eta module function, tupled application (same compiled representation) +let case31_etaTupled () = Action(fun a b -> handlerTupled (a, b)) + +// 37. partial application of module function (constant arg) +let case37_partial () = Action(handler3 1) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..dcd46c650c9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,190 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case1_etaCurried@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::handlerCurried(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case31_etaTupled@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::handlerTupled(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case37_partial@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call void assembly::handler3(int32, + int32, + int32) + IL_0008: nop + IL_0009: ret + } + + } + + .method public static void handlerCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void handlerTupled(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 case17_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly::handlerCurried(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case1_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case1_etaCurried@14::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case31_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case31_etaTupled@17::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case37_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case37_partial@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..4d080c7c4a9 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOff.il.bsl @@ -0,0 +1,209 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case17_nonEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::handlerCurried(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case1_etaCurried@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::handlerCurried(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case31_etaTupled@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::handlerTupled(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case37_partial@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call void assembly::handler3(int32, + int32, + int32) + IL_0008: nop + IL_0009: ret + } + + } + + .method public static void handlerCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void handlerTupled(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 case17_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case17_nonEta@11::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case1_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case1_etaCurried@14::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case31_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case31_etaTupled@17::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case37_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case37_partial@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..c737dc4e5dd --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,187 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case17_nonEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case1_etaCurried@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case31_etaTupled@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case37_partial@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void handlerCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void handlerTupled(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 case17_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case17_nonEta@11::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case1_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case1_etaCurried@14::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case31_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case31_etaTupled@17::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case37_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case37_partial@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..2ac94696387 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateKnownFunction.fs.OptimizeOn.il.bsl @@ -0,0 +1,187 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case17_nonEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case1_etaCurried@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case31_etaTupled@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case37_partial@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void handlerCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void handlerTupled(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 case17_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case17_nonEta@11::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case1_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case1_etaCurried@14::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case31_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case31_etaTupled@17::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case37_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case37_partial@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs new file mode 100644 index 00000000000..4f1c2e34a96 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs @@ -0,0 +1,25 @@ +module DelegateNegativeCases + +open System + +// 42. first-class function value: there is no target method to point at, so a closure must remain +let firstClass (handler: int -> int -> unit) = Action(handler) + +// 43. lambda body is not a single direct forwarding call to a known target (the argument is computed, +// not the delegate parameters forwarded as-is): a closure must remain +let private sink (x: int) : unit = () +let notDirect (k: int) = Action(fun a b -> sink (a + b + k)) + +// 44. arguments reordered: not a transparent forwarding, so a closure must remain +let reordered (handler: int -> int -> unit) = Action(fun a b -> handler b a) + +type Holder() = + [] + member _.TakesObj (x: obj) : int = 1 + +// 45. Reference-parameter contravariance: the delegate's Invoke is (string):int and the target is (object):int. +// The CLR would accept this binding directly (a delegate may bind a method whose parameter is a supertype), +// but it stays a closure: F# elaborates the 'string -> obj' argument upcast as a coercion, so the forwarded +// argument is no longer a verbatim Invoke parameter and the direct-delegate recognizer does not match. (The +// signature check is not involved - it never even runs here.) +let contra (h: Holder) = System.Func(fun s -> h.TakesObj s) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..ca393fa812c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,271 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 TakesObj(object x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname firstClass@6 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname notDirect@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/notDirect@11::k + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/notDirect@11::k + IL_0009: add + IL_000a: call void assembly::sink(int32) + IL_000f: nop + IL_0010: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname reordered@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0006: ldarg.2 + IL_0007: ldarg.1 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname contra@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/contra@25::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/contra@25::h + IL_0006: ldarg.1 + IL_0007: callvirt instance int32 assembly/Holder::TakesObj(object) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Action`2 firstClass(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/firstClass@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/firstClass@6::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method private static void sink(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 notDirect(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/notDirect@11::.ctor(int32) + IL_0006: ldftn instance void assembly/notDirect@11::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 reordered(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/reordered@14::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/reordered@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`2 contra(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/contra@25::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/contra@25::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..8498432adc8 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOff.il.bsl @@ -0,0 +1,271 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 TakesObj(object x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname firstClass@6 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname notDirect@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/notDirect@11::k + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/notDirect@11::k + IL_0009: add + IL_000a: call void assembly::sink(int32) + IL_000f: nop + IL_0010: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname reordered@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0006: ldarg.2 + IL_0007: ldarg.1 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname contra@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/contra@25::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/contra@25::h + IL_0006: ldarg.1 + IL_0007: callvirt instance int32 assembly/Holder::TakesObj(object) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Action`2 firstClass(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/firstClass@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/firstClass@6::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method private static void sink(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 notDirect(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/notDirect@11::.ctor(int32) + IL_0006: ldftn instance void assembly/notDirect@11::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 reordered(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/reordered@14::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/reordered@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`2 contra(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/contra@25::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/contra@25::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..00a429b94a5 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,250 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 TakesObj(object x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname firstClass@6 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname notDirect@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname reordered@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0006: ldarg.2 + IL_0007: ldarg.1 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname contra@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/contra@25::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/contra@25::h + IL_0006: ldarg.1 + IL_0007: callvirt instance int32 assembly/Holder::TakesObj(object) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Action`2 firstClass(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/firstClass@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/firstClass@6::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method private static void sink(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 notDirect(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/notDirect@11::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 reordered(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/reordered@14::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/reordered@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`2 contra(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/contra@25::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/contra@25::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..25621c1ba07 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNegativeCases.fs.OptimizeOn.il.bsl @@ -0,0 +1,250 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public Holder + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public specialname rtspecialname instance void .ctor() cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ret + } + + .method public hidebysig instance int32 TakesObj(object x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname firstClass@6 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/firstClass@6::'handler' + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname notDirect@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname reordered@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler' + .method public specialname rtspecialname instance void .ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> assembly/reordered@14::'handler' + IL_0006: ldarg.2 + IL_0007: ldarg.1 + IL_0008: call !!0 class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2::InvokeFast(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>, + !0, + !1) + IL_000d: pop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname contra@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/Holder h + .method public specialname rtspecialname instance void .ctor(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/Holder assembly/contra@25::h + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(string s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/Holder assembly/contra@25::h + IL_0006: ldarg.1 + IL_0007: callvirt instance int32 assembly/Holder::TakesObj(object) + IL_000c: ret + } + + } + + .method public static class [runtime]System.Action`2 firstClass(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/firstClass@6::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/firstClass@6::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method private static void sink(int32 x) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 notDirect(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/notDirect@11::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 reordered(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2> 'handler') cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/reordered@14::.ctor(class [FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2>) + IL_0006: ldftn instance void assembly/reordered@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`2 contra(class assembly/Holder h) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/contra@25::.ctor(class assembly/Holder) + IL_0006: ldftn instance int32 assembly/contra@25::Invoke(string) + IL_000c: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs new file mode 100644 index 00000000000..0cdba8a007a --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs @@ -0,0 +1,47 @@ +module DelegateNonInlinable + +open System + +[] +let accCurried (x: int) (y: int) : int = x + y + +[] +let accTupled (x: int, y: int) : int = x + y + +// 22. non-eta module function, non-inlinable +let niNonEta () = Func(accCurried) + +// 6. eta module function, non-inlinable (curried application) +let niEtaCurried () = Func(fun a b -> accCurried a b) + +// 36. eta module function, non-inlinable, tupled application +let niEtaTupled () = Func(fun a b -> accTupled (a, b)) + +type S = + [] + static member AccS (x: int) (y: int) : int = x + y + +// 23. non-eta static method, non-inlinable +let niStaticNonEta () = Func(S.AccS) + +// 7. eta static method, non-inlinable +let niStaticEta () = Func(fun a b -> S.AccS a b) + +type C(k: int) = + [] + member _.AccC (x: int) (y: int) : int = x + y + k + + [] + member _.GPick<'T> (x: 'T) (y: 'T) : 'T = x + +// 24. non-eta instance method, non-inlinable +let niInstanceNonEta (o: C) = Func(o.AccC) + +// 8. eta instance method, non-inlinable +let niInstanceEta (o: C) = Func(fun a b -> o.AccC a b) + +// 25. non-eta generic instance method, non-inlinable +let niGenericInstanceNonEta (o: C) = Func(o.GPick) + +// 9. eta generic instance method, non-inlinable +let niGenericInstanceEta (o: C) = Func(fun a b -> o.GPick a b) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..15f41614e90 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,374 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public S + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 AccS(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance int32 AccC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/C::k + IL_0009: add + IL_000a: ret + } + + .method public hidebysig instance !!T GPick(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accCurried(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accTupled(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niStaticEta@28 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly/S::AccS(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niInstanceEta@41 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niInstanceEta@41::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niInstanceEta@41::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: tail. + IL_000a: callvirt instance int32 assembly/C::AccC(int32, + int32) + IL_000f: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niGenericInstanceEta@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance !!0 assembly/C::GPick(!!0, + !!0) + IL_000d: ret + } + + } + + .method public static int32 accCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static int32 accTupled(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static class [runtime]System.Func`3 niNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::accCurried(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/S::AccS(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niStaticEta@28::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::AccC(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niInstanceEta@41::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niInstanceEta@41::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance !!0 assembly/C::GPick(!!0, + !!0) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niGenericInstanceEta@47::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niGenericInstanceEta@47::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..dea6f5753aa --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOff.il.bsl @@ -0,0 +1,477 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public S + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 AccS(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance int32 AccC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/C::k + IL_0009: add + IL_000a: ret + } + + .method public hidebysig instance !!T GPick(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niNonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accCurried(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accCurried(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accTupled(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niStaticNonEta@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly/S::AccS(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niStaticEta@28 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly/S::AccS(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niInstanceNonEta@38 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niInstanceNonEta@38::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niInstanceNonEta@38::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: tail. + IL_000a: callvirt instance int32 assembly/C::AccC(int32, + int32) + IL_000f: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niInstanceEta@41 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niInstanceEta@41::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niInstanceEta@41::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: tail. + IL_000a: callvirt instance int32 assembly/C::AccC(int32, + int32) + IL_000f: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niGenericInstanceNonEta@44 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niGenericInstanceNonEta@44::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niGenericInstanceNonEta@44::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance !!0 assembly/C::GPick(!!0, + !!0) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niGenericInstanceEta@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance !!0 assembly/C::GPick(!!0, + !!0) + IL_000d: ret + } + + } + + .method public static int32 accCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static int32 accTupled(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static class [runtime]System.Func`3 niNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niNonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niStaticNonEta@25::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niStaticEta@28::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niInstanceNonEta@38::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niInstanceNonEta@38::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niInstanceEta@41::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niInstanceEta@41::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niGenericInstanceNonEta@44::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niGenericInstanceNonEta@44::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niGenericInstanceEta@47::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niGenericInstanceEta@47::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..f2ac084ccbb --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,271 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public S + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 AccS(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance int32 AccC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/C::k + IL_0009: add + IL_000a: ret + } + + .method public hidebysig instance !!T GPick(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accTupled(int32, + int32) + IL_0007: ret + } + + } + + .method public static int32 accCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static int32 accTupled(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static class [runtime]System.Func`3 niNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::accCurried(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly::accCurried(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/S::AccS(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/S::AccS(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::AccC(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance int32 assembly/C::AccC(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance !!0 assembly/C::GPick(!!0, + !!0) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldftn instance !!0 assembly/C::GPick(!!0, + !!0) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..3f3f5dc01ed --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateNonInlinable.fs.OptimizeOn.il.bsl @@ -0,0 +1,475 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public S + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static int32 AccS(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + } + + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/C::k + IL_000f: ret + } + + .method public hidebysig instance int32 AccC(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ldarg.0 + IL_0004: ldfld int32 assembly/C::k + IL_0009: add + IL_000a: ret + } + + .method public hidebysig instance !!T GPick(!!T x, !!T y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niNonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accCurried(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accCurried(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niEtaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly::accTupled(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niStaticNonEta@25 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly/S::AccS(int32, + int32) + IL_0007: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname niStaticEta@28 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static int32 Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call int32 assembly/S::AccS(int32, + int32) + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niInstanceNonEta@38 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niInstanceNonEta@38::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niInstanceNonEta@38::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::AccC(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niInstanceEta@41 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niInstanceEta@41::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niInstanceEta@41::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance int32 assembly/C::AccC(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niGenericInstanceNonEta@44 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niGenericInstanceNonEta@44::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niGenericInstanceNonEta@44::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance !!0 assembly/C::GPick(!!0, + !!0) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname niGenericInstanceEta@47 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/C o + .method public specialname rtspecialname instance void .ctor(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/C assembly/niGenericInstanceEta@47::o + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: callvirt instance !!0 assembly/C::GPick(!!0, + !!0) + IL_000d: ret + } + + } + + .method public static int32 accCurried(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static int32 accTupled(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: add + IL_0003: ret + } + + .method public static class [runtime]System.Func`3 niNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niNonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niEtaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niEtaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niStaticNonEta@25::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niStaticEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn int32 assembly/niStaticEta@28::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`3 niInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niInstanceNonEta@38::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niInstanceNonEta@38::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niInstanceEta@41::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niInstanceEta@41::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceNonEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niGenericInstanceNonEta@44::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niGenericInstanceNonEta@44::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 niGenericInstanceEta(class assembly/C o) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/niGenericInstanceEta@47::.ctor(class assembly/C) + IL_0006: ldftn instance int32 assembly/niGenericInstanceEta@47::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs new file mode 100644 index 00000000000..2e1a9a13c4e --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs @@ -0,0 +1,26 @@ +module DelegatePartialApplication + +open System + +// Cases 37/38 (in DelegateKnownFunction.fs / DelegateStaticMethod.fs) capture a +// constant first argument, so their closure can stay static (the constant is re-materialised in Invoke +// with no instance field). Capturing a runtime VALUE instead forces the closure to carry an instance +// field, which exercises a distinct emit path. None of these can ever become a direct delegate (the +// target has more parameters than the delegate's Invoke), so a closure must remain. + +let handler3 (x: int) (y: int) (z: int) : unit = () + +type C = + static member Add3 (x: int) (y: int) (z: int) : unit = () + +type I(k: int) = + member _.Add3 (x: int) (y: int) (z: int) : unit = ignore k + +// 39. partial application of module function (captured var: instance-field capture of n) +let papKnownVar (n: int) = Action(handler3 n) + +// 40. partial application of static method (captured var) +let papStaticVar (n: int) = Action(C.Add3 n) + +// 41. partial application of instance method (captures both the receiver and n) +let papInstanceVar (o: I) (n: int) = Action(o.Add3 n) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..c4365038d12 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,270 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public I + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/I::k + IL_000f: ret + } + + .method public hidebysig instance void + Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/I::k + IL_0006: stloc.0 + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papKnownVar@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 n + .method public specialname rtspecialname instance void .ctor(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/papKnownVar@20::n + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/papKnownVar@20::n + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call void assembly::handler3(int32, + int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papStaticVar@23 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 n + .method public specialname rtspecialname instance void .ctor(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/papStaticVar@23::n + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/papStaticVar@23::n + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call void assembly/C::Add3(int32, + int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papInstanceVar@26 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/I o + .field public int32 n + .method public specialname rtspecialname instance void .ctor(class assembly/I o, int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/I assembly/papInstanceVar@26::o + IL_0007: ldarg.0 + IL_0008: ldarg.2 + IL_0009: stfld int32 assembly/papInstanceVar@26::n + IL_000e: ldarg.0 + IL_000f: call instance void [runtime]System.Object::.ctor() + IL_0014: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/I assembly/papInstanceVar@26::o + IL_0006: ldarg.0 + IL_0007: ldfld int32 assembly/papInstanceVar@26::n + IL_000c: ldarg.1 + IL_000d: ldarg.2 + IL_000e: callvirt instance void assembly/I::Add3(int32, + int32, + int32) + IL_0013: nop + IL_0014: ret + } + + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 papKnownVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/papKnownVar@20::.ctor(int32) + IL_0006: ldftn instance void assembly/papKnownVar@20::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 papStaticVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/papStaticVar@23::.ctor(int32) + IL_0006: ldftn instance void assembly/papStaticVar@23::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 papInstanceVar(class assembly/I o, int32 n) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: newobj instance void assembly/papInstanceVar@26::.ctor(class assembly/I, + int32) + IL_0007: ldftn instance void assembly/papInstanceVar@26::Invoke(int32, + int32) + IL_000d: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0012: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..c4365038d12 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOff.il.bsl @@ -0,0 +1,270 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public I + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/I::k + IL_000f: ret + } + + .method public hidebysig instance void + Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 3 + .locals init (int32 V_0) + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/I::k + IL_0006: stloc.0 + IL_0007: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papKnownVar@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 n + .method public specialname rtspecialname instance void .ctor(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/papKnownVar@20::n + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/papKnownVar@20::n + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call void assembly::handler3(int32, + int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papStaticVar@23 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public int32 n + .method public specialname rtspecialname instance void .ctor(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld int32 assembly/papStaticVar@23::n + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld int32 assembly/papStaticVar@23::n + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call void assembly/C::Add3(int32, + int32, + int32) + IL_000d: nop + IL_000e: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname papInstanceVar@26 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public class assembly/I o + .field public int32 n + .method public specialname rtspecialname instance void .ctor(class assembly/I o, int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld class assembly/I assembly/papInstanceVar@26::o + IL_0007: ldarg.0 + IL_0008: ldarg.2 + IL_0009: stfld int32 assembly/papInstanceVar@26::n + IL_000e: ldarg.0 + IL_000f: call instance void [runtime]System.Object::.ctor() + IL_0014: ret + } + + .method assembly hidebysig instance void Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldfld class assembly/I assembly/papInstanceVar@26::o + IL_0006: ldarg.0 + IL_0007: ldfld int32 assembly/papInstanceVar@26::n + IL_000c: ldarg.1 + IL_000d: ldarg.2 + IL_000e: callvirt instance void assembly/I::Add3(int32, + int32, + int32) + IL_0013: nop + IL_0014: ret + } + + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 papKnownVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/papKnownVar@20::.ctor(int32) + IL_0006: ldftn instance void assembly/papKnownVar@20::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 papStaticVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/papStaticVar@23::.ctor(int32) + IL_0006: ldftn instance void assembly/papStaticVar@23::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Action`2 papInstanceVar(class assembly/I o, int32 n) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: newobj instance void assembly/papInstanceVar@26::.ctor(class assembly/I, + int32) + IL_0007: ldftn instance void assembly/papInstanceVar@26::Invoke(int32, + int32) + IL_000d: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_0012: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..61c73994f65 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,195 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public I + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/I::k + IL_000f: ret + } + + .method public hidebysig instance void + Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papKnownVar@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papStaticVar@23 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papInstanceVar@26 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 papKnownVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papKnownVar@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 papStaticVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papStaticVar@23::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 papInstanceVar(class assembly/I o, int32 n) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papInstanceVar@26::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..61c73994f65 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegatePartialApplication.fs.OptimizeOn.il.bsl @@ -0,0 +1,195 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class auto ansi serializable nested public I + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .field assembly int32 k + .method public specialname rtspecialname instance void .ctor(int32 k) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: callvirt instance void [runtime]System.Object::.ctor() + IL_0006: ldarg.0 + IL_0007: pop + IL_0008: ldarg.0 + IL_0009: ldarg.1 + IL_000a: stfld int32 assembly/I::k + IL_000f: ret + } + + .method public hidebysig instance void + Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papKnownVar@20 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papStaticVar@23 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname papInstanceVar@26 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void handler3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 papKnownVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papKnownVar@20::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 papStaticVar(int32 n) cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papStaticVar@23::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 papInstanceVar(class assembly/I o, int32 n) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/papInstanceVar@26::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs new file mode 100644 index 00000000000..a78c9c97dac --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs @@ -0,0 +1,21 @@ +module DelegateStaticMethod + +open System + +type C = + static member AddC (x: int) (y: int) : unit = () + static member AddT (x: int, y: int) : unit = () + static member Add3 (x: int) (y: int) (z: int) : unit = () + +// 18. non-eta static method +// (a tupled member is seen as a single tuple-arg value and will not coerce non-eta; use the curried member) +let case18_nonEta () = Action(C.AddC) + +// 2. eta static method (curried application) +let case2_etaCurried () = Action(fun a b -> C.AddC a b) + +// 32. eta static method, tupled application +let case32_etaTupled () = Action(fun a b -> C.AddT(a, b)) + +// 38. partial application of static method (constant arg) +let case38_partial () = Action(C.Add3 1) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..2b90acb082f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,196 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void AddC(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void AddT(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case2_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly/C::AddC(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case32_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly/C::AddT(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case38_partial@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call void assembly/C::Add3(int32, + int32, + int32) + IL_0008: nop + IL_0009: ret + } + + } + + .method public static class [runtime]System.Action`2 case18_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/C::AddC(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case2_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case2_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case32_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case32_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case38_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case38_partial@21::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..ce68901f780 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOff.il.bsl @@ -0,0 +1,215 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void AddC(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void AddT(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case18_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly/C::AddC(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case2_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly/C::AddC(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case32_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly/C::AddT(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case38_partial@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ldarg.0 + IL_0002: ldarg.1 + IL_0003: call void assembly/C::Add3(int32, + int32, + int32) + IL_0008: nop + IL_0009: ret + } + + } + + .method public static class [runtime]System.Action`2 case18_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case18_nonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case2_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case2_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case32_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case32_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case38_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case38_partial@21::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..1de6bfcc577 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,193 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void AddC(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void AddT(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case18_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case2_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case32_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case38_partial@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case18_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case18_nonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case2_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case2_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case32_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case32_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case38_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case38_partial@21::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..1de6bfcc577 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStaticMethod.fs.OptimizeOn.il.bsl @@ -0,0 +1,193 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static void AddC(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static void AddT(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static void Add3(int32 x, + int32 y, + int32 z) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 03 00 00 00 01 00 00 00 01 00 00 00 01 00 + 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case18_nonEta@12 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case2_etaCurried@15 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case32_etaTupled@18 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname case38_partial@21 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 delegateArg0, + int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static class [runtime]System.Action`2 case18_nonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case18_nonEta@12::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case2_etaCurried() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case2_etaCurried@15::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case32_etaTupled() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case32_etaTupled@18::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 case38_partial() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/case38_partial@21::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs new file mode 100644 index 00000000000..c856d1f5c7b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs @@ -0,0 +1,17 @@ +module DelegateStructTarget + +open System + +[] +type S = + [] + member _.Add (x: int) (y: int) : int = x + y + +// The target is an instance method on a value type. A delegate's Target is an object, so a direct delegate +// would have to box the receiver; until that is implemented a closure is kept. (See DelegateInstanceMethod +// for the reference-type case, which is emitted directly.) +// 48. non-eta struct (value-type) receiver +let structInstanceNonEta (s: S) = Func(s.Add) + +// 49. eta struct (value-type) receiver +let structInstanceEta (s: S) = Func(fun a b -> s.Add a b) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..291dc96be7c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,317 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class sequential ansi serializable sealed nested public S + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .pack 0 + .size 1 + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig virtual final instance int32 CompareTo(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.0 + IL_0004: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: unbox.any assembly/S + IL_0007: call instance int32 assembly/S::CompareTo(valuetype assembly/S) + IL_000c: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0, + valuetype assembly/S& V_1) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: stloc.1 + IL_000a: ldc.i4.0 + IL_000b: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 assembly/S::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig instance bool Equals(valuetype assembly/S obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (object V_0, + valuetype assembly/S V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst assembly/S + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001d + + IL_000d: ldarg.1 + IL_000e: unbox.any assembly/S + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: ldarg.2 + IL_0017: call instance bool assembly/S::Equals(valuetype assembly/S, + class [runtime]System.Collections.IEqualityComparer) + IL_001c: ret + + IL_001d: ldc.i4.0 + IL_001e: ret + } + + .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 4 + .locals init (object V_0, + valuetype assembly/S V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst assembly/S + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001c + + IL_000d: ldarg.1 + IL_000e: unbox.any assembly/S + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: call instance bool assembly/S::Equals(valuetype assembly/S) + IL_001b: ret + + IL_001c: ldc.i4.0 + IL_001d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceNonEta@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 7 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: call instance int32 assembly/S::Add(int32, + int32) + IL_0010: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceEta@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 7 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: call instance int32 assembly/S::Add(int32, + int32) + IL_0010: ret + } + + } + + .method public static class [runtime]System.Func`3 structInstanceNonEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceNonEta@14::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceNonEta@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 structInstanceEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceEta@17::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceEta@17::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..291dc96be7c --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOff.il.bsl @@ -0,0 +1,317 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class sequential ansi serializable sealed nested public S + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .pack 0 + .size 1 + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig virtual final instance int32 CompareTo(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.0 + IL_0004: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: unbox.any assembly/S + IL_0007: call instance int32 assembly/S::CompareTo(valuetype assembly/S) + IL_000c: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0, + valuetype assembly/S& V_1) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: stloc.1 + IL_000a: ldc.i4.0 + IL_000b: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 assembly/S::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig instance bool Equals(valuetype assembly/S obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 5 + .locals init (object V_0, + valuetype assembly/S V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst assembly/S + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001d + + IL_000d: ldarg.1 + IL_000e: unbox.any assembly/S + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: ldarg.2 + IL_0017: call instance bool assembly/S::Equals(valuetype assembly/S, + class [runtime]System.Collections.IEqualityComparer) + IL_001c: ret + + IL_001d: ldc.i4.0 + IL_001e: ret + } + + .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S& V_0) + IL_0000: ldarga.s obj + IL_0002: stloc.0 + IL_0003: ldc.i4.1 + IL_0004: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 4 + .locals init (object V_0, + valuetype assembly/S V_1) + IL_0000: ldarg.1 + IL_0001: stloc.0 + IL_0002: ldloc.0 + IL_0003: isinst assembly/S + IL_0008: ldnull + IL_0009: cgt.un + IL_000b: brfalse.s IL_001c + + IL_000d: ldarg.1 + IL_000e: unbox.any assembly/S + IL_0013: stloc.1 + IL_0014: ldarg.0 + IL_0015: ldloc.1 + IL_0016: call instance bool assembly/S::Equals(valuetype assembly/S) + IL_001b: ret + + IL_001c: ldc.i4.0 + IL_001d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceNonEta@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 7 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: call instance int32 assembly/S::Add(int32, + int32) + IL_0010: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceEta@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 7 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.0 + IL_0001: ldfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0006: stloc.0 + IL_0007: ldloca.s V_0 + IL_0009: ldarg.1 + IL_000a: ldarg.2 + IL_000b: call instance int32 assembly/S::Add(int32, + int32) + IL_0010: ret + } + + } + + .method public static class [runtime]System.Func`3 structInstanceNonEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceNonEta@14::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceNonEta@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 structInstanceEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceEta@17::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceEta@17::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..f83c608dc89 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,284 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class sequential ansi serializable sealed nested public S + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .pack 0 + .size 1 + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig virtual final instance int32 CompareTo(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 assembly/S::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig instance bool Equals(valuetype assembly/S obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: isinst assembly/S + IL_0006: brfalse.s IL_0011 + + IL_0008: ldarg.1 + IL_0009: unbox.any assembly/S + IL_000e: stloc.0 + IL_000f: ldc.i4.1 + IL_0010: ret + + IL_0011: ldc.i4.0 + IL_0012: ret + } + + .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: isinst assembly/S + IL_0006: brfalse.s IL_0011 + + IL_0008: ldarg.1 + IL_0009: unbox.any assembly/S + IL_000e: stloc.0 + IL_000f: ldc.i4.1 + IL_0010: ret + + IL_0011: ldc.i4.0 + IL_0012: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceNonEta@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call instance int32 assembly/S::Add(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceEta@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype assembly/S assembly/structInstanceEta@17::s + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call instance int32 assembly/S::Add(int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 structInstanceNonEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceNonEta@14::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceNonEta@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 structInstanceEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceEta@17::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceEta@17::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..f83c608dc89 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateStructTarget.fs.OptimizeOn.il.bsl @@ -0,0 +1,284 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class sequential ansi serializable sealed nested public S + extends [runtime]System.ValueType + implements class [runtime]System.IEquatable`1, + [runtime]System.Collections.IStructuralEquatable, + class [runtime]System.IComparable`1, + [runtime]System.IComparable, + [runtime]System.Collections.IStructuralComparable + { + .pack 0 + .size 1 + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.StructAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public hidebysig virtual final instance int32 CompareTo(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: ret + } + + .method public hidebysig virtual final instance int32 CompareTo(object obj, class [runtime]System.Collections.IComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: unbox.any assembly/S + IL_0006: stloc.0 + IL_0007: ldc.i4.0 + IL_0008: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode(class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.0 + IL_0001: ret + } + + .method public hidebysig virtual final instance int32 GetHashCode() cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call class [runtime]System.Collections.IEqualityComparer [FSharp.Core]Microsoft.FSharp.Core.LanguagePrimitives::get_GenericEqualityComparer() + IL_0006: call instance int32 assembly/S::GetHashCode(class [runtime]System.Collections.IEqualityComparer) + IL_000b: ret + } + + .method public hidebysig instance bool Equals(valuetype assembly/S obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj, class [runtime]System.Collections.IEqualityComparer comp) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: isinst assembly/S + IL_0006: brfalse.s IL_0011 + + IL_0008: ldarg.1 + IL_0009: unbox.any assembly/S + IL_000e: stloc.0 + IL_000f: ldc.i4.1 + IL_0010: ret + + IL_0011: ldc.i4.0 + IL_0012: ret + } + + .method public hidebysig instance int32 Add(int32 x, int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.1 + IL_0001: ldarg.2 + IL_0002: add + IL_0003: ret + } + + .method public hidebysig virtual final instance bool Equals(valuetype assembly/S obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldc.i4.1 + IL_0001: ret + } + + .method public hidebysig virtual final instance bool Equals(object obj) cil managed + { + .custom instance void [runtime]System.Runtime.CompilerServices.CompilerGeneratedAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 3 + .locals init (valuetype assembly/S V_0) + IL_0000: ldarg.1 + IL_0001: isinst assembly/S + IL_0006: brfalse.s IL_0011 + + IL_0008: ldarg.1 + IL_0009: unbox.any assembly/S + IL_000e: stloc.0 + IL_000f: ldc.i4.1 + IL_0010: ret + + IL_0011: ldc.i4.0 + IL_0012: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceNonEta@14 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 delegateArg0, int32 delegateArg1) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype assembly/S assembly/structInstanceNonEta@14::s + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call instance int32 assembly/S::Add(int32, + int32) + IL_000d: ret + } + + } + + .class auto autochar serializable sealed nested assembly beforefieldinit specialname structInstanceEta@17 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .field public valuetype assembly/S s + .method public specialname rtspecialname instance void .ctor(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: stfld valuetype assembly/S assembly/structInstanceEta@17::s + IL_0007: ldarg.0 + IL_0008: call instance void [runtime]System.Object::.ctor() + IL_000d: ret + } + + .method assembly hidebysig instance int32 Invoke(int32 a, int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldflda valuetype assembly/S assembly/structInstanceEta@17::s + IL_0006: ldarg.1 + IL_0007: ldarg.2 + IL_0008: call instance int32 assembly/S::Add(int32, + int32) + IL_000d: ret + } + + } + + .method public static class [runtime]System.Func`3 structInstanceNonEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceNonEta@14::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceNonEta@14::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + + .method public static class [runtime]System.Func`3 structInstanceEta(valuetype assembly/S s) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: newobj instance void assembly/structInstanceEta@17::.ctor(valuetype assembly/S) + IL_0006: ldftn instance int32 assembly/structInstanceEta@17::Invoke(int32, + int32) + IL_000c: newobj instance void class [runtime]System.Func`3::.ctor(object, + native int) + IL_0011: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs new file mode 100644 index 00000000000..7a164ad4045 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs @@ -0,0 +1,11 @@ +module DelegateUnitArg + +open System + +let handler () : unit = () + +// 46. non-eta unit-argument delegate +let caseUnitNonEta () = Action(handler) + +// 47. eta unit-argument delegate +let caseUnitEta () = Action(fun () -> handler ()) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..b91d58c4597 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,114 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitNonEta@8 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: call void assembly::'handler'() + IL_0005: nop + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: call void assembly::'handler'() + IL_0005: nop + IL_0006: ret + } + + } + + .method public static void 'handler'() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action caseUnitNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitNonEta@8::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action caseUnitEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitEta@11::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..b91d58c4597 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOff.il.bsl @@ -0,0 +1,114 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitNonEta@8 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: call void assembly::'handler'() + IL_0005: nop + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: call void assembly::'handler'() + IL_0005: nop + IL_0006: ret + } + + } + + .method public static void 'handler'() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action caseUnitNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitNonEta@8::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action caseUnitEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitEta@11::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..3684e4e4a6b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,110 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitNonEta@8 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void 'handler'() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action caseUnitNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitNonEta@8::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action caseUnitEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitEta@11::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..3684e4e4a6b --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitArg.fs.OptimizeOn.il.bsl @@ -0,0 +1,110 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitNonEta@8 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname caseUnitEta@11 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + } + + .method public static void 'handler'() cil managed + { + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action caseUnitNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitNonEta@8::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action caseUnitEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/caseUnitEta@11::Invoke() + IL_0007: newobj instance void [runtime]System.Action::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs new file mode 100644 index 00000000000..eca9f6e4b1f --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs @@ -0,0 +1,27 @@ +module DelegateUnitReturn + +open System + +// Target returns unit, compiled to void; delegate (Action) returns void. +[] +let returnsUnit (x: int) (y: int) : unit = () + +// 26. non-eta unit-returning member (compiled to void) +let voidNonEta () = Action(returnsUnit) + +// 10. eta unit-returning member +let voidEta () = Action(fun a b -> returnsUnit a b) + +type C = + // Generic method returning its own type variable; instantiated to unit below. The compiled method + // returns the type variable (System.Unit once instantiated), not void - a distinct case from the + // void-returning member above. + [] + static member Echo<'T>(x: 'T) : 'T = x + +// Generic return type variable instantiated to unit; the delegate likewise returns unit. +// 27. non-eta generic return tyvar instantiated to unit (compiled return is Unit, not void) +let unitGenericReturnNonEta () = Func(C.Echo) + +// 11. eta generic unit-returning method +let unitGenericReturnEta () = Func(fun (x: unit) -> C.Echo x) diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.Preview.il.bsl new file mode 100644 index 00000000000..97b1e27f918 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.Preview.il.bsl @@ -0,0 +1,160 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static !!T Echo(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname voidEta@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::returnsUnit(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname unitGenericReturnEta@27 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static class [FSharp.Core]Microsoft.FSharp.Core.Unit Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly/C::Echo(!!0) + IL_0006: ret + } + + } + + .method public static void returnsUnit(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 voidNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly::returnsUnit(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 voidEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/voidEta@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly/C::Echo(!!0) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [FSharp.Core]Microsoft.FSharp.Core.Unit assembly/unitGenericReturnEta@27::Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.il.bsl new file mode 100644 index 00000000000..72f76894471 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOff.il.bsl @@ -0,0 +1,194 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static !!T Echo(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname voidNonEta@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::returnsUnit(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname voidEta@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::returnsUnit(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname unitGenericReturnNonEta@24 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static class [FSharp.Core]Microsoft.FSharp.Core.Unit Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly/C::Echo(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname unitGenericReturnEta@27 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static class [FSharp.Core]Microsoft.FSharp.Core.Unit Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly/C::Echo(!!0) + IL_0006: ret + } + + } + + .method public static void returnsUnit(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 voidNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/voidNonEta@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 voidEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/voidEta@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [FSharp.Core]Microsoft.FSharp.Core.Unit assembly/unitGenericReturnNonEta@24::Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [FSharp.Core]Microsoft.FSharp.Core.Unit assembly/unitGenericReturnEta@27::Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.Preview.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.Preview.il.bsl new file mode 100644 index 00000000000..2f7c62741e0 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.Preview.il.bsl @@ -0,0 +1,126 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static !!T Echo(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + } + + .method public static void returnsUnit(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 voidNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly::returnsUnit(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 voidEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly::returnsUnit(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly/C::Echo(!!0) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn !!0 assembly/C::Echo(!!0) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.il.bsl b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.il.bsl new file mode 100644 index 00000000000..72f76894471 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DelegateUnitReturn.fs.OptimizeOn.il.bsl @@ -0,0 +1,194 @@ + + + + + +.assembly extern runtime { } +.assembly extern FSharp.Core { } +.assembly assembly +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute::.ctor(int32, + int32, + int32) = ( 01 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 ) + + + + + .hash algorithm 0x00008004 + .ver 0:0:0:0 +} +.module assembly.exe + +.imagebase {value} +.file alignment 0x00000200 +.stackreserve 0x00100000 +.subsystem 0x0003 +.corflags 0x00000001 + + + + + +.class public abstract auto ansi sealed assembly + extends [runtime]System.Object +{ + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 07 00 00 00 00 00 ) + .class auto ansi serializable nested public C + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 03 00 00 00 00 00 ) + .method public static !!T Echo(!!T x) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname voidNonEta@10 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 x, + int32 y) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::returnsUnit(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname voidEta@13 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static void Invoke(int32 a, + int32 b) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: ldarg.1 + IL_0002: call void assembly::returnsUnit(int32, + int32) + IL_0007: nop + IL_0008: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname unitGenericReturnNonEta@24 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static class [FSharp.Core]Microsoft.FSharp.Core.Unit Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly/C::Echo(!!0) + IL_0006: ret + } + + } + + .class abstract auto autochar serializable sealed nested assembly beforefieldinit specialname unitGenericReturnEta@27 + extends [runtime]System.Object + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationMappingAttribute::.ctor(valuetype [FSharp.Core]Microsoft.FSharp.Core.SourceConstructFlags) = ( 01 00 06 00 00 00 00 00 ) + .method assembly static class [FSharp.Core]Microsoft.FSharp.Core.Unit Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit x) cil managed + { + + .maxstack 8 + IL_0000: ldarg.0 + IL_0001: call !!0 assembly/C::Echo(!!0) + IL_0006: ret + } + + } + + .method public static void returnsUnit(int32 x, + int32 y) cil managed + { + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.NoCompilerInliningAttribute::.ctor() = ( 01 00 00 00 ) + .custom instance void [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::.ctor(int32[]) = ( 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) + + .maxstack 8 + IL_0000: ret + } + + .method public static class [runtime]System.Action`2 voidNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/voidNonEta@10::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Action`2 voidEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn void assembly/voidEta@13::Invoke(int32, + int32) + IL_0007: newobj instance void class [runtime]System.Action`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnNonEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [FSharp.Core]Microsoft.FSharp.Core.Unit assembly/unitGenericReturnNonEta@24::Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + + .method public static class [runtime]System.Func`2 unitGenericReturnEta() cil managed + { + + .maxstack 8 + IL_0000: ldnull + IL_0001: ldftn class [FSharp.Core]Microsoft.FSharp.Core.Unit assembly/unitGenericReturnEta@27::Invoke(class [FSharp.Core]Microsoft.FSharp.Core.Unit) + IL_0007: newobj instance void class [runtime]System.Func`2::.ctor(object, + native int) + IL_000c: ret + } + +} + +.class private abstract auto ansi sealed ''.$assembly + extends [runtime]System.Object +{ + .method public static void main@() cil managed + { + .entrypoint + + .maxstack 8 + IL_0000: ret + } + +} + + + + + + diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DirectDelegates.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DirectDelegates.fs new file mode 100644 index 00000000000..d23f9038694 --- /dev/null +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/DirectDelegates/DirectDelegates.fs @@ -0,0 +1,569 @@ +module EmittedIL.RealInternalSignature.DirectDelegates + +open System.IO +open Xunit +open FSharp.Test +open FSharp.Test.Compiler + +let private coreOptions compilation = + compilation + |> withOptions [ "--test:EmitFeeFeeAs100001" ] + |> asExe + |> withEmbeddedPdb + |> withEmbedAllSource + |> ignoreWarnings + +let verifyCompilation compilation = + compilation + |> coreOptions + |> compile + |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> verifyILBaseline + +// Redirect the IL baseline to a distinct *.Preview.il.bsl path so the preview variant can reuse the +// very same input .fs file (no input duplication / drift) without clobbering the default baseline. +let private withPreviewBaseline (cUnit: CompilationUnit) : CompilationUnit = + match cUnit with + | FS src -> + let baseline = + src.Baseline + |> Option.map (fun bsl -> + let path = bsl.ILBaseline.BslSource.Replace(".il.bsl", ".Preview.il.bsl") + let content = if File.Exists path then Some(File.ReadAllText path) else None + { bsl with ILBaseline = { bsl.ILBaseline with BslSource = path; Content = content } }) + FS { src with Baseline = baseline } + | other -> other + +let verifyPreviewCompilation compilation = + compilation + |> coreOptions + |> withLangVersionPreview + |> withPreviewBaseline + |> compile + |> shouldSucceed + |> verifyPEFileWithSystemDlls + |> verifyILBaseline + +[] +let ``DelegateKnownFunction_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateKnownFunction_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateStaticMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateStaticMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateGenericStaticMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateGenericStaticMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateInstanceMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateInstanceMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateGenericInstanceMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateGenericInstanceMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateUnitArg_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateUnitArg_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateNegativeCases_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateNegativeCases_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateNonInlinable_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateNonInlinable_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegatePartialApplication_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegatePartialApplication_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateUnitReturn_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateUnitReturn_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateStructTarget_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateStructTarget_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateExtensionMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateExtensionMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateILMethod_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateILMethod_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``DelegateCustomType_fs`` compilation = + compilation |> getCompilation |> verifyCompilation + +[] +let ``DelegateCustomType_fs preview`` compilation = + compilation |> getCompilation |> verifyPreviewCompilation + +[] +let ``Direct delegates target the real method and dispatch correctly (preview)`` () = + FSharp """ +module DirectDelegateExecution + +open System + +[] +let add (x: int) (y: int) : int = x + y + +type G<'U> = + [] + static member Pick<'T>(x: 'T) (y: 'T) : 'T = x + +[] +type Base() = + abstract M: int -> int + +type Derived() = + inherit Base() + override _.M x = x + 100 + +[] +let main _ = + // Non-eta known function: the delegate points directly at 'add'. + let d = Func(add) + if d.Invoke(2, 3) <> 5 then failwith "add: wrong result" + if d.Method.Name <> "add" then failwithf "add: expected Method.Name 'add' but got '%s'" d.Method.Name + + // Non-eta generic method on a generic type: the delegate points directly at the fully instantiated method. + let gd = Func(G.Pick) + if gd.Invoke(7, 9) <> 7 then failwithf "generic: expected 7 but got %d" (gd.Invoke(7, 9)) + if gd.Method.Name <> "Pick" then failwithf "generic: expected Method.Name 'Pick' but got '%s'" gd.Method.Name + + // Non-eta virtual instance method: dup; ldvirtftn must preserve override dispatch. + let b: Base = Derived() + let vd = Func(b.M) + if vd.Invoke 1 <> 101 then failwithf "virtual: expected 101 but got %d" (vd.Invoke 1) + if vd.Method.Name <> "M" then failwithf "virtual: expected Method.Name 'M' but got '%s'" vd.Method.Name + if not (obj.ReferenceEquals(vd.Target, b)) then failwith "virtual: Target is not the receiver" + + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +[] +let ``Without the feature the delegate goes through a closure (default langversion)`` () = + FSharp """ +module ClosureDelegateExecution + +open System + +[] +let add (x: int) (y: int) : int = x + y + +[] +let main _ = + let d = Func(add) + if d.Invoke(2, 3) <> 5 then failwith "add: wrong result" + // Without the feature the delegate is built over a generated closure method named 'Invoke'. + if d.Method.Name <> "Invoke" then failwithf "expected closure Method.Name 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> compileExeAndRun + |> shouldSucceed + +// IL (BCL) method target: compiled as TOp.ILCall. With ILCall recognition the optimized eta-expanded +// delegate points directly at the BCL method, so Method.Name is the real method ('Max'), not a closure +// 'Invoke'. Compiled with --optimize+ so the eta forwarding call survives to codegen. +[] +let ``IL method targets are emitted directly when optimized (preview)`` () = + FSharp """ +module IlMethodDelegate + +open System + +[] +let main _ = + let d = Func(fun a b -> Math.Max(a, b)) + if d.Invoke(3, 7) <> 7 then failwith "il: wrong result" + if d.Method.Name <> "Max" then failwithf "il: expected direct 'Max' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed + +// A closure built from an explicit eta-lambda re-evaluates the receiver on every Invoke; a direct +// delegate would evaluate it once at construction. When the receiver has an effect (here a counter- +// bumping call) that difference is observable, so the closure must be kept even under optimization. +[] +let ``Side-effecting receiver keeps the closure so it is re-evaluated per invoke (preview)`` () = + FSharp """ +module ReceiverEffectDelegate + +open System + +let mutable calls = 0 + +type Box(tag: int) = + member _.Read (_: int) : int = tag + +let getBox () = + calls <- calls + 1 + Box(calls) + +[] +let main _ = + // The receiver 'getBox()' has an effect, so it must run on each invocation, not once at construction. + let d = Func(fun a -> (getBox()).Read a) + let r1 = d.Invoke 0 + let r2 = d.Invoke 0 + if calls <> 2 then failwithf "receiver should be re-evaluated per invoke; calls=%d" calls + if r1 = r2 then failwithf "expected distinct boxes per invoke but got %d and %d" r1 r2 + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed + +// Instance IL method target: a BCL instance method bound directly. The delegate's Target must be the +// receiver and Method.Name the real method. +[] +let ``Instance IL method targets are emitted directly when optimized (preview)`` () = + FSharp """ +module IlInstanceMethodDelegate + +open System +open System.Text + +[] +let main _ = + let sb = StringBuilder() + // StringBuilder.Append(string) is an instance method on a reference type. + let d = Func(fun s -> sb.Append(s)) + d.Invoke "hello" |> ignore + if sb.ToString() <> "hello" then failwith "il-instance: wrong result" + if d.Method.Name <> "Append" then failwithf "il-instance: expected direct 'Append' but got '%s'" d.Method.Name + if not (obj.ReferenceEquals(d.Target, sb)) then failwith "il-instance: Target is not the receiver" + 0 + """ + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed + +// Custom, F#-declared delegate types (not just BCL Func/Action) point directly at the target method. +// Non-eta targets, so direct in both debug and release. Covers a static target (null Target) and an +// instance target (Target = receiver) through a user-defined delegate. +[] +let ``Custom F# delegate targets the real method and dispatch correctly (preview)`` () = + FSharp """ +module CustomDelegateExecution + +open System + +type DTupled = delegate of int * int -> int + +[] +let acc (x: int) (y: int) : int = x + y + +type C() = + [] + member _.M (x: int) (y: int) : int = x * y + +[] +let main _ = + let ds = DTupled(acc) + if ds.Invoke(2, 3) <> 5 then failwith "static: wrong result" + if ds.Method.Name <> "acc" then failwithf "static: expected 'acc' but got '%s'" ds.Method.Name + if not (isNull ds.Target) then failwith "static: Target should be null" + + let c = C() + let di = DTupled(c.M) + if di.Invoke(4, 5) <> 20 then failwith "instance: wrong result" + if di.Method.Name <> "M" then failwithf "instance: expected 'M' but got '%s'" di.Method.Name + if not (obj.ReferenceEquals(di.Target, c)) then failwith "instance: Target is not the receiver" + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Cases 31-36: a tupled application forwards a single tuple, not the Invoke parameters verbatim, so the +// shape is not recognized and a closure is kept even in release. +[] +let ``Tupled application stays a closure (preview)`` () = + FSharp """ +module TupledClosure + +open System + +[] +let accT (x: int, y: int) : int = x + y + +[] +let main _ = + let d = Func(fun a b -> accT (a, b)) + if d.Invoke(2, 3) <> 5 then failwith "wrong result" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed + +// Cases 37-41: a partial application leaves the target with more parameters than the delegate's Invoke, +// so there is no closed direct form and a closure is kept. +[] +let ``Partial application stays a closure (preview)`` () = + FSharp """ +module PartialClosure + +open System + +[] +let add3 (x: int) (y: int) (z: int) : int = x + y + z + +[] +let main _ = + let d = Func(add3 1) + if d.Invoke(2, 3) <> 6 then failwith "wrong result" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Cases 46-47: the synthesized unit argument is seen as a leading argument for a static target, so a +// unit-argument delegate stays a closure (and still runs). +[] +let ``Unit-argument delegate stays a closure (preview)`` () = + FSharp """ +module UnitArgClosure + +open System + +let mutable ran = false +let handler () : unit = ran <- true + +[] +let main _ = + let d = Action(handler) + d.Invoke() + if not ran then failwith "did not run" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Cases 48-49: a value-type receiver would need boxing (a delegate Target is object); not implemented, so +// it stays a closure and still dispatches correctly. +[] +let ``Struct value-type receiver stays a closure (preview)`` () = + FSharp """ +module StructClosure + +open System + +[] +type S = + member _.Add (x: int) (y: int) : int = x + y + +[] +let main _ = + let s = S() + let d = Func(s.Add) + if d.Invoke(2, 3) <> 5 then failwith "wrong result" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Case 50: an extension member compiles to a static method whose first parameter is the receiver, so it is +// bound as a leading argument (a partial application) and stays a closure. +[] +let ``Extension member stays a closure (preview)`` () = + FSharp """ +module ExtensionClosure + +open System +open System.Runtime.CompilerServices + +type Holder() = class end + +[] +type HolderExtensions = + [] + static member Combine (h: Holder, x: int, y: int) : int = x + y + +[] +let main _ = + let h = Holder() + let d = Func(fun a b -> h.Combine(a, b)) + if d.Invoke(2, 3) <> 5 then failwith "wrong result" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Case 51: a byref Invoke parameter with a mutating body is not a transparent forwarding call, so it stays +// a closure and mutates through the byref correctly. +[] +let ``Byref-parameter delegate stays a closure and mutates (preview)`` () = + FSharp """ +module ByrefClosure + +open System + +type D = delegate of byref -> unit + +[] +let main _ = + let d = D(fun x -> x <- x + 1) + let mutable v = 10 + d.Invoke(&v) + if v <> 11 then failwithf "expected 11 but got %d" v + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withLangVersionPreview + |> compileExeAndRun + |> shouldSucceed + +// Cross-assembly targets: the recognizer has no locality guard, so a delegate over an F# function imported +// from a *referenced* assembly takes the same FSharpVal direct path (StorageForValRef resolution + method-spec +// build across an assembly boundary) that the same-compiland baseline suite never reaches. The targets are +// [] so cross-assembly inlining cannot dissolve the forwarding call before codegen. +let private crossAssemblyLibrary = + FSharp """ +module DelegateLib + +[] +let add (x: int) (y: int) : int = x + y + +type Calc(k: int) = + [] + member _.Scale (x: int) (y: int) : int = (x + y) * k + +// A small inline function: its body is serialized into the referenced assembly and is always inlined at the +// use site (independent of --optimize), so a delegate over it can never see a forwarding call. +let inline addInline (x: int) (y: int) : int = x + y + """ + |> asLibrary + +[] +let ``Cross-assembly F# target is emitted directly (preview)`` () = + FSharp """ +module CrossAsmDirect + +open System +open DelegateLib + +[] +let main _ = + // Static module function imported from another assembly: direct, null Target, real Method.Name. + let ds = Func(add) + if ds.Invoke(2, 3) <> 5 then failwith "static: wrong result" + if ds.Method.Name <> "add" then failwithf "static: expected 'add' but got '%s'" ds.Method.Name + if not (isNull ds.Target) then failwith "static: Target should be null" + + // Instance member imported from another assembly: direct, Target is the receiver. + let c = Calc(10) + let di = Func(c.Scale) + if di.Invoke(2, 3) <> 50 then failwithf "instance: expected 50 but got %d" (di.Invoke(2, 3)) + if di.Method.Name <> "Scale" then failwithf "instance: expected 'Scale' but got '%s'" di.Method.Name + if not (obj.ReferenceEquals(di.Target, c)) then failwith "instance: Target is not the receiver" + 0 + """ + |> withReferences [ crossAssemblyLibrary ] + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed + +// An inline target from a referenced assembly is always inlined before the recognizer runs, so the forwarding +// call vanishes and a closure is kept even in release - the deterministic cross-assembly end of the inline-race. +[] +let ``Cross-assembly inline target stays a closure (preview)`` () = + FSharp """ +module CrossAsmInline + +open System +open DelegateLib + +[] +let main _ = + let d = Func(fun a b -> addInline a b) + if d.Invoke(2, 3) <> 5 then failwith "wrong result" + if d.Method.Name <> "Invoke" then failwithf "expected closure 'Invoke' but got '%s'" d.Method.Name + 0 + """ + |> withReferences [ crossAssemblyLibrary ] + |> withLangVersionPreview + |> withOptions [ "--optimize+" ] + |> compileExeAndRun + |> shouldSucceed diff --git a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj index 2f96624917e..dd3238cf913 100644 --- a/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj +++ b/tests/FSharp.Compiler.ComponentTests/FSharp.Compiler.ComponentTests.fsproj @@ -260,6 +260,7 @@ + diff --git a/tests/FSharp.Compiler.ComponentTests/Language/CodeQuotationTests.fs b/tests/FSharp.Compiler.ComponentTests/Language/CodeQuotationTests.fs index 29556381221..7085bd7a3a7 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/CodeQuotationTests.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/CodeQuotationTests.fs @@ -40,6 +40,42 @@ let z : unit = |> compileAndRun |> shouldSucceed + [] + let ``Delegate construction quotations are unaffected by the direct delegate optimization`` () = + Fsx """ +open System +open FSharp.Quotations.Patterns + +let handlerCurried (x: int) (y: int) : unit = () + +type C(k: int) = + member _.AddC (x: int) (y: int) : unit = ignore k + +let check (label: string) (target: string) (expr: Quotations.Expr) = + match expr with + | NewDelegate(dty, _, _) when dty = typeof> -> () + | e -> failwithf "%s: expected NewDelegate of Action, got %A" label e + if not ((string expr).Contains target) then + failwithf "%s: expected the quotation to reference target '%s', got %A" label target expr + +let o = C(1) + +// non-eta-expanded known function +check "nonEta" "handlerCurried" <@ Action(handlerCurried) @> +// eta-expanded known function +check "etaCurried" "handlerCurried" <@ Action(fun a b -> handlerCurried a b) @> +// non-eta-expanded instance method +check "instanceNonEta" "AddC" <@ Action(o.AddC) @> +// eta-expanded instance method +check "instanceEta" "AddC" <@ Action(fun a b -> o.AddC a b) @> + +printfn "ok" + """ + |> asExe + |> withLangVersionPreview + |> compileAndRun + |> shouldSucceed + [] let ``Quotation on decimal literal compiles and runs`` () = FSharp """