Skip to content

Commit

Permalink
Precompile inlined functions (#2634)
Browse files Browse the repository at this point in the history
* Remove reference to FCS in Replacements

* Precompile inline functions

* Fixt Fable.Library build

* Make tests compilable

* Unresolved member ref

* Fix standalone
  • Loading branch information
alfonsogarciacaro authored Dec 6, 2021
1 parent bb8164c commit f7871e4
Show file tree
Hide file tree
Showing 16 changed files with 660 additions and 435 deletions.
32 changes: 20 additions & 12 deletions Fable.sln
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{C8CB96CF-68A8-4083-A0F8-319275CF8097}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Core", "src\Fable.Core\Fable.Core.fsproj", "{287FF404-A34F-4385-95BE-C892BA0E3DCE}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Core", "src\Fable.Core\Fable.Core.fsproj", "{287FF404-A34F-4385-95BE-C892BA0E3DCE}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Library", "src\fable-library\Fable.Library.fsproj", "{11C625B4-0E0E-49BD-977F-4A0FC9821B5B}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Library", "src\fable-library\Fable.Library.fsproj", "{11C625B4-0E0E-49BD-977F-4A0FC9821B5B}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.AST", "src\Fable.AST\Fable.AST.fsproj", "{893F6BC9-81D7-4154-88D8-0F0D4601E7AE}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.AST", "src\Fable.AST\Fable.AST.fsproj", "{893F6BC9-81D7-4154-88D8-0F0D4601E7AE}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Transforms", "src\Fable.Transforms\Fable.Transforms.fsproj", "{AC4FFF83-30BB-4DBA-9600-C19FA999E088}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Transforms", "src\Fable.Transforms\Fable.Transforms.fsproj", "{AC4FFF83-30BB-4DBA-9600-C19FA999E088}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.Cli", "src\Fable.Cli\Fable.Cli.fsproj", "{964B545D-0EB2-485A-9D74-693D75DB3EDE}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.Cli", "src\Fable.Cli\Fable.Cli.fsproj", "{964B545D-0EB2-485A-9D74-693D75DB3EDE}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "QuickTest", "src\quicktest\QuickTest.fsproj", "{11F9359C-06BA-410A-AB1B-339B89222983}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "QuickTest", "src\quicktest\QuickTest.fsproj", "{11F9359C-06BA-410A-AB1B-339B89222983}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fable.PublishUtils", "src\Fable.PublishUtils\Fable.PublishUtils.fsproj", "{B6D5BB00-D2C2-404D-8CA2-A278784AF0CA}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fable.PublishUtils", "src\Fable.PublishUtils\Fable.PublishUtils.fsproj", "{B6D5BB00-D2C2-404D-8CA2-A278784AF0CA}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1972E8A5-9DC3-40FA-87FD-FE25FC90132B}"
ProjectSection(SolutionItems) = preProject
build.fsx = build.fsx
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{287FF404-A34F-4385-95BE-C892BA0E3DCE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{287FF404-A34F-4385-95BE-C892BA0E3DCE}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -57,6 +59,9 @@ Global
{B6D5BB00-D2C2-404D-8CA2-A278784AF0CA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B6D5BB00-D2C2-404D-8CA2-A278784AF0CA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{287FF404-A34F-4385-95BE-C892BA0E3DCE} = {C8CB96CF-68A8-4083-A0F8-319275CF8097}
{11C625B4-0E0E-49BD-977F-4A0FC9821B5B} = {C8CB96CF-68A8-4083-A0F8-319275CF8097}
Expand All @@ -66,4 +71,7 @@ Global
{11F9359C-06BA-410A-AB1B-339B89222983} = {C8CB96CF-68A8-4083-A0F8-319275CF8097}
{B6D5BB00-D2C2-404D-8CA2-A278784AF0CA} = {C8CB96CF-68A8-4083-A0F8-319275CF8097}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {58DF9285-8523-4EAC-B598-BE5B02A76A00}
EndGlobalSection
EndGlobal
48 changes: 43 additions & 5 deletions src/Fable.AST/Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ type GenericParam =
abstract Name: string

type Parameter =
abstract Name: string option
abstract Type: Type
{ Name: string option
Type: Type }

type MemberInfo =
abstract Attributes: Attribute seq
Expand Down Expand Up @@ -160,8 +160,8 @@ type Declaration =
||> List.fold (fun acc m -> Set.union acc m.UsedNames)

type File(decls, ?usedRootNames) =
member __.Declarations: Declaration list = decls
member __.UsedNamesInRootScope: Set<string> = defaultArg usedRootNames Set.empty
member _.Declarations: Declaration list = decls
member _.UsedNamesInRootScope: Set<string> = defaultArg usedRootNames Set.empty

type Ident =
{ Name: string
Expand Down Expand Up @@ -224,6 +224,7 @@ type ValueKind =
type CallMemberInfo =
{ CurriedParameterGroups: Parameter list list
IsInstance: bool
IsGetter: bool
FullName: string
CompiledName: string
DeclaringEntity: EntityRef option }
Expand Down Expand Up @@ -264,8 +265,13 @@ type OperationKind =
| Binary of BinaryOperator * left: Expr * right: Expr
| Logical of LogicalOperator * left: Expr * right: Expr

type FieldKey =
{ Name: string
FieldType: Type
IsMutable: bool }

type KeyKind =
| FieldKey of Field
| FieldKey of FieldKey
| ExprKey of Expr

type GetKind =
Expand All @@ -283,6 +289,34 @@ type TestKind =
| ListTest of isCons: bool
| UnionCaseTest of tag: int

type MemberRefInfo =
{
Name: string
Path: string
IsMutable: bool
IsPublic: bool
HasOverloadSuffix: bool
}

type UnresolvedExpr =
// TODO: Add also MemberKind from the flags?
| UnresolvedTraitCall of sourceTypes: Type list * traitName: string * isInstance: bool * argTypes: Type list * argExprs: Expr list * typ: Type * range: SourceLocation option
| UnresolvedReplaceCall of thisArg: Expr option * args: Expr list * info: ReplaceCallInfo * attachedCall: Expr option * typ: Type * range: SourceLocation option
| UnresolvedInlineCall of memberUniqueName: string * genArgs: (string * Type) list * callee: Expr option * info: CallInfo * typ: Type * range: SourceLocation option
| UnresolvedMemberRef of MemberRefInfo * typ: Type * range: SourceLocation option
member this.Type =
match this with
| UnresolvedTraitCall(_,_,_,_,_,t,_)
| UnresolvedReplaceCall(_,_,_,_,t,_)
| UnresolvedInlineCall(_,_,_,_,t,_)
| UnresolvedMemberRef(_,t,_) -> t
member this.Range =
match this with
| UnresolvedTraitCall(_,_,_,_,_,_,r)
| UnresolvedReplaceCall(_,_,_,_,_,r)
| UnresolvedInlineCall(_,_,_,_,_,r)
| UnresolvedMemberRef(_,_,r) -> r

type Expr =
// Values and Idents
| Value of ValueKind * SourceLocation option
Expand Down Expand Up @@ -326,8 +360,11 @@ type Expr =
| TryCatch of body: Expr * catch: (Ident * Expr) option * finalizer: Expr option * range: SourceLocation option
| IfThenElse of guardExpr: Expr * thenExpr: Expr * elseExpr: Expr * range: SourceLocation option

| Unresolved of UnresolvedExpr

member this.Type =
match this with
| Unresolved e -> e.Type
| Test _ -> Boolean
| Value (kind, _) -> kind.Type
| IdentExpr id -> id.Type
Expand Down Expand Up @@ -355,6 +392,7 @@ type Expr =

member this.Range: SourceLocation option =
match this with
| Unresolved e -> e.Range
| ObjectExpr _
| Sequential _
| Let _
Expand Down
26 changes: 15 additions & 11 deletions src/Fable.Cli/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ type ProjectCracked(cliArgs: CliArgs, crackerResponse: CrackerResponse, sourceFi
member _.SourceFiles = sourceFiles
member _.SourceFilePaths = sourceFiles |> Array.map (fun f -> f.NormalizedFullPath)

member _.MakeCompiler(currentFile, project, triggeredByDependency) =
let opts = { cliArgs.CompilerOptions with TriggeredByDependency = triggeredByDependency }
member _.MakeCompiler(currentFile, project, ?triggeredByDependency) =
let opts =
match triggeredByDependency with
| Some t -> { cliArgs.CompilerOptions with TriggeredByDependency = t }
| None -> cliArgs.CompilerOptions
let fableLibDir = Path.getRelativePath currentFile crackerResponse.FableLibDir
CompilerImpl(currentFile, project, opts, fableLibDir, ?outDir=cliArgs.OutDir)

Expand Down Expand Up @@ -362,26 +365,27 @@ type ProjectChecked(checker: InteractiveChecker, errors: FSharpDiagnostic array,
member _.Checker = checker
member _.Errors = errors

static member Init(config: ProjectCracked) = async {
let checker = InteractiveChecker.Create(config.ProjectOptions)
let! implFiles, errors, assemblies = checkProject config checker None
static member Init(projCracked: ProjectCracked) = async {
let checker = InteractiveChecker.Create(projCracked.ProjectOptions)
let! implFiles, errors, assemblies = checkProject projCracked checker None

return ProjectChecked(checker, errors, Project.From(
config.ProjectFile,
projCracked.ProjectFile,
implFiles,
assemblies.Value,
getPlugin = loadType config.CliArgs,
trimRootModule = config.FableOptions.RootModule))
mkCompiler = (fun p f -> projCracked.MakeCompiler(f, p)),
getPlugin = loadType projCracked.CliArgs,
trimRootModule = projCracked.FableOptions.RootModule))
}

member this.Update(config: ProjectCracked, filesToCompile) = async {
member this.Update(projCracked: ProjectCracked, filesToCompile) = async {
let! implFiles, errors, _ =
Some(Array.last filesToCompile)
|> checkProject config this.Checker
|> checkProject projCracked this.Checker

let filesToCompile = set filesToCompile
let implFiles = implFiles |> List.filter (fun f -> filesToCompile.Contains(f.FileName))
return ProjectChecked(checker, errors, this.Project.Update(implFiles))
return ProjectChecked(checker, errors, this.Project.Update(implFiles, mkCompiler = (fun p f -> projCracked.MakeCompiler(f, p))))
}

type Watcher =
Expand Down
9 changes: 9 additions & 0 deletions src/Fable.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"profiles": {
"Fable.Cli": {
"commandName": "Project",
"commandLineArgs": "watch src/Quicktest --noCache --exclude Fable.Core",
"workingDirectory": "C:\\Users\\alfon\\repos\\Fable"
}
}
}
Loading

0 comments on commit f7871e4

Please sign in to comment.