Skip to content
Merged
2 changes: 1 addition & 1 deletion src/fsharp/CheckFormatStrings.fs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let lowestDefaultPriority = 0 (* See comment on TyparConstraint.DefaultsTo *)

let mkFlexibleFormatTypar m tys dflt =
let tp = NewTypar (TyparKind.Type,TyparRigidity.Rigid,Typar(mkSynId m "fmt",HeadTypeStaticReq,true),false,TyparDynamicReq.Yes,[],false,false)
tp.FixupConstraints [ TyparConstraint.SimpleChoice (tys,m); TyparConstraint.DefaultsTo (lowestDefaultPriority,dflt,m)]
tp.SetConstraints [ TyparConstraint.SimpleChoice (tys,m); TyparConstraint.DefaultsTo (lowestDefaultPriority,dflt,m)]
copyAndFixupFormatTypar m tp

let mkFlexibleIntFormatTypar (g: TcGlobals) m =
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/ConstraintSolver.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1637,8 +1637,8 @@ and AddConstraint (csenv:ConstraintSolverEnv) ndeep m2 trace tp newConstraint =

// Write the constraint into the type variable
// Record a entry in the undo trace if one is provided
let orig = tp.typar_constraints
trace.Exec (fun () -> tp.typar_constraints <- newConstraints) (fun () -> tp.typar_constraints <- orig)
let orig = tp.Constraints
trace.Exec (fun () -> tp.SetConstraints newConstraints) (fun () -> tp.SetConstraints orig)

CompleteD)))

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/IlxGen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3435,7 +3435,7 @@ and GenGenericParam cenv eenv (tp:Typar) =
// use the CompiledName if given
// Inference variables get given an IL name "TA, TB" etc.
let nm =
match tp.typar_il_name with
match tp.ILName with
| None -> tp.Name
| Some nm -> nm
// Some special rules apply when compiling Fsharp.Core.dll to avoid a proliferation of [<CompiledName>] attributes on type parameters
Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/SignatureConformance.fs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
(errorR(Error(FSComp.SR.typrelSigImplNotCompatibleConstraintsDifferRemove(sigTypar.Name, Layout.showL(NicePrint.layoutTyparConstraint denv (sigTypar,sigTyparCx))),m)); false)
else
true) &&
(not checkingSig || checkAttribs aenv implTypar.Attribs sigTypar.Attribs (fun attribs -> implTypar.typar_attribs <- attribs)))
(not checkingSig || checkAttribs aenv implTypar.Attribs sigTypar.Attribs (fun attribs -> implTypar.SetAttribs attribs)))

