Skip to content

Commit bdb6462

Browse files
vzarytovskiidsyme0101
authored
RFC FS-1124 - Interfaces with static abstract methods (#13119)
Co-authored-by: Don Syme <[email protected]> Co-authored-by: Don Syme <[email protected]> Co-authored-by: Petr Pokorny <[email protected]>
1 parent f8b56cb commit bdb6462

File tree

154 files changed

+5853
-1714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+5853
-1714
lines changed

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"internalConsoleOptions": "neverOpen",
2424
"suppressJITOptimizations": true,
2525
"stopAtEntry": false,
26-
"justMyCode": false,
26+
"justMyCode": true,
2727
"enableStepFiltering": true,
2828
"symbolOptions": {
2929
"searchMicrosoftSymbolServer": true,
@@ -73,7 +73,7 @@
7373
"enabled": true
7474
}
7575
},
76-
"justMyCode": false,
76+
"justMyCode": true,
7777
"enableStepFiltering": false,
7878
}
7979
]

src/Compiler/AbstractIL/il.fs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ type ILInstr =
13701370

13711371
| I_call of ILTailcall * ILMethodSpec * ILVarArgs
13721372
| I_callvirt of ILTailcall * ILMethodSpec * ILVarArgs
1373-
| I_callconstraint of ILTailcall * ILType * ILMethodSpec * ILVarArgs
1373+
| I_callconstraint of callvirt: bool * ILTailcall * ILType * ILMethodSpec * ILVarArgs
13741374
| I_calli of ILTailcall * ILCallingSignature * ILVarArgs
13751375
| I_ldftn of ILMethodSpec
13761376
| I_newobj of ILMethodSpec * ILVarArgs
@@ -3410,9 +3410,6 @@ let mkNormalCall mspec = I_call(Normalcall, mspec, None)
34103410

34113411
let mkNormalCallvirt mspec = I_callvirt(Normalcall, mspec, None)
34123412

3413-
let mkNormalCallconstraint (ty, mspec) =
3414-
I_callconstraint(Normalcall, ty, mspec, None)
3415-
34163413
let mkNormalNewobj mspec = I_newobj(mspec, None)
34173414

34183415
/// Comment on common object cache sizes:
@@ -3822,18 +3819,24 @@ let mkILClassCtor impl =
38223819
let mk_ospec (ty: ILType, callconv, nm, genparams, formal_args, formal_ret) =
38233820
OverridesSpec(mkILMethRef (ty.TypeRef, callconv, nm, genparams, formal_args, formal_ret), ty)
38243821

