Skip to content

Remove implicit conversion operators from Type #2577

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions src/asm2wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -1508,7 +1508,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
assert(params[i] == Type::f64 ||
curr->operands[i]->type == Type::unreachable);
// overloaded, upgrade to f64
switch (curr->operands[i]->type) {
switch (curr->operands[i]->type.getSingle()) {
case Type::i32:
curr->operands[i] = parent->builder.makeUnary(
ConvertSInt32ToFloat64, curr->operands[i]);
Expand All @@ -1529,7 +1529,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
if (importResults == Type::f64) {
// we use a JS f64 value which is the most general, and convert to
// it
switch (old) {
switch (old.getSingle()) {
case Type::i32: {
Unary* trunc =
parent->builder.makeUnary(TruncSFloat64ToInt32, curr);
Expand Down
4 changes: 2 additions & 2 deletions src/asmjs/asm_v_wasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Type asmToWasmType(AsmType asmType) {
}

AsmType wasmToAsmType(Type type) {
switch (type) {
switch (type.getSingle()) {
case Type::i32:
return ASM_INT;
case Type::f32:
Expand All @@ -67,7 +67,7 @@ AsmType wasmToAsmType(Type type) {
}

char getSig(Type type) {
switch (type) {
switch (type.getSingle()) {
case Type::i32:
return 'i';
case Type::i64:
Expand Down
26 changes: 13 additions & 13 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ static_assert(sizeof(BinaryenLiteral) == sizeof(Literal),

BinaryenLiteral toBinaryenLiteral(Literal x) {
BinaryenLiteral ret;
ret.type = x.type;
switch (x.type) {
ret.type = x.type.getID();
switch (x.type.getSingle()) {
case Type::i32:
ret.i32 = x.geti32();
break;
Expand Down Expand Up @@ -305,19 +305,19 @@ BinaryenType BinaryenTypeCreate(BinaryenType* types, uint32_t numTypes) {
}
std::cout << "};\n";
std::cout << " BinaryenTypeCreate(" << array << ", " << numTypes
<< "); // " << uint32_t(result) << "\n";
<< "); // " << result.getID() << "\n";
std::cout << " }\n";
}

return uint32_t(result);
return result.getID();
}

uint32_t BinaryenTypeArity(BinaryenType t) { return Type(t).size(); }

void BinaryenTypeExpand(BinaryenType t, BinaryenType* buf) {
const std::vector<Type>& types = Type(t).expand();
for (size_t i = 0; i < types.size(); ++i) {
buf[i] = types[i];
buf[i] = types[i].getSingle();
}
}

Expand Down Expand Up @@ -1833,7 +1833,7 @@ BinaryenType BinaryenExpressionGetType(BinaryenExpressionRef expr) {
<< "]);\n";
}

return ((Expression*)expr)->type;
return ((Expression*)expr)->type.getID();
}
void BinaryenExpressionPrint(BinaryenExpressionRef expr) {
if (tracing) {
Expand Down Expand Up @@ -2643,7 +2643,7 @@ BinaryenType BinaryenAtomicWaitGetExpectedType(BinaryenExpressionRef expr) {

auto* expression = (Expression*)expr;
assert(expression->is<AtomicWait>());
return static_cast<AtomicWait*>(expression)->expectedType;
return static_cast<AtomicWait*>(expression)->expectedType.getID();
}
// AtomicNotify
BinaryenExpressionRef BinaryenAtomicNotifyGetPtr(BinaryenExpressionRef expr) {
Expand Down Expand Up @@ -4112,15 +4112,15 @@ BinaryenType BinaryenFunctionGetParams(BinaryenFunctionRef func) {
<< "]);\n";
}

return ((Function*)func)->sig.params;
return ((Function*)func)->sig.params.getID();
}
BinaryenType BinaryenFunctionGetResults(BinaryenFunctionRef func) {
if (tracing) {
std::cout << " BinaryenFunctionGetResults(functions[" << functions[func]
<< "]);\n";
}

return ((Function*)func)->sig.results;
return ((Function*)func)->sig.results.getID();
}
BinaryenIndex BinaryenFunctionGetNumVars(BinaryenFunctionRef func) {
if (tracing) {
Expand All @@ -4139,7 +4139,7 @@ BinaryenType BinaryenFunctionGetVar(BinaryenFunctionRef func,

auto* fn = (Function*)func;
assert(index < fn->vars.size());
return fn->vars[index];
return fn->vars[index].getID();
}
BinaryenExpressionRef BinaryenFunctionGetBody(BinaryenFunctionRef func) {
if (tracing) {
Expand Down Expand Up @@ -4230,7 +4230,7 @@ BinaryenType BinaryenGlobalGetType(BinaryenGlobalRef global) {
<< "]);\n";
}

return ((Global*)global)->type;
return ((Global*)global)->type.getID();
}
int BinaryenGlobalIsMutable(BinaryenGlobalRef global) {
if (tracing) {
Expand Down Expand Up @@ -4273,7 +4273,7 @@ BinaryenType BinaryenEventGetParams(BinaryenEventRef event) {
std::cout << " BinaryenEventGetParams(events[" << events[event] << "]);\n";
}

return ((Event*)event)->sig.params;
return ((Event*)event)->sig.params.getID();
}

BinaryenType BinaryenEventGetResults(BinaryenEventRef event) {
Expand All @@ -4282,7 +4282,7 @@ BinaryenType BinaryenEventGetResults(BinaryenEventRef event) {
<< "]);\n";
}

return ((Event*)event)->sig.results;
return ((Event*)event)->sig.results.getID();
}

//
Expand Down
10 changes: 5 additions & 5 deletions src/ir/ExpressionAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ template<typename T> void visitImmediates(Expression* curr, T& visitor) {
visitor.visitInt(curr->isReturn);
}
void visitCallIndirect(CallIndirect* curr) {
visitor.visitInt(curr->sig.params);
visitor.visitInt(curr->sig.results);
visitor.visitInt(curr->sig.params.getID());
visitor.visitInt(curr->sig.results.getID());
visitor.visitInt(curr->isReturn);
}
void visitLocalGet(LocalGet* curr) { visitor.visitIndex(curr->index); }
Expand All @@ -164,7 +164,7 @@ template<typename T> void visitImmediates(Expression* curr, T& visitor) {
visitor.visitAddress(curr->offset);
visitor.visitAddress(curr->align);
visitor.visitInt(curr->isAtomic);
visitor.visitInt(curr->valueType);
visitor.visitInt(curr->valueType.getID());
}
void visitAtomicRMW(AtomicRMW* curr) {
visitor.visitInt(curr->op);
Expand Down Expand Up @@ -438,7 +438,7 @@ HashType ExpressionAnalyzer::hash(Expression* curr) {
// if we hash between modules, then we need to take int account
// call_imports type, etc. The simplest thing is just to hash the
// type for all of them.
hash(curr->type);
hash(curr->type.getID());
// Blocks and loops introduce scoping.
if (auto* block = curr->dynCast<Block>()) {
noteScopeName(block->name);
Expand Down Expand Up @@ -477,7 +477,7 @@ HashType ExpressionAnalyzer::hash(Expression* curr) {
void visitNonScopeName(Name curr) { return hash64(uint64_t(curr.str)); }
void visitInt(int32_t curr) { hash(curr); }
void visitLiteral(Literal curr) { hash(std::hash<Literal>()(curr)); }
void visitType(Type curr) { hash(int32_t(curr)); }
void visitType(Type curr) { hash(int32_t(curr.getSingle())); }
void visitIndex(Index curr) {
static_assert(sizeof(Index) == sizeof(int32_t),
"wasm64 will need changes here");
Expand Down
2 changes: 1 addition & 1 deletion src/ir/ReFinalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ void ReFinalize::replaceUntaken(Expression* value, Expression* condition) {
condition = builder.makeDrop(condition);
}
replacement = builder.makeSequence(value, condition);
assert(replacement->type);
assert(replacement->type.getSingle());
}
replaceCurrent(replacement);
}
Expand Down
4 changes: 2 additions & 2 deletions src/ir/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ enum Op {
// you can provide i32 and Add and receive the specific opcode for a 32-bit
// addition, AddInt32. If the op does not exist, it returns Invalid.
inline UnaryOp getUnary(Type type, Op op) {
switch (type) {
switch (type.getSingle()) {
case Type::i32: {
return InvalidUnary;
}
Expand Down Expand Up @@ -93,7 +93,7 @@ inline UnaryOp getUnary(Type type, Op op) {
}

inline BinaryOp getBinary(Type type, Op op) {
switch (type) {
switch (type.getSingle()) {
case Type::i32: {
switch (op) {
case Add:
Expand Down
6 changes: 3 additions & 3 deletions src/ir/hashed.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ struct FunctionHasher : public WalkerPass<PostWalker<FunctionHasher>> {

static HashType hashFunction(Function* func) {
HashType ret = 0;
ret = rehash(ret, (HashType)func->sig.params);
ret = rehash(ret, (HashType)func->sig.results);
ret = rehash(ret, (HashType)func->sig.params.getID());
ret = rehash(ret, (HashType)func->sig.results.getID());
for (auto type : func->vars) {
ret = rehash(ret, (HashType)type);
ret = rehash(ret, (HashType)type.getSingle());
}
ret = rehash(ret, (HashType)ExpressionAnalyzer::hash(func->body));
return ret;
Expand Down
8 changes: 4 additions & 4 deletions src/literal.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Literal {
bool isNone() { return type == Type::none; }

static Literal makeFromInt32(int32_t x, Type type) {
switch (type) {
switch (type.getSingle()) {
case Type::i32:
return Literal(int32_t(x));
break;
Expand Down Expand Up @@ -454,7 +454,7 @@ template<> struct hash<wasm::Literal> {
a.getBits(bytes);
int64_t chunks[2];
memcpy(chunks, bytes, sizeof(chunks));
return wasm::rehash(wasm::rehash(uint64_t(hash<size_t>()(size_t(a.type))),
return wasm::rehash(wasm::rehash(uint64_t(hash<uint32_t>()(a.type.getID())),
uint64_t(hash<int64_t>()(chunks[0]))),
uint64_t(hash<int64_t>()(chunks[1])));
}
Expand All @@ -464,10 +464,10 @@ template<> struct less<wasm::Literal> {
if (a.type < b.type) {
return true;
}
if (a.type > b.type) {
if (b.type < a.type) {
return false;
}
switch (a.type) {
switch (a.type.getSingle()) {
case wasm::Type::i32:
return a.geti32() < b.geti32();
case wasm::Type::f32:
Expand Down
12 changes: 6 additions & 6 deletions src/parsing.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
ret->type = type;
if (type.isFloat()) {
if (s == _INFINITY) {
switch (type) {
switch (type.getSingle()) {
case Type::f32:
ret->value = Literal(std::numeric_limits<float>::infinity());
break;
Expand All @@ -98,7 +98,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
return ret;
}
if (s == NEG_INFINITY) {
switch (type) {
switch (type.getSingle()) {
case Type::f32:
ret->value = Literal(-std::numeric_limits<float>::infinity());
break;
Expand All @@ -112,7 +112,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
return ret;
}
if (s == _NAN) {
switch (type) {
switch (type.getSingle()) {
case Type::f32:
ret->value = Literal(float(std::nan("")));
break;
Expand All @@ -137,7 +137,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
if (!(modifier ? positive[4] == '0' && positive[5] == 'x' : 1)) {
throw ParseException("bad nan input");
}
switch (type) {
switch (type.getSingle()) {
case Type::f32: {
uint32_t pattern;
if (modifier) {
Expand Down Expand Up @@ -187,7 +187,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
return ret;
}
if (s == NEG_NAN) {
switch (type) {
switch (type.getSingle()) {
case Type::f32:
ret->value = Literal(float(-std::nan("")));
break;
Expand All @@ -201,7 +201,7 @@ parseConst(cashew::IString s, Type type, MixedArena& allocator) {
return ret;
}
}
switch (type) {
switch (type.getSingle()) {
case Type::i32: {
if ((str[0] == '0' && str[1] == 'x') ||
(str[0] == '-' && str[1] == '0' && str[2] == 'x')) {
Expand Down
2 changes: 1 addition & 1 deletion src/passes/ConstHoisting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ struct ConstHoisting : public WalkerPass<PostWalker<ConstHoisting>> {
}
// measure the size of the constant
Index size = 0;
switch (value.type) {
switch (value.type.getSingle()) {
case Type::i32: {
size = getWrittenSize(S32LEB(value.geti32()));
break;
Expand Down
4 changes: 2 additions & 2 deletions src/passes/FuncCastEmulation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static const int NUM_PARAMS = 16;
// Converts a value to the ABI type of i64.
static Expression* toABI(Expression* value, Module* module) {
Builder builder(*module);
switch (value->type) {
switch (value->type.getSingle()) {
case Type::i32: {
value = builder.makeUnary(ExtendUInt32, value);
break;
Expand Down Expand Up @@ -88,7 +88,7 @@ static Expression* toABI(Expression* value, Module* module) {
// Converts a value from the ABI type of i64 to the expected type
static Expression* fromABI(Expression* value, Type type, Module* module) {
Builder builder(*module);
switch (type) {
switch (type.getSingle()) {
case Type::i32: {
value = builder.makeUnary(WrapInt64, value);
break;
Expand Down
4 changes: 2 additions & 2 deletions src/passes/I64ToI32Lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {

private:
void freeIdx() {
auto& freeList = pass.freeTemps[(int)ty];
auto& freeList = pass.freeTemps[ty.getSingle()];
assert(std::find(freeList.begin(), freeList.end(), idx) ==
freeList.end());
freeList.push_back(idx);
Expand Down Expand Up @@ -1459,7 +1459,7 @@ struct I64ToI32Lowering : public WalkerPass<PostWalker<I64ToI32Lowering>> {

TempVar getTemp(Type ty = Type::i32) {
Index ret;
auto& freeList = freeTemps[(int)ty];
auto& freeList = freeTemps[ty.getSingle()];
if (freeList.size() > 0) {
ret = freeList.back();
freeList.pop_back();
Expand Down
4 changes: 2 additions & 2 deletions src/passes/InstrumentLocals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {
void visitLocalGet(LocalGet* curr) {
Builder builder(*getModule());
Name import;
switch (curr->type) {
switch (curr->type.getSingle()) {
case Type::i32:
import = get_i32;
break;
Expand Down Expand Up @@ -122,7 +122,7 @@ struct InstrumentLocals : public WalkerPass<PostWalker<InstrumentLocals>> {

Builder builder(*getModule());
Name import;
switch (curr->value->type) {
switch (curr->value->type.getSingle()) {
case Type::i32:
import = set_i32;
break;
Expand Down
4 changes: 2 additions & 2 deletions src/passes/InstrumentMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
curr->ptr},
Type::i32);
Name target;
switch (curr->type) {
switch (curr->type.getSingle()) {
case Type::i32:
target = load_val_i32;
break;
Expand Down Expand Up @@ -117,7 +117,7 @@ struct InstrumentMemory : public WalkerPass<PostWalker<InstrumentMemory>> {
curr->ptr},
Type::i32);
Name target;
switch (curr->value->type) {
switch (curr->value->type.getSingle()) {
case Type::i32:
target = store_val_i32;
break;
Expand Down
Loading