and checkTypeDef (aenv: TypeEquivEnv) (implTycon:Tycon) (sigTycon:Tycon) =
let m = implTycon.Range
Expand Down
8 changes: 4 additions & 4 deletions src/fsharp/TastOps.fs
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ and copyAndRemapAndBindTyparsFull remapAttrib tyenv tps =
let tps' = copyTypars tps
let tyenv = { tyenv with tpinst = bindTypars tps (generalizeTypars tps') tyenv.tpinst }
(tps, tps') ||> List.iter2 (fun tporig tp ->
tp.FixupConstraints (remapTyparConstraintsAux tyenv tporig.Constraints)
tp.typar_attribs <- tporig.typar_attribs |> remapAttrib)
tp.SetConstraints (remapTyparConstraintsAux tyenv tporig.Constraints)
tp.SetAttribs (tporig.Attribs |> remapAttrib))
tps', tyenv

// copies bound typars, extends tpinst
Expand Down Expand Up @@ -2273,7 +2273,7 @@ module PrettyTypes =
let niceTypars = List.map2 newPrettyTypar tps names
let tl, _tt = mkTyparToTyparRenaming tps niceTypars in
let renaming = renaming @ tl
(tps, niceTypars) ||> List.iter2 (fun tp tpnice -> tpnice.FixupConstraints (instTyparConstraints renaming tp.Constraints)) ;
(tps, niceTypars) ||> List.iter2 (fun tp tpnice -> tpnice.SetConstraints (instTyparConstraints renaming tp.Constraints)) ;
niceTypars, renaming

// We choose names for type parameters from 'a'..'t'
Expand All @@ -2282,7 +2282,7 @@ module PrettyTypes =
// Finally, we skip any names already in use
let NeedsPrettyTyparName (tp:Typar) =
tp.IsCompilerGenerated &&
tp.typar_il_name.IsNone &&
tp.ILName.IsNone &&
(tp.typar_id.idText = unassignedTyparName)

let PrettyTyparNames pred alreadyInUse tps =
Expand Down
12 changes: 6 additions & 6 deletions src/fsharp/TastPickle.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,7 +1511,7 @@ let p_typar_spec_data (x:Typar) st =
p_typar_constraints
p_xmldoc

(x.typar_id,x.typar_attribs,int64 x.typar_flags.PickledBits,x.typar_constraints,x.typar_xmldoc) st
(x.typar_id,x.Attribs,int64 x.typar_flags.PickledBits,x.Constraints,x.XmlDoc) st

let p_typar_spec (x:Typar) st =
//Disabled, workaround for bug 2721: if x.Rigidity <> TyparRigidity.Rigid then warning(Error(sprintf "p_typar_spec: typar#%d is not rigid" x.Stamp, x.Range))
Expand All @@ -1523,14 +1523,14 @@ let p_typar_specs = (p_list p_typar_spec)
let u_typar_spec_data st =
let a,c,d,e,g = u_tup5 u_ident u_attribs u_int64 u_typar_constraints u_xmldoc st
{ typar_id=a
typar_il_name=None
typar_stamp=newStamp()
typar_attribs=c
typar_flags=TyparFlags(int32 d)
typar_constraints=e
typar_solution=None
typar_xmldoc=g
typar_astype= Unchecked.defaultof<_> }
typar_astype= Unchecked.defaultof<_>
typar_opt_data=
match g, e, c with
| XmlDoc [||], [], [] -> None
| _ -> Some { typar_il_name = None; typar_xmldoc = g; typar_constraints = e; typar_attribs = c } }

let u_typar_spec st =
u_osgn_decl st.itypars u_typar_spec_data st
Expand Down
4 changes: 2 additions & 2 deletions src/fsharp/TypeChecker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4513,7 +4513,7 @@ and TcTyparDecl cenv env (TyparDecl(synAttrs, (Typar(id, _, _) as stp))) =
let tp = NewTypar ((if hasMeasureAttr then TyparKind.Measure else TyparKind.Type), TyparRigidity.WarnIfNotRigid, stp, false, TyparDynamicReq.Yes, attrs, hasEqDepAttr, hasCompDepAttr)
match TryFindFSharpStringAttribute cenv.g cenv.g.attrib_CompiledNameAttribute attrs with
| Some compiledName ->
tp.typar_il_name <- Some compiledName
tp.SetILName (Some compiledName)
| None ->
()
let item = Item.TypeVar(id.idText, tp)
Expand Down Expand Up @@ -4940,7 +4940,7 @@ and TcTypeApp cenv newOk checkCxs occ env tpenv m tcref pathTypeArgs (synArgTys:

// If we're not checking constraints, i.e. when we first assert the super/interfaces of a type definition, then just
// clear the constraint lists of the freshly generated type variables. A little ugly but fairly localized.
if checkCxs = NoCheckCxs then tps |> List.iter (fun tp -> tp.typar_constraints <- [])
if checkCxs = NoCheckCxs then tps |> List.iter (fun tp -> tp.SetConstraints [])
if tinst.Length <> pathTypeArgs.Length + synArgTys.Length then
error (TyconBadArgs(env.DisplayEnv, tcref, pathTypeArgs.Length + synArgTys.Length, m))

Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/import.fs
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ let ImportILGenericParameters amap m scoref tinst (gps: ILGenericParameterDefs)
let constraints = if gp.HasReferenceTypeConstraint then (TyparConstraint.IsReferenceType(m)::constraints) else constraints
let constraints = if gp.HasNotNullableValueTypeConstraint then (TyparConstraint.IsNonNullableStruct(m)::constraints) else constraints
let constraints = if gp.HasDefaultConstructorConstraint then (TyparConstraint.RequiresDefaultConstructor(m)::constraints) else constraints
tp.FixupConstraints constraints)
tp.SetConstraints constraints)
tps


