Skip to content

Commit

Permalink
fix #771 Update to FSharp.Compiler.Service 14.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Sep 13, 2017
1 parent e6adc33 commit 1d4e817
Show file tree
Hide file tree
Showing 12 changed files with 144 additions and 77 deletions.
2 changes: 1 addition & 1 deletion paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ group fcs
strategy: min

nuget System.ValueTuple 4.3.0
nuget FSharp.Compiler.Service 13.0.0
nuget FSharp.Compiler.Service ~14.0.2
6 changes: 3 additions & 3 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ RESTRICTION: || (== net45) (== net46)
NUGET
remote: https://api.nuget.org/v3/index.json
AjaxMin (5.14.5506.26202)
FAKE (4.63)
FAKE (4.63.2)
FSharp.Compiler.Tools (4.1.23)
Mono.Cecil (0.10.0-beta6)
System.ValueTuple (4.3)
Expand All @@ -14,8 +14,8 @@ STRATEGY: MIN
RESTRICTION: == net45
NUGET
remote: https://api.nuget.org/v3/index.json
FSharp.Compiler.Service (13.0)
System.Collections.Immutable (>= 1.3.1)
FSharp.Compiler.Service (14.0.2)
System.Collections.Immutable (>= 1.2)
System.Reflection.Metadata (>= 1.4.2)
System.Collections.Immutable (1.3.1)
System.Reflection.Metadata (1.4.2)
Expand Down
21 changes: 13 additions & 8 deletions src/compiler/WebSharper.Compiler.FSharp/CodeReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,11 @@ let getSourcePos (x: FSharpExpr) =
let withSourcePos (x: FSharpExpr) (expr: Expression) =
ExprSourcePos (getSourcePos x, IgnoreExprSourcePos expr)

let getEnclosingEntity (x : FSharpMemberOrFunctionOrValue) =
match x.EnclosingEntity with
| Some e -> e
| None -> failwithf "Enclosing entity not found for %s" x.FullName

type FixCtorTransformer(?thisExpr) =
inherit Transformer()

Expand Down Expand Up @@ -273,7 +278,7 @@ type SymbolReader(comp : WebSharper.Compiler.Compilation) as self =
override this.GetAssemblyName attr = self.ReadSimpleName attr.AttributeType.Assembly
override this.GetName attr = attr.AttributeType.LogicalName
override this.GetCtorArgs attr = attr.ConstructorArguments |> Seq.map snd |> Array.ofSeq
override this.GetTypeDef o = self.ReadTypeDefinition (o :?> FSharpType).TypeDefinition
override this.GetTypeDef o = (self.ReadType Map.empty (o :?> FSharpType) : Type).TypeDefinition
}

member this.ReadSimpleName (a: FSharpAssembly) =
Expand Down Expand Up @@ -322,7 +327,7 @@ type SymbolReader(comp : WebSharper.Compiler.Compilation) as self =
{ Assembly = "mscorlib"; FullName = "System.Double" }
| _ -> res
| _ -> res
|> fun x -> TypeDefinition x
|> fun x -> TypeDefinition x |> comp.FindProxied

member this.ReadTypeSt markStaticTP (tparams: Map<string, int>) (t: FSharpType) =
if t.IsGenericParameter then
Expand Down Expand Up @@ -381,7 +386,7 @@ type SymbolReader(comp : WebSharper.Compiler.Compilation) as self =
| _ ->
GenericType td (t.GenericArguments |> Seq.map (this.ReadTypeSt markStaticTP tparams) |> List.ofSeq)

member this.ReadType tparams t = this.ReadTypeSt false tparams t
member this.ReadType tparams t = (this.ReadTypeSt false tparams t).Normalize()

member this.ReadAbstractSlot tparams (x: FSharpAbstractSignature) : Method =
let tparams =
Expand All @@ -402,7 +407,7 @@ type SymbolReader(comp : WebSharper.Compiler.Compilation) as self =
if name = ".cctor" then Member.StaticConstructor else

let tparams =
Seq.append x.EnclosingEntity.GenericParameters x.GenericParameters
Seq.append (getEnclosingEntity x).GenericParameters x.GenericParameters
|> Seq.distinctBy (fun p -> p.Name)
|> Seq.mapi (fun i p -> p.Name, i) |> Map.ofSeq

