Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
d380a0e
substitute 'nameof(<long ident>)` with `Conts(<long ident as string l…
Jan 18, 2017
223d313
Implementing basic nameof and typenameof operators
Jan 18, 2017
529cc6f
Apply feedback
Jan 18, 2017
f3c4ba5
Revert "Apply feedback"
Jan 18, 2017
8fd0392
Revert "Implementing basic nameof and typenameof operators"
Jan 18, 2017
77c8f77
revert nameof and typenameof functions to FSharp.Core
vasily-kirichenko Jan 18, 2017
3070c1d
wip
vasily-kirichenko Jan 18, 2017
b3e712d
it works
vasily-kirichenko Jan 18, 2017
6c6e3b5
Merge remote-tracking branch 'origin/master' into nameof-operator
Jan 19, 2017
7832be5
refactoring
Jan 19, 2017
6581790
make it work on simple `Ident`s
Jan 19, 2017
0f5165f
use proper error message
Jan 19, 2017
22898ad
restrict using `nameof` operator as first class
Jan 19, 2017
e5033af
remove `typenameof` bits
Jan 19, 2017
1ad0a0e
nameof(typeof<_>) works
Jan 19, 2017
c9a64b2
Merge branch 'master' into nameof-operator
vasily-kirichenko Jan 28, 2017
5657759
fix QA tests
vasily-kirichenko Jan 28, 2017
b26994c
Merge branch 'master' into nameof-operator
vasily-kirichenko Feb 3, 2017
a732de0
remove nameof function form FSharp.Core
vasily-kirichenko Feb 3, 2017
b29fe57
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko Feb 4, 2017
b7763a6
Revert "remove nameof function form FSharp.Core"
vasily-kirichenko Feb 4, 2017
906a934
Try to resolve the `nameof` operator argument to prevent passing anyt…
vasily-kirichenko Feb 4, 2017
a770e3c
nameof works on generic types
vasily-kirichenko Feb 4, 2017
067955a
fix error range in case of wrong `nameof`operator argument
vasily-kirichenko Feb 4, 2017
bfcc390
notify name resolution sink about nameof operator argument Item in or…
vasily-kirichenko Feb 5, 2017
6a92a80
fully type check `nameof` argument
vasily-kirichenko Feb 5, 2017
bcec600
try to type check arg again
vasily-kirichenko Feb 5, 2017
f64b3c5
Merge remote-tracking branch 'origin/master' into nameof-operator
Feb 6, 2017
0c1cad2
type check `nameof` argument more carefully
vasily-kirichenko Feb 6, 2017
15bf862
Merge remote-tracking branch 'vasily-kirichenko/nameof-operator' into…
vasily-kirichenko Feb 6, 2017
5b72f32
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko Feb 15, 2017
ceb7731
Merge branch 'master' into nameof-operator
vasily-kirichenko Mar 1, 2017
588de2e
factor tcExpr to top level function
vasily-kirichenko Mar 1, 2017
f2ae00f
Merge remote-tracking branch 'origin/master' into nameof-operator
vasily-kirichenko Mar 8, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Implementing basic nameof and typenameof operators"
This reverts commit 223d313.

Conflicts:
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAdditionExpr.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAppliedFunction.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfAsAFunction.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfDictLookup.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntConst.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfIntegerAppliedFunction.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfParameterAppliedFunction.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfPartiallyAppliedFunction.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfStringConst.fs
	tests/fsharpqa/Source/Conformance/Expressions/DataExpressions/NameOf/E_NameOfWithPipe.fs
  • Loading branch information
Vasily Kirichenko authored and Vasily Kirichenko committed Jan 18, 2017
commit 8fd039239c427df0c4974f8995388431f711f396
6 changes: 0 additions & 6 deletions src/fsharp/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4748,12 +4748,6 @@ namespace Microsoft.FSharp.Core
[<CompiledName("TypeOf")>]
let inline typeof<'T> = BasicInlinedOperations.typeof<'T>

