@@ -84,8 +84,11 @@ export function generate<S extends Stack>(
8484 }
8585 }
8686
87+ // A block of an inlined body is entered inside that body
88+ const entryDebug = withEntryInline ( block ) ;
89+
8790 if ( callSiteCode ) {
88- const entry = block . entryDebug ;
91+ const entry = entryDebug ;
8992 const continuationDebug = {
9093 ...entry ,
9194 context : {
@@ -95,7 +98,7 @@ export function generate<S extends Stack>(
9598 } ;
9699 result = result . then ( JUMPDEST ( { debug : continuationDebug } ) ) ;
97100 } else {
98- result = result . then ( JUMPDEST ( { debug : block . entryDebug } ) ) ;
101+ result = result . then ( JUMPDEST ( { debug : entryDebug } ) ) ;
99102 }
100103
101104 // Annotate TOS with dest variable if this is a continuation with return value.
@@ -262,6 +265,46 @@ export function generate<S extends Stack>(
262265 . done ( ) ;
263266}
264267
268+ /**
269+ * A block's entry debug, with an `inline` transform for each inlined
270+ * body the block's entry is in: each one its first operation is in,
271+ * but for those whose invoke it carries (its entry is just before
272+ * them).
273+ */
274+ function withEntryInline ( block : Ir . Block ) : Ir . Block . Debug | undefined {
275+ const first = block . instructions [ 0 ] ?? block . terminator ;
276+ const context = first . operationDebug ?. context ;
277+ const depth =
278+ inlineCount ( context ) - Ir . Utils . activationsOf ( context , "invoke" ) . length ;
279+ if ( depth <= 0 ) return block . entryDebug ;
280+ return {
281+ ...block . entryDebug ,
282+ ...Ir . Utils . addTransform (
283+ block . entryDebug ,
284+ ...Array < "inline" > ( depth ) . fill ( "inline" ) ,
285+ ) ,
286+ } ;
287+ }
288+
289+ /** How many `inline` transforms a context has, gathered ones too */
290+ function inlineCount ( context : Format . Program . Context | undefined ) : number {
291+ if ( ! context || typeof context !== "object" ) return 0 ;
292+ const { transform, gather } = context as {
293+ transform ?: unknown ;
294+ gather ?: unknown ;
295+ } ;
296+ const own = Array . isArray ( transform )
297+ ? transform . filter ( ( id ) => id === "inline" ) . length
298+ : 0 ;
299+ return Array . isArray ( gather )
300+ ? own +
301+ ( gather as Format . Program . Context [ ] ) . reduce (
302+ ( sum , c ) => sum + inlineCount ( c ) ,
303+ 0 ,
304+ )
305+ : own ;
306+ }
307+
265308/**
266309 * Generate code for the phi nodes of the block that `predecessor`
267310 * jumps to. The phis copy in parallel: one phi's source may be another
0 commit comments