Skip to content

Commit 328dd9e

Browse files
Jeremy Lilleyfacebook-github-bot
authored andcommitted
[future] Make new IValue future constValue semantics match torch::utils counterpart (#38355)
Summary: Pull Request resolved: #38355 The torch::utils::Future api which this api was copied from last week intentionally does not throw. Harmonize the semantics and comment appropriately. ghstack-source-id: 104014210 Test Plan: buck test mode/dev-nosan caffe2/test/... Differential Revision: D21533016 fbshipit-source-id: db26af32656d7b9dacf4fad4e77c944a0087c9b0
1 parent b668bbc commit 328dd9e

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

aten/src/ATen/core/ivalue_inl.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,12 +310,11 @@ struct C10_EXPORT ivalue::Future final : c10::intrusive_ptr_target {
310310
return value_;
311311
}
312312

313+
// This accessor should only be used if we know that the future is
314+
// completed() with no error.
313315
const IValue& constValue() {
314316
std::unique_lock<std::mutex> lock(mutex_);
315317
AT_ASSERT(completed());
316-
if (error_) {
317-
throw *error_;
318-
}
319318
return value_;
320319
}
321320

torch/csrc/distributed/rpc/rref_impl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ RRefForkData UserRRef::fork() const {
203203

204204
const IValue& OwnerRRef::getValue() const {
205205
future_->wait();
206+
if (future_->hasError()) {
207+
(void)future_->value(); // Throws the error.
208+
}
206209
return future_->constValue();
207210
}
208211

torch/csrc/utils/future.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ class TORCH_API Future final {
4747
return value_;
4848
}
4949

50+
// These constValue/moveValue accessors should only be used if
51+
// we know that the future is completed() with no error.
5052
const T& constValue() const {
5153
std::unique_lock<std::mutex> lock(mutex_);
5254
AT_ASSERT(completed_);

0 commit comments

Comments
 (0)