@@ -566,15 +566,12 @@ internal enum ClosureStatus : byte
566566 ShouldBeStaticMethod = 1 << 3
567567 }
568568
569- [ Flags ] internal enum LabelFlags : byte { Undefined = 0 , Defined = 1 }
570-
571569 internal struct LabelInfo
572570 {
573571 public object Target ; // label target is the link between the goto and the label.
574572 public Label Label ;
575- public int ReturnVariableIndexPlusOne ;
573+ public int ReturnVariableIndexPlusOneAndIsDefined ;
576574 public Label ReturnLabel ;
577- public LabelFlags Flags ; // todo: @perf combine flags and ReturnVariableIndexPlusOne into one to save space
578575 public int InlinedLambdaInvokeIndex ;
579576 }
580577
@@ -731,9 +728,9 @@ public int AddInlinedLambdaInvoke(InvocationExpression e)
731728 public Label GetDefinedLabel ( int index , ILGenerator il )
732729 {
733730 ref var label = ref Labels . Items [ index ] ;
734- if ( ( label . Flags & LabelFlags . Defined ) == 0 )
731+ if ( ( label . ReturnVariableIndexPlusOneAndIsDefined & 1 ) == 0 )
735732 {
736- label . Flags |= LabelFlags . Defined ;
733+ label . ReturnVariableIndexPlusOneAndIsDefined |= 1 ;
737734 label . Label = il . DefineLabel ( ) ;
738735 }
739736 return label . Label ;
@@ -742,11 +739,11 @@ public Label GetDefinedLabel(int index, ILGenerator il)
742739 public void TryMarkDefinedLabel ( int index , ILGenerator il )
743740 {
744741 ref var label = ref Labels . Items [ index ] ;
745- if ( ( label . Flags & LabelFlags . Defined ) != 0 )
742+ if ( ( label . ReturnVariableIndexPlusOneAndIsDefined & 1 ) == 1 )
746743 il . MarkLabel ( label . Label ) ;
747744 else
748745 {
749- label . Flags |= LabelFlags . Defined ;
746+ label . ReturnVariableIndexPlusOneAndIsDefined |= 1 ;
750747 il . MarkLabel ( label . Label = il . DefineLabel ( ) ) ;
751748 }
752749 }
@@ -1968,11 +1965,11 @@ public static bool TryEmit(Expression expr, IReadOnlyList<PE> paramExprs,
19681965 if ( invokeIndex == - 1 )
19691966 return false ;
19701967 ref var invokeInfo = ref closure . Labels . Items [ invokeIndex ] ;
1971- var varIndex = invokeInfo . ReturnVariableIndexPlusOne - 1 ;
1968+ var varIndex = ( invokeInfo . ReturnVariableIndexPlusOneAndIsDefined >> 1 ) - 1 ;
19721969 if ( varIndex == - 1 )
19731970 {
19741971 varIndex = il . GetNextLocalVarIndex ( gtOrLabelValue . Type ) ;
1975- invokeInfo . ReturnVariableIndexPlusOne = varIndex + 1 ;
1972+ invokeInfo . ReturnVariableIndexPlusOneAndIsDefined = ( varIndex + 1 ) << 1 ;
19761973 invokeInfo . ReturnLabel = il . DefineLabel ( ) ;
19771974 }
19781975 EmitStoreLocalVariable ( il , varIndex ) ;
@@ -2174,11 +2171,11 @@ private static bool TryEmitLabel(LabelExpression expr, IReadOnlyList<PE> paramE
21742171 return false ; // should be found in first collecting constants round
21752172
21762173 ref var label = ref closure . Labels . Items [ index ] ;
2177- if ( ( label . Flags & LabelFlags . Defined ) != 0 )
2174+ if ( ( label . ReturnVariableIndexPlusOneAndIsDefined & 1 ) == 1 )
21782175 il . MarkLabel ( label . Label ) ;
21792176 else
21802177 {
2181- label . Flags |= LabelFlags . Defined ;
2178+ label . ReturnVariableIndexPlusOneAndIsDefined |= 1 ;
21822179 il . MarkLabel ( label . Label = il . DefineLabel ( ) ) ;
21832180 }
21842181
@@ -2189,7 +2186,7 @@ private static bool TryEmitLabel(LabelExpression expr, IReadOnlyList<PE> paramE
21892186 // get the TryCatch variable from the LabelInfo - if it is not 0:
21902187 // first if label has the default value then store into this return variable the defaultValue which is currently on stack
21912188 // mark the associated TryCatch return label here and load the variable if parent does not ignore the result, otherwise don't load
2192- var returnVariableIndexPlusOne = label . ReturnVariableIndexPlusOne ;
2189+ var returnVariableIndexPlusOne = label . ReturnVariableIndexPlusOneAndIsDefined >> 1 ;
21932190 if ( returnVariableIndexPlusOne != 0 )
21942191 {
21952192 if ( defaultValue != null )
@@ -2249,11 +2246,11 @@ private static bool TryEmitGoto(GotoExpression expr, IReadOnlyList<PE> paramExp
22492246 // store the return expression result into the that variable
22502247 // emit OpCodes.Leave to the special label with the result which should be marked after the label to jump over its default value
22512248 ref var label = ref closure . Labels . Items [ index ] ;
2252- var varIndex = label . ReturnVariableIndexPlusOne - 1 ;
2249+ var varIndex = ( label . ReturnVariableIndexPlusOneAndIsDefined >> 1 ) - 1 ;
22532250 if ( varIndex == - 1 )
22542251 {
22552252 varIndex = il . GetNextLocalVarIndex ( gotoValue . Type ) ;
2256- label . ReturnVariableIndexPlusOne = varIndex + 1 ;
2253+ label . ReturnVariableIndexPlusOneAndIsDefined = ( varIndex + 1 ) << 1 ;
22572254 label . ReturnLabel = il . DefineLabel ( ) ;
22582255 }
22592256 EmitStoreLocalVariable ( il , varIndex ) ;
@@ -2270,11 +2267,11 @@ private static bool TryEmitGoto(GotoExpression expr, IReadOnlyList<PE> paramExp
22702267 if ( invokeIndex == - 1 )
22712268 return false ;
22722269 ref var invokeInfo = ref closure . Labels . Items [ invokeIndex ] ;
2273- var varIndex = invokeInfo . ReturnVariableIndexPlusOne - 1 ;
2270+ var varIndex = ( invokeInfo . ReturnVariableIndexPlusOneAndIsDefined >> 1 ) - 1 ;
22742271 if ( varIndex == - 1 )
22752272 {
22762273 varIndex = il . GetNextLocalVarIndex ( gotoValue . Type ) ;
2277- invokeInfo . ReturnVariableIndexPlusOne = varIndex + 1 ;
2274+ invokeInfo . ReturnVariableIndexPlusOneAndIsDefined = ( varIndex + 1 ) << 1 ;
22782275 invokeInfo . ReturnLabel = il . DefineLabel ( ) ;
22792276 }
22802277 EmitStoreLocalVariable ( il , varIndex ) ;
@@ -4252,10 +4249,11 @@ private static bool TryEmitInvoke(InvocationExpression expr, IReadOnlyList<PE> p
42524249 if ( li != - 1 )
42534250 {
42544251 ref var labelInfo = ref closure . Labels . Items [ li ] ;
4255- if ( labelInfo . ReturnVariableIndexPlusOne != 0 )
4252+ var returnVariableIndexPlusOne = labelInfo . ReturnVariableIndexPlusOneAndIsDefined >> 1 ;
4253+ if ( returnVariableIndexPlusOne != 0 )
42564254 {
42574255 il . MarkLabel ( labelInfo . ReturnLabel ) ;
4258- EmitLoadLocalVariable ( il , labelInfo . ReturnVariableIndexPlusOne - 1 ) ;
4256+ EmitLoadLocalVariable ( il , returnVariableIndexPlusOne - 1 ) ;
42594257 }
42604258 }
42614259 }
0 commit comments