diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2021-06-11 09:41:09 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-11 06:41:09 -0700 |
commit | 446634a503116186a025d23375c430cb837e00f0 (patch) | |
tree | 4538df79e3c7cabec072ff90053c30ea6309a0f5 /src/wasm-type.h | |
parent | ca263c00ec8ff3b7c51d066b273eeee50180091b (diff) | |
download | binaryen-446634a503116186a025d23375c430cb837e00f0.tar.gz binaryen-446634a503116186a025d23375c430cb837e00f0.tar.bz2 binaryen-446634a503116186a025d23375c430cb837e00f0.zip |
Nominal subtyping (#3927)
Add methods to the TypeBuilder interface to declare subtyping relationships
between the built types. These relationships are validated and recorded globally
as part of type building. If the relationships are not valid, a fatal error is
produced. In the future, it would be better to report the error to the
TypeBuilder client code, but this behavior is sufficient for now. Also updates
SubTyper and TypeBounder to be aware of nominal mode so that subtyping and LUBs
are correctly calculated.
Tests of the failing behavior will be added in a future PR that exposes this
functionality to the command line, since the current `example` testing
infrastructure cannot handle testing fatal errors.
Diffstat (limited to 'src/wasm-type.h')
-rw-r--r-- | src/wasm-type.h | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/wasm-type.h b/src/wasm-type.h index 11b23ed52..ff7e9af9c 100644 --- a/src/wasm-type.h +++ b/src/wasm-type.h @@ -550,9 +550,16 @@ struct TypeBuilder { Type getTempRefType(HeapType heapType, Nullability nullable); Type getTempRttType(Rtt rtt); + // In nominal mode, declare the HeapType being built at index `i` to be an + // immediate subtype of the HeapType being built at index `j`. Does nothing in + // equirecursive mode. + void setSubType(size_t i, size_t j); + // Returns all of the newly constructed heap types. May only be called once // all of the heap types have been initialized with `setHeapType`. In nominal - // mode, all of the constructed HeapTypes will be fresh and distinct. + // mode, all of the constructed HeapTypes will be fresh and distinct. In + // nominal mode, will also produce a fatal error if the declared subtype + // relationships are not valid. std::vector<HeapType> build(); // Utility for ergonomically using operator[] instead of explicit setHeapType @@ -581,6 +588,11 @@ struct TypeBuilder { builder.setHeapType(index, array); return *this; } + Entry& subTypeOf(Entry other) { + assert(&builder == &other.builder); + builder.setSubType(index, other.index); + return *this; + } }; Entry operator[](size_t i) { return Entry{*this, i}; } |