@@ -5217,27 +5217,28 @@ and remarkBind m (TBind(v, repr, _)) =
52175217
52185218
52195219//--------------------------------------------------------------------------
5220- //Reference semantics?
5220+ //Mutability analysis
52215221//--------------------------------------------------------------------------
52225222
5223- let isRecdOrStructFieldAllocObservable ( f : RecdField ) = not f.IsStatic&& f.IsMutable
5224- let isUnionCaseAllocObservable ( uc : UnionCase ) = uc.FieldTable.FieldsByIndex|> Array.existsisRecdOrStructFieldAllocObservable
5225- let isUnionCaseRefAllocObservable ( uc : UnionCaseRef ) = uc.UnionCase|> isUnionCaseAllocObservable
5223+ let isRecdOrStructFieldDefinitelyMutable ( f : RecdField ) = not f.IsStatic&& f.IsMutable
5224+ let isUnionCaseDefinitelyMutable ( uc : UnionCase ) = uc.FieldTable.FieldsByIndex|> Array.existsisRecdOrStructFieldDefinitelyMutable
5225+ let isUnionCaseRefDefinitelyMutable ( uc : UnionCaseRef ) = uc.UnionCase|> isUnionCaseDefinitelyMutable
52265226
5227- let isRecdOrUnionOrStructTyconAllocObservable ( _g : TcGlobals ) ( tycon : Tycon ) =
5227+ /// This is an incomplete check for .NET struct types. Returning 'false' doesn't mean the thing is immutable.
5228+ let isRecdOrUnionOrStructTyconDefinitelyMutable ( _g : TcGlobals ) ( tycon : Tycon ) =
52285229if tycon.IsUnionTyconthen
5229- tycon.UnionCasesArray|> Array.existsisUnionCaseAllocObservable
5230+ tycon.UnionCasesArray|> Array.existsisUnionCaseDefinitelyMutable
52305231elif tycon.IsRecordTycon|| tycon.IsStructOrEnumTyconthen
5231- tycon.AllFieldsArray|> Array.existsisRecdOrStructFieldAllocObservable
5232+ tycon.AllFieldsArray|> Array.existsisRecdOrStructFieldDefinitelyMutable
52325233else
52335234false
52345235
5235- let isRecdOrUnionOrStructTyconRefAllocObservable g ( tcr : TyconRef ) = isRecdOrUnionOrStructTyconAllocObservable g tcr.Deref
5236+ let isRecdOrUnionOrStructTyconRefDefinitelyMutable g ( tcr : TyconRef ) = isRecdOrUnionOrStructTyconDefinitelyMutable g tcr.Deref
52365237
52375238// Although from the pure F# perspective exception values cannot be changed, the .NET
52385239// implementation of exception objects attaches a whole bunch of stack information to
52395240// each raised object. Hence we treat exception objects as if they have identity
5240- let isExnAllocObservable ( _ecref : TyconRef ) = true
5241+ let isExnDefinitelyMutable ( _ecref : TyconRef ) = true
52415242
52425243// Some of the implementations of library functions on lists use mutation on the tail
52435244// of the cons cell. These cells are always private, i.e. not accessible by any other
@@ -5556,11 +5557,11 @@ let mkAndSimplifyMatch spBind exprm matchm ty tree targets =
55565557type Mutates = DefinitelyMutates| PossiblyMutates| NeverMutates
55575558exception DefensiveCopyWarningof string * range
55585559
5559- let isRecdOrStructTyImmutable g ty =
5560+ let isRecdOrStructTyReadOnly g ty =
55605561match tryDestAppTy g tywith
55615562| None-> false
55625563| Some tcref->
5563- not ( isRecdOrUnionOrStructTyconRefAllocObservable g tcref) ||
5564+ not ( isRecdOrUnionOrStructTyconRefDefinitelyMutable g tcref) ||
55645565 tyconRefEq g tcref g.decimal_ tcr||
55655566 tyconRefEq g tcref g.date_ tcr
55665567
@@ -5575,7 +5576,7 @@ let isRecdOrStructTyImmutable g ty =
55755576// let g1 = A.G(1)
55765577// (fun () -> g1.x1)
55775578//
5578- // Note:isRecdOrStructTyImmutable implies PossiblyMutates or NeverMutates
5579+ // Note:isRecdOrStructTyReadOnly implies PossiblyMutates or NeverMutates
55795580//
55805581// We only do this for true local or closure fields because we can't take addresses of immutable static
55815582// fields across assemblies.
@@ -5586,7 +5587,7 @@ let CanTakeAddressOfImmutableVal g (v:ValRef) mut =
55865587not v.IsMemberOrModuleBinding&&
55875588( match mutwith
55885589| NeverMutates-> true
5589- | PossiblyMutates-> isRecdOrStructTyImmutable g v.Type
5590+ | PossiblyMutates-> isRecdOrStructTyReadOnly g v.Type
55905591| DefinitelyMutates-> false )
55915592
55925593let MustTakeAddressOfVal ( g : TcGlobals ) ( v : ValRef ) =
@@ -5605,13 +5606,13 @@ let CanTakeAddressOfRecdFieldRef (g:TcGlobals) (rfref: RecdFieldRef) mut tinst =
56055606 mut<> DefinitelyMutates&&
56065607// We only do this if the field is defined in this assembly because we can't take addresses across assemblies for immutable fields
56075608 entityRefInThisAssembly g.compilingFslib rfref.TyconRef&&
5608- isRecdOrStructTyImmutable g( actualTyOfRecdFieldRef rfref tinst)
5609+ isRecdOrStructTyReadOnly g( actualTyOfRecdFieldRef rfref tinst)
56095610
56105611let CanTakeAddressOfUnionFieldRef ( g : TcGlobals ) ( uref : UnionCaseRef ) mut tinst cidx =
56115612 mut<> DefinitelyMutates&&
56125613// We only do this if the field is defined in this assembly because we can't take addresses across assemblies for immutable fields
56135614 entityRefInThisAssembly g.compilingFslib uref.TyconRef&&
5614- isRecdOrStructTyImmutable g( actualTyOfUnionFieldRef uref cidx tinst)
5615+ isRecdOrStructTyReadOnly g( actualTyOfUnionFieldRef uref cidx tinst)
56155616
56165617
56175618let rec mkExprAddrOfExprAux g mustTakeAddress useReadonlyForGenericArrayAddress mut e addrExprVal m =