Skip to content

Commit 2c6e3b6

Browse files
committed
hide representations in Abstract IL
1 parent a8d21e5 commit 2c6e3b6

File tree

16 files changed

+1149
-1083
lines changed

16 files changed

+1149
-1083
lines changed

src/absil/il.fs

Lines changed: 418 additions & 352 deletions
Large diffs are not rendered by default.

src/absil/il.fsi

Lines changed: 200 additions & 207 deletions
Large diffs are not rendered by default.

src/absil/ilmorph.fs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ let cattrs_typ2typ ilg f (cs: ILAttributes) =
155155
mkILCustomAttrs (List.map (cattr_typ2typ ilg f) cs.AsList)
156156

157157
let fdef_typ2typ ilg ftype (fd: ILFieldDef) =
158-
{fd with Type=ftype fd.Type;
159-
CustomAttrs=cattrs_typ2typ ilg ftype fd.CustomAttrs}
158+
fd.With(fieldType=ftype fd.FieldType,
159+
customAttrs=cattrs_typ2typ ilg ftype fd.CustomAttrs)
160160

161161
let local_typ2typ f (l: ILLocal) = {l with Type = f l.Type}
162162
let varargs_typ2typ f (varargs: ILVarArgs) = Option.map (List.map f) varargs
@@ -225,16 +225,15 @@ let morphILMethodBody (filmbody) (x: ILLazyMethodBody) =
225225

226226
let ospec_typ2typ f (OverridesSpec(mref,ty)) = OverridesSpec(mref_typ2typ f mref, f ty)
227227

