Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)],
Expand Down Expand Up @@ -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)


Expand Down
1 change: 0 additions & 1 deletion src/fsharp/TcGlobals.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 1 addition & 3 deletions src/fsharp/fsc.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down