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

Commit7cf60a1

Browse files
committed
Allow implicit quotation of expressions used as a method arguments
1 parent805e0b2 commit7cf60a1

File tree

17 files changed

+390
-74
lines changed

17 files changed

+390
-74
lines changed

‎src/fsharp/FSComp.txt‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ chkUnionCaseDefaultAugmentation,"default augmentation of the union case"
286286
438,chkDuplicateMethod,"Duplicate method. The method '%s' has the same name and signature as another method in this type."
287287
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."
288288
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."
289-
440,chkCurriedMethodsCantHaveOutParams,"Methods with curried arguments cannot declare 'out', 'ParamArray', 'optional' or 'byref' arguments"
289+
440,chkCurriedMethodsCantHaveOutParams,"Methods with curried arguments cannot declare 'out', 'ParamArray', 'optional', 'ReflectedDefinition' or 'byref' arguments"
290290
441,chkDuplicateProperty,"Duplicate property. The property '%s' has the same name and signature as another property in this type."
291291
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."
292292
442,chkDuplicateMethodInheritedType,"Duplicate method. The abstract method '%s' has the same name and signature as an abstract method in an inherited type."
@@ -1331,4 +1331,4 @@ descriptionUnavailable,"(description unavailable...)"
13311331
3176,tcFieldNameConflictsWithGeneratedNameForAnonymousField,"Named field '%s' conflicts with autogenerated name for anonymous field."
13321332
3177,tastConstantExpressionOverflow,"This literal expression or attribute argument results in an arithmetic overflow."
13331333
3178,tcIllegalStructTypeForConstantExpression,"This is not valid literal expression. The [<Literal>] attribute will be ignored."
1334-
3179,fscSystemRuntimeInteropServicesIsRequired,"System.Runtime.InteropServices assembly is required to use UnknownWrapper\DispatchWrapper classes."
1334+
3179,fscSystemRuntimeInteropServicesIsRequired,"System.Runtime.InteropServices assembly is required to use UnknownWrapper\DispatchWrapper classes."

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

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

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

212214
[<AttributeUsage(AttributeTargets.Method||| AttributeTargets.Class||| AttributeTargets.Field||| AttributeTargets.Interface||| AttributeTargets.Struct||| AttributeTargets.Delegate||| AttributeTargets.Enum||| AttributeTargets.Property,AllowMultiple=false)>]
213215
[<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

@@ -1434,7 +1457,7 @@ module Patterns =
14341457
|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))
14351458
|38-> u_void st|>(fun()NoTyArgs-> LetRecCombOp)
14361459
|39-> u_void st|>(fun()NoTyArgs-> AppOp)
1437-
|40-> u_void st|>(fun()(OneTyArg(ty))-> ValueOp(null,ty))
1460+
|40-> u_void st|>(fun()(OneTyArg(ty))-> ValueOp(null,ty,None))
14381461
|41-> u_void st|>(fun()(OneTyArg(ty))-> DefaultValueOp(ty))
14391462
|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))
14401463
|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))
@@ -1897,6 +1920,24 @@ type Expr with
18971920
checkNonNull"expressionType" expressionType
18981921
mkValue(obj, expressionType)
18991922

1923+
static memberValueWithName(v:'T,name:string)=
1924+
checkNonNull"name" name
1925+
mkValueWithName(box v, typeof<'T>, name)
1926+
1927+
static memberValueWithName(obj:obj,expressionType:Type,name:string)=
1928+
checkNonNull"expressionType" expressionType
1929+
checkNonNull"name" name
1930+
mkValueWithName(obj, expressionType, name)
1931+
1932+
static memberWithValue(v:'T,definition:Expr<'T>)=
1933+
letraw= mkValueWithDefn(box v, typeof<'T>, definition)
1934+
new Expr<'T>(raw.Tree,raw.CustomAttributes)
1935+
1936+
static memberWithValue(obj:obj,expressionType:Type,definition:Expr)=
1937+
checkNonNull"expressionType" expressionType
1938+
mkValueWithDefn(obj, expressionType, definition)
1939+
1940+
19001941
static memberVar(v)=
19011942
mkVar(v)
19021943

@@ -1957,7 +1998,7 @@ module DerivedPatterns =
19571998
[<CompiledName("UInt64Pattern")>]
19581999
let(|UInt64|_|)=function ValueObj(:? uint64as v)-> Some(v)|_-> None
19592000
[<CompiledName("UnitPattern")>]
1960-
let(|Unit|_|)=function Comb0(ValueOp(_,ty))when ty= typeof<unit>-> Some()|_-> None
2001+
let(|Unit|_|)=function Comb0(ValueOp(_,ty,None))when ty= typeof<unit>-> Some()|_-> None
19612002

19622003
/// (fun (x,y) -> z) is represented as 'fun p -> let x = p#0 let y = p#1' etc.
19632004
/// This reverses this encoding.
@@ -2086,7 +2127,9 @@ module ExprShape =
20862127
| TryFinallyOp,[e1;e2]-> mkTryFinally(e1,e2)
20872128
| TryWithOp,[e1;Lambda(v1,e2);Lambda(v2,e3)]-> mkTryWith(e1,v1,e2,v2,e3)
20882129
| QuoteOp,[e1]-> mkQuote(e1)
2089-
| ValueOp(v,ty),[]-> mkValue(v,ty)
2130+
| ValueOp(v,ty,None),[]-> mkValue(v,ty)
2131+
| ValueOp(v,ty,Some nm),[]-> mkValueWithName(v,ty,nm)
2132+
| WithValueOp(v,ty),[e]-> mkValueWithDefn(v,ty,e)
20902133
|_-> raise<| System.InvalidOperationException(SR.GetString(SR.QillFormedAppOrLet))
20912134

20922135

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp