Skip to content

Commit 4385bb7

Browse files
dsymelatkin
authored andcommitted
fix for 82 - Scope of types for named attribute values
Scope of types for named values in attributes improperly set as assembly where attribute is defined fixes dotnet/fsharp#82 closes dotnet/fsharp#568 commit a7e74c8cba301d39bb5b1d07f448dc4bcef88967 Author: latkin <latkin@microsoft.com> Date: Thu Aug 13 16:55:32 2015 -0700 Add tests commit 6c6cb0e0ebae07c1e55847e2ddbab72bdcffef54 Merge: d2a25c8 01dc508 Author: Don Syme <donsyme@fastmail.fm> Date: Tue Aug 4 20:05:22 2015 +0100 update commit d2a25c8db9c55d1ee0bd78c140355ccaa9130fee Author: Don Syme <donsyme@fastmail.fm> Date: Mon May 11 12:44:15 2015 +0100 updates to fix (3) commit 1097c068a457585c1e303e788d6bbb792a71e32d Author: Don Syme <donsyme@fastmail.fm> Date: Mon May 11 12:42:43 2015 +0100 updates to fix (2) commit 27c926891d1671edc6c174ee676eece370cbdc78 Author: Don Syme <donsyme@fastmail.fm> Date: Mon May 11 12:40:47 2015 +0100 updates to fix commit fb3a470b9ec90bc81f4c2289d0c0c7a6c7e3cebe Author: Don Syme <donsyme@fastmail.fm> Date: Mon May 11 12:36:13 2015 +0100 fix for 82
1 parent e6593d2 commit 4385bb7

File tree

15 files changed

+2806
-31
lines changed

15 files changed

+2806
-31
lines changed

src/absil/il.fs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4685,7 +4685,7 @@ type ILTypeSigParser(tstring : string) =
46854685
let ilty = x.ParseType()
46864686
ILAttribElem.Type(Some(ilty))
46874687

4688-
let decodeILAttribData ilg (ca: ILAttribute) scope =
4688+
let decodeILAttribData ilg (ca: ILAttribute) =
46894689
let bytes = ca.Data
46904690
let sigptr = 0
46914691
let bb0,sigptr = sigptr_get_byte bytes sigptr
@@ -4779,15 +4779,19 @@ let decodeILAttribData ilg (ca: ILAttribute) scope =
47794779
let et,sigptr = sigptr_get_u8 bytes sigptr
47804780
// We have a named value
47814781
let ty,sigptr =
4782-
// REVIEW: Post-M3, consider removing the restriction for scope - it's unnecessary
4783-
// because you can reconstruct scope using the qualified name from the CA Blob
4784-
if (0x50 = (int et) || 0x55 = (int et)) && Option.isSome scope then
4782+
if (0x50 = (int et) || 0x55 = (int et)) then
47854783
let qualified_tname,sigptr = sigptr_get_serstring bytes sigptr
4786-
// we're already getting the qualified name from the binary blob
4787-
// if we don't split out the unqualified name from the qualified name,
4788-
// we'll write the qualified assembly reference string twice to the binary blob
4789-
let unqualified_tname = qualified_tname.Split([|','|]).[0]
4790-
let scoref = Option.get scope
4784+
let unqualified_tname, rest =
4785+
let pieces = qualified_tname.Split(',')
4786+
if pieces.Length > 1 then
4787+
pieces.[0], Some (String.concat "," pieces.[1..])
4788+
else
4789+
pieces.[0], None
4790+
let scoref =
4791+
match rest with
4792+
| Some aname -> ILScopeRef.Assembly(ILAssemblyRef.FromAssemblyName(System.Reflection.AssemblyName(aname)))
4793+
| None -> ilg.traits.ScopeRef
4794+
47914795
let tref = mkILTyRef (scoref,unqualified_tname)
47924796
let tspec = mkILNonGenericTySpec tref
47934797
ILType.Value(tspec),sigptr

