Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3070c1d

Browse files
wip
1 parent77c8f77 commit3070c1d

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

‎src/fsharp/TastOps.fs‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2884,6 +2884,16 @@ let isSizeOfValRef g vref =
28842884
// There is an internal version of typeof defined in prim-types.fs that needs to be detected
28852885
||(g.compilingFslib&& vref.LogicalName="sizeof")
28862886

2887+
letisNameOfValRef g vref=
2888+
valRefEq g vref g.nameof_vref
2889+
// There is an internal version of typeof defined in prim-types.fs that needs to be detected
2890+
||(g.compilingFslib&& vref.LogicalName="nameof")
2891+
2892+
letisTypeNameOfValRef g vref=
2893+
valRefEq g vref g.typenameof_vref
2894+
// There is an internal version of typeof defined in prim-types.fs that needs to be detected
2895+
||(g.compilingFslib&& vref.LogicalName="typenameof")
2896+
28872897
letisTypeDefOfValRef g vref=
28882898
valRefEq g vref g.typedefof_vref
28892899
// There is an internal version of typedefof defined in prim-types.fs that needs to be detected
@@ -2909,7 +2919,15 @@ let (|TypeDefOfExpr|_|) g expr =
29092919
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_)when isTypeDefOfValRef g vref-> Some ty
29102920
|_-> None
29112921

2922+
let(|NameOfExpr|_|)g expr=
2923+
match exprwith
2924+
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_)when isNameOfValRef g vref-> Some ty
2925+
|_-> None
29122926

2927+
let(|TypeNameOfExpr|_|)g expr=
2928+
match exprwith
2929+
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_)when isTypeNameOfValRef g vref-> Some ty
2930+
|_-> None
29132931

29142932
//--------------------------------------------------------------------------
29152933
// DEBUG layout

‎src/fsharp/TcGlobals.fs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,9 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
569569
letv_typeof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"typeof", None, Some"TypeOf",[vara],([], v_system_Type_typ))
570570
letv_methodhandleof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"methodhandleof", None, Some"MethodHandleOf",[vara;varb],([[varaTy--> varbTy]], v_system_RuntimeMethodHandle_typ))
571571
letv_sizeof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"sizeof", None, Some"SizeOf",[vara],([], v_int_ty))
572+
letv_typenameof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"typenameof", None, Some"TypeNameOf",[vara],([], v_string_ty))
573+
letv_nameof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"nameof", None, Some"NameOf",[vara],([[varaTy]], v_string_ty))
574+
572575
letv_unchecked_defaultof_info= makeIntrinsicValRef(fslib_MFOperatorsUnchecked_nleref,"defaultof", None, Some"DefaultOf",[vara],([], varaTy))
573576
letv_typedefof_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"typedefof", None, Some"TypeDefOf",[vara],([], v_system_Type_typ))
574577
letv_enum_info= makeIntrinsicValRef(fslib_MFOperators_nleref,"enum", None, Some"ToEnum",[vara],([[v_int_ty]], varaTy))
@@ -1121,6 +1124,8 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
11211124
member valmethodhandleof_vref= ValRefForIntrinsic v_methodhandleof_info
11221125
member valtypeof_vref= ValRefForIntrinsic v_typeof_info
11231126
member valsizeof_vref= ValRefForIntrinsic v_sizeof_info
1127+
member valnameof_vref= ValRefForIntrinsic v_nameof_info
1128+
member valtypenameof_vref= ValRefForIntrinsic v_typenameof_info
11241129
member valtypedefof_vref= ValRefForIntrinsic v_typedefof_info
11251130
member valenum_vref= ValRefForIntrinsic v_enum_info
11261131
member valenumOfValue_vref= ValRefForIntrinsic v_enumOfValue_info

‎src/fsharp/TypeChecker.fs‎

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8249,22 +8249,32 @@ and TcFunctionApplicationThen cenv overallTy env tpenv mExprAndArg expr exprty (
82498249
// it is an error or a computation expression
82508250
match UnifyFunctionTypeUndoIfFailed cenv denv mFunExpr exprty with
82518251
| Some (domainTy,resultTy) ->
8252-
8253-
// Notice the special case 'seq { ... }'. In this case 'seq' is actually a function in the F# library.
8254-
// Set a flag in the syntax tree to say we noticed a leading 'seq'
8255-
match synArg with
8256-
| SynExpr.CompExpr (false,isNotNakedRefCell,_comp,_m) ->
8257-
isNotNakedRefCell :=
8258-
!isNotNakedRefCell
8259-
||
8260-
(match expr with
8261-
| ApplicableExpr(_,Expr.Op(TOp.Coerce,_,[Expr.App(Expr.Val(vf,_,_),_,_,_,_)],_),_) when valRefEq cenv.g vf cenv.g.seq_vref -> true
8262-
| _ -> false)
8263-
| _ -> ()
8264-
8265-
let arg,tpenv = TcExpr cenv domainTy env tpenv synArg
8266-
let exprAndArg = buildApp cenv expr exprty arg mExprAndArg
8267-
TcDelayed cenv overallTy env tpenv mExprAndArg exprAndArg resultTy atomicFlag delayed
8252+
match expr, synArg with
8253+
| (ApplicableExpr(_, Expr.Val(vref,_,_), _), SynExpr.LongIdent(_, LongIdentWithDots(idents, _), _, _))
8254+
when valRefEq cenv.g vref cenv.g.nameof_vref && not (isNil idents) ->
8255+
8256+
let argIdent = List.last idents
8257+
let r = expr.Range
8258+
// generate fake `range` for the constant the `nameof(..)` we are substituting
8259+
let constRange = mkRange r.FileName r.Start (mkPos r.StartLine (r.StartColumn + argIdent.idText.Length + 2)) // `2` are for quotes
8260+
TcDelayed cenv overallTy env tpenv mExprAndArg (ApplicableExpr(cenv, Expr.Const(Const.String(argIdent.idText), constRange, cenv.g.string_ty), true)) cenv.g.string_ty ExprAtomicFlag.Atomic delayed
8261+
| _ ->
8262+
// Notice the special case 'seq { ... }'. In this case 'seq' is actually a function in the F# library.
8263+
// Set a flag in the syntax tree to say we noticed a leading 'seq'
8264+
match synArg with
8265+
| SynExpr.CompExpr (false,isNotNakedRefCell,_comp,_m) ->
8266+
isNotNakedRefCell :=
8267+
!isNotNakedRefCell
8268+
||
8269+
(match expr with
8270+
| ApplicableExpr(_,Expr.Op(TOp.Coerce,_,[Expr.App(Expr.Val(vf,_,_),_,_,_,_)],_),_) when valRefEq cenv.g vf cenv.g.seq_vref -> true
8271+
| _ -> false)
8272+
| _ -> ()
8273+
8274+
let arg,tpenv = TcExpr cenv domainTy env tpenv synArg
8275+
let exprAndArg = buildApp cenv expr exprty arg mExprAndArg
8276+
TcDelayed cenv overallTy env tpenv mExprAndArg exprAndArg resultTy atomicFlag delayed
8277+
82688278
| None ->
82698279
// OK, 'expr' doesn't have function type, but perhaps 'expr' is a computation expression builder, and 'arg' is '{ ... }'
82708280
match synArg with

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp