Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit09ad755

Browse files
dsymelatkin
authored andcommitted
Allow implicit quotation of expressions used as a method arguments
commit 4747cd9198db754974e179f4df2e1c2ff5378875Author: latkin <latkin@microsoft.com>Date: Wed Jan 21 15:06:33 2015 -0800 Update baseline for typecheck testcommit bd4dd1aa7b4fbd099f1ead0073e1b3ad98bdd06eMerge:c3e25848dd11c0Author: latkin <latkin@microsoft.com>Date: Wed Jan 21 14:31:37 2015 -0800 Merge branch 'auto-quote' ofhttps://git01.codeplex.com/forks/dsyme/cleanup into autoquot Conflicts: src/fsharp/creflect.fscommit8dd11c0Author: Don Syme <dsyme@microsoft.com>Date: Thu Jan 15 11:51:35 2015 +0000 clean up testscommiteb3bb2eAuthor: Don Syme <dsyme@microsoft.com>Date: Thu Jan 15 11:40:33 2015 +0000 remove auto-quotation for 'raw' Expr argumentscommitbdee98eAuthor: Don Syme <dsyme@microsoft.com>Date: Thu Jan 15 09:30:22 2015 +0000 add tests for using ReflectedDefinition methods as first class valuescommitbe48342Author: Don Syme <dsyme@microsoft.com>Date: Wed Jan 14 19:44:34 2015 +0000 allow first-class use of ReflectedDefinition methodscommit23d00fdAuthor: Don Syme <dsyme@microsoft.com>Date: Mon Jan 12 17:14:34 2015 +0000 add tests for interaction with C#-style extension memberscommit0a30282Merge:32307ff51d7b62Author: Don Syme <dsyme@microsoft.com>Date: Mon Jan 12 11:54:57 2015 +0000 Merge branch 'fsharp4' ofhttps://git01.codeplex.com/visualfsharp into auto-quotecommit32307ffAuthor: Don Syme <dsyme@microsoft.com>Date: Tue Dec 2 16:26:28 2014 +0000 update for methods defined in IL and provided methodscommit5e7517bAuthor: Don Syme <dsyme@microsoft.com>Date: Tue Dec 2 16:13:30 2014 +0000 update code and add more testscommit7cf60a1Author: Don Syme <dsyme@microsoft.com>Date: Thu Oct 30 17:17:19 2014 +0000 Allow implicit quotation of expressions used as a method arguments
1 parent6d0ac01 commit09ad755

File tree

21 files changed

+553
-82
lines changed

21 files changed

+553
-82
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ chkUnionCaseDefaultAugmentation,"default augmentation of the union case"
285285
438,chkDuplicateMethod,"Duplicate method. The method '%s' has the same name and signature as another method in this type."
286286
438,chkDuplicateMethodWithSuffix,"Duplicate method. The method '%s' has the same name and signature as another method in this type once tuples, functions, units of measure and/or provided types are erased."
287287
439,chkDuplicateMethodCurried,"The method '%s' has curried arguments but has the same name as another method in this type. Methods with curried arguments cannot be overloaded. Consider using a method taking tupled arguments."
288-
440,chkCurriedMethodsCantHaveOutParams,"Methods with curried arguments cannot declare 'out', 'ParamArray', 'optional' or 'byref' arguments"
288+
440,chkCurriedMethodsCantHaveOutParams,"Methods with curried arguments cannot declare 'out', 'ParamArray', 'optional', 'ReflectedDefinition' or 'byref' arguments"
289289
441,chkDuplicateProperty,"Duplicate property. The property '%s' has the same name and signature as another property in this type."
290290
441,chkDuplicatePropertyWithSuffix,"Duplicate property. The property '%s' has the same name and signature as another property in this type once tuples, functions, units of measure and/or provided types are erased."
291291
442,chkDuplicateMethodInheritedType,"Duplicate method. The abstract method '%s' has the same name and signature as an abstract method in an inherited type."

‎src/fsharp/FSharp.Core/prim-types.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,12 @@ namespace Microsoft.FSharp.Core
206206
typeNoComparisonAttribute()=
207207
inherit System.Attribute()
208208

209-
[<AttributeUsage(AttributeTargets.Class||| AttributeTargets.Method||| AttributeTargets.Property||| AttributeTargets.Constructor,AllowMultiple=false)>]
209+
[<AttributeUsage(AttributeTargets.Class||| AttributeTargets.Parameter||| AttributeTargets.Method||| AttributeTargets.Property||| AttributeTargets.Constructor,AllowMultiple=false)>]
210210
[<Sealed>]
211-
typeReflectedDefinitionAttribute()=
211+
typeReflectedDefinitionAttribute(includeValue: bool)=
212212
inherit System.Attribute()
213+
new()= ReflectedDefinitionAttribute(false)
214+
memberx.IncludeValue= includeValue
213215

214216
[<AttributeUsage(AttributeTargets.Method||| AttributeTargets.Class||| AttributeTargets.Field||| AttributeTargets.Interface||| AttributeTargets.Struct||| AttributeTargets.Delegate||| AttributeTargets.Enum||| AttributeTargets.Property,AllowMultiple=false)>]
215217
[<Sealed>]

‎src/fsharp/FSharp.Core/prim-types.fsi‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,14 +138,22 @@ namespace Microsoft.FSharp.Core
138138
/// <summary>Adding this attribute to the let-binding for the definition of a top-level
139139
/// value makes the quotation expression that implements the value available
140140
/// for use at runtime.</summary>
141-
[<AttributeUsage(AttributeTargets.Class||| AttributeTargets.Method||| AttributeTargets.Property||| AttributeTargets.Constructor,AllowMultiple=false)>]
141+
[<AttributeUsage(AttributeTargets.Class||| AttributeTargets.Parameter||| AttributeTargets.Method||| AttributeTargets.Property||| AttributeTargets.Constructor,AllowMultiple=false)>]
142142
[<Sealed>]
143143
typeReflectedDefinitionAttribute=
144144
inherit System.Attribute
145145
/// <summary>Creates an instance of the attribute</summary>
146146
/// <returns>ReflectedDefinitionAttribute</returns>
147147
new: unit-> ReflectedDefinitionAttribute
148148

149+
/// <summary>Creates an instance of the attribute</summary>
150+
/// <param name="includeValue">Indicates whether to include the evaluated value of the definition as the outer node of the quotation</param>
151+
/// <returns>ReflectedDefinitionAttribute</returns>
152+
new: includeValue:bool-> ReflectedDefinitionAttribute
153+
154+
/// <summary>The value of the attribute, indicating whether to include the evaluated value of the definition as the outer node of the quotation</summary>
155+
memberIncludeValue:bool
156+
149157
/// <summary>This attribute is used to indicate a generic container type satisfies the F# 'equality'
150158
/// constraint only if a generic argument also satisfies this constraint. For example, adding
151159
/// this attribute to parameter 'T on a type definition C&lt;'T&gt; means that a type C&lt;X&gt; only supports

‎src/fsharp/FSharp.Core/quotations.fs‎

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,28 @@ and
190190
| ForIntegerRangeLoopOp
191191
| WhileLoopOp
192192
// Arbitrary spliced values - not serialized
193-
| ValueOpofobj*Type
193+
| ValueOpofobj*Type*stringoption
194+
| WithValueOpofobj*Type
194195
| DefaultValueOpofType
195196

196197
and [<CompiledName("FSharpExpr")>]
197198
Expr(term:Tree,attribs:Expr list)=
198199
memberx.Tree= term
199200
memberx.CustomAttributes= attribs
200-
overridex.Equals(obj:obj)=
201-
match objwith
202-
|:? Expras yt-> x.Tree= yt.Tree
201+
202+
overridex.Equals(yobj)=
203+
match yobjwith
204+
|:? Expras y->
205+
let receq t1 t2=
206+
match t1, t2with
207+
// We special-case ValueOp to ensure that ValueWithName = Value
208+
| CombTerm(ValueOp(v1,ty1,_),[]),CombTerm(ValueOp(v2,ty2,_),[])->(v1= v2)&&(ty1= ty2)
209+
| CombTerm(c1, es1), CombTerm(c2,es2)-> c1= c2&& es1.Length= es2.Length&&(es1= es2)
210+
| VarTerm v1, VarTerm v2->(v1= v2)
211+
| LambdaTerm(v1,e1), LambdaTerm(v2,e2)->(v1= v2)&&(e1= e2)
212+
| HoleTerm(ty1,n1), HoleTerm(ty2,n2)->(ty1= ty2)&&(n1= n2)
213+
|_->false
214+
eq x.Tree y.Tree
203215
|_->false
204216

