@@ -54,8 +54,8 @@ type QuotationGenerationScope =
5454
5555static member Create ( g : TcGlobals , amap , scope , isReflectedDefinition ) =
5656{ g= g
57- scope= scope
58- amap= amap
57+ scope= scope
58+ amap= amap
5959 referencedTypeDefs= new ResizeArray<_>()
6060 referencedTypeDefsTable= new Dictionary<_,_>()
6161 typeSplices= new ResizeArray<_>()
@@ -90,8 +90,8 @@ type QuotationTranslationEnv =
9090 substVals: ValMap < Expr > }
9191
9292static member Empty =
93- { vs= ValMap<_>. Empty
94- nvs= 0
93+ { vs= ValMap<_>. Empty
94+ nvs= 0
9595 tyvs= Map.empty
9696 isinstVals= ValMap<_>. Empty
9797 substVals= ValMap<_>. Empty}
@@ -103,15 +103,16 @@ type QuotationTranslationEnv =
103103member env.BindTypars vs =
104104( env, vs) ||> List.fold( fun env v -> env.BindTypar v) // fold left-to-right because indexes are left-to-right
105105
106- let BindFormalTypars ( env : QuotationTranslationEnv ) vs =
107- { envwith tyvs= Map.empty}. BindTypars vs
106+ let BindFormalTypars ( env : QuotationTranslationEnv ) vs =
107+ { envwith tyvs= Map.empty}. BindTypars vs
108108
109- let BindVal env v =
110- let idx = env.nvs
111- { envwith vs= env.vs.Add v idx; nvs= env.nvs+ 1 }
109+ let BindVal env v =
110+ { envwith
111+ vs= env.vs.Add v env.nvs
112+ nvs= env.nvs+ 1 }
112113
113114let BindIsInstVal env v ( ty , e ) =
114- { envwith isinstVals= env.isinstVals.Add v( ty, e) }
115+ { envwith isinstVals= env.isinstVals.Add v( ty, e) }
115116
116117let BindSubstVal env v e =
117118{ envwith substVals= env.substVals.Add v e}
@@ -123,13 +124,13 @@ let BindFlatVals env vs = List.fold BindVal env vs // fold left-to-right because
123124exception InvalidQuotedTermof exn
124125exception IgnoringPartOfQuotedTermWarningof string * Range.range
125126
126- let wfail e = raise( InvalidQuotedTerm( e ) )
127+ let wfail e = raise( InvalidQuotedTerm e )
127128
128129let (| ModuleValueOrMemberUse | _ |) g expr =
129130let rec loop expr args =
130131match stripExpr exprwith
131- | Expr.App(( InnerExprPat( Expr.Val( vref, vFlags,_) as f)), fty, tyargs, actualArgs,_ m) when vref.IsMemberOrModuleBinding->
132- Some( vref, vFlags, f, fty, tyargs, actualArgs@ args)
132+ | Expr.App(( InnerExprPat( Expr.Val( vref, vFlags,_) as f)), fty, tyargs, actualArgs,_ m) when vref.IsMemberOrModuleBinding->
133+ Some( vref, vFlags, f, fty, tyargs, actualArgs@ args)
133134| Expr.App( f,_ fty,[], actualArgs,_) ->
134135 loop f( actualArgs@ args)
135136| ( Expr.Val( vref, vFlags,_ m) as f) when ( match vref.ActualParentwith ParentNone-> false | _ -> true ) ->
@@ -186,10 +187,12 @@ let rec EmitDebugInfoIfNecessary cenv env m astExpr : QP.ExprData =
186187 mkInt cenv.g m m.StartLine
187188 mkInt cenv.g m m.StartColumn
188189 mkInt cenv.g m m.EndLine
189- mkInt cenv.g m m.EndColumn; ]
190+ mkInt cenv.g m m.EndColumn]
190191let attrExpr =
191192 mk_ tuple cenv.g m
192- [ mkString cenv.g m" DebugRange" ; rangeExpr]
193+ [ mkString cenv.g m" DebugRange"
194+ rangeExpr]
195+
193196let attrExprR = ConvExprCore cenv env attrExpr
194197
195198 QP.mkAttributedExpression( astExpr, attrExprR)
@@ -221,9 +224,10 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
221224let idx = cenv.exprSplices.Count
222225let ty = tyOfExpr cenv.g expr
223226
224- match ( freeInExpr CollectTyparsAndLocalsNoCaching x0) .FreeLocals|> Seq.tryPick( fun v -> if env.vs.ContainsVal vthen Some( v ) else None) with
227+ match ( freeInExpr CollectTyparsAndLocalsNoCaching x0) .FreeLocals|> Seq.tryPick( fun v -> if env.vs.ContainsVal vthen Some v else None) with
225228| Some v-> errorR( Error( FSComp.SR.crefBoundVarUsedInSplice( v.DisplayName), v.Range))
226229| None-> ()
230+
227231 cenv.exprSplices.Add(( x0, m))
228232let hole = QP.mkHole( ConvType cenv env m ty, idx)
229233( hole, rest) ||> List.fold( fun fR arg -> QP.mkApp( fR, ConvExpr cenv env arg))
@@ -235,8 +239,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
235239let ( numEnclTypeArgs , _ , isNewObj , valUseFlags , isSelfInit , takesInstanceArg , isPropGet , isPropSet ) =
236240 GetMemberCallInfo cenv.g( vref, vFlags)
237241
238- let isMember , tps , curriedArgInfos , retTy =
239-
242+ let isMember , tps , curriedArgInfos , retTy =
240243match vref.MemberInfowith
241244| Some_ when not vref.IsExtensionMember->
242245// This is an application of a member method
@@ -264,8 +267,8 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
264267// If so, adjust and try again
265268if curriedArgs.Length< curriedArgInfos.Length||
266269(( List.take curriedArgInfos.Length curriedArgs, curriedArgInfos) ||> List.exists2( fun arg argInfo ->
267- ( argInfo.Length> ( tryDestRefTupleExpr arg) .Length))) then
268-
270+ ( argInfo.Length> ( tryDestRefTupleExpr arg) .Length)))
271+ then
269272if verboseCReflectthen
270273 dprintfn" vref.DisplayName =%A was under applied" vref.DisplayName
271274// Too few arguments or incorrect tupling? Convert to a lambda and beta-reduce the
@@ -278,7 +281,6 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
278281let expr , exprty = AdjustValForExpectedArity cenv.g m vref vFlags topValInfo
279282 ConvExpr cenv env( MakeApplicationAndBetaReduce cenv.g( expr, exprty,[ tyargs], curriedArgs, m))
280283else
281-
282284// Too many arguments? Chop
283285let ( curriedArgs : Expr list ), laterArgs = List.chop curriedArgInfos.Length curriedArgs
284286
@@ -303,40 +305,40 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
303305let callArgs = ( objArgs:: untupledCurriedArgs) |> List.concat
304306
305307let parentTyconR = ConvTyconRef cenv vref.TopValActualParent m
306- let isNewObj = ( isNewObj|| valUseFlags|| isSelfInit)
308+ let isNewObj = isNewObj|| valUseFlags|| isSelfInit
307309// The signature types are w.r.t. to the formal context
308310let envinner = BindFormalTypars env tps
309- let argTys = curriedArgInfos|> List.concat|> List.map fst
311+ let argTys = curriedArgInfos|> List.concat|> List.map fst
310312let methArgTypesR = ConvTypes cenv envinner m argTys
311313let methRetTypeR = ConvReturnType cenv envinner m retTy
312314let methName = vref.CompiledName
313- let numGenericArgs = tyargs.Length- numEnclTypeArgs
315+ let numGenericArgs = tyargs.Length- numEnclTypeArgs
314316 ConvObjectModelCall cenv env m( isPropGet, isPropSet, isNewObj, parentTyconR, methArgTypesR, methRetTypeR, methName, tyargs, numGenericArgs, callArgs)
315317else
316318// This is an application of the module value.
317319 ConvModuleValueApp cenv env m vref tyargs untupledCurriedArgs
318320match curriedArgs, curriedArgInfoswith
319321// static member and module value unit argument elimination
320- | [ arg: Expr],[[]] ->
321- // we got here if quotation is represents a call with unit argument
322- // let f () = ()
323- // <@ f @> // => (\arg -> f arg) => arg is Expr.Val - no-effects, first case
324- // <@ f() @> // Expr.Const(Unit) - no-effects - first case
325- // <@ f (someFunctionThatReturnsUnit) @> - potential effects - second case
326- match argwith
327- | Expr.Val_
328- | Expr.Const( Const.Unit,_,_) -> subCall
329- | _ ->
330- let argQ = ConvExpr cenv env arg
331- QP.mkSequential( argQ, subCall)
332- | _ -> subCall
322+ | [ arg: Expr],[[]] ->
323+ // we got here if quotation is represents a call with unit argument
324+ // let f () = ()
325+ // <@ f @> // => (\arg -> f arg) => arg is Expr.Val - no-effects, first case
326+ // <@ f() @> // Expr.Const(Unit) - no-effects - first case
327+ // <@ f (someFunctionThatReturnsUnit) @> - potential effects - second case
328+ match argwith
329+ | Expr.Val_
330+ | Expr.Const( Const.Unit,_,_) -> subCall
331+ | _ ->
332+ let argQ = ConvExpr cenv env arg
333+ QP.mkSequential( argQ, subCall)
334+ | _ -> subCall
333335
334336 List.fold( fun fR arg -> QP.mkApp( fR, ConvExpr cenv env arg)) callR laterArgs
335337
336338
337339// Blast type application nodes and expression application nodes apart so values are left with just their type arguments
338340| Expr.App( f, fty,(_ :: _ as tyargs),(_ :: _ as args), m) ->
339- let rfty = applyForallTy cenv.g fty tyargs
341+ let rfty = applyForallTy cenv.g fty tyargs
340342 ConvExpr cenv env( primMkApp( primMkApp( f, fty) tyargs[] m, rfty) [] args m)
341343
342344// Uses of possibly-polymorphic values
@@ -352,12 +354,10 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
352354| Expr.Const( c, m, ty) ->
353355 ConvConst cenv env m c ty
354356
355- | Expr.Val( vref,_ vFlags, m) ->
356-
357+ | Expr.Val( vref,_ vFlags, m) ->
357358 ConvValReftrue cenv env m vref[]
358359
359- | Expr.Let( bind, body,_,_) ->
360-
360+ | Expr.Let( bind, body,_,_) ->
361361// The binding may be a compiler-generated binding that gets removed in the quotation presentation
362362match ConvLetBind cenv env bindwith
363363| None, env-> ConvExpr cenv env body
@@ -368,18 +368,18 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
368368let vsR = vs|> List.map( ConvVal cenv env)
369369let env = BindFlatVals env vs
370370let bodyR = ConvExpr cenv env body
371- let bindsR = List.zip vsR( binds|> List.map( fun b -> b.Expr |> ConvExpr cenv env))
371+ let bindsR = List.zip vsR( binds|> List.map( fun b -> ConvExpr cenv env b.Expr ))
372372 QP.mkLetRec( bindsR, bodyR)
373373
374374| Expr.Lambda(_,_,_, vs, b,_,_) ->
375375let v , b = MultiLambdaToTupledLambda cenv.g vs b
376376let vR = ConvVal cenv env v
377- let bR = ConvExpr cenv( BindVal env v) b
377+ let bR = ConvExpr cenv( BindVal env v) b
378378 QP.mkLambda( vR, bR)
379379
380380| Expr.Quote( ast,_,_,_, ety) ->
381381// F# 2.0-3.1 had a bug with nested 'raw' quotations. F# 4.0 + FSharp.Core 4.4.0.0+ allows us to do the right thing.
382- if cenv.quotationFormat= QuotationSerializationFormat.FSharp_ 40_ Plus&&
382+ if cenv.quotationFormat= QuotationSerializationFormat.FSharp_ 40_ Plus&&
383383// Look for a 'raw' quotation
384384 tyconRefEq cenv.g( tcrefOfAppTy cenv.g ety) cenv.g.raw_ expr_ tcr
385385then
@@ -415,15 +415,18 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
415415let tyargsR = ConvTypes cenv env m tyargs
416416let argsR = ConvExprs cenv env args
417417 QP.mkSum( mkR, tyargsR, argsR)
418+
418419| TOp.Tuple tupInfo, tyargs,_ ->
419420let tyR = ConvType cenv env m( mkAnyTupledTy cenv.g tupInfo tyargs)
420421let argsR = ConvExprs cenv env args
421422 QP.mkTuple( tyR, argsR) // TODO: propagate to quotations
423+
422424| TOp.Recd(_, tcref),_,_ ->
423425let rgtypR = ConvTyconRef cenv tcref m
424426let tyargsR = ConvTypes cenv env m tyargs
425427let argsR = ConvExprs cenv env args
426428 QP.mkRecdMk( rgtypR, tyargsR, argsR)
429+
427430| TOp.UnionCaseFieldGet( ucref, n), tyargs,[ e] ->
428431let tyargsR = ConvTypes cenv env m tyargs
429432let tcR , s = ConvUnionCaseRef cenv ucref m
@@ -560,14 +563,15 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
560563
561564| TOp.ILCall(_,_,_, isNewObj, valUseFlags, isProp,_, ilMethRef, enclTypeArgs, methTypeArgs,_ tys),[], callArgs->
562565let parentTyconR = ConvILTypeRefUnadjusted cenv m ilMethRef.EnclosingTypeRef
563- let isNewObj = ( isNewObj|| ( match valUseFlagswith CtorValUsedAsSuperInit| CtorValUsedAsSelfInit-> true | _ -> false ) )
566+ let isNewObj = isNewObj|| ( match valUseFlagswith CtorValUsedAsSuperInit| CtorValUsedAsSelfInit-> true | _ -> false )
564567let methArgTypesR = List.map( ConvILType cenv env m) ilMethRef.ArgTypes
565568let methRetTypeR = ConvILType cenv env m ilMethRef.ReturnType
566569let methName = ilMethRef.Name
567570let isPropGet = isProp&& methName.StartsWith( " get_" , System.StringComparison.Ordinal)
568571let isPropSet = isProp&& methName.StartsWith( " set_" , System.StringComparison.Ordinal)
569572let tyargs = ( enclTypeArgs@ methTypeArgs)
570573 ConvObjectModelCall cenv env m( isPropGet, isPropSet, isNewObj, parentTyconR, methArgTypesR, methRetTypeR, methName, tyargs, methTypeArgs.Length, callArgs)
574+
571575| TOp.TryFinally_,[_ resty],[ Expr.Lambda(_,_,_,[_], e1,_,_); Expr.Lambda(_,_,_,[_], e2,_,_)] ->
572576 QP.mkTryFinally( ConvExpr cenv env e1, ConvExpr cenv env e2)
573577
@@ -580,6 +584,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
580584
581585| TOp.Bytes bytes,[],[] ->
582586 ConvExpr cenv env( Expr.Op( TOp.Array, [ cenv.g.byte_ ty], List.ofArray( Array.map( mkByte cenv.g m) bytes), m))
587+
583588| TOp.UInt16s arr,[],[] ->
584589 ConvExpr cenv env( Expr.Op( TOp.Array, [ cenv.g.uint16_ ty], List.ofArray( Array.map( mkUInt16 cenv.g m) arr), m))
585590
@@ -595,7 +600,7 @@ and private ConvExprCore cenv (env : QuotationTranslationEnv) (expr: Expr) : QP.
595600| _ ->
596601 wfail( InternalError( sprintf" unhandled construct in AST:%A " expr, expr.Range))
597602
598- and ConvLdfld cenv env m( fspec : ILFieldSpec ) enclTypeArgs args =
603+ and ConvLdfld cenv env m ( fspec : ILFieldSpec ) enclTypeArgs args =
599604let tyargsR = ConvTypes cenv env m enclTypeArgs
600605let parentTyconR = ConvILTypeRefUnadjusted cenv m fspec.EnclosingTypeRef
601606let argsR = ConvLValueArgs cenv env args
@@ -619,6 +624,7 @@ and private ConvRFieldGetCore cenv env m rfref tyargs args =
619624let envinner = BindFormalTypars env tcref.TyparsNoRange
620625let propRetTypeR = ConvType cenv envinner m fspec.FormalType
621626 QP.mkPropGet( ( parentTyconR, fldOrPropName, propRetTypeR,[]), tyargsR, argsR)
627+
622628and ConvLetBind cenv env ( bind : Binding ) =
623629match bind.Exprwith
624630// Map for values bound by the
@@ -637,6 +643,7 @@ and ConvLetBind cenv env (bind : Binding) =
637643// Remove let unionCase = ... from quotation tree
638644| Expr.Op( TOp.UnionCaseProof_,_,[ e],_) ->
639645 None, BindSubstVal env bind.Var e
646+
640647| _ ->
641648let v = bind.Var
642649let vR = ConvVal cenv env v
@@ -651,6 +658,7 @@ and ConvLValueArgs cenv env args =
651658
652659and ConvLValueExpr cenv env expr =
653660 EmitDebugInfoIfNecessary cenv env expr.Range( ConvLValueExprCore cenv env expr)
661+
654662// This function has to undo the work of mkExprAddrOfExpr
655663and ConvLValueExprCore cenv env expr =
656664match exprwith
@@ -674,7 +682,6 @@ and ConvObjectModelCall cenv env m callInfo =
674682 EmitDebugInfoIfNecessary cenv env m( ConvObjectModelCallCore cenv env m callInfo)
675683
676684and ConvObjectModelCallCore cenv env m ( isPropGet , isPropSet , isNewObj , parentTyconR , methArgTypesR , methRetTypeR , methName , tyargs , numGenericArgs , callArgs ) =
677-
678685let tyargsR = ConvTypes cenv env m tyargs
679686let callArgsR = ConvLValueArgs cenv env callArgs
680687
@@ -698,11 +705,12 @@ and ConvObjectModelCallCore cenv env m (isPropGet,isPropSet,isNewObj,parentTycon
698705 methArgTypes= methArgTypesR
699706 methRetType= methRetTypeR
700707 methName= methName
701- numGenericArgs= numGenericArgs}
708+ numGenericArgs= numGenericArgs}
702709 QP.mkMethodCall( methR, tyargsR, callArgsR)
703710
704711and ConvModuleValueApp cenv env m ( vref : ValRef ) tyargs ( args : Expr list list ) =
705712 EmitDebugInfoIfNecessary cenv env m( ConvModuleValueAppCore cenv env m vref tyargs args)
713+
706714and ConvModuleValueAppCore cenv env m ( vref : ValRef ) tyargs ( args : Expr list list ) =
707715match vref.ActualParentwith
708716| ParentNone-> failwith" ConvModuleValueApp"