Skip to content

Commit

Permalink
[Rust] Updated support for interface object expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
ncave committed Sep 19, 2024
1 parent b487e2b commit 1905b2a
Show file tree
Hide file tree
Showing 13 changed files with 237 additions and 277 deletions.
101 changes: 44 additions & 57 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,12 @@
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": [
"--",
"src/fable-library-dart",
"--outDir",
"temp/fable-library-dart",
"--fableLib",
"./temp/fable-library-dart",
"--lang",
"dart",
"--exclude",
"Fable.Core",
"--define",
"FABLE_LIBRARY",
"--outDir", "temp/fable-library-dart",
"--fableLib", "./temp/fable-library-dart",
"--exclude", "Fable.Core",
"--define", "FABLE_LIBRARY",
"--lang", "Dart",
"--noCache"
]
},
Expand All @@ -216,21 +210,14 @@
"program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": [
"src/fable-library-ts",
"--outDir",
"temp/fable-library-ts",
"--fableLib",
"./temp/fable-library-ts",
"--lang",
"typescript",
"--exclude",
"Fable.Core",
"--define",
"FABLE_LIBRARY",
"--noCache",
"--typedArrays",
"false",
"--define",
"FX_NO_BIGINT"
"--outDir", "temp/fable-library-ts",
"--fableLib", "./temp/fable-library-ts",
"--exclude", "Fable.Core",
"--define", "FABLE_LIBRARY",
"--define", "FX_NO_BIGINT",
"--typedArrays", "false",
"--lang", "TypeScript",
"--noCache"
]
},
{
Expand All @@ -241,16 +228,11 @@
"program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": [
"src/fable-library-py/fable_library",
"--outDir",
"temp/fable-library-py/fable_library",
"--fableLib",
".",
"--lang",
"python",
"--exclude",
"Fable.Core",
"--define",
"FABLE_LIBRARY",
"--outDir", "temp/fable-library-py/fable_library",
"--fableLib", ".",
"--exclude", "Fable.Core",
"--define", "FABLE_LIBRARY",
"--lang", "Python",
"--noCache"
]
},
Expand All @@ -262,29 +244,34 @@
"program": "${workspaceFolder}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": [
"src/fable-library-rust/src",
"--outDir",
"temp/fable-library-rust/src",
"--fableLib",
".",
"--lang",
"rust",
"--exclude",
"Fable.Core",
"--define",
"FABLE_LIBRARY",
"--noCache"
"--outDir", "temp/fable-library-rust/src",
"--fableLib", ".",
"--exclude", "Fable.Core",
"--define", "FABLE_LIBRARY",
"--lang", "Rust",
"--noCache",
"--noParallelTypeCheck",
"--test:MSBuildCracker"
]
},
{
"name": "Fable.Cli on ../fable-test",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": ["--outDir", "${workspaceRoot}/../fable-test", "--fableLib", "${workspaceRoot}/temp/fable-library-rust", "--exclude", "Fable.Core", "--lang", "Rust", "--noCache", "--noParallelTypeCheck", "--test:MSBuildCracker"],
"cwd": "${workspaceRoot}/../fable-test",
"stopAtEntry": false,
"console": "internalConsole"
"name": "Fable.Cli on ../fable-test",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/Fable.Cli/bin/Debug/net6.0/fable.dll",
"args": [
"--outDir", "${workspaceRoot}/../fable-test",
"--fableLib", "${workspaceRoot}/temp/fable-library-rust",
"--exclude", "Fable.Core",
"--lang", "Rust",
"--noCache",
"--noParallelTypeCheck",
"--test:MSBuildCracker"
],
"cwd": "${workspaceRoot}/../fable-test",
"stopAtEntry": false,
"console": "internalConsole"
}
]
}
}
18 changes: 13 additions & 5 deletions src/Fable.Cli/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -478,20 +478,30 @@ type FableCompilerState =
and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fableProj: Project) =
let agent =
MailboxProcessor<FableCompilerMsg>.Start(fun agent ->
let startInThreadPool toMsg work =
let postTo toMsg work =
async {
try
let! result = work ()
toMsg result |> agent.Post
with e ->
UnexpectedError e |> agent.Post
}
|> Async.Start

let startInThreadPool toMsg work = postTo toMsg work |> Async.Start

let runSynchronously toMsg work =
postTo toMsg work |> Async.RunSynchronously

let fableCompile state fileName =
let fableProj = state.FableProj

startInThreadPool
let runner =
// for Rust, sequential compilation captures all imports and namespaces
match projCracked.CliArgs.CompilerOptions.Language with
| Rust -> runSynchronously // sequential file compilation
| _ -> startInThreadPool // parallel file compilation

runner
FableFileCompiled
(fun () ->
async {
Expand Down Expand Up @@ -574,7 +584,6 @@ and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fabl
// Print F# AST to file
if projCracked.CliArgs.PrintAst then
let outPath = getOutPath projCracked.CliArgs state.PathResolver file.FileName

let outDir = IO.Path.GetDirectoryName(outPath)
Printers.printAst outDir [ file ]

Expand All @@ -586,7 +595,6 @@ and FableCompiler(checker: InteractiveChecker, projCracked: ProjectCracked, fabl
state
else
let state = { state with FableProj = state.FableProj.Update([ file ]) }

fableCompile state fileName

return! loop state
Expand Down
9 changes: 9 additions & 0 deletions src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,8 @@ type FsEnt(maybeAbbrevEnt: FSharpEntity) =
| None -> ent.LogicalName

static member Ref(ent: FSharpEntity) : Fable.EntityRef =
let ent = Helpers.nonAbbreviatedDefinition ent

let path =
match ent.Assembly.FileName with
| Some asmPath ->
Expand Down Expand Up @@ -2711,6 +2713,13 @@ module Util =
)
|> snd

let getInterfaceMembers (com: Compiler) (ent: Fable.Entity) =
ent.AllInterfaces
|> Seq.collect (fun ifc ->
let ifcEnt = com.GetEntity(ifc.Entity)
ifcEnt.MembersFunctionsAndValues |> Seq.map (fun memb -> ifc, memb)
)

let hasInterface fullName (ent: Fable.Entity) =
ent.AllInterfaces |> Seq.exists (fun ifc -> ifc.Entity.FullName = fullName)

Expand Down
10 changes: 9 additions & 1 deletion src/Fable.Transforms/Global/Naming.fs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,16 @@ module Naming =
else
s.Substring(i1 + 1, i2 - i1 - 1)

let splitFirstBy (sep: string) (s: string) =
let i = s.IndexOf(sep, StringComparison.Ordinal)

if i < 0 then
s, ""
else
s.Substring(0, i), s.Substring(i + sep.Length)

let splitLastBy (sep: string) (s: string) =
let i = s.LastIndexOf(sep)
let i = s.LastIndexOf(sep, StringComparison.Ordinal)

if i < 0 then
"", s
Expand Down
Loading

0 comments on commit 1905b2a

Please sign in to comment.