Skip to content

[WASM] Fix KeyPath optimization bug around signature match #1709

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
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: 4 additions & 0 deletions lib/IRGen/GenKeyPath.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,10 @@ getAccessorForComputedComponent(IRGenModule &IGM,
forwardingSubs,
&ignoreWitnessMetadata,
forwardedArgs);
} else if (IGM.Triple.isOSBinFormatWasm()) {
// wasm: Add null swift.type pointer to match signature even when there is
// no generic environment.
forwardedArgs.add(llvm::ConstantPointerNull::get(IGM.TypeMetadataPtrTy));
}
auto fnPtr = FunctionPointer::forDirect(IGM, accessorFn,
accessor->getLoweredFunctionType());
Expand Down
17 changes: 16 additions & 1 deletion lib/SILOptimizer/Utils/KeyPathProjector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,22 @@ class GettablePropertyProjector : public ComponentProjector {
assert(getter->getArguments().size() == 2 + target.isOSBinFormatWasm());

auto ref = builder.createFunctionRef(loc, getter);
builder.createApply(loc, ref, subs, {addr, parentValue});

std::vector<SILValue> args{addr, parentValue};
// FIXME(wasm): For wasm, KeyPath getter always take indices parameter
// to match callee and caller signature. So need to pass stub pointer.
// See also: getOrCreateKeyPathSetter and getOrCreateKeyPathGetter
if (builder.getASTContext().LangOpts.Target.isOSBinFormatWasm()) {
auto IntTy = SILType::getBuiltinIntegerType(32, builder.getASTContext());
auto UnsafeRawPointerTy = SILType::getRawPointerType(builder.getASTContext());
auto zeroVal = SILValue(builder.createIntegerLiteral(loc, IntTy, 0));
auto stackBuffer = SILValue(builder.createAllocStack(loc, IntTy));
builder.createStore(loc, zeroVal, stackBuffer, StoreOwnershipQualifier::Unqualified);
auto nonePointer = builder.createUncheckedAddrCast(loc, stackBuffer, UnsafeRawPointerTy);
args.push_back(SILValue(nonePointer));
}

builder.createApply(loc, ref, subs, args);

// If we were previously accessing a class member, we're done now.
insertEndAccess(beginAccess, builder);
Expand Down