Skip to content

Commit c64060c

Browse files
committed
code
1 parent 542e005 commit c64060c

File tree

3 files changed

+30
-18
lines changed

3 files changed

+30
-18
lines changed

src/Compiler/CodeGen/IlxGen.fs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ let ComputeTypeAccess (tref: ILTypeRef) hidden (accessibility: Accessibility) re
521521

522522
/// Indicates how type parameters are mapped to IL type variables
523523
[<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) =
525525

526526
static let empty = TypeReprEnv(count = 0, reprs = Map.empty, templateReplacement = None)
527527

@@ -536,7 +536,7 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
536536
/// Lookup a type parameter
537537
member _.Item(tp: Typar, m: range) =
538538
try
539-
reprs[tp.Stamp]
539+
reprs[tp.Stamp] |>fst
540540
with :? KeyNotFoundException ->
541541
errorR (InternalError("Undefined or unsolved type variable: " + showL (typarL tp), m))
542542
// Random value for post-hoc diagnostic analysis on generated tree *
@@ -546,7 +546,7 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
546546
/// then it is ignored, since it doesn't correspond to a .NET type parameter.
547547
member tyenv.AddOne(tp: Typar) =
548548
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)
550550
else
551551
tyenv
552552

@@ -573,6 +573,9 @@ type TypeReprEnv(reprs: Map<Stamp, uint16>, count: int, templateReplacement: (Ty
573573
/// Get the environment for generating a reference to items within a type definition
574574
member eenv.ForTyconRef(tcref: TyconRef) = eenv.ForTycon tcref.Deref
575575

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+
576579
//--------------------------------------------------------------------------
577580
// Generate type references
578581
//--------------------------------------------------------------------------
@@ -6892,14 +6895,6 @@ and GenFreevar cenv m eenvouter tyenvinner (fv: Val) =
68926895
and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames expr =
68936896
let g = cenv.g
68946897

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-
69036898
// Get a unique stamp for the closure. This must be stable for things that can be part of a let rec.
69046899
let uniq =
69056900
match expr with
@@ -6909,18 +6904,30 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
69096904
| _ -> newUnique ()
69106905

69116906
// 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+
69136916
// FSharp 1.0 bug 3404: System.Reflection doesn't like '.' and '`' in type names
69146917
let basenameSafeForUseAsTypename = CleanUpGeneratedTypeName basename
69156918

6916-
let suffixmark = expr.Range
6917-
69186919
let cloName =
69196920
// Ensure that we have an g.CompilerGlobalState
69206921
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
69226929

6923-
NestedTypeRefForCompLoc eenv.cloc cloName
6930+
ilCloTypeRef, initialFreeTyvars
69246931

69256932
// Collect the free variables of the closure
69266933
let cloFreeVarResults =
@@ -6931,7 +6938,7 @@ and GetIlxClosureFreeVars cenv m (thisVars: ValRef list) boxity eenv takenNames
69316938
| None -> opts
69326939
| Some(tcref, _, typars, _) -> opts.WithTemplateReplacement(tyconRefEq g tcref, typars)
69336940

6934-
freeInExpr opts expr
6941+
accFreeInExpr opts expr { emptyFreeVars with FreeTyvars = initialFreeTyvars }
69356942

69366943
// Partition the free variables when some can be accessed from places besides the immediate environment
69376944
// Also filter out the current value being bound, if any, as it is available from the "this"

src/Compiler/TypedTree/CompilerGlobalState.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,6 @@ let newUnique() = System.Threading.Interlocked.Increment &uniqueCount
7373
/// Unique name generator for stamps attached to to val_specs, tycon_specs etc.
7474
//++GLOBAL MUTABLE STATE (concurrency-safe)
7575
let mutable private stampCount = 0L
76-
let newStamp() = System.Threading.Interlocked.Increment &stampCount
76+
let newStamp() =
77+
let stamp = System.Threading.Interlocked.Increment &stampCount
78+
stamp

src/Compiler/TypedTree/TypedTreeOps.fsi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,9 @@ val accFreeInDecisionTree: FreeVarOptions -> DecisionTree -> FreeVars -> FreeVar
11841184
/// Get the free variables in a module definition.
11851185
val freeInModuleOrNamespace: FreeVarOptions -> ModuleOrNamespaceContents -> FreeVars
11861186

1187+
/// Get the free variables in an expression with accumulator
1188+
val accFreeInExpr: FreeVarOptions -> Expr -> FreeVars -> FreeVars
1189+
11871190
/// Get the free variables in an expression.
11881191
val freeInExpr: FreeVarOptions -> Expr -> FreeVars
11891192

0 commit comments

Comments
 (0)