Skip to content

Exposing slot signature of members in object expressions #463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 30, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 5 additions & 3 deletions src/fsharp/vs/Exprs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ type E =
| ILAsm of string * FSharpType list * FSharpExpr list

/// Used to represent the information at an object expression member
and [<Sealed>] FSharpObjectExprOverride(gps: FSharpGenericParameter list, args:FSharpMemberFunctionOrValue list list, body: FSharpExpr) =
and [<Sealed>] FSharpObjectExprOverride(sgn: FSharpAbstractSignature, gps: FSharpGenericParameter list, args:FSharpMemberFunctionOrValue list list, body: FSharpExpr) =
member __.Signature = sgn
member __.GenericParameters = gps
member __.CurriedParameterGroups = args
member __.Body = body
Expand Down Expand Up @@ -444,13 +445,14 @@ module FSharpExprConvert =
| Expr.Obj (_lambdaId,typ,_basev,basecall,overrides, iimpls,_m) ->
let basecallR = ConvExpr cenv env basecall
let ConvertMethods methods =
[ for (TObjExprMethod(_slotsig,_,tps,tmvs,body,_)) in methods ->
[ for (TObjExprMethod(slotsig,_,tps,tmvs,body,_)) in methods ->
let vslR = List.map (List.map (ConvVal cenv)) tmvs
let sgn = FSharpAbstractSignature(cenv, slotsig)
let tpsR = [ for tp in tps -> FSharpGenericParameter(cenv,tp) ]
let env = ExprTranslationEnv.Empty.BindTypars (Seq.zip tps tpsR |> Seq.toList)
let env = env.BindCurriedVals tmvs
let bodyR = ConvExpr cenv env body
FSharpObjectExprOverride(tpsR, vslR, bodyR) ]
FSharpObjectExprOverride(sgn, tpsR, vslR, bodyR) ]
let overridesR = ConvertMethods overrides
let iimplsR = List.map (fun (ty,impls) -> ConvType cenv ty, ConvertMethods impls) iimpls

Expand Down
2 changes: 2 additions & 0 deletions src/fsharp/vs/Exprs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ and [<Sealed>] FSharpExpr =

/// Represents a checked method in an object expression, as seen by the F# language.
and [<Sealed>] FSharpObjectExprOverride =
/// The signature of the implemented abstract slot
member Signature : FSharpAbstractSignature
/// The generic parameters of the method
member GenericParameters : FSharpGenericParameter list
/// The parameters of the method
Expand Down
1 change: 1 addition & 0 deletions src/fsharp/vs/Symbols.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ and [<Class>] FSharpAbstractParameter =

/// Represents the signature of an abstract slot of a class or interface
and [<Class>] FSharpAbstractSignature =
internal new : Impl.cenv * SlotSig -> FSharpAbstractSignature

/// Get the arguments of the abstract slot
member AbstractArguments : IList<IList<FSharpAbstractParameter>>
Expand Down
15 changes: 11 additions & 4 deletions tests/service/ExprTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ module Utils =
| BasicPatterns.UnionCaseGet(obj,ty,uc,f1) -> printExpr 10 obj + "." + f1.Name
| BasicPatterns.UnionCaseTest(obj,ty,f1) -> printExpr 10 obj + ".Is" + f1.Name
| BasicPatterns.UnionCaseTag(obj,ty) -> printExpr 10 obj + ".Tag"
| BasicPatterns.ObjectExpr(ty,basecall,overrides,iimpls) -> "{ new " + printTy ty + " with ... }"
| BasicPatterns.ObjectExpr(ty,basecall,overrides,iimpls) -> "{ " + printExpr 10 basecall + " with " + printOverrides overrides + " " + printIimpls iimpls + " }"
| BasicPatterns.TraitCall(tys,nm,argtys,tinst,args) -> "trait call " + nm + printTupledArgs args
| BasicPatterns.Const(obj,ty) ->
match obj with
Expand All @@ -84,7 +84,14 @@ module Utils =
and printCurriedParams (vs: FSharpMemberOrFunctionOrValue list list) = String.concat " " (List.map printParams vs)
and printTy ty = ty.Format(FSharpDisplayContext.Empty)
and printTyargs tyargs = match tyargs with [] -> "" | args -> "<" + String.concat "," (List.map printTy tyargs) + ">"

and printOverrides ors = String.concat ";" (List.map printOverride ors)
and printOverride o =
match o.CurriedParameterGroups with
| [t] :: a ->
"member " + t.CompiledName + "." + o.Signature.Name + printCurriedParams a + " = " + printExpr 10 o.Body
| _ -> failwith "wrong this argument in object expression override"
and printIimpls iis = String.concat ";" (List.map printImlementation iis)
and printImlementation (i, ors) = "interface " + printTy i + " with " + printOverrides ors

let rec printDeclaration (excludes:HashSet<_> option) (d: FSharpImplementationFileDeclaration) =
seq {
Expand Down Expand Up @@ -428,8 +435,8 @@ let ``Test Declarations project1`` () =
"member Method(x) (a,b) = 1 @ (106,37--106,38)";
"member CurriedMethod(x) (a1,b1) (a2,b2) = 1 @ (107,63--107,64)";
"let testFunctionThatCallsMultiArgMethods(unitVar0) = let m: M.MultiArgMethods = new MultiArgMethods(3,4) in Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (m.Method(7,8),fun tupledArg -> let arg00: Microsoft.FSharp.Core.int = tupledArg.Item0 in let arg01: Microsoft.FSharp.Core.int = tupledArg.Item1 in fun tupledArg -> let arg10: Microsoft.FSharp.Core.int = tupledArg.Item0 in let arg11: Microsoft.FSharp.Core.int = tupledArg.Item1 in m.CurriedMethod(arg00,arg01,arg10,arg11) (9,10) (11,12)) @ (110,8--110,9)";
"let functionThatUsesObjectExpression(unitVar0) = { new Microsoft.FSharp.Core.obj with ... } @ (114,3--114,55)";
"let functionThatUsesObjectExpressionWithInterfaceImpl(unitVar0) = { new Microsoft.FSharp.Core.obj with ... } :> System.IComparable @ (117,3--120,38)";
"let functionThatUsesObjectExpression(unitVar0) = { Object..ctor () with member x.ToString(unitVar1) = Operators.ToString<Microsoft.FSharp.Core.int> (888) } @ (114,3--114,55)";
"let functionThatUsesObjectExpressionWithInterfaceImpl(unitVar0) = { Object..ctor () with member x.ToString(unitVar1) = Operators.ToString<Microsoft.FSharp.Core.int> (888) interface System.IComparable with member x.CompareTo(y) = 0 } :> System.IComparable @ (117,3--120,38)";
"let testFunctionThatUsesUnitsOfMeasure(x) (y) = Operators.op_Addition<Microsoft.FSharp.Core.float<'u>,Microsoft.FSharp.Core.float<'u>,Microsoft.FSharp.Core.float<'u>> (x,y) @ (122,70--122,75)";
"let testFunctionThatUsesAddressesAndByrefs(x) = let mutable w: Microsoft.FSharp.Core.int = 4 in let y1: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = x in let y2: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = &w in let arr: Microsoft.FSharp.Core.int Microsoft.FSharp.Core.[] = [| ... |] in let r: Microsoft.FSharp.Core.int Microsoft.FSharp.Core.ref = Operators.Ref<Microsoft.FSharp.Core.int> (3) in let y3: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = [I_ldelema (NormalAddress,false,ILArrayShape [(Some 0, null)],TypeVar 0us)](arr,0) in let y4: Microsoft.FSharp.Core.byref<Microsoft.FSharp.Core.int> = &r.contents in let z: Microsoft.FSharp.Core.int = Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (x,y1),y2),y3) in (w <- 3; (x <- 4; (y2 <- 4; (y3 <- 5; Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (Operators.op_Addition<Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int,Microsoft.FSharp.Core.int> (z,x),y1),y2),y3),y4),IntrinsicFunctions.GetArray<Microsoft.FSharp.Core.int> (arr,0)),r.contents))))) @ (125,16--125,17)";
"let testFunctionThatUsesStructs1(dt) = dt.AddDays(3) @ (139,57--139,72)";
Expand Down