Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/wasm-type.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ namespace wasm {

class Type {
// enough for the limit of 1000 function arguments
static constexpr unsigned sizeBits = 10;
static constexpr unsigned unknownSize = (1 << sizeBits) - 1;
unsigned id : 32 - sizeBits;
unsigned _size : sizeBits;
static constexpr unsigned SIZE_BITS = 10;
static constexpr unsigned ID_BITS = 32 - SIZE_BITS;
static constexpr unsigned UNKNOWN_SIZE = (1 << SIZE_BITS) - 1;
unsigned id : ID_BITS;
unsigned _size : SIZE_BITS;
void init(const std::vector<Type>&);

public:
Expand Down Expand Up @@ -57,7 +58,7 @@ class Type {
constexpr Type(ValueType id) : id(id), _size(id == none ? 0 : 1){};

// But converting raw uint32_t is more dangerous, so make it explicit
constexpr explicit Type(uint32_t id) : id(id), _size(unknownSize){};
constexpr explicit Type(uint32_t id) : id(id), _size(UNKNOWN_SIZE){};

// Construct from lists of elementary types
Type(std::initializer_list<Type> types);
Expand Down
8 changes: 4 additions & 4 deletions src/wasm/wasm-type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ void Type::init(const std::vector<Type>& types) {
}
#endif

if (types.size() >= unknownSize) {
if (types.size() >= UNKNOWN_SIZE) {
WASM_UNREACHABLE("Type too large");
}
_size = types.size();
Expand Down Expand Up @@ -120,7 +120,7 @@ void Type::init(const std::vector<Type>& types) {
if (lookup()) {
return;
}
if (typeLists.size() >= (1 << (32 - sizeBits))) {
if (typeLists.size() >= (1 << (ID_BITS))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extra unnecessary parens here around ID_BITS

WASM_UNREACHABLE("Too many types!");
}
id = typeLists.size();
Expand All @@ -134,14 +134,14 @@ Type::Type(std::initializer_list<Type> types) { init(types); }
Type::Type(const std::vector<Type>& types) { init(types); }

size_t Type::size() {
if (_size == unknownSize) {
if (_size == UNKNOWN_SIZE) {
_size = expand().size();
}
return _size;
}

size_t Type::size() const {
if (_size == unknownSize) {
if (_size == UNKNOWN_SIZE) {
return expand().size();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the bad old path? i hope we can avoid it as mentioned in another comment, by requiring the size to always be known.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, this seems ok for now but we should figure this out later.

}
return _size;
Expand Down