pytorch/torch/csrc/jit/frontend/source_ref.h
Han Qi 0723639b60 Revert D34455360: Multisect successfully blamed D34455360 for test failures
Summary:
This diff is reverting D34455360 (61d6c43864)
D34455360 (61d6c43864) is making the following tests to fail and this revert diff is either the revert of the blame diff or the revert of the stack of diffs that need to be reverted to revert the blame diff

Tests affected:
- https://www.internalfb.com/intern/test/562950004334605/

Multisect link:
https://www.internalfb.com/intern/testinfra/multisect/756170

Test Plan: NA

Reviewed By: zhxchen17

Differential Revision: D34596156

fbshipit-source-id: a465bca0094db3caf6130c80f1ed49eea981359b
(cherry picked from commit ef5e5578c64ce9827570757fb016aafa9c782c6a)
2022-03-08 23:18:54 +00:00

48 lines
1.3 KiB
C++

#pragma once
#include <functional>
#include <memory>
#include <ATen/core/ivalue.h>
#include <c10/macros/Export.h>
#include <torch/csrc/jit/frontend/source_range.h>
namespace torch {
namespace jit {
/**
* SourceRef does two things:
* 1. Owns a Source object.
* 2. Serves as lookup key to the owned Source in associative containers, for
* runtime data aggregation.
* We don't want to use std::shared_ptr<Source> directly because we want to
* support heteogeneous lookup, and also shared_ptr is an implementation detail
* which should be encapsulated.
*/
class TORCH_API SourceRef : public CustomClassHolder {
public:
explicit SourceRef(std::shared_ptr<SourceView> source_view)
: source_view_(std::move(source_view)) {}
bool operator==(const SourceRef& other) const {
return source_view_ == other.source_view_;
}
bool operator<(const SourceView& other) const {
return source_view_.get() < &other;
}
friend bool operator<(const SourceView& other, const SourceRef& self) {
return &other < self.source_view_.get();
}
bool operator<(const SourceRef& other) const {
return *this < *other.source_view_.get();
}
const SourceView* operator->() const {
return source_view_.get();
}
private:
std::shared_ptr<SourceView> source_view_;
};
} // namespace jit
} // namespace torch