Skip to content

Commit

Permalink
Remove synchronous invocations from Swift (#2627)
Browse files Browse the repository at this point in the history
  • Loading branch information
externl authored Aug 7, 2024
1 parent adccd6b commit f7aac56
Show file tree
Hide file tree
Showing 68 changed files with 1,563 additions and 4,569 deletions.
8 changes: 4 additions & 4 deletions cpp/src/slice2swift/Gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1128,10 +1128,11 @@ Gen::ProxyVisitor::visitInterfaceDefStart(const InterfaceDefPtr& p)
out << nl << "/// - throws: `Ice.LocalException` if a communication error occurs.";
out << nl << "public func checkedCast" << spar << ("prx: " + getUnqualified("Ice.ObjectPrx", swiftModule))
<< ("type: " + prx + ".Protocol") << ("facet: Swift.String? = nil")
<< ("context: " + getUnqualified("Ice.Context", swiftModule) + "? = nil") << epar << " throws -> " << prx
<< ("context: " + getUnqualified("Ice.Context", swiftModule) + "? = nil") << epar << " async throws -> " << prx
<< "?";
out << sb;
out << nl << "return try " << prxI << ".checkedCast(prx: prx, facet: facet, context: context) as " << prxI << "?";
out << nl << "return try await " << prxI << ".checkedCast(prx: prx, facet: facet, context: context) as " << prxI
<< "?";
out << eb;

//
Expand Down Expand Up @@ -1218,7 +1219,6 @@ void
Gen::ProxyVisitor::visitOperation(const OperationPtr& op)
{
writeProxyOperation(out, op);
writeProxyAsyncOperation(out, op);
}

Gen::ValueVisitor::ValueVisitor(::IceInternal::Output& o) : out(o) {}
Expand Down Expand Up @@ -1518,7 +1518,7 @@ Gen::ObjectVisitor::visitOperation(const OperationPtr& op)
const ExceptionList allExceptions = op->throws();

out << sp;
writeOpDocSummary(out, op, true, true);
writeOpDocSummary(out, op, true);
out << nl << "func " << opName;
out << spar;
for (ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q)
Expand Down
175 changes: 41 additions & 134 deletions cpp/src/slice2swift/SwiftUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ SwiftGenerator::splitComment(const string& c)
string comment = c;

//
// TODO: this comment is suspicious. Does this apply to Swift docs as well?
// Strip HTML markup and javadoc links -- MATLAB doesn't display them.
//
string::size_type pos = 0;
Expand Down Expand Up @@ -662,7 +663,7 @@ SwiftGenerator::writeDocSummary(IceInternal::Output& out, const ContainedPtr& p)
}