205217
overridex.GetHashCode()=
@@ -246,7 +258,9 @@ and [<CompiledName("FSharpExpr")>]
246258
| CombTerm(UnionCaseTestOp(unionCase),args)-> combL"UnionCaseTest"(exprs args@[ucaseL unionCase])
247259
| CombTerm(NewTupleOp_,args)-> combL"NewTuple"(exprs args)
248260
| CombTerm(TupleGetOp(_,i),[arg])-> combL"TupleGet"([expr arg]@[objL i])
249-
| CombTerm(ValueOp(v,_),[])-> combL"Value"[objL v]
261+
| CombTerm(ValueOp(v,_,Some nm),[])-> combL"ValueWithName"[objL v; wordL nm]
262+
| CombTerm(ValueOp(v,_,None),[])-> combL"Value"[objL v]
263+
| CombTerm(WithValueOp(v,_),[defn])-> combL"WithValue"[objL v; expr defn]
250264
| CombTerm(InstanceMethodCallOp(minfo),obj::args)-> combL"Call"[someL obj; minfoL minfo; listL(exprs args)]
251265
| CombTerm(StaticMethodCallOp(minfo),args)-> combL"Call"[noneL; minfoL minfo; listL(exprs args)]
252266
| CombTerm(InstancePropGetOp(pinfo),(obj::args))-> combL"PropertyGet"[someL obj; pinfoL pinfo; listL(exprs args)]
@@ -412,10 +426,16 @@ module Patterns =
412426
let(|VarSet|_|)=function E(CombTerm(VarSetOp,[E(VarTerm(v)); e]))-> Some(v,e)|_-> None
413427

414428
[<CompiledName("ValuePattern")>]
415-
let(|Value|_|)=function E(CombTerm(ValueOp(v,ty),_))-> Some(v,ty)|_-> None
429+
let(|Value|_|)=function E(CombTerm(ValueOp(v,ty,_),_))-> Some(v,ty)|_-> None
416430

417431
[<CompiledName("ValueObjPattern")>]
418-
let(|ValueObj|_|)=function E(CombTerm(ValueOp(v,_),_))-> Some(v)|_-> None
432+
let(|ValueObj|_|)=function E(CombTerm(ValueOp(v,_,_),_))-> Some(v)|_-> None
433+
434+
[<CompiledName("ValueWithNamePattern")>]
435+
let(|ValueWithName|_|)=function E(CombTerm(ValueOp(v,ty,Some nm),_))-> Some(v,ty,nm)|_-> None
436+
437+
[<CompiledName("WithValuePattern")>]
438+
let(|WithValue|_|)=function E(CombTerm(WithValueOp(v,ty),[e]))-> Some(v,ty,e)|_-> None
419439

420440
[<CompiledName("AddressOfPattern")>]
421441
let(|AddressOf|_|)=function Comb1(AddressOfOp,e)-> Some(e)|_-> None
@@ -535,7 +555,8 @@ module Patterns =
535555
| NewRecordOp ty,_-> ty
536556
| NewUnionCaseOp unionCase,_-> unionCase.DeclaringType
537557
| UnionCaseTestOp_,_-> typeof<Boolean>
538-
| ValueOp(_, ty),_-> ty
558+
| ValueOp(_, ty,_),_-> ty
559+
| WithValueOp(_, ty),_-> ty
539560
| TupleGetOp(ty,i),_-> FSharpType.GetTupleElements(ty).[i]
540561
| NewTupleOp ty,_-> ty
541562
| StaticPropGetOp prop,_-> prop.PropertyType
@@ -637,11 +658,13 @@ module Patterns =
637658
letmkVar v= E(VarTerm v)
638659
letmkQuote(a)= E(CombTerm(QuoteOp,[(a:>Expr)]))
639660

640-
letmkValue(v,ty)= mkFE0(ValueOp(v,ty))
661+
letmkValue(v,ty)= mkFE0(ValueOp(v,ty,None))
662+
letmkValueWithName(v,ty,nm)= mkFE0(ValueOp(v,ty,Some nm))
663+
letmkValueWithDefn(v,ty,defn)= mkFE1(WithValueOp(v,ty)) defn
641664
letmkValueG(v:'T)= mkValue(box v, typeof<'T>)
642665
letmkLiftedValueOpG(v,ty:System.Type)=
643666
letobj=if ty.IsEnumthen System.Enum.ToObject(ty, box v)else box v
644-
ValueOp(obj, ty)
667+
ValueOp(obj, ty, None)
645668
letmkUnit()= mkValue(null, typeof<unit>)
646669
letmkAddressOf v= mkFE1 AddressOfOp v
647670
letmkSequential(e1,e2)= mkFE2 SequentialOp(e1,e2)
@@ -653,7 +676,7 @@ module Patterns =
653676
letmkTryFinally(e1,e2)= mkFE2 TryFinallyOp(e1,e2)
654677