Expand Down Expand Up @@ -446,7 +451,7 @@ type SymbolReader(comp : WebSharper.Compiler.Compilation) as self =
MethodName = name
Parameters = getPars()
ReturnType = this.ReadType tparams x.ReturnParameter.Type
Generics = tparams.Count - x.EnclosingEntity.GenericParameters.Count
Generics = tparams.Count - (getEnclosingEntity x).GenericParameters.Count
}
)

Expand Down Expand Up @@ -628,7 +633,7 @@ let rec transformExpression (env: Environment) (expr: FSharpExpr) =
tr body
)
| P.Call(this, meth, typeGenerics, methodGenerics, arguments) ->
let td = sr.ReadAndRegisterTypeDefinition env.Compilation meth.EnclosingEntity
let td = sr.ReadAndRegisterTypeDefinition env.Compilation (getEnclosingEntity meth)
if td.Value.FullName = "Microsoft.FSharp.Core.Operators" && meth.CompiledName = "Reraise" then
IgnoredStatementExpr (Throw (Var env.Exception.Value))
else
Expand Down Expand Up @@ -684,7 +689,7 @@ let rec transformExpression (env: Environment) (expr: FSharpExpr) =
| P.IfThenElse (cond, then_, else_) ->
Conditional(tr cond, tr then_, tr else_)
| P.NewObject (ctor, typeGenerics, arguments) ->
let td = sr.ReadAndRegisterTypeDefinition env.Compilation ctor.EnclosingEntity
let td = sr.ReadAndRegisterTypeDefinition env.Compilation (getEnclosingEntity ctor)
let t = Generic td (typeGenerics |> List.map (sr.ReadType env.TParams))
let args = List.map tr arguments
let args, before =
Expand Down Expand Up @@ -720,7 +725,7 @@ let rec transformExpression (env: Environment) (expr: FSharpExpr) =
IgnoredStatementExpr(While(tr cond, ExprStatement (Capturing().CaptureValueIfNeeded(tr body))))
| P.ValueSet (var, value) ->
if var.IsModuleValueOrMember then
let td = sr.ReadAndRegisterTypeDefinition env.Compilation var.EnclosingEntity
let td = sr.ReadAndRegisterTypeDefinition env.Compilation (getEnclosingEntity var)
match sr.ReadMember var with
| Member.Method (_, m) ->
let me = m.Value
Expand Down
19 changes: 9 additions & 10 deletions src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,13 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) (
let addConstructor (mem: option<FSMFV * Member>) mAnnot (def: Constructor) kind compiled curriedArgs expr =
match proxied, mem with
| Some ms, Some (mem, memdef) ->
// if mem.Accessibility.IsPublic then
if def.Value.CtorParameters.Length > 0 && not (ms.Contains memdef) then
let candidates =
ms |> Seq.choose (function Member.Constructor c -> Some c | _ -> None)
|> Seq.map (fun m -> string m.Value) |> List.ofSeq
if not (mem.Accessibility.IsPrivate || mem.Accessibility.IsInternal) then
let msg = sprintf "Proxy constructor do not match any constructor signatures of target class. Current: %s, candidates: %s" (string def.Value) (String.concat ", " candidates)
comp.AddWarning(Some (CodeReader.getRange mem.DeclarationLocation), SourceWarning msg)
if def.Value.CtorParameters.Length > 0 && not (ms.Contains memdef) then
let candidates =
ms |> Seq.choose (function Member.Constructor c -> Some c | _ -> None)
|> Seq.map (fun m -> string m.Value) |> List.ofSeq
if not (mem.Accessibility.IsPrivate || mem.Accessibility.IsInternal) then
let msg = sprintf "Proxy constructor do not match any constructor signatures of target class. Current: %s, candidates: %s" (string def.Value) (String.concat ", " candidates)
comp.AddWarning(Some (CodeReader.getRange mem.DeclarationLocation), SourceWarning msg)
| _ -> ()
clsMembers.Add (NotResolvedMember.Constructor (def, (getUnresolved mAnnot kind compiled curriedArgs expr)))

Expand Down Expand Up @@ -534,7 +533,7 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) (
| _ -> failwith "impossible"

let addModuleValueProp kind body =
if List.isEmpty args && meth.EnclosingEntity.IsFSharpModule then
if List.isEmpty args && (CodeReader.getEnclosingEntity meth).IsFSharpModule then
let iBody = Call(None, NonGeneric def, Generic mdef (List.init mdef.Value.Generics TypeParameter), [])
// TODO : check proxy targets for module values
addMethod None mAnnot (Method { mdef.Value with MethodName = "get_" + mdef.Value.MethodName }) N.Inline false None iBody
Expand Down Expand Up @@ -1051,7 +1050,7 @@ let transformAssembly (comp : Compilation) assemblyName (checkResults: FSharpChe
else
b |> List.iter (getTypesWithMembers parentMembers)
| FSIFD.MemberOrFunctionOrValue (a, b, c) ->
types.[a.EnclosingEntity].Add(SourceMember(a, b, c))
types.[CodeReader.getEnclosingEntity a].Add(SourceMember(a, b, c))
| FSIFD.InitAction a ->
parentMembers.Add (InitAction a)

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/WebSharper.Compiler/AttributeReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ type AttributeReader<'A>() =
failwithf "Type must be in format \"FullName, AssemblyName\": %s" s
| t ->
try this.GetTypeDef t
with _ -> failwith "Failed to parse type argument of attribute."
with e -> failwithf "Failed to parse type argument of attribute with error %s at %s" e.Message e.StackTrace
let param =
if args.Length = 2 then
Some args.[1]
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/WebSharper.Compiler/Compilation.fs
Original file line number Diff line number Diff line change
Expand Up @@ -331,9 +331,9 @@ type Compilation(meta: Info, ?hasGraph) =
with _ ->
if cls.IsProxy then
if Option.isSome cls.StrongName then
this.AddError(None, SourceError ("Proxy extension can't be strongly named."))
this.AddError(None, SourceError ("Proxy extension can't be strongly named: " + typ.Value.FullName))
elif Option.isSome cls.BaseClass then
this.AddError(None, SourceError ("Proxy extension can't have a non-Object base class."))
this.AddError(None, SourceError ("Proxy extension can't have a non-Object base class: " + typ.Value.FullName))
else
let orig = notResolvedClasses.[typ]
notResolvedClasses.[typ] <-
Expand Down
112 changes: 85 additions & 27 deletions src/compiler/WebSharper.Core/ASTTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,45 @@ type TypeDefinitionInfo =

type TypeDefinition = Hashed<TypeDefinitionInfo>

module Definitions =
let FSharpFunc =
TypeDefinition {
Assembly = "FSharp.Core"
FullName = "Microsoft.FSharp.Core.FSharpFunc`2"
}

let Tuple isStruct (arity: int) =
TypeDefinition {
Assembly = if isStruct then "System.ValueTuple" else "mscorlib"
FullName =
let name = if isStruct then "System.ValueTuple" else "System.Tuple"
if arity = 0 then name else name + "`" + string (min arity 8)
}

let Array =
TypeDefinition {
Assembly = "mscorlib"
FullName = "[]"
}

let Array2 =
TypeDefinition {
Assembly = "mscorlib"
FullName = "[,]"
}

let Unit =
TypeDefinition {
Assembly = "FSharp.Core"
FullName = "Microsoft.FSharp.Core.Unit"
}

let Void =
TypeDefinition {
Assembly = "System.Void"
FullName = "mscorlib"
}

/// Stores a definition and type parameter information
type Concrete<'T> =
{
Expand Down Expand Up @@ -341,7 +380,7 @@ and Type =
name + "8[[" +
String.concat "],[" (ts |> Seq.take 7 |> Seq.map (fun g -> g.AssemblyQualifiedName)) +
getName (l - 7) (ts |> Seq.skip 7 |> List.ofSeq) + "]]"
getName (List.length ts) ts, "mscorlib"
getName (List.length ts) ts, if v then "System.ValueTuple" else "mscorlib"
| FSharpFuncType (a, r) ->
"Microsoft.FSharp.Core.FSharpFunc`2[[" + a.AssemblyQualifiedName + "],[" + r.AssemblyQualifiedName + "]]", "FSharp.Core"
| ByRefType t -> getNameAndAsm t
Expand All @@ -355,11 +394,11 @@ and Type =
| StaticTypeParameter _
| LocalTypeParameter
| TypeParameter _ -> invalidOp "Generic parameter has no TypeDefinition"
| ArrayType _ -> invalidOp "Array type has no TypeDefinition"
| TupleType _ -> invalidOp "Tuple type has no TypeDefinition"
| FSharpFuncType _ -> invalidOp "FSharpFunc type has no TypeDefinition"
| ArrayType _ -> Definitions.Array
| TupleType (ts, isStruct) -> Definitions.Tuple isStruct (List.length ts)
| FSharpFuncType _ -> Definitions.FSharpFunc
| ByRefType t -> t.TypeDefinition
| VoidType -> invalidOp "Void type has no TypeDefinition"
| VoidType -> Definitions.Unit

member this.SubstituteGenerics (gs : Type[]) =
match this with
Expand All @@ -369,9 +408,9 @@ and Type =
| TupleType (ts, v) -> TupleType (ts |> List.map (fun p -> p.SubstituteGenerics gs), v)
| FSharpFuncType (a, r) -> FSharpFuncType (a.SubstituteGenerics gs, r.SubstituteGenerics gs)
| ByRefType t -> ByRefType (t.SubstituteGenerics gs)
| VoidType -> VoidType
| StaticTypeParameter i -> StaticTypeParameter i
| LocalTypeParameter -> LocalTypeParameter
| VoidType
| StaticTypeParameter _
| LocalTypeParameter -> this

member this.SubstituteGenericsToSame(o : Type) =
match this with
Expand All @@ -381,9 +420,9 @@ and Type =
| TupleType (ts, v) -> TupleType (ts |> List.map (fun p -> p.SubstituteGenericsToSame(o)), v)
| FSharpFuncType (a, r) -> FSharpFuncType (a.SubstituteGenericsToSame(o), r.SubstituteGenericsToSame(o))
| ByRefType t -> ByRefType (t.SubstituteGenericsToSame(o))
| VoidType -> VoidType
| StaticTypeParameter i -> StaticTypeParameter i
| LocalTypeParameter -> LocalTypeParameter
| VoidType
| StaticTypeParameter _
| LocalTypeParameter -> this

member this.GetStableHash() =
let inline (++) a b = StableHash.tuple (a, b)
Expand All @@ -407,6 +446,33 @@ and Type =
| StaticTypeParameter i -> 7 ++ i
| LocalTypeParameter -> 8

member this.Normalize() =
match this with
| ConcreteType t ->
let td = t.Entity
if td = Definitions.Void || td = Definitions.Unit then
VoidType
elif td = Definitions.Array then
ArrayType (t.Generics.[0].Normalize(), 1)
elif td = Definitions.Array2 then
ArrayType (t.Generics.[0].Normalize(), 2)
elif td = Definitions.FSharpFunc then
FSharpFuncType (t.Generics.[0].Normalize(), t.Generics.[1].Normalize())
elif td.Value.FullName.StartsWith "System.Tuple`" then // TODO: longer tuples
TupleType(t.Generics |> List.map (fun p -> p.Normalize()), false)
elif td.Value.FullName.StartsWith "System.ValueTuple`" then
TupleType(t.Generics |> List.map (fun p -> p.Normalize()), true)
else
ConcreteType { t with Generics = t.Generics |> List.map (fun p -> p.Normalize()) }
| ArrayType (t, i) -> ArrayType (t.Normalize(), i)
| TupleType (ts, v) -> TupleType (ts |> List.map (fun p -> p.Normalize()), v)
| FSharpFuncType (a, r) -> FSharpFuncType (a.Normalize(), r.Normalize())
| ByRefType t -> ByRefType (t.Normalize())
| TypeParameter _
| VoidType
| StaticTypeParameter _
| LocalTypeParameter -> this

type MethodInfo =
{
MethodName : string
Expand Down Expand Up @@ -482,22 +548,14 @@ module Reflection =

let ReadTypeDefinition (t: System.Type) =
if t.IsArray then
Hashed {
Assembly = "mscorlib"
FullName = "[]"
}
elif FST.IsFunction t then
Hashed {
Assembly = "FSharp.Core"
FullName = "Microsoft.FSharp.Core.FSharpFunc`2"
}
elif FST.IsTuple t then
let name = if t.IsValueType then "System.ValueTuple`" else "System.Tuple`"
let g = t.GetGenericArguments().Length
Hashed {
Assembly = "mscorlib"
FullName = name + string (max g 8)
}
if t.GetArrayRank() = 1 then
Definitions.Array
else
Definitions.Array2
elif FST.IsFunction t then
Definitions.FSharpFunc
elif FST.IsTuple t then
Definitions.Tuple t.IsValueType (t.GetGenericArguments().Length)
else
getTypeDefinitionUnchecked false t

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/WebSharper.FSharp/ErrorPrinting.fs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

module WebSharper.FSharp.ErrorPrinting

open Microsoft.FSharp.Compiler
open Microsoft.FSharp.Compiler.SourceCodeServices
open WebSharper.Core
open WebSharper.Compiler
open WebSharper.Compiler.ErrorPrinting
Expand Down
7 changes: 7 additions & 0 deletions src/compiler/WebSharper.FSharp/WebSharper.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
<Content Include="App.config" />
<None Include="paket.references" />
</ItemGroup>
<Target Name="CopyToOutput" AfterTargets="Build">
<ItemGroup>
<FSharpCoreExtraFiles Include="..\..\..\packages\fsharp4\FSharp.Core\lib\net45\FSharp.Core.sigdata" />
<FSharpCoreExtraFiles Include="..\..\..\packages\fsharp4\FSharp.Core\lib\net45\FSharp.Core.optdata" />
</ItemGroup>
<Copy SourceFiles="@(FSharpCoreExtraFiles)" DestinationFiles="@(FSharpCoreExtraFiles->'..\..\..\build\$(Configuration)\FSharp\%(Filename)%(Extension)')" />
</Target>
<ItemGroup>
<ProjectReference Include="..\WebSharper.Compiler.FSharp\WebSharper.Compiler.FSharp.fsproj">
<Name>WebSharper.Compiler.FSharp</Name>
Expand Down
4 changes: 2 additions & 2 deletions src/stdlib/WebSharper.Main.Proxies/Operators.fs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ let ToFloat (x: 'T) = X<float>
let Floor (x: 'T) = X<'T>

[<Inline "$x[0]">]
let Fst (x: System.Tuple<'T1,'T2>) = X<'T1>
let Fst (x: TupleProxy<'T1,'T2>) = X<'T1>

[<Inline>]
let Hash<'T when 'T : equality> (x: 'T) = Unchecked.hash x
Expand Down Expand Up @@ -311,7 +311,7 @@ let Sin (x: 'T) = X<'T>
let Sinh (x: 'T) = x

[<Inline "$x[1]">]
let Snd (x: System.Tuple<'T1,'T2>) = X<'T2>
let Snd (x: TupleProxy<'T1,'T2>) = X<'T2>

[<Inline "Math.sqrt($x)">]
let Sqrt (x: 'T1) = X<'T2>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@
<Compile Include="../WebSharper.Main.Proxies/NullableOperators.fs">
<Link>NullableOperators.fs</Link>
</Compile>
<Compile Include="../WebSharper.Main.Proxies/Tuple.fs">
<Link>Tuple.fs</Link>
</Compile>
<Compile Include="../WebSharper.Main.Proxies/Operators.fs">
<Link>Operators.fs</Link>
</Compile>
Expand Down Expand Up @@ -226,9 +229,6 @@
<Compile Include="../WebSharper.Main.Proxies/Task.fs">
<Link>Task.fs</Link>
</Compile>
<Compile Include="../WebSharper.Main.Proxies/Tuple.fs">
<Link>Tuple.fs</Link>
</Compile>
<Compile Include="../WebSharper.Main.Proxies/TimeSpan.fs">
<Link>TimeSpan.fs</Link>
</Compile>
Expand Down
Loading

0 comments on commit 1d4e817

Please sign in to comment.