[<CompiledName("TypeNameOf")>]
let inline typenameof<'T> : string = raise (Exception "may not call directly, should always be optimized away")

[<CompiledName("NameOf")>]
let inline nameof (_: 'T) : string = raise (Exception "may not call directly, should always be optimized away")

[<CompiledName("MethodHandleOf")>]
let methodhandleof (_call: ('T -> 'TResult)) : System.RuntimeMethodHandle = raise (Exception "may not call directly, should always be optimized away")

Expand Down
9 changes: 0 additions & 9 deletions src/fsharp/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2320,15 +2320,6 @@ namespace Microsoft.FSharp.Core
[<CompiledName("TypeOf")>]
val inline typeof<'T> : System.Type

/// <summary>Returns the name of the given static type.</summary>
[<RequiresExplicitTypeArguments>]
[<CompiledName("TypeNameOf")>]
val inline typenameof<'T> : string

/// <summary>Returns the name of the given symbol.</summary>
[<CompiledName("NameOf")>]
val inline nameof : 'T -> string

/// <summary>An internal, library-only compiler intrinsic for compile-time
/// generation of a RuntimeMethodHandle.</summary>
[<CompiledName("MethodHandleOf")>]
Expand Down
33 changes: 1 addition & 32 deletions src/fsharp/Optimizer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ let AbstractAndRemapModulInfo msg g m (repackage,hidden) info =
info

//-------------------------------------------------------------------------
// Misc helpers
// Misc helerps
//-------------------------------------------------------------------------

// Mark some variables (the ones we introduce via abstractBigTargets) as don't-eliminate
Expand Down Expand Up @@ -2501,37 +2501,6 @@ and TryDevirtualizeApplication cenv env (f,tyargs,args,m) =
MightMakeCriticalTailcall = false
Info=UnknownValue})

// Analyze the name of the given symbol and rewrite AST to constant string expression with the name
| Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.nameof_vref ->
PostTypeCheckSemanticChecks.tryExtractNameOf args
|> Option.map (fun name ->
Expr.Const(Const.String name, m, cenv.g.string_ty),
{ TotalSize = 1
FunctionSize = 1
HasEffect = false
MightMakeCriticalTailcall = false
Info = UnknownValue })
// Analyze the name of the given type and rewrite AST to constant string expression with the name
| Expr.Val(vref,_,_),_,_ when valRefEq cenv.g vref cenv.g.typenameof_vref ->
match tyargs with
| (typeName:TType):: _ ->
let name =
match typeName with
| TType_forall (_tps,ty) -> ty.ToString()
| TType_app (tcref, _) -> tcref.CompiledRepresentationForNamedType.FullName
| TType_tuple tinst -> "(" + String.concat "," (List.map string tinst) + ")"
| TType_fun (d,r) -> "(" + string d + " -> " + string r + ")"
| TType_ucase (uc,_) -> uc.CaseName
| TType_var tp -> tp.DisplayName
| TType_measure ms -> sprintf "%A" ms

Some(Expr.Const(Const.String name, m, cenv.g.string_ty),
{ TotalSize = 1
FunctionSize = 1
HasEffect = false
MightMakeCriticalTailcall = false
Info = UnknownValue })
| _ -> None
| _ -> None

/// Attempt to inline an application of a known value at callsites
Expand Down
35 changes: 2 additions & 33 deletions src/fsharp/PostInferenceChecks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -507,27 +507,6 @@ let CheckMultipleInterfaceInstantiations cenv interfaces m =
let rec CheckExprNoByrefs (cenv:cenv) (env:env) expr =
CheckExpr cenv env expr NoByrefs

