Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf070cb8

Browse files
authored
Collapse Val with ValData, Entity with EntityData, Typar with TyparData (dotnet#2384)
The F# compiler code has always used a separationValRef --> Val --> ValDataEntityRef --> Entity --> EntityDataTypar --> TyparDatawhere the Val node was just a { mutable Data: ValData }. This was to enable the easy coding of the TastUnpickle deserialization routine which filled in the data (Link) while declaring ValData as immutable as possible. (likewise Entity, Typar)The Val and ValData fields can be collapsed into one object if we accept that the Link routine can mutate the fields of a unchecked-initialized Val.As well as saving the indirection during processing, the memory listings here indicate that about 5MB out of 150MB of data is spent on these Val/Tycon/Entity nodes.
1 parent8da7286 commitf070cb8

File tree

11 files changed

+473
-370
lines changed

11 files changed

+473
-370
lines changed

‎src/fsharp/CompileOps.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3973,7 +3973,7 @@ type TcImports(tcConfigP:TcConfigProvider, initialResolutions:TcAssemblyResoluti
39733973
entity.ModuleOrNamespaceType.AddProvidedTypeEntity(newEntity)
39743974
| None->()
39753975

3976-
entity.Data.entity_tycon_repr<-
3976+
entity.entity_tycon_repr<-
39773977
match entity.TypeReprInfowith
39783978
// This is the first extension
39793979
| TNoRepr->

‎src/fsharp/ConstraintSolver.fs‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,8 @@ let SubstMeasure (r:Typar) ms =
431431
if r.Rigidity= TyparRigidity.Rigidthen error(InternalError("SubstMeasure: rigid",r.Range));
432432
if r.Kind= TyparKind.Typethen error(InternalError("SubstMeasure: kind=type",r.Range));
433433

434-
lettp= r.Data
435-
match tp.typar_solutionwith
436-
| None-> tp.typar_solution<- Some(TType_measure ms)
434+
match r.typar_solutionwith
435+
| None-> r.typar_solution<- Some(TType_measure ms)
437436
| Some_-> error(InternalError("already solved",r.Range));
438437

439438
let recTransactStaticReq(csenv:ConstraintSolverEnv)(trace:OptionalTrace)(tpr:Typar)req=
@@ -695,8 +694,7 @@ let rec SolveTyparEqualsTyp (csenv:ConstraintSolverEnv) ndeep m2 (trace:Optional
695694
// Record the solution before we solve the constraints, since
696695
// We may need to make use of the equation when solving the constraints.
697696
// Record a entry in the undo trace if one is provided
698-
lettpdata= r.Data
699-
trace.Exec(fun()-> tpdata.typar_solution<- Some ty)(fun()-> tpdata.typar_solution<- None)
697+
trace.Exec(fun()-> r.typar_solution<- Some ty)(fun()-> r.typar_solution<- None)
700698

701699
(* dprintf "setting typar %d to type %s at %a\n" r.Stamp ((DebugPrint.showType ty)) outputRange m;*)
702700

@@ -1631,9 +1629,8 @@ and AddConstraint (csenv:ConstraintSolverEnv) ndeep m2 trace tp newConstraint =
16311629

16321630
// Write the constraint into the type variable
16331631
// Record a entry in the undo trace if one is provided
1634-
letd= tp.Data
1635-
letorig= d.typar_constraints
1636-
trace.Exec(fun()-> d.typar_constraints<- newConstraints)(fun()-> d.typar_constraints<- orig)
1632+
letorig= tp.typar_constraints
1633+
trace.Exec(fun()-> tp.typar_constraints<- newConstraints)(fun()-> tp.typar_constraints<- orig)
16371634

16381635
CompleteD)))
16391636

‎src/fsharp/IlxGen.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3383,7 +3383,7 @@ and GenGenericParam cenv eenv (tp:Typar) =
33833383
// use the CompiledName if given
33843384
// Inference variables get given an IL name "TA, TB" etc.
33853385
letnm=
3386-
match tp.Data.typar_il_namewith
3386+
match tp.typar_il_namewith
33873387
| None-> tp.Name
33883388
| Some nm-> nm
33893389
// Some special rules apply when compiling Fsharp.Core.dll to avoid a proliferation of [<CompiledName>] attributes on type parameters
@@ -5193,7 +5193,7 @@ and GenMethodForBinding
51935193
// active pattern names
51945194
mdef.Name.StartsWith("|",System.StringComparison.Ordinal)||
51955195
// event add/remove method
5196-
v.Data.val_flags.IsGeneratedEventValthen
5196+
v.val_flags.IsGeneratedEventValthen
51975197
{mdefwith IsSpecialName=true}
51985198
else
51995199
mdef

‎src/fsharp/Optimizer.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ let BindTypeVarsToUnknown (tps:Typar list) env =
492492
letnms= PrettyTypes.PrettyTyparNames(fun _->true)(env.typarInfos|> List.map(fun(tp,_)-> tp.Name)) tps
493493
(tps,nms)||> List.iter2(fun tp nm->
494494
if PrettyTypes.NeedsPrettyTyparName tpthen
495-
tp.Data.typar_id<- ident(nm,tp.Range))
495+
tp.typar_id<- ident(nm,tp.Range))
496496
List.fold(fun sofar arg-> BindTypeVar arg UnknownTypeValue sofar) env tps
497497

498498
letBindCcu(ccu:Tast.CcuThunk)mval env(_g:TcGlobals)=
@@ -3087,7 +3087,7 @@ and OptimizeModuleExpr cenv env x =
30873087
mty
30883088
andelimModSpec(mspec:ModuleOrNamespace)=
30893089
letmtyp= elimModTy mspec.ModuleOrNamespaceType
3090-
mspec.Data.entity_modul_contents<- MaybeLazy.Strict mtyp
3090+
mspec.entity_modul_contents<- MaybeLazy.Strict mtyp
30913091

30923092
let recelimModDef x=
30933093
match xwith

‎src/fsharp/PostInferenceChecks.fs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let BindTypars g env (tps:Typar list) =
156156
letnms= PrettyTypes.PrettyTyparNames(fun _->true) env.boundTyparNames tps
157157
(tps,nms)||> List.iter2(fun tp nm->
158158
if PrettyTypes.NeedsPrettyTyparName tpthen
159-
tp.Data.typar_id<- ident(nm,tp.Range))
159+
tp.typar_id<- ident(nm,tp.Range))
160160
List.fold BindTypar env tps
161161

162162
/// Set the set of vals which are arguments in the active lambda. We are allowed to return
@@ -1195,7 +1195,7 @@ and CheckBinding cenv env alwaysCheckNoReraise (TBind(v,bindRhs,_) as bind) =
11951195

11961196
// If we've already recorded a definition then skip this
11971197
match v.ReflectedDefinitionwith
1198-
| None-> v.Data.val_defn<- Some bindRhs
1198+
| None-> v.val_defn<- Some bindRhs
11991199
| Some_->()
12001200
// Run the conversion process over the reflected definition to report any errors in the
12011201
// front end rather than the back end. We currently re-run this during ilxgen.fs but there's

‎src/fsharp/SignatureConformance.fs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
158158
(errorR(Error(FSComp.SR.typrelSigImplNotCompatibleConstraintsDifferRemove(sigTypar.Name, Layout.showL(NicePrint.layoutTyparConstraint denv(sigTypar,sigTyparCx))),m));false)
159159
else
160160
true)&&
161-
(not checkingSig|| checkAttribs aenv implTypar.Attribs sigTypar.Attribs(fun attribs-> implTypar.Data.typar_attribs<- attribs)))
161+
(not checkingSig|| checkAttribs aenv implTypar.Attribs sigTypar.Attribs(fun attribs-> implTypar.typar_attribs<- attribs)))
162162

163163
andcheckTypeDef(aenv:TypeEquivEnv)(implTycon:Tycon)(sigTycon:Tycon)=
164164
letm= implTycon.Range
@@ -231,7 +231,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
231231
checkTypars m aenv implTypars sigTypars&&
232232
checkTypeRepr m aenv implTycon sigTycon.TypeReprInfo&&
233233
checkTypeAbbrev m aenv implTycon sigTycon&&
234-
checkAttribs aenv implTycon.Attribs sigTycon.Attribs(fun attribs-> implTycon.Data.entity_attribs<- attribs)&&
234+
checkAttribs aenv implTycon.Attribs sigTycon.Attribs(fun attribs-> implTycon.entity_attribs<- attribs)&&
235235
checkModuleOrNamespaceContents implTycon.Range aenv(mkLocalEntityRef implTycon) sigTycon.ModuleOrNamespaceType
236236

