Skip to content

Commit

Permalink
Backed out 4 changesets (bug 1790626) for causing spider-monkey failu…
Browse files Browse the repository at this point in the history
…res in js/src/wasm/WasmTypeDef.h CLOSED TREE

Backed out changeset 81ed136e034e (bug 1790626)
Backed out changeset 955d80c9d75c (bug 1790626)
Backed out changeset cc0a57db46c0 (bug 1790626)
Backed out changeset 91bfaab095a5 (bug 1790626)
  • Loading branch information
Sandor Molnar committed Oct 18, 2022
1 parent 4a64b9a commit 2395049
Show file tree
Hide file tree
Showing 41 changed files with 1,092 additions and 1,055 deletions.
9 changes: 4 additions & 5 deletions js/src/jit/CodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12814,7 +12814,7 @@ static bool CreateStackMapFromLSafepoint(LSafepoint& safepoint,
}

bool CodeGenerator::generateWasm(
wasm::CallIndirectId callIndirectId, wasm::BytecodeOffset trapOffset,
wasm::TypeIdDesc funcTypeId, wasm::BytecodeOffset trapOffset,
const wasm::ArgTypeVector& argTypes, const RegisterOffsets& trapExitLayout,
size_t trapExitLayoutNumWords, wasm::FuncOffsets* offsets,
wasm::StackMaps* stackMaps, wasm::Decoder* decoder) {
Expand All @@ -12824,8 +12824,7 @@ bool CodeGenerator::generateWasm(

size_t nInboundStackArgBytes = StackArgAreaSizeUnaligned(argTypes);

wasm::GenerateFunctionPrologue(masm, callIndirectId, mozilla::Nothing(),
offsets);
wasm::GenerateFunctionPrologue(masm, funcTypeId, mozilla::Nothing(), offsets);

MOZ_ASSERT(masm.framePushed() == 0);

Expand Down Expand Up @@ -17313,7 +17312,7 @@ void CodeGenerator::emitIonToWasmCallBase(LIonToWasmCallBase<NumDefs>* lir) {
break;
case wasm::RefType::Func:
case wasm::RefType::Eq:
case wasm::RefType::TypeRef:
case wasm::RefType::TypeIndex:
MOZ_CRASH("unexpected argument type when calling from ion to wasm");
}
break;
Expand Down Expand Up @@ -17390,7 +17389,7 @@ void CodeGenerator::emitIonToWasmCallBase(LIonToWasmCallBase<NumDefs>* lir) {
// API to do so.
MOZ_ASSERT(lir->mir()->type() == MIRType::Value);
break;
case wasm::RefType::TypeRef:
case wasm::RefType::TypeIndex:
MOZ_CRASH("unexpected return type when calling from ion to wasm");
}
break;
Expand Down
2 changes: 1 addition & 1 deletion js/src/jit/CodeGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class CodeGenerator final : public CodeGeneratorSpecific {

[[nodiscard]] bool generate();
[[nodiscard]] bool generateWasm(
wasm::CallIndirectId callIndirectId, wasm::BytecodeOffset trapOffset,
wasm::TypeIdDesc funcTypeId, wasm::BytecodeOffset trapOffset,
const wasm::ArgTypeVector& argTys, const RegisterOffsets& trapExitLayout,
size_t trapExitLayoutNumWords, wasm::FuncOffsets* offsets,
wasm::StackMaps* stackMaps, wasm::Decoder* decoder);
Expand Down
14 changes: 7 additions & 7 deletions js/src/jit/MacroAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3958,15 +3958,15 @@ void MacroAssembler::wasmCallIndirect(const wasm::CallSiteDesc& desc,

// Write the functype-id into the ABI functype-id register.

const wasm::CallIndirectId callIndirectId = callee.wasmTableSigId();
switch (callIndirectId.kind()) {
case wasm::CallIndirectIdKind::Global:
loadWasmGlobalPtr(callIndirectId.globalDataOffset(), WasmTableCallSigReg);
const wasm::TypeIdDesc funcTypeId = callee.wasmTableSigId();
switch (funcTypeId.kind()) {
case wasm::TypeIdDescKind::Global:
loadWasmGlobalPtr(funcTypeId.globalDataOffset(), WasmTableCallSigReg);
break;
case wasm::CallIndirectIdKind::Immediate:
move32(Imm32(callIndirectId.immediate()), WasmTableCallSigReg);
case wasm::TypeIdDescKind::Immediate:
move32(Imm32(funcTypeId.immediate()), WasmTableCallSigReg);
break;
case wasm::CallIndirectIdKind::None:
case wasm::TypeIdDescKind::None:
break;
}

Expand Down
42 changes: 20 additions & 22 deletions js/src/wasm/AsmJS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1941,18 +1941,14 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared {
}

*sigIndex = moduleEnv_.types->length();
MutableTypeDef typeDef = moduleEnv_.types->addType();
if (!typeDef) {
return false;
}
*typeDef = std::move(sig);
return true;
return moduleEnv_.types->append(std::move(sig)) &&
moduleEnv_.typeIds.append(TypeIdDesc());
}
bool declareSig(FuncType&& sig, uint32_t* sigIndex) {
SigSet::AddPtr p = sigSet_.lookupForAdd(sig);
if (p) {
*sigIndex = p->sigIndex();
MOZ_ASSERT(moduleEnv_.types->type(*sigIndex).funcType() == sig);
MOZ_ASSERT(moduleEnv_.types->funcType(*sigIndex) == sig);
return true;
}

Expand Down Expand Up @@ -2133,15 +2129,17 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared {
uint32_t funcIndex = r.front().value();
uint32_t funcTypeIndex = r.front().key().sigIndex();
MOZ_ASSERT(!moduleEnv_.funcs[funcIndex].type);
moduleEnv_.funcs[funcIndex] = FuncDesc(
&moduleEnv_.types->type(funcTypeIndex).funcType(), funcTypeIndex);
moduleEnv_.funcs[funcIndex] =
FuncDesc(&moduleEnv_.types->funcType(funcTypeIndex),
&moduleEnv_.typeIds[funcTypeIndex], funcTypeIndex);
}
for (const Func& func : funcDefs_) {
uint32_t funcIndex = funcImportMap_.count() + func.funcDefIndex();
uint32_t funcTypeIndex = func.sigIndex();
MOZ_ASSERT(!moduleEnv_.funcs[funcIndex].type);
moduleEnv_.funcs[funcIndex] = FuncDesc(
&moduleEnv_.types->type(funcTypeIndex).funcType(), funcTypeIndex);
moduleEnv_.funcs[funcIndex] =
FuncDesc(&moduleEnv_.types->funcType(funcTypeIndex),
&moduleEnv_.typeIds[funcTypeIndex], funcTypeIndex);
}
for (const Export& exp : moduleEnv_.exports) {
if (exp.kind() != DefinitionKind::Function) {
Expand All @@ -2152,7 +2150,10 @@ class MOZ_STACK_CLASS ModuleValidator : public ModuleValidatorShared {
/* canRefFunc */ false);
}

moduleEnv_.numFuncImports = funcImportMap_.count();
if (!moduleEnv_.funcImportGlobalDataOffsets.resize(
funcImportMap_.count())) {
return nullptr;
}

MOZ_ASSERT(asmJSMetadata_->asmJSFuncNames.empty());
if (!asmJSMetadata_->asmJSFuncNames.resize(funcImportMap_.count())) {
Expand Down Expand Up @@ -4041,8 +4042,7 @@ static bool CheckFunctionSignature(ModuleValidator<Unit>& m, ParseNode* usepn,
return m.addFuncDef(name, usepn->pn_pos.begin, std::move(sig), func);
}

const FuncType& existingSig =
m.env().types->type(existing->sigIndex()).funcType();
const FuncType& existingSig = m.env().types->funcType(existing->sigIndex());

if (!CheckSignatureAgainstExisting(m, usepn, sig, existingSig)) {
return false;
Expand Down Expand Up @@ -4116,7 +4116,7 @@ static bool CheckFuncPtrTableAgainstExisting(ModuleValidator<Unit>& m,
}

if (!CheckSignatureAgainstExisting(
m, usepn, sig, m.env().types->type(table.sigIndex()).funcType())) {
m, usepn, sig, m.env().types->funcType(table.sigIndex()))) {
return false;
}

Expand Down Expand Up @@ -5954,8 +5954,7 @@ static bool CheckReturnType(FunctionValidatorShared& f, ParseNode* usepn,

if (f.returnedType() != type) {
return f.failf(usepn, "%s incompatible with previous return of type %s",
ToString(type, nullptr).get(),
ToString(f.returnedType(), nullptr).get());
ToString(type).get(), ToString(f.returnedType()).get());
}

return true;
Expand Down Expand Up @@ -6186,11 +6185,10 @@ static bool CheckFunction(ModuleValidator<Unit>& m) {
}
}

FuncType sig(std::move(args), std::move(results));

ModuleValidatorShared::Func* func = nullptr;
if (!CheckFunctionSignature(m, funNode, std::move(sig), FunctionName(funNode),
&func)) {
if (!CheckFunctionSignature(m, funNode,
FuncType(std::move(args), std::move(results)),
FunctionName(funNode), &func)) {
return false;
}

Expand Down Expand Up @@ -6281,7 +6279,7 @@ static bool CheckFuncPtrTable(ModuleValidator<Unit>& m, ParseNode* decl) {
elem, "function-pointer table's elements must be names of functions");
}

const FuncType& funcSig = m.env().types->type(func->sigIndex()).funcType();
const FuncType& funcSig = m.env().types->funcType(func->sigIndex());
if (sig) {
if (*sig != funcSig) {
return m.fail(elem, "all functions in table must have same signature");
Expand Down
4 changes: 4 additions & 0 deletions js/src/wasm/WasmBCClass-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const FuncType& BaseCompiler::funcType() const {
return *moduleEnv_.funcs[func_.index].type;
}

const TypeIdDesc& BaseCompiler::funcTypeId() const {
return *moduleEnv_.funcs[func_.index].typeId;
}

bool BaseCompiler::usesMemory() const { return moduleEnv_.usesMemory(); }

bool BaseCompiler::usesSharedMemory() const {
Expand Down
1 change: 1 addition & 0 deletions js/src/wasm/WasmBCClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ struct BaseCompiler final {
// WasmBaselineObject-inl.h.

inline const FuncType& funcType() const;
inline const TypeIdDesc& funcTypeId() const;
inline bool usesMemory() const;
inline bool usesSharedMemory() const;
inline bool isMem32() const;
Expand Down
14 changes: 7 additions & 7 deletions js/src/wasm/WasmBaselineCompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ bool BaseCompiler::beginFunction() {
}

GenerateFunctionPrologue(
masm, CallIndirectId::forFunc(moduleEnv_, func_.index),
masm, *moduleEnv_.funcs[func_.index].typeId,
compilerEnv_.mode() == CompileMode::Tier1 ? Some(func_.index) : Nothing(),
&offsets_);

Expand Down Expand Up @@ -1574,16 +1574,15 @@ bool BaseCompiler::callIndirect(uint32_t funcTypeIndex, uint32_t tableIndex,
const Stk& indexVal, const FunctionCall& call,
CodeOffset* fastCallOffset,
CodeOffset* slowCallOffset) {
CallIndirectId callIndirectId =
CallIndirectId::forFuncType(moduleEnv_, funcTypeIndex);
MOZ_ASSERT(callIndirectId.kind() != CallIndirectIdKind::None);
const TypeIdDesc& funcTypeId = moduleEnv_.typeIds[funcTypeIndex];
MOZ_ASSERT(funcTypeId.kind() != TypeIdDescKind::None);

const TableDesc& table = moduleEnv_.tables[tableIndex];

loadI32(indexVal, RegI32(WasmTableCallIndexReg));

CallSiteDesc desc(bytecodeOffset(), CallSiteDesc::Indirect);
CalleeDesc callee = CalleeDesc::wasmTable(table, callIndirectId);
CalleeDesc callee = CalleeDesc::wasmTable(table, funcTypeId);
OutOfLineCode* oob = addOutOfLineCode(
new (alloc_) OutOfLineAbortingTrap(Trap::OutOfBounds, bytecodeOffset()));
if (!oob) {
Expand Down Expand Up @@ -4707,7 +4706,7 @@ bool BaseCompiler::emitCall() {

CodeOffset raOffset;
if (import) {
raOffset = callImport(moduleEnv_.offsetOfFuncImportInstanceData(funcIndex),
raOffset = callImport(moduleEnv_.funcImportGlobalDataOffsets[funcIndex],
baselineCall);
} else {
raOffset = callDefinition(funcIndex, baselineCall);
Expand Down Expand Up @@ -6306,11 +6305,12 @@ void BaseCompiler::emitBarrieredClear(RegPtr valueAddr) {
#ifdef ENABLE_WASM_GC

void BaseCompiler::emitGcCanon(uint32_t typeIndex) {
const TypeIdDesc& typeId = moduleEnv_.typeIds[typeIndex];
RegRef rp = needRef();
# ifndef RABALDR_PIN_INSTANCE
fr.loadInstancePtr(InstanceReg);
# endif
masm.loadWasmGlobalPtr(moduleEnv_.offsetOfTypeId(typeIndex), rp);
masm.loadWasmGlobalPtr(typeId.globalDataOffset(), rp);
pushRef(rp);
}

Expand Down
Loading

0 comments on commit 2395049

Please sign in to comment.