// tries to extract the name of an expression
let tryExtractNameOf args =
match args with
| [Expr.App(Expr.Val(r,_,_),_,_,Expr.Const(constant,_,_)::_,_)] ->
if r.CompiledName.StartsWith("get_") && constant = Const.Unit then // TODO: We need a better way to find static property getters
Some(r.CompiledName.Substring(4))
else
None // the function was applied
| [Expr.App(Expr.Val(r,_,_),_,_,[],_)] -> Some(r.CompiledName)
| [Expr.App(Expr.Val(r,_,_),_,_,_,_)] ->
if r.CompiledName.StartsWith("get_") then // TODO: We need a better way to find member property getters
Some(r.CompiledName.Substring(4))
else
None // the function was applied
| [Expr.Let(_,Expr.Val(r,_,_),_,_)] -> Some(r.CompiledName)
| [Expr.Let(_,Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_),_,_)] -> Some(r.CompiledName)
| [Expr.Lambda(_,_,_,_,Expr.App(Expr.Val(r,_,_),_,_,_,_),_,_)] -> Some(r.CompiledName)
| [Expr.Op(TOp.ValFieldGet(r),_,_,_)] -> Some(r.FieldName)
| [Expr.Lambda(_,_,_,_,Expr.Op(TOp.ILCall(_,_,_,_,_,_,_,r,_,_,_),_,_,_),_,_)] -> Some(r.Name)
| _ -> None

/// Check a value
and CheckVal (cenv:cenv) (env:env) v m context =
if cenv.reportErrors then
Expand Down Expand Up @@ -557,18 +536,8 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
CheckExpr cenv env body context

| Expr.Const (_,m,ty) ->
CheckTypePermitByrefs cenv env m ty

| Expr.App(Expr.Val (v,_,_),_,_,args,m) ->
if cenv.reportErrors then
if valRefEq cenv.g v cenv.g.nameof_vref && tryExtractNameOf args = None then
errorR(Error(FSComp.SR.expressionHasNoName(), m))
match args with
| [_;Expr.App(Expr.Val (v,_,_),_,_,args,m)] ->
if valRefEq cenv.g v cenv.g.nameof_vref && tryExtractNameOf args = None then
errorR(Error(FSComp.SR.nameofNotPermitted(), m))
| _ -> ()

CheckTypePermitByrefs cenv env m ty

| Expr.Val (v,vFlags,m) ->
if cenv.reportErrors then
if v.BaseOrThisInfo = BaseVal then
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/PostInferenceChecks.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ open Microsoft.FSharp.Compiler.InfoReader

val testFlagMemberBody : bool ref
val CheckTopImpl : TcGlobals * Import.ImportMap * bool * InfoReader * Tast.CompilationPath list * Tast.CcuThunk * Tastops.DisplayEnv * Tast.ModuleOrNamespaceExprWithSig * Tast.Attribs * (bool * bool) -> bool
val tryExtractNameOf : Microsoft.FSharp.Compiler.Tast.Expr list -> string option
12 changes: 0 additions & 12 deletions src/fsharp/TastOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2879,11 +2879,6 @@ let isTypeOfValRef g vref =
// There is an internal version of typeof defined in prim-types.fs that needs to be detected
|| (g.compilingFslib && vref.LogicalName = "typeof")

let isTypeNameOfValRef g vref =
valRefEq g vref g.typenameof_vref
// There is an internal version of typenameof defined in prim-types.fs that needs to be detected
|| (g.compilingFslib && vref.LogicalName = "typenameof")

let isSizeOfValRef g vref =
valRefEq g vref g.sizeof_vref
// There is an internal version of typeof defined in prim-types.fs that needs to be detected
Expand All @@ -2904,11 +2899,6 @@ let (|TypeOfExpr|_|) g expr =
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_) when isTypeOfValRef g vref -> Some ty
| _ -> None

let (|TypeNameOfExpr|_|) g expr =
match expr with
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_) when isTypeNameOfValRef g vref -> Some ty
| _ -> None