228-
let mdef_typ2typ_ilmbody2ilmbody ilg fs md =
228+
let mdef_typ2typ_ilmbody2ilmbody ilg fs (md: ILMethodDef) =
229229
let (ftype,filmbody) = fs
230230
let ftype' = ftype (Some md)
231-
let body' = morphILMethodBody (filmbody (Some md)) md.mdBody
232-
{md with
233-
GenericParams=gparams_typ2typ ftype' md.GenericParams;
234-
mdBody= body';
235-
Parameters = List.map (param_typ2typ ilg ftype') md.Parameters;
236-
Return = return_typ2typ ilg ftype' md.Return;
237-
CustomAttrs=cattrs_typ2typ ilg ftype' md.CustomAttrs }
231+
let body' = morphILMethodBody (filmbody (Some md)) md.Body
232+
md.With(genericParams=gparams_typ2typ ftype' md.GenericParams,
233+
body= body',
234+
parameters = List.map (param_typ2typ ilg ftype') md.Parameters,
235+
ret = return_typ2typ ilg ftype' md.Return,
236+
customAttrs=cattrs_typ2typ ilg ftype' md.CustomAttrs)
238237

239238
let fdefs_typ2typ ilg f x = fdefs_fdef2fdef (fdef_typ2typ ilg f) x
240239

@@ -244,44 +243,41 @@ let mimpl_typ2typ f e =
244243
{ Overrides = ospec_typ2typ f e.Overrides;
245244
OverrideBy = mspec_typ2typ (f,(fun _ -> f)) e.OverrideBy; }
246245

247-
let edef_typ2typ ilg f e =
248-
{ e with
249-
Type = Option.map f e.Type;
250-
AddMethod = mref_typ2typ f e.AddMethod;
251-
RemoveMethod = mref_typ2typ f e.RemoveMethod;
252-
FireMethod = Option.map (mref_typ2typ f) e.FireMethod;
253-
OtherMethods = List.map (mref_typ2typ f) e.OtherMethods;
254-
CustomAttrs = cattrs_typ2typ ilg f e.CustomAttrs }
255-
256-
let pdef_typ2typ ilg f p =
257-
{ p with
258-
SetMethod = Option.map (mref_typ2typ f) p.SetMethod;
259-
GetMethod = Option.map (mref_typ2typ f) p.GetMethod;
260-
Type = f p.Type;
261-
Args = List.map f p.Args;
262-
CustomAttrs = cattrs_typ2typ ilg f p.CustomAttrs }
246+
let edef_typ2typ ilg f (e: ILEventDef) =
247+
e.With(eventType = Option.map f e.EventType,
248+
addMethod = mref_typ2typ f e.AddMethod,
249+
removeMethod = mref_typ2typ f e.RemoveMethod,
250+
fireMethod = Option.map (mref_typ2typ f) e.FireMethod,
251+
otherMethods = List.map (mref_typ2typ f) e.OtherMethods,
252+
customAttrs = cattrs_typ2typ ilg f e.CustomAttrs)
253+
254+
let pdef_typ2typ ilg f (p: ILPropertyDef) =
255+
p.With(setMethod = Option.map (mref_typ2typ f) p.SetMethod,
256+
getMethod = Option.map (mref_typ2typ f) p.GetMethod,
257+
propertyType = f p.PropertyType,
258+
args = List.map f p.Args,
259+
customAttrs = cattrs_typ2typ ilg f p.CustomAttrs)
263260

264261
let pdefs_typ2typ ilg f (pdefs: ILPropertyDefs) = mkILProperties (List.map (pdef_typ2typ ilg f) pdefs.AsList)
265262
let edefs_typ2typ ilg f (edefs: ILEventDefs) = mkILEvents (List.map (edef_typ2typ ilg f) edefs.AsList)
266263

267264
let mimpls_typ2typ f (mimpls : ILMethodImplDefs) = mkILMethodImpls (List.map (mimpl_typ2typ f) mimpls.AsList)
268265

269-
let rec tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs td =
266+
let rec tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs (td: ILTypeDef) =
270267
let (ftype,fmdefs) = fs
271268
let ftype' = ftype (Some (enc,td)) None
272269
let mdefs' = fmdefs (enc,td) td.Methods
273270
let fdefs' = fdefs_typ2typ ilg ftype' td.Fields
274-
{td with Implements= List.map ftype' td.Implements;
275-
GenericParams= gparams_typ2typ ftype' td.GenericParams;
276-
Extends = Option.map ftype' td.Extends;
277-
Methods=mdefs';
278-
NestedTypes=tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg (enc@[td]) fs td.NestedTypes;
279-
Fields=fdefs';
280-
MethodImpls = mimpls_typ2typ ftype' td.MethodImpls;
281-
Events = edefs_typ2typ ilg ftype' td.Events;
282-
Properties = pdefs_typ2typ ilg ftype' td.Properties;
283-
CustomAttrs = cattrs_typ2typ ilg ftype' td.CustomAttrs;
284-
}
271+
td.With(implements= List.map ftype' td.Implements,
272+
genericParams= gparams_typ2typ ftype' td.GenericParams,
273+
extends = Option.map ftype' td.Extends,
274+
methods=mdefs',
275+
nestedTypes=tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg (enc@[td]) fs td.NestedTypes,
276+
fields=fdefs',
277+
methodImpls = mimpls_typ2typ ftype' td.MethodImpls,
278+
events = edefs_typ2typ ilg ftype' td.Events,
279+
properties = pdefs_typ2typ ilg ftype' td.Properties,
280+
customAttrs = cattrs_typ2typ ilg ftype' td.CustomAttrs)
285281

286282
and tdefs_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs tdefs =
287283
morphILTypeDefs (tdef_typ2typ_ilmbody2ilmbody_mdefs2mdefs ilg enc fs) tdefs

src/absil/ilprint.fs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ and goutput_permission _env os p =
270270

271271

272272
match p with
273-
| PermissionSet (sa,b) ->
273+
| ILSecurityDecl (sa,b) ->
274274
output_string os " .permissionset "
275275
output_security_action os sa
276276
output_string os " = ("
277277
output_bytes os b
278278
output_string os ")"
279279

280-
and goutput_security_decls env os (ps: ILPermissions) = output_seq " " (goutput_permission env) os ps.AsList
280+
and goutput_security_decls env os (ps: ILSecurityDecls) = output_seq " " (goutput_permission env) os ps.AsList
281281

282282
and goutput_gparam env os (gf: ILGenericParameterDef) =
283283
output_string os (tyvar_generator gf.Name);
@@ -469,30 +469,30 @@ let output_custom_attr_data os data =
469469
output_string os " = "; output_parens output_bytes os data
470470

471471
let goutput_custom_attr env os attr =
472-
output_string os " .custom ";
473-
goutput_mspec env os attr.Method;
472+
output_string os " .custom "
473+
goutput_mspec env os attr.Method
474474
output_custom_attr_data os attr.Data
475475

476476
let goutput_custom_attrs env os (attrs : ILAttributes) =
477477
List.iter (fun attr -> goutput_custom_attr env os attr; output_string os "\n" ) attrs.AsList
478478

479-
let goutput_fdef _tref env os fd =
480-
output_string os " .field ";
479+
let goutput_fdef _tref env os (fd: ILFieldDef) =
480+
output_string os " .field "
481481
match fd.Offset with Some i -> output_string os "["; output_i32 os i; output_string os "] " | None -> ()
482482
match fd.Marshal with Some _i -> output_string os "// marshal attribute not printed\n"; | None -> ()
483-
output_member_access os fd.Access;
484-
output_string os " ";
485-
if fd.IsStatic then output_string os " static ";
486-
if fd.IsLiteral then output_string os " literal ";
487-
if fd.IsSpecialName then output_string os " specialname rtspecialname ";
488-
if fd.IsInitOnly then output_string os " initonly ";
489-
if fd.NotSerialized then output_string os " notserialized ";
490-
goutput_typ env os fd.Type;
491-
output_string os " ";
492-
output_id os fd.Name;
493-
output_option output_at os fd.Data;
494-
output_option output_field_init os fd.LiteralValue;
495-
output_string os "\n";
483+
output_member_access os fd.Access
484+
output_string os " "
485+
if fd.IsStatic then output_string os " static "
486+
if fd.IsLiteral then output_string os " literal "
487+
if fd.IsSpecialName then output_string os " specialname rtspecialname "
488+
if fd.IsInitOnly then output_string os " initonly "
489+
if fd.NotSerialized then output_string os " notserialized "
490+
goutput_typ env os fd.FieldType
491+
output_string os " "
492+
output_id os fd.Name
493+
output_option output_at os fd.Data
494+
output_option output_field_init os fd.LiteralValue
495+
output_string os "\n"
496496
goutput_custom_attrs env os fd.CustomAttrs
497497

498498

@@ -768,7 +768,7 @@ let goutput_ilmbody env os (il: ILMethodBody) =
768768
output_string os ")\n"
769769

770770

771-
let goutput_mbody is_entrypoint env os md =
771+
let goutput_mbody is_entrypoint env os (md: ILMethodDef) =
772772
if md.ImplAttributes &&& MethodImplAttributes.Native <> enum 0 then output_string os "native "
773773
elif md.ImplAttributes &&& MethodImplAttributes.IL <> enum 0 then output_string os "cil "
774774
else output_string os "runtime "
@@ -779,7 +779,7 @@ let goutput_mbody is_entrypoint env os md =
779779
output_string os " \n{ \n" ;
780780
goutput_security_decls env os md.SecurityDecls;
781781
goutput_custom_attrs env os md.CustomAttrs;
782-
match md.mdBody.Contents with
782+
match md.Body.Contents with
783783
| MethodBody.IL il -> goutput_ilmbody env os il
784784
| _ -> ()
785785
if is_entrypoint then output_string os " .entrypoint";
@@ -799,7 +799,7 @@ let goutput_mdef env os (md:ILMethodDef) =
799799
elif md.IsConstructor then "rtspecialname"
800800
elif md.IsStatic then
801801
"static "^
802-
(match md.mdBody.Contents with
802+
(match md.Body.Contents with
803803
MethodBody.PInvoke (attr) ->
804804
"pinvokeimpl(\""^ attr.Where.Name^"\" as \""^ attr.Name ^"\""^
805805
(match attr.CallingConv with
@@ -852,7 +852,7 @@ let goutput_mdef env os (md:ILMethodDef) =
852852
(goutput_mbody is_entrypoint menv) os md;
853853
output_string os "\n"
854854

855-
let goutput_pdef env os pd =
855+
let goutput_pdef env os (pd: ILPropertyDef) =
856856
output_string os "property\n\tgetter: ";
857857
(match pd.GetMethod with None -> () | Some mref -> goutput_mref env os mref);
858858
output_string os "\n\tsetter: ";
@@ -891,7 +891,7 @@ let goutput_mdefs env os (mdefs: ILMethodDefs) =
891891
let goutput_pdefs env os (pdefs: ILPropertyDefs) =
892892
List.iter (fun f -> (goutput_pdef env) os f; output_string os "\n" ) pdefs.AsList
893893

894-
let rec goutput_tdef (enc) env contents os cd =
894+
let rec goutput_tdef enc env contents os (cd: ILTypeDef) =
895895
let env = ppenv_enter_tdef cd.GenericParams env
896896
let layout_attr,pp_layout_decls = splitTypeLayout cd.Layout
897897
if isTypeNameForGlobalFunctions cd.Name then
@@ -939,26 +939,26 @@ and output_init_semantics os f =
939939
and goutput_lambdas env os lambdas =
940940
match lambdas with
941941
| Lambdas_forall (gf,l) ->
942-
output_angled (goutput_gparam env) os gf;
943-
output_string os " ";
942+
output_angled (goutput_gparam env) os gf
943+
output_string os " "
944944
(goutput_lambdas env) os l
945945
| Lambdas_lambda (ps,l) ->
946946
output_parens (goutput_param env) os ps;
947-
output_string os " ";
947+
output_string os " "
948948
(goutput_lambdas env) os l
949949
| Lambdas_return typ -> output_string os "--> "; (goutput_typ env) os typ
950950

951-
and goutput_tdefs contents (enc) env os (td: ILTypeDefs) =
951+
and goutput_tdefs contents enc env os (td: ILTypeDefs) =
952952
List.iter (goutput_tdef enc env contents os) td.AsList
953953

954954
let output_ver os (a,b,c,d) =
955-
output_string os " .ver ";
956-
output_u16 os a;
957-
output_string os " : ";
958-
output_u16 os b;
959-
output_string os " : ";
960-
output_u16 os c;
961-
output_string os " : ";
955+
output_string os " .ver "
956+
output_u16 os a
957+
output_string os " : "
958+
output_u16 os b
959+
output_string os " : "
960+
output_u16 os c
961+
output_string os " : "
962962
output_u16 os d
963963

964964
let output_locale os s = output_string os " .Locale "; output_qstring os s

0 commit comments

Comments
 (0)