Expand Down
2 changes: 1 addition & 1 deletion src/fsharp/infos.fs
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ let FixupNewTypars m (formalEnclosingTypars:Typars) (tinst: TType list) (tpsorig
// The real code..
let renaming,tptys = mkTyparToTyparRenaming tpsorig tps
let tprefInst = mkTyparInst formalEnclosingTypars tinst @ renaming
(tpsorig,tps) ||> List.iter2 (fun tporig tp -> tp.FixupConstraints (CopyTyparConstraints m tprefInst tporig))
(tpsorig,tps) ||> List.iter2 (fun tporig tp -> tp.SetConstraints (CopyTyparConstraints m tprefInst tporig))
renaming,tptys


Expand Down
3 changes: 1 addition & 2 deletions src/fsharp/symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,8 +1067,7 @@ and FSharpGenericParameter(cenv, v:Typar) =
member __.IsCompilerGenerated = v.IsCompilerGenerated

member __.IsMeasure = (v.Kind = TyparKind.Measure)

member __.XmlDoc = v.typar_xmldoc |> makeXmlDoc
member __.XmlDoc = v.XmlDoc |> makeXmlDoc

member __.IsSolveAtCompileTime = (v.StaticReq = TyparStaticReq.HeadTypeStaticReq)

Expand Down
126 changes: 82 additions & 44 deletions src/fsharp/tast.fs
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,22 @@ and Accessibility =

override x.ToString() = "Accessibility(...)"

and [<NoEquality; NoComparison>]
TyparOptionalData =
{
/// MUTABILITY: we set the names of generalized inference type parameters to make the look nice for IL code generation
mutable typar_il_name: string option

/// The documentation for the type parameter. Empty for type inference variables.
/// MUTABILITY: for linking when unpickling
mutable typar_xmldoc : XmlDoc

/// The inferred constraints for the type inference variable
mutable typar_constraints: TyparConstraint list

/// The declared attributes of the type parameter. Empty for type inference variables.
mutable typar_attribs: Attribs
}
and TyparData = Typar
and
[<NoEquality; NoComparison>]
Expand All @@ -1947,45 +1963,26 @@ and
Typar =
// Backing data for type parameters and type inference variables
//
// MEMORY PERF: TyparData objects are common. They could be reduced to a record of 4-5 words in
// the common case of inference type variables, e.g.
//
// TyparDataCommon =
// typar_details: TyparDataUncommon // null indicates standard values for uncommon data
// typar_stamp: Stamp
// typar_solution: TType option
// typar_constraints: TyparConstraint list
// where the "common" settings are
// kind=TyparKind.Type, rigid=TyparRigidity.Flexible, id=compgen_id, staticReq=NoStaticReq, isCompGen=true, isFromError=false,
// dynamicReq=TyparDynamicReq.No, attribs=[], eqDep=false, compDep=false

{ /// MUTABILITY: we set the names of generalized inference type parameters to make the look nice for IL code generation
mutable typar_id: Ident

/// MUTABILITY: we set the names of generalized inference type parameters to make the look nice for IL code generation
mutable typar_il_name: string option

mutable typar_flags: TyparFlags

/// The unique stamp of the typar blob.
/// MUTABILITY: for linking when unpickling
mutable typar_stamp: Stamp

/// The documentation for the type parameter. Empty for type inference variables.
/// MUTABILITY: for linking when unpickling
mutable typar_xmldoc : XmlDoc

/// The declared attributes of the type parameter. Empty for type inference variables.
mutable typar_attribs: Attribs
mutable typar_stamp: Stamp

/// An inferred equivalence for a type inference variable.
mutable typar_solution: TType option

/// The inferred constraints for the type inference variable
mutable typar_constraints: TyparConstraint list

/// A cached TAST type used when this type variable is used as type.
mutable typar_astype: TType }
mutable typar_astype: TType

mutable typar_opt_data: TyparOptionalData option }

/// The name of the type parameter
member x.Name = x.typar_id.idText
Expand All @@ -2003,7 +2000,10 @@ and
member x.Solution = x.typar_solution

/// The inferred constraints for the type inference variable, if any
member x.Constraints = x.typar_constraints
member x.Constraints =
match x.typar_opt_data with
| Some optData -> optData.typar_constraints
| _ -> []

/// Indicates if the type variable is compiler generated, i.e. is an implicit type inference variable
member x.IsCompilerGenerated = x.typar_flags.IsCompilerGenerated
Expand Down Expand Up @@ -2034,41 +2034,70 @@ and
member x.IsErased = match x.Kind with TyparKind.Type -> false | _ -> true

/// The declared attributes of the type parameter. Empty for type inference variables and parameters from .NET
member x.Attribs = x.typar_attribs
member x.Attribs =
match x.typar_opt_data with
| Some optData -> optData.typar_attribs
| _ -> []

member x.SetAttribs attribs =
match attribs, x.typar_opt_data with
| [], None -> ()
| [], Some { typar_il_name = None; typar_xmldoc = XmlDoc [||]; typar_constraints = [] } ->
x.typar_opt_data <- None
| _, Some optData -> optData.typar_attribs <- attribs
| _ -> x.typar_opt_data <- Some { typar_il_name = None; typar_xmldoc = XmlDoc.Empty; typar_constraints = []; typar_attribs = attribs }

member x.XmlDoc =
match x.typar_opt_data with
| Some optData -> optData.typar_xmldoc
| _ -> XmlDoc.Empty

member x.ILName =
match x.typar_opt_data with
| Some optData -> optData.typar_il_name
| _ -> None

member x.SetILName il_name =
match x.typar_opt_data with
| Some optData -> optData.typar_il_name <- il_name
| _ -> x.typar_opt_data <- Some { typar_il_name = il_name; typar_xmldoc = XmlDoc.Empty; typar_constraints = []; typar_attribs = [] }

/// Indicates the display name of a type variable
member x.DisplayName = if x.Name = "?" then "?"+string x.Stamp else x.Name

/// Adjusts the constraints associated with a type variable
member x.FixupConstraints cs =
x.typar_constraints <- cs
member x.SetConstraints cs =
match cs, x.typar_opt_data with
| [], None -> ()
| [], Some { typar_il_name = None; typar_xmldoc = XmlDoc [||]; typar_attribs = [] } ->
x.typar_opt_data <- None
| _, Some optData -> optData.typar_constraints <- cs
| _ -> x.typar_opt_data <- Some { typar_il_name = None; typar_xmldoc = XmlDoc.Empty; typar_constraints = cs; typar_attribs = [] }


/// Creates a type variable that contains empty data, and is not yet linked. Only used during unpickling of F# metadata.
static member NewUnlinked() : Typar =
{ typar_id = Unchecked.defaultof<_>
typar_il_name = Unchecked.defaultof<_>
typar_flags = Unchecked.defaultof<_>
typar_stamp = Unchecked.defaultof<_>
typar_xmldoc = Unchecked.defaultof<_>
typar_attribs = Unchecked.defaultof<_>
typar_stamp = -1L
typar_solution = Unchecked.defaultof<_>
typar_constraints = Unchecked.defaultof<_>
typar_astype = Unchecked.defaultof<_> }
typar_astype = Unchecked.defaultof<_>
typar_opt_data = Unchecked.defaultof<_> }