237237
andcheckValInfo aenv err(implVal:Val)(sigVal:Val)=
@@ -297,7 +297,7 @@ type Checker(g, amap, denv, remapInfo: SignatureRepackageInfo, checkingSig) =
297297
elifnot(checkValInfo aenv(err denv) implVal sigVal)thenfalse
298298
elifnot(implVal.IsExtensionMember= sigVal.IsExtensionMember)then err denv(FSComp.SR.ValueNotContainedMutabilityExtensionsDiffer)
299299
elifnot(checkMemberDatasConform(err denv)(implVal.Attribs, implVal,implVal.MemberInfo)(sigVal.Attribs,sigVal,sigVal.MemberInfo))thenfalse
300-
else checkAttribs aenv implVal.Attribs sigVal.Attribs(fun attribs-> implVal.Data.val_attribs<- attribs)
300+
else checkAttribs aenv implVal.Attribs sigVal.Attribs(fun attribs-> implVal.val_attribs<- attribs)
301301

302302

303303
andcheckExnInfo err aenv implTypeRepr sigTypeRepr=

‎src/fsharp/TastOps.fs‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ and copyAndRemapAndBindTyparsFull remapAttrib tyenv tps =
278278
lettyenv={ tyenvwith tpinst= bindTypars tps(generalizeTypars tps') tyenv.tpinst}
279279
(tps,tps')||> List.iter2(fun tporig tp->
280280
tp.FixupConstraints(remapTyparConstraintsAux tyenv tporig.Constraints);
281-
tp.Data.typar_attribs<- tporig.Data.typar_attribs|> remapAttrib);
281+
tp.typar_attribs<- tporig.typar_attribs|> remapAttrib);
282282
tps',tyenv
283283

284284
// copies bound typars, extends tpinst
@@ -529,7 +529,7 @@ let tryNormalizeMeasureInType g ty =
529529
| TType_measure(Measure.Var v)->
530530
match v.Solutionwith
531531
| Some(TType_measure ms)->
532-
(v.Data.typar_solution<- Some(TType_measure(normalizeMeasure g ms)); ty)
532+
(v.typar_solution<- Some(TType_measure(normalizeMeasure g ms)); ty)
533533
|_-> ty
534534

535535
|_-> ty
@@ -1928,7 +1928,7 @@ and accFreeInTypes opts tys acc =
19281928
| h:: t-> accFreeInTypes opts t(accFreeInType opts h acc)
19291929
andfreeInType opts ty= accFreeInType opts ty emptyFreeTyvars
19301930

1931-
andaccFreeInVal opts(v:Val)acc= accFreeInType opts v.Data.val_type acc
1931+
andaccFreeInVal opts(v:Val)acc= accFreeInType opts v.val_type acc
19321932

19331933
letfreeInTypes opts tys= accFreeInTypes opts tys emptyFreeTyvars
19341934
letfreeInVal opts v= accFreeInVal opts v emptyFreeTyvars
@@ -2230,8 +2230,8 @@ module PrettyTypes =
22302230
// Finally, we skip any names already in use
22312231
letNeedsPrettyTyparName(tp:Typar)=
22322232
tp.IsCompilerGenerated&&
2233-
tp.Data.typar_il_name.IsNone&&
2234-
(tp.Data.typar_id.idText= unassignedTyparName)
2233+
tp.typar_il_name.IsNone&&
2234+
(tp.typar_id.idText= unassignedTyparName)
22352235

22362236
letPrettyTyparNames pred alreadyInUse tps=
22372237
let recchoose(tps:Typar list)(typeIndex,measureIndex)acc=
@@ -4579,7 +4579,7 @@ and remapArgData g tmenv (argInfo : ArgReprInfo) : ArgReprInfo =
45794579
andremapValReprInfo g tmenv(ValReprInfo(tpNames,arginfosl,retInfo))=
45804580
ValReprInfo(tpNames,List.mapSquared(remapArgData g tmenv) arginfosl, remapArgData g tmenv retInfo)
45814581

4582-
andremapValData g tmenvd=
4582+
andremapValData g tmenv(d:ValData)=
45834583
letty= d.val_type
45844584
lettopValInfo= d.val_repr_info
45854585
letty'= ty|> remapPossibleForallTy g tmenv
@@ -4610,7 +4610,9 @@ and fixupValData g compgen tmenv (v2:Val) =
46104610
match compgenwith
46114611
| OnlyCloneExprValswhen v2.IsMemberOrModuleBinding->()
46124612
|_->
4613-
v2.Data<- remapValData g tmenv v2.Data|> markAsCompGen compgen
4613+
letnewData= remapValData g tmenv v2|> markAsCompGen compgen
4614+
// uses the same stamp
4615+
v2.SetData newData
46144616

46154617
andcopyAndRemapAndBindVals g compgen tmenv vs=
46164618
letvs2= vs|> List.map(copyVal compgen)
@@ -4963,9 +4965,7 @@ and copyAndRemapAndBindTyconsAndVals g compgen tmenv tycons vs =
49634965
mkLocalTyconRef tycon
49644966
tcref.Deref
49654967

4966-
(tycons,tycons')||> List.iter2(fun tc tc'->
4967-
lettcd= tc.Data
4968-
lettcd'= tc'.Data
4968+
(tycons,tycons')||> List.iter2(fun tcd tcd'->
49694969
lettps',tmenvinner2= tmenvCopyRemapAndBindTypars(remapAttribs g tmenvinner) tmenvinner(tcd.entity_typars.Force(tcd.entity_range))
49704970
tcd'.entity_typars<- LazyWithContext.NotLazy tps';
49714971
tcd'.entity_attribs<- tcd.entity_attribs|> remapAttribs g tmenvinner2;
@@ -6864,12 +6864,12 @@ let NormalizeAndAdjustPossibleSubsumptionExprs g inputExpr =
68646864
// polymorphic things bound in complex matches at top level require eta expansion of the
68656865
// type function to ensure the r.h.s. of the binding is indeed a type function
68666866
letetaExpandTypeLambda g m tps(tm,ty)=
6867-
if isNil tpsthen tmelse mkTypeLambda m tps(mkApps g((tm,ty),[(List.map mkTyparTy tps)],[],m),ty)
6867+
if isNil tpsthen tmelse mkTypeLambda m tps(mkApps g((tm,ty),[(List.map mkTyparTy tps)],[],m),ty)
68686868

68696869
letAdjustValToTopVal(tmp:Val)parent valData=
6870-
tmp.SetValReprInfo(Some valData);
6871-
tmp.Data.val_actual_parent<- parent;
6872-
tmp.SetIsMemberOrModuleBinding()
6870+
tmp.SetValReprInfo(Some valData);
6871+
tmp.val_actual_parent<- parent;
6872+
tmp.SetIsMemberOrModuleBinding()
68736873

68746874
/// For match with only one non-failing target T0, the other targets, T1... failing (say, raise exception).
68756875
/// tree, T0(v0,..,vN) => rhs ; T1() => fail ; ...
@@ -7626,7 +7626,7 @@ let MakeExportRemapping viewedCcu (mspec:ModuleOrNamespace) =
76267626
//------------------------------------------------------------------------
76277627

76287628

7629-
let recremapEntityDataToNonLocal g tmenv(d:EntityData)=
7629+
let recremapEntityDataToNonLocal g tmenv(d:Entity)=
76307630
lettps',tmenvinner= tmenvCopyRemapAndBindTypars(remapAttribs g tmenv) tmenv(d.entity_typars.Force(d.entity_range))
76317631

76327632
{ dwith
@@ -7644,6 +7644,7 @@ and remapTyconToNonLocal g tmenv x =
76447644
x|> NewModifiedTycon(remapEntityDataToNonLocal g tmenv)
76457645

76467646
andremapValToNonLocal g tmenv inp=
7647+
// creates a new stamp
76477648
inp|> NewModifiedVal(remapValData g tmenv)
76487649

76497650
letApplyExportRemappingToEntity g tmenv x= remapTyconToNonLocal g tmenv x

‎src/fsharp/TastPickle.fs‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ type WriterState =
115115
{ os:ByteBuffer;
116116
oscope:CcuThunk;
117117
occus:Table<CcuReference>;
118-
otycons:NodeOutTable<EntityData,Tycon>;
118+
otycons:NodeOutTable<EntityData,Entity>;
119119
otypars:NodeOutTable<TyparData,Typar>;
120120
ovals:NodeOutTable<ValData,Val>;
121121
ostrings:Table<string>;
@@ -672,9 +672,9 @@ let pickleObjWithDanglingCcus file g scope p x =
672672
{ os= ByteBuffer.Create100000;
673673
oscope=scope;
674674
occus= Table<_>.Create"occus";
675-
otycons=NodeOutTable<_,_>.Create((fun(tc:Tycon)-> tc.Stamp),(fun tc-> tc.LogicalName),(fun tc-> tc.Range),(fun osgn-> osgn.Data),"otycons");
676-
otypars=NodeOutTable<_,_>.Create((fun(tp:Typar)-> tp.Stamp),(fun tp-> tp.DisplayName),(fun tp-> tp.Range),(fun osgn-> osgn.Data),"otypars");
677-
ovals=NodeOutTable<_,_>.Create((fun(v:Val)-> v.Stamp),(fun v-> v.LogicalName),(fun v-> v.Range),(fun osgn-> osgn.Data),"ovals");
675+
otycons=NodeOutTable<_,_>.Create((fun(tc:Tycon)-> tc.Stamp),(fun tc-> tc.LogicalName),(fun tc-> tc.Range),(fun osgn-> osgn),"otycons");
676+
otypars=NodeOutTable<_,_>.Create((fun(tp:Typar)-> tp.Stamp),(fun tp-> tp.DisplayName),(fun tp-> tp.Range),(fun osgn-> osgn),"otypars");
677+
ovals=NodeOutTable<_,_>.Create((fun(v:Val)-> v.Stamp),(fun v-> v.LogicalName),(fun v-> v.Range),(fun osgn-> osgn),"ovals");
678678
ostrings=Table<_>.Create"ostrings";
679679
onlerefs=Table<_>.Create"onlerefs";
680680
opubpaths=Table<_>.Create"opubpaths";
@@ -694,9 +694,9 @@ let pickleObjWithDanglingCcus file g scope p x =
694694
{ os= ByteBuffer.Create100000;
695695
oscope=scope;
696696
occus= Table<_>.Create"occus (fake)";
697-
otycons=NodeOutTable<_,_>.Create((fun(tc:Tycon)-> tc.Stamp),(fun tc-> tc.LogicalName),(fun tc-> tc.Range),(fun osgn-> osgn.Data),"otycons");
698-
otypars=NodeOutTable<_,_>.Create((fun(tp:Typar)-> tp.Stamp),(fun tp-> tp.DisplayName),(fun tp-> tp.Range),(fun osgn-> osgn.Data),"otypars");
699-
ovals=NodeOutTable<_,_>.Create((fun(v:Val)-> v.Stamp),(fun v-> v.LogicalName),(fun v-> v.Range),(fun osgn-> osgn.Data),"ovals");
697+
otycons=NodeOutTable<_,_>.Create((fun(tc:Tycon)-> tc.Stamp),(fun tc-> tc.LogicalName),(fun tc-> tc.Range),(fun osgn-> osgn),"otycons");
698+
otypars=NodeOutTable<_,_>.Create((fun(tp:Typar)-> tp.Stamp),(fun tp-> tp.DisplayName),(fun tp-> tp.Range),(fun osgn-> osgn),"otypars");
699+
ovals=NodeOutTable<_,_>.Create((fun(v:Val)-> v.Stamp),(fun v-> v.LogicalName),(fun v-> v.Range),(fun osgn-> osgn),"ovals");
700700
ostrings=Table<_>.Create"ostrings (fake)";
701701
opubpaths=Table<_>.Create"opubpaths (fake)";
702702
onlerefs=Table<_>.Create"onlerefs (fake)";
@@ -1515,7 +1515,7 @@ let u_typar_constraints = (u_list_revi u_typar_constraint)
15151515

15161516

15171517
#if INCLUDE_METADATA_WRITER
1518-
letp_typar_spec_data(x:TyparData)st=
1518+
letp_typar_spec_data(x:Typar)st=
15191519
p_tup5
15201520
p_ident
15211521
p_attribs
@@ -1542,7 +1542,8 @@ let u_typar_spec_data st =
15421542
typar_flags=TyparFlags(int32 d);
15431543
typar_constraints=e;
15441544
typar_solution=None;
1545-
typar_xmldoc=g}
1545+
typar_xmldoc=g;
1546+
typar_astype= Unchecked.defaultof<_>}
15461547

15471548
letu_typar_spec st=
15481549
u_osgn_decl st.itypars u_typar_spec_data st
@@ -1716,7 +1717,7 @@ and p_recdfield_spec x st =
17161717
andp_rfield_table x st=
17171718
p_list p_recdfield_spec(Array.toList x.FieldsByIndex) st
17181719

1719-
andp_entity_spec_data(x:EntityData)st=
1720+
andp_entity_spec_data(x:Entity)st=
17201721
p_typar_specs(x.entity_typars.Force(x.entity_range)) st
17211722
p_string x.entity_logical_name st
17221723
p_option p_string x.entity_compiled_name st
@@ -1974,7 +1975,7 @@ and u_recdfield_spec st =
19741975

19751976
andu_rfield_table st= MakeRecdFieldsTable(u_list u_recdfield_spec st)
19761977

1977-
andu_entity_spec_data st:EntityData=
1978+
andu_entity_spec_data st:Entity=
19781979
letx1,x2a,x2b,x2c,x3,(x4a,x4b),x6,x7f,x8,x9,x10,x10b,x11,x12,x13,x14,_space=
19791980
u_tup17
19801981
u_typar_specs

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp