diff --git a/.editorconfig b/.editorconfig index 8a4e4a33e1..4267c3c5b9 100644 --- a/.editorconfig +++ b/.editorconfig @@ -23,7 +23,6 @@ fsharp_bar_before_discriminated_union_declaration = true fsharp_multiline_bracket_style = aligned fsharp_keep_max_number_of_blank_lines = 2 fsharp_record_multiline_formatter = number_of_items -fsharp_array_or_list_multiline_formatter = number_of_items fsharp_align_function_signature_to_indentation = true fsharp_multi_line_lambda_closing_newline = true fsharp_max_if_then_else_short_width = 0 diff --git a/build_old.fsx b/build_old.fsx index 55526242ee..1179805e2b 100644 --- a/build_old.fsx +++ b/build_old.fsx @@ -224,11 +224,7 @@ let buildLibraryTs () = let buildDirTs = "./build/fable-library-ts" let buildDirJs = "./build/fable-library" - cleanDirs - [ - buildDirTs - buildDirJs - ] + cleanDirs [ buildDirTs; buildDirJs ] runInDir baseDir "npm install" @@ -357,12 +353,7 @@ let buildLibraryDartIfNotExists () = let testStandaloneFast () = runFableWithArgs "src/fable-standalone/src" [ "--noCache" ] - runFableWithArgs - "src/fable-compiler-js/src" - [ - "--exclude Fable.Core" - "--define LOCAL_TEST" - ] + runFableWithArgs "src/fable-compiler-js/src" [ "--exclude Fable.Core"; "--define LOCAL_TEST" ] let fableJs = "./src/fable-compiler-js/src/app.fs.js" let testProj = "tests/Js/Main/Fable.Tests.fsproj" @@ -389,12 +380,7 @@ let buildWorker let fableLib = "./build/fable-library" let distDir = "src/fable-standalone/dist" - runFableWithArgs - (projectDir + "/Worker") - [ - "--outDir " + buildDir + "/worker" - "--fableLib " + fableLib - ] + runFableWithArgs (projectDir + "/Worker") [ "--outDir " + buildDir + "/worker"; "--fableLib " + fableLib ] let rollupTarget = match opts.minify with @@ -457,11 +443,7 @@ let buildStandalone // cleanup if not opts.watch then - cleanDirs - [ - buildDir - distDir - ] + cleanDirs [ buildDir; distDir ] makeDirRecursive distDir @@ -514,21 +496,11 @@ let buildCompilerJs (minify: bool) = watch = false |} - cleanDirs - [ - buildDir - distDir - ] + cleanDirs [ buildDir; distDir ] makeDirRecursive distDir - runFableWithArgs - projectDir - [ - "--outDir " + buildDir - "--fableLib " + fableLib - "--exclude Fable.Core" - ] + runFableWithArgs projectDir [ "--outDir " + buildDir; "--fableLib " + fableLib; "--exclude Fable.Core" ] let rollupTarget = if minify then @@ -584,13 +556,7 @@ let compileAndRunTestsWithMocha clean projectName = if clean then cleanDirs [ buildDir ] - runFableWithArgs - projectDir - [ - "--outDir " + buildDir - "--fableLib " + fableLib - "--exclude Fable.Core" - ] + runFableWithArgs projectDir [ "--outDir " + buildDir; "--fableLib " + fableLib; "--exclude Fable.Core" ] runMocha buildDir @@ -649,11 +615,7 @@ let testTypeScript isWatch = let buildDir2 = "build/tests/TypeScriptCompiled" let fableLib = "fable-library-ts" - cleanDirs - [ - buildDir - buildDir2 - ] + cleanDirs [ buildDir; buildDir2 ] copyFile (projectDir "tsconfig.json") (buildDir "tsconfig.json") @@ -1025,12 +987,7 @@ match BUILD_ARGS_LOWER with let runCmd = $"npx concurrently \"tsc -w -p {srcDir} --outDir {dirname outPath}\" \"nodemon -w {outPath} {outPath}\"" - watchFableWithArgs - srcDir - [ - "--lang ts --watch --exclude Fable.Core --noCache --run" - runCmd - ] + watchFableWithArgs srcDir [ "--lang ts --watch --exclude Fable.Core --noCache --run"; runCmd ] | ("quicktest-py" | "quicktest-python") :: _ -> buildLibraryPyIfNotExists () diff --git a/src/Fable.AST/Fable.fs b/src/Fable.AST/Fable.fs index 7165036b16..4385ef3932 100644 --- a/src/Fable.AST/Fable.fs +++ b/src/Fable.AST/Fable.fs @@ -199,11 +199,7 @@ type Type = | Option(gen, _) | Array(gen, _) | List gen -> [ gen ] - | LambdaType(argType, returnType) -> - [ - argType - returnType - ] + | LambdaType(argType, returnType) -> [ argType; returnType ] | DelegateType(argTypes, returnType) -> argTypes @ [ returnType ] | Tuple(gen, _) -> gen | DeclaredType(_, gen) -> gen diff --git a/src/Fable.Build/Utils.fs b/src/Fable.Build/Utils.fs index e482a76915..145abd7f14 100644 --- a/src/Fable.Build/Utils.fs +++ b/src/Fable.Build/Utils.fs @@ -15,16 +15,7 @@ type Path = /// Resolve a path relative to the repository root /// static member Resolve([] segments: string array) : string = - let paths = - Array.concat - [ - [| - __SOURCE_DIRECTORY__ - ".." - ".." - |] - segments - ] + let paths = Array.concat [ [| __SOURCE_DIRECTORY__; ".."; ".." |]; segments ] // Use GetFullPath to clean the path Path.GetFullPath(Path.Combine(paths)) diff --git a/src/Fable.Build/Utils/ChangelogParser.fs b/src/Fable.Build/Utils/ChangelogParser.fs index 455e7bb197..b6e10c9c80 100644 --- a/src/Fable.Build/Utils/ChangelogParser.fs +++ b/src/Fable.Build/Utils/ChangelogParser.fs @@ -360,12 +360,7 @@ module Transform = let fromSymbols (symbols: Symbols list) = parse symbols Changelog.Empty let parse (changelogContent: string) = - changelogContent.Split( - [| - '\r' - '\n' - |] - ) + changelogContent.Split([| '\r'; '\n' |]) |> Array.toList |> Lexer.toSymbols |> Transform.fromSymbols diff --git a/src/Fable.Cli/BuildalyzerCrackerResolver.fs b/src/Fable.Cli/BuildalyzerCrackerResolver.fs index d476bd25ba..c5eca504c5 100644 --- a/src/Fable.Cli/BuildalyzerCrackerResolver.fs +++ b/src/Fable.Cli/BuildalyzerCrackerResolver.fs @@ -118,14 +118,7 @@ If you see this file in your project, you can delete it safely""" // to their expected state let projDir = IO.Path.GetDirectoryName projectFile - Process.runSync - projDir - "dotnet" - [ - "restore" - projectFile - ] - |> ignore + Process.runSync projDir "dotnet" [ "restore"; projectFile ] |> ignore let compilerArgs, result = csprojResult diff --git a/src/Fable.Cli/Entry.fs b/src/Fable.Cli/Entry.fs index e73800e295..dd02f12fc8 100644 --- a/src/Fable.Cli/Entry.fs +++ b/src/Fable.Cli/Entry.fs @@ -59,35 +59,23 @@ type CliArgs(args: string list) = let knownCliArgs () = [ [ "--cwd" ], [ "Working directory" ] - [ - "-o" - "--outDir" - ], - [ "Redirect compilation output to a directory" ] - [ - "-e" - "--extension" - ], - [ "Extension for generated JS files (default .fs.js)" ] - [ - "-s" - "--sourceMaps" - ], - [ "Enable source maps" ] + [ "-o"; "--outDir" ], [ "Redirect compilation output to a directory" ] + [ "-e"; "--extension" ], [ "Extension for generated JS files (default .fs.js)" ] + [ "-s"; "--sourceMaps" ], [ "Enable source maps" ] [ "--sourceMapsRoot" ], [ "Set the value of the `sourceRoot` property in generated source maps" ] [], [] [ "--define" ], [ "Defines a symbol for use in conditional compilation" ] - [ - "-c" - "--configuration" - ], + [ "-c"; "--configuration" ], [ "The configuration to use when parsing .fsproj with MSBuild," "default is 'Debug' in watch mode, or 'Release' otherwise" ] [ "--verbose" ], [ "Print more info during compilation" ] [ "--silent" ], [ "Don't print any log during compilation" ] - [ "--typedArrays" ], [ "Compile numeric arrays as JS typed arrays (default is true for JS, false for TS)" ] + [ "--typedArrays" ], + [ + "Compile numeric arrays as JS typed arrays (default is true for JS, false for TS)" + ] [ "--watch" ], [ "Alias of watch command" ] [ "--watchDelay" ], [ "Delay in ms before recompiling after a file changes (default 200)" ] [], [] @@ -110,10 +98,7 @@ let knownCliArgs () = ] [], [] [ "--optimize" ], [ "Compile with optimized F# AST (experimental)" ] - [ - "--lang" - "--language" - ], + [ "--lang"; "--language" ], [ "Choose wich languages to compile to" "" @@ -150,11 +135,7 @@ let printKnownCliArgs () = match desc with | [] -> [] // Args without description are hidden - | desc :: extraLines -> - [ - $" %-18s{args}{desc}" - yield! extraLines |> List.map (sprintf "%20s%s" "") - ] + | desc :: extraLines -> [ $" %-18s{args}{desc}"; yield! extraLines |> List.map (sprintf "%20s%s" "") ] ) let sanitizeCliArgs (args: CliArgs) = @@ -297,11 +278,7 @@ type Runner = | _ -> Ok() do! - let reservedDirs = - [ - Naming.fableModules - "obj" - ] + let reservedDirs = [ Naming.fableModules; "obj" ] let outDirLast = outDir @@ -420,13 +397,7 @@ type Runner = } let clean (args: CliArgs) language rootDir = - let ignoreDirs = - set - [ - "bin" - "obj" - "node_modules" - ] + let ignoreDirs = set [ "bin"; "obj"; "node_modules" ] let outDir = args.Value("-o", "--outDir") diff --git a/src/Fable.Cli/Main.fs b/src/Fable.Cli/Main.fs index d4f239e6d2..b209a24441 100644 --- a/src/Fable.Cli/Main.fs +++ b/src/Fable.Cli/Main.fs @@ -138,18 +138,8 @@ module private Util = let modules = absPath .Substring(outDir.Length, absPath.Length - outDir.Length - fileName.Length) - .Trim( - [| - '/' - '\\' - |] - ) - .Split( - [| - '/' - '\\' - |] - ) + .Trim([| '/'; '\\' |]) + .Split([| '/'; '\\' |]) let modules = match Array.toList modules, cliArgs.FableLibraryPath with @@ -276,13 +266,7 @@ open FileWatcher open FileWatcherUtil type FsWatcher(delayMs: int) = - let globFilters = - [ - "*.fs" - "*.fsi" - "*.fsx" - "*.fsproj" - ] + let globFilters = [ "*.fs"; "*.fsi"; "*.fsx"; "*.fsproj" ] let createWatcher () = let usePolling = @@ -298,12 +282,7 @@ type FsWatcher(delayMs: int) = Log.always ("Using polling watcher.") // Ignored for performance reasons: let ignoredDirectoryNameRegexes = - [ - "(?i)node_modules" - "(?i)bin" - "(?i)obj" - "\..+" - ] + [ "(?i)node_modules"; "(?i)bin"; "(?i)obj"; "\..+" ] upcast new ResetablePollingFileWatcher(globFilters, ignoredDirectoryNameRegexes) else diff --git a/src/Fable.Compiler/Globbing.fs b/src/Fable.Compiler/Globbing.fs index 4bb1919d02..2b9e1cb2c2 100644 --- a/src/Fable.Compiler/Globbing.fs +++ b/src/Fable.Compiler/Globbing.fs @@ -106,13 +106,7 @@ module Glob = let normPattern = normalizePath pattern let patternParts = - normPattern.Split( - [| - '/' - '\\' - |], - StringSplitOptions.RemoveEmptyEntries - ) + normPattern.Split([| '/'; '\\' |], StringSplitOptions.RemoveEmptyEntries) let patternPathParts = patternParts |> Seq.takeWhile (fun p -> not (p.Contains("*"))) |> Seq.toArray @@ -158,14 +152,7 @@ module Glob = let filePattern = Path.GetFileName(input) - let splits = - input.Split( - [| - '/' - '\\' - |], - StringSplitOptions.None - ) + let splits = input.Split([| '/'; '\\' |], StringSplitOptions.None) let baseItems = let start, rest = diff --git a/src/Fable.Compiler/ProjectCracker.fs b/src/Fable.Compiler/ProjectCracker.fs index 70dc307369..634523bf1b 100644 --- a/src/Fable.Compiler/ProjectCracker.fs +++ b/src/Fable.Compiler/ProjectCracker.fs @@ -138,14 +138,7 @@ type CrackerOptions(cliArgs: CliArgs, evaluateOnly: bool) = |> Array.rev |> String.concat "/" - Process.runSync - projDir - "dotnet" - [ - "build" - "-c" - cliArgs.Configuration - ] + Process.runSync projDir "dotnet" [ "build"; "-c"; cliArgs.Configuration ] |> ignore builtDlls.Add(normalizedDllPath) |> ignore @@ -684,11 +677,7 @@ let getFableLibraryPath (opts: CrackerOptions) = baseDir |> File.tryFindNonEmptyDirectoryUpwards {| - matches = - [ - buildDir - "temp/" + buildDir - ] + matches = [ buildDir; "temp/" + buildDir ] exclude = [ "src" ] |} |> Option.defaultWith (fun () -> @@ -840,10 +829,7 @@ let getFullProjectOpts (resolver: ProjectCrackerResolver) (opts: CrackerOptions) cacheInfo.Version = Literals.VERSION && cacheInfo.Exclude = opts.Exclude && cacheInfo.FableOptions.Language = opts.FableOptions.Language - && ([ - cacheInfo.ProjectPath - yield! cacheInfo.References - ] + && ([ cacheInfo.ProjectPath; yield! cacheInfo.References ] |> List.forall (fun fsproj -> if IO.File.Exists(fsproj) && isOlderThanCache fsproj then // Check if the project uses Paket diff --git a/src/Fable.PublishUtils/PublishUtils.fs b/src/Fable.PublishUtils/PublishUtils.fs index 5ff43b3071..5ff881826b 100644 --- a/src/Fable.PublishUtils/PublishUtils.fs +++ b/src/Fable.PublishUtils/PublishUtils.fs @@ -504,11 +504,7 @@ module Publish = buildAction () let projDir = dirname projFile // Restore dependencies here so they're updated to latest project versions - runList - [ - "dotnet restore" - projDir - ] + runList [ "dotnet restore"; projDir ] // Update the project file readFile projFile |> replaceRegex @@ -548,13 +544,7 @@ module Publish = let nupkg = findFileWithExt tempDir ".nupkg" - runList - [ - "dotnet nuget push" - nupkg - "-s nuget.org -k" - nugetInfo.ApiKey - ] + runList [ "dotnet nuget push"; nupkg; "-s nuget.org -k"; nugetInfo.ApiKey ] // Looks like the `nuget push` command automatically detects the .snupkg symbols // We issue the command below just in case but with --skip-duplicate to prevent errors diff --git a/src/Fable.Transforms/Dart/Fable2Dart.fs b/src/Fable.Transforms/Dart/Fable2Dart.fs index f98984b2d8..500bb583dc 100644 --- a/src/Fable.Transforms/Dart/Fable2Dart.fs +++ b/src/Fable.Transforms/Dart/Fable2Dart.fs @@ -207,13 +207,7 @@ module Util = Type.reference (makeImmutableIdent MetaType "Iterator", [ genArg ]) let makeMapEntry key value = - Type.reference ( - makeImmutableIdent MetaType "MapEntry", - [ - key - value - ] - ) + Type.reference (makeImmutableIdent MetaType "MapEntry", [ key; value ]) match entRef.FullName, genArgs with | Types.enum_, _ -> Integer @@ -601,12 +595,7 @@ module Util = statements @ statements2, capturedExpr let transformExprsAndResolve2 com ctx returnStrategy expr0 expr1 transformExprs = - List.map - (transform com ctx (Capture(binding = None))) - [ - expr0 - expr1 - ] + List.map (transform com ctx (Capture(binding = None))) [ expr0; expr1 ] |> combineCapturedExprs com ctx |> fun (statements, exprs) -> let statements2, capturedExpr = @@ -803,10 +792,7 @@ module Util = let regexIdent = makeImmutableIdent MetaType "RegExp" let args = - [ - None, Expression.stringLiteral source - yield! flags |> List.choose flagToArg - ] + [ None, Expression.stringLiteral source; yield! flags |> List.choose flagToArg ] Expression.invocationExpression (regexIdent.Expr, args, Type.reference regexIdent) |> resolveExpr returnStrategy @@ -947,10 +933,7 @@ module Util = com ctx returnStrategy - [ - head - tail - ] + [ head; tail ] (fun exprs -> libCall com ctx (Fable.List typ) "List" "cons" exprs) | exprs, Some tail -> @@ -962,10 +945,7 @@ module Util = (fun exprs -> let exprs, tail = List.splitLast exprs - [ - makeImmutableListExpr com ctx typ exprs - tail - ] + [ makeImmutableListExpr com ctx typ exprs; tail ] |> libCall com ctx (Fable.List typ) "List" "ofArrayWithTail" ) @@ -1206,7 +1186,9 @@ module Util = let statements, _ = transform com ctx returnStrategy body prevStatements - @ [ Statement.tryStatement (statements, handlers = handlers, ?finalizer = finalizer) ], + @ [ + Statement.tryStatement (statements, handlers = handlers, ?finalizer = finalizer) + ], captureExpr /// Branching expressions like conditionals, decision trees or try catch cannot capture @@ -1499,7 +1481,9 @@ module Util = | _ -> varDecls @ body args', - [ Statement.labeledStatement (tc.Label, Statement.whileStatement (Expression.booleanLiteral (true), body)) ], + [ + Statement.labeledStatement (tc.Label, Statement.whileStatement (Expression.booleanLiteral (true), body)) + ], returnType | _ -> args |> List.map (transformIdent com ctx), body, returnType @@ -1565,7 +1549,9 @@ module Util = // If value is an anonymous function this will be converted into function declaration in printing step ctx, valueStatements - @ [ Statement.variableDeclaration (ident, kind, value = value, addToScope = ctx.AddToScope) ] + @ [ + Statement.variableDeclaration (ident, kind, value = value, addToScope = ctx.AddToScope) + ] let transformSwitch (com: IDartCompiler) ctx returnStrategy evalExpr cases defaultCase = let cases = @@ -2167,10 +2153,7 @@ module Util = combineStatementsAndExprs com ctx - [ - transformAndCaptureExpr com ctx start - transformAndCaptureExpr com ctx limit - ] + [ transformAndCaptureExpr com ctx start; transformAndCaptureExpr com ctx limit ] let body, _ = transform com ctx Ignore body let param = transformIdent com ctx var @@ -2422,7 +2405,9 @@ module Util = |> Seq.filter (fun memb -> not memb.IsProperty) |> Seq.mapToList (transformAbstractMember com ctx) - [ Declaration.classDeclaration (decl.Name, genParams = genParams, methods = methods, isAbstract = true) ] + [ + Declaration.classDeclaration (decl.Name, genParams = genParams, methods = methods, isAbstract = true) + ] // Mirrors Dart.Replacements.equals let equals com ctx (left: Expression) (right: Expression) = @@ -2431,10 +2416,7 @@ module Util = let y = makeImmutableIdent t "y" Expression.anonymousFunction ( - [ - x - y - ], + [ x; y ], [ equals com ctx x.Expr y.Expr |> Statement.returnStatement ], Integer ) @@ -2443,29 +2425,9 @@ module Util = | List t -> let fn = makeEqualsFunction t - libCall - com - ctx - Fable.Boolean - "Util" - "equalsList" - [ - left - right - fn - ] + libCall com ctx Fable.Boolean "Util" "equalsList" [ left; right; fn ] | Dynamic - | Generic _ -> - libCall - com - ctx - Fable.Boolean - "Util" - "equalsDynamic" - [ - left - right - ] + | Generic _ -> libCall com ctx Fable.Boolean "Util" "equalsDynamic" [ left; right ] | _ -> Expression.binaryExpression (BinaryEqual, left, right, Boolean) // Mirrors Dart.Replacements.compare @@ -2475,10 +2437,7 @@ module Util = let y = makeImmutableIdent t "y" Expression.anonymousFunction ( - [ - x - y - ], + [ x; y ], [ compare com ctx x.Expr y.Expr |> Statement.returnStatement ], Integer ) @@ -2487,54 +2446,14 @@ module Util = | List t -> let fn = makeComparerFunction t - libCall - com - ctx - (numType Int32) - "Util" - "compareList" - [ - left - right - fn - ] + libCall com ctx (numType Int32) "Util" "compareList" [ left; right; fn ] | Nullable t -> let fn = makeComparerFunction t - libCall - com - ctx - (numType Int32) - "Util" - "compareNullable" - [ - left - right - fn - ] - | Boolean -> - libCall - com - ctx - (numType Int32) - "Util" - "compareBool" - [ - left - right - ] + libCall com ctx (numType Int32) "Util" "compareNullable" [ left; right; fn ] + | Boolean -> libCall com ctx (numType Int32) "Util" "compareBool" [ left; right ] | Dynamic - | Generic _ -> - libCall - com - ctx - (numType Int32) - "Util" - "compareDynamic" - [ - left - right - ] + | Generic _ -> libCall com ctx (numType Int32) "Util" "compareDynamic" [ left; right ] | _ -> Expression.invocationExpression (left, "compareTo", [ right ], Integer) let makeStructuralEquals @@ -2739,11 +2658,7 @@ module Util = let extends = transformInheritedClass com ctx ent interfaceInfo.implementsEnumerable None - let implements = - [ - libTypeRef com ctx "Types" "Union" [] - yield! interfaces - ] + let implements = [ libTypeRef com ctx "Types" "Union" []; yield! interfaces ] let extraMethods = if not hasCasesWithoutFields then @@ -2785,11 +2700,7 @@ module Util = let extends = transformInheritedClass com ctx ent interfaceInfo.implementsEnumerable None - let implements = - [ - libTypeRef com ctx "Types" "Record" [] - yield! interfaces - ] + let implements = [ libTypeRef com ctx "Types" "Record" []; yield! interfaces ] let hasMutableFields = ent.FSharpFields |> List.exists (fun f -> f.IsMutable) diff --git a/src/Fable.Transforms/Dart/Replacements.fs b/src/Fable.Transforms/Dart/Replacements.fs index 90718e7e7d..10cc67003b 100644 --- a/src/Fable.Transforms/Dart/Replacements.fs +++ b/src/Fable.Transforms/Dart/Replacements.fs @@ -55,11 +55,7 @@ let makeLongInt com r t signed (x: uint64) = let unsigned = BoolConstant(not signed) let args = - [ - makeValue None lowBits - makeValue None highBits - makeValue None unsigned - ] + [ makeValue None lowBits; makeValue None highBits; makeValue None unsigned ] Helper.LibCall(com, "Long", "fromBits", t, args, ?loc = r) @@ -445,32 +441,11 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) = | _ -> let fn = makeEqualityFunction com ctx t - Helper.LibCall( - com, - "Util", - "equalsList", - Boolean, - [ - left - right - fn - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equalsList", Boolean, [ left; right; fn ], ?loc = r) |> is equal | Any | GenericParam _ -> - Helper.LibCall( - com, - "Util", - "equalsDynamic", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equalsDynamic", Boolean, [ left; right ], ?loc = r) |> is equal | _ -> if equal then @@ -487,58 +462,14 @@ and compare (com: ICompiler) ctx r (left: Expr) (right: Expr) = | Array(t, _) -> let fn = makeComparerFunction com ctx t - Helper.LibCall( - com, - "Util", - "compareList", - t, - [ - left - right - fn - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "compareList", t, [ left; right; fn ], ?loc = r) | Option(t, _) -> let fn = makeComparerFunction com ctx t - Helper.LibCall( - com, - "Util", - "compareNullable", - t, - [ - left - right - fn - ], - ?loc = r - ) - | Boolean -> - Helper.LibCall( - com, - "Util", - "compareBool", - t, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "compareNullable", t, [ left; right; fn ], ?loc = r) + | Boolean -> Helper.LibCall(com, "Util", "compareBool", t, [ left; right ], ?loc = r) | Any - | GenericParam _ -> - Helper.LibCall( - com, - "Util", - "compareDynamic", - t, - [ - left - right - ], - ?loc = r - ) + | GenericParam _ -> Helper.LibCall(com, "Util", "compareDynamic", t, [ left; right ], ?loc = r) | _ -> Helper.InstanceCall(left, "compareTo", t, [ right ], ?loc = r) /// Boolean comparison operators like <, >, <=, >= @@ -554,15 +485,7 @@ and makeComparerFunction (com: ICompiler) ctx typArg = let y = makeTypedIdent typArg "y" let body = compare com ctx None (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) and makeComparer (com: ICompiler) ctx typArg = Helper.LibCall(com, "Types", "Comparer", Any, [ makeComparerFunction com ctx typArg ]) @@ -572,15 +495,7 @@ and makeEqualityFunction (com: ICompiler) ctx typArg = let y = makeTypedIdent typArg "y" let body = equals com ctx None true (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) let makeEqualityComparer (com: ICompiler) ctx typArg = let x = makeTypedIdent typArg "x" @@ -592,15 +507,7 @@ let makeEqualityComparer (com: ICompiler) ctx typArg = "EqualityComparer", Any, [ - Delegate( - [ - x - y - ], - equals com ctx None true (IdentExpr x) (IdentExpr y), - None, - Tags.empty - ) + Delegate([ x; y ], equals com ctx None true (IdentExpr x) (IdentExpr y), None, Tags.empty) Delegate([ x ], structuralHash com None (IdentExpr x), None, Tags.empty) ] ) @@ -645,11 +552,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | Builtin BclGuid -> emptyGuid () | Builtin(FSharpSet genArg) as t -> makeSet com ctx None t "Empty" [] [ genArg ] | Builtin(BclKeyValuePair(k, v)) -> - let args = - [ - getZero com ctx k - getZero com ctx v - ] + let args = [ getZero com ctx k; getZero com ctx v ] Helper.ConstructorCall(makeIdentExpr "MapEntry", t, args) | ListSingleton(CustomOp com ctx None t "get_Zero" [] e) -> e @@ -668,27 +571,9 @@ let makeAddFunction (com: ICompiler) ctx t = let x = makeTypedIdent t "x" let y = makeTypedIdent t "y" - let body = - applyOp - com - ctx - None - t - Operators.addition - [ - IdentExpr x - IdentExpr y - ] - - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.addition [ IdentExpr x; IdentExpr y ] + + Delegate([ x; y ], body, None, Tags.empty) let makeGenericAdder (com: ICompiler) ctx t = Helper.LibCall( @@ -696,10 +581,7 @@ let makeGenericAdder (com: ICompiler) ctx t = "Types", "GenericAdder", Any, - [ - getZero com ctx t |> makeDelegate [] - makeAddFunction com ctx t - ] + [ getZero com ctx t |> makeDelegate []; makeAddFunction com ctx t ] ) let makeGenericAverager (com: ICompiler) ctx t = @@ -707,38 +589,16 @@ let makeGenericAverager (com: ICompiler) ctx t = let x = makeTypedIdent t "x" let i = makeTypedIdent Int32.Number "i" - let body = - applyOp - com - ctx - None - t - Operators.divideByInt - [ - IdentExpr x - IdentExpr i - ] - - Delegate( - [ - x - i - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.divideByInt [ IdentExpr x; IdentExpr i ] + + Delegate([ x; i ], body, None, Tags.empty) Helper.LibCall( com, "Types", "GenericAverager", Any, - [ - getZero com ctx t |> makeDelegate [] - makeAddFunction com ctx t - divideFn - ] + [ getZero com ctx t |> makeDelegate []; makeAddFunction com ctx t; divideFn ] ) let injectArg (com: ICompiler) (ctx: Context) r moduleName methName (genArgs: Type list) args = @@ -918,14 +778,7 @@ let makeRefFromMutableValue com ctx r t (value: Expr) = Delegate([ v ], Set(value, ValueSet, t, IdentExpr v, None), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let makeRefFromMutableField com ctx r t callee key = let getter = @@ -936,14 +789,7 @@ let makeRefFromMutableField com ctx r t callee key = Delegate([ v ], Set(callee, FieldSet(key), t, IdentExpr v, r), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] // Not sure if this is needed in Dart, see comment in JS.Replacements.makeRefFromMutableFunc let makeRefFromMutableFunc com ctx r t (value: Expr) = @@ -955,32 +801,14 @@ let makeRefFromMutableFunc com ctx r t (value: Expr) = let setter = let v = makeUniqueIdent ctx t "v" - let args = - [ - IdentExpr v - makeBoolConst true - ] + let args = [ IdentExpr v; makeBoolConst true ] - let info = - makeCallInfo - None - args - [ - t - Boolean - ] + let info = makeCallInfo None args [ t; Boolean ] let value = makeCall r Unit info value Delegate([ v ], value, None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let refCells (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Expr list) = match i.CompiledName, thisArg, args with @@ -1102,29 +930,10 @@ let fsFormat (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op _, _ -> fsharpModule com ctx r t i thisArg args | ".ctor", _, str :: (Value(NewArray(ArrayValues templateArgs, _, MutableArray), _) as values) :: _ -> - match - makeStringTemplateFrom - [| - "%s" - "%i" - |] - templateArgs - str - with + match makeStringTemplateFrom [| "%s"; "%i" |] templateArgs str with | Some v -> makeValue r v |> Some | None -> - Helper.LibCall( - com, - "String", - "interpolate", - t, - [ - str - values - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "String", "interpolate", t, [ str; values ], i.SignatureArgTypes, ?loc = r) |> Some | ".ctor", _, arg :: _ -> Helper.LibCall(com, "String", "printf", t, [ arg ], i.SignatureArgTypes, ?loc = r) @@ -1138,17 +947,7 @@ let defaultValue com ctx r t defValue option = | Some value -> Some value | None -> Some defValue | _ -> - Helper.LibCall( - com, - "Option", - "defaultValue", - t, - [ - defValue - option - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultValue", t, [ defValue; option ], ?loc = r) |> Some let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Expr list) = @@ -1187,12 +986,7 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o let addStep args = match args with - | [ first; last ] -> - [ - first - getOne com ctx genArg - last - ] + | [ first; last ] -> [ first; getOne com ctx genArg; last ] | _ -> args let modul, meth, args = @@ -1208,28 +1002,9 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o | "op_PipeRight", [ x; f ] | "op_PipeLeft", [ f; x ] -> curriedApply r t f [ x ] |> Some | "op_PipeRight2", [ x; y; f ] - | "op_PipeLeft2", [ f; x; y ] -> - curriedApply - r - t - f - [ - x - y - ] - |> Some + | "op_PipeLeft2", [ f; x; y ] -> curriedApply r t f [ x; y ] |> Some | "op_PipeRight3", [ x; y; z; f ] - | "op_PipeLeft3", [ f; x; y; z ] -> - curriedApply - r - t - f - [ - x - y - z - ] - |> Some + | "op_PipeLeft3", [ f; x; y; z ] -> curriedApply r t f [ x; y; z ] |> Some | "op_ComposeRight", [ f1; f2 ] -> compose com ctx r t f1 f2 |> Some | "op_ComposeLeft", [ f2; f1 ] -> compose com ctx r t f1 f2 |> Some // Strings @@ -1539,10 +1314,7 @@ let getEnumerator (_com: ICompiler) r t expr = getFieldWith r t expr "iterator" let toStartEndIndices startIndex count = let endIndex = makeBinOp None Int32.Number startIndex count BinaryPlus - [ - startIndex - endIndex - ] + [ startIndex; endIndex ] let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Expr list) = match i.CompiledName, thisArg, args with @@ -1553,18 +1325,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | [ char; count ] -> // String(char, int) let str = Helper.GlobalCall("String", t, [ char ], memb = "fromCharCode") - Helper.LibCall( - com, - "String", - "replicate", - t, - [ - count - str - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "String", "replicate", t, [ count; str ], ?loc = r) |> Some | _ -> "Unexpected arguments in System.String constructor." |> addErrorAndReturnNull com ctx.InlinePath r @@ -1605,17 +1366,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | "Equals", Some x, [ y; kind ] | "Equals", None, [ x; y; kind ] -> let left = - Helper.LibCall( - com, - "String", - "compareWith", - Int32.Number, - [ - x - y - kind - ] - ) + Helper.LibCall(com, "String", "compareWith", Int32.Number, [ x; y; kind ]) makeEqOp r left (makeIntConst 0) BinaryEqual |> Some | "GetEnumerator", Some c, _ -> stringToCharSeq c |> getEnumerator com r t |> Some @@ -1704,12 +1455,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt let args = match restArgs with - | [ ExprType(Number(_, NumberInfo.IsEnum _)) as options ] -> - [ - arg1 - Value(Null Any, None) - options - ] + | [ ExprType(Number(_, NumberInfo.IsEnum _)) as options ] -> [ arg1; Value(Null Any, None); options ] | _ -> arg1 :: restArgs Helper.LibCall(com, "String", meth, t, args, ?thisArg = thisArg, ?loc = r) @@ -1734,19 +1480,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt Helper.InstanceCall(arg, "join", t, [ makeStrConst "" ], ?loc = r) |> Some | "CompareOrdinal", None, [ x; y ] - | "CompareTo", Some x, [ y ] -> - Helper.LibCall( - com, - "String", - "compare", - t, - [ - x - y - ], - ?loc = r - ) - |> Some + | "CompareTo", Some x, [ y ] -> Helper.LibCall(com, "String", "compare", t, [ x; y ], ?loc = r) |> Some | "Compare", None, args -> let meth = match args with @@ -1877,10 +1611,7 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg "Event", "createEvent", t, - [ - addHandler - removeHandler - ], + [ addHandler; removeHandler ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r @@ -1926,18 +1657,7 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | "Clear", Some ar, [] -> Helper.InstanceCall(ar, "clear", t, [], ?loc = r) |> Some | "Remove", Some ar, [ arg ] -> Helper.InstanceCall(ar, "remove", t, [ arg ], ?loc = r) |> Some | "RemoveAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "removeAllInPlace", - t, - [ - arg - ar - ], - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.LibCall(com, "Array", "removeAllInPlace", t, [ arg; ar ], genArgs = i.GenericArgs, ?loc = r) |> Some | "FindIndex", Some ar, [ arg ] -> Helper.InstanceCall(ar, "indexWhere", t, [ arg ], ?loc = r) |> Some | "FindLastIndex", Some ar, [ arg ] -> Helper.InstanceCall(ar, "lastIndexWhere", t, [ arg ], ?loc = r) |> Some @@ -1945,19 +1665,7 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | "GetEnumerator", Some ar, _ -> getEnumerator com r t ar |> Some // ICollection members, implemented in dictionaries and sets too. | "get_Count", Some ar, _ -> getLength ar |> Some - | "ConvertAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + | "ConvertAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "map", t, [ arg; ar ], ?loc = r) |> Some | "Exists", Some ar, [ arg ] -> Helper.InstanceCall(ar, "any", t, [ arg ], ?loc = r) |> Some | "Contains", Some ar, [ arg ] -> Helper.InstanceCall(ar, "contains", t, [ arg ], ?loc = r) |> Some // Find/FindLast don't work because we cannot provide a default value for ref types with null safety in Dart @@ -1968,73 +1676,17 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this // let opt = Helper.LibCall(com, "Array", "tryFindBack", t, [arg; ar], ?loc=r) // Helper.LibCall(com, "Option", "defaultArg", t, [opt; defaultof com ctx r t], ?loc=r) |> Some | "FindAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "filter", - t, - [ - arg - ar - ], - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.LibCall(com, "Array", "filter", t, [ arg; ar ], genArgs = i.GenericArgs, ?loc = r) |> Some | "AddRange", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], genArgs = i.GenericArgs, ?loc = r) |> Some | "GetRange", Some ar, [ idx; cnt ] -> - Helper.LibCall( - com, - "Array", - "getSubArray", - t, - [ - ar - idx - cnt - ], - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.LibCall(com, "Array", "getSubArray", t, [ ar; idx; cnt ], genArgs = i.GenericArgs, ?loc = r) |> Some | "IndexOf", Some ar, args -> Helper.InstanceCall(ar, "indexOf", t, args, ?loc = r) |> Some - | "Insert", Some ar, [ idx; arg ] -> - Helper.InstanceCall( - ar, - "insert", - t, - [ - idx - arg - ], - ?loc = r - ) - |> Some - | "InsertRange", Some ar, [ idx; arg ] -> - Helper.InstanceCall( - ar, - "insertAll", - t, - [ - idx - arg - ], - ?loc = r - ) - |> Some + | "Insert", Some ar, [ idx; arg ] -> Helper.InstanceCall(ar, "insert", t, [ idx; arg ], ?loc = r) |> Some + | "InsertRange", Some ar, [ idx; arg ] -> Helper.InstanceCall(ar, "insertAll", t, [ idx; arg ], ?loc = r) |> Some | "RemoveRange", Some ar, [ startIdx; count ] -> Helper.InstanceCall(ar, "removeRange", t, toStartEndIndices startIdx count, ?loc = r) |> Some @@ -2046,18 +1698,7 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this Helper.InstanceCall(ar, "sort", t, [ compareFn ], ?loc = r) |> Some | "Sort", Some ar, [ ExprType(DelegateType _) ] -> Helper.InstanceCall(ar, "sort", t, args, ?loc = r) |> Some | "Sort", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "sortInPlace", - t, - [ - ar - arg - ], - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.LibCall(com, "Array", "sortInPlace", t, [ ar; arg ], genArgs = i.GenericArgs, ?loc = r) |> Some | "ToArray", Some ar, [] -> Helper.InstanceCall(ar, "sublist", t, [ makeIntConst 0 ], ?loc = r) |> Some | _ -> None @@ -2073,31 +1714,9 @@ let collectionExtensions = match i.CompiledName, thisArg, args with | "AddRange", None, [ ar; arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - genArgs = i.GenericArgs, - ?loc = r - ) - |> Some - | "InsertRange", None, [ ar; idx; arg ] -> - Helper.InstanceCall( - ar, - "insertAll", - t, - [ - idx - arg - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], genArgs = i.GenericArgs, ?loc = r) |> Some + | "InsertRange", None, [ ar; idx; arg ] -> Helper.InstanceCall(ar, "insertAll", t, [ idx; arg ], ?loc = r) |> Some | _ -> None let readOnlySpans (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: Expr option) (args: Expr list) = @@ -2142,31 +1761,9 @@ let arrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: E | "set_Item", Some arg, [ idx; value ] -> setExpr r arg idx value |> Some | "Copy", None, [ _source; _sourceIndex; _target; _targetIndex; _count ] -> copyToArray com r t i args | "Copy", None, [ source; target; count ] -> - copyToArray - com - r - t - i - [ - source - makeIntConst 0 - target - makeIntConst 0 - count - ] + copyToArray com r t i [ source; makeIntConst 0; target; makeIntConst 0; count ] | "ConvertAll", None, [ source; mapping ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - mapping - source - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "map", t, [ mapping; source ], ?loc = r) |> Some | "IndexOf", None, args -> Helper.LibCall(com, "Array", "indexOf", t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) |> Some @@ -2190,16 +1787,7 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex | "ZeroCreate", [ count ] -> let defValue = genArg com ctx r 0 i.GenericArgs |> getZero com ctx - Helper.GlobalCall( - "List", - t, - [ - count - defValue - ], - memb = "filled", - ?loc = r - ) + Helper.GlobalCall("List", t, [ count; defValue ], memb = "filled", ?loc = r) |> Some | "Create", _ -> Helper.GlobalCall("List", t, args, memb = "filled", ?loc = r) |> Some | "Singleton", [ value ] -> @@ -2438,12 +2026,7 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op if isFloatOrDecimal then [ str ] @ outValue else - [ - str - makeIntConst style - makeBoolConst unsigned - makeIntConst bitsize - ] + [ str; makeIntConst style; makeBoolConst unsigned; makeIntConst bitsize ] @ outValue Helper.LibCall(com, numberModule, Naming.lowerFirst meth, t, args, ?loc = r) @@ -2531,14 +2114,8 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op "String", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -2614,14 +2191,8 @@ let decimals (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: "String", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -2732,18 +2303,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr | ("GenericComparison" | "GenericComparisonIntrinsic"), [ left; right ] -> compare com ctx r left right |> Some | ("FastCompareTuple2" | "FastCompareTuple3" | "FastCompareTuple4" | "FastCompareTuple5" | "GenericComparisonWithComparer" | "GenericComparisonWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Compare", - t, - [ - left - right - ], - i.SignatureArgTypes, - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.InstanceCall(comp, "Compare", t, [ left; right ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) |> Some | ("GenericLessThan" | "GenericLessThanIntrinsic"), [ left; right ] -> booleanCompare com ctx r left right BinaryLess |> Some @@ -2759,18 +2319,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr equals com ctx r true left right |> Some | ("FastEqualsTuple2" | "FastEqualsTuple3" | "FastEqualsTuple4" | "FastEqualsTuple5" | "GenericEqualityWithComparer" | "GenericEqualityWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Equals", - t, - [ - left - right - ], - i.SignatureArgTypes, - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.InstanceCall(comp, "Equals", t, [ left; right ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) |> Some | ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> makeEqOp r left right BinaryEqual |> Some | ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] -> @@ -2803,11 +2352,7 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr | Value(NewOption(None, _, _), _) -> [ lower ] | Value(NewOption(Some upper, _, _), _) // Upper index is inclusive in F# but exclusive in Dart - | upper -> - [ - lower - add upper (makeIntConst 1) - ] + | upper -> [ lower; add upper (makeIntConst 1) ] let meth = if meth = "GetStringSlice" then @@ -2895,18 +2440,7 @@ let dictionaries (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | ([] | [ Number _ ]), _ -> Helper.GlobalCall("Map", t, [], genArgs = i.GenericArgs, ?loc = r) |> Some | [ IDictionary ], [ arg ] -> Helper.GlobalCall("Map", t, [ arg ], memb = "of", ?loc = r) |> Some | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> - Helper.LibCall( - com, - "Types", - "mapWith", - t, - [ - eqComp - arg - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Types", "mapWith", t, [ eqComp; arg ], ?loc = r) |> Some | [ IEqualityComparer ], [ eqComp ] | [ Number _; IEqualityComparer ], [ _; eqComp ] -> Helper.LibCall(com, "Types", "mapWith", t, [ eqComp ], genArgs = i.GenericArgs, ?loc = r) @@ -2962,18 +2496,7 @@ let hashSets (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op | [], _ -> Helper.GlobalCall("Set", t, [], genArgs = i.GenericArgs, ?loc = r) |> Some | [ IEnumerable ], [ arg ] -> Helper.GlobalCall("Set", t, [ arg ], memb = "of", ?loc = r) |> Some | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> - Helper.LibCall( - com, - "Types", - "setWith", - t, - [ - eqComp - arg - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Types", "setWith", t, [ eqComp; arg ], ?loc = r) |> Some | [ IEqualityComparer ], [ eqComp ] -> Helper.LibCall(com, "Types", "setWith", t, [ eqComp ], ?loc = r) |> Some | _ -> None // Const are read-only but I'm not sure how to detect this in runtime @@ -3017,17 +2540,7 @@ let objects (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt match i.CompiledName, thisArg, args with | ".ctor", _, _ -> typedObjExpr t [] |> Some | "ToString", Some arg, _ -> toString com ctx r [ arg ] |> Some - | "ReferenceEquals", _, [ left; right ] -> - Helper.GlobalCall( - "identical", - t, - [ - left - right - ], - ?loc = r - ) - |> Some + | "ReferenceEquals", _, [ left; right ] -> Helper.GlobalCall("identical", t, [ left; right ], ?loc = r) |> Some | "Equals", Some arg1, [ arg2 ] | "Equals", None, [ arg1; arg2 ] -> equals com ctx r true arg1 arg2 |> Some | "GetHashCode", Some arg, _ -> identityHash com r arg |> Some @@ -3050,17 +2563,7 @@ let unchecked (com: ICompiler) (ctx: Context) r t (i: CallInfo) (_: Expr option) | "Hash", [ arg ] -> structuralHash com r arg |> Some | "Equals", [ arg1; arg2 ] -> equals com ctx r true arg1 arg2 |> Some | "Compare", [ arg1; arg2 ] -> - Helper.LibCall( - com, - "Util", - "compareDynamic", - t, - [ - arg1 - arg2 - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "compareDynamic", t, [ arg1; arg2 ], ?loc = r) |> Some | _ -> None @@ -3226,19 +2729,9 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio match args.Length, last.Type with | 7, Number(_, NumberInfo.IsEnum ent) when ent.FullName = "System.DateTimeKind" -> - let args = - (List.take 6 args) - @ [ - makeIntConst 0 - last - ] - - let argTypes = - (List.take 6 i.SignatureArgTypes) - @ [ - Int32.Number - last.Type - ] + let args = (List.take 6 args) @ [ makeIntConst 0; last ] + + let argTypes = (List.take 6 i.SignatureArgTypes) @ [ Int32.Number; last.Type ] Helper.LibCall(com, "Date", "create", t, args, argTypes, ?loc = r) |> Some | _ -> Helper.LibCall(com, moduleName, "create", t, args, ?loc = r) |> Some @@ -3280,17 +2773,7 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio | "get_DateTime" -> let kind = System.DateTimeKind.Unspecified |> int |> makeIntConst - Helper.LibCall( - com, - "Date", - "fromDateTimeOffset", - t, - [ - thisArg.Value - kind - ], - ?loc = r - ) + Helper.LibCall(com, "Date", "fromDateTimeOffset", t, [ thisArg.Value; kind ], ?loc = r) |> Some | "FromUnixTimeSeconds" | "FromUnixTimeMilliseconds" -> @@ -3308,14 +2791,8 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio "DateOffset", "default", t, - [ - value - makeIntConst 0 - ], - [ - value.Type - Int32.Number - ], + [ value; makeIntConst 0 ], + [ value.Type; Int32.Number ], ?loc = r ) |> Some @@ -3342,11 +2819,7 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio match meth, args with // Ignore IFormatProvider | "Parse", arg :: _ -> [ arg ] - | "TryParse", input :: _culture :: _styles :: defVal :: _ -> - [ - input - defVal - ] + | "TryParse", input :: _culture :: _styles :: defVal :: _ -> [ input; defVal ] | _ -> args let meth = Naming.removeGetSetPrefix meth |> Naming.lowerFirst @@ -3766,11 +3239,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp | None, input :: pattern :: args -> let reg = createRegex None Any (pattern :: args) - [ - reg - input - ] - |> Some + [ reg; input ] |> Some | _ -> None |> Option.map (fun args -> match meth, args with @@ -3952,18 +3421,7 @@ let asyncBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | _, "Singleton", _ -> makeImportLib com t "singleton" "AsyncBuilder" |> Some // For Using we need to cast the argument to IDisposable | Some x, "Using", [ arg; f ] -> - Helper.InstanceCall( - x, - "Using", - t, - [ - arg - f - ], - i.SignatureArgTypes, - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.InstanceCall(x, "Using", t, [ arg; f ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) |> Some | Some x, meth, _ -> Helper.InstanceCall(x, meth, t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) @@ -4381,15 +3839,7 @@ let makeMethodInfo com r (name: string) (parameters: (string * Type) list) (retu [ makeStrConst name parameters - |> List.map (fun (name, t) -> - makeTuple - None - false - [ - makeStrConst name - makeTypeInfo None t - ] - ) + |> List.map (fun (name, t) -> makeTuple None false [ makeStrConst name; makeTypeInfo None t ]) |> makeArray Any makeTypeInfo None returnType ] @@ -4621,27 +4071,12 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.dictionary -> let args = match argTypes.Value, args with - | ([] | [ Number _ ]), _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] + | ([] | [ Number _ ]), _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] | [ IEqualityComparer ], [ eqComp ] | [ Number _; IEqualityComparer ], [ _; eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected dictionary constructor" |> raise let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier "Dictionary" @@ -4650,26 +4085,10 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.hashset -> let args = match argTypes.Value, args with - | [], _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] - | [ IEqualityComparer ], [ eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + | [], _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] + | [ IEqualityComparer ], [ eqComp ] -> [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected hashset constructor" |> raise let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier "HashSet" @@ -4724,43 +4143,11 @@ let tryType = | BclTimer -> Some("System.Timers.Timer", timers, []) | BclTimeSpan -> Some(Types.timespan, timeSpans, []) | BclHashSet genArg -> Some(Types.hashset, hashSets, [ genArg ]) - | BclDictionary(key, value) -> - Some( - Types.dictionary, - dictionaries, - [ - key - value - ] - ) - | BclKeyValuePair(key, value) -> - Some( - Types.keyValuePair, - keyValuePairs, - [ - key - value - ] - ) - | FSharpMap(key, value) -> - Some( - Types.fsharpMap, - maps, - [ - key - value - ] - ) + | BclDictionary(key, value) -> Some(Types.dictionary, dictionaries, [ key; value ]) + | BclKeyValuePair(key, value) -> Some(Types.keyValuePair, keyValuePairs, [ key; value ]) + | FSharpMap(key, value) -> Some(Types.fsharpMap, maps, [ key; value ]) | FSharpSet genArg -> Some(Types.fsharpSet, sets, [ genArg ]) - | FSharpResult(genArg1, genArg2) -> - Some( - Types.result, - results, - [ - genArg1 - genArg2 - ] - ) + | FSharpResult(genArg1, genArg2) -> Some(Types.result, results, [ genArg1; genArg2 ]) | FSharpChoice genArgs -> Some($"{Types.choiceNonGeneric}`{List.length genArgs}", results, genArgs) | FSharpReference genArg -> Some(Types.refCell, refCells, [ genArg ]) | _ -> None diff --git a/src/Fable.Transforms/FSharp2Fable.Util.fs b/src/Fable.Transforms/FSharp2Fable.Util.fs index 2fe25cebf9..2e96cf2d96 100644 --- a/src/Fable.Transforms/FSharp2Fable.Util.fs +++ b/src/Fable.Transforms/FSharp2Fable.Util.fs @@ -1229,19 +1229,7 @@ module Patterns = && t2.TypeDefinition.CompiledName = "obj" && comp.FullName = "Microsoft.FSharp.Core.LanguagePrimitives.GenericEqualityComparer" -> - Some( - memb, - Some comp, - "GenericEquality", - [ - e1.Type - e2.Type - ], - [ - e1 - e2 - ] - ) + Some(memb, Some comp, "GenericEquality", [ e1.Type; e2.Type ], [ e1; e2 ]) | _ -> None else None diff --git a/src/Fable.Transforms/FSharp2Fable.fs b/src/Fable.Transforms/FSharp2Fable.fs index 3556d7827f..fc479383c8 100644 --- a/src/Fable.Transforms/FSharp2Fable.fs +++ b/src/Fable.Transforms/FSharp2Fable.fs @@ -1263,14 +1263,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs let valToSet = makeValueFrom com ctx r valToSet let args = [ valueExpr ] - let info = - makeCallInfo - None - args - [ - valToSet.Type - Fable.Boolean - ] + let info = makeCallInfo None args [ valToSet.Type; Fable.Boolean ] return makeCall r Fable.Unit info valToSet | _ -> @@ -1328,21 +1321,9 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) appliedGenArgs fs transformBaseConsCall com ctx r baseEnt call genArgs args |> captureBaseCall [ second ] - | _ -> - [ - first - second - ] - | _ -> - [ - first - second - ] - | _ -> - [ - first - second - ] + | _ -> [ first; second ] + | _ -> [ first; second ] + | _ -> [ first; second ] let! exprs = transformExprList com ctx exprs return Fable.Sequential exprs diff --git a/src/Fable.Transforms/Fable2Babel.fs b/src/Fable.Transforms/Fable2Babel.fs index ed92cb7fbc..f1fc91534e 100644 --- a/src/Fable.Transforms/Fable2Babel.fs +++ b/src/Fable.Transforms/Fable2Babel.fs @@ -132,15 +132,7 @@ module Lib = com.IsTypeScript && ent.IsFSharpUnion && List.isMultiple ent.UnionCases - && not ( - Util.hasAnyAttribute - [ - Atts.stringEnum - Atts.erase - Atts.tsTaggedUnion - ] - ent.Attributes - ) + && not (Util.hasAnyAttribute [ Atts.stringEnum; Atts.erase; Atts.tsTaggedUnion ] ent.Attributes) -> Util.UnionHelpers.UNION_SUFFIX | Annotation -> "" @@ -185,12 +177,7 @@ module Reflection = let typeInfo = transformTypeInfoFor Reflection com ctx r genMap fi.FieldType - Expression.arrayExpression ( - [| - fieldName - typeInfo - |] - ) + Expression.arrayExpression ([| fieldName; typeInfo |]) ) |> List.toArray @@ -330,37 +317,18 @@ module Reflection = | None -> 0. Expression.arrayExpression ( - [| - Expression.stringLiteral (name) - Expression.numericLiteral (value) - |] + [| Expression.stringLiteral (name); Expression.numericLiteral (value) |] ) |> Some ) |> Seq.toArray |> Expression.arrayExpression - [ - Expression.stringLiteral (entRef.FullName) - numberInfo kind - cases - ] + [ Expression.stringLiteral (entRef.FullName); numberInfo kind; cases ] |> libReflectionCall com ctx None "enum" | _ -> numberInfo kind - | Fable.LambdaType(argType, returnType) -> - genericTypeInfo - "lambda" - [ - argType - returnType - ] - | Fable.DelegateType(argTypes, returnType) -> - genericTypeInfo - "delegate" - [ - yield! argTypes - yield returnType - ] + | Fable.LambdaType(argType, returnType) -> genericTypeInfo "lambda" [ argType; returnType ] + | Fable.DelegateType(argTypes, returnType) -> genericTypeInfo "delegate" [ yield! argTypes; yield returnType ] | Fable.Tuple(genArgs, _) -> genericTypeInfo "tuple" genArgs | Fable.Option(genArg, _) -> genericTypeInfo "option" [ genArg ] | Fable.Array(genArg, _) -> genericTypeInfo "array" [ genArg ] @@ -371,13 +339,7 @@ module Reflection = let genArgs = resolveGenerics genArgs List.zip (fieldNames |> Array.toList) genArgs - |> List.map (fun (k, t) -> - Expression.arrayExpression - [| - Expression.stringLiteral (k) - t - |] - ) + |> List.map (fun (k, t) -> Expression.arrayExpression [| Expression.stringLiteral (k); t |]) |> libReflectionCall com ctx None "anonRecord" | Fable.DeclaredType(entRef, genArgs) -> let fullName = entRef.FullName @@ -683,11 +645,7 @@ module Annotation = | Some(FunctionTypeAnnotation _) as annotation -> let _, typeParams = match typ with - | Fable.LambdaType(argType, returnType) -> - [ - argType - returnType - ] + | Fable.LambdaType(argType, returnType) -> [ argType; returnType ] | Fable.DelegateType(argTypes, returnType) -> argTypes @ [ returnType ] | _ -> [] |> Util.getTypeParameters ctx @@ -763,44 +721,14 @@ module Annotation = | Replacements.Util.BclTimer -> makeFableLibImportTypeAnnotation com ctx [] "Timer" "Timer" | Replacements.Util.BclHashSet key -> makeFableLibImportTypeAnnotation com ctx [ key ] "Util" "ISet" | Replacements.Util.BclDictionary(key, value) -> - makeFableLibImportTypeAnnotation - com - ctx - [ - key - value - ] - "Util" - "IMap" - | Replacements.Util.BclKeyValuePair(key, value) -> - makeTupleTypeAnnotation - com - ctx - [ - key - value - ] + makeFableLibImportTypeAnnotation com ctx [ key; value ] "Util" "IMap" + | Replacements.Util.BclKeyValuePair(key, value) -> makeTupleTypeAnnotation com ctx [ key; value ] | Replacements.Util.FSharpSet key -> makeFableLibImportTypeAnnotation com ctx [ key ] "Set" "FSharpSet" | Replacements.Util.FSharpMap(key, value) -> - makeFableLibImportTypeAnnotation - com - ctx - [ - key - value - ] - "Map" - "FSharpMap" + makeFableLibImportTypeAnnotation com ctx [ key; value ] "Map" "FSharpMap" | Replacements.Util.FSharpResult(ok, err) -> $"FSharpResult$2{Util.UnionHelpers.UNION_SUFFIX}" - |> makeFableLibImportTypeAnnotation - com - ctx - [ - ok - err - ] - "Result" + |> makeFableLibImportTypeAnnotation com ctx [ ok; err ] "Result" | Replacements.Util.FSharpChoice genArgs -> $"FSharpChoice${List.length genArgs}{Util.UnionHelpers.UNION_SUFFIX}" |> makeFableLibImportTypeAnnotation com ctx genArgs "Choice" @@ -1633,10 +1561,7 @@ module Util = Expression.newExpression ( consRef, - [| - tagExpr - Expression.arrayExpression values - |], + [| tagExpr; Expression.arrayExpression values |], ?typeArguments = typeParamInst, ?loc = r ) @@ -1738,22 +1663,9 @@ module Util = | [ TransformExpr com ctx expr ], None -> libCall com ctx r "List" "singleton" [] [ expr ] | exprs, None -> [ makeArray com ctx exprs ] |> libCall com ctx r "List" "ofArray" [] | [ TransformExpr com ctx head ], Some(TransformExpr com ctx tail) -> - libCall - com - ctx - r - "List" - "cons" - [] - [ - head - tail - ] + libCall com ctx r "List" "cons" [] [ head; tail ] | exprs, Some(TransformExpr com ctx tail) -> - [ - makeArray com ctx exprs - tail - ] + [ makeArray com ctx exprs; tail ] |> libCall com ctx r "List" "ofArrayWithTail" [] | Fable.NewOption(value, t, _) -> match value with @@ -1790,7 +1702,11 @@ module Util = let enumerator = libCall com ctx None "Util" "getEnumerator" [] [ Expression.identifier ("this") ] - BlockStatement([| Statement.returnStatement (libCall com ctx None "Util" "toIterator" [] [ enumerator ]) |]) + BlockStatement( + [| + Statement.returnStatement (libCall com ctx None "Util" "toIterator" [] [ enumerator ]) + |] + ) let extractSuperClassFromBaseCall (com: IBabelCompiler) @@ -1869,13 +1785,7 @@ module Util = let returnType = if isOptional then returnType - |> Option.map (fun t -> - UnionTypeAnnotation - [| - t - UndefinedTypeAnnotation - |] - ) + |> Option.map (fun t -> UnionTypeAnnotation [| t; UndefinedTypeAnnotation |]) else returnType @@ -1894,7 +1804,9 @@ module Util = if not memb.IsMangled && (info.IsValue || (not compileAsClass && info.IsGetter)) then let _, body = unwrapOptionalArg com memb.Body - [ ObjectMember.objectProperty (prop, com.TransformAsExpr(ctx, body), isComputed = isComputed) ] + [ + ObjectMember.objectProperty (prop, com.TransformAsExpr(ctx, body), isComputed = isComputed) + ] elif not memb.IsMangled && info.IsGetter then [ makeMethod ObjectGetter ] @@ -1911,10 +1823,7 @@ module Util = ObjectMember.objectMethod (ObjectMeth, prop, [||], body, isComputed = isComputed) - [ - method - iterator - ] + [ method; iterator ] else [ makeMethod ObjectMeth ] @@ -2081,10 +1990,7 @@ module Util = "Reflection", "equals", Fable.Boolean, - [ - e1 - e2 - ], + [ e1; e2 ], ?loc = range ) @@ -2163,16 +2069,7 @@ module Util = let props = List.zipSafe names args |> List.map (fun (key, value) -> - Fable.Value( - Fable.NewTuple( - [ - Fable.Value(Fable.StringConstant key, None) - value - ], - false - ), - None - ) + Fable.Value(Fable.NewTuple([ Fable.Value(Fable.StringConstant key, None); value ], false), None) ) transformJsxEl com ctx callee props @@ -2292,14 +2189,20 @@ module Util = | None -> callInfo.Args optimizeTailCall com ctx range tc args - | _ -> [| transformCall com ctx range t callee callInfo |> resolveExpr t returnStrategy |] + | _ -> + [| + transformCall com ctx range t callee callInfo |> resolveExpr t returnStrategy + |] let transformCurriedApplyAsStatements com ctx range t returnStrategy callee args = // Warn when there's a recursive call that couldn't be optimized? match returnStrategy, ctx.TailCallOpportunity with | Some(Return | ReturnUnit), Some tc when tc.IsRecursiveRef(callee) && List.sameLength args tc.Args -> optimizeTailCall com ctx range tc args - | _ -> [| transformCurriedApply com ctx range callee args |> resolveExpr t returnStrategy |] + | _ -> + [| + transformCurriedApply com ctx range callee args |> resolveExpr t returnStrategy + |] // When expecting a block, it's usually not necessary to wrap it // in a lambda to isolate its variable context @@ -2562,7 +2465,9 @@ module Util = | _ -> Array.append caseBody [| Statement.breakStatement () |] guards - @ [ SwitchCase.switchCase (transformGuard lastGuard, [| Statement.blockStatement (caseBody) |]) ] + @ [ + SwitchCase.switchCase (transformGuard lastGuard, [| Statement.blockStatement (caseBody) |]) + ] ) let cases = cases |> List.toArray @@ -2575,7 +2480,11 @@ module Util = | [||], Some defaultCase when not (canHaveSideEffects evalExpr) -> defaultCase | cases, Some defaultCase -> let cases = - Array.append cases [| SwitchCase.switchCase (body = [| Statement.blockStatement (defaultCase) |]) |] + Array.append + cases + [| + SwitchCase.switchCase (body = [| Statement.blockStatement (defaultCase) |]) + |] [| Statement.switchStatement (switchGuard, cases) |] | cases, None -> [| Statement.switchStatement (switchGuard, cases) |] @@ -2767,14 +2676,7 @@ module Util = let count = Map.tryFind idx targetRefs |> Option.defaultValue 0 Map.add idx (count + 1) targetRefs | Fable.Let(_, _, body) -> List.fold findSuccess targetRefs [ body ] - | Fable.IfThenElse(_cond, thenExpr, elseExpr, _) -> - List.fold - findSuccess - targetRefs - [ - thenExpr - elseExpr - ] + | Fable.IfThenElse(_cond, thenExpr, elseExpr, _) -> List.fold findSuccess targetRefs [ thenExpr; elseExpr ] // | Fable.LetRec(_, body) -> List.fold findSuccess targetRefs [body] // | Fable.Sequential exprs -> exprs |> List.tryLast |> Option.toList |> List.fold findSuccess targetRefs // | Fable.TryCatch(body, catch, _finalizer, _) -> body::(catch |> Option.map snd |> Option.toList) |> List.fold findSuccess targetRefs @@ -2838,11 +2740,7 @@ module Util = let decisionTree = com.TransformAsStatements(ctx, Some targetAssign, treeExpr) - [| - yield multiVarDecl - yield! decisionTree - yield! switch2 - |] + [| yield multiVarDecl; yield! decisionTree; yield! switch2 |] let transformDecisionTreeAsStatements (com: IBabelCompiler) @@ -2955,12 +2853,7 @@ module Util = if ctx.HoistVars [ ident ] then let assignment = transformBindingAsExpr com ctx ident value - Expression.sequenceExpression ( - [| - assignment - com.TransformAsExpr(ctx, body) - |] - ) + Expression.sequenceExpression ([| assignment; com.TransformAsExpr(ctx, body) |]) else iife com ctx expr @@ -3133,7 +3026,9 @@ module Util = transformDecisionTreeSuccessAsStatements com ctx returnStrategy idx boundValues | Fable.WhileLoop(TransformExpr com ctx guard, body, range) -> - [| Statement.whileStatement (guard, transformBlock com ctx None body, ?loc = range) |] + [| + Statement.whileStatement (guard, transformBlock com ctx None body, ?loc = range) + |] | Fable.ForLoop(var, TransformExpr com ctx start, TransformExpr com ctx limit, body, isUp, range) -> let op1, op2 = @@ -3367,11 +3262,7 @@ module Util = let classExpr = Expression.classExpression ( - [| - yield! classFields - classCons - yield! classMembers - |], + [| yield! classFields; classCons; yield! classMembers |], ?superClass = superClass, ?typeParameters = typeParamDecl, ?implements = implements @@ -3429,10 +3320,7 @@ module Util = else let reflectionDeclaration = declareTypeReflection com ctx ent entName - [ - typeDeclaration - reflectionDeclaration - ] + [ typeDeclaration; reflectionDeclaration ] let hasAttribute fullName (atts: Fable.Attribute seq) = atts |> Seq.exists (fun att -> att.Entity.FullName = fullName) @@ -3535,13 +3423,7 @@ module Util = let returnType = if isOptional then returnType - |> Option.map (fun t -> - UnionTypeAnnotation - [| - t - UndefinedTypeAnnotation - |] - ) + |> Option.map (fun t -> UnionTypeAnnotation [| t; UndefinedTypeAnnotation |]) else returnType @@ -3715,11 +3597,7 @@ module Util = case_ta, AbstractMember.abstractProperty ( Expression.numericLiteral (i), - TupleTypeAnnotation - [| - LiteralTypeAnnotation(Literal.stringLiteral (uci.Name)) - fields_ta - |] + TupleTypeAnnotation [| LiteralTypeAnnotation(Literal.stringLiteral (uci.Name)); fields_ta |] ) ) |> Array.unzip @@ -3736,11 +3614,7 @@ module Util = Parameter.parameter ("fields", typeAnnotation = fieldsArgTa) |] - let consArgsModifiers = - [| - Readonly - Readonly - |] + let consArgsModifiers = [| Readonly; Readonly |] let consBody = BlockStatement [| callSuperAsStatement [] |] let classMembers = Array.append [| cases |] classMembers @@ -3749,7 +3623,9 @@ module Util = Some( Array.append entParamsDecl - [| TypeParameter.typeParameter (tagArgName, bound = KeyofTypeAnnotation(union_cases_alias)) |] + [| + TypeParameter.typeParameter (tagArgName, bound = KeyofTypeAnnotation(union_cases_alias)) + |] ) [ @@ -3776,10 +3652,7 @@ module Util = [| Expression.newExpression ( Expression.Identifier union_cons, - [| - Expression.Literal tag - passedArgs - |], + [| Expression.Literal tag; passedArgs |], typeArguments = consTypeArgs ) |> Statement.returnStatement @@ -3820,21 +3693,14 @@ module Util = // Multiple cases, no-TypeScript | _ -> - let args = - [| - Parameter.parameter ("tag") - Parameter.parameter ("fields") - |] + let args = [| Parameter.parameter ("tag"); Parameter.parameter ("fields") |] let body = BlockStatement [| callSuperAsStatement [] yield! - [ - "tag" - "fields" - ] + [ "tag"; "fields" ] |> List.map (fun name -> let left = get None thisExpr name let right = Expression.identifier (name) @@ -4236,11 +4102,7 @@ module Util = ) // We used to have trouble when mixing member, default and namespace imports, // issue an import statement for each kind just in case - [ - mems - defs - alls - ] + [ mems; defs; alls ] |> List.choose ( function | [] -> None @@ -4258,11 +4120,7 @@ module Util = [] | decls -> decls ) - |> fun staticImports -> - [ - yield! staticImports - yield! statefulImports - ] + |> fun staticImports -> [ yield! staticImports; yield! statefulImports ] let getIdentForImport (com: IBabelCompiler) (ctx: Context) noMangle (path: string) (selector: string) = if System.String.IsNullOrEmpty selector then diff --git a/src/Fable.Transforms/FableTransforms.fs b/src/Fable.Transforms/FableTransforms.fs index d98b8b3cb2..01ed034a9e 100644 --- a/src/Fable.Transforms/FableTransforms.fs +++ b/src/Fable.Transforms/FableTransforms.fs @@ -438,25 +438,11 @@ module private Transforms = | Operation(Binary(AST.BinaryPlus, v1, v2), _, _, _) -> match v1, v2 with | Value(StringConstant v1, r1), Value(StringConstant v2, r2) -> - Value( - StringConstant(v1 + v2), - addRanges - [ - r1 - r2 - ] - ) + Value(StringConstant(v1 + v2), addRanges [ r1; r2 ]) // Assume NumberKind and NumberInfo are the same | Value(NumberConstant(:? int as v1, AST.Int32, NumberInfo.Empty), r1), Value(NumberConstant(:? int as v2, AST.Int32, NumberInfo.Empty), r2) -> - Value( - NumberConstant(v1 + v2, AST.Int32, NumberInfo.Empty), - addRanges - [ - r1 - r2 - ] - ) + Value(NumberConstant(v1 + v2, AST.Int32, NumberInfo.Empty), addRanges [ r1; r2 ]) | _ -> e | Operation(Logical(AST.LogicalAnd, (Value(BoolConstant b, _) as v1), v2), [], _, _) -> @@ -897,12 +883,7 @@ let rec transformDeclaration transformations (com: Compiler) file decl = // In order to uncurry correctly the baseCall arguments, // we need to include it in the constructor body let args, body = - Sequential - [ - baseCall - cons.Body - ] - |> curryArgIdentsAndReplaceInBody cons.Args + Sequential [ baseCall; cons.Body ] |> curryArgIdentsAndReplaceInBody cons.Args transformExpr com body |> function diff --git a/src/Fable.Transforms/Global/Naming.fs b/src/Fable.Transforms/Global/Naming.fs index e328ae415c..dc9d739b85 100644 --- a/src/Fable.Transforms/Global/Naming.fs +++ b/src/Fable.Transforms/Global/Naming.fs @@ -50,13 +50,7 @@ module Naming = let unknown = "UNKNOWN" let isInFableModules (file: string) = - file.Split( - [| - '\\' - '/' - |] - ) - |> Array.exists ((=) fableModules) + file.Split([| '\\'; '/' |]) |> Array.exists ((=) fableModules) let isIdentChar index (c: char) = let code = int c diff --git a/src/Fable.Transforms/Global/Prelude.fs b/src/Fable.Transforms/Global/Prelude.fs index 508a204569..cf3062074d 100644 --- a/src/Fable.Transforms/Global/Prelude.fs +++ b/src/Fable.Transforms/Global/Prelude.fs @@ -260,22 +260,13 @@ module Path = if path1.Length = 0 then path1 else - (path1.TrimEnd - [| - '\\' - '/' - |]) - + "/" + (path1.TrimEnd [| '\\'; '/' |]) + "/" let path2 = if path2.StartsWith("./") then path2.[2..] else - path2.TrimStart - [| - '\\' - '/' - |] + path2.TrimStart [| '\\'; '/' |] path1 + path2 #else @@ -465,12 +456,7 @@ module Path = let parent = split parent let child = split child - let commonPrefix = - getCommonPrefix - [ - parent - child - ] + let commonPrefix = getCommonPrefix [ parent; child ] commonPrefix.Length >= parent.Length diff --git a/src/Fable.Transforms/OverloadSuffix.fs b/src/Fable.Transforms/OverloadSuffix.fs index f863e59101..76754868b6 100644 --- a/src/Fable.Transforms/OverloadSuffix.fs +++ b/src/Fable.Transforms/OverloadSuffix.fs @@ -81,10 +81,7 @@ let rec private getTypeFastFullName (genParams: IDictionary<_, _>) (t: Fable.Typ + (getTypeFastFullName genParams genArg) + " option" | Fable.LambdaType(argType, returnType) -> - [ - argType - returnType - ] + [ argType; returnType ] |> List.map (getTypeFastFullName genParams) |> String.concat " -> " // TODO: Use Func` instead? diff --git a/src/Fable.Transforms/Php/Fable2Php.fs b/src/Fable.Transforms/Php/Fable2Php.fs index 69403b6e45..151f7cc940 100644 --- a/src/Fable.Transforms/Php/Fable2Php.fs +++ b/src/Fable.Transforms/Php/Fable2Php.fs @@ -335,11 +335,7 @@ let convertSingleCaseUnion (com: IPhpCompiler) (decl: Fable.ClassDecl) (info: Fa ] Abstract = false BaseType = None - Interfaces = - [ - PhpUnion.fSharpUnion - Core.icomparable - ] + Interfaces = [ PhpUnion.fSharpUnion; Core.icomparable ] File = com.CurrentFile OriginalFullName = info.FullName } @@ -1481,15 +1477,7 @@ and convertValue (com: IPhpCompiler) (value: Fable.ValueKind) range = | Fable.CharConstant(c) -> PhpConst(PhpConstString(string c)) | Fable.Null _ -> PhpConst(PhpConstNull) | Fable.NewList(Some(head, tail), _) -> - libCall - com - "List" - "FSharpList" - "cons" - [ - convertExpr com head - convertExpr com tail - ] + libCall com "List" "FSharpList" "cons" [ convertExpr com head; convertExpr com tail ] | Fable.NewList(None, _) -> libCall com "List" "FSharpList" "_empty" [] | Fable.NewArray(kind, _, _) -> match kind with @@ -1764,7 +1752,9 @@ and convertExprToStatement (com: IPhpCompiler) expr returnStrategy = [ PhpFor(id, startExpr, limitExpr, isUp, bodyExpr) ] | Fable.Extended(Fable.Debugger, _) -> - [ PhpDo(PhpFunctionCall(PhpIdent(unscopedIdent "assert"), [ PhpConst(PhpConstBool false) ])) ] + [ + PhpDo(PhpFunctionCall(PhpIdent(unscopedIdent "assert"), [ PhpConst(PhpConstBool false) ])) + ] | Fable.Extended(Fable.Throw(expr, _), _) -> match expr with | None -> failwith "TODO: rethrow" diff --git a/src/Fable.Transforms/Python/Fable2Python.fs b/src/Fable.Transforms/Python/Fable2Python.fs index c796b7a758..2aa65e64a9 100644 --- a/src/Fable.Transforms/Python/Fable2Python.fs +++ b/src/Fable.Transforms/Python/Fable2Python.fs @@ -156,12 +156,7 @@ module Reflection = let name = fi.Name |> Naming.toSnakeCase |> Helpers.clean - (Expression.tuple - [ - Expression.stringConstant (name) - typeInfo - ]), - stmts + (Expression.tuple [ Expression.stringConstant (name); typeInfo ]), stmts ) |> Seq.toList |> Helpers.unzipArgs @@ -170,12 +165,7 @@ module Reflection = let py, stmts' = pyConstructor com ctx ent - [ - fullnameExpr - Expression.list generics - py - fields - ] + [ fullnameExpr; Expression.list generics; py; fields ] |> libReflectionCall com ctx None "record", stmts @ stmts' @@ -210,12 +200,7 @@ module Reflection = let py, stmts = pyConstructor com ctx ent - [ - fullnameExpr - Expression.list generics - py - cases - ] + [ fullnameExpr; Expression.list generics; py; cases ] |> libReflectionCall com ctx None "union", stmts @@ -288,38 +273,18 @@ module Reflection = | Some v -> Convert.ToDouble v | None -> 0. - Expression.tuple - [ - Expression.stringConstant name - Expression.floatConstant value - ] + Expression.tuple [ Expression.stringConstant name; Expression.floatConstant value ] |> Some ) |> Seq.toList |> Expression.list - [ - Expression.stringConstant entRef.FullName - numberInfo kind - cases - ] + [ Expression.stringConstant entRef.FullName; numberInfo kind; cases ] |> libReflectionCall com ctx None "enum", [] | _ -> numberInfo kind, [] - | Fable.LambdaType(argType, returnType) -> - genericTypeInfo - "lambda" - [| - argType - returnType - |] - | Fable.DelegateType(argTypes, returnType) -> - genericTypeInfo - "delegate" - [| - yield! argTypes - yield returnType - |] + | Fable.LambdaType(argType, returnType) -> genericTypeInfo "lambda" [| argType; returnType |] + | Fable.DelegateType(argTypes, returnType) -> genericTypeInfo "delegate" [| yield! argTypes; yield returnType |] | Fable.Tuple(genArgs, _) -> genericTypeInfo "tuple" (List.toArray genArgs) | Fable.Option(genArg, _) -> genericTypeInfo "option" [| genArg |] | Fable.Array(genArg, _) -> genericTypeInfo "array" [| genArg |] @@ -330,13 +295,7 @@ module Reflection = let genArgs, stmts = resolveGenerics (List.toArray genArgs) List.zip (List.ofArray fieldNames) genArgs - |> List.map (fun (k, t) -> - Expression.tuple - [ - Expression.stringConstant k - t - ] - ) + |> List.map (fun (k, t) -> Expression.tuple [ Expression.stringConstant k; t ]) |> libReflectionCall com ctx None "anonRecord", stmts | Fable.DeclaredType(entRef, generics) -> @@ -363,28 +322,13 @@ module Reflection = let values, stmts' = transformTypeInfo com ctx r genMap value - genericEntity - fullName - [ - keys - values - ], - stmts @ stmts' + genericEntity fullName [ keys; values ], stmts @ stmts' | Replacements.Util.FSharpResult(ok, err) -> let ent = com.GetEntity(entRef) let ok', stmts = transformTypeInfo com ctx r genMap ok let err', stmts' = transformTypeInfo com ctx r genMap err - let expr, stmts'' = - transformUnionReflectionInfo - com - ctx - r - ent - [ - ok' - err' - ] + let expr, stmts'' = transformUnionReflectionInfo com ctx r ent [ ok'; err' ] expr, stmts @ stmts' @ stmts'' | Replacements.Util.FSharpChoice gen -> @@ -478,11 +422,7 @@ module Reflection = let pyInstanceof consExpr (Util.TransformExpr com ctx (expr, stmts)) : Expression * Statement list = let func = Expression.name (Identifier("isinstance")) - let args = - [ - expr - consExpr - ] + let args = [ expr; consExpr ] Expression.call (func, args), stmts @@ -688,14 +628,7 @@ module Annotation = ) |> Expression.list - Expression.subscript ( - expr, - Expression.tuple - [ - args - returnType - ] - ) + Expression.subscript (expr, Expression.tuple [ args; returnType ]) | _, [] -> expr | _, [ arg ] -> Expression.subscript (expr, arg) | _, args -> Expression.subscript (expr, Expression.tuple args) @@ -819,15 +752,7 @@ module Annotation = let value = Expression.name "dict" let any, stmts = stdlibModuleTypeHint com ctx "typing" "Any" [] - Expression.subscript ( - value, - Expression.tuple - [ - Expression.name "str" - any - ] - ), - stmts + Expression.subscript (value, Expression.tuple [ Expression.name "str"; any ]), stmts | Fable.DeclaredType(entRef, genArgs) -> makeEntityTypeAnnotation com ctx entRef genArgs repeatedGenerics | _ -> stdlibModuleTypeHint com ctx "typing" "Any" [] @@ -874,21 +799,13 @@ module Annotation = | Some v -> Convert.ToDouble v | None -> 0. - Expression.tuple - [ - Expression.stringConstant name - Expression.floatConstant value - ] + Expression.tuple [ Expression.stringConstant name; Expression.floatConstant value ] |> Some ) |> Seq.toList |> Expression.list - [ - Expression.stringConstant entRef.FullName - numberInfo kind - cases - ] + [ Expression.stringConstant entRef.FullName; numberInfo kind; cases ] |> libReflectionCall com ctx None "enum", [] | Decimal, _ -> stdlibModuleTypeHint com ctx "decimal" "Decimal" [] @@ -1000,11 +917,7 @@ module Annotation = | "Fable.Core.Py.Callable", _ -> let any, stmts = stdlibModuleTypeHint com ctx "typing" "Any" [] - let genArgs = - [ - Expression.ellipsis - any - ] + let genArgs = [ Expression.ellipsis; any ] stdlibModuleAnnotation com ctx "collections.abc" "Callable" genArgs, stmts | _ -> @@ -1067,15 +980,7 @@ module Annotation = |> makeImportTypeAnnotation com ctx genArgs "Fable.Core" *) | Replacements.Util.FSharpResult(ok, err) -> - let resolved, stmts = - resolveGenerics - com - ctx - [ - ok - err - ] - repeatedGenerics + let resolved, stmts = resolveGenerics com ctx [ ok; err ] repeatedGenerics fableModuleAnnotation com ctx "result" "FSharpResult_2" resolved, stmts | _ -> stdlibModuleTypeHint com ctx "typing" "Any" [] @@ -1524,13 +1429,7 @@ module Util = | Expression.Constant _, _ -> e // TODO: Unsigned ints seem to cause problems, should we check only Int32 here? | _, Fable.Number((Int8 | Int16 | Int32), _) -> - Expression.boolOp ( - BoolOperator.Or, - [ - e - Expression.intConstant 0 - ] - ) + Expression.boolOp (BoolOperator.Or, [ e; Expression.intConstant 0 ]) | _ -> e let wrapExprInBlockWithReturn (e, stmts) = stmts @ [ Statement.return' e ] @@ -1863,26 +1762,11 @@ module Util = let expr, stmts = makeList com ctx exprs [ expr ] |> libCall com ctx r "list" "ofArray", stmts | [ TransformExpr com ctx (head, stmts) ], Some(TransformExpr com ctx (tail, stmts')) -> - libCall - com - ctx - r - "list" - "cons" - [ - head - tail - ], - stmts @ stmts' + libCall com ctx r "list" "cons" [ head; tail ], stmts @ stmts' | exprs, Some(TransformExpr com ctx (tail, stmts)) -> let expr, stmts' = makeList com ctx exprs - [ - expr - tail - ] - |> libCall com ctx r "list" "ofArrayWithTail", - stmts @ stmts' + [ expr; tail ] |> libCall com ctx r "list" "ofArrayWithTail", stmts @ stmts' | Fable.NewOption(value, t, _) -> match value with | Some(TransformExpr com ctx (e, stmts)) -> @@ -2040,10 +1924,7 @@ module Util = Statement.functionDef (name = name, args = args, body = body) - [ - method - iterator - ] + [ method; iterator ] else [ makeMethod memb.Name info.HasSpread memb.Args memb.Body [] ] ) @@ -2234,15 +2115,7 @@ module Util = | _ -> Expression.binOp (left, op, right, ?loc = range), stmts @ stmts' | Fable.Logical(op, TransformExpr com ctx (left, stmts), TransformExpr com ctx (right, stmts')) -> - Expression.boolOp ( - op, - [ - left - right - ], - ?loc = range - ), - stmts @ stmts' + Expression.boolOp (op, [ left; right ], ?loc = range), stmts @ stmts' let transformEmit (com: IPythonCompiler) ctx range (info: Fable.EmitInfo) = let macro = info.Macro @@ -2677,15 +2550,7 @@ module Util = let test = match fallThrough with - | Some ft -> - Expression.boolOp ( - op = Or, - values = - [ - ft - expr - ] - ) + | Some ft -> Expression.boolOp (op = Or, values = [ ft; expr ]) | _ -> expr // Check for fallthrough @@ -3275,7 +3140,9 @@ module Util = | None -> failwith "TODO: rethrow" | Some(TransformExpr com ctx (e, stmts)) -> stmts @ [ Statement.raise e ] | Fable.Debugger -> - [ Statement.assert' (Expression.boolOp (op = Or, values = [ Expression.boolConstant true ])) ] + [ + Statement.assert' (Expression.boolOp (op = Or, values = [ Expression.boolConstant true ])) + ] | Fable.TypeCast(e, t) -> let expr, stmts = transformCast com ctx t e @@ -3496,15 +3363,7 @@ module Util = let step = Expression.intConstant step let iter = - Expression.call ( - Expression.name (Identifier "range"), - args = - [ - start - limit - step - ] - ) + Expression.call (Expression.name (Identifier "range"), args = [ start; limit; step ]) let body = transformBlock com ctx None body let target = com.GetIdentifierAsExpr(ctx, var.Name) @@ -3698,10 +3557,7 @@ module Util = let fieldsId = makeTypedIdent (Fable.Array(Fable.Any, Fable.MutableArray)) "fields" - [| - tagId - fieldsId - |] + [| tagId; fieldsId |] let getEntityFieldsAsIdents _com (ent: Fable.Entity) = ent.FSharpFields @@ -3756,11 +3612,7 @@ module Util = let bases = baseExpr |> Option.toList let classBody = - let body = - [ - yield! props - yield! classMembers - ] + let body = [ yield! props; yield! classMembers ] match body with | [] -> [ Statement.ellipsis ] @@ -3781,7 +3633,9 @@ module Util = ) ] - [ Statement.classDef (name, body = classBody, decoratorList = decorators, bases = bases @ generics) ] + [ + Statement.classDef (name, body = classBody, decoratorList = decorators, bases = bases @ generics) + ] let declareClassType (com: IPythonCompiler) @@ -3803,11 +3657,7 @@ module Util = let classMembers = classCons @ classMembers //printfn "ClassMembers: %A" classMembers let classBody = - let body = - [ - yield! classFields - yield! classMembers - ] + let body = [ yield! classFields; yield! classMembers ] match body with | [] -> [ Statement.ellipsis ] @@ -3847,7 +3697,9 @@ module Util = let name = com.GetIdentifier(ctx, entName) stmts - @ [ Statement.classDef (name, body = classBody, bases = bases @ interfaces @ generics) ] + @ [ + Statement.classDef (name, body = classBody, bases = bases @ interfaces @ generics) + ] let createSlotsForRecordType (com: IPythonCompiler) ctx (classEnt: Fable.Entity) = let strFromIdent (ident: Identifier) = ident.Name @@ -3926,11 +3778,7 @@ module Util = info.Attributes |> Seq.exists (fun att -> att.Entity.FullName = Atts.entryPoint) |> function - | true -> - [ - stmt - declareEntryPoint com ctx expr - ] + | true -> [ stmt; declareEntryPoint com ctx expr ] | false -> if com.OutputType = OutputType.Library then com.AddExport membName |> ignore @@ -4073,10 +3921,7 @@ module Util = | Fable.Number _ -> Expression.boolOp ( BoolOperator.Or, - [ - identAsExpr com ctx id - Expression.intConstant 0 - ] + [ identAsExpr com ctx id; Expression.intConstant 0 ] ) | Fable.Array _ -> // Convert varArg from tuple to list. TODO: we might need to do this other places as well. diff --git a/src/Fable.Transforms/Python/Replacements.fs b/src/Fable.Transforms/Python/Replacements.fs index d891896d66..33830c3fc5 100644 --- a/src/Fable.Transforms/Python/Replacements.fs +++ b/src/Fable.Transforms/Python/Replacements.fs @@ -103,14 +103,7 @@ let makeRefFromMutableValue com ctx r t (value: Expr) = Delegate([ v ], Set(value, ValueSet, t, IdentExpr v, None), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let makeRefFromMutableField com ctx r t callee key = let getter = @@ -121,14 +114,7 @@ let makeRefFromMutableField com ctx r t callee key = Delegate([ v ], Set(callee, FieldSet(key), t, IdentExpr v, r), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] // Mutable and public module values are compiled as functions, because // values imported from ES2015 modules cannot be modified (see #986) @@ -142,26 +128,12 @@ let makeRefFromMutableFunc com ctx r t (value: Expr) = let v = makeUniqueIdent ctx t "v" let args = [ IdentExpr v ] - let info = - makeCallInfo - None - args - [ - t - Boolean - ] + let info = makeCallInfo None args [ t; Boolean ] let value = makeCall r Unit info value Delegate([ v ], value, None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let makeEqOpStrict range left right op = Operation(Binary(op, left, right), [ "strict" ], Boolean, range) @@ -269,16 +241,7 @@ let toFloat com (ctx: Context) r targetType (args: Expr list) : Expr = match args.Head.Type with | Char -> //Helper.InstanceCall(args.Head, "charCodeAt", Int32.Number, [ makeIntConst 0 ]) - Helper.LibCall( - com, - "char", - "char_code_at", - targetType, - [ - args.Head - makeIntConst 0 - ] - ) + Helper.LibCall(com, "char", "char_code_at", targetType, [ args.Head; makeIntConst 0 ]) | String -> Helper.LibCall(com, "double", "parse", targetType, args) | Number(kind, _) -> match kind with @@ -296,16 +259,7 @@ let toDecimal com (ctx: Context) r targetType (args: Expr list) : Expr = match args.Head.Type with | Char -> //Helper.InstanceCall(args.Head, "charCodeAt", Int32.Number, [ makeIntConst 0 ]) - Helper.LibCall( - com, - "char", - "char_code_at", - targetType, - [ - args.Head - makeIntConst 0 - ] - ) + Helper.LibCall(com, "char", "char_code_at", targetType, [ args.Head; makeIntConst 0 ]) |> makeDecimalFromExpr com r targetType | String -> makeDecimalFromExpr com r targetType args.Head | Number(kind, _) -> @@ -337,12 +291,7 @@ let stringToInt com (ctx: Context) r targetType (args: Expr list) : Expr = let _isFloatOrDecimal, numberModule, unsigned, bitsize = getParseParams kind - let parseArgs = - [ - makeIntConst style - makeBoolConst unsigned - makeIntConst bitsize - ] + let parseArgs = [ makeIntConst style; makeBoolConst unsigned; makeIntConst bitsize ] Helper.LibCall(com, numberModule, "parse", targetType, [ args.Head ] @ parseArgs @ args.Tail, ?loc = r) @@ -350,33 +299,14 @@ let toLong com (ctx: Context) r (unsigned: bool) targetType (args: Expr list) : let fromInteger kind arg = let kind = makeIntConst (kindIndex kind) - Helper.LibCall( - com, - "long", - "fromInteger", - targetType, - [ - arg - makeBoolConst unsigned - kind - ] - ) + Helper.LibCall(com, "long", "fromInteger", targetType, [ arg; makeBoolConst unsigned; kind ]) let sourceType = args.Head.Type match sourceType with | Char -> //Helper.InstanceCall(args.Head, "charCodeAt", Int32.Number, [ makeIntConst 0 ]) - Helper.LibCall( - com, - "char", - "char_code_at", - targetType, - [ - args.Head - makeIntConst 0 - ] - ) + Helper.LibCall(com, "char", "char_code_at", targetType, [ args.Head; makeIntConst 0 ]) |> fromInteger UInt16 | String -> stringToInt com ctx r targetType args | Number(kind, _) -> @@ -384,16 +314,7 @@ let toLong com (ctx: Context) r (unsigned: bool) targetType (args: Expr list) : | Decimal -> let n = Helper.LibCall(com, "decimal", "toNumber", Float64.Number, args) - Helper.LibCall( - com, - "long", - "fromNumber", - targetType, - [ - n - makeBoolConst unsigned - ] - ) + Helper.LibCall(com, "long", "fromNumber", targetType, [ n; makeBoolConst unsigned ]) | BigInt -> Helper.LibCall(com, "big_int", castBigIntMethod targetType, targetType, args) | Int64 | UInt64 -> Helper.LibCall(com, "long", "fromValue", targetType, args @ [ makeBoolConst unsigned ]) @@ -432,16 +353,7 @@ let toInt com (ctx: Context) r targetType (args: Expr list) = match sourceType, targetType with | Char, _ -> //Helper.InstanceCall(args.Head, "charCodeAt", targetType, [ makeIntConst 0 ]) - Helper.LibCall( - com, - "char", - "char_code_at", - targetType, - [ - args.Head - makeIntConst 0 - ] - ) + Helper.LibCall(com, "char", "char_code_at", targetType, [ args.Head; makeIntConst 0 ]) | String, _ -> stringToInt com ctx r targetType args | Number(BigInt, _), _ -> Helper.LibCall(com, "big_int", castBigIntMethod targetType, targetType, args) | Number(typeFrom, _), Number(typeTo, _) -> @@ -524,19 +436,7 @@ let applyOp (com: ICompiler) (ctx: Context) r t opName (args: Expr list) = // Floor result of integer divisions (see #172) | Number((Int8 | Int16 | Int32 | UInt8 | UInt16 | UInt32 | Int64 | UInt64 | BigInt), _) :: _ -> binOp BinaryDivide left right |> fastIntFloor - | _ -> - Helper.LibCall( - com, - "double", - "divide", - t, - [ - left - right - ], - argTypes, - ?loc = r - ) + | _ -> Helper.LibCall(com, "double", "divide", t, [ left; right ], argTypes, ?loc = r) | Operators.modulus, [ left; right ] -> binOp BinaryModulus left right | Operators.leftShift, [ left; right ] -> binOp BinaryShiftLeft left right |> truncateUnsigned // See #1530 | Operators.rightShift, [ left; right ] -> @@ -658,30 +558,10 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) = match left.Type with | Number(Decimal, _) -> - Helper.LibCall( - com, - "decimal", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "decimal", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Number(BigInt, _) -> - Helper.LibCall( - com, - "big_int", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "big_int", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Builtin(BclGuid | BclTimeSpan) | Boolean @@ -696,99 +576,28 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) = makeBinOp r Boolean left right op | Builtin(BclDateTime | BclDateTimeOffset) -> - Helper.LibCall( - com, - "date", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "date", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Builtin(FSharpSet _ | FSharpMap _) -> Helper.InstanceCall(left, "Equals", Boolean, [ right ]) |> is equal | DeclaredType _ -> - Helper.LibCall( - com, - "util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Array(t, _) -> let f = makeEqualityFunction com ctx t - Helper.LibCall( - com, - "array", - "equalsWith", - Boolean, - [ - f - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "array", "equalsWith", Boolean, [ f; left; right ], ?loc = r) |> is equal | List _ -> - Helper.LibCall( - com, - "util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | MetaType -> - Helper.LibCall( - com, - "reflection", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "reflection", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Tuple _ -> - Helper.LibCall( - com, - "util", - "equalArrays", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "util", "equalArrays", Boolean, [ left; right ], ?loc = r) |> is equal | _ -> - Helper.LibCall( - com, - "util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal /// Compare function that will call Util.compare or instance `CompareTo` as appropriate @@ -796,121 +605,22 @@ and compare (com: ICompiler) ctx r (left: Expr) (right: Expr) = let t = Int32.Number match left.Type with - | Number(Decimal, _) -> - Helper.LibCall( - com, - "decimal", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | Number(BigInt, _) -> - Helper.LibCall( - com, - "big_int", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + | Number(Decimal, _) -> Helper.LibCall(com, "decimal", "compare", t, [ left; right ], ?loc = r) + | Number(BigInt, _) -> Helper.LibCall(com, "big_int", "compare", t, [ left; right ], ?loc = r) | Builtin(BclGuid | BclTimeSpan) | Boolean | Char | String - | Number _ -> - Helper.LibCall( - com, - "util", - "comparePrimitives", - t, - [ - left - right - ], - ?loc = r - ) - | Builtin(BclDateTime | BclDateTimeOffset) -> - Helper.LibCall( - com, - "date", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | DeclaredType _ -> - Helper.LibCall( - com, - "util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + | Number _ -> Helper.LibCall(com, "util", "comparePrimitives", t, [ left; right ], ?loc = r) + | Builtin(BclDateTime | BclDateTimeOffset) -> Helper.LibCall(com, "date", "compare", t, [ left; right ], ?loc = r) + | DeclaredType _ -> Helper.LibCall(com, "util", "compare", t, [ left; right ], ?loc = r) | Array(genArg, _) -> let f = makeComparerFunction com ctx genArg // TODO: change to compareTo after main sync. See #2961 - Helper.LibCall( - com, - "array", - "compareWith", - t, - [ - f - left - right - ], - ?loc = r - ) - | List _ -> - Helper.LibCall( - com, - "util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | Tuple _ -> - Helper.LibCall( - com, - "util", - "compareArrays", - t, - [ - left - right - ], - ?loc = r - ) - | _ -> - Helper.LibCall( - com, - "util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "array", "compareWith", t, [ f; left; right ], ?loc = r) + | List _ -> Helper.LibCall(com, "util", "compare", t, [ left; right ], ?loc = r) + | Tuple _ -> Helper.LibCall(com, "util", "compareArrays", t, [ left; right ], ?loc = r) + | _ -> Helper.LibCall(com, "util", "compare", t, [ left; right ], ?loc = r) /// Boolean comparison operators like <, >, <=, >= and booleanCompare (com: ICompiler) ctx r (left: Expr) (right: Expr) op = @@ -925,15 +635,7 @@ and makeComparerFunction (com: ICompiler) ctx typArg = let y = makeUniqueIdent ctx typArg "y" let body = compare com ctx None (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) and makeComparer (com: ICompiler) ctx typArg = objExpr [ "Compare", makeComparerFunction com ctx typArg ] @@ -943,15 +645,7 @@ and makeEqualityFunction (com: ICompiler) ctx typArg = let y = makeUniqueIdent ctx typArg "y" let body = equals com ctx None true (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) let makeEqualityComparer (com: ICompiler) ctx typArg = let x = makeUniqueIdent ctx typArg "x" @@ -959,16 +653,7 @@ let makeEqualityComparer (com: ICompiler) ctx typArg = objExpr [ - "Equals", - Delegate( - [ - x - y - ], - equals com ctx None true (IdentExpr x) (IdentExpr y), - None, - Tags.empty - ) + "Equals", Delegate([ x; y ], equals com ctx None true (IdentExpr x) (IdentExpr y), None, Tags.empty) "GetHashCode", Delegate([ x ], structuralHash com None (IdentExpr x), None, Tags.empty) ] @@ -987,18 +672,7 @@ let makeMap (com: ICompiler) ctx r t methName args genArg = Helper.LibCall(com, "map", Naming.lowerFirst methName, t, args, ?loc = r) let makeDictionaryWithComparer com r t sourceSeq comparer = - Helper.LibCall( - com, - "mutable_map", - "Dictionary", - t, - [ - sourceSeq - comparer - ], - isConstructor = true, - ?loc = r - ) + Helper.LibCall(com, "mutable_map", "Dictionary", t, [ sourceSeq; comparer ], isConstructor = true, ?loc = r) let makeDictionary (com: ICompiler) ctx r t sourceSeq = match t with @@ -1008,18 +682,7 @@ let makeDictionary (com: ICompiler) ctx r t sourceSeq = | _ -> Helper.GlobalCall("dict", t, [ sourceSeq ], isConstructor = true, ?loc = r) let makeHashSetWithComparer com r t sourceSeq comparer = - Helper.LibCall( - com, - "mutable_set", - "HashSet", - t, - [ - sourceSeq - comparer - ], - isConstructor = true, - ?loc = r - ) + Helper.LibCall(com, "mutable_set", "HashSet", t, [ sourceSeq; comparer ], isConstructor = true, ?loc = r) let makeHashSet (com: ICompiler) ctx r t sourceSeq = match t with @@ -1040,14 +703,7 @@ let rec getZero (com: ICompiler) ctx (t: Type) = | Builtin BclDateTime as t -> Helper.LibCall(com, "date", "minValue", t, []) | Builtin BclDateTimeOffset as t -> Helper.LibCall(com, "DateOffset", "minValue", t, []) | Builtin(FSharpSet genArg) as t -> makeSet com ctx None t "Empty" [] genArg - | Builtin(BclKeyValuePair(k, v)) -> - makeTuple - None - true - [ - getZero com ctx k - getZero com ctx v - ] + | Builtin(BclKeyValuePair(k, v)) -> makeTuple None true [ getZero com ctx k; getZero com ctx v ] | ListSingleton(CustomOp com ctx None t "get_Zero" [] e) -> e | _ -> Value(Null Any, None) // null @@ -1062,27 +718,9 @@ let makeAddFunction (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let y = makeUniqueIdent ctx t "y" - let body = - applyOp - com - ctx - None - t - Operators.addition - [ - IdentExpr x - IdentExpr y - ] - - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.addition [ IdentExpr x; IdentExpr y ] + + Delegate([ x; y ], body, None, Tags.empty) let makeGenericAdder (com: ICompiler) ctx t = objExpr @@ -1096,27 +734,9 @@ let makeGenericAverager (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let i = makeUniqueIdent ctx (Int32.Number) "i" - let body = - applyOp - com - ctx - None - t - Operators.divideByInt - [ - IdentExpr x - IdentExpr i - ] - - Delegate( - [ - x - i - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.divideByInt [ IdentExpr x; IdentExpr i ] + + Delegate([ x; i ], body, None, Tags.empty) objExpr [ @@ -1309,22 +929,11 @@ let fableCoreLib (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp let isStatement = rest = "Statement" emitTemplate r t args isStatement template |> Some | "op_EqualsEqualsGreater", [ name; MaybeLambdaUncurriedAtCompileTime value ] -> - makeTuple - r - false - [ - name - value - ] - |> Some + makeTuple r false [ name; value ] |> Some | "createObj", _ -> Helper.LibCall(com, "util", "createObj", Any, args) |> withTag "pojo" |> Some | "keyValueList", [ caseRule; keyValueList ] -> // makePojo com ctx caseRule keyValueList - let args = - [ - keyValueList - caseRule - ] + let args = [ keyValueList; caseRule ] Helper.LibCall(com, "map_util", "keyValueList", Any, args) |> withTag "pojo" @@ -1425,29 +1034,10 @@ let fsFormat (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op _, _ -> fsharpModule com ctx r t i thisArg args | ".ctor", _, str :: (Value(NewArray(ArrayValues templateArgs, _, _), _) as values) :: _ -> - match - makeStringTemplateFrom - [| - "%s" - "%i" - |] - templateArgs - str - with + match makeStringTemplateFrom [| "%s"; "%i" |] templateArgs str with | Some v -> makeValue r v |> Some | None -> - Helper.LibCall( - com, - "string", - "interpolate", - t, - [ - str - values - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "string", "interpolate", t, [ str; values ], i.SignatureArgTypes, ?loc = r) |> Some | ".ctor", _, arg :: _ -> Helper.LibCall(com, "string", "printf", t, [ arg ], i.SignatureArgTypes, ?loc = r) @@ -1496,12 +1086,7 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o let addStep args = match args with - | [ first; last ] -> - [ - first - getOne com ctx genArg - last - ] + | [ first; last ] -> [ first; getOne com ctx genArg; last ] | _ -> args let modul, meth, args = @@ -1520,28 +1105,9 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o | "op_PipeRight", [ x; f ] | "op_PipeLeft", [ f; x ] -> curriedApply r t f [ x ] |> Some | "op_PipeRight2", [ x; y; f ] - | "op_PipeLeft2", [ f; x; y ] -> - curriedApply - r - t - f - [ - x - y - ] - |> Some + | "op_PipeLeft2", [ f; x; y ] -> curriedApply r t f [ x; y ] |> Some | "op_PipeRight3", [ x; y; z; f ] - | "op_PipeLeft3", [ f; x; y; z ] -> - curriedApply - r - t - f - [ - x - y - z - ] - |> Some + | "op_PipeLeft3", [ f; x; y; z ] -> curriedApply r t f [ x; y; z ] |> Some | "op_ComposeRight", [ f1; f2 ] -> compose com ctx r t f1 f2 |> Some | "op_ComposeLeft", [ f2; f1 ] -> compose com ctx r t f1 f2 |> Some // Strings @@ -1798,18 +1364,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | "Equals", None, [ x; y ] -> makeEqOp r x y BinaryEqual |> Some | "Equals", Some x, [ y; kind ] | "Equals", None, [ x; y; kind ] -> - let left = - Helper.LibCall( - com, - "string", - "compare", - Int32.Number, - [ - x - y - kind - ] - ) + let left = Helper.LibCall(com, "string", "compare", Int32.Number, [ x; y; kind ]) makeEqOp r left (makeIntConst 0) BinaryEqual |> Some | "GetEnumerator", Some c, _ -> getEnumerator com r t c |> Some @@ -1851,11 +1406,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt c, "rfind", t, - [ - str - Value(NumberConstant(0, Int32, NumberInfo.Empty), None) - start - ], + [ str; Value(NumberConstant(0, Int32, NumberInfo.Empty), None); start ], i.SignatureArgTypes, ?loc = r ) @@ -1896,12 +1447,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | Array _ -> arg1 | _ -> Value(NewArray(ArrayValues [ arg1 ], String, MutableArray), None) - let args = - [ - arg1 - Value(Null Any, None) - arg2 - ] + let args = [ arg1; Value(Null Any, None); arg2 ] Helper.LibCall(com, "string", "split", t, c :: args, ?loc = r) |> Some | args -> @@ -1971,13 +1517,7 @@ let formattableString (args: Expr list) = match i.CompiledName, thisArg, args with - | "Create", None, [ str; args ] -> - objExpr - [ - "str", str - "args", args - ] - |> Some + | "Create", None, [ str; args ] -> objExpr [ "str", str; "args", args ] |> Some | "get_Format", Some x, _ -> getFieldWith r t x "str" |> Some | "get_ArgumentCount", Some x, _ -> Helper.GlobalCall("len", t, [ getField x "args" ], [ t ], ?loc = r) |> Some | "GetArgument", Some x, [ idx ] -> getExpr r t (getField x "args") idx |> Some @@ -1988,18 +1528,7 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg match i.CompiledName, args with | "Cast", [ arg ] -> Some arg // Erase | "CreateEvent", [ addHandler; removeHandler; createHandler ] -> - Helper.LibCall( - com, - "event", - "createEvent", - t, - [ - addHandler - removeHandler - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "event", "createEvent", t, [ addHandler; removeHandler ], i.SignatureArgTypes, ?loc = r) |> Some | "Distinct" | "DistinctBy" | "Except" | "GroupBy" | "CountBy" as meth, args -> let meth = Naming.lowerFirst meth @@ -2017,27 +1546,9 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg let injectIndexOfArgs com ctx r genArgs args = let args = match args with - | [ ar; item; start; count ] -> - [ - ar - item - start - count - ] - | [ ar; item; start ] -> - [ - ar - item - start - makeNone (Int32.Number) - ] - | [ ar; item ] -> - [ - ar - item - makeNone (Int32.Number) - makeNone (Int32.Number) - ] + | [ ar; item; start; count ] -> [ ar; item; start; count ] + | [ ar; item; start ] -> [ ar; item; start; makeNone (Int32.Number) ] + | [ ar; item ] -> [ ar; item; makeNone (Int32.Number); makeNone (Int32.Number) ] | _ -> failwith "Unexpected number of arguments" injectArg com ctx r "Array" "indexOf" genArgs args @@ -2057,72 +1568,18 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this |> emitExpr r t [ Helper.InstanceCall(ar, "append", t, [ arg ]) ] |> Some | "Remove", Some ar, [ arg ] -> - let args = - injectArg - com - ctx - r - "Array" - "removeInPlace" - i.GenericArgs - [ - arg - ar - ] + let args = injectArg com ctx r "Array" "removeInPlace" i.GenericArgs [ arg; ar ] Helper.LibCall(com, "array", "removeInPlace", t, args, ?loc = r) |> Some | "RemoveAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "array", - "removeAllInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "array", "removeAllInPlace", t, [ arg; ar ], ?loc = r) |> Some | "FindIndex", Some ar, [ arg ] -> - Helper.LibCall( - com, - "resize_array", - "find_index", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "resize_array", "find_index", t, [ arg; ar ], ?loc = r) |> Some | "FindLastIndex", Some ar, [ arg ] -> - Helper.LibCall( - com, - "array", - "findLastIndex", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some - | "ForEach", Some ar, [ arg ] -> - Helper.LibCall( - com, - "array", - "iterate", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "array", "findLastIndex", t, [ arg; ar ], ?loc = r) |> Some + | "ForEach", Some ar, [ arg ] -> Helper.LibCall(com, "array", "iterate", t, [ arg; ar ], ?loc = r) |> Some | "GetEnumerator", Some ar, _ -> getEnumerator com r t ar |> Some // ICollection members, implemented in dictionaries and sets too. We need runtime checks (see #1120) | "get_Count", Some(MaybeCasted(ar)), _ -> @@ -2133,124 +1590,26 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | _ -> Helper.LibCall(com, "util", "count", t, [ ar ], ?loc = r) |> Some | "Clear", Some ar, _ -> Helper.LibCall(com, "Util", "clear", t, [ ar ], ?loc = r) |> Some | "Find", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "array", - "tryFind", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "array", "tryFind", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - defaultof com ctx r t - ], - ?loc = r - ) - |> Some - | "Exists", Some ar, [ arg ] -> - Helper.LibCall( - com, - "resize_array", - "exists", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; defaultof com ctx r t ], ?loc = r) |> Some + | "Exists", Some ar, [ arg ] -> Helper.LibCall(com, "resize_array", "exists", t, [ arg; ar ], ?loc = r) |> Some | "FindLast", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "array", - "tryFindBack", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "array", "tryFindBack", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - defaultof com ctx r t - ], - ?loc = r - ) - |> Some - | "FindAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "filter", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; defaultof com ctx r t ], ?loc = r) |> Some + | "FindAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "filter", t, [ arg; ar ], ?loc = r) |> Some | "AddRange", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "GetRange", Some ar, [ idx; cnt ] -> - Helper.LibCall( - com, - "Array", - "getSubArray", - t, - [ - ar - idx - cnt - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "getSubArray", t, [ ar; idx; cnt ], ?loc = r) |> Some | "Contains", Some(MaybeCasted(ar)), [ arg ] -> // emitExpr r t [ ar; arg ] "$1 in $0" |> Some - let args = - injectArg - com - ctx - r - "Array" - "contains" - i.GenericArgs - [ - arg - ar - ] + let args = injectArg com ctx r "Array" "contains" i.GenericArgs [ arg; ar ] let moduleName = match ar.Type with @@ -2261,31 +1620,9 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | "IndexOf", Some ar, args -> let args = injectIndexOfArgs com ctx r i.GenericArgs (ar :: args) Helper.LibCall(com, "array", "index_of", t, args, ?loc = r) |> Some - | "Insert", Some ar, [ idx; arg ] -> - Helper.InstanceCall( - ar, - "insert", - t, - [ - idx - arg - ], - ?loc = r - ) - |> Some + | "Insert", Some ar, [ idx; arg ] -> Helper.InstanceCall(ar, "insert", t, [ idx; arg ], ?loc = r) |> Some | "InsertRange", Some ar, [ idx; arg ] -> - Helper.LibCall( - com, - "array", - "insert_range_in_place", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "array", "insert_range_in_place", t, [ idx; arg; ar ], ?loc = r) |> Some | "RemoveRange", Some ar, args -> Helper.LibCall(com, "resize_array", "remove_range", t, args @ [ ar ], ?loc = r) @@ -2298,18 +1635,7 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this Helper.InstanceCall(ar, "sort", t, [ compareFn ], ?loc = r) |> Some | "Sort", Some ar, [ ExprType(DelegateType _) ] -> Helper.InstanceCall(ar, "sort", t, args, ?loc = r) |> Some | "Sort", Some ar, [ arg ] -> - Helper.LibCall( - com, - "array", - "sortInPlace", - t, - [ - ar - arg - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "array", "sortInPlace", t, [ ar; arg ], i.SignatureArgTypes, ?loc = r) |> Some | "ToArray", Some ar, [] -> Helper.InstanceCall(ar, "to_array", t, args, ?loc = r) |> Some | _ -> None @@ -2325,31 +1651,10 @@ let collectionExtensions = match i.CompiledName, thisArg, args with | "AddRange", None, [ ar; arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "InsertRange", None, [ ar; idx; arg ] -> - Helper.LibCall( - com, - "array", - "insert_range_in_place", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "array", "insert_range_in_place", t, [ idx; arg; ar ], ?loc = r) |> Some | _ -> None @@ -2407,18 +1712,7 @@ let arrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: E | "set_Item", Some arg, [ idx; value ] -> setExpr r arg idx value |> Some | "Copy", None, [ _source; _sourceIndex; _target; _targetIndex; _count ] -> copyToArray com r t i args | "Copy", None, [ source; target; count ] -> - copyToArray - com - r - t - i - [ - source - makeIntConst 0 - target - makeIntConst 0 - count - ] + copyToArray com r t i [ source; makeIntConst 0; target; makeIntConst 0; count ] | "IndexOf", None, args -> let args = injectIndexOfArgs com ctx r i.GenericArgs args @@ -2437,18 +1731,7 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex | Array(t2, _), value -> let value = value |> Option.defaultWith (fun () -> getZero com ctx t2) // If we don't fill the array some operations may behave unexpectedly, like Array.prototype.reduce - Helper.LibCall( - com, - "array", - "fill", - t, - [ - newArray size t2 - makeIntConst 0 - size - value - ] - ) + Helper.LibCall(com, "array", "fill", t, [ newArray size t2; makeIntConst 0; size; value ]) | _ -> $"Expecting an array type but got {t}" |> addErrorAndReturnNull com ctx.InlinePath r @@ -2648,19 +1931,7 @@ let optionModule isStruct (com: ICompiler) (ctx: Context) r (t: Type) (i: CallIn Helper.LibCall(com, "list", "ofArray", t, args, ?loc = r) |> Some | "FoldBack", [ folder; opt; state ] -> - Helper.LibCall( - com, - "seq", - "foldBack", - t, - [ - folder - toArray None t opt - state - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "seq", "foldBack", t, [ folder; toArray None t opt; state ], i.SignatureArgTypes, ?loc = r) |> Some | "DefaultValue", _ -> Helper.LibCall(com, "option", "defaultArg", t, List.rev args, ?loc = r) |> Some | "DefaultWith", _ -> @@ -2706,12 +1977,7 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op if isFloatOrDecimal then [ str ] @ outValue else - [ - str - makeIntConst style - makeBoolConst unsigned - makeIntConst bitsize - ] + [ str; makeIntConst style; makeBoolConst unsigned; makeIntConst bitsize ] @ outValue Helper.LibCall(com, numberModule, Naming.lowerFirst meth, t, args, ?loc = r) @@ -2776,14 +2042,8 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op "string", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -2850,14 +2110,8 @@ let decimals (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: "string", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -2950,17 +2204,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr | ("GenericComparison" | "GenericComparisonIntrinsic"), [ left; right ] -> compare com ctx r left right |> Some | ("FastCompareTuple2" | "FastCompareTuple3" | "FastCompareTuple4" | "FastCompareTuple5" | "GenericComparisonWithComparer" | "GenericComparisonWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Compare", - t, - [ - left - right - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(comp, "Compare", t, [ left; right ], i.SignatureArgTypes, ?loc = r) |> Some | ("GenericLessThan" | "GenericLessThanIntrinsic"), [ left; right ] -> booleanCompare com ctx r left right BinaryLess |> Some @@ -2976,17 +2220,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr equals com ctx r true left right |> Some | ("FastEqualsTuple2" | "FastEqualsTuple3" | "FastEqualsTuple4" | "FastEqualsTuple5" | "GenericEqualityWithComparer" | "GenericEqualityWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Equals", - t, - [ - left - right - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(comp, "Equals", t, [ left; right ], i.SignatureArgTypes, ?loc = r) |> Some | ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> makeEqOp r left right BinaryEqual |> Some | ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] -> @@ -3016,17 +2250,7 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr //getExpr None (Int32.Number) ar (makeStrConst "length2") | _ -> add upper (makeIntConst 1) - Helper.InstanceCall( - ar, - "slice", - t, - [ - lower - upper - ], - ?loc = r - ) - |> Some + Helper.InstanceCall(ar, "slice", t, [ lower; upper ], ?loc = r) |> Some | "SetArraySlice", None, args -> Helper.LibCall(com, "array", "setSlice", t, args, i.SignatureArgTypes, ?loc = r) |> Some @@ -3122,17 +2346,7 @@ let dictionaries (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | "ContainsValue", _ -> match thisArg, args with | Some c, [ arg ] -> - Helper.LibCall( - com, - "map_util", - "contains_value", - t, - [ - arg - c - ], - ?loc = r - ) + Helper.LibCall(com, "map_util", "contains_value", t, [ arg; c ], ?loc = r) |> Some | _ -> None | "TryGetValue", _ -> @@ -3175,19 +2389,7 @@ let hashSets (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op | ReplaceName [ "Clear", "clear"; "Contains", "has"; "Remove", "delete" ] methName, Some c, args -> Helper.InstanceCall(c, methName, t, args, i.SignatureArgTypes, ?loc = r) |> Some | "GetEnumerator", Some c, _ -> getEnumerator com r t c |> Some - | "Add", Some c, [ arg ] -> - Helper.LibCall( - com, - "map_util", - "addToSet", - t, - [ - arg - c - ], - ?loc = r - ) - |> Some + | "Add", Some c, [ arg ] -> Helper.LibCall(com, "map_util", "addToSet", t, [ arg; c ], ?loc = r) |> Some | ("IsProperSubsetOf" | "IsProperSupersetOf" | "UnionWith" | "IntersectWith" | "ExceptWith" | "IsSubsetOf" | "IsSupersetOf" as meth), Some c, args -> @@ -3261,17 +2463,9 @@ let enums (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio let args = match meth, args with // TODO: Parse at compile time if we know the type - | "parseEnum", [ value ] -> - [ - makeTypeInfo None t - value - ] + | "parseEnum", [ value ] -> [ makeTypeInfo None t; value ] | "tryParseEnum", [ value; refValue ] -> - [ - genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None - value - refValue - ] + [ genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None; value; refValue ] | _ -> args Helper.LibCall(com, "Reflection", meth, t, args, ?loc = r) |> Some @@ -3407,17 +2601,11 @@ let private ignoreFormatProvider com (ctx: Context) r (moduleName: string) meth | "TryParse", input :: _culture :: _styles :: defVal :: _ -> addWarning com ctx.InlinePath r $"%s{moduleName}.TryParse will ignore culture and styles" - [ - input - defVal - ] + [ input; defVal ] | "TryParse", input :: _culture :: defVal :: _ -> addWarning com ctx.InlinePath r $"%s{moduleName}.TryParse will ignore culture" - [ - input - defVal - ] + [ input; defVal ] | _ -> args let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Expr list) = @@ -3445,37 +2633,16 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio match args.Length, last.Type with | 7, Number(_, NumberInfo.IsEnum ent) when ent.FullName = "System.DateTimeKind" -> - let args = - (List.take 6 args) - @ [ - makeIntConst 0 - makeIntConst 0 - last - ] + let args = (List.take 6 args) @ [ makeIntConst 0; makeIntConst 0; last ] let argTypes = - (List.take 6 i.SignatureArgTypes) - @ [ - Int32.Number - Int32.Number - last.Type - ] + (List.take 6 i.SignatureArgTypes) @ [ Int32.Number; Int32.Number; last.Type ] Helper.LibCall(com, "Date", "create", t, args, argTypes, ?loc = r) |> Some | 8, Number(_, NumberInfo.IsEnum ent) when ent.FullName = "System.DateTimeKind" -> - let args = - (List.take 7 args) - @ [ - makeIntConst 0 - last - ] + let args = (List.take 7 args) @ [ makeIntConst 0; last ] - let argTypes = - (List.take 7 i.SignatureArgTypes) - @ [ - Int32.Number - last.Type - ] + let argTypes = (List.take 7 i.SignatureArgTypes) @ [ Int32.Number; last.Type ] Helper.LibCall(com, "Date", "create", t, args, argTypes, ?loc = r) |> Some | _ -> @@ -3504,14 +2671,8 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio "Date", "fromDateTimeOffset", t, - [ - thisArg.Value - kind - ], - [ - thisArg.Value.Type - kind.Type - ], + [ thisArg.Value; kind ], + [ thisArg.Value.Type; kind.Type ], ?loc = r ) |> Some @@ -3531,14 +2692,8 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio "DateOffset", "datetime.fromtimestamp", t, - [ - value - makeIntConst 0 - ], - [ - value.Type - Int32.Number - ], + [ value; makeIntConst 0 ], + [ value.Type; Int32.Number ], ?loc = r ) |> Some @@ -3565,34 +2720,14 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio "long", "op_Division", i.SignatureArgTypes.Head, - [ - ticks - makeIntConst 10000 - ], - [ - ticks.Type - Int32.Number - ] + [ ticks; makeIntConst 10000 ], + [ ticks.Type; Int32.Number ] ) let ms = Helper.LibCall(com, "long", "toNumber", Float64.Number, [ ms ], [ ms.Type ]) - Helper.LibCall( - com, - moduleName, - "addMilliseconds", - Float64.Number, - [ - c - ms - ], - [ - c.Type - ms.Type - ], - ?loc = r - ) + Helper.LibCall(com, moduleName, "addMilliseconds", Float64.Number, [ c; ms ], [ c.Type; ms.Type ], ?loc = r) |> Some | _ -> None | meth -> @@ -3687,21 +2822,7 @@ let random (com: ICompiler) (ctx: Context) r t (i: CallInfo) (_: Expr option) (a | [ min; max ] -> min, max | _ -> FableError "Unexpected arg count for Random.Next" |> raise - Helper.LibCall( - com, - "util", - "randint", - t, - [ - min - max - ], - [ - min.Type - max.Type - ], - ?loc = r - ) + Helper.LibCall(com, "util", "randint", t, [ min; max ], [ min.Type; max.Type ], ?loc = r) |> Some | "NextDouble" -> Helper.ImportedCall("random", "random", t, [], []) |> Some | "NextBytes" -> @@ -3814,18 +2935,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp | "get_Success" -> nullCheck r false thisArg.Value |> Some // MatchCollection & GroupCollection | "get_Item" when i.DeclaringEntityFullName = Types.regexGroupCollection -> - Helper.LibCall( - com, - "RegExp", - "get_item", - t, - [ - thisArg.Value - args.Head - ], - [ thisArg.Value.Type ], - ?loc = r - ) + Helper.LibCall(com, "RegExp", "get_item", t, [ thisArg.Value; args.Head ], [ thisArg.Value.Type ], ?loc = r) |> Some | "get_Item" -> getExpr r t thisArg.Value args.Head |> Some | "get_Count" -> Helper.GlobalCall("len", t, [ thisArg.Value ], [ t ], ?loc = r) |> Some @@ -3843,11 +2953,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp | None, input :: pattern :: args -> let reg = createRegex None Any (pattern :: args) - [ - reg - input - ] - |> Some + [ reg; input ] |> Some | _ -> None |> Option.map (fun args -> Helper.LibCall(com, "RegExp", Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc = r) @@ -3964,17 +3070,7 @@ let asyncBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | _, "Singleton", _ -> makeImportLib com t "singleton" "async_builder" |> Some // For Using we need to cast the argument to IDisposable | Some x, "Using", [ arg; f ] -> - Helper.InstanceCall( - x, - "Using", - t, - [ - arg - f - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(x, "Using", t, [ arg; f ], i.SignatureArgTypes, ?loc = r) |> Some | Some x, meth, _ -> Helper.InstanceCall(x, meth, t, args, i.SignatureArgTypes, ?loc = r) |> Some | None, meth, _ -> @@ -4060,30 +3156,10 @@ let taskBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr // For Using we need to cast the argument to IDisposable | Some x, "Using", [ arg; f ] | Some x, "TaskBuilderBase.Using", [ arg; f ] -> - Helper.InstanceCall( - x, - "Using", - t, - [ - arg - f - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(x, "Using", t, [ arg; f ], i.SignatureArgTypes, ?loc = r) |> Some | Some x, "TaskBuilderBase.Bind", [ arg; f ] -> - Helper.InstanceCall( - x, - "Bind", - t, - [ - arg - f - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(x, "Bind", t, [ arg; f ], i.SignatureArgTypes, ?loc = r) |> Some | Some x, "TaskBuilderBase.ReturnFrom", [ arg ] -> Helper.InstanceCall(x, "ReturnFrom", t, [ arg ], i.SignatureArgTypes, ?loc = r) @@ -4618,27 +3694,12 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.dictionary -> let args = match argTypes.Value, args with - | ([] | [ Number _ ]), _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] + | ([] | [ Number _ ]), _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] | [ IEqualityComparer ], [ eqComp ] | [ Number _; IEqualityComparer ], [ _; eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected dictionary constructor" |> raise let entityName = Naming.cleanNameAsPyIdentifier "Dictionary" @@ -4646,26 +3707,10 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.hashset -> let args = match argTypes.Value, args with - | [], _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] - | [ IEqualityComparer ], [ eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + | [], _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] + | [ IEqualityComparer ], [ eqComp ] -> [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected hashset constructor" |> raise let entityName = Naming.cleanNameAsPyIdentifier "HashSet" @@ -4700,43 +3745,11 @@ let tryType = | BclDateTimeOffset -> Some(Types.datetimeOffset, dates, []) | BclTimer -> Some("System.Timers.Timer", timers, []) | BclHashSet genArg -> Some(Types.hashset, hashSets, [ genArg ]) - | BclDictionary(key, value) -> - Some( - Types.dictionary, - dictionaries, - [ - key - value - ] - ) - | BclKeyValuePair(key, value) -> - Some( - Types.keyValuePair, - keyValuePairs, - [ - key - value - ] - ) - | FSharpMap(key, value) -> - Some( - Types.fsharpMap, - maps, - [ - key - value - ] - ) + | BclDictionary(key, value) -> Some(Types.dictionary, dictionaries, [ key; value ]) + | BclKeyValuePair(key, value) -> Some(Types.keyValuePair, keyValuePairs, [ key; value ]) + | FSharpMap(key, value) -> Some(Types.fsharpMap, maps, [ key; value ]) | FSharpSet genArg -> Some(Types.fsharpSet, sets, [ genArg ]) - | FSharpResult(genArg1, genArg2) -> - Some( - Types.result, - results, - [ - genArg1 - genArg2 - ] - ) + | FSharpResult(genArg1, genArg2) -> Some(Types.result, results, [ genArg1; genArg2 ]) | FSharpChoice genArgs -> Some($"{Types.choiceNonGeneric}`{List.length genArgs}", results, genArgs) | FSharpReference genArg -> Some(Types.refCell, refCells, [ genArg ]) | BclDateOnly diff --git a/src/Fable.Transforms/Replacements.Util.fs b/src/Fable.Transforms/Replacements.Util.fs index 94e98ab7a9..f524e40184 100644 --- a/src/Fable.Transforms/Replacements.Util.fs +++ b/src/Fable.Transforms/Replacements.Util.fs @@ -577,16 +577,7 @@ let curryExprAtRuntime (com: Compiler) arity (expr: Expr) = let curried = partialApplyAtRuntime com t arity fe [] let fn = Delegate([ f ], curried, None, Tags.empty) // TODO: This may be different per language - Helper.LibCall( - com, - "Option", - "map", - Option(curried.Type, isStruct), - [ - fn - expr - ] - ) + Helper.LibCall(com, "Option", "map", Option(curried.Type, isStruct), [ fn; expr ]) | _ -> partialApplyAtRuntime com expr.Type arity expr [] let uncurryExprAtRuntime (com: Compiler) arity (expr: Expr) = @@ -643,16 +634,7 @@ let uncurryExprAtRuntime (com: Compiler) arity (expr: Expr) = let uncurried = uncurry (IdentExpr f) let fn = Delegate([ f ], uncurried, None, Tags.empty) // TODO: This may be different per language - Helper.LibCall( - com, - "Option", - "map", - Option(uncurried.Type, isStruct), - [ - fn - expr - ] - ) + Helper.LibCall(com, "Option", "map", Option(uncurried.Type, isStruct), [ fn; expr ]) | expr -> uncurry expr let (|Namesof|_|) com ctx e = namesof com ctx [] e @@ -912,14 +894,7 @@ let (|UniversalFableCoreHelpers|_|) (com: ICompiler) (ctx: Context) r t (i: Call match args with | [ Nameof com ctx name as arg ] -> if meth = "nameof2" then - makeTuple - r - true - [ - makeStrConst name - arg - ] - |> Some + makeTuple r true [ makeStrConst name; arg ] |> Some else makeStrConst name |> Some | _ -> @@ -983,15 +958,7 @@ let (|UniversalFableCoreHelpers|_|) (com: ICompiler) (ctx: Context) r t (i: Call Some(Naming.unknown, -1) ) - |> Option.map (fun (s, i) -> - makeTuple - r - true - [ - makeStrConst s - makeIntConst i - ] - ) + |> Option.map (fun (s, i) -> makeTuple r true [ makeStrConst s; makeIntConst i ]) | _ -> None diff --git a/src/Fable.Transforms/Replacements.fs b/src/Fable.Transforms/Replacements.fs index dfe79f9db1..c3d3196831 100644 --- a/src/Fable.Transforms/Replacements.fs +++ b/src/Fable.Transforms/Replacements.fs @@ -126,14 +126,7 @@ let makeRefFromMutableValue com ctx r t (value: Expr) = Delegate([ v ], Set(value, ValueSet, t, IdentExpr v, None), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let makeRefFromMutableField com ctx r t callee key = let getter = @@ -144,14 +137,7 @@ let makeRefFromMutableField com ctx r t callee key = Delegate([ v ], Set(callee, FieldSet(key), t, IdentExpr v, r), None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] // Mutable and public module values are compiled as functions, because // values imported from ES2015 modules cannot be modified (see #986) @@ -165,26 +151,12 @@ let makeRefFromMutableFunc com ctx r t (value: Expr) = let v = makeUniqueIdent ctx t "v" let args = [ IdentExpr v ] - let info = - makeCallInfo - None - args - [ - t - Boolean - ] + let info = makeCallInfo None args [ t; Boolean ] let value = makeCall r Unit info value Delegate([ v ], value, None, Tags.empty) - makeRefCell - com - r - t - [ - getter - setter - ] + makeRefCell com r t [ getter; setter ] let toChar (arg: Expr) = match arg.Type with @@ -306,12 +278,7 @@ let stringToInt com (ctx: Context) r targetType (args: Expr list) : Expr = let style = int System.Globalization.NumberStyles.Any let _isFloatOrDecimal, numberModule, unsigned, bitsize = getParseParams kind - let parseArgs = - [ - makeIntConst style - makeBoolConst unsigned - makeIntConst bitsize - ] + let parseArgs = [ makeIntConst style; makeBoolConst unsigned; makeIntConst bitsize ] Helper.LibCall(com, numberModule, "parse", targetType, [ args.Head ] @ parseArgs @ args.Tail, ?loc = r) @@ -564,30 +531,10 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) = match left.Type with | Number(Decimal, _) -> - Helper.LibCall( - com, - "Decimal", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Decimal", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Number(BigIntegers _, _) -> - Helper.LibCall( - com, - "BigInt", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "BigInt", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Builtin(BclGuid | BclTimeSpan | BclTimeOnly) | Boolean @@ -606,86 +553,25 @@ let rec equals (com: ICompiler) ctx r equal (left: Expr) (right: Expr) = // We will call Reflection.equals in the Fable2Babel step //| MetaType -> Helper.LibCall(com, "Reflection", "equals", Boolean, [left; right], ?loc=r) |> is equal | Builtin(BclDateTime | BclDateTimeOffset | BclDateOnly) -> - Helper.LibCall( - com, - "Date", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Date", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Builtin(FSharpSet _ | FSharpMap _) -> Helper.InstanceCall(left, "Equals", Boolean, [ right ]) |> is equal | DeclaredType _ -> - Helper.LibCall( - com, - "Util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Array(t, _) -> let f = makeEqualityFunction com ctx t - Helper.LibCall( - com, - "Array", - "equalsWith", - Boolean, - [ - f - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "equalsWith", Boolean, [ f; left; right ], ?loc = r) |> is equal | List _ -> - Helper.LibCall( - com, - "Util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal | Tuple _ -> - Helper.LibCall( - com, - "Util", - "equalArrays", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equalArrays", Boolean, [ left; right ], ?loc = r) |> is equal | _ -> - Helper.LibCall( - com, - "Util", - "equals", - Boolean, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "equals", Boolean, [ left; right ], ?loc = r) |> is equal /// Compare function that will call Util.compare or instance `CompareTo` as appropriate @@ -693,121 +579,23 @@ and compare (com: ICompiler) ctx r (left: Expr) (right: Expr) = let t = Int32.Number match left.Type with - | Number(Decimal, _) -> - Helper.LibCall( - com, - "Decimal", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | Number(BigIntegers _, _) -> - Helper.LibCall( - com, - "BigInt", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + | Number(Decimal, _) -> Helper.LibCall(com, "Decimal", "compare", t, [ left; right ], ?loc = r) + | Number(BigIntegers _, _) -> Helper.LibCall(com, "BigInt", "compare", t, [ left; right ], ?loc = r) | Builtin(BclGuid | BclTimeSpan | BclTimeOnly) | Boolean | Char | String - | Number _ -> - Helper.LibCall( - com, - "Util", - "comparePrimitives", - t, - [ - left - right - ], - ?loc = r - ) + | Number _ -> Helper.LibCall(com, "Util", "comparePrimitives", t, [ left; right ], ?loc = r) | Builtin(BclDateTime | BclDateTimeOffset | BclDateOnly) -> - Helper.LibCall( - com, - "Date", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | DeclaredType _ -> - Helper.LibCall( - com, - "Util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Date", "compare", t, [ left; right ], ?loc = r) + | DeclaredType _ -> Helper.LibCall(com, "Util", "compare", t, [ left; right ], ?loc = r) | Array(t, _) -> let f = makeComparerFunction com ctx t // Note Array.compareWith doesn't check the length first, see #2961 - Helper.LibCall( - com, - "Array", - "compareTo", - t, - [ - f - left - right - ], - ?loc = r - ) - | List _ -> - Helper.LibCall( - com, - "Util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | Tuple _ -> - Helper.LibCall( - com, - "Util", - "compareArrays", - t, - [ - left - right - ], - ?loc = r - ) - | _ -> - Helper.LibCall( - com, - "Util", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "compareTo", t, [ f; left; right ], ?loc = r) + | List _ -> Helper.LibCall(com, "Util", "compare", t, [ left; right ], ?loc = r) + | Tuple _ -> Helper.LibCall(com, "Util", "compareArrays", t, [ left; right ], ?loc = r) + | _ -> Helper.LibCall(com, "Util", "compare", t, [ left; right ], ?loc = r) /// Boolean comparison operators like <, >, <=, >= and booleanCompare (com: ICompiler) ctx r (left: Expr) (right: Expr) op = @@ -822,15 +610,7 @@ and makeComparerFunction (com: ICompiler) ctx typArg = let y = makeUniqueIdent ctx typArg "y" let body = compare com ctx None (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) and makeComparer (com: ICompiler) ctx typArg = objExpr [ "Compare", makeComparerFunction com ctx typArg ] @@ -840,15 +620,7 @@ and makeEqualityFunction (com: ICompiler) ctx typArg = let y = makeUniqueIdent ctx typArg "y" let body = equals com ctx None true (IdentExpr x) (IdentExpr y) - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + Delegate([ x; y ], body, None, Tags.empty) let makeEqualityComparer (com: ICompiler) ctx typArg = let x = makeUniqueIdent ctx typArg "x" @@ -856,16 +628,7 @@ let makeEqualityComparer (com: ICompiler) ctx typArg = objExpr [ - "Equals", - Delegate( - [ - x - y - ], - equals com ctx None true (IdentExpr x) (IdentExpr y), - None, - Tags.empty - ) + "Equals", Delegate([ x; y ], equals com ctx None true (IdentExpr x) (IdentExpr y), None, Tags.empty) "GetHashCode", Delegate([ x ], structuralHash com None (IdentExpr x), None, Tags.empty) ] @@ -884,18 +647,7 @@ let makeMap (com: ICompiler) ctx r t methName args genArg = Helper.LibCall(com, "Map", Naming.lowerFirst methName, t, args, ?loc = r) let makeDictionaryWithComparer com r t sourceSeq comparer = - Helper.LibCall( - com, - "MutableMap", - "Dictionary", - t, - [ - sourceSeq - comparer - ], - isConstructor = true, - ?loc = r - ) + Helper.LibCall(com, "MutableMap", "Dictionary", t, [ sourceSeq; comparer ], isConstructor = true, ?loc = r) let makeDictionary (com: ICompiler) ctx r t sourceSeq = match t with @@ -905,18 +657,7 @@ let makeDictionary (com: ICompiler) ctx r t sourceSeq = | _ -> Helper.GlobalCall("Map", t, [ sourceSeq ], isConstructor = true, ?loc = r) let makeHashSetWithComparer com r t sourceSeq comparer = - Helper.LibCall( - com, - "MutableSet", - "HashSet", - t, - [ - sourceSeq - comparer - ], - isConstructor = true, - ?loc = r - ) + Helper.LibCall(com, "MutableSet", "HashSet", t, [ sourceSeq; comparer ], isConstructor = true, ?loc = r) let makeHashSet (com: ICompiler) ctx r t sourceSeq = match t with @@ -936,14 +677,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | Builtin BclDateTimeOffset as t -> Helper.LibCall(com, "DateOffset", "minValue", t, []) | Builtin BclDateOnly as t -> Helper.LibCall(com, "DateOnly", "minValue", t, []) | Builtin(FSharpSet genArg) as t -> makeSet com ctx None t "Empty" [] genArg - | Builtin(BclKeyValuePair(k, v)) -> - makeTuple - None - true - [ - getZero com ctx k - getZero com ctx v - ] + | Builtin(BclKeyValuePair(k, v)) -> makeTuple None true [ getZero com ctx k; getZero com ctx v ] | ListSingleton(CustomOp com ctx None t "get_Zero" [] e) -> e | _ -> Value(Null Any, None) // null @@ -958,27 +692,9 @@ let makeAddFunction (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let y = makeUniqueIdent ctx t "y" - let body = - applyOp - com - ctx - None - t - Operators.addition - [ - IdentExpr x - IdentExpr y - ] - - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.addition [ IdentExpr x; IdentExpr y ] + + Delegate([ x; y ], body, None, Tags.empty) let makeGenericAdder (com: ICompiler) ctx t = objExpr @@ -992,27 +708,9 @@ let makeGenericAverager (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let i = makeUniqueIdent ctx (Int32.Number) "i" - let body = - applyOp - com - ctx - None - t - Operators.divideByInt - [ - IdentExpr x - IdentExpr i - ] - - Delegate( - [ - x - i - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.divideByInt [ IdentExpr x; IdentExpr i ] + + Delegate([ x; i ], body, None, Tags.empty) objExpr [ @@ -1339,22 +1037,11 @@ let fableCoreLib (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp let isStatement = rest = "Statement" emitTemplate r t args isStatement template |> Some | "op_EqualsEqualsGreater", [ name; MaybeLambdaUncurriedAtCompileTime value ] -> - makeTuple - r - true - [ - name - value - ] - |> Some + makeTuple r true [ name; value ] |> Some | "createObj", _ -> Helper.LibCall(com, "Util", "createObj", Any, args) |> withTag "pojo" |> Some | "keyValueList", [ caseRule; keyValueList ] -> // makePojo com ctx caseRule keyValueList - let args = - [ - keyValueList - caseRule - ] + let args = [ keyValueList; caseRule ] Helper.LibCall(com, "MapUtil", "keyValueList", Any, args) |> withTag "pojo" @@ -1486,29 +1173,10 @@ let fsFormat (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op _, _ -> fsharpModule com ctx r t i thisArg args | ".ctor", _, str :: (Value(NewArray(ArrayValues templateArgs, _, _), _) as values) :: _ -> - match - makeStringTemplateFrom - [| - "%s" - "%i" - |] - templateArgs - str - with + match makeStringTemplateFrom [| "%s"; "%i" |] templateArgs str with | Some v -> makeValue r v |> Some | None -> - Helper.LibCall( - com, - "String", - "interpolate", - t, - [ - str - values - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "String", "interpolate", t, [ str; values ], i.SignatureArgTypes, ?loc = r) |> Some | ".ctor", _, arg :: _ -> Helper.LibCall(com, "String", "printf", t, [ arg ], i.SignatureArgTypes, ?loc = r) @@ -1553,12 +1221,7 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o let addStep args = match args with - | [ first; last ] -> - [ - first - getOne com ctx genArg - last - ] + | [ first; last ] -> [ first; getOne com ctx genArg; last ] | _ -> args let modul, meth, args = @@ -1576,28 +1239,9 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o | "op_PipeRight", [ x; f ] | "op_PipeLeft", [ f; x ] -> curriedApply r t f [ x ] |> Some | "op_PipeRight2", [ x; y; f ] - | "op_PipeLeft2", [ f; x; y ] -> - curriedApply - r - t - f - [ - x - y - ] - |> Some + | "op_PipeLeft2", [ f; x; y ] -> curriedApply r t f [ x; y ] |> Some | "op_PipeRight3", [ x; y; z; f ] - | "op_PipeLeft3", [ f; x; y; z ] -> - curriedApply - r - t - f - [ - x - y - z - ] - |> Some + | "op_PipeLeft3", [ f; x; y; z ] -> curriedApply r t f [ x; y; z ] |> Some | "op_ComposeRight", [ f1; f2 ] -> compose com ctx r t f1 f2 |> Some | "op_ComposeLeft", [ f2; f1 ] -> compose com ctx r t f1 f2 |> Some // Strings @@ -1858,18 +1502,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | "Equals", None, [ x; y ] -> makeEqOp r x y BinaryEqual |> Some | "Equals", Some x, [ y; kind ] | "Equals", None, [ x; y; kind ] -> - let left = - Helper.LibCall( - com, - "String", - "compare", - Int32.Number, - [ - x - y - kind - ] - ) + let left = Helper.LibCall(com, "String", "compare", Int32.Number, [ x; y; kind ]) makeEqOp r left (makeIntConst 0) BinaryEqual |> Some | "GetEnumerator", Some c, _ -> stringToCharArray c |> getEnumerator com r t |> Some @@ -1953,12 +1586,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | Array _ -> arg1 | _ -> Value(NewArray(ArrayValues [ arg1 ], String, MutableArray), None) - let args = - [ - arg1 - makeNone (Int32.Number) - arg2 - ] + let args = [ arg1; makeNone (Int32.Number); arg2 ] Helper.LibCall(com, "String", "split", t, c :: args, ?loc = r) |> Some | arg1 :: args -> @@ -2084,18 +1712,7 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg match i.CompiledName, args with | "Cast", _ -> Helper.LibCall(com, "Util", "downcast", t, args) |> withTag "downcast" |> Some | "CreateEvent", [ addHandler; removeHandler; _createHandler ] -> - Helper.LibCall( - com, - "Event", - "createEvent", - t, - [ - addHandler - removeHandler - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "Event", "createEvent", t, [ addHandler; removeHandler ], i.SignatureArgTypes, ?loc = r) |> Some | ("Distinct" | "DistinctBy" | "Except" | "GroupBy" | "CountBy" as meth), args -> let meth = Naming.lowerFirst meth @@ -2123,27 +1740,9 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg let injectIndexOfArgs com ctx r genArgs args = let args = match args with - | [ ar; item; start; count ] -> - [ - ar - item - start - count - ] - | [ ar; item; start ] -> - [ - ar - item - start - makeNone (Int32.Number) - ] - | [ ar; item ] -> - [ - ar - item - makeNone (Int32.Number) - makeNone (Int32.Number) - ] + | [ ar; item; start; count ] -> [ ar; item; start; count ] + | [ ar; item; start ] -> [ ar; item; start; makeNone (Int32.Number) ] + | [ ar; item ] -> [ ar; item; makeNone (Int32.Number); makeNone (Int32.Number) ] | _ -> failwith "Unexpected number of arguments" injectArg com ctx r "Array" "indexOf" genArgs args @@ -2166,47 +1765,15 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this |> emitExpr r t [ Helper.InstanceCall(ar, "push", t, [ arg ]) ] |> Some | "Remove", Some ar, [ arg ] -> - let args = - injectArg - com - ctx - r - "Array" - "removeInPlace" - i.GenericArgs - [ - arg - ar - ] + let args = injectArg com ctx r "Array" "removeInPlace" i.GenericArgs [ arg; ar ] Helper.LibCall(com, "Array", "removeInPlace", t, args, ?loc = r) |> Some | "RemoveAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "removeAllInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "removeAllInPlace", t, [ arg; ar ], ?loc = r) |> Some | "FindIndex", Some ar, [ arg ] -> Helper.InstanceCall(ar, "findIndex", t, [ arg ], ?loc = r) |> Some | "FindLastIndex", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "findLastIndex", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "findLastIndex", t, [ arg; ar ], ?loc = r) |> Some | "ForEach", Some ar, [ arg ] -> Helper.InstanceCall(ar, "forEach", t, [ arg ], ?loc = r) |> Some | "GetEnumerator", Some ar, _ -> getEnumerator com r t ar |> Some // ICollection members, implemented in dictionaries and sets too. We need runtime checks (see #1120) @@ -2217,128 +1784,30 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | Array _ -> getFieldWith r t ar "length" |> Some | _ -> Helper.LibCall(com, "Util", "count", t, [ ar ], ?loc = r) |> Some | "Clear", Some ar, _ -> Helper.LibCall(com, "Util", "clear", t, [ ar ], ?loc = r) |> Some - | "ConvertAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + | "ConvertAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "map", t, [ arg; ar ], ?loc = r) |> Some | "Find", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "Array", - "tryFind", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "Array", "tryFind", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - defaultof com ctx r t - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; defaultof com ctx r t ], ?loc = r) |> Some | "Exists", Some ar, [ arg ] -> let left = Helper.InstanceCall(ar, "findIndex", Int32.Number, [ arg ], ?loc = r) makeEqOp r left (makeIntConst -1) BinaryGreater |> Some | "FindLast", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "Array", - "tryFindBack", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "Array", "tryFindBack", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - defaultof com ctx r t - ], - ?loc = r - ) - |> Some - | "FindAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "filter", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; defaultof com ctx r t ], ?loc = r) |> Some + | "FindAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "filter", t, [ arg; ar ], ?loc = r) |> Some | "AddRange", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "GetRange", Some ar, [ idx; cnt ] -> - Helper.LibCall( - com, - "Array", - "getSubArray", - t, - [ - ar - idx - cnt - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "getSubArray", t, [ ar; idx; cnt ], ?loc = r) |> Some | "Contains", Some(MaybeCasted(ar)), [ arg ] -> - let args = - injectArg - com - ctx - r - "Array" - "contains" - i.GenericArgs - [ - arg - ar - ] + let args = injectArg com ctx r "Array" "contains" i.GenericArgs [ arg; ar ] let moduleName = match ar.Type with @@ -2350,45 +1819,13 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this let args = injectIndexOfArgs com ctx r i.GenericArgs (ar :: args) Helper.LibCall(com, "Array", "indexOf", t, args, ?loc = r) |> Some | "Insert", Some ar, [ idx; arg ] -> - Helper.InstanceCall( - ar, - "splice", - t, - [ - idx - makeIntConst 0 - arg - ], - ?loc = r - ) + Helper.InstanceCall(ar, "splice", t, [ idx; makeIntConst 0; arg ], ?loc = r) |> Some | "InsertRange", Some ar, [ idx; arg ] -> - Helper.LibCall( - com, - "Array", - "insertRangeInPlace", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "insertRangeInPlace", t, [ idx; arg; ar ], ?loc = r) |> Some | "RemoveRange", Some ar, args -> Helper.InstanceCall(ar, "splice", t, args, ?loc = r) |> Some - | "RemoveAt", Some ar, [ idx ] -> - Helper.InstanceCall( - ar, - "splice", - t, - [ - idx - makeIntConst 1 - ], - ?loc = r - ) - |> Some + | "RemoveAt", Some ar, [ idx ] -> Helper.InstanceCall(ar, "splice", t, [ idx; makeIntConst 1 ], ?loc = r) |> Some | "Reverse", Some ar, [] -> Helper.InstanceCall(ar, "reverse", t, args, ?loc = r) |> Some | "Sort", Some ar, [] -> let compareFn = (genArg com ctx r 0 i.GenericArgs) |> makeComparerFunction com ctx @@ -2396,18 +1833,7 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this Helper.InstanceCall(ar, "sort", t, [ compareFn ], ?loc = r) |> Some | "Sort", Some ar, [ ExprType(DelegateType _) ] -> Helper.InstanceCall(ar, "sort", t, args, ?loc = r) |> Some | "Sort", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "sortInPlace", - t, - [ - ar - arg - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "Array", "sortInPlace", t, [ ar; arg ], i.SignatureArgTypes, ?loc = r) |> Some | "ToArray", Some ar, [] -> Helper.InstanceCall(ar, "slice", t, args, ?loc = r) |> Some | _ -> None @@ -2423,31 +1849,10 @@ let collectionExtensions = match i.CompiledName, thisArg, args with | "AddRange", None, [ ar; arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "InsertRange", None, [ ar; idx; arg ] -> - Helper.LibCall( - com, - "Array", - "insertRangeInPlace", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "insertRangeInPlace", t, [ idx; arg; ar ], ?loc = r) |> Some | _ -> None @@ -2505,31 +1910,9 @@ let arrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: E | "set_Item", Some arg, [ idx; value ] -> setExpr r arg idx value |> Some | "Copy", None, [ _source; _sourceIndex; _target; _targetIndex; _count ] -> copyToArray com r t i args | "Copy", None, [ source; target; count ] -> - copyToArray - com - r - t - i - [ - source - makeIntConst 0 - target - makeIntConst 0 - count - ] + copyToArray com r t i [ source; makeIntConst 0; target; makeIntConst 0; count ] | "ConvertAll", None, [ source; mapping ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - mapping - source - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "map", t, [ mapping; source ], ?loc = r) |> Some | "IndexOf", None, args -> let args = injectIndexOfArgs com ctx r i.GenericArgs args @@ -2555,18 +1938,7 @@ let arrayModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (_: Ex | Array(t2, _), value -> let value = value |> Option.defaultWith (fun () -> getZero com ctx t2) // If we don't fill the array some operations may behave unexpectedly, like Array.prototype.reduce - Helper.LibCall( - com, - "Array", - "fill", - t, - [ - newArrayAlloc size t2 - makeIntConst 0 - size - value - ] - ) + Helper.LibCall(com, "Array", "fill", t, [ newArrayAlloc size t2; makeIntConst 0; size; value ]) | _ -> $"Expecting an array type but got %A{t}" |> addErrorAndReturnNull com ctx.InlinePath r @@ -2795,11 +2167,7 @@ let optionModule isStruct (com: ICompiler) (ctx: Context) r (t: Type) (i: CallIn "Seq", "foldBack", t, - [ - folder - toArray None t opt - state - ], + [ folder; toArray None t opt; state ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r @@ -2868,12 +2236,7 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op if isFloatOrDecimal then [ str ] @ outValue else - [ - str - makeIntConst style - makeBoolConst unsigned - makeIntConst bitsize - ] + [ str; makeIntConst style; makeBoolConst unsigned; makeIntConst bitsize ] @ outValue let callExpr = @@ -2960,14 +2323,8 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op "String", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -3022,14 +2379,8 @@ let decimals (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: "String", "format", t, - [ - format - thisArg.Value - ], - [ - format.Type - thisArg.Value.Type - ], + [ format; thisArg.Value ], + [ format.Type; thisArg.Value.Type ], ?loc = r ) |> Some @@ -3116,17 +2467,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr | ("GenericComparison" | "GenericComparisonIntrinsic"), [ left; right ] -> compare com ctx r left right |> Some | ("FastCompareTuple2" | "FastCompareTuple3" | "FastCompareTuple4" | "FastCompareTuple5" | "GenericComparisonWithComparer" | "GenericComparisonWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Compare", - t, - [ - left - right - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(comp, "Compare", t, [ left; right ], i.SignatureArgTypes, ?loc = r) |> Some | ("GenericLessThan" | "GenericLessThanIntrinsic"), [ left; right ] -> booleanCompare com ctx r left right BinaryLess |> Some @@ -3142,17 +2483,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr equals com ctx r true left right |> Some | ("FastEqualsTuple2" | "FastEqualsTuple3" | "FastEqualsTuple4" | "FastEqualsTuple5" | "GenericEqualityWithComparer" | "GenericEqualityWithComparerIntrinsic"), [ comp; left; right ] -> - Helper.InstanceCall( - comp, - "Equals", - t, - [ - left - right - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.InstanceCall(comp, "Equals", t, [ left; right ], i.SignatureArgTypes, ?loc = r) |> Some | ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> makeEqOp r left right BinaryEqual |> Some | ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] -> @@ -3184,17 +2515,7 @@ let intrinsicFunctions (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr | Value(NewOption(None, _, _), _) -> getExpr None (Int32.Number) ar (makeStrConst "length") | _ -> add upper (makeIntConst 1) - Helper.InstanceCall( - ar, - "slice", - t, - [ - lower - upper - ], - ?loc = r - ) - |> Some + Helper.InstanceCall(ar, "slice", t, [ lower; upper ], ?loc = r) |> Some | "SetArraySlice", None, args -> Helper.LibCall(com, "Array", "setSlice", t, args, i.SignatureArgTypes, ?loc = r) |> Some @@ -3290,19 +2611,7 @@ let dictionaries (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | "GetEnumerator", Some callee -> getEnumerator com r t callee |> Some | "ContainsValue", _ -> match thisArg, args with - | Some c, [ arg ] -> - Helper.LibCall( - com, - "MapUtil", - "containsValue", - t, - [ - arg - c - ], - ?loc = r - ) - |> Some + | Some c, [ arg ] -> Helper.LibCall(com, "MapUtil", "containsValue", t, [ arg; c ], ?loc = r) |> Some | _ -> None | "TryGetValue", _ -> Helper.LibCall(com, "MapUtil", "tryGetValue", t, args, i.SignatureArgTypes, ?thisArg = thisArg, ?loc = r) @@ -3342,19 +2651,7 @@ let hashSets (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op | ReplaceName [ "Clear", "clear"; "Contains", "has"; "Remove", "delete" ] methName, Some c, args -> Helper.InstanceCall(c, methName, t, args, i.SignatureArgTypes, ?loc = r) |> Some | "GetEnumerator", Some c, _ -> getEnumerator com r t c |> Some - | "Add", Some c, [ arg ] -> - Helper.LibCall( - com, - "MapUtil", - "addToSet", - t, - [ - arg - c - ], - ?loc = r - ) - |> Some + | "Add", Some c, [ arg ] -> Helper.LibCall(com, "MapUtil", "addToSet", t, [ arg; c ], ?loc = r) |> Some | ("IsProperSubsetOf" | "IsProperSupersetOf" | "UnionWith" | "IntersectWith" | "ExceptWith" | "IsSubsetOf" | "IsSupersetOf" as meth), Some c, args -> @@ -3427,17 +2724,9 @@ let enums (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio let args = match meth, args with // TODO: Parse at compile time if we know the type - | "parseEnum", [ value ] -> - [ - makeTypeInfo None t - value - ] + | "parseEnum", [ value ] -> [ makeTypeInfo None t; value ] | "tryParseEnum", [ value; refValue ] -> - [ - genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None - value - refValue - ] + [ genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None; value; refValue ] | _ -> args Helper.LibCall(com, "Reflection", meth, t, args, ?loc = r) |> Some @@ -3542,16 +2831,8 @@ let ignoreFormatProvider meth args = match meth, args with // Ignore IFormatProvider | "Parse", arg :: _ -> [ arg ] - | "TryParse", input :: _culture :: _styles :: defVal :: _ -> - [ - input - defVal - ] - | "TryParse", input :: _culture :: defVal :: _ -> - [ - input - defVal - ] + | "TryParse", input :: _culture :: _styles :: defVal :: _ -> [ input; defVal ] + | "TryParse", input :: _culture :: defVal :: _ -> [ input; defVal ] | _ -> args let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Expr list) = @@ -3579,19 +2860,9 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio match args.Length, last.Type with | 7, Number(_, NumberInfo.IsEnum ent) when ent.FullName = "System.DateTimeKind" -> - let args = - (List.take 6 args) - @ [ - makeIntConst 0 - last - ] - - let argTypes = - (List.take 6 i.SignatureArgTypes) - @ [ - Int32.Number - last.Type - ] + let args = (List.take 6 args) @ [ makeIntConst 0; last ] + + let argTypes = (List.take 6 i.SignatureArgTypes) @ [ Int32.Number; last.Type ] Helper.LibCall(com, "Date", "create", t, args, argTypes, ?loc = r) |> Some | _ -> @@ -3627,14 +2898,8 @@ let dates (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio "Date", "fromDateTimeOffset", t, - [ - thisArg.Value - kind - ], - [ - thisArg.Value.Type - kind.Type - ], + [ thisArg.Value; kind ], + [ thisArg.Value.Type; kind.Type ], ?loc = r ) |> Some @@ -3993,11 +3258,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp | None, input :: pattern :: args -> let reg = createRegex None Any (pattern :: args) - [ - reg - input - ] - |> Some + [ reg; input ] |> Some | _ -> None |> Option.map (fun args -> Helper.LibCall(com, "RegExp", Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc = r) @@ -4136,18 +3397,7 @@ let asyncBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | _, "Singleton", _ -> makeImportLib com t "singleton" "AsyncBuilder" |> Some // For Using we need to cast the argument to IDisposable | Some x, "Using", [ arg; f ] -> - Helper.InstanceCall( - x, - "Using", - t, - [ - arg - f - ], - i.SignatureArgTypes, - genArgs = i.GenericArgs, - ?loc = r - ) + Helper.InstanceCall(x, "Using", t, [ arg; f ], i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) |> Some | Some x, meth, _ -> Helper.InstanceCall(x, meth, t, args, i.SignatureArgTypes, genArgs = i.GenericArgs, ?loc = r) @@ -4505,15 +3755,7 @@ let makeMethodInfo com r (name: string) (parameters: (string * Type) list) (retu [ makeStrConst name parameters - |> List.map (fun (name, t) -> - makeTuple - None - false - [ - makeStrConst name - makeGenericTypeInfo None t - ] - ) + |> List.map (fun (name, t) -> makeTuple None false [ makeStrConst name; makeGenericTypeInfo None t ]) |> makeArray Any makeGenericTypeInfo None returnType ] @@ -4742,27 +3984,12 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.dictionary -> let args = match argTypes.Value, args with - | ([] | [ Number _ ]), _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] + | ([] | [ Number _ ]), _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IDictionary; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] | [ IEqualityComparer ], [ eqComp ] | [ Number _; IEqualityComparer ], [ _; eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected dictionary constructor" |> raise let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier "Dictionary" @@ -4771,26 +3998,10 @@ let tryBaseConstructor com ctx (ent: EntityRef) (argTypes: Lazy) genA | Types.hashset -> let args = match argTypes.Value, args with - | [], _ -> - [ - makeArray Any [] - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable ], [ arg ] -> - [ - arg - makeEqualityComparer com ctx (Seq.head genArgs) - ] - | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> - [ - arg - makeComparerFromEqualityComparer eqComp - ] - | [ IEqualityComparer ], [ eqComp ] -> - [ - makeArray Any [] - makeComparerFromEqualityComparer eqComp - ] + | [], _ -> [ makeArray Any []; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable ], [ arg ] -> [ arg; makeEqualityComparer com ctx (Seq.head genArgs) ] + | [ IEnumerable; IEqualityComparer ], [ arg; eqComp ] -> [ arg; makeComparerFromEqualityComparer eqComp ] + | [ IEqualityComparer ], [ eqComp ] -> [ makeArray Any []; makeComparerFromEqualityComparer eqComp ] | _ -> FableError "Unexpected hashset constructor" |> raise let entityName = FSharp2Fable.Helpers.cleanNameAsJsIdentifier "HashSet" @@ -4845,43 +4056,11 @@ let tryType = | BclTimer -> Some("System.Timers.Timer", timers, []) | BclTimeSpan -> Some(Types.timespan, timeSpans, []) | BclHashSet genArg -> Some(Types.hashset, hashSets, [ genArg ]) - | BclDictionary(key, value) -> - Some( - Types.dictionary, - dictionaries, - [ - key - value - ] - ) - | BclKeyValuePair(key, value) -> - Some( - Types.keyValuePair, - keyValuePairs, - [ - key - value - ] - ) - | FSharpMap(key, value) -> - Some( - Types.fsharpMap, - maps, - [ - key - value - ] - ) + | BclDictionary(key, value) -> Some(Types.dictionary, dictionaries, [ key; value ]) + | BclKeyValuePair(key, value) -> Some(Types.keyValuePair, keyValuePairs, [ key; value ]) + | FSharpMap(key, value) -> Some(Types.fsharpMap, maps, [ key; value ]) | FSharpSet genArg -> Some(Types.fsharpSet, sets, [ genArg ]) - | FSharpResult(genArg1, genArg2) -> - Some( - Types.result, - results, - [ - genArg1 - genArg2 - ] - ) + | FSharpResult(genArg1, genArg2) -> Some(Types.result, results, [ genArg1; genArg2 ]) | FSharpChoice genArgs -> Some($"{Types.choiceNonGeneric}`{List.length genArgs}", results, genArgs) | FSharpReference genArg -> Some(Types.refCell, refCells, [ genArg ]) | _ -> None diff --git a/src/Fable.Transforms/Rust/AST/Rust.AST.Helpers.fs b/src/Fable.Transforms/Rust/AST/Rust.AST.Helpers.fs index 1c33dbf271..d6238d1465 100644 --- a/src/Fable.Transforms/Rust/AST/Rust.AST.Helpers.fs +++ b/src/Fable.Transforms/Rust/AST/Rust.AST.Helpers.fs @@ -14,15 +14,7 @@ type HashSet<'T> = System.Collections.Generic.HashSet<'T> [] module Naming = - let topKeywords = - HashSet( - [ - "crate" - "self" - "super" - "Self" - ] - ) + let topKeywords = HashSet([ "crate"; "self"; "super"; "Self" ]) let allKeywords = HashSet(kw.RustKeywords) let rustPrelude = HashSet(kw.RustPrelude) @@ -53,13 +45,7 @@ module Naming = stripRaw ident // no need to keep it raw here let splitNameParts (name: string) = - name.Split( - [| - "." - "::" - |], - System.StringSplitOptions.RemoveEmptyEntries - ) + name.Split([| "."; "::" |], System.StringSplitOptions.RemoveEmptyEntries) |> List.ofArray [] @@ -567,10 +553,7 @@ module MacroArgs = let ttt = tok |> token.TokenTree.Token let sep = kind |> mkTokenTree // if i < count - 1 then - [ - (ttt, token.Spacing.Joint) - (sep, token.Spacing.Alone) - ] + [ (ttt, token.Spacing.Joint); (sep, token.Spacing.Alone) ] // else // [ (ttt, token.Spacing.Alone) ] ) diff --git a/src/Fable.Transforms/Rust/AST/Tests/Sample.AST.fs b/src/Fable.Transforms/Rust/AST/Tests/Sample.AST.fs index dfdf83a72a..507d00ea06 100644 --- a/src/Fable.Transforms/Rust/AST/Tests/Sample.AST.fs +++ b/src/Fable.Transforms/Rust/AST/Tests/Sample.AST.fs @@ -13,13 +13,7 @@ open Fable.Transforms.Rust.AST.Helpers // } let stmt1 = - [ - "1" - "2" - "3" - "4" - "5" - ] + [ "1"; "2"; "3"; "4"; "5" ] |> Seq.map mkIntToken |> mkBracketCommaDelimitedMacCall "vec" |> mkMacCallExpr @@ -28,18 +22,12 @@ let stmt1 = |> mkLocalStmt let stmt2 = - [ - mkStrToken "{:?}" - mkIdentToken "a" - ] + [ mkStrToken "{:?}"; mkIdentToken "a" ] |> mkParensCommaDelimitedMacCall "println" |> mkMacCallStmt let fnItem = - [ - stmt1 - stmt2 - ] + [ stmt1; stmt2 ] |> mkBlock |> Some |> mkFnKind DEFAULT_FN_HEADER (mkFnDecl [] VOID_RETURN_TY) NO_GENERICS diff --git a/src/Fable.Transforms/Rust/Fable2Rust.fs b/src/Fable.Transforms/Rust/Fable2Rust.fs index 77f7f56ec2..7eeb16f2dd 100644 --- a/src/Fable.Transforms/Rust/Fable2Rust.fs +++ b/src/Fable.Transforms/Rust/Fable2Rust.fs @@ -1031,40 +1031,11 @@ module TypeInfo = | Replacements.Util.BclTimeOnly -> transformTimeOnlyType com ctx | Replacements.Util.BclTimer -> transformTimerType com ctx | Replacements.Util.BclHashSet(genArg) -> transformHashSetType com ctx genArg - | Replacements.Util.BclDictionary(k, v) -> - transformHashMapType - com - ctx - [ - k - v - ] + | Replacements.Util.BclDictionary(k, v) -> transformHashMapType com ctx [ k; v ] | Replacements.Util.FSharpSet(genArg) -> transformSetType com ctx genArg - | Replacements.Util.FSharpMap(k, v) -> - transformMapType - com - ctx - [ - k - v - ] - | Replacements.Util.BclKeyValuePair(k, v) -> - transformTupleType - com - ctx - true - [ - k - v - ] - | Replacements.Util.FSharpResult(ok, err) -> - transformResultType - com - ctx - [ - ok - err - ] + | Replacements.Util.FSharpMap(k, v) -> transformMapType com ctx [ k; v ] + | Replacements.Util.BclKeyValuePair(k, v) -> transformTupleType com ctx true [ k; v ] + | Replacements.Util.FSharpResult(ok, err) -> transformResultType com ctx [ ok; err ] | Replacements.Util.FSharpChoice genArgs -> transformChoiceType com ctx genArgs | Replacements.Util.FSharpReference(genArg) -> if isInRefOrAnyType com typ then @@ -1097,22 +1068,9 @@ module TypeInfo = // interfaces implemented as the type itself | Replacements.Util.IsEntity (Types.iset) (entRef, [ genArg ]) -> transformHashSetType com ctx genArg - | Replacements.Util.IsEntity (Types.idictionary) (entRef, [ k; v ]) -> - transformHashMapType - com - ctx - [ - k - v - ] + | Replacements.Util.IsEntity (Types.idictionary) (entRef, [ k; v ]) -> transformHashMapType com ctx [ k; v ] | Replacements.Util.IsEntity (Types.ireadonlydictionary) (entRef, [ k; v ]) -> - transformHashMapType - com - ctx - [ - k - v - ] + transformHashMapType com ctx [ k; v ] | Replacements.Util.IsEntity (Types.keyCollection) (entRef, [ k; v ]) -> transformArrayType com ctx k | Replacements.Util.IsEntity (Types.valueCollection) (entRef, [ k; v ]) -> transformArrayType com ctx v | Replacements.Util.IsEntity (Types.icollectionGeneric) (entRef, [ t ]) -> transformArrayType com ctx t @@ -1439,10 +1397,7 @@ module Util = let macroName = getLibraryImportName com ctx "Native" "interface_cast" - [ - mkExprToken expr - mkTyToken ifcTy - ] + [ mkExprToken expr; mkTyToken ifcTy ] |> mkParensCommaDelimitedMacCall macroName |> mkMacCallExpr | _ -> expr @@ -1789,16 +1744,7 @@ module Util = let value = transformExpr com ctx valueExpr |> mkAddrOfExpr let count = transformExpr com ctx countExpr - makeLibCall - com - ctx - None - "NativeArray" - "new_init" - [ - value - count - ] + makeLibCall com ctx None "NativeArray" "new_init" [ value; count ] | expr -> // this assumes expr converts to a slice // TODO: this may not always work, make it work @@ -1829,23 +1775,9 @@ module Util = | [], None -> libCall com ctx r [ typ ] "List" "empty" [] | [ expr ], None -> libCall com ctx r [] "List" "singleton" [ expr ] | exprs, None -> [ makeNewArray r typ exprs ] |> libCall com ctx r [] "List" "ofArray" - | [ head ], Some tail -> - libCall - com - ctx - r - [] - "List" - "cons" - [ - head - tail - ] + | [ head ], Some tail -> libCall com ctx r [] "List" "cons" [ head; tail ] | exprs, Some tail -> - [ - makeNewArray r typ exprs - tail - ] + [ makeNewArray r typ exprs; tail ] |> libCall com ctx r [] "List" "ofArrayWithTail" let makeTuple (com: IRustCompiler) ctx r isStruct (exprs: (Fable.Expr) list) = @@ -2217,17 +2149,7 @@ module Util = let right = transformLeaveContext com ctx None rightExpr |> maybeAddParens rightExpr match leftExpr.Type, kind with - | Fable.String, Rust.BinOpKind.Add -> - makeLibCall - com - ctx - None - "String" - "append" - [ - left - right - ] + | Fable.String, Rust.BinOpKind.Add -> makeLibCall com ctx None "String" "append" [ left; right ] | _ -> mkBinaryExpr (mkBinOp kind) left right // ?loc=range) | Fable.Logical(op, TransformExpr com ctx left, TransformExpr com ctx right) -> @@ -2793,16 +2715,7 @@ module Util = let try_f = makeLocalLambda com ctx [] body let catch_f = makeLocalLambda com ctx [ catchVar ] catchBody - makeLibCall - com - ctx - None - "Exception" - "try_catch" - [ - try_f - catch_f - ] + makeLibCall com ctx None "Exception" "try_catch" [ try_f; catch_f ] | None -> // try...finally @@ -2814,11 +2727,7 @@ module Util = let bodyExpr = transformExpr com ctx body - [ - finAlloc |> mkSemiStmt - bodyExpr |> mkExprStmt - ] - |> mkStmtBlockExpr + [ finAlloc |> mkSemiStmt; bodyExpr |> mkExprStmt ] |> mkStmtBlockExpr | _ -> // no catch, no finalizer @@ -2837,12 +2746,7 @@ module Util = | Fable.String -> err | _ -> mkMethodCallExpr "get_Message" None err [] - mkMacroExpr - "panic" - [ - mkStrLitExpr "{}" - msg - ] + mkMacroExpr "panic" [ mkStrLitExpr "{}"; msg ] let transformCurry (com: IRustCompiler) (ctx: Context) arity (expr: Fable.Expr) : Rust.Expr = com.TransformExpr(ctx, Replacements.Api.curryExprAtRuntime com arity expr) @@ -3007,13 +2911,7 @@ module Util = match evalType with | Fable.Option(genArg, _) -> // let genArgsOpt = transformGenArgs com ctx [genArg] - let unionCaseFullName = - [ - "Some" - "None" - ] - |> List.item caseIndex - |> rawIdent + let unionCaseFullName = [ "Some"; "None" ] |> List.item caseIndex |> rawIdent let fields = match evalName with @@ -3368,10 +3266,7 @@ module Util = let modItem = mkUnloadedModItem attrs modName let useItem = mkGlobUseItem [] [ modName ] - [ - modItem - useItem |> mkPublicItem - ] + [ modItem; useItem |> mkPublicItem ] let modItems = com.GetAllModules() |> List.sort |> List.collect makeModItems @@ -3713,13 +3608,7 @@ module Util = let funcWrap = getLibraryImportName com ctx "Native" ("Func" + argCount) - makeCall - [ - funcWrap - "new" - ] - None - [ closureExpr ] + makeCall [ funcWrap; "new" ] None [ closureExpr ] let makeTypeBounds (com: IRustCompiler) ctx argName (constraints: Fable.Constraint list) = let makeGenBound names tyNames = @@ -3748,21 +3637,13 @@ module Util = | Operators.division, true -> [ makeOpBound "Div" ] | Operators.modulus, true -> [ makeOpBound "Rem" ] | Operators.unaryNegation, true -> [ makeOpBound "Neg" ] - | Operators.divideByInt, true -> - [ - makeOpBound "Div" - makeGenBound [ rawIdent "From" ] [ "i32" ] - ] + | Operators.divideByInt, true -> [ makeOpBound "Div"; makeGenBound [ rawIdent "From" ] [ "i32" ] ] | "get_Zero", true -> [ makeRawBound "Default" ] | _ -> [] | Fable.Constraint.CoercesTo(targetType) -> match targetType with | IFormattable -> [ makeGenBound ("core" :: "fmt" :: "Display" :: []) [] ] - | IEquatable _ -> - [ - makeRawBound "Eq" - makeGenBound ("core" :: "hash" :: "Hash" :: []) [] - ] + | IEquatable _ -> [ makeRawBound "Eq"; makeGenBound ("core" :: "hash" :: "Hash" :: []) [] ] | Fable.DeclaredType(entRef, genArgs) -> let ent = com.GetEntity(entRef) @@ -4001,13 +3882,7 @@ module Util = let attrs = transformAttributes com ctx memb.Attributes - let fnBody = - [ - staticStmt - valueStmt - ] - |> mkBlock - |> Some + let fnBody = [ staticStmt; valueStmt ] |> mkBlock |> Some let fnDecl = mkFnDecl [] (mkFnRetTy ty) let fnKind = mkFnKind DEFAULT_FN_HEADER fnDecl NO_GENERICS fnBody @@ -4376,10 +4251,7 @@ module Util = let ofTrait = mkTraitRef path |> Some mkImplItem [] "" ty generics memberItems ofTrait - [ - traitItem |> mkPublicItem - implItem - ] + [ traitItem |> mkPublicItem; implItem ] let makeFSharpExceptionItems com ctx (ent: Fable.Entity) = // expected output: @@ -4400,15 +4272,7 @@ module Util = let fieldsAsTuple = Fable.Value(Fable.NewTuple(fieldValues, true), None) - let body = - formatString - com - ctx - "{} {:?}" - [ - entNameExpr - fieldsAsTuple - ] + let body = formatString com ctx "{} {:?}" [ entNameExpr; fieldsAsTuple ] let fnBody = [ mkExprStmt body ] |> mkBlock |> Some let fnRetTy = Fable.String |> transformType com ctx |> mkFnRetTy @@ -4443,10 +4307,7 @@ module Util = let p1 = mkImplSelfParam false false let p2 = mkTypedParam "f" (ty |> mkMutRefTy None) false false - [ - p1 - p2 - ] + [ p1; p2 ] let output = let ty = mkGenericPathTy ("core" :: "fmt" :: (rawIdent "Result") :: []) None @@ -4460,14 +4321,7 @@ module Util = let generics = makeGenerics com ctx genArgs let implItemFor traitName = - let path = - mkGenericPath - [ - "core" - "fmt" - traitName - ] - None + let path = mkGenericPath ("core" :: "fmt" :: traitName :: []) None let ofTrait = mkTraitRef path |> Some mkImplItem [] "" self_ty generics [ fnItem ] ofTrait @@ -4527,13 +4381,7 @@ module Util = let macroName = getLibraryImportName com ctx "Native" op_macro - let id_tokens = - [ - op_trait - op_fn - decl.Name - ] - |> List.map mkIdentToken + let id_tokens = [ op_trait; op_fn; decl.Name ] |> List.map mkIdentToken let ty_tokens = (self_ty :: rhs_tys) @ genArgTys |> List.map mkTyToken @@ -4610,12 +4458,7 @@ module Util = // "ReferenceEquals" ] - let ignoredInterfaceNames = - set - [ - Types.ienumerable - Types.ienumerator - ] + let ignoredInterfaceNames = set [ Types.ienumerable; Types.ienumerator ] let transformClassMembers (com: IRustCompiler) ctx (classDecl: Fable.ClassDecl) = let entRef = classDecl.Entity @@ -4873,10 +4716,7 @@ module Util = let modItem = mkModItem [] modName items let useItem = mkGlobUseItem [] [ modName ] - [ - modItem - useItem |> mkPublicItem - ] + [ modItem; useItem |> mkPublicItem ] else items @@ -5141,12 +4981,7 @@ module Compiler = if isLastFileInProject com then // adds "no_std" for fable library crate if feature is enabled if isFableLibrary com then - mkInnerAttr - "cfg_attr" - [ - "feature = \"no_std\"" - "no_std" - ] + mkInnerAttr "cfg_attr" [ "feature = \"no_std\""; "no_std" ] // TODO: make some of those conditional on compiler options mkInnerAttr "allow" [ "dead_code" ] diff --git a/src/Fable.Transforms/Rust/Replacements.fs b/src/Fable.Transforms/Rust/Replacements.fs index 3be8193296..76bae9fb0d 100644 --- a/src/Fable.Transforms/Rust/Replacements.fs +++ b/src/Fable.Transforms/Rust/Replacements.fs @@ -150,17 +150,7 @@ let toNativeIndex expr = TypeCast(expr, UNativeInt.Number) let toChar com (arg: Expr) = match arg.Type with | Char -> arg - | String -> - Helper.LibCall( - com, - "String", - "getCharAt", - Char, - [ - arg - makeIntConst 0 - ] - ) + | String -> Helper.LibCall(com, "String", "getCharAt", Char, [ arg; makeIntConst 0 ]) | _ -> let code = TypeCast(arg, UInt32.Number) Helper.LibCall(com, "String", "fromCharCode", Char, [ code ]) @@ -338,11 +328,7 @@ let emitFormat (com: ICompiler) r t (args: Expr list) macro = let args = match args with | [] -> [ makeStrConst "" ] - | [ arg ] -> - [ - makeStrConst "{0}" - arg - ] + | [ arg ] -> [ makeStrConst "{0}"; arg ] | [ ExprTypeAs(String, fmt); Value(NewArray(ArrayValues [], _, _), _) ] -> [ fmt ] | [ ExprTypeAs(String, fmt); Value(NewArray(ArrayValues restArgs, _, _), _) ] -> fmt :: restArgs | (ExprType String) :: restArgs -> args @@ -468,18 +454,7 @@ let referenceEquals (com: ICompiler) ctx r (left: Expr) (right: Expr) = | Char | String | Number _ -> makeEqOp r left right BinaryEqual - | _ -> - Helper.LibCall( - com, - "Native", - "referenceEquals", - Boolean, - [ - makeRef left - makeRef right - ], - ?loc = r - ) + | _ -> Helper.LibCall(com, "Native", "referenceEquals", Boolean, [ makeRef left; makeRef right ], ?loc = r) let equals (com: ICompiler) ctx r (left: Expr) (right: Expr) = let t = Boolean @@ -489,54 +464,10 @@ let equals (com: ICompiler) ctx r (left: Expr) (right: Expr) = | Char | String | Number _ -> makeEqOp r left right BinaryEqual - | Builtin kind -> - Helper.LibCall( - com, - coreModFor kind, - "equals", - t, - [ - left - right - ], - ?loc = r - ) - | Array _ -> - Helper.LibCall( - com, - "Array", - "equals", - t, - [ - left - right - ], - ?loc = r - ) - | List _ -> - Helper.LibCall( - com, - "List", - "equals", - t, - [ - left - right - ], - ?loc = r - ) - | IEnumerable -> - Helper.LibCall( - com, - "Seq", - "equals", - t, - [ - left - right - ], - ?loc = r - ) + | Builtin kind -> Helper.LibCall(com, coreModFor kind, "equals", t, [ left; right ], ?loc = r) + | Array _ -> Helper.LibCall(com, "Array", "equals", t, [ left; right ], ?loc = r) + | List _ -> Helper.LibCall(com, "List", "equals", t, [ left; right ], ?loc = r) + | IEnumerable -> Helper.LibCall(com, "Seq", "equals", t, [ left; right ], ?loc = r) // | MetaType -> // Helper.LibCall(com, "Reflection", "equals", t, [left; right], ?loc=r) | HasReferenceEquality com _ -> referenceEquals com ctx r left right @@ -557,78 +488,12 @@ let compare (com: ICompiler) ctx r (left: Expr) (right: Expr) = | Boolean | Char | String - | Number _ -> - Helper.LibCall( - com, - "Native", - "compare", - t, - [ - left - right - ], - ?loc = r - ) - | Builtin kind -> - Helper.LibCall( - com, - coreModFor kind, - "compareTo", - t, - [ - left - right - ], - ?loc = r - ) - | Array _ -> - Helper.LibCall( - com, - "Array", - "compareTo", - t, - [ - left - right - ], - ?loc = r - ) - | List _ -> - Helper.LibCall( - com, - "List", - "compareTo", - t, - [ - left - right - ], - ?loc = r - ) - | IEnumerable -> - Helper.LibCall( - com, - "Seq", - "compareTo", - t, - [ - left - right - ], - ?loc = r - ) - | _ -> - Helper.LibCall( - com, - "Native", - "compare", - t, - [ - left - right - ], - ?loc = r - ) + | Number _ -> Helper.LibCall(com, "Native", "compare", t, [ left; right ], ?loc = r) + | Builtin kind -> Helper.LibCall(com, coreModFor kind, "compareTo", t, [ left; right ], ?loc = r) + | Array _ -> Helper.LibCall(com, "Array", "compareTo", t, [ left; right ], ?loc = r) + | List _ -> Helper.LibCall(com, "List", "compareTo", t, [ left; right ], ?loc = r) + | IEnumerable -> Helper.LibCall(com, "Seq", "compareTo", t, [ left; right ], ?loc = r) + | _ -> Helper.LibCall(com, "Native", "compare", t, [ left; right ], ?loc = r) /// Boolean comparison operators like <, >, <=, >= let booleanCompare (com: ICompiler) ctx r (left: Expr) (right: Expr) op = @@ -689,16 +554,7 @@ let makeEqualityComparer (com: ICompiler) ctx typArg = objExpr [ - "Equals", - Delegate( - [ - x - y - ], - equals com ctx None (IdentExpr x) (IdentExpr y), - None, - Tags.empty - ) + "Equals", Delegate([ x; y ], equals com ctx None (IdentExpr x) (IdentExpr y), None, Tags.empty) "GetHashCode", Delegate([ x ], getHashCode com ctx None (IdentExpr x), None, Tags.empty) ] @@ -764,14 +620,7 @@ let rec getZero (com: ICompiler) (ctx: Context) (t: Type) = | Builtin BclTimeSpan -> Helper.LibValue(com, "TimeSpan", "zero", t) | Builtin(FSharpSet genArg) -> makeSet com ctx None t [] genArg | Builtin BclGuid -> Helper.LibValue(com, "Guid", "empty", t) - | Builtin(BclKeyValuePair(k, v)) -> - makeTuple - None - true - [ - getZero com ctx k - getZero com ctx v - ] + | Builtin(BclKeyValuePair(k, v)) -> makeTuple None true [ getZero com ctx k; getZero com ctx v ] | ListSingleton(CustomOp com ctx None t "get_Zero" [] e) -> e | _ -> Helper.LibCall(com, "Native", "defaultOf", t, []) @@ -788,27 +637,9 @@ let makeAddFunction (com: ICompiler) ctx t = let x = makeUniqueIdent ctx t "x" let y = makeUniqueIdent ctx t "y" - let body = - applyOp - com - ctx - None - t - Operators.addition - [ - IdentExpr x - IdentExpr y - ] - - Delegate( - [ - x - y - ], - body, - None, - Tags.empty - ) + let body = applyOp com ctx None t Operators.addition [ IdentExpr x; IdentExpr y ] + + Delegate([ x; y ], body, None, Tags.empty) // let makeGenericAdder (com: ICompiler) ctx t = // objExpr [ @@ -1089,32 +920,12 @@ let fsFormat (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op let cont = Helper.LibCall(com, "Util", "bprintf", t, [ sb ]) Helper.Application(cont, t, [ template ], ?loc = r) |> Some | "PrintFormatToStringBuilderThen", None, [ cont; sb; StringConst fmt ] -> - let cont = - Helper.LibCall( - com, - "Util", - "kbprintf", - t, - [ - cont - sb - ] - ) + let cont = Helper.LibCall(com, "Util", "kbprintf", t, [ cont; sb ]) let macro = Helper.LibValue(com, "String", "kprintf!", Any) macro |> makeRustFormatExpr r t fmt [ cont ] |> Some | "PrintFormatToStringBuilderThen", None, [ cont; sb; MaybeCasted(template) ] -> - let cont = - Helper.LibCall( - com, - "Util", - "kbprintf", - t, - [ - cont - sb - ] - ) + let cont = Helper.LibCall(com, "Util", "kbprintf", t, [ cont; sb ]) Helper.Application(cont, t, [ template ], ?loc = r) |> Some | ".ctor", _, (StringConst fmt) :: (Value(NewArray(ArrayValues templateArgs, _, _), _)) :: _ -> @@ -1163,12 +974,7 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o let addStep args = match args with - | [ first; last ] -> - [ - first - getOne com ctx genArg - last - ] + | [ first; last ] -> [ first; getOne com ctx genArg; last ] | _ -> args let meth, args = @@ -1182,28 +988,9 @@ let operators (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr o | "op_PipeRight", [ x; f ] | "op_PipeLeft", [ f; x ] -> curriedApply r t f [ x ] |> Some | "op_PipeRight2", [ x; y; f ] - | "op_PipeLeft2", [ f; x; y ] -> - curriedApply - r - t - f - [ - x - y - ] - |> Some + | "op_PipeLeft2", [ f; x; y ] -> curriedApply r t f [ x; y ] |> Some | "op_PipeRight3", [ x; y; z; f ] - | "op_PipeLeft3", [ f; x; y; z ] -> - curriedApply - r - t - f - [ - x - y - z - ] - |> Some + | "op_PipeLeft3", [ f; x; y; z ] -> curriedApply r t f [ x; y; z ] |> Some | "op_ComposeRight", [ f1; f2 ] -> compose com ctx r t f1 f2 |> Some | "op_ComposeLeft", [ f2; f1 ] -> compose com ctx r t f1 f2 |> Some // Strings @@ -1488,18 +1275,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt $"String.CompareTo will be compiled as String.CompareOrdinal" |> addWarning com ctx.InlinePath r - Helper.LibCall( - com, - "String", - "compareOrdinal", - t, - [ - c - arg - makeBoolConst false - ], - ?loc = r - ) + Helper.LibCall(com, "String", "compareOrdinal", t, [ c; arg; makeBoolConst false ], ?loc = r) |> Some | "Concat", None, _ -> match args with @@ -1530,18 +1306,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt match thisArg, args with | Some x, [ ExprTypeAs(String, y) ] | None, [ ExprTypeAs(String, x); ExprTypeAs(String, y) ] -> - Helper.LibCall( - com, - "String", - "equalsOrdinal", - t, - [ - x - y - makeBoolConst false - ], - ?loc = r - ) + Helper.LibCall(com, "String", "equalsOrdinal", t, [ x; y; makeBoolConst false ], ?loc = r) |> Some | Some x, [ ExprTypeAs(String, y); NumberConst(:? int as kind, _, NumberInfo.IsEnum _) ] | None, [ ExprTypeAs(String, x); ExprTypeAs(String, y); NumberConst(:? int as kind, _, NumberInfo.IsEnum _) ] -> @@ -1551,18 +1316,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt let ignoreCase = kind = 1 || kind = 3 || kind = 5 - Helper.LibCall( - com, - "String", - "equalsOrdinal", - t, - [ - x - y - makeBoolConst ignoreCase - ], - ?loc = r - ) + Helper.LibCall(com, "String", "equalsOrdinal", t, [ x; y; makeBoolConst ignoreCase ], ?loc = r) |> Some | _ -> None | "Format", None, _ -> @@ -1601,44 +1355,20 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | "Join", None, _ -> let args = match args with - | [ ExprTypeAs(String, sep); ExprTypeAs(IEnumerable, arg) ] -> - [ - sep - toArray com t arg - ] - | [ ExprTypeAs(String, sep); ExprTypeAs(Array(String, _), arg) ] -> - [ - sep - arg - ] + | [ ExprTypeAs(String, sep); ExprTypeAs(IEnumerable, arg) ] -> [ sep; toArray com t arg ] + | [ ExprTypeAs(String, sep); ExprTypeAs(Array(String, _), arg) ] -> [ sep; arg ] | [ ExprTypeAs(Char, sep); ExprTypeAs(Array(String, _), arg) ] -> let sep = Helper.LibCall(com, "String", "ofChar", String, [ sep ]) - [ - sep - arg - ] + [ sep; arg ] | [ ExprTypeAs(String, sep) ExprTypeAs(Array(String, _), arg) ExprTypeAs(Number(Int32, _), idx) ExprTypeAs(Number(Int32, _), cnt) ] -> let arg = - Helper.LibCall( - com, - "Array", - "getSubArray", - Array(String, MutableArray), - [ - arg - idx - cnt - ] - ) + Helper.LibCall(com, "Array", "getSubArray", Array(String, MutableArray), [ arg; idx; cnt ]) - [ - sep - arg - ] + [ sep; arg ] | [ ExprTypeAs(Char, sep) ExprTypeAs(Array(String, _), arg) ExprTypeAs(Number(Int32, _), idx) @@ -1646,22 +1376,9 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt let sep = Helper.LibCall(com, "String", "ofChar", String, [ sep ]) let arg = - Helper.LibCall( - com, - "Array", - "getSubArray", - Array(String, MutableArray), - [ - arg - idx - cnt - ] - ) + Helper.LibCall(com, "Array", "getSubArray", Array(String, MutableArray), [ arg; idx; cnt ]) - [ - sep - arg - ] + [ sep; arg ] | _ -> [] if not (List.isEmpty args) then @@ -1675,19 +1392,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | [ ExprTypeAs(Number(Int32, _), arg) ] -> let ch = makeTypeConst None Char ' ' - Helper.LibCall( - com, - "String", - methName, - t, - [ - c - arg - ch - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "String", methName, t, [ c; arg; ch ], ?loc = r) |> Some | [ ExprType(Number(Int32, _)); ExprType Char ] -> Helper.LibCall(com, "String", methName, t, c :: args, ?loc = r) |> Some | _ -> None @@ -1705,115 +1410,31 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt | "Split", Some c, _ -> match args with | [] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - makeStrConst "" - makeIntConst -1 - makeIntConst 0 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; makeStrConst ""; makeIntConst -1; makeIntConst 0 ], ?loc = r) |> Some | [ ExprTypeAs(String, arg1) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - makeIntConst -1 - makeIntConst 0 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; makeIntConst -1; makeIntConst 0 ], ?loc = r) |> Some | [ ExprTypeAs(String, arg1); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg2) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - makeIntConst -1 - arg2 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; makeIntConst -1; arg2 ], ?loc = r) |> Some | [ ExprTypeAs(String, arg1) ExprTypeAs(Number(Int32, _), arg2) ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg3) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - arg2 - arg3 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; arg2; arg3 ], ?loc = r) |> Some | [ Value(NewArray(ArrayValues [ arg1 ], String, _), _) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - makeIntConst -1 - makeIntConst 0 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; makeIntConst -1; makeIntConst 0 ], ?loc = r) |> Some | [ Value(NewArray(ArrayValues [ arg1 ], String, _), _); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg2) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - makeIntConst -1 - arg2 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; makeIntConst -1; arg2 ], ?loc = r) |> Some | [ Value(NewArray(ArrayValues [ arg1 ], String, _), _) ExprTypeAs(Number(Int32, _), arg2) ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg3) ] -> - Helper.LibCall( - com, - "String", - "split", - t, - [ - c - arg1 - arg2 - arg3 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "split", t, [ c; arg1; arg2; arg3 ], ?loc = r) |> Some | [ ExprTypeAs(Char, arg1) ] -> @@ -1822,12 +1443,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt "String", "splitChars", t, - [ - c - makeArray Char [ arg1 ] - makeIntConst -1 - makeIntConst 0 - ], + [ c; makeArray Char [ arg1 ]; makeIntConst -1; makeIntConst 0 ], ?loc = r ) |> Some @@ -1837,92 +1453,27 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt "String", "splitChars", t, - [ - c - makeArray Char [ arg1 ] - makeIntConst -1 - arg2 - ], + [ c; makeArray Char [ arg1 ]; makeIntConst -1; arg2 ], ?loc = r ) |> Some | [ ExprTypeAs(Char, arg1); ExprTypeAs(Number(Int32, _), arg2); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg3) ] -> - Helper.LibCall( - com, - "String", - "splitChars", - t, - [ - c - makeArray Char [ arg1 ] - arg2 - arg3 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "splitChars", t, [ c; makeArray Char [ arg1 ]; arg2; arg3 ], ?loc = r) |> Some | [ ExprTypeAs(Array(Char, _), arg1) ] -> - Helper.LibCall( - com, - "String", - "splitChars", - t, - [ - c - arg1 - makeIntConst -1 - makeIntConst 0 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "splitChars", t, [ c; arg1; makeIntConst -1; makeIntConst 0 ], ?loc = r) |> Some | [ ExprTypeAs(Array(Char, _), arg1); ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg2) ] -> - Helper.LibCall( - com, - "String", - "splitChars", - t, - [ - c - arg1 - makeIntConst -1 - arg2 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "splitChars", t, [ c; arg1; makeIntConst -1; arg2 ], ?loc = r) |> Some | [ ExprTypeAs(Array(Char, _), arg1); ExprTypeAs(Number(Int32, _), arg2) ] -> - Helper.LibCall( - com, - "String", - "splitChars", - t, - [ - c - arg1 - arg2 - makeIntConst 0 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "splitChars", t, [ c; arg1; arg2; makeIntConst 0 ], ?loc = r) |> Some | [ ExprTypeAs(Array(Char, _), arg1) ExprTypeAs(Number(Int32, _), arg2) ExprTypeAs(Number(_, NumberInfo.IsEnum _), arg3) ] -> - Helper.LibCall( - com, - "String", - "splitChars", - t, - [ - c - arg1 - arg2 - arg3 - ], - ?loc = r - ) + Helper.LibCall(com, "String", "splitChars", t, [ c; arg1; arg2; arg3 ], ?loc = r) |> Some // TODO: handle arrays of string separators with more than one element @@ -1966,17 +1517,7 @@ let strings (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr opt let stringModule (com: ICompiler) (ctx: Context) r t (i: CallInfo) (_: Expr option) (args: Expr list) = match i.CompiledName, args with | "Concat", [ sep; arg ] -> - Helper.LibCall( - com, - "String", - "join", - t, - [ - sep - toArray com t arg - ], - ?loc = r - ) + Helper.LibCall(com, "String", "join", t, [ sep; toArray com t arg ], ?loc = r) |> Some | meth, args -> Helper.LibCall(com, "String", Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc = r) @@ -1989,36 +1530,14 @@ let stringBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Ex | (ExprType String :: _) -> let s = "format!" |> emitFormat com None String args - Helper.LibCall( - com, - "Util", - "sb_Append", - t, - [ - sb - s - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Util", "sb_Append", t, [ sb; s ], ?loc = r) |> Some | (cultureInfo :: restArgs) -> $"StringBuilder.AppendFormat(): Format provider argument is ignored" |> addWarning com ctx.InlinePath r let s = "format!" |> emitFormat com None String restArgs - Helper.LibCall( - com, - "Util", - "sb_Append", - t, - [ - sb - s - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Util", "sb_Append", t, [ sb; s ], ?loc = r) |> Some | _ -> None | _ -> bclType com ctx r t i thisArg args @@ -2080,18 +1599,7 @@ let seqModule (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg Helper.LibCall(com, "List", "ofSeq", t, args, i.SignatureArgTypes, ?loc = r) |> Some | "CreateEvent", [ addHandler; removeHandler; createHandler ] -> - Helper.LibCall( - com, - "Event", - "createEvent", - t, - [ - addHandler - removeHandler - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "Event", "createEvent", t, [ addHandler; removeHandler ], i.SignatureArgTypes, ?loc = r) |> Some | ("Distinct" | "DistinctBy" | "Except" | "GroupBy" | "CountBy" as meth), args -> let meth = Naming.lowerFirst meth @@ -2117,247 +1625,52 @@ let resizeArrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (this | "get_Item", Some ar, [ idx ] -> getExpr r t ar idx |> Some | "set_Item", Some ar, [ idx; value ] -> setExpr r ar idx value |> Some | "Add", Some(MaybeCasted(ar)), [ arg ] -> - Helper.LibCall( - com, - "NativeArray", - "add", - t, - [ - ar - arg - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "NativeArray", "add", t, [ ar; arg ], ?loc = r) |> Some | "Remove", Some(MaybeCasted(ar)), [ arg ] -> - Helper.LibCall( - com, - "Array", - "removeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "removeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "RemoveAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "removeAllInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "removeAllInPlace", t, [ arg; ar ], ?loc = r) |> Some | "FindIndex", Some ar, [ arg ] -> - Helper.LibCall( - com, - "NativeArray", - "FindIndex", - t, - [ - ar - arg - ], - ?loc = r - ) + Helper.LibCall(com, "NativeArray", "FindIndex", t, [ ar; arg ], ?loc = r) |> Some | "FindLastIndex", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "findLastIndex", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "findLastIndex", t, [ arg; ar ], ?loc = r) |> Some | "ForEach", Some ar, [ arg ] -> makeInstanceCall r t i ar "forEach" [ arg ] |> Some | "GetEnumerator", Some(MaybeCasted(ar)), _ -> Helper.LibCall(com, "Seq", "Enumerable::ofArray", t, [ ar ], ?loc = r) |> Some | "get_Count", Some(MaybeCasted(ar)), _ -> Helper.LibCall(com, "NativeArray", "count", t, [ ar ], ?loc = r) |> Some | "Clear", Some(MaybeCasted(ar)), [] -> makeInstanceCall r t i (getMut ar) "clear" [] |> Some - | "ConvertAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - arg - ar - ], - ?loc = r - ) - |> Some + | "ConvertAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "map", t, [ arg; ar ], ?loc = r) |> Some | "Find", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "Array", - "tryFind", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "Array", "tryFind", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - getZero com ctx t - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; getZero com ctx t ], ?loc = r) |> Some | "Exists", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "exists", - t, - [ - arg - ar - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "Array", "exists", t, [ arg; ar ], i.SignatureArgTypes, ?loc = r) |> Some | "FindLast", Some ar, [ arg ] -> - let opt = - Helper.LibCall( - com, - "Array", - "tryFindBack", - t, - [ - arg - ar - ], - ?loc = r - ) + let opt = Helper.LibCall(com, "Array", "tryFindBack", t, [ arg; ar ], ?loc = r) - Helper.LibCall( - com, - "Option", - "defaultArg", - t, - [ - opt - getZero com ctx t - ], - ?loc = r - ) - |> Some - | "FindAll", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "filter", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Option", "defaultArg", t, [ opt; getZero com ctx t ], ?loc = r) |> Some + | "FindAll", Some ar, [ arg ] -> Helper.LibCall(com, "Array", "filter", t, [ arg; ar ], ?loc = r) |> Some | "AddRange", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "GetRange", Some ar, [ idx; cnt ] -> - Helper.LibCall( - com, - "Array", - "getSubArray", - t, - [ - ar - idx - cnt - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "getSubArray", t, [ ar; idx; cnt ], ?loc = r) |> Some | "Contains", Some(MaybeCasted(ar)), [ arg ] -> - Helper.LibCall( - com, - "Array", - "contains", - t, - [ - arg - ar - ], - i.SignatureArgTypes, - ?loc = r - ) + Helper.LibCall(com, "Array", "contains", t, [ arg; ar ], i.SignatureArgTypes, ?loc = r) |> Some | "IndexOf", Some ar, [ arg ] -> - Helper.LibCall( - com, - "Array", - "indexOf", - t, - [ - ar - arg - ], - i.SignatureArgTypes, - ?loc = r - ) - |> Some - | "Insert", Some ar, [ idx; arg ] -> - makeInstanceCall - r - t - i - (getMut ar) - "insert" - [ - toNativeIndex idx - arg - ] + Helper.LibCall(com, "Array", "indexOf", t, [ ar; arg ], i.SignatureArgTypes, ?loc = r) |> Some + | "Insert", Some ar, [ idx; arg ] -> makeInstanceCall r t i (getMut ar) "insert" [ toNativeIndex idx; arg ] |> Some | "InsertRange", Some ar, [ idx; arg ] -> - Helper.LibCall( - com, - "Array", - "insertRangeInPlace", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "insertRangeInPlace", t, [ idx; arg; ar ], ?loc = r) |> Some | "RemoveRange", Some ar, args -> makeInstanceCall r t i ar "splice" args |> Some | "RemoveAt", Some ar, [ idx ] -> makeInstanceCall r t i (getMut ar) "remove" [ toNativeIndex idx ] |> Some @@ -2386,31 +1699,10 @@ let collectionExtensions = match i.CompiledName, thisArg, args with | "AddRange", None, [ ar; arg ] -> - Helper.LibCall( - com, - "Array", - "addRangeInPlace", - t, - [ - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "addRangeInPlace", t, [ arg; ar ], ?loc = r) |> Some | "InsertRange", None, [ ar; idx; arg ] -> - Helper.LibCall( - com, - "Array", - "insertRangeInPlace", - t, - [ - idx - arg - ar - ], - ?loc = r - ) + Helper.LibCall(com, "Array", "insertRangeInPlace", t, [ idx; arg; ar ], ?loc = r) |> Some | _ -> None @@ -2450,37 +1742,9 @@ let createArray (com: ICompiler) ctx r t i count value = | Array(typ, _), None -> let value = getZero com ctx typ - Value( - NewArray( - makeTuple - None - true - [ - value - count - ] - |> ArrayFrom, - typ, - MutableArray - ), - r - ) + Value(NewArray(makeTuple None true [ value; count ] |> ArrayFrom, typ, MutableArray), r) | Array(typ, _), Some value -> - Value( - NewArray( - makeTuple - None - true - [ - value - count - ] - |> ArrayFrom, - typ, - MutableArray - ), - r - ) + Value(NewArray(makeTuple None true [ value; count ] |> ArrayFrom, typ, MutableArray), r) | _ -> $"Expecting an array type but got %A{t}" |> addErrorAndReturnNull com ctx.InlinePath r @@ -2497,31 +1761,9 @@ let arrays (com: ICompiler) (ctx: Context) r (t: Type) (i: CallInfo) (thisArg: E | "Clone", Some ar, _ -> Helper.LibCall(com, "NativeArray", "new_copy", t, [ ar ], ?loc = r) |> Some | "Copy", None, [ _source; _sourceIndex; _target; _targetIndex; _count ] -> copyToArray com r t i args | "Copy", None, [ source; target; count ] -> - copyToArray - com - r - t - i - [ - source - makeIntConst 0 - target - makeIntConst 0 - count - ] + copyToArray com r t i [ source; makeIntConst 0; target; makeIntConst 0; count ] | "ConvertAll", None, [ source; mapping ] -> - Helper.LibCall( - com, - "Array", - "map", - t, - [ - mapping - source - ], - ?loc = r - ) - |> Some + Helper.LibCall(com, "Array", "map", t, [ mapping; source ], ?loc = r) |> Some | "IndexOf", None, [ ar; arg ] -> Helper.LibCall(com, "Array", "indexOf", t, args, i.SignatureArgTypes, ?loc = r) |> Some @@ -2774,11 +2016,7 @@ let parseNum (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr op if not withStyleArg then [ str ] @ outValue else - [ - str - makeIntConst style - ] - @ outValue + [ str; makeIntConst style ] @ outValue Helper.LibCall(com, moduleName, memberName, t, args, ?loc = r) @@ -2974,18 +2212,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr [ comp; arg ] -> makeInstanceCall r t i comp "GetHashCode" [ arg ] |> Some | ("GenericComparison" | "GenericComparisonIntrinsic"), [ left; right ] -> compare com ctx r left right |> Some | ("FastCompareTuple2" | "FastCompareTuple3" | "FastCompareTuple4" | "FastCompareTuple5" | "GenericComparisonWithComparer" | "GenericComparisonWithComparerIntrinsic"), - [ comp; left; right ] -> - makeInstanceCall - r - t - i - comp - "Compare" - [ - left - right - ] - |> Some + [ comp; left; right ] -> makeInstanceCall r t i comp "Compare" [ left; right ] |> Some | ("GenericLessThan" | "GenericLessThanIntrinsic"), [ left; right ] -> booleanCompare com ctx r left right BinaryLess |> Some | ("GenericLessOrEqual" | "GenericLessOrEqualIntrinsic"), [ left; right ] -> @@ -2999,18 +2226,7 @@ let languagePrimitives (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisAr // TODO: In ER mode, equality on two NaNs returns "true". equals com ctx r left right |> Some | ("FastEqualsTuple2" | "FastEqualsTuple3" | "FastEqualsTuple4" | "FastEqualsTuple5" | "GenericEqualityWithComparer" | "GenericEqualityWithComparerIntrinsic"), - [ comp; left; right ] -> - makeInstanceCall - r - t - i - comp - "Equals" - [ - left - right - ] - |> Some + [ comp; left; right ] -> makeInstanceCall r t i comp "Equals" [ left; right ] |> Some | ("PhysicalEquality" | "PhysicalEqualityIntrinsic"), [ left; right ] -> referenceEquals com ctx r left right |> Some | ("PhysicalHash" | "PhysicalHashIntrinsic"), [ arg ] -> referenceHash com ctx r arg |> Some @@ -3247,17 +2463,9 @@ let enums (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Expr optio let args = match meth, args with // TODO: Parse at compile time if we know the type - | "parseEnum", [ value ] -> - [ - makeTypeInfo None t - value - ] + | "parseEnum", [ value ] -> [ makeTypeInfo None t; value ] | "tryParseEnum", [ value; refValue ] -> - [ - genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None - value - refValue - ] + [ genArg com ctx r 0 i.GenericArgs |> makeTypeInfo None; value; refValue ] | _ -> args Helper.LibCall(com, "Reflection", meth, t, args, ?loc = r) |> Some @@ -3338,16 +2546,8 @@ let ignoreFormatProvider compiledName args = | "ToString", ExprTypeAs(String, arg) :: _ -> [ arg ] | "ToString", _ -> [ makeStrConst "" ] // default (no format string) | "Parse", arg :: _ -> [ arg ] - | "TryParse", input :: _culture :: _styles :: defVal :: _ -> - [ - input - defVal - ] - | "TryParse", input :: _culture :: defVal :: _ -> - [ - input - defVal - ] + | "TryParse", input :: _culture :: _styles :: defVal :: _ -> [ input; defVal ] + | "TryParse", input :: _culture :: defVal :: _ -> [ input; defVal ] | _ -> args let makeDateOrTimeMemberCall com ctx r t i moduleName memberName (thisArg: Expr option) (args: Expr list) = @@ -3615,21 +2815,7 @@ let random (com: ICompiler) (ctx: Context) r t (i: CallInfo) (_: Expr option) (a | [ min; max ] -> min, max | _ -> FableError "Unexpected arg count for Random.Next" |> raise - Helper.LibCall( - com, - "Util", - "randomNext", - t, - [ - min - max - ], - [ - min.Type - max.Type - ], - ?loc = r - ) + Helper.LibCall(com, "Util", "randomNext", t, [ min; max ], [ min.Type; max.Type ], ?loc = r) |> Some | "NextDouble" -> Helper.GlobalCall("Math", t, [], memb = "random") |> Some | "NextBytes" -> @@ -3845,18 +3031,7 @@ let asyncBuilder (com: ICompiler) (ctx: Context) r t (i: CallInfo) (thisArg: Exp | "Singleton", _, _ -> Value(UnitConstant, r) |> Some //makeImportLib com t "singleton" "AsyncBuilder" |> Some // For Using we need to cast the argument to IDisposable - | "Using", Some callee, [ arg; f ] -> - makeInstanceCall - r - t - i - callee - "Using" - [ - arg - f - ] - |> Some + | "Using", Some callee, [ arg; f ] -> makeInstanceCall r t i callee "Using" [ arg; f ] |> Some | "Delay", _, _ -> Helper.LibCall(com, "AsyncBuilder", "delay", t, args, i.SignatureArgTypes, ?loc = r) |> Some @@ -4464,43 +3639,11 @@ let tryType typ = | BclTimer -> Some("System.Timers.Timer", timers, []) | BclTimeSpan -> Some(Types.timespan, timeSpans, []) | BclHashSet genArg -> Some(Types.hashset, hashSets, [ genArg ]) - | BclDictionary(key, value) -> - Some( - Types.dictionary, - dictionaries, - [ - key - value - ] - ) - | BclKeyValuePair(key, value) -> - Some( - Types.keyValuePair, - keyValuePairs, - [ - key - value - ] - ) - | FSharpMap(key, value) -> - Some( - Types.fsharpMap, - maps, - [ - key - value - ] - ) + | BclDictionary(key, value) -> Some(Types.dictionary, dictionaries, [ key; value ]) + | BclKeyValuePair(key, value) -> Some(Types.keyValuePair, keyValuePairs, [ key; value ]) + | FSharpMap(key, value) -> Some(Types.fsharpMap, maps, [ key; value ]) | FSharpSet genArg -> Some(Types.fsharpSet, sets, [ genArg ]) - | FSharpResult(genArg1, genArg2) -> - Some( - Types.result, - results, - [ - genArg1 - genArg2 - ] - ) + | FSharpResult(genArg1, genArg2) -> Some(Types.result, results, [ genArg1; genArg2 ]) | FSharpChoice genArgs -> Some($"{Types.choiceNonGeneric}`{List.length genArgs}", results, genArgs) | FSharpReference genArg -> Some(Types.refCell, refCells, [ genArg ]) | _ -> None diff --git a/src/Fable.Transforms/Transforms.Util.fs b/src/Fable.Transforms/Transforms.Util.fs index e99d4aabc3..c7e1b08e01 100644 --- a/src/Fable.Transforms/Transforms.Util.fs +++ b/src/Fable.Transforms/Transforms.Util.fs @@ -1569,11 +1569,7 @@ module AST = | ArrayFrom e -> [ e ] | NewList(ht, _) -> match ht with - | Some(h, t) -> - [ - h - t - ] + | Some(h, t) -> [ h; t ] | None -> [] | NewRecord(exprs, _, _) -> exprs | NewAnonymousRecord(exprs, _, _, _) -> exprs @@ -1593,16 +1589,8 @@ module AST = | Operation(kind, _, _, _) -> match kind with | Unary(_, operand) -> [ operand ] - | Binary(_, left, right) -> - [ - left - right - ] - | Logical(_, left, right) -> - [ - left - right - ] + | Binary(_, left, right) -> [ left; right ] + | Logical(_, left, right) -> [ left; right ] | Get(e, kind, _, _) -> match kind with | ListHead @@ -1612,49 +1600,18 @@ module AST = | UnionTag | UnionField _ | FieldGet _ -> [ e ] - | ExprGet e2 -> - [ - e - e2 - ] + | ExprGet e2 -> [ e; e2 ] | Sequential exprs -> exprs - | Let(_, value, body) -> - [ - value - body - ] + | Let(_, value, body) -> [ value; body ] | LetRec(bs, body) -> (List.map snd bs) @ [ body ] - | IfThenElse(cond, thenExpr, elseExpr, _) -> - [ - cond - thenExpr - elseExpr - ] + | IfThenElse(cond, thenExpr, elseExpr, _) -> [ cond; thenExpr; elseExpr ] | Set(e, kind, _, v, _) -> match kind with - | ExprSet e2 -> - [ - e - e2 - v - ] + | ExprSet e2 -> [ e; e2; v ] | FieldSet _ - | ValueSet -> - [ - e - v - ] - | WhileLoop(e1, e2, _) -> - [ - e1 - e2 - ] - | ForLoop(_, e1, e2, e3, _, _) -> - [ - e1 - e2 - e3 - ] + | ValueSet -> [ e; v ] + | WhileLoop(e1, e2, _) -> [ e1; e2 ] + | ForLoop(_, e1, e2, e3, _, _) -> [ e1; e2; e3 ] | TryCatch(body, catch, finalizer, _) -> match catch with | Some(_, c) -> body :: c :: (Option.toList finalizer) diff --git a/src/fable-compiler-js/src/Platform.fs b/src/fable-compiler-js/src/Platform.fs index 2976d1bb24..606b74e6a1 100644 --- a/src/fable-compiler-js/src/Platform.fs +++ b/src/fable-compiler-js/src/Platform.fs @@ -116,19 +116,9 @@ module Path = if path1.Length = 0 then path1 else - (path1.TrimEnd - [| - '\\' - '/' - |]) - + "/" - - path1 - + (path2.TrimStart - [| - '\\' - '/' - |]) + (path1.TrimEnd [| '\\'; '/' |]) + "/" + + path1 + (path2.TrimStart [| '\\'; '/' |]) let ChangeExtension (path: string, ext: string) = let i = path.LastIndexOf(".") diff --git a/src/fable-compiler-js/src/ProjectParser.fs b/src/fable-compiler-js/src/ProjectParser.fs index f0a307cca4..e1bfb38671 100644 --- a/src/fable-compiler-js/src/ProjectParser.fs +++ b/src/fable-compiler-js/src/ProjectParser.fs @@ -108,19 +108,10 @@ let parseCompilerOptions projectXml = projectXml |> getXmlTagContents "DefineConstants" |> Seq.collect (fun s -> s.Split(';')) - |> Seq.append - [ - "FABLE_COMPILER" - "FABLE_COMPILER_4" - "FABLE_COMPILER_JAVASCRIPT" - ] + |> Seq.append [ "FABLE_COMPILER"; "FABLE_COMPILER_4"; "FABLE_COMPILER_JAVASCRIPT" ] |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(DefineConstants)" - "" - ] + |> Seq.except [ "$(DefineConstants)"; "" ] |> Seq.toArray // get disabled warnings @@ -130,11 +121,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(NoWarn)" - "" - ] + |> Seq.except [ "$(NoWarn)"; "" ] |> Seq.toArray // get warnings as errors @@ -144,11 +131,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(WarningsAsErrors)" - "" - ] + |> Seq.except [ "$(WarningsAsErrors)"; "" ] |> Seq.toArray // get other flags @@ -158,11 +141,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(' ')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(OtherFlags)" - "" - ] + |> Seq.except [ "$(OtherFlags)"; "" ] |> Seq.toArray let otherOptions = diff --git a/src/fable-compiler-js/src/app.fs b/src/fable-compiler-js/src/app.fs index 21b0ce99eb..caa3d81c79 100644 --- a/src/fable-compiler-js/src/app.fs +++ b/src/fable-compiler-js/src/app.fs @@ -395,14 +395,7 @@ let run opts projectFileName outDir = let options = { - outDir = - opts - |> argValue - [ - "--outDir" - "-o" - ] - |> Option.orElse outDir + outDir = opts |> argValue [ "--outDir"; "-o" ] |> Option.orElse outDir libDir = opts |> argValue [ "--fableLib" ] benchmark = opts |> hasFlag "--benchmark" optimize = opts |> hasFlag "--optimize" @@ -410,11 +403,7 @@ let run opts projectFileName outDir = typedArrays = opts |> tryFlag "--typedArrays" language = opts - |> argValue - [ - "--language" - "--lang" - ] + |> argValue [ "--language"; "--lang" ] |> Option.map (fun _ -> "TypeScript") |> Option.defaultValue "JavaScript" printAst = opts |> hasFlag "--printAst" diff --git a/src/fable-compiler-js/test/test_script.fsx b/src/fable-compiler-js/test/test_script.fsx index c262daae79..1a0e01bd12 100644 --- a/src/fable-compiler-js/test/test_script.fsx +++ b/src/fable-compiler-js/test/test_script.fsx @@ -75,213 +75,33 @@ let getFirstSolution = substitute 0 0 >> Seq.head let test () = let expectedSolution = [ - [ - 1 - 2 - 8 - 3 - 4 - 5 - 6 - 9 - 7 - ] - [ - 5 - 3 - 4 - 6 - 7 - 9 - 2 - 1 - 8 - ] - [ - 6 - 7 - 9 - 1 - 8 - 2 - 5 - 4 - 3 - ] + [ 1; 2; 8; 3; 4; 5; 6; 9; 7 ] + [ 5; 3; 4; 6; 7; 9; 2; 1; 8 ] + [ 6; 7; 9; 1; 8; 2; 5; 4; 3 ] - [ - 2 - 1 - 6 - 4 - 3 - 8 - 7 - 5 - 9 - ] - [ - 4 - 8 - 5 - 7 - 9 - 1 - 3 - 2 - 6 - ] - [ - 3 - 9 - 7 - 5 - 2 - 6 - 4 - 8 - 1 - ] + [ 2; 1; 6; 4; 3; 8; 7; 5; 9 ] + [ 4; 8; 5; 7; 9; 1; 3; 2; 6 ] + [ 3; 9; 7; 5; 2; 6; 4; 8; 1 ] - [ - 7 - 6 - 2 - 9 - 1 - 4 - 8 - 3 - 5 - ] - [ - 9 - 4 - 3 - 8 - 5 - 7 - 1 - 6 - 2 - ] - [ - 8 - 5 - 1 - 2 - 6 - 3 - 9 - 7 - 4 - ] + [ 7; 6; 2; 9; 1; 4; 8; 3; 5 ] + [ 9; 4; 3; 8; 5; 7; 1; 6; 2 ] + [ 8; 5; 1; 2; 6; 3; 9; 7; 4 ] ] |> toSudoku let solution = [ - [ - 0 - 0 - 8 - 3 - 0 - 0 - 6 - 0 - 0 - ] - [ - 0 - 0 - 4 - 0 - 0 - 0 - 0 - 1 - 0 - ] - [ - 6 - 7 - 0 - 0 - 8 - 0 - 0 - 0 - 0 - ] + [ 0; 0; 8; 3; 0; 0; 6; 0; 0 ] + [ 0; 0; 4; 0; 0; 0; 0; 1; 0 ] + [ 6; 7; 0; 0; 8; 0; 0; 0; 0 ] - [ - 0 - 1 - 6 - 4 - 3 - 0 - 0 - 0 - 0 - ] - [ - 0 - 0 - 0 - 7 - 9 - 0 - 0 - 2 - 0 - ] - [ - 0 - 9 - 0 - 0 - 0 - 0 - 4 - 0 - 1 - ] + [ 0; 1; 6; 4; 3; 0; 0; 0; 0 ] + [ 0; 0; 0; 7; 9; 0; 0; 2; 0 ] + [ 0; 9; 0; 0; 0; 0; 4; 0; 1 ] - [ - 0 - 0 - 0 - 9 - 1 - 0 - 0 - 0 - 5 - ] - [ - 0 - 0 - 3 - 0 - 5 - 0 - 0 - 0 - 2 - ] - [ - 0 - 5 - 0 - 0 - 0 - 0 - 0 - 7 - 4 - ] + [ 0; 0; 0; 9; 1; 0; 0; 0; 5 ] + [ 0; 0; 3; 0; 5; 0; 0; 0; 2 ] + [ 0; 5; 0; 0; 0; 0; 0; 7; 4 ] ] |> toSudoku |> getFirstSolution diff --git a/src/fable-library-dart/Seq.fs b/src/fable-library-dart/Seq.fs index 97b9b63721..b78e255524 100644 --- a/src/fable-library-dart/Seq.fs +++ b/src/fable-library-dart/Seq.fs @@ -282,12 +282,7 @@ let toList (xs: seq<'T>) : 'T list = // let inline generateUsing (openf: unit -> ('U :> IDisposable)) compute = // generate openf compute (fun (s: 'U) -> s.Dispose()) -let append (xs: seq<'T>) (ys: seq<'T>) = - concat - [| - xs - ys - |] +let append (xs: seq<'T>) (ys: seq<'T>) = concat [| xs; ys |] //let cast (xs: Collections.IEnumerable) = // mkSeq (fun () -> @@ -898,11 +893,7 @@ let scan<'T, 'State> (folder: 'State -> 'T -> 'State) (state: 'State) (xs: seq<' acc ) - [| - first - rest - |] - |> concat + [| first; rest |] |> concat ) let scanBack<'T, 'State> (folder: 'T -> 'State -> 'State) (xs: seq<'T>) (state: 'State) : seq<'State> = diff --git a/src/fable-library/BigInt.fs b/src/fable-library/BigInt.fs index f0cdea212a..dd679162a9 100644 --- a/src/fable-library/BigInt.fs +++ b/src/fable-library/BigInt.fs @@ -91,16 +91,7 @@ let private flipTwosComplement currByte lowBitFound = | _, false -> // Found first byte containing a 1, flip higher bits and all future bytes let firstBitIndex = - [| - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - |] + [| 0; 1; 2; 3; 4; 5; 6; 7 |] |> Array.find (fun i -> currByte &&& (1uy <<< i) > 0uy) (currByte ^^^ (0b11111110uy <<< firstBitIndex)) &&& 255uy, true diff --git a/src/fable-library/Seq.fs b/src/fable-library/Seq.fs index 7f292cd134..355157e272 100644 --- a/src/fable-library/Seq.fs +++ b/src/fable-library/Seq.fs @@ -350,12 +350,7 @@ let generateIndexed create compute dispose = // let inline generateUsing (openf: unit -> ('U :> System.IDisposable)) compute = // generate openf compute (fun (s: 'U) -> s.Dispose()) -let append (xs: seq<'T>) (ys: seq<'T>) = - concat - [| - xs - ys - |] +let append (xs: seq<'T>) (ys: seq<'T>) = concat [| xs; ys |] let cast (xs: IEnumerable<'T>) = mkSeq (fun () -> @@ -953,11 +948,7 @@ let scan folder (state: 'State) (xs: seq<'T>) = acc ) - [| - first - rest - |] - |> concat + [| first; rest |] |> concat ) let scanBack folder (xs: seq<'T>) (state: 'State) = diff --git a/src/fable-standalone/src/Worker/Worker.fs b/src/fable-standalone/src/Worker/Worker.fs index 265b95ea2f..1e91c58454 100644 --- a/src/fable-standalone/src/Worker/Worker.fs +++ b/src/fable-standalone/src/Worker/Worker.fs @@ -119,13 +119,7 @@ let makeFableState (config: FableStateConfig) otherFSharpOptions = let private compileCode fable fileName fsharpNames fsharpCodes language otherFSharpOptions = async { // detect (and remove) the non-F# compiler options to avoid changing msg contract - let nonFSharpOptions = - set - [ - "--typedArrays" - "--clampByteArrays" - "--sourceMaps" - ] + let nonFSharpOptions = set [ "--typedArrays"; "--clampByteArrays"; "--sourceMaps" ] let fableOptions, otherFSharpOptions = otherFSharpOptions |> Array.partition (fun x -> Set.contains x nonFSharpOptions) diff --git a/src/fable-standalone/test/bench-compiler/Platform.fs b/src/fable-standalone/test/bench-compiler/Platform.fs index 48a4f6ca26..54e168d0a0 100644 --- a/src/fable-standalone/test/bench-compiler/Platform.fs +++ b/src/fable-standalone/test/bench-compiler/Platform.fs @@ -197,19 +197,9 @@ module Path = if path1.Length = 0 then path1 else - (path1.TrimEnd - [| - '\\' - '/' - |]) - + "/" - - path1 - + (path2.TrimStart - [| - '\\' - '/' - |]) + (path1.TrimEnd [| '\\'; '/' |]) + "/" + + path1 + (path2.TrimStart [| '\\'; '/' |]) let ChangeExtension (path: string, ext: string) = let i = path.LastIndexOf(".") diff --git a/src/fable-standalone/test/bench-compiler/ProjectParser.fs b/src/fable-standalone/test/bench-compiler/ProjectParser.fs index f0a307cca4..e1bfb38671 100644 --- a/src/fable-standalone/test/bench-compiler/ProjectParser.fs +++ b/src/fable-standalone/test/bench-compiler/ProjectParser.fs @@ -108,19 +108,10 @@ let parseCompilerOptions projectXml = projectXml |> getXmlTagContents "DefineConstants" |> Seq.collect (fun s -> s.Split(';')) - |> Seq.append - [ - "FABLE_COMPILER" - "FABLE_COMPILER_4" - "FABLE_COMPILER_JAVASCRIPT" - ] + |> Seq.append [ "FABLE_COMPILER"; "FABLE_COMPILER_4"; "FABLE_COMPILER_JAVASCRIPT" ] |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(DefineConstants)" - "" - ] + |> Seq.except [ "$(DefineConstants)"; "" ] |> Seq.toArray // get disabled warnings @@ -130,11 +121,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(NoWarn)" - "" - ] + |> Seq.except [ "$(NoWarn)"; "" ] |> Seq.toArray // get warnings as errors @@ -144,11 +131,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(';')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(WarningsAsErrors)" - "" - ] + |> Seq.except [ "$(WarningsAsErrors)"; "" ] |> Seq.toArray // get other flags @@ -158,11 +141,7 @@ let parseCompilerOptions projectXml = |> Seq.collect (fun s -> s.Split(' ')) |> Seq.map (fun s -> s.Trim()) |> Seq.distinct - |> Seq.except - [ - "$(OtherFlags)" - "" - ] + |> Seq.except [ "$(OtherFlags)"; "" ] |> Seq.toArray let otherOptions = diff --git a/src/fable-standalone/test/bench-compiler/app.fs b/src/fable-standalone/test/bench-compiler/app.fs index deb4e154ff..579701925b 100644 --- a/src/fable-standalone/test/bench-compiler/app.fs +++ b/src/fable-standalone/test/bench-compiler/app.fs @@ -372,14 +372,7 @@ let run opts projectFileName outDir = let options = { - outDir = - opts - |> argValue - [ - "--outDir" - "-o" - ] - |> Option.orElse outDir + outDir = opts |> argValue [ "--outDir"; "-o" ] |> Option.orElse outDir libDir = opts |> argValue [ "--fableLib" ] benchmark = opts |> hasFlag "--benchmark" optimize = opts |> hasFlag "--optimize" @@ -387,11 +380,7 @@ let run opts projectFileName outDir = typedArrays = opts |> tryFlag "--typedArrays" language = opts - |> argValue - [ - "--language" - "--lang" - ] + |> argValue [ "--language"; "--lang" ] |> Option.map (fun _ -> "TypeScript") |> Option.defaultValue "JavaScript" printAst = opts |> hasFlag "--printAst" diff --git a/src/quicktest-dart/QuickTest.fs b/src/quicktest-dart/QuickTest.fs index 8ca2a7234d..329bc94e23 100644 --- a/src/quicktest-dart/QuickTest.fs +++ b/src/quicktest-dart/QuickTest.fs @@ -36,12 +36,6 @@ let throwsAnyError (f: unit -> 'a) : unit = let main () = testCase "Array.length works" <| fun () -> - let xs = - [| - "a" - "a" - "a" - "a" - |] + let xs = [| "a"; "a"; "a"; "a" |] Array.length xs |> equal 4