/// Creates a type variable based on the given data. Only used during unpickling of F# metadata.
static member New (data: TyparData) : Typar = data

/// Links a previously unlinked type variable to the given data. Only used during unpickling of F# metadata.
member x.Link (tg: TyparData) =
x.typar_id <- tg.typar_id
x.typar_il_name <- tg.typar_il_name
x.typar_flags <- tg.typar_flags
x.typar_stamp <- tg.typar_stamp
x.typar_xmldoc <- tg.typar_xmldoc
x.typar_attribs <- tg.typar_attribs
x.typar_solution <- tg.typar_solution
x.typar_constraints <- tg.typar_constraints
match tg.typar_opt_data with
| Some tg ->
let optData = { typar_il_name = tg.typar_il_name; typar_xmldoc = tg.typar_xmldoc; typar_constraints = tg.typar_constraints; typar_attribs = tg.typar_attribs }
x.typar_opt_data <- Some optData
| None -> ()

/// Links a previously unlinked type variable to the given data. Only used during unpickling of F# metadata.
member x.AsType =
Expand All @@ -2081,7 +2110,7 @@ and
| _ -> ty

/// Indicates if a type variable has been linked. Only used during unpickling of F# metadata.
member x.IsLinked = match box x.typar_attribs with null -> false | _ -> true
member x.IsLinked = x.typar_stamp <> -1L

/// Indicates if a type variable has been solved.
member x.IsSolved =
Expand Down Expand Up @@ -4750,7 +4779,16 @@ let mkTyparTy (tp:Typar) =
| TyparKind.Type -> tp.AsType
| TyparKind.Measure -> TType_measure (Measure.Var tp)

let copyTypar (tp: Typar) = Typar.New { tp with typar_stamp=newStamp(); typar_astype=Unchecked.defaultof<_> }
let copyTypar (tp: Typar) =
let optData = tp.typar_opt_data |> Option.map (fun tg -> { typar_il_name = tg.typar_il_name; typar_xmldoc = tg.typar_xmldoc; typar_constraints = tg.typar_constraints; typar_attribs = tg.typar_attribs })
Typar.New { typar_id = tp.typar_id
typar_flags = tp.typar_flags
typar_stamp = newStamp()
typar_solution = tp.typar_solution
typar_astype = Unchecked.defaultof<_>
// Be careful to clone the mutable optional data too
typar_opt_data = optData }

let copyTypars tps = List.map copyTypar tps

//--------------------------------------------------------------------------
Expand Down Expand Up @@ -5035,14 +5073,14 @@ let MakeUnionRepr ucs = TUnionRepr (MakeUnionCases ucs)
let NewTypar (kind,rigid,Typar(id,staticReq,isCompGen),isFromError,dynamicReq,attribs,eqDep,compDep) =
Typar.New
{ typar_id = id
typar_il_name = None
typar_stamp = newStamp()
typar_flags= TyparFlags(kind,rigid,isFromError,isCompGen,staticReq,dynamicReq,eqDep,compDep)
typar_attribs= attribs
typar_solution = None
typar_constraints=[]
typar_xmldoc = XmlDoc.Empty
typar_astype = Unchecked.defaultof<_>}
typar_astype = Unchecked.defaultof<_>
typar_opt_data =
match attribs with
| [] -> None
| _ -> Some { typar_il_name = None; typar_xmldoc = XmlDoc.Empty; typar_constraints = []; typar_attribs = attribs } }

let NewRigidTypar nm m = NewTypar (TyparKind.Type,TyparRigidity.Rigid,Typar(mkSynId m nm,NoStaticReq,true),false,TyparDynamicReq.Yes,[],false,false)

Expand Down