@@ -1908,7 +1908,16 @@ type TypeDefBuilder(tdef: ILTypeDef, tdefDiscards) =
19081908        if  not  discard then 
19091909            AddPropertyDefToHash m gproperties pdef
19101910
1911-     member  _.PrependInstructionsToSpecificMethodDef ( cond ,  instrs ,  tag ,  imports )  = 
1911+     member  _.AppendInstructionsToSpecificMethodDef ( cond ,  instrs ,  tag ,  imports )  = 
1912+         match  ResizeArray.tryFindIndex cond gmethods with 
1913+         |  Some idx ->  gmethods[ idx]  <-  appendInstrsToMethod instrs gmethods[ idx] 
1914+         |  None -> 
1915+             let  body  = 
1916+                 mkMethodBody ( false ,  [],  1 ,  nonBranchingInstrsToCode instrs,  tag,  imports) 
1917+ 
1918+             gmethods.Add( mkILClassCtor body) 
1919+ 
1920+     member  this.PrependInstructionsToSpecificMethodDef ( cond ,  instrs ,  tag ,  imports )  = 
19121921        match  ResizeArray.tryFindIndex cond gmethods with 
19131922        |  Some idx ->  gmethods[ idx]  <-  prependInstrsToMethod instrs gmethods[ idx] 
19141923        |  None -> 
@@ -1917,6 +1926,8 @@ type TypeDefBuilder(tdef: ILTypeDef, tdefDiscards) =
19171926
19181927            gmethods.Add( mkILClassCtor body) 
19191928
1929+         this
1930+ 
19201931and  TypeDefsBuilder ()  = 
19211932
19221933    let  tdefs  = 
@@ -2264,6 +2275,22 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
22642275    /// static init fields on script modules. 
22652276let  scriptInitFspecs  =  ConcurrentStack< ILFieldSpec *  range>() 
22662277
2278+     let  initialInstrs  seqpt feefee  = 
2279+         [ 
2280+             yield ! 
2281+                 ( if  isEnvVarSet " NO_ADD_FEEFEE_TO_CCTORS" then  [] 
2282+                  elif  isEnvVarSet " ADD_SEQPT_TO_CCTORS" then  seqpt
2283+                  else  feefee)  // mark start of hidden code 
2284+         ] 
2285+ 
2286+     let  finalInstrs  fspec  = 
2287+         [ 
2288+             yield  mkLdcInt32 0 
2289+             yield  mkNormalStsfld fspec
2290+             yield  mkNormalLdsfld fspec
2291+             yield  AI_ pop
2292+         ] 
2293+ 
22672294    member  _.AddScriptInitFieldSpec ( fieldSpec ,  range )  = 
22682295        scriptInitFspecs.Push(( fieldSpec,  range)) 
22692296
@@ -2276,15 +2303,7 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
22762303            let  InitializeCompiledScript   ( fspec ,  m )  = 
22772304                let  ilDebugRange  =  GenPossibleILDebugRange cenv m
22782305
2279-                 mgbuf.AddExplicitInitToSpecificMethodDef( 
2280-                     ( fun   ( md :  ILMethodDef )  -> ), 
2281-                     tref, 
2282-                     fspec, 
2283-                     ilDebugRange, 
2284-                     imports, 
2285-                     [], 
2286-                     [] 
2287-                 ) 
2306+                 mgbuf.AddExplicitInitToEntryPoint( tref,  fspec,  ilDebugRange,  imports,  [],  []) 
22882307
22892308            scriptInitFspecs |>  Seq.iter InitializeCompiledScript
22902309        |  None ->  () 
@@ -2325,24 +2344,23 @@ and AssemblyBuilder(cenv: cenv, anonTypeTable: AnonTypeGenerationTable) as mgbuf
23252344        if  ilMethodDef.IsEntryPoint then 
23262345            explicitEntryPointInfo <-  Some tref
23272346
2328-     member  _.AddExplicitInitToSpecificMethodDef ( cond ,  tref ,  fspec ,  sourceOpt ,  imports ,  feefee ,  seqpt )  = 
2329-         // Authoring a .cctor with effects forces the cctor for the 'initialization' module by doing a dummy store & load of a field 
2330-         // Doing both a store and load keeps FxCop happier because it thinks the field is useful 
2331-         let  instrs  = 
2332-             [ 
2333-                 yield ! 
2334-                     ( if  isEnvVarSet " NO_ADD_FEEFEE_TO_CCTORS" then  [] 
2335-                      elif  isEnvVarSet " ADD_SEQPT_TO_CCTORS" then  seqpt
2336-                      else  feefee)  // mark start of hidden code 
2337-                 yield  mkLdcInt32 0 
2338-                 yield  mkNormalStsfld fspec
2339-                 yield  mkNormalLdsfld fspec
2340-                 yield  AI_ pop
2341-             ] 
2347+     member  _.AddExplicitInitToEntryPoint ( tref ,  fspec ,  sourceOpt ,  imports ,  feefee ,  seqpt )  = 
2348+ 
2349+         let  cond  =  ( fun   ( md :  ILMethodDef )  -> ) 
23422350
23432351        gtdefs
23442352            .FindNestedTypeDefBuilder( tref) 
2345-             .PrependInstructionsToSpecificMethodDef( cond,  instrs,  sourceOpt,  imports) 
2353+             .PrependInstructionsToSpecificMethodDef( cond,  ( initialInstrs seqpt feefee)  @  ( finalInstrs fspec),  sourceOpt,  imports) 
2354+         |>  ignore
2355+ 
2356+     member  _.AddExplicitInitToCctor ( tref ,  fspec ,  sourceOpt ,  imports ,  feefee ,  seqpt )  = 
2357+ 
2358+         let  cond  =  ( fun   ( md :  ILMethodDef )  -> =  " .cctor" ) 
2359+ 
2360+         gtdefs
2361+             .FindNestedTypeDefBuilder( tref) 
2362+             .PrependInstructionsToSpecificMethodDef( cond,  initialInstrs seqpt feefee,  sourceOpt,  imports) 
2363+             .AppendInstructionsToSpecificMethodDef( cond,  finalInstrs fspec,  sourceOpt,  imports) 
23462364
23472365    member  _.AddEventDef ( tref ,  edef )  = 
23482366        gtdefs.FindNestedTypeDefBuilder( tref) .AddEventDef( edef) 
@@ -10194,15 +10212,7 @@ and GenImplFile cenv (mgbuf: AssemblyBuilder) mainInfoOpt eenv (implFile: Checke
1019410212                    // This adds the explicit init of the .cctor to the explicit entry point main method 
1019510213                    let  ilDebugRange  =  GenPossibleILDebugRange cenv m
1019610214
10197-                     mgbuf.AddExplicitInitToSpecificMethodDef( 
10198-                         ( fun  md  ->  md.IsEntryPoint), 
10199-                         tref, 
10200-                         fspec, 
10201-                         ilDebugRange, 
10202-                         eenv.imports, 
10203-                         feefee, 
10204-                         seqpt
10205-                     )) 
10215+                     mgbuf.AddExplicitInitToEntryPoint( tref,  fspec,  ilDebugRange,  eenv.imports,  feefee,  seqpt)) 
1020610216
1020710217                let  cctorMethDef  = 
1020810218                    mkILClassCtor ( MethodBody.IL( InterruptibleLazy.FromValue topCode)) 
@@ -10289,7 +10299,7 @@ and GenForceWholeFileInitializationAsPartOfCCtor cenv (mgbuf: AssemblyBuilder) (
1028910299    // Doing both a store and load keeps FxCop happier because it thinks the field is useful 
1029010300    lazyInitInfo.Add( fun  fspec feefee seqpt  -> 
1029110301        let  ilDebugRange  =  GenPossibleILDebugRange cenv m
10292-         mgbuf.AddExplicitInitToSpecificMethodDef (( fun  md  ->  md.Name  =   " .cctor " ),   tref,  fspec,  ilDebugRange,  imports,  feefee,  seqpt)) 
10302+         mgbuf.AddExplicitInitToCctor ( tref,  fspec,  ilDebugRange,  imports,  feefee,  seqpt)) 
1029310303
1029410304/// Generate an Equals method. 
1029510305and  GenEqualsOverrideCallingIComparable  cenv  ( tcref :  TyconRef ,  ilThisTy ,  _ilThatTy )  = 
0 commit comments