Skip to content

Commit 04fb2bf

Browse files
[SYCL] Remove exception ctors referencing std::string from ABI boundary (#13560)
This PR ABI-neutralize some exception ctors that require context objects. However, #include <sycl/context.hpp> caused a cyclic dependency issue. So, moving them into context.hpp solved the issue. --------- Signed-off-by: Byoungro So <[email protected]> Co-authored-by: Andrei Elovikov <[email protected]>
1 parent 15c9c62 commit 04fb2bf

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

sycl/include/sycl/context.hpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,35 @@ class __SYCL_EXPORT context : public detail::OwnerLessBase<context> {
259259
friend T detail::createSyclObjFromImpl(decltype(T::impl) ImplObj);
260260
};
261261

262+
#ifdef __INTEL_PREVIEW_BREAKING_CHANGES
263+
// context.hpp depends on exception.hpp but we can't define these ctors in
264+
// exception.hpp while context is still an incomplete type.
265+
inline exception::exception(context Ctx, std::error_code EC,
266+
const std::string &WhatArg)
267+
: exception(EC, std::make_shared<context>(Ctx), WhatArg) {}
268+
269+
inline exception::exception(context Ctx, std::error_code EC,
270+
const char *WhatArg)
271+
: exception(Ctx, EC, std::string(WhatArg)) {}
272+
273+
inline exception::exception(context Ctx, std::error_code EC)
274+
: exception(Ctx, EC, "") {}
275+
276+
inline exception::exception(context Ctx, int EV,
277+
const std::error_category &ECat,
278+
const char *WhatArg)
279+
: exception(Ctx, {EV, ECat}, std::string(WhatArg)) {}
280+
281+
inline exception::exception(context Ctx, int EV,
282+
const std::error_category &ECat,
283+
const std::string &WhatArg)
284+
: exception(Ctx, {EV, ECat}, WhatArg) {}
285+
286+
inline exception::exception(context Ctx, int EV,
287+
const std::error_category &ECat)
288+
: exception(Ctx, EV, ECat, "") {}
289+
#endif
290+
262291
} // namespace _V1
263292
} // namespace sycl
264293

sycl/include/sycl/exception.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ class __SYCL_EXPORT exception : public virtual std::exception {
8787
exception(int, const std::error_category &, const char *);
8888
exception(int, const std::error_category &);
8989

90+
// context.hpp depends on exception.hpp but we can't define these ctors in
91+
// exception.hpp while context is still an incomplete type.
92+
// So, definition of ctors that require a context parameter are moved to
93+
// context.hpp.
9094
exception(context, std::error_code, const std::string &);
9195
exception(context, std::error_code, const char *);
9296
exception(context, std::error_code);

sycl/source/exception.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ exception::exception(int EV, const std::error_category &ECat,
2929
exception::exception(int EV, const std::error_category &ECat)
3030
: exception({EV, ECat}, nullptr, "") {}
3131

32+
#ifndef __INTEL_PREVIEW_BREAKING_CHANGES
3233
exception::exception(context Ctx, std::error_code EC,
3334
const std::string &WhatArg)
3435
: exception(EC, std::make_shared<context>(Ctx), WhatArg) {}
@@ -49,6 +50,7 @@ exception::exception(context Ctx, int EV, const std::error_category &ECat,
4950

5051
exception::exception(context Ctx, int EV, const std::error_category &ECat)
5152
: exception(Ctx, EV, ECat, "") {}
53+
#endif
5254

5355
// protected base constructor for all SYCL 2020 constructors
5456
exception::exception(std::error_code EC, std::shared_ptr<context> SharedPtrCtx,

0 commit comments

Comments
 (0)