@@ -85,7 +85,8 @@ import {
8585 DecoratorFlags ,
8686 Class ,
8787 PropertyPrototype ,
88- VariableLikeElement
88+ VariableLikeElement ,
89+ Function ,
8990} from "./program" ;
9091
9192import {
@@ -10673,6 +10674,17 @@ builtinFunctions.set(BuiltinNames.i32x4_relaxed_dot_i8x16_i7x16_add_s, builtin_i
1067310674
1067410675// === Internal helpers =======================================================================
1067510676
10677+ function getVisitInstanceName ( visitInstance : Function , classReference : Class ) : string | null {
10678+ if ( classReference . hasDecorator ( DecoratorFlags . Final ) ) {
10679+ if ( classReference . visitRef != 0 ) {
10680+ return classReference . visitorFunctionName ;
10681+ } else if ( classReference . isPointerfree ) {
10682+ return null ; // no visitor for pointerfree classes
10683+ }
10684+ }
10685+ return visitInstance . internalName ;
10686+ }
10687+
1067610688/** Compiles the `visit_globals` function. */
1067710689export function compileVisitGlobals ( compiler : Compiler ) : void {
1067810690 let module = compiler . module ;
@@ -10695,11 +10707,13 @@ export function compileVisitGlobals(compiler: Compiler): void {
1069510707 ! classReference . hasDecorator ( DecoratorFlags . Unmanaged ) &&
1069610708 global . is ( CommonFlags . Compiled )
1069710709 ) {
10710+ let visitFunctionName = getVisitInstanceName ( visitInstance , classReference ) ;
10711+ if ( visitFunctionName == null ) continue ;
1069810712 if ( global . is ( CommonFlags . Inlined ) ) {
1069910713 let value = global . constantIntegerValue ;
1070010714 if ( i64_low ( value ) || i64_high ( value ) ) {
1070110715 exprs . push (
10702- module . call ( visitInstance . internalName , [
10716+ module . call ( visitFunctionName , [
1070310717 compiler . options . isWasm64
1070410718 ? module . i64 ( i64_low ( value ) , i64_high ( value ) )
1070510719 : module . i32 ( i64_low ( value ) ) ,
@@ -10714,7 +10728,7 @@ export function compileVisitGlobals(compiler: Compiler): void {
1071410728 module . global_get ( global . internalName , sizeTypeRef ) ,
1071510729 false // internal
1071610730 ) ,
10717- module . call ( visitInstance . internalName , [
10731+ module . call ( visitFunctionName , [
1071810732 module . local_get ( 1 , sizeTypeRef ) , // tempRef != null
1071910733 module . local_get ( 0 , TypeRef . I32 ) // cookie
1072010734 ] , TypeRef . None )
@@ -10750,7 +10764,7 @@ function ensureVisitMembersOf(compiler: Compiler, instance: Class): void {
1075010764 let base = instance . base ;
1075110765 if ( base ) {
1075210766 body . push (
10753- module . call ( ` ${ base . internalName } ~visit` , [
10767+ module . call ( base . visitorFunctionName , [
1075410768 module . local_get ( 0 , sizeTypeRef ) , // this
1075510769 module . local_get ( 1 , TypeRef . I32 ) // cookie
1075610770 ] , TypeRef . None )
@@ -10860,7 +10874,7 @@ export function compileVisitMembers(compiler: Compiler): void {
1086010874 cases [ i ] = module . return ( ) ;
1086110875 } else {
1086210876 cases [ i ] = module . block ( null , [
10863- module . call ( ` ${ instance . internalName } ~visit` , [
10877+ module . call ( instance . visitorFunctionName , [
1086410878 module . local_get ( 0 , sizeTypeRef ) , // this
1086510879 module . local_get ( 1 , TypeRef . I32 ) // cookie
1086610880 ] , TypeRef . None ) ,
0 commit comments