void
SwiftGenerator::writeOpDocSummary(IceInternal::Output& out, const OperationPtr& p, bool async, bool dispatch)
SwiftGenerator::writeOpDocSummary(IceInternal::Output& out, const OperationPtr& p, bool dispatch)
{
DocElements doc = parseComment(p);
if (!doc.overview.empty())
Expand Down Expand Up @@ -708,71 +709,63 @@ SwiftGenerator::writeOpDocSummary(IceInternal::Output& out, const OperationPtr&

typeCtx = 0;

if (async)
const ParamInfoList allOutParams = getAllOutParams(p, typeCtx);
if (allOutParams.size() == 1)
{
ParamInfo ret = allOutParams.front();
out << nl << "///";
out << nl << "/// - returns: `" << operationReturnType(p, typeCtx) << "` - The result of the operation";
}
else
{
const ParamInfoList allOutParams = getAllOutParams(p, typeCtx);
if (allOutParams.size() == 1)
out << nl << "/// - returns: `" << ret.typeStr << "`";
if (p->returnType())
{
ParamInfo ret = allOutParams.front();
out << nl << "///";
out << nl << "/// - returns: `" << ret.typeStr << "`";
if (p->returnType())
if (!doc.returns.empty())
{
if (!doc.returns.empty())
{
out << " - ";
writeDocLines(out, doc.returns, false);
}
out << " - ";
writeDocLines(out, doc.returns, false);
}
else
}
else
{
map<string, StringList>::const_iterator r = doc.params.find(ret.name);
if (r != doc.params.end() && !r->second.empty())
{
map<string, StringList>::const_iterator r = doc.params.find(ret.name);
if (r != doc.params.end() && !r->second.empty())
{
out << " - ";
writeDocLines(out, r->second, false);
}
out << " - ";
writeDocLines(out, r->second, false);
}
}
else if (allOutParams.size() > 1)
}
else if (allOutParams.size() > 1)
{
out << nl << "///";
out << nl << "/// - returns: `" << operationReturnType(p, typeCtx) << "`:";
if (p->returnType())
{
ParamInfo ret = allOutParams.back();
out << nl << "///";
out << nl << "/// - returns: `" << operationReturnType(p, typeCtx) << "`:";
if (p->returnType())
out << nl << "/// - " << ret.name << ": `" << ret.typeStr << "`";
if (!doc.returns.empty())
{
ParamInfo ret = allOutParams.back();
out << nl << "///";
out << nl << "/// - " << ret.name << ": `" << ret.typeStr << "`";
if (!doc.returns.empty())
{
out << " - ";
writeDocLines(out, doc.returns, false);
}
out << " - ";
writeDocLines(out, doc.returns, false);
}
}

for (ParamInfoList::const_iterator q = allOutParams.begin(); q != allOutParams.end(); ++q)
for (ParamInfoList::const_iterator q = allOutParams.begin(); q != allOutParams.end(); ++q)
{
if (q->param != 0)
{
if (q->param != 0)
out << nl << "///";
out << nl << "/// - " << q->name << ": `" << q->typeStr << "`";
map<string, StringList>::const_iterator r = doc.params.find(q->name);
if (r != doc.params.end() && !r->second.empty())
{
out << nl << "///";
out << nl << "/// - " << q->name << ": `" << q->typeStr << "`";
map<string, StringList>::const_iterator r = doc.params.find(q->name);
if (r != doc.params.end() && !r->second.empty())
{
out << " - ";
writeDocLines(out, r->second, false);
}
out << " - ";
writeDocLines(out, r->second, false);
}
}
}
}

if (!doc.exceptions.empty() && !async)
if (!doc.exceptions.empty())
{
out << nl << "///";
out << nl << "/// - throws:";
Expand Down Expand Up @@ -2374,93 +2367,7 @@ SwiftGenerator::writeProxyOperation(::IceInternal::Output& out, const OperationP
const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(op)));

out << sp;
writeOpDocSummary(out, op, false, false);
out << nl << "func " << opName;
out << spar;
for (ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q)
{
if (allInParams.size() == 1)
{
out << ("_ iceP_" + q->name + ": " + q->typeStr + (q->optional ? " = nil" : ""));
}
else
{
out << (q->name + " iceP_" + q->name + ": " + q->typeStr + (q->optional ? " = nil" : ""));
}
}
out << ("context: " + getUnqualified("Ice.Context", swiftModule) + "? = nil");

out << epar;
out << " throws";

if (allOutParams.size() > 0)
{
out << " -> " << operationReturnType(op);
}

out << sb;

//
// Invoke
//
out << sp;
out << nl;
if (allOutParams.size() > 0)
{
out << "return ";
}
out << "try _impl._invoke(";

out.useCurrentPosAsIndent();
out << "operation: \"" << op->name() << "\",";
out << nl << "mode: " << modeToString(op->mode()) << ",";

if (op->format())
{
out << nl << "format: " << opFormatTypeToString(op);
out << ",";
}

if (allInParams.size() > 0)
{
out << nl << "write: ";
writeMarshalInParams(out, op);
out << ",";
}

if (allOutParams.size() > 0)
{
out << nl << "read: ";
writeUnmarshalOutParams(out, op);
out << ",";
}

if (allExceptions.size() > 0)
{
out << nl << "userException:";
writeUnmarshalUserException(out, op);
out << ",";
}

out << nl << "context: context)";
out.restoreIndent();

out << eb;
}

void
SwiftGenerator::writeProxyAsyncOperation(::IceInternal::Output& out, const OperationPtr& op)
{
const string opName = fixIdent(op->name() + "Async");

const ParamInfoList allInParams = getAllInParams(op);
const ParamInfoList allOutParams = getAllOutParams(op);
const ExceptionList allExceptions = op->throws();

const string swiftModule = getSwiftModule(getTopLevelModule(dynamic_pointer_cast<Contained>(op)));

out << sp;
writeOpDocSummary(out, op, true, false);
writeOpDocSummary(out, op, false);
out << nl << "func " << opName;
out << spar;
for (ParamInfoList::const_iterator q = allInParams.begin(); q != allInParams.end(); ++q)
Expand Down Expand Up @@ -2492,7 +2399,7 @@ SwiftGenerator::writeProxyAsyncOperation(::IceInternal::Output& out, const Opera
// Invoke
//
out << sp;
out << nl << "return try await _impl._invokeAsync(";
out << nl << "return try await _impl._invoke(";

out.useCurrentPosAsIndent();
out << "operation: \"" << op->name() << "\",";
Expand Down
3 changes: 1 addition & 2 deletions cpp/src/slice2swift/SwiftUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace Slice
void writeDocSentence(IceInternal::Output&, const StringList&);
void writeSeeAlso(IceInternal::Output&, const StringList&, const ContainerPtr&);
void writeDocSummary(IceInternal::Output&, const ContainedPtr&);
void writeOpDocSummary(IceInternal::Output&, const OperationPtr&, bool, bool);
void writeOpDocSummary(IceInternal::Output&, const OperationPtr&, bool);

void writeProxyDocSummary(IceInternal::Output&, const InterfaceDefPtr&, const std::string&);
void writeServantDocSummary(IceInternal::Output&, const InterfaceDefPtr&, const std::string&);
Expand Down Expand Up @@ -148,7 +148,6 @@ namespace Slice
void writeUnmarshalUserException(::IceInternal::Output& out, const OperationPtr&);
void writeSwiftAttributes(::IceInternal::Output&, const StringList&);
void writeProxyOperation(::IceInternal::Output&, const OperationPtr&);
void writeProxyAsyncOperation(::IceInternal::Output&, const OperationPtr&);
void writeDispatchOperation(::IceInternal::Output&, const OperationPtr&);

private:
Expand Down
Loading

0 comments on commit f7aac56

Please sign in to comment.