@@ -521,7 +521,7 @@ let ComputeTypeAccess (tref: ILTypeRef) hidden (accessibility: Accessibility) re
521
521
522
522
/// Indicates how type parameters are mapped to IL type variables
523
523
[<NoEquality; NoComparison>]
524
- type TypeReprEnv ( reprs : Map < Stamp , uint16 >, count : int , templateReplacement : ( TyconRef * ILTypeRef * Typars * TyparInstantiation ) option ) =
524
+ type TypeReprEnv ( reprs : Map < Stamp , ( uint16 * Typar ) >, count : int , templateReplacement : ( TyconRef * ILTypeRef * Typars * TyparInstantiation ) option ) =
525
525
526
526
static let empty = TypeReprEnv( count = 0 , reprs = Map.empty, templateReplacement = None)
527
527
@@ -536,7 +536,7 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
536
536
/// Lookup a type parameter
537
537
member _.Item ( tp : Typar , m : range ) =
538
538
try
539
- reprs[ tp.Stamp]
539
+ reprs[ tp.Stamp] |> fst
540
540
with :? KeyNotFoundException ->
541
541
errorR ( InternalError( " Undefined or unsolved type variable: " + showL ( typarL tp), m))
542
542
// Random value for post-hoc diagnostic analysis on generated tree *
@@ -546,7 +546,7 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
546
546
/// then it is ignored, since it doesn't correspond to a .NET type parameter.
547
547
member tyenv.AddOne ( tp : Typar ) =
548
548
if IsNonErasedTypar tp then
549
- TypeReprEnv( reprs.Add( tp.Stamp, uint16 count), count + 1 , templateReplacement)
549
+ TypeReprEnv( reprs.Add( tp.Stamp, ( uint16 count, tp ) ), count + 1 , templateReplacement)
550
550
else
551
551
tyenv
552
552
@@ -573,6 +573,9 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
573
573
/// Get the environment for generating a reference to items within a type definition
574
574
member eenv.ForTyconRef ( tcref : TyconRef ) = eenv.ForTycon tcref.Deref
575
575
576
+ /// Get a list of the Typars in this environment
577
+ member eenv.AsUserProvidedTypars () = reprs |> Map.toList |> List.map( fun ( _ , ( _ , tp )) -> tp) |> List.filter( fun tp -> not tp.IsCompilerGenerated) |> Zset.ofList typarOrder
578
+
576
579
//--------------------------------------------------------------------------
577
580
// Generate type references
578
581
//--------------------------------------------------------------------------
@@ -6892,14 +6895,6 @@ and GenFreevar cenv m eenvouter tyenvinner (fv: Val) =
6892
6895
and GetIlxClosureFreeVars cenv m ( thisVars : ValRef list ) boxity eenv takenNames expr =
6893
6896
let g = cenv.g
6894
6897
6895
- // Choose a base name for the closure
6896
- let basename =
6897
- let boundv = eenv.letBoundVars |> List.tryFind ( fun v -> not v.IsCompilerGenerated)
6898
-
6899
- match boundv with
6900
- | Some v -> v.CompiledName cenv.g.CompilerGlobalState
6901
- | None -> " clo"
6902
-
6903
6898
// Get a unique stamp for the closure. This must be stable for things that can be part of a let rec.
6904
6899
let uniq =
6905
6900
match expr with
@@ -6909,18 +6904,30 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
6909
6904
| _ -> newUnique ()
6910
6905
6911
6906
// Choose a name for the closure
6912
- let ilCloTypeRef =
6907
+ let ilCloTypeRef , initialFreeTyvars =
6908
+ let boundvar =
6909
+ eenv.letBoundVars |> List.tryFind ( fun v -> not v.IsCompilerGenerated)
6910
+
6911
+ let basename =
6912
+ match boundvar with
6913
+ | Some v -> v.CompiledName cenv.g.CompilerGlobalState
6914
+ | None -> " clo"
6915
+
6913
6916
// FSharp 1.0 bug 3404: System.Reflection doesn't like '.' and '`' in type names
6914
6917
let basenameSafeForUseAsTypename = CleanUpGeneratedTypeName basename
6915
6918
6916
- let suffixmark = expr.Range
6917
-
6918
6919
let cloName =
6919
6920
// Ensure that we have an g.CompilerGlobalState
6920
6921
assert ( g.CompilerGlobalState |> Option.isSome)
6921
- g.CompilerGlobalState.Value.StableNameGenerator.GetUniqueCompilerGeneratedName( basenameSafeForUseAsTypename, suffixmark, uniq)
6922
+ g.CompilerGlobalState.Value.StableNameGenerator.GetUniqueCompilerGeneratedName( basenameSafeForUseAsTypename, expr.Range, uniq)
6923
+
6924
+ let ilCloTypeRef = NestedTypeRefForCompLoc eenv.cloc cloName
6925
+ let initialFreeTyvars =
6926
+ match g.realsig with
6927
+ | true -> { emptyFreeTyvars with FreeTypars = eenv.tyenv.AsUserProvidedTypars() }
6928
+ | false -> emptyFreeTyvars
6922
6929
6923
- NestedTypeRefForCompLoc eenv.cloc cloName
6930
+ ilCloTypeRef , initialFreeTyvars
6924
6931
6925
6932
// Collect the free variables of the closure
6926
6933
let cloFreeVarResults =
@@ -6931,7 +6938,7 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
6931
6938
| None -> opts
6932
6939
| Some( tcref, _, typars, _) -> opts.WithTemplateReplacement( tyconRefEq g tcref, typars)
6933
6940
6934
- freeInExpr opts expr
6941
+ accFreeInExpr opts expr { emptyFreeVars with FreeTyvars = initialFreeTyvars }
6935
6942
6936
6943
// Partition the free variables when some can be accessed from places besides the immediate environment
6937
6944
// Also filter out the current value being bound, if any, as it is available from the "this"
0 commit comments