Skip to content

Commit 940f457

Browse files
authored
Remove redundant ptrType from MemorySize/Grow instructions. NFC (#6590)
I recently add TableSize/Grow and noticed I didn't need these. It seems they are superfluous.
1 parent 140386e commit 940f457

File tree

8 files changed

+9
-26
lines changed

8 files changed

+9
-26
lines changed

src/passes/Memory64Lowering.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
7070
if (memory->is64()) {
7171
auto size = static_cast<Expression*>(curr);
7272
extendAddress64(size, curr->memory);
73-
curr->ptrType = Type::i32;
73+
curr->type = Type::i32;
7474
replaceCurrent(size);
7575
}
7676
}
@@ -82,7 +82,7 @@ struct Memory64Lowering : public WalkerPass<PostWalker<Memory64Lowering>> {
8282
wrapAddress64(curr->delta, curr->memory);
8383
auto size = static_cast<Expression*>(curr);
8484
extendAddress64(size, curr->memory);
85-
curr->ptrType = Type::i32;
85+
curr->type = Type::i32;
8686
replaceCurrent(size);
8787
}
8888
}

src/wasm-builder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ class Builder {
666666
MemoryInfo info = MemoryInfo::Unspecified) {
667667
auto* ret = wasm.allocator.alloc<MemorySize>();
668668
if (isMemory64(memoryName, info)) {
669-
ret->make64();
669+
ret->type = Type::i64;
670670
}
671671
ret->memory = memoryName;
672672
ret->finalize();
@@ -677,7 +677,7 @@ class Builder {
677677
MemoryInfo info = MemoryInfo::Unspecified) {
678678
auto* ret = wasm.allocator.alloc<MemoryGrow>();
679679
if (isMemory64(memoryName, info)) {
680-
ret->make64();
680+
ret->type = Type::i64;
681681
}
682682
ret->delta = delta;
683683
ret->memory = memoryName;

src/wasm-delegations-fields.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,12 +485,10 @@ DELEGATE_FIELD_OPTIONAL_CHILD(Return, value)
485485
DELEGATE_FIELD_CASE_END(Return)
486486

487487
DELEGATE_FIELD_CASE_START(MemorySize)
488-
DELEGATE_FIELD_TYPE(MemorySize, ptrType)
489488
DELEGATE_FIELD_NAME_KIND(MemorySize, memory, ModuleItemKind::Memory)
490489
DELEGATE_FIELD_CASE_END(MemorySize)
491490

492491
DELEGATE_FIELD_CASE_START(MemoryGrow)
493-
DELEGATE_FIELD_TYPE(MemoryGrow, ptrType)
494492
DELEGATE_FIELD_CHILD(MemoryGrow, delta)
495493
DELEGATE_FIELD_NAME_KIND(MemoryGrow, memory, ModuleItemKind::Memory)
496494
DELEGATE_FIELD_CASE_END(MemoryGrow)

src/wasm.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,10 +1305,8 @@ class MemorySize : public SpecificExpression<Expression::MemorySizeId> {
13051305
MemorySize() { type = Type::i32; }
13061306
MemorySize(MixedArena& allocator) : MemorySize() {}
13071307

1308-
Type ptrType = Type::i32;
13091308
Name memory;
13101309

1311-
void make64();
13121310
void finalize();
13131311
};
13141312

@@ -1318,10 +1316,8 @@ class MemoryGrow : public SpecificExpression<Expression::MemoryGrowId> {
13181316
MemoryGrow(MixedArena& allocator) : MemoryGrow() {}
13191317

13201318
Expression* delta = nullptr;
1321-
Type ptrType = Type::i32;
13221319
Name memory;
13231320

1324-
void make64();
13251321
void finalize();
13261322
};
13271323

src/wasm/wasm-binary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6882,7 +6882,7 @@ void WasmBinaryReader::visitMemorySize(MemorySize* curr) {
68826882
BYN_TRACE("zz node: MemorySize\n");
68836883
Index index = getU32LEB();
68846884
if (getMemory(index)->is64()) {
6885-
curr->make64();
6885+
curr->type = Type::i64;
68866886
}
68876887
curr->finalize();
68886888
memoryRefs[index].push_back(&curr->memory);
@@ -6893,7 +6893,7 @@ void WasmBinaryReader::visitMemoryGrow(MemoryGrow* curr) {
68936893
curr->delta = popNonVoidExpression();
68946894
Index index = getU32LEB();
68956895
if (getMemory(index)->is64()) {
6896-
curr->make64();
6896+
curr->type = Type::i64;
68976897
}
68986898
memoryRefs[index].push_back(&curr->memory);
68996899
}

src/wasm/wasm-s-parser.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1537,7 +1537,7 @@ Expression* SExpressionWasmBuilder::makeMemorySize(Element& s) {
15371537
}
15381538
ret->memory = memory;
15391539
if (isMemory64(memory)) {
1540-
ret->make64();
1540+
ret->type = Type::i64;
15411541
}
15421542
ret->finalize();
15431543
return ret;
@@ -1554,7 +1554,7 @@ Expression* SExpressionWasmBuilder::makeMemoryGrow(Element& s) {
15541554
}
15551555
ret->memory = memory;
15561556
if (isMemory64(memory)) {
1557-
ret->make64();
1557+
ret->type = Type::i64;
15581558
}
15591559
ret->delta = parseExpression(s[i]);
15601560
ret->finalize();

src/wasm/wasm.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -789,15 +789,11 @@ void Drop::finalize() {
789789
}
790790
}
791791

792-
void MemorySize::make64() { type = ptrType = Type::i64; }
793-
void MemorySize::finalize() { type = ptrType; }
792+
void MemorySize::finalize() {}
794793

795-
void MemoryGrow::make64() { type = ptrType = Type::i64; }
796794
void MemoryGrow::finalize() {
797795
if (delta->type == Type::unreachable) {
798796
type = Type::unreachable;
799-
} else {
800-
type = ptrType;
801797
}
802798
}
803799

test/binaryen.js/expressions.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -482,11 +482,7 @@ console.log("# MemorySize");
482482
assert(theMemorySize instanceof binaryen.MemorySize);
483483
assert(theMemorySize instanceof binaryen.Expression);
484484
assert(theMemorySize.type === type);
485-
486-
theMemorySize.type = type = binaryen.f64;
487-
assert(theMemorySize.type === type);
488485
theMemorySize.finalize();
489-
assert(theMemorySize.type === binaryen.i32);
490486

491487
console.log(theMemorySize.toText());
492488
assert(
@@ -513,10 +509,7 @@ console.log("# MemoryGrow");
513509

514510
theMemoryGrow.delta = delta = module.i32.const(2);
515511
assert(theMemoryGrow.delta === delta);
516-
theMemoryGrow.type = type = binaryen.f64;
517-
assert(theMemoryGrow.type === type);
518512
theMemoryGrow.finalize();
519-
assert(theMemoryGrow.type === binaryen.i32);
520513

521514
console.log(theMemoryGrow.toText());
522515
assert(

0 commit comments

Comments
 (0)