Skip to content

Commit

Permalink
Bump version to 2.0.0-alpha-016
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsogarciacaro committed Jun 8, 2018
1 parent c144658 commit 5e385f6
Show file tree
Hide file tree
Showing 10 changed files with 720 additions and 31 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceRoot}/src/dotnet/Fable.Compiler/bin/Debug/netcoreapp2.0/Fable.Compiler.dll",
"program": "${workspaceRoot}/src/dotnet/Fable.Compiler/bin/Debug/netcoreapp2.0/dotnet-fable.dll",
"args": ["yarn-splitter", "--fable-core", "../../../build/fable-core"],
"cwd": "${workspaceRoot}/src/tools/",
"stopAtEntry": true,
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Fable.Compiler/CLI/CLI.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Fable.CLI

module Literals =

let [<Literal>] VERSION = "2.0.0-alpha-015"
let [<Literal>] VERSION = "2.0.0-alpha-016"
let [<Literal>] DEFAULT_PORT = 61225
let [<Literal>] FORCE = "force:"

Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Fable.Compiler/Fable.Compiler.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<Description>Fable: F# to JS Compiler</Description>
<Version>2.0.0</Version>
<PackageVersion>2.0.0-alpha-015</PackageVersion>
<PackageVersion>2.0.0-alpha-016</PackageVersion>
<OutputType>Exe</OutputType>
<PackageType>DotnetCliTool</PackageType>
<AssemblyName>dotnet-fable</AssemblyName>
Expand Down
2 changes: 1 addition & 1 deletion src/dotnet/Fable.Compiler/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### 2.0.0-alpha-015
### 2.0.0-alpha-016

* Fable 2 alpha

Expand Down
14 changes: 8 additions & 6 deletions src/dotnet/Fable.Compiler/Transforms/FableTransforms.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ open Microsoft.FSharp.Compiler.SourceCodeServices
let visit f e =
match e with
| IdentExpr _ | Debugger _ -> e
| Import(e1, e2, kind, t, r) -> Import(f e1, f e2, kind, t, r)
| Import(e1, e2, kind, t, r) -> Import(f e1, f e2, kind, t, r)
| Value kind ->
match kind with
| TypeInfo _ | This _ | Super _ | Null _ | UnitConstant
Expand Down Expand Up @@ -319,6 +319,8 @@ module private Transforms =
| FunctionType(LambdaType argType, returnType)
| Option(FunctionType(LambdaType argType, returnType)) ->
uncurryLambdaTypeInner [argType] returnType
| FunctionType(DelegateType argTypes, returnType) ->
argTypes, returnType
| returnType -> [], returnType

let replaceIdentType replacements (id: Ident) =
Expand Down Expand Up @@ -475,11 +477,11 @@ module private Transforms =
Operation(Emit(macro, Some info), t, r)
| e -> e

