emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.4k stars 3.25k forks source link

[embind] Using `EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0` fails with polymorphic types #21619

Open sbc100 opened 3 months ago

sbc100 commented 3 months ago

The EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 feature seems to not work with polymorphic types.

Adding a flavor of other.test_embind that builds with EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 causes the test to fail with:

Error: expected: PolyDerived, actual: PolyBase
    at Object.assert.equal (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6055:18)
    at Object.<anonymous> (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6688:20)
    at runTest (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:5887:23)
    at run_all (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:5907:26)
    at run_all_tests (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6410:5)
    at Object.<anonymous> (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:9366:5)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47
error: Error: expected: PolyDerived, actual: PolyBase
    at Object.assert.equal (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6055:18)
    at Object.<anonymous> (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6688:20)
    at runTest (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:5887:23)
    at run_all (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:5907:26)
    at run_all_tests (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:6410:5)
    at Object.<anonymous> (/usr/local/google/home/sbc/dev/wasm/emscripten/out/test/embind_test.js:9366:5)
    at Module._compile (node:internal/modules/cjs/loader:1196:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1250:10)
    at Module.load (node:internal/modules/cjs/loader:1074:32)
    at Function.Module._load (node:internal/modules/cjs/loader:909:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:22:47 {
  info: { Expected: 'PolyDerived', Actual: 'PolyBase' }
}

I believe this is because getLightTypeID() is able to inspect the type of a value when EMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES is enabled but other wise it only looks at the type T and not the value: https://github.com/emscripten-core/emscripten/blob/d99707c10d916cdb2064c38216ab7304cdb781c0/system/include/emscripten/wire.h#L85-L95

sbc100 commented 3 months ago

It looks like when this feature was first added we only used the LightTypeID when the type was not polymorphic: 2bbdb0cd396d785a9587bc776d699283c1902ff7

However this check was removed in #10914

sbc100 commented 3 months ago

@brendandahl

sbc100 commented 3 months ago

@dnfield it seems like the assumption of https://github.com/emscripten-core/emscripten/pull/10914 is that all cases should work find without RTTI. If that is true why do we have the rtti mode still? Why not default to not -DEMSCRIPTEN_HAS_UNBOUND_TYPE_NAMES=0 and no rtti usage.

However, based on the above failure, I'm not sure this assumption is true.

sbc100 commented 3 months ago

CC @chadaustin