Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
470 changes: 249 additions & 221 deletions src/fsharp/IlxGen.fs

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions src/fsharp/InnerLambdasToTopLevelFuncs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,12 +1129,12 @@ module Pass4_RewriteAssembly =

// ilobj - has implicit lambda exprs and recursive/base references
| Expr.Obj (_, ty, basev, basecall, overrides, iimpls, m) ->
let basecall, z = TransExpr penv z basecall
let overrides, z = List.mapFold (TransMethod penv) z overrides
let (iimpls:(TType*ObjExprMethod list)list), (z: RewriteState) =
List.mapFold (fun z (tType, objExprs) ->
let basecall, z = TransExpr penv z basecall
let overrides, z = List.mapFold (TransMethod penv) z overrides
let iimpls, z =
(z, iimpls) ||> List.mapFold (fun z (tType, objExprs) ->
let objExprs', z' = List.mapFold (TransMethod penv) z objExprs
(tType, objExprs'), z') z iimpls
(tType, objExprs'), z')
let expr = Expr.Obj (newUnique(), ty, basev, basecall, overrides, iimpls, m)
let pds, z = ExtractPreDecs z
MakePreDecs m pds expr, z (* if TopLevel, lift preDecs over the ilobj expr *)
Expand Down
205 changes: 103 additions & 102 deletions src/fsharp/LowerCallsAndSeqs.fs

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion src/fsharp/LowerCallsAndSeqs.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ val LowerImplFile: g: TcGlobals -> assembly: TypedImplFile -> TypedImplFile
/// a program counter (pc) that records the current state, and a current generated value (current).
/// All these variables are then represented as fields in a hosting closure object along with any additional
/// free variables of the sequence expression.
val LowerSeqExpr: g: TcGlobals -> amap: ImportMap -> overallExpr: Expr -> (ValRef * ValRef * ValRef * ValRef list * Expr * Expr * Expr * TType * range) option
val ConvertSequenceExprToObject: g: TcGlobals -> amap: ImportMap -> overallExpr: Expr -> (ValRef * ValRef * ValRef * ValRef list * Expr * Expr * Expr * TType * range) option

val IsPossibleSequenceExpr: g: TcGlobals -> overallExpr: Expr -> bool
107 changes: 92 additions & 15 deletions src/fsharp/TypedTree.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4116,7 +4116,7 @@ type AttribNamedArg =
override x.ToString() = sprintf "AttribNamedArg(...)"

/// Constants in expressions
[<RequireQualifiedAccess>]
[<RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
type Const =
| Bool of bool
| SByte of sbyte
Expand All @@ -4137,6 +4137,30 @@ type Const =
| Unit
| Zero // null/zero-bit-pattern

[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override c.ToString() =
match c with
| Bool b -> (if b then "true" else "false")
| SByte x -> string x + "y"
| Byte x -> string x + "uy"
| Int16 x -> string x + "s"
| UInt16 x -> string x + "us"
| Int32 x -> string x
| UInt32 x -> string x + "u"
| Int64 x -> string x + "L"
| UInt64 x -> string x + "UL"
| IntPtr x -> string x + "n"
| UIntPtr x -> string x + "un"
| Single x -> string x + "f"
| Double x -> string x
| Char x -> "'" + string x + "'"
| String x -> "\"" + x + "\""
| Decimal x -> string x + "M"
| Unit -> "()"
| Zero -> "Const.Zero"

/// Decision trees. Pattern matching has been compiled down to
/// a decision tree by this point. The right-hand-sides (actions) of
/// a decision tree by this point. The right-hand-sides (actions) of
Expand Down Expand Up @@ -4235,7 +4259,7 @@ type DecisionTreeTest =
/// A target of a decision tree. Can be thought of as a little function, though is compiled as a local block.
[<NoEquality; NoComparison; StructuredFormatDisplay("{DebugText}")>]
type DecisionTreeTarget =
| TTarget of Vals * Expr * DebugPointForTarget
| TTarget of Val list * Expr * DebugPointForTarget

[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()
Expand Down Expand Up @@ -4359,7 +4383,7 @@ type Exprs = Expr list
type Vals = Val list

/// Represents an expression in the typed abstract syntax
[<NoEquality; NoComparison; RequireQualifiedAccess (* ; StructuredFormatDisplay("{DebugText}") *) >]
[<NoEquality; NoComparison; RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}")>]
type Expr =
/// A constant expression.
| Const of
Expand Down Expand Up @@ -4496,13 +4520,32 @@ type Expr =
/// appropriate type instantiation. These are immediately eliminated on subsequent rewrites.
| Link of Expr ref

// Prefer to use the default formatting of this union type
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
//member x.DebugText = x.ToString()
//
//override __.ToString() = "Expr(...)"

[<NoEquality; NoComparison; RequireQualifiedAccess (* ; StructuredFormatDisplay("{DebugText}") *) >]
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member expr.DebugText = expr.ToDebugString(3)

override expr.ToString() = expr.ToDebugString(3)

member expr.ToDebugString(depth: int) =
if depth = 0 then ".." else
let depth = depth - 1
match expr with
| Const (c, _, _) -> c.ToString()
| Val (v, _, _) -> v.LogicalName
| Sequential (e1, e2, _, _, _) -> "Sequential(" + e1.ToDebugString(depth) + ", " + e2.ToDebugString(depth) + ")"
| Lambda (_, _, _, vs, body, _, _) -> sprintf "Lambda(%+A, " vs + body.ToDebugString(depth) + ")"
| TyLambda (_, tps, body, _, _) -> sprintf "TyLambda(%+A, " tps + body.ToDebugString(depth) + ")"
| App (f, _, _, args, _) -> "App(" + f.ToDebugString(depth) + ", [" + String.concat ", " (args |> List.map (fun e -> e.ToDebugString(depth))) + "])"
| LetRec _ -> "LetRec(..)"
| Let (bind, body, _, _) -> "Let(" + bind.Var.DisplayName + ", " + bind.Expr.ToDebugString(depth) + ", " + body.ToDebugString(depth) + ")"
| Obj (_, _objTy, _, _, _, _, _) -> "Obj(..)"
| Match (_, _, _dt, _tgs, _, _) -> "Match(..)"
| StaticOptimization (_, _, _, _) -> "StaticOptimization(..)"
| Op (op, _, args, _) -> "Op(" + op.ToString() + ", " + String.concat ", " (args |> List.map (fun e -> e.ToDebugString(depth))) + ")"
| Quote _ -> "Quote(..)"
| TyChoose _ -> "TyChoose(..)"
| Link e -> "Link(" + e.Value.ToDebugString(depth) + ")"

[<NoEquality; NoComparison; RequireQualifiedAccess; StructuredFormatDisplay("{DebugText}") >]
type TOp =

/// An operation representing the creation of a union value of the particular union case
Expand Down Expand Up @@ -4619,11 +4662,45 @@ type TOp =
/// retTy -- the types of pushed values, if any
| ILCall of bool * bool * bool * bool * ValUseFlag * bool * bool * ILMethodRef * TypeInst * TypeInst * TTypes

// Prefer to use the default formatting of this union type
//[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
//member x.DebugText = x.ToString()
//
//override __.ToString() = "TOp(...)"
[<DebuggerBrowsable(DebuggerBrowsableState.Never)>]
member x.DebugText = x.ToString()

override op.ToString() =
match op with
| UnionCase ucref -> "UnionCase(" + ucref.CaseName + ")"
| ExnConstr ecref -> "ExnConstr(" + ecref.LogicalName + ")"
| Tuple _tupinfo -> "Tuple"
| AnonRecd _anonInfo -> "AnonRecd(..)"
| AnonRecdGet _ -> "AnonRecdGet(..)"
| Array -> "NewArray"
| Bytes _ -> "Bytes(..)"
| UInt16s _ -> "UInt16s(..)"
| While _ -> "While"
| For _ -> "For"
| TryCatch _ -> "TryCatch"
| TryFinally _ -> "TryFinally"
| Recd (_, tcref) -> "Recd(" + tcref.LogicalName + ")"
| ValFieldSet rfref -> "ValFieldSet(" + rfref.FieldName + ")"
| ValFieldGet rfref -> "ValFieldGet(" + rfref.FieldName + ")"
| ValFieldGetAddr (rfref, _) -> "ValFieldGetAddr(" + rfref.FieldName + ",..)"
| UnionCaseTagGet tcref -> "UnionCaseTagGet(" + tcref.LogicalName + ")"
| UnionCaseProof ucref -> "UnionCaseProof(" + ucref.CaseName + ")"
| UnionCaseFieldGet (ucref, _) -> "UnionCaseFieldGet(" + ucref.CaseName + ",..)"
| UnionCaseFieldGetAddr (ucref, _, _) -> "UnionCaseFieldGetAddr(" + ucref.CaseName + ",..)"
| UnionCaseFieldSet (ucref, _) -> "UnionCaseFieldSet(" + ucref.CaseName + ",..)"
| ExnFieldGet (tcref, _) -> "ExnFieldGet(" + tcref.LogicalName + ",..)"
| ExnFieldSet (tcref, _) -> "ExnFieldSet(" + tcref.LogicalName + ",..)"
| TupleFieldGet _ -> "TupleFieldGet(..)"
| ILAsm _ -> "ILAsm(..)"
| RefAddrGet _ -> "RefAddrGet(..)"
| Coerce -> "Coerce"
| Reraise -> "Reraise"
| Return -> "Return"
| Goto n -> "Goto(" + string n + ")"
| Label n -> "Label(" + string n + ")"
| TraitCall info -> "TraitCall(" + info.MemberName + ")"
| LValueOp (op, vref) -> sprintf "%+A(%s)" op vref.LogicalName
| ILCall (_,_,_,_,_,_,_,m,_,_,_) -> "ILCall(" + m.ToString() + ",..)"

/// Represents the kind of record construction operation.
type RecordConstructionInfo =
Expand Down
Loading