Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Quotation support #1839

Open
wants to merge 46 commits into
base: nagareyama
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b362f7f
initial Quotations sketch
krauthaufen Apr 5, 2019
2924407
added some Expr constructors
krauthaufen Apr 5, 2019
0bb535b
Reflection sync
krauthaufen Apr 6, 2019
5f300b6
removed old Reflection API
krauthaufen Apr 6, 2019
5338cc7
most tests working again
krauthaufen Apr 7, 2019
f5d6b34
passing generic parameter names
krauthaufen Apr 8, 2019
0631fcf
declarations no longer using old reflection-API
krauthaufen Apr 8, 2019
8d54ed1
removed old Reflection API (fixed generic types)
krauthaufen Apr 8, 2019
6ef3907
added support for GenericMethods
krauthaufen Apr 8, 2019
0a0cbd4
Reflection error messages
krauthaufen Apr 9, 2019
eefedb5
Expr implementation
krauthaufen Apr 9, 2019
57445e9
added missing get_FieldType function
krauthaufen Apr 9, 2019
e398346
Module reflection
krauthaufen Apr 11, 2019
d344a05
implemented quotation path through all stages (only Lambda/Var/Value/…
krauthaufen Apr 13, 2019
6ba809e
added one-line ToString for Expr
krauthaufen Apr 13, 2019
b84fd26
most quotation things working
krauthaufen Apr 16, 2019
538137e
String: implemented FromBase64String/ToBase64String from first princi…
krauthaufen Apr 17, 2019
e4a41bb
sync
krauthaufen Apr 18, 2019
0f225b8
various reflection fixes
krauthaufen Apr 19, 2019
56e71f4
standalone working again
krauthaufen Apr 23, 2019
75bb2d2
Merge branch 'master' of github.com:fable-compiler/Fable
krauthaufen Apr 23, 2019
a3b129c
Tests: re-enabled DateTimeOffset test
krauthaufen Apr 23, 2019
183614d
Fable.Transforms: re-added DisableImplicitFSharpCoreReference
krauthaufen Apr 23, 2019
073396b
added SourceLocations for Quotations and improved error handling
krauthaufen Apr 23, 2019
951eaa2
fixed quotation error messages
krauthaufen Apr 23, 2019
3a66110
Merge branch 'master' of github.com:fable-compiler/Fable
krauthaufen Apr 23, 2019
4ed7175
Fable.Library: added preprocessor defines again
krauthaufen Apr 23, 2019
bcddad5
build: increased max heap size
krauthaufen Apr 23, 2019
efd5b73
Quotation cleanup (optional debug ranges for Expr)
krauthaufen Apr 24, 2019
bcbfc19
Reflection cleanup (fixed implementations for Invoke/GetValue/SetValue)
krauthaufen Apr 24, 2019
be89aa6
Quotations: fixed nasty but in RebuildShapeCombination
krauthaufen Apr 24, 2019
2aa205a
added FABLE_QUOTATIONS define to enable quotation features
krauthaufen Apr 24, 2019
569fe0f
Merge pull request #1818 from krauthaufen/master
alfonsogarciacaro Apr 26, 2019
0edf884
- now importing precompiled reflection-infos - Reflection-Infos no lo…
krauthaufen Apr 27, 2019
185f57a
Reflection: added GetHashCode/Equals/CompareTo to MemberInfos
krauthaufen Apr 29, 2019
707661b
Quotations: Var now using Guid instead of incrementing id (caused pro…
krauthaufen Apr 29, 2019
d1ea26d
Merge branch 'master' into quotations
alfonsogarciacaro May 9, 2019
2b8d6fd
Publish fable-compiler-quotations 2.3.7
alfonsogarciacaro May 9, 2019
32a1df7
Merge branch 'master' into quotations
alfonsogarciacaro May 19, 2019
a7495d6
Fix fable-library
alfonsogarciacaro May 20, 2019
d400928
Merge branch 'master' into quotations
alfonsogarciacaro May 20, 2019
bf25730
Publish 2.3.10
alfonsogarciacaro May 20, 2019
cd1cb8f
[FSharpToFable] hacky fix for unknown attribute constructors (solving…
krauthaufen May 31, 2019
d5227d6
Merge branch 'master' into quotations
alfonsogarciacaro Apr 27, 2020
a48d4bf
Merge branch 'master' into quotations
alfonsogarciacaro Jun 4, 2020
38a2494
Resoved conflicts
ncave Jun 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Fable.Cli/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ let toCompilerOptions (msg: Message): CompilerOptions =
debugMode = Array.contains "DEBUG" msg.define
verbosity = GlobalParams.Singleton.Verbosity
outputPublicInlinedFunctions = Array.contains "FABLE_REPL_LIB" msg.define
quotations = Array.contains "FABLE_QUOTATIONS" msg.define
precompiledLib = None
}

Expand Down
61 changes: 58 additions & 3 deletions src/Fable.Transforms/AST/AST.Fable.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Type =
| Char
| String
| Regex
| Expr of gen : Option<Type>
| Number of NumberKind
| Enum of FSharpEntity
| Option of genericArg: Type
Expand All @@ -29,7 +30,7 @@ type Type =

member this.Generics =
match this with
| Option gen | Array gen | List gen -> [gen]
| Expr (Some gen) | Option gen | Array gen | List gen -> [gen]
| FunctionType(LambdaType argType, returnType) -> [argType; returnType]
| FunctionType(DelegateType argTypes, returnType) -> argTypes @ [returnType]
| Tuple gen -> gen
Expand All @@ -38,6 +39,7 @@ type Type =
| _ -> []
member this.ReplaceGenerics(newGen: Type list) =
match this with
| Expr (Some _) -> Expr (Some newGen.Head)
| Option _ -> Option newGen.Head
| Array _ -> Array newGen.Head
| List _ -> List newGen.Head
Expand All @@ -52,6 +54,32 @@ type Type =
| DeclaredType(ent,_) -> DeclaredType(ent,newGen)
| t -> t


type ParameterInfo =
{
Name : string
Type : Type
}

type MemberInfoKind =
| Property of name : string * typ : Type * fsharp : bool * isStatic : bool * get : Option<Expr> * set : Option<Expr>
| Field of name : string * typ : Type * isStatic : bool * get : Option<Expr>
| Method of genericParameters : string[] * name : string * parameters : ParameterInfo[] * returnType : Type * isStatic : bool * invoke : Option<Expr>
| Constructor of parameters : ParameterInfo[] * invoke : Expr
| UnionCaseConstructor of tag : int * name : string * parameters : array<string * Type> * mangledName : string * mangledTypeName : string

type MemberInfo =
{
Kind : MemberInfoKind
Attributes : array<string * Expr>
}

type UnionCaseInfo =
{
Name : string
Fields : MemberInfo[]
}

type ValueDeclarationInfo =
{ Name: string
IsPublic: bool
Expand All @@ -63,6 +91,7 @@ type ValueDeclarationInfo =
type ClassImplicitConstructorInfo =
{ Name: string
Entity: FSharpEntity
Members : MemberInfo[]
EntityName: string
IsEntityPublic: bool
IsConstructorPublic: bool
Expand All @@ -74,11 +103,13 @@ type ClassImplicitConstructorInfo =

type UnionConstructorInfo =
{ Entity: FSharpEntity
Members : MemberInfo[]
EntityName: string
IsPublic: bool }

type CompilerGeneratedConstructorInfo =
{ Entity: FSharpEntity
Members : MemberInfo[]
EntityName: string
IsPublic: bool }

Expand All @@ -96,7 +127,8 @@ type Declaration =
| ActionDeclaration of Expr
| ValueDeclaration of Expr * ValueDeclarationInfo
| AttachedMemberDeclaration of args: Ident list * body: Expr * AttachedMemberDeclarationInfo
| ConstructorDeclaration of ConstructorKind * SourceLocation option
| ConstructorDeclaration of declaringName : Option<string> * ConstructorKind * SourceLocation option
| ModuleDeclaration of declaringName : Option<string> * name : string * ent : FSharpEntity * mems : MemberInfo[]

type File(sourcePath, decls, ?usedVarNames, ?inlineDependencies) =
member __.SourcePath: string = sourcePath
Expand Down Expand Up @@ -271,6 +303,24 @@ type DelayedResolutionKind =
| AsPojo of Expr * caseRules: Expr
| Curry of Expr * arity: int


type VarData =
{ name : string; typ : Type; isMutable : bool }

type ValueData =
{ name : string; typ : Type; expr : Expr }

type ExprData =
{
typ : Type
variables : VarData[]
values : ValueData[]
literals : Expr[]
types : Type[]
members : array<FSharpEntity * Type * MemberInfo * Type[]>
data : byte[]
}

type Expr =
| Value of ValueKind * SourceLocation option
| IdentExpr of Ident
Expand Down Expand Up @@ -300,8 +350,12 @@ 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

| Quote of typed : bool * data : ExprData * range : SourceLocation option

member this.Type =
match this with
| Quote(true, value, _) -> Expr(Some value.typ)
| Quote(false, _, _) -> Expr None
| Test _ -> Boolean
| Value(kind,_) -> kind.Type
| IdentExpr id -> id.Type
Expand All @@ -320,10 +374,11 @@ type Expr =
| Import _ | DelayedResolution _
| ObjectExpr _ | Sequential _ | Let _
| DecisionTree _ | DecisionTreeSuccess _ -> None

| Function(_,e,_) | TypeCast(e,_) -> e.Range
| IdentExpr id -> id.Range

| Quote(_,_,r)
| Value(_,r) | IfThenElse(_,_,_,r) | TryCatch(_,_,_,r)
| Debugger r | Test(_,_,r) | Operation(_,_,r) | Get(_,_,_,r)
| Throw(_,_,r) | Set(_,_,_,r) | Loop(_,r) -> r
15 changes: 14 additions & 1 deletion src/Fable.Transforms/FSharp2Fable.Util.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type Context =
InlinePath: (string * (SourceLocation option)) list
CaptureBaseConsCall: (FSharpEntity * (Fable.Expr * Fable.Expr -> unit)) option
}
static member Create(enclosingEntity) =
static member Create(enclosingEntity:Option<FSharpEntity>) =
{ Scope = []
ScopeInlineValues = []
GenericArgs = Map.empty
Expand Down Expand Up @@ -104,6 +104,18 @@ module Helpers =
(getEntityMangledName com true ent, Naming.NoMemberPart)
||> Naming.sanitizeIdent (fun _ -> false)

let getModuleReflectionName (com: ICompiler) (ent : FSharpEntity) =
if ent.IsFSharpModule then
let name =
(getEntityMangledName com true ent, Naming.NoMemberPart)
||> Naming.sanitizeIdent (fun _ -> false)
if name = "" then
Some ""
else
Some name
else
None

let isUnit (typ: FSharpType) =
let typ = nonAbbreviatedType typ
if typ.HasTypeDefinition
Expand Down Expand Up @@ -144,6 +156,7 @@ module Helpers =
| Naming.StaticMemberPart(_, overloadSuffix) ->
String.IsNullOrEmpty(overloadSuffix) |> not
| Naming.NoMemberPart -> false
| Naming.ReflectionMemberPart -> false
sanitizedName, hasOverloadSuffix

/// Used to identify members uniquely in the inline expressions dictionary
Expand Down
Loading