Skip to content
Open
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
17 changes: 17 additions & 0 deletions .agents/skills/code-review/references/custom-code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,23 @@ virtual ModelOutput forward(torch::Tensor tokens, ...);
- Use `std::shared_ptr` only when shared ownership is genuinely needed.
- Raw pointers are acceptable only for non-owning references where the lifetime is clearly managed elsewhere.

- **Prefer `std::make_unique` and `std::make_shared` to direct use of `new`** when creating heap objects managed by smart pointers.
- Avoid repeating the type and avoid exception-unsafe patterns such as passing `std::shared_ptr<T>(new T(...))` in the same statement as other expressions.
- Direct `new` is acceptable when make functions cannot be used (e.g. custom deleters, braced initialization of the pointee, or APIs that require a raw pointer and take ownership explicitly).
- If `new` is required, assign the result to a smart pointer in a standalone statement before any other expression that may throw.

```cpp
// Good
auto widget = std::make_unique<Widget>(arg);
auto widget = std::make_shared<Widget>(arg);
stub_ = std::make_unique<ServiceStub>(&channel_);

// Bad
std::unique_ptr<Widget> widget(new Widget(arg));
stub_.reset(new ServiceStub(&channel_));
process(std::shared_ptr<Widget>(new Widget), compute_priority()); // may leak
```

---

## 6. Scoping & Visibility
Expand Down
2 changes: 1 addition & 1 deletion xllm/core/distributed_runtime/comm_channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool CommChannel::init_brpc(const std::string& server_address) {
return false;
}

stub_.reset(new proto::DistributeWorker_Stub(&channel_));
stub_ = std::make_unique<proto::DistributeWorker_Stub>(&channel_);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion xllm/core/framework/xtensor/xtensor_dist_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ XTensorDistClient::XTensorDistClient(int32_t global_rank,
LOG(ERROR) << "Failed to initialize brpc channel to " << server_address;
return;
}
stub_.reset(new proto::XTensorDist_Stub(&channel_));
stub_ = std::make_unique<proto::XTensorDist_Stub>(&channel_);
wait_for_server_ready(server_address);
}

Expand Down
6 changes: 3 additions & 3 deletions xllm/core/triton_jit/src/jit_kernel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ JITKernel& JITKernel::get(std::string py_path, std::string fn_name) {
std::lock_guard<std::mutex> lock(registry_mutex);
auto it = registry.find(key);
if (it == registry.end()) {
std::unique_ptr<JITKernel> p(
new JITKernel(std::move(py_path), std::move(fn_name)));
auto [ins, ok] = registry.emplace(key, std::move(p));
auto [ins, ok] = registry.emplace(
key,
std::make_unique<JITKernel>(std::move(py_path), std::move(fn_name)));
it = ins;
}
return *it->second;
Expand Down
4 changes: 2 additions & 2 deletions xllm/core/util/suffix_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ void SuffixTree::append(int32_t seq_id, int32_t token) {
// This should be the first child being added.
assert(!node->head_child && !node->tail_child);
node->head_child = node->tail_child = new_child;
new_child->group.reset(new Group(new_child));
new_child->group = std::make_shared<Group>(new_child);
} else {
assert(node->tail_child);
insert_into_siblings_after(new_child, node->tail_child);
Expand Down Expand Up @@ -500,7 +500,7 @@ void SuffixTree::append(int32_t seq_id, int32_t token) {

// Create a new group for the child node.
new_node->head_child = new_node->tail_child = child;
child->group.reset(new Group(child));
child->group = std::make_shared<Group>(child);

// Increment the new node count and update siblings lists.
increment_count(new_node);
Expand Down
Loading