src/absil/il.fsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,11 +1797,9 @@ val destTypeDefsWithGlobalFunctionsFirst: ILGlobals -> ILTypeDefs -> ILTypeDef l
17971797
/// Note: not all custom attribute data can be decoded without binding types. In particular
17981798
/// enums must be bound in order to discover the size of the underlying integer.
17991799
/// The following assumes enums have size int32.
1800-
/// It also does not completely decode System.Type attributes
18011800
val decodeILAttribData:
18021801
ILGlobals ->
18031802
ILAttribute ->
1804-
ILScopeRef option ->
18051803
ILAttribElem list * (* fixed args *)
18061804
ILAttributeNamedArg list (* named args: values and flags indicating if they are fields or properties *)
18071805

src/absil/ilmorph.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ let cattr_typ2typ ilg f c =
292292
// dev11 M3 defensive coding: if anything goes wrong with attribute decoding or encoding, then back out.
293293
if morphCustomAttributeData then
294294
try
295-
let elems,namedArgs = IL.decodeILAttribData ilg c (Some(meth.MethodRef.EnclosingTypeRef.Scope))
295+
let elems,namedArgs = IL.decodeILAttribData ilg c
296296
let elems = elems |> List.map (celem_typ2typ f)
297297
let namedArgs = namedArgs |> List.map (cnamedarg_typ2typ f)
298298
IL.mkILCustomAttribMethRef ilg (meth, elems, namedArgs)

src/fsharp/IlxGen.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5796,7 +5796,7 @@ and CreatePermissionSets g amap eenv (securityAttributes : Attrib list) =
57965796
let tref = tcref.CompiledRepresentationForNamedType
57975797
let ilattr = GenAttr amap g eenv attr
57985798
let _, ilNamedArgs =
5799-
match TryDecodeILAttribute g tref (Some(tref.Scope)) (mkILCustomAttrs [ilattr]) with
5799+
match TryDecodeILAttribute g tref (mkILCustomAttrs [ilattr]) with
58005800
| Some(ae,na) -> ae, na
58015801
| _ -> [],[]
58025802
let setArgs = ilNamedArgs |> List.map (fun (n,ilt,_,ilae) -> (n,ilt,ilae))

src/fsharp/TastOps.fs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,8 +2522,8 @@ let isILAttrib (tref:ILTypeRef) (attr: ILAttribute) =
25222522
// results of attribute lookups in the TAST
25232523
let HasILAttribute tref (attrs: ILAttributes) = List.exists (isILAttrib tref) attrs.AsList
25242524

2525-
let TryDecodeILAttribute g tref scope (attrs: ILAttributes) =
2526-
attrs.AsList |> List.tryPick(fun x -> if isILAttrib tref x then Some(decodeILAttribData g.ilg x scope) else None)
2525+
let TryDecodeILAttribute g tref (attrs: ILAttributes) =
2526+
attrs.AsList |> List.tryPick(fun x -> if isILAttrib tref x then Some(decodeILAttribData g.ilg x) else None)
25272527

25282528
// This one is done by name to ensure the compiler doesn't take a dependency on dereferencing a type that only exists in .NET 3.5
25292529
let ILThingHasExtensionAttribute (attrs : ILAttributes) =
@@ -2590,7 +2590,7 @@ let TryBindTyconRefAttribute g (m:range) (AttribInfo (atref,_) as args) (tcref:T
25902590
| None -> None
25912591
#endif
25922592
| ILTypeMetadata (_,tdef) ->
2593-
match TryDecodeILAttribute g atref (Some(atref.Scope)) tdef.CustomAttrs with
2593+
match TryDecodeILAttribute g atref tdef.CustomAttrs with
25942594
| Some attr -> f1 attr
25952595
| _ -> None
25962596
| FSharpOrArrayOrByrefOrTupleOrExnTypeMetadata ->
@@ -6111,8 +6111,7 @@ let isTypeProviderAssemblyAttr (cattr:ILAttribute) =
61116111

61126112
let TryDecodeTypeProviderAssemblyAttr ilg (cattr:ILAttribute) =
61136113
if isTypeProviderAssemblyAttr cattr then
6114-
// ok to use ecmaILGlobals here since we're querying metadata, not making it
6115-
let parms, _args = decodeILAttribData ilg cattr None
6114+
let parms, _args = decodeILAttribData ilg cattr
61166115
match parms with // The first parameter to the attribute is the name of the assembly with the compiler extensions.
61176116
| (ILAttribElem.String (Some assemblyName))::_ -> Some assemblyName
61186117
| (ILAttribElem.String None)::_ -> Some null
@@ -6144,8 +6143,7 @@ let tref_AutoOpenAttr () = mkILTyRef(IlxSettings.ilxFsharpCoreLibScopeRef (), tn
61446143
let IsSignatureDataVersionAttr cattr = isILAttrib (tref_SignatureDataVersionAttr ()) cattr
61456144
let TryFindAutoOpenAttr (ilg : IL.ILGlobals) cattr =
61466145
if isILAttrib (tref_AutoOpenAttr ()) cattr then
6147-
// ok to use ecmaILGlobals here since we're querying metadata, not making it
6148-
match decodeILAttribData ilg cattr None with
6146+
match decodeILAttribData ilg cattr with
61496147
| [ILAttribElem.String s],_ -> s
61506148
| [],_ -> None
61516149
| _ ->
@@ -6159,8 +6157,7 @@ let tref_InternalsVisibleToAttr (ilg : IL.ILGlobals) =
61596157

61606158
let TryFindInternalsVisibleToAttr ilg cattr =
61616159
if isILAttrib (tref_InternalsVisibleToAttr ilg) cattr then
6162-
// ok to use ecmaILGlobals here since we're querying metadata, not making it
6163-
match decodeILAttribData ilg cattr None with
6160+
match decodeILAttribData ilg cattr with
61646161
| [ILAttribElem.String s],_ -> s
61656162
| [],_ -> None
61666163
| _ ->
@@ -6171,8 +6168,7 @@ let TryFindInternalsVisibleToAttr ilg cattr =
61716168

61726169
let IsMatchingSignatureDataVersionAttr ilg ((v1,v2,v3,_) : ILVersionInfo) cattr =
61736170
IsSignatureDataVersionAttr cattr &&
6174-
// ok to use ecmaILGlobals here since we're querying metadata, not making it
6175-
match decodeILAttribData ilg cattr None with
6171+
match decodeILAttribData ilg cattr with
61766172
| [ILAttribElem.Int32 u1; ILAttribElem.Int32 u2;ILAttribElem.Int32 u3 ],_ ->
61776173
(v1 = uint16 u1) && (v2 = uint16 u2) && (v3 = uint16 u3)
61786174
| _ ->

src/fsharp/TastOps.fsi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ val mkLdelem : TcGlobals -> range -> TType -> Expr -> Expr -> Expr
11971197
// Analyze attribute sets
11981198
//-------------------------------------------------------------------------
11991199

1200-
val TryDecodeILAttribute : TcGlobals -> ILTypeRef -> ILScopeRef option -> ILAttributes -> (ILAttribElem list * ILAttributeNamedArg list) option
1200+
val TryDecodeILAttribute : TcGlobals -> ILTypeRef -> ILAttributes -> (ILAttribElem list * ILAttributeNamedArg list) option
12011201
val TryFindILAttribute : BuiltinAttribInfo -> ILAttributes -> bool
12021202
val TryFindILAttributeOpt : BuiltinAttribInfo option -> ILAttributes -> bool
12031203

src/fsharp/TypeChecker.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9722,7 +9722,7 @@ and TcAttribute cenv (env: TcEnv) attrTgt (synAttr: SynAttribute) =
97229722
let tdef = tcref.ILTyconRawMetadata
97239723
let tref = cenv.g.attrib_AttributeUsageAttribute.TypeRef
97249724

9725-
match TryDecodeILAttribute cenv.g tref (Some(tref.Scope)) tdef.CustomAttrs with
9725+
match TryDecodeILAttribute cenv.g tref tdef.CustomAttrs with
97269726
| Some ([ILAttribElem.Int32 validOn ],named) ->
97279727
let inherited =
97289728
match List.tryPick (function ("Inherited",_,_,ILAttribElem.Bool res) -> Some res | _ -> None) named with

src/fsharp/infos.fs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ type ILMethInfo =
753753
member x.IsDllImport g =
754754
match g.attrib_DllImportAttribute with
755755
| None -> false
756-
| Some (AttribInfo(tref,_)) ->x.RawMetadata.CustomAttrs |> TryDecodeILAttribute g tref (Some tref.Scope) |> isSome
756+
| Some (AttribInfo(tref,_)) ->x.RawMetadata.CustomAttrs |> TryDecodeILAttribute g tref |> isSome
757757

758758
/// Get the (zero or one) 'self'/'this'/'object' arguments associated with an IL method.
759759
/// An instance extension method returns one object argument.
@@ -1233,7 +1233,7 @@ type MethInfo =
12331233
[ [ for p in ilMethInfo.ParamMetadata do
12341234
let isParamArrayArg = TryFindILAttribute g.attrib_ParamArrayAttribute p.CustomAttrs
12351235
let reflArgInfo =
1236-
match TryDecodeILAttribute g g.attrib_ReflectedDefinitionAttribute.TypeRef (Some(g.attrib_ReflectedDefinitionAttribute.TypeRef.Scope)) p.CustomAttrs with
1236+
match TryDecodeILAttribute g g.attrib_ReflectedDefinitionAttribute.TypeRef p.CustomAttrs with
12371237
| Some ([ILAttribElem.Bool b ],_) -> ReflectedArgInfo.Quote b
12381238
| Some _ -> ReflectedArgInfo.Quote false
12391239
| _ -> ReflectedArgInfo.None
@@ -2558,7 +2558,7 @@ module AttributeChecking =
25582558
ignore f3
25592559
#endif
25602560
BindMethInfoAttributes m minfo
2561-
(fun ilAttribs -> TryDecodeILAttribute g atref (Some(atref.Scope)) ilAttribs |> Option.bind f1)
2561+
(fun ilAttribs -> TryDecodeILAttribute g atref ilAttribs |> Option.bind f1)
25622562
(fun fsAttribs -> TryFindFSharpAttribute g attribSpec fsAttribs |> Option.bind f2)
25632563
#if EXTENSIONTYPING
25642564
(fun provAttribs ->
@@ -2591,7 +2591,7 @@ module AttributeChecking =
25912591
/// Check IL attributes for 'ObsoleteAttribute', returning errors and warnings as data
25922592
let private CheckILAttributes g cattrs m =
25932593
let (AttribInfo(tref,_)) = g.attrib_SystemObsolete
2594-
match TryDecodeILAttribute g tref (Some(tref.Scope)) cattrs with
2594+
match TryDecodeILAttribute g tref cattrs with
25952595
| Some ([ILAttribElem.String (Some msg) ],_) ->
25962596
WarnD(ObsoleteWarning(msg,m))
25972597
| Some ([ILAttribElem.String (Some msg); ILAttribElem.Bool isError ],_) ->
@@ -2676,7 +2676,7 @@ module AttributeChecking =
26762676
/// Indicate if a list of IL attributes contains 'ObsoleteAttribute'. Used to suppress the item in intellisense.
26772677
let CheckILAttributesForUnseen g cattrs _m =
26782678
let (AttribInfo(tref,_)) = g.attrib_SystemObsolete
2679-
isSome (TryDecodeILAttribute g tref (Some(tref.Scope)) cattrs)
2679+
isSome (TryDecodeILAttribute g tref cattrs)
26802680

26812681
/// Checks the attributes for CompilerMessageAttribute, which has an IsHidden argument that allows
26822682
/// items to be suppressed from intellisense.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type T = Top.Repro.C
2+
T.Run()
3+
4+
let attrs = typeof<T>.GetMethod("Run").GetCustomAttributes(false)
5+
let attr = attrs.[0] :?> System.ServiceModel.FaultContractAttribute
6+
7+
printfn "%A" (attr.ProtectionLevel.ToString())
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NoMT SOURCE=mirror.fs SCFLAGS="-a ..\\providedtypes.fs" PRECMD="\$CSC_PIPE /target:library library.cs" # Attribute_Arg_Type_Scope_Setup
2+
NoMT SOURCE=client.fs SCFLAGS="-r:mirror.dll -r:System.ServiceModel.dll" # Attribute_Arg_Type_Scope_Test

0 commit comments

Comments
 (0)