Skip to content

Commit

Permalink
Merge pull request #620 from Jand42/master
Browse files Browse the repository at this point in the history
Fix #568: recognize provided expressions
  • Loading branch information
dsyme authored Aug 12, 2016
2 parents bed62ac + 03511ed commit 48a703f
Show file tree
Hide file tree
Showing 13 changed files with 840 additions and 131 deletions.
22 changes: 21 additions & 1 deletion FSharp.Compiler.Service.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "project", "project", "{B6B68AE6-E7A4-4D43-9B34-FFA74BFE192B}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -63,6 +63,8 @@ Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.Pro
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "FSharp.Compiler.Service.ProjectCracker", "src\fsharp\FSharp.Compiler.Service.ProjectCracker\FSharp.Compiler.Service.ProjectCracker.fsproj", "{893C3CD9-5AF8-4027-A667-21E62FC2C703}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "TestTP", "tests\service\data\TestTP\TestTP.fsproj", "{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -247,6 +249,24 @@ Global
{893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{893C3CD9-5AF8-4027-A667-21E62FC2C703}.Release|x86.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|x86.ActiveCfg = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Debug|x86.Build.0 = Debug|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Any CPU.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Any CPU.Build.0 = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Mixed Platforms.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|Mixed Platforms.Build.0 = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|x86.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Proto|x86.Build.0 = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Any CPU.Build.0 = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|x86.ActiveCfg = Release|Any CPU
{FF76BD3C-5E0A-4752-B6C3-044F6E15719B}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
58 changes: 56 additions & 2 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4265,20 +4265,74 @@ let compareILVersions (a1,a2,a3,a4) ((b1,b2,b3,b4) : ILVersionInfo) =
if c <> 0 then c else
0

let qunscope_scoref scoref_old =
match scoref_old with
| ILScopeRef.Local -> None
| _ -> Some ILScopeRef.Local

let qunscope_tref (x:ILTypeRef) =
match qunscope_scoref x.Scope with
| None -> None
| Some s -> Some (ILTypeRef.Create(s,x.Enclosing,x.Name))

let unscopeILScopeRef y = match qunscope_scoref y with Some x -> x | None -> y
let unscopeILTypeRef y = match qunscope_tref y with Some x -> x | None -> y

let rec unscopeILTypeSpecQuick (tspec:ILTypeSpec) =
let tref = tspec.TypeRef
let tinst = tspec.GenericArgs
let qtref = qunscope_tref tref
if ILList.isEmpty tinst && isNone qtref then
None (* avoid reallocation in the common case *)
else
match qtref with
| None -> Some (ILTypeSpec.Create (tref, unscopeILTypes tinst))
| Some tref -> Some (ILTypeSpec.Create (tref, unscopeILTypes tinst))

and unscopeILTypeSpec x y =
match rescopeILTypeSpecQuick x y with
| Some x -> x
| None -> y

and unscopeILType typ =
match typ with
| ILType.Ptr t -> ILType.Ptr (unscopeILType t)
| ILType.FunctionPointer t -> ILType.FunctionPointer (unscopeILCallSig t)
| ILType.Byref t -> ILType.Byref (unscopeILType t)
| ILType.Boxed cr ->
match unscopeILTypeSpecQuick cr with
| Some res -> mkILBoxedType res
| None -> typ // avoid reallocation in the common case
| ILType.Array (s,ty) -> ILType.Array (s,unscopeILType ty)
| ILType.Value cr ->
match unscopeILTypeSpecQuick cr with
| Some res -> ILType.Value res
| None -> typ // avoid reallocation in the common case
| ILType.Modified(b,tref,ty) -> ILType.Modified(b,unscopeILTypeRef tref, unscopeILType ty)
| x -> x

and unscopeILTypes i =
if ILList.isEmpty i then i
else ILList.map unscopeILType i

and unscopeILCallSig csig =
mkILCallSigRaw (csig.CallingConv,unscopeILTypes csig.ArgTypes,unscopeILType csig.ReturnType)

let resolveILMethodRefWithRescope r td (mref:ILMethodRef) =
let args = mref.ArgTypes
let nargs = args.Length
let nm = mref.Name
let possibles = td.Methods.FindByNameAndArity (nm,nargs)
if isNil possibles then failwith ("no method named "+nm+" found in type "+td.Name);
let argTypes = mref.ArgTypes |> List.map r
let retType : ILType = r mref.ReturnType
match
possibles |> List.filter (fun md ->
mref.CallingConv = md.CallingConv &&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
(md.Parameters,mref.ArgTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) &&
(md.Parameters,argTypes) ||> ILList.lengthsEqAndForall2 (fun p1 p2 -> r p1.Type = p2) &&
// REVIEW: this uses equality on ILType. For CMOD_OPTIONAL this is not going to be correct
r md.Return.Type = mref.ReturnType) with
r md.Return.Type = retType) with
| [] -> failwith ("no method named "+nm+" with appropriate argument types found in type "+td.Name)
| [mdef] -> mdef
| _ -> failwith ("multiple methods named "+nm+" appear with identical argument types in type "+td.Name)
Expand Down
3 changes: 3 additions & 0 deletions src/absil/il.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,9 @@ val rescopeILMethodRef: ILScopeRef -> ILMethodRef -> ILMethodRef
/// the new scope.
val rescopeILFieldRef: ILScopeRef -> ILFieldRef -> ILFieldRef

/// Unscoping. Clears every scope information, use for looking up IL method references only.
val unscopeILType: ILType -> ILType


//-----------------------------------------------------------------------
// The ILCode Builder utility.
Expand Down
Loading

0 comments on commit 48a703f

Please sign in to comment.