655678
letmkCoerce(ty,x)= mkFE1(CoerceOp ty) x
656-
letmkNull(ty)= mkFE0(ValueOp(null,ty))
679+
letmkNull(ty)= mkFE0(ValueOp(null,ty,None))
657680

658681
letmkApplication v= checkAppliedLambda v; mkFE2 AppOp v
659682

@@ -1457,7 +1480,7 @@ module Patterns =
14571480
|37-> u_tup2 u_NamedType u_string st|>(fun(a,b)tyargs->letfinfo= bindField(a,b,tyargs)inif finfo.IsStaticthen StaticFieldGetOp(finfo)else InstanceFieldGetOp(finfo))
14581481
|38-> u_void st|>(fun()NoTyArgs-> LetRecCombOp)
14591482
|39-> u_void st|>(fun()NoTyArgs-> AppOp)
1460-
|40-> u_void st|>(fun()(OneTyArg(ty))-> ValueOp(null,ty))
1483+
|40-> u_void st|>(fun()(OneTyArg(ty))-> ValueOp(null,ty,None))
14611484
|41-> u_void st|>(fun()(OneTyArg(ty))-> DefaultValueOp(ty))
14621485
|42-> u_PropInfoData st|>(fun(a,b,c,d)tyargs->letpinfo= bindProp(a,b,c,d,tyargs)inif pinfoIsStatic pinfothen StaticPropSetOp(pinfo)else InstancePropSetOp(pinfo))
14631486
|43-> u_tup2 u_NamedType u_string st|>(fun(a,b)tyargs->letfinfo= bindField(a,b,tyargs)inif finfo.IsStaticthen StaticFieldSetOp(finfo)else InstanceFieldSetOp(finfo))
@@ -1927,6 +1950,24 @@ type Expr with
19271950
checkNonNull"expressionType" expressionType
19281951
mkValue(obj, expressionType)
19291952

1953+
static memberValueWithName(v:'T,name:string)=
1954+
checkNonNull"name" name
1955+
mkValueWithName(box v, typeof<'T>, name)
1956+
1957+
static memberValueWithName(obj:obj,expressionType:Type,name:string)=
1958+
checkNonNull"expressionType" expressionType
1959+
checkNonNull"name" name
1960+
mkValueWithName(obj, expressionType, name)
1961+
1962+
static memberWithValue(v:'T,definition:Expr<'T>)=
1963+
letraw= mkValueWithDefn(box v, typeof<'T>, definition)
1964+
new Expr<'T>(raw.Tree,raw.CustomAttributes)
1965+
1966+
static memberWithValue(obj:obj,expressionType:Type,definition:Expr)=
1967+
checkNonNull"expressionType" expressionType
1968+
mkValueWithDefn(obj, expressionType, definition)
1969+
1970+
19301971
static memberVar(v)=
19311972
mkVar(v)
19321973

@@ -1997,7 +2038,7 @@ module DerivedPatterns =
19972038
[<CompiledName("UInt64Pattern")>]
19982039
let(|UInt64|_|)=function ValueObj(:? uint64as v)-> Some(v)|_-> None
19992040
[<CompiledName("UnitPattern")>]
2000-
let(|Unit|_|)=function Comb0(ValueOp(_,ty))when ty= typeof<unit>-> Some()|_-> None
2041+
let(|Unit|_|)=function Comb0(ValueOp(_,ty,None))when ty= typeof<unit>-> Some()|_-> None
20012042

20022043
/// (fun (x,y) -> z) is represented as 'fun p -> let x = p#0 let y = p#1' etc.
20032044
/// This reverses this encoding.
@@ -2138,7 +2179,9 @@ module ExprShape =
21382179
| TryFinallyOp,[e1;e2]-> mkTryFinally(e1,e2)
21392180
| TryWithOp,[e1;Lambda(v1,e2);Lambda(v2,e3)]-> mkTryWith(e1,v1,e2,v2,e3)
21402181
| QuoteOp,[e1]-> mkQuote(e1)
2141-
| ValueOp(v,ty),[]-> mkValue(v,ty)
2182+
| ValueOp(v,ty,None),[]-> mkValue(v,ty)
2183+
| ValueOp(v,ty,Some nm),[]-> mkValueWithName(v,ty,nm)
2184+
| WithValueOp(v,ty),[e]-> mkValueWithDefn(v,ty,e)
21422185
|_-> raise<| System.InvalidOperationException(SR.GetString(SR.QillFormedAppOrLet))
21432186

21442187

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp