@@ -327,22 +327,14 @@ private static void checkFailures(ArrayList<Throwable> failures) {
327327 }
328328 }
329329
330- void resolveGlobalImport (WasmStore store , WasmInstance instance , ImportDescriptor importDescriptor , int globalIndex , int valueType , byte mutability ,
331- ImportValueSupplier imports ) {
330+ void resolveGlobalImport (WasmStore store , WasmInstance instance , ImportDescriptor importDescriptor , int globalIndex , int valueType , byte mutability , ImportValueSupplier imports ) {
332331 instance .globals ().setInitialized (globalIndex , false );
333332 final String importedGlobalName = importDescriptor .memberName ();
334333 final String importedModuleName = importDescriptor .moduleName ();
335334 final Runnable resolveAction = () -> {
336335 assert instance .module ().globalImported (globalIndex ) && globalIndex == importDescriptor .targetIndex () : importDescriptor ;
337336 WasmGlobal externalGlobal = lookupImportObject (instance , importDescriptor , imports , WasmGlobal .class );
338- final int exportedValueType ;
339- final SymbolTable .ClosedValueType exportedClosedValueType ;
340- final byte exportedMutability ;
341- if (externalGlobal != null ) {
342- exportedValueType = externalGlobal .getType ();
343- exportedClosedValueType = externalGlobal .getClosedValueType ();
344- exportedMutability = externalGlobal .getMutability ();
345- } else {
337+ if (externalGlobal == null ) {
346338 final WasmInstance importedInstance = store .lookupModuleInstance (importedModuleName );
347339 if (importedInstance == null ) {
348340 throw WasmException .create (Failure .UNKNOWN_IMPORT , "Module '" + importedModuleName + "', referenced in the import of global variable '" +
@@ -356,21 +348,22 @@ void resolveGlobalImport(WasmStore store, WasmInstance instance, ImportDescripto
356348 "', was not exported in the module '" + importedModuleName + "'." );
357349 }
358350
359- exportedValueType = importedInstance .symbolTable ().globalValueType (exportedGlobalIndex );
360- exportedClosedValueType = importedInstance .symbolTable ().globalClosedValueType (exportedGlobalIndex );
361- exportedMutability = importedInstance .symbolTable ().globalMutability (exportedGlobalIndex );
362-
363351 externalGlobal = importedInstance .externalGlobal (exportedGlobalIndex );
364352 }
365- if (!instance .symbolTable ().closedTypeOf (valueType ).isSupertypeOf (exportedClosedValueType )) {
353+ SymbolTable .ClosedValueType importType = instance .symbolTable ().closedTypeOf (valueType );
354+ SymbolTable .ClosedValueType exportType = externalGlobal .getClosedType ();
355+ if (mutability != externalGlobal .getMutability ()) {
366356 throw WasmException .create (Failure .INCOMPATIBLE_IMPORT_TYPE , "Global variable '" + importedGlobalName + "' is imported into module '" + instance .name () +
367- "' with the type " + WasmType . toString ( valueType ) + ", " +
368- "but it was exported in the module '" + importedModuleName + "' with the type " + WasmType . toString ( exportedValueType ) + "." );
357+ "' with the modifier " + GlobalModifier . asString ( mutability ) + ", " +
358+ "but it was exported in the module '" + importedModuleName + "' with the modifier " + GlobalModifier . asString ( externalGlobal . getMutability () ) + "." );
369359 }
370- if (exportedMutability != mutability ) {
360+ // matching for mutable globals does not work by subtyping, but requires equivalent
361+ // types
362+ if (!(externalGlobal .isMutable () ? importType .equals (exportType ) : importType .isSupertypeOf (exportType ))) {
371363 throw WasmException .create (Failure .INCOMPATIBLE_IMPORT_TYPE , "Global variable '" + importedGlobalName + "' is imported into module '" + instance .name () +
372- "' with the modifier " + GlobalModifier .asString (mutability ) + ", " +
373- "but it was exported in the module '" + importedModuleName + "' with the modifier " + GlobalModifier .asString (exportedMutability ) + "." );
364+ "' with the type " + GlobalModifier .asString (mutability ) + " " + WasmType .toString (valueType ) + ", " +
365+ "but it was exported in the module '" + importedModuleName + "' with the type " + GlobalModifier .asString (externalGlobal .getMutability ()) + " " +
366+ WasmType .toString (externalGlobal .getType ()) + "." );
374367 }
375368 instance .setExternalGlobal (globalIndex , externalGlobal );
376369 instance .globals ().setInitialized (globalIndex , true );
@@ -391,7 +384,7 @@ private static void initializeGlobal(WasmInstance instance, int globalIndex, Obj
391384 assert !instance .globals ().isInitialized (globalIndex ) : globalIndex ;
392385 SymbolTable symbolTable = instance .symbolTable ();
393386 if (symbolTable .globalExternal (globalIndex )) {
394- var global = new WasmGlobal (symbolTable . globalValueType ( globalIndex ) , symbolTable . isGlobalMutable ( globalIndex ), instance . symbolTable () , initValue );
387+ var global = new WasmGlobal (globalIndex , symbolTable , initValue );
395388 instance .setExternalGlobal (globalIndex , global );
396389 } else {
397390 instance .globals ().store (symbolTable .globalValueType (globalIndex ), symbolTable .globalAddress (globalIndex ), initValue );
@@ -568,9 +561,8 @@ void resolveTagImport(WasmStore store, WasmInstance instance, ImportDescriptor i
568561 }
569562 importedTag = importedInstance .tag (exportedTagIndex );
570563 }
571- // matching for tag types does not work by subtyping, but requires equivalent types,
572- // A <= B and B <= A
573- Assert .assertTrue (type .isSupertypeOf (importedTag .type ()) && importedTag .type ().isSupertypeOf (type ), Failure .INCOMPATIBLE_IMPORT_TYPE );
564+ // matching for tag types does not work by subtyping, but requires equivalent types
565+ Assert .assertTrue (type .equals (importedTag .type ()), Failure .INCOMPATIBLE_IMPORT_TYPE );
574566 instance .setTag (tagIndex , importedTag );
575567 };
576568 resolutionDag .resolveLater (new ImportTagSym (instance .name (), importDescriptor , tagIndex ), new Sym []{new ExportTagSym (importedModuleName , importedTagName )}, resolveAction );
0 commit comments