3825-
let mkILGenericVirtualMethod (nm, access, genparams, actual_args, actual_ret, impl) =
3822+
let mkILGenericVirtualMethod (nm, callconv: ILCallingConv, access, genparams, actual_args, actual_ret, impl) =
3823+
let attributes =
3824+
convertMemberAccess access
3825+
||| MethodAttributes.CheckAccessOnOverride
3826+
||| (match impl with
3827+
| MethodBody.Abstract -> MethodAttributes.Abstract ||| MethodAttributes.Virtual
3828+
| _ -> MethodAttributes.Virtual)
3829+
||| (if callconv.IsInstance then
3830+
enum 0
3831+
else
3832+
MethodAttributes.Static)
3833+
38263834
ILMethodDef(
38273835
name = nm,
3828-
attributes =
3829-
(convertMemberAccess access
3830-
||| MethodAttributes.CheckAccessOnOverride
3831-
||| (match impl with
3832-
| MethodBody.Abstract -> MethodAttributes.Abstract ||| MethodAttributes.Virtual
3833-
| _ -> MethodAttributes.Virtual)),
3836+
attributes = attributes,
38343837
implAttributes = MethodImplAttributes.Managed,
38353838
genericParams = genparams,
3836-
callingConv = ILCallingConv.Instance,
3839+
callingConv = callconv,
38373840
parameters = actual_args,
38383841
ret = actual_ret,
38393842
isEntryPoint = false,
@@ -3842,8 +3845,11 @@ let mkILGenericVirtualMethod (nm, access, genparams, actual_args, actual_ret, im
38423845
body = notlazy impl
38433846
)
38443847

3845-
let mkILNonGenericVirtualMethod (nm, access, args, ret, impl) =
3846-
mkILGenericVirtualMethod (nm, access, mkILEmptyGenericParams, args, ret, impl)
3848+
let mkILNonGenericVirtualMethod (nm, callconv, access, args, ret, impl) =
3849+
mkILGenericVirtualMethod (nm, callconv, access, mkILEmptyGenericParams, args, ret, impl)
3850+
3851+
let mkILNonGenericVirtualInstanceMethod (nm, access, args, ret, impl) =
3852+
mkILNonGenericVirtualMethod (nm, ILCallingConv.Instance, access, args, ret, impl)
38473853

38483854
let mkILGenericNonVirtualMethod (nm, access, genparams, actual_args, actual_ret, impl) =
38493855
ILMethodDef(
@@ -4267,7 +4273,7 @@ let mkILDelegateMethods access (ilg: ILGlobals) (iltyp_AsyncCallback, iltyp_IAsy
42674273

42684274
let one nm args ret =
42694275
let mdef =
4270-
mkILNonGenericVirtualMethod (nm, access, args, mkILReturn ret, MethodBody.Abstract)
4276+
mkILNonGenericVirtualInstanceMethod (nm, access, args, mkILReturn ret, MethodBody.Abstract)
42714277

42724278
mdef.WithAbstract(false).WithHideBySig(true).WithRuntime(true)
42734279

@@ -5298,7 +5304,7 @@ and refsOfILInstr s x =
52985304
| I_callvirt (_, mr, varargs) ->
52995305
refsOfILMethodSpec s mr
53005306
refsOfILVarArgs s varargs
5301-
| I_callconstraint (_, tr, mr, varargs) ->
5307+
| I_callconstraint (_, _, tr, mr, varargs) ->
53025308
refsOfILType s tr
53035309
refsOfILMethodSpec s mr
53045310
refsOfILVarArgs s varargs

src/Compiler/AbstractIL/il.fsi

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ type internal ILInstr =
523523
// Method call
524524
| I_call of ILTailcall * ILMethodSpec * ILVarArgs
525525
| I_callvirt of ILTailcall * ILMethodSpec * ILVarArgs
526-
| I_callconstraint of ILTailcall * ILType * ILMethodSpec * ILVarArgs
526+
| I_callconstraint of callvirt: bool * ILTailcall * ILType * ILMethodSpec * ILVarArgs
527527
| I_calli of ILTailcall * ILCallingSignature * ILVarArgs
528528
| I_ldftn of ILMethodSpec
529529
| I_newobj of ILMethodSpec * ILVarArgs
@@ -1970,7 +1970,6 @@ type internal ILLocalsAllocator =
19701970
/// Derived functions for making some common patterns of instructions.
19711971
val internal mkNormalCall: ILMethodSpec -> ILInstr
19721972
val internal mkNormalCallvirt: ILMethodSpec -> ILInstr
1973-
val internal mkNormalCallconstraint: ILType * ILMethodSpec -> ILInstr
19741973
val internal mkNormalNewobj: ILMethodSpec -> ILInstr
19751974
val internal mkCallBaseConstructor: ILType * ILType list -> ILInstr list
19761975
val internal mkNormalStfld: ILFieldSpec -> ILInstr
@@ -2025,12 +2024,16 @@ val internal mkILNonGenericStaticMethod:
20252024
string * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
20262025

20272026
val internal mkILGenericVirtualMethod:
2028-
string * ILMemberAccess * ILGenericParameterDefs * ILParameter list * ILReturn * MethodBody -> ILMethodDef
2027+
string * ILCallingConv * ILMemberAccess * ILGenericParameterDefs * ILParameter list * ILReturn * MethodBody ->
2028+
ILMethodDef
20292029

20302030
val internal mkILGenericNonVirtualMethod:
20312031
string * ILMemberAccess * ILGenericParameterDefs * ILParameter list * ILReturn * MethodBody -> ILMethodDef
20322032

20332033
val internal mkILNonGenericVirtualMethod:
2034+
string * ILCallingConv * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
2035+
2036+
val internal mkILNonGenericVirtualInstanceMethod:
20342037
string * ILMemberAccess * ILParameter list * ILReturn * MethodBody -> ILMethodDef
20352038

20362039
val internal mkILNonGenericInstanceMethod:

src/Compiler/AbstractIL/ilmorph.fs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,8 @@ let morphILTypesInILInstr ((factualTy, fformalTy)) i =
212212
| I_calli (a, mref, varargs) -> I_calli(a, callsig_ty2ty factualTy mref, morphILVarArgs factualTy varargs)
213213
| I_call (a, mr, varargs) -> I_call(a, conv_mspec mr, morphILVarArgs factualTy varargs)
214214
| I_callvirt (a, mr, varargs) -> I_callvirt(a, conv_mspec mr, morphILVarArgs factualTy varargs)
215-
| I_callconstraint (a, ty, mr, varargs) -> I_callconstraint(a, factualTy ty, conv_mspec mr, morphILVarArgs factualTy varargs)
215+
| I_callconstraint (callvirt, a, ty, mr, varargs) ->
216+
I_callconstraint(callvirt, a, factualTy ty, conv_mspec mr, morphILVarArgs factualTy varargs)
216217
| I_newobj (mr, varargs) -> I_newobj(conv_mspec mr, morphILVarArgs factualTy varargs)
217218
| I_ldftn mr -> I_ldftn(conv_mspec mr)
218219
| I_ldvirtftn mr -> I_ldvirtftn(conv_mspec mr)

src/Compiler/AbstractIL/ilprint.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,11 +893,11 @@ let rec goutput_instr env os inst =
893893
output_string os "callvirt "
894894
goutput_vararg_mspec env os (mspec, varargs)
895895
output_after_tailcall os tl
896-
| I_callconstraint (tl, ty, mspec, varargs) ->
896+
| I_callconstraint (callvirt, tl, ty, mspec, varargs) ->
897897
output_tailness os tl
898898
output_string os "constraint. "
899899
goutput_typ env os ty
900-
output_string os " callvirt "
900+
output_string os (if callvirt then " callvirt " else " call ")
901901
goutput_vararg_mspec env os (mspec, varargs)
902902
output_after_tailcall os tl
903903
| I_castclass ty ->

src/Compiler/AbstractIL/ilread.fs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -626,17 +626,23 @@ let instrs () =
626626
i_stsfld, I_field_instr(volatilePrefix (fun x fspec -> I_stsfld(x, fspec)))
627627
i_ldflda, I_field_instr(noPrefixes I_ldflda)
628628
i_ldsflda, I_field_instr(noPrefixes I_ldsflda)
629-
i_call, I_method_instr(tailPrefix (fun tl (mspec, y) -> I_call(tl, mspec, y)))
629+
(i_call,
630+
I_method_instr(
631+
constraintOrTailPrefix (fun (c, tl) (mspec, y) ->
632+
match c with
633+
| Some ty -> I_callconstraint(false, tl, ty, mspec, y)
634+
| None -> I_call(tl, mspec, y))
635+
))
630636
i_ldftn, I_method_instr(noPrefixes (fun (mspec, _y) -> I_ldftn mspec))
631637
i_ldvirtftn, I_method_instr(noPrefixes (fun (mspec, _y) -> I_ldvirtftn mspec))
632638
i_newobj, I_method_instr(noPrefixes I_newobj)
633-
i_callvirt,
634-
I_method_instr(
635-
constraintOrTailPrefix (fun (c, tl) (mspec, y) ->
636-
match c with
637-
| Some ty -> I_callconstraint(tl, ty, mspec, y)
638-
| None -> I_callvirt(tl, mspec, y))
639-
)
639+
(i_callvirt,
640+
I_method_instr(
641+
constraintOrTailPrefix (fun (c, tl) (mspec, y) ->
642+
match c with
643+
| Some ty -> I_callconstraint(true, tl, ty, mspec, y)
644+
| None -> I_callvirt(tl, mspec, y))
645+
))
640646
i_leave_s, I_unconditional_i8_instr(noPrefixes (fun x -> I_leave x))
641647
i_br_s, I_unconditional_i8_instr(noPrefixes I_br)
642648
i_leave, I_unconditional_i32_instr(noPrefixes (fun x -> I_leave x))

src/Compiler/AbstractIL/ilreflect.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,9 +1391,10 @@ let rec emitInstr cenv (modB: ModuleBuilder) emEnv (ilG: ILGenerator) instr =
13911391
emitSilverlightCheck ilG
13921392
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
13931393

1394-
| I_callconstraint (tail, ty, mspec, varargs) ->
1394+
| I_callconstraint (callvirt, tail, ty, mspec, varargs) ->
13951395
ilG.Emit(OpCodes.Constrained, convType cenv emEnv ty)
1396-
emitInstrCall cenv emEnv ilG OpCodes.Callvirt tail mspec varargs
1396+
let instr = if callvirt then OpCodes.Callvirt else OpCodes.Call
1397+
emitInstrCall cenv emEnv ilG instr tail mspec varargs
13971398

13981399
| I_calli (tail, callsig, None) ->
13991400
emitInstrTail cenv ilG tail (fun () ->

src/Compiler/AbstractIL/ilwrite.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,10 +1922,11 @@ module Codebuf =
19221922
emitTailness cenv codebuf tl
19231923
emitMethodSpecInstr cenv codebuf env i_callvirt (mspec, varargs)
19241924
//emitAfterTailcall codebuf tl
1925-
| I_callconstraint (tl, ty, mspec, varargs) ->
1925+
| I_callconstraint (callvirt, tl, ty, mspec, varargs) ->
19261926
emitTailness cenv codebuf tl
19271927
emitConstrained cenv codebuf env ty
1928-
emitMethodSpecInstr cenv codebuf env i_callvirt (mspec, varargs)
1928+
let instr = if callvirt then i_callvirt else i_call
1929+
emitMethodSpecInstr cenv codebuf env instr (mspec, varargs)
19291930
//emitAfterTailcall codebuf tl
19301931
| I_newobj (mspec, varargs) ->
19311932
emitMethodSpecInstr cenv codebuf env i_newobj (mspec, varargs)

src/Compiler/Checking/CheckComputationExpressions.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ let TcComputationExpression (cenv: cenv) env (overallTy: OverallTy) tpenv (mWhol
468468
match info with
469469
| None -> false
470470
| Some args ->
471-
args |> List.exists (fun (isParamArrayArg, _isInArg, isOutArg, optArgInfo, _callerInfo, _reflArgInfo) -> isParamArrayArg || isOutArg || optArgInfo.IsOptional))
471+
args |> List.exists (fun (ParamAttribs(isParamArrayArg, _isInArg, isOutArg, optArgInfo, _callerInfo, _reflArgInfo)) -> isParamArrayArg || isOutArg || optArgInfo.IsOptional))
472472
else
473473
false
474474

0 commit comments

Comments
 (0)