let (|SizeOfExpr|_|) g expr =
match expr with
| Expr.App(Expr.Val(vref,_,_),_,[ty],[],_) when isSizeOfValRef g vref -> Some ty
Expand Down Expand Up @@ -6089,7 +6079,6 @@ let mkCallUnboxFast (g:TcGlobals) m ty e1 = mkApps g (typedExprFor
let mkCallTypeTest (g:TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsic g m g.istype_info, [[ty]], [ e1 ], m)
let mkCallTypeOf (g:TcGlobals) m ty = mkApps g (typedExprForIntrinsic g m g.typeof_info, [[ty]], [ ], m)
let mkCallTypeDefOf (g:TcGlobals) m ty = mkApps g (typedExprForIntrinsic g m g.typedefof_info, [[ty]], [ ], m)
let mkCallTypeNameOf g m ty = mkApps g (typedExprForIntrinsic g m g.typenameof_info, [[ty]], [ ], m)


let mkCallDispose (g:TcGlobals) m ty e1 = mkApps g (typedExprForIntrinsic g m g.dispose_info, [[ty]], [ e1 ], m)
Expand Down Expand Up @@ -7751,7 +7740,6 @@ let IsSimpleSyntacticConstantExpr g inputExpr =
| Expr.Op (TOp.UnionCase _,_,[],_) // Nullary union cases
| UncheckedDefaultOfExpr g _
| SizeOfExpr g _
| TypeNameOfExpr g _
| TypeOfExpr g _ -> true
// All others are not simple constant expressions
| _ -> false
Expand Down
1 change: 0 additions & 1 deletion src/fsharp/TastOps.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,6 @@ val mkCallTypeTest : TcGlobals -> range -> TType -> Expr -> Expr
val canUseTypeTestFast : TcGlobals -> TType -> bool

val mkCallTypeOf : TcGlobals -> range -> TType -> Expr
val mkCallTypeNameOf : TcGlobals -> range -> TType -> Expr
val mkCallTypeDefOf : TcGlobals -> range -> TType -> Expr

val mkCallCreateInstance : TcGlobals -> range -> TType -> Expr
Expand Down
10 changes: 0 additions & 10 deletions src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -162,10 +162,6 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
// The helper to find system types amongst referenced DLLs
tryFindSysTypeCcu,
emitDebugInfoInQuotations: bool, usesMscorlib: bool, noDebugData: bool) =
nameof_info : IntrinsicValRef
nameof_vref : ValRef
typenameof_info : IntrinsicValRef
typenameof_vref : ValRef

let vara = NewRigidTypar "a" envRange
let varb = NewRigidTypar "b" envRange
Expand Down Expand Up @@ -573,8 +569,6 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
let v_typeof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "typeof" , None , Some "TypeOf" , [vara], ([], v_system_Type_typ))
let v_methodhandleof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "methodhandleof" , None , Some "MethodHandleOf", [vara;varb], ([[varaTy --> varbTy]], v_system_RuntimeMethodHandle_typ))
let v_sizeof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "sizeof" , None , Some "SizeOf" , [vara], ([], v_int_ty))
let typenameof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "typenameof" ,None ,Some "TypeNameOf" ,[vara], ([],string_ty))
let nameof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "nameof" ,None ,Some "NameOf" ,[vara], ([[varaTy]],string_ty))
let v_unchecked_defaultof_info = makeIntrinsicValRef(fslib_MFOperatorsUnchecked_nleref, "defaultof" , None , Some "DefaultOf", [vara], ([], varaTy))
let v_typedefof_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "typedefof" , None , Some "TypeDefOf", [vara], ([], v_system_Type_typ))
let v_enum_info = makeIntrinsicValRef(fslib_MFOperators_nleref, "enum" , None , Some "ToEnum" , [vara], ([[v_int_ty]], varaTy))
Expand Down Expand Up @@ -916,10 +910,6 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
member val system_MarshalByRefObject_typ = tryMkSysNonGenericTy sys "MarshalByRefObject"

member __.system_Reflection_MethodInfo_typ = v_system_Reflection_MethodInfo_typ
nameof_info = nameof_info
nameof_vref = ValRefForIntrinsic nameof_info
typenameof_info = typenameof_info
typenameof_vref = ValRefForIntrinsic typenameof_info

member val system_Array_tcref = findSysTyconRef sys "Array"
member val system_Object_tcref = findSysTyconRef sys "Object"
Expand Down