let rec uncurryApplications e =
let rec uncurryApplications (com: ICompiler) e =
match e with
| NestedApply(applied, args, t, r) ->
let applied = visitFromOutsideIn uncurryApplications applied
let args = args |> List.map (visitFromOutsideIn uncurryApplications)
let applied = visitFromOutsideIn (uncurryApplications com) applied
let args = args |> List.map (visitFromOutsideIn (uncurryApplications com))
match applied.Type with
| FunctionType(DelegateType argTypes, _) ->
if List.sameLength argTypes args then
Expand Down Expand Up @@ -519,9 +521,9 @@ let optimizations =
// Then apply uncurry optimizations
fun com e -> visitFromInsideOut (uncurryReceivedArgs com) e
fun com e -> visitFromInsideOut (uncurryRecordFields com) e
fun com e -> visitFromInsideOut (uncurrySendingArgs com) e
fun com e -> visitFromInsideOut (uncurryInnerFunctions com) e
fun _ e -> visitFromOutsideIn uncurryApplications e
fun com e -> visitFromOutsideIn (uncurryApplications com) e
fun com e -> visitFromInsideOut (uncurrySendingArgs com) e
// Don't traverse the expression for the unwrap function optimization
unwrapFunctions
]
Expand Down
53 changes: 32 additions & 21 deletions src/js/fable-core/Util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -442,28 +442,39 @@ export interface ICurried {
/* tslint:disable */
export function uncurry(arity: number, f: Function) {
/* tslint:enable */

// f may be a function option with None value
if (f == null) {
return null;
if (f == null) { return null; }

// return (...args) => {
// // In some cases there may be more arguments applied than necessary
// // (e.g. index when mapping an array), discard them
// args = args.slice(0, arity);
// let res = f;
// while (args.length > 0) {
// const curArgs = args.splice(0,1);
// res = res.apply(null, curArgs);
// }
// return res;
// };
switch (arity) {
case 2:
return (a1: any, a2: any) => f(a1)(a2);
case 3:
return (a1: any, a2: any, a3: any) => f(a1)(a2)(a3);
case 4:
return (a1: any, a2: any, a3: any, a4: any) => f(a1)(a2)(a3)(a4);
case 5:
return (a1: any, a2: any, a3: any, a4: any, a5: any) => f(a1)(a2)(a3)(a4)(a5);
case 6:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any) => f(a1)(a2)(a3)(a4)(a5)(a6);
case 7:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any) => f(a1)(a2)(a3)(a4)(a5)(a6)(a7);
case 8:
return (a1: any, a2: any, a3: any, a4: any, a5: any, a6: any, a7: any, a8: any) =>
f(a1)(a2)(a3)(a4)(a5)(a6)(a7)(a8);
default:
throw new Error("Uncurrying to more than 8-arity is not supported: " + arity);
}

const wrap: ICurried = (...args: any[]) => {
// In some cases there may be more arguments applied than necessary
// (e.g. index when mapping an array), discard them
let res: any = f;
for (let i = 0; i < arity; i++) {
const accArgs = [args[i]];
const partialArity = Math.max(f.length, 1);
while (accArgs.length < partialArity) {
accArgs.push(args[++i]);
}
res = res.apply(null, accArgs);
}
return res;
};
wrap.curried = true;
return wrap;
}

/* tslint:disable */
Expand Down Expand Up @@ -522,7 +533,7 @@ export function partialApply(arity: number, f: ICurried, args: any[]): any {
return (a1: any) => (a2: any) => (a3: any) => (a4: any) => (a5: any) => (a6: any) =>
(a7: any) => (a8: any) => f.apply(null, args.concat([a1, a2, a3, a4, a5, a6, a7, a8]));
default:
throw new Error("Partially applying to get a function with more than 8-arity is not supported: " + arity);
throw new Error("Partially applying to more than 8-arity is not supported: " + arity);
}
}
}
1 change: 1 addition & 0 deletions src/tools/QuickTest.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<Reference Include="../../build/fable/Fable.Core.dll" />
</ItemGroup>
<ItemGroup>
<Compile Include="../../tests/Main/Util/Thoth.Json.Decode.fs" />
<Compile Include="QuickTest.fs" />
</ItemGroup>
</Project>
16 changes: 16 additions & 0 deletions tests/Main/ApplicativeTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,8 @@ module Results =
let sum = add3 <!> Ok 1 <*> Ok 2 <*> Ok 3
equal (Ok 6) sum

open Thoth.Json.Decode

let tests7 = [
testCase "SRTP with ActivePattern works" <| fun () ->
(lengthWrapper []) |> equal 0
Expand Down Expand Up @@ -810,6 +812,20 @@ let tests7 = [
[1,2; 3,4; 5,6]
|> List.map (sum 10)
List.sum li |> equal 51

testCase "Composing methods returning 2-arity lambdas works" <| fun _ ->
let infoHelp version =
match version with
| 4 -> succeed 1
| 3 -> succeed 1
| _ -> fail <| "Trying to decode info, but version " + (version.ToString()) + "is not supported"

let info : Decoder<int> =
field "version" int
|> andThen infoHelp

decodeString info """{ "version": 3, "data": 2 }"""
|> equal (FSharp.Core.Ok 1)
]

let tests =
Expand Down
1 change: 1 addition & 0 deletions tests/Main/Fable.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Util/b.fs" />
<Compile Include="Util/Thoth.Json.Decode.fs" />
<Compile Include="Util/Aether.fs" />
<Compile Include="Util/Util.fs" />
<Compile Include="Util/Util2.fs" />
Expand Down
Loading

0 comments on commit 5e385f6

Please sign in to comment.