Skip to content

Commit

Permalink
#1366 F# lang updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Jand42 committed Jul 14, 2024
1 parent 481f541 commit 29f78c3
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 21 deletions.
1 change: 1 addition & 0 deletions msbuild/WebSharper.FSharp.Internal.targets
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
<WebSharperConfigFile Condition=" '$(WebSharperConfigFile)' == '' AND Exists('$(MSBuildProjectDirectory)/wsconfig.json') ">$(MSBuildProjectDirectory)/wsconfig.json</WebSharperConfigFile>
<SkipCompilerExecution>True</SkipCompilerExecution>
<ProvideCommandLineArgs>True</ProvideCommandLineArgs>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<NoWarn>$(NoWarn);3366;3370</NoWarn>
</PropertyGroup>
<Target Name="RecompileOnConfigChanges" BeforeTargets="BeforeBuild" Condition=" '$(WebSharperRunCompiler)' == 'True' AND '$(WebSharperConfigFile)' != '' AND Exists('$(WebSharperConfigFile)') ">
Expand Down
38 changes: 18 additions & 20 deletions src/compiler/WebSharper.Compiler.FSharp/ProjectReader.fs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type private N = NotResolvedMemberKind
type private SourceMemberOrEntity =
| SourceMember of FSMFV * list<list<FSMFV>> * FSharpExpr
| SourceEntity of FSharpEntity * ResizeArray<SourceMemberOrEntity>
| SourceInterface of FSharpEntity
| SourceInterface of FSharpEntity * ResizeArray<SourceMemberOrEntity>
| InitAction of FSharpExpr

let annotForTypeOrFile name (annot: A.TypeAnnotation) =
Expand Down Expand Up @@ -84,10 +84,9 @@ let rec private collectTypeAnnotations (d: Dictionary<FSharpEntity, TypeDefiniti
t.Add(thisDef, cls)
for m in members do
match m with
| SourceEntity (ent, nmembers) ->
| SourceEntity (ent, nmembers)
| SourceInterface (ent, nmembers) ->
collectTypeAnnotations d t sr annot ent nmembers
| SourceInterface ent ->
collectTypeAnnotations d t sr annot ent Seq.empty
| _ -> ()

let private getConstraints (genParams: seq<FSharpGenericParameter>) (sr: CodeReader.SymbolReader) tparams =
Expand Down Expand Up @@ -481,7 +480,7 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) (
| _ -> error "Only methods can be defined Remote"
| _ -> ()

if isThisInterface && not isNotWSInterface && clsMembers.Count = 0 then None else
if isThisInterface && not isNotWSInterface && clsMembers.Count = 0 && members.Count = 0 then None else

let fsharpSpecificNonException =
cls.IsFSharpUnion || cls.IsFSharpRecord || cls.IsValueType
Expand Down Expand Up @@ -978,10 +977,10 @@ let rec private transformClass (sc: Lazy<_ * StartupCode>) (comp: Compilation) (
| _ -> error "JavaScript attribute on parameter is only allowed on methods and constructors"
| SourceEntity (ent, nmembers) ->
transformClass sc comp ac sr classAnnots isInterface false recMembers ent nmembers |> Option.iter comp.AddClass
| SourceInterface i ->
| SourceInterface (i, nmembers) ->
let intf, isNotWSInterface = transformInterface sr classAnnots i
intf |> Option.iter comp.AddInterface
transformClass sc comp ac sr classAnnots isInterface isNotWSInterface recMembers i (ResizeArray()) |> Option.iter comp.AddClass
transformClass sc comp ac sr classAnnots isInterface isNotWSInterface recMembers i nmembers |> Option.iter comp.AddClass
| InitAction expr ->
transformInitAction sc comp sr annot recMembers expr

Expand Down Expand Up @@ -1684,7 +1683,13 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co
| FSIFD.Entity (a, b) ->
if not a.IsFSharpAbbreviation then
if a.IsInterface then
parentMembers.Add (SourceInterface a)
let ms = ResizeArray()
parentMembers.Add (SourceInterface (a, ms))
try
types.Add (a, ms)
with _ ->
comp.AddError(Some (CodeReader.getRange a.DeclarationLocation), SourceError "Duplicate type definition")
//b |> List.iter (getTypesWithMembers ms)
elif isILClass a then
let ms = ResizeArray()
parentMembers.Add (SourceEntity (a, ms))
Expand All @@ -1699,14 +1704,7 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co
let m = SourceMember(a, b, c)
match a.DeclaringEntity with
| Some e ->
match types.TryGetValue(e) with
| true, t -> t.Add(m)
| _ ->
// interface might not have type generated for statics
let ms = ResizeArray()
ms.Add(m)
parentMembers.Add (SourceEntity (e, ms))
types.Add (e, ms)
types[e].Add(m)
| _ ->
let i = Id.New(a.LogicalName)
recMembers.Add(a, (i, c))
Expand All @@ -1721,8 +1719,8 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co
match t with
| SourceEntity (c, m) ->
collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot c m
| SourceInterface i ->
collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot i Seq.empty
| SourceInterface (i, m) ->
collectTypeAnnotations classAnnotations typeImplLookup sr rootTypeAnnot i m
| _ -> ()

// register all proxies for signature redirection
Expand All @@ -1737,10 +1735,10 @@ let transformAssembly (logger: LoggerBase) (comp : Compilation) assemblyName (co
| InitAction _ -> failwith "impossible: top level init action"
| SourceEntity (c, m) ->
transformClass sc comp argCurrying sr classAnnotations isInterface false recMembers c m |> Option.iter comp.AddClass
| SourceInterface i ->
| SourceInterface (i, m) ->
let intf, isNotWSInterface = transformInterface sr classAnnotations i
intf |> Option.iter comp.AddInterface
transformClass sc comp argCurrying sr classAnnotations isInterface isNotWSInterface recMembers i [||] |> Option.iter comp.AddClass
transformClass sc comp argCurrying sr classAnnotations isInterface isNotWSInterface recMembers i m |> Option.iter comp.AddClass

let getStartupCodeClass (def: TypeDefinition, sc: StartupCode) =

Expand Down
35 changes: 35 additions & 0 deletions src/stdlib/WebSharper.Main.Proxies/RuntimeHelpers.fs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,41 @@ let EnumerateUsing<'T1,'T2,'T3 when 'T1 :> System.IDisposable
else
false

[<Name "enumTryWith">]
let EnumerateTryWith (s: seq<'T>) (f: exn -> int) (h: exn -> seq<'T>) : seq<'T> =
Enumerable.Of <| fun () ->
let mutable enum = null
let mutable orig = true
Enumerator.NewDisposing () (fun _ -> safeDispose enum) <| fun e ->
try
if enum = null then
enum <- Enumerator.Get s
if enum.MoveNext() then
e.Current <- enum.Current
true
else
false
with err when orig && f err = 1 ->
orig <- false
safeDispose enum
enum <- Enumerator.Get (h err)
if enum.MoveNext() then
e.Current <- enum.Current
true
else
false

[<Name "enumFunc">]
let EnumerateFromFunctions (c: unit -> 'T) (n: 'T -> bool) (v: 'T -> 'U) : seq<'U> =
Enumerable.Of <| fun () ->
let st = c()
Enumerator.New st <| fun e ->
if n st then
e.Current <- v st
true
else
false

[<Name "enumWhile">]
let EnumerateWhile (f: unit -> bool) (s: seq<'T>) : seq<'T> =
Enumerable.Of (fun () ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<WebSharperProject>Library</WebSharperProject>
<DisableImplicitFSharpCoreReference>True</DisableImplicitFSharpCoreReference>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<ProduceReferenceAssembly>False</ProduceReferenceAssembly>
<DebugType>None</DebugType>
</PropertyGroup>
<ItemGroup>
Expand Down

0 comments on commit 29f78c3

Please # to comment.