未验证 提交 478dfd76 编写于 作者: K Kevin Ransom (msft) 提交者: GitHub

Set serializable bit for all serializable types (#4211)

上级 5a12cde1
......@@ -3747,8 +3747,8 @@ and GenClosureTypeDefs cenv (tref:ILTypeRef, ilGenParams, attrs, ilCloFreeVars,
Properties = emptyILProperties
Methods= mkILMethods mdefs
MethodImpls= mkILMethodImpls mimpls
IsSerializable= cenv.g.attrib_SerializableAttribute.IsSome
IsComInterop= false
IsSerializable=true
IsComInterop= false
IsSpecialName= true
NestedTypes=emptyILTypeDefs
Encoding= ILDefaultPInvokeEncoding.Auto
......@@ -3803,8 +3803,8 @@ and GenLambdaClosure cenv (cgbuf:CodeGenBuffer) eenv isLocalTypeFunc selfv expr
Properties = emptyILProperties
Methods= mkILMethods ilContractMeths
MethodImpls= emptyILMethodImpls
IsSerializable= cenv.g.attrib_SerializableAttribute.IsSome
IsComInterop=false
IsSerializable=true
IsComInterop=false
IsSpecialName= true
NestedTypes=emptyILTypeDefs
Encoding= ILDefaultPInvokeEncoding.Auto
......@@ -6563,9 +6563,8 @@ and GenTypeDef cenv mgbuf lazyInitInfo eenv m (tycon:Tycon) =
let ilFields = mkILFields ilFieldDefs
let tdef, tdefDiscards =
let isSerializable = (TryFindFSharpBoolAttribute cenv.g cenv.g.attrib_AutoSerializableAttribute tycon.Attribs <> Some(false))
&& cenv.g.attrib_SerializableAttribute.IsSome
let isSerializable = (TryFindFSharpBoolAttribute cenv.g cenv.g.attrib_AutoSerializableAttribute tycon.Attribs <> Some(false))
match tycon.TypeReprInfo with
| TILObjectRepr _ ->
let td = tycon.ILTyconRawMetadata
......@@ -6817,11 +6816,10 @@ and GenExnDef cenv mgbuf eenv m (exnc:Tycon) =
else
[]
let serializationRelatedMembers =
// do not emit serialization related members if target framework lacks SerializableAttribute or SerializationInfo
match cenv.g.attrib_SerializableAttribute, cenv.g.iltyp_SerializationInfo, cenv.g.iltyp_StreamingContext with
| Some _, Some serializationInfoType, Some streamingContextType ->
// do not emit serialization related members if target framework lacks SerializationInfo or StreamingContext
match cenv.g.iltyp_SerializationInfo, cenv.g.iltyp_StreamingContext with
| Some serializationInfoType, Some streamingContextType ->
let ilCtorDefForSerialziation =
mkILCtor(ILMemberAccess.Family,
[mkILParamNamed("info", serializationInfoType);mkILParamNamed("context",streamingContextType)],
......@@ -6880,7 +6878,7 @@ and GenExnDef cenv mgbuf eenv m (exnc:Tycon) =
emptyILEvents,
mkILCustomAttrs [mkCompilationMappingAttr cenv.g (int SourceConstructFlags.Exception)],
ILTypeInit.BeforeField)
let tdef = { tdef with IsSerializable = cenv.g.attrib_SerializableAttribute.IsSome }
let tdef = { tdef with IsSerializable = true }
mgbuf.AddTypeDef(tref, tdef, false, false, None)
......
......@@ -1005,7 +1005,6 @@ type public TcGlobals(compilingFslib: bool, ilg:ILGlobals, fslibCcu: CcuThunk, d
member val attrib_ProjectionParameterAttribute = mk_MFCore_attrib "ProjectionParameterAttribute"
member val attrib_CustomOperationAttribute = mk_MFCore_attrib "CustomOperationAttribute"
member val attrib_NonSerializedAttribute = tryFindSysAttrib "System.NonSerializedAttribute"
member val attrib_SerializableAttribute = tryFindSysAttrib "System.SerializableAttribute"
member val attrib_AutoSerializableAttribute = mk_MFCore_attrib "AutoSerializableAttribute"
member val attrib_RequireQualifiedAccessAttribute = mk_MFCore_attrib "RequireQualifiedAccessAttribute"
......
......@@ -1968,12 +1968,10 @@ let main2b (tcImportsCapture,dynamicAssemblyCreator) (Args (ctok, tcConfig: TcCo
use unwindBuildPhase = PushThreadBuildPhaseUntilUnwind BuildPhase.IlxGen
let ilxGenerator = CreateIlxAssemblyGenerator (tcConfig, tcImports, tcGlobals, (LightweightTcValForUsingInBuildMethodCall tcGlobals), generatedCcu)
// Check if System.SerializableAttribute exists in mscorlib.dll,
// so that make sure the compiler only emits "serializable" bit into IL metadata when it is available.
// Note that SerializableAttribute may be relocated in the future but now resides in mscorlib.
let codegenResults = GenerateIlxCode ((if Option.isSome dynamicAssemblyCreator then IlReflectBackend else IlWriteBackend), Option.isSome dynamicAssemblyCreator, false, tcConfig, topAttrs, optimizedImpls, generatedCcu.AssemblyName, ilxGenerator)
let casApplied = new Dictionary<Stamp, bool>()
let securityAttrs, topAssemblyAttrs = topAttrs.assemblyAttrs |> List.partition (fun a -> TypeChecker.IsSecurityAttribute tcGlobals (tcImports.GetImportMap()) casApplied a rangeStartup)
// remove any security attributes from the top-level assembly attribute list
let topAttrs = {topAttrs with assemblyAttrs=topAssemblyAttrs}
let permissionSets = ilxGenerator.CreatePermissionSets securityAttrs
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册