Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit b494caa

Browse files
committed
Fixed bugs and bugged things
1 parent 77b5e45 commit b494caa

File tree

7 files changed

+51
-14
lines changed

7 files changed

+51
-14
lines changed

cpp/frontend/frontend.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Frontend::Frontend(std::string server, int port)
2828
.registerFrontendRequest()
2929
.send()
3030
.then([](auto res) { return res.getContext(); })),
31+
builder_(false),
3132
stop_request_(kj::READY_NOW) {}
3233

3334
File* Frontend::provideFile(const std::string& path,
@@ -198,14 +199,19 @@ void Execution::notifyStart(std::function<void()> callback) {
198199
}
199200

200201
void Execution::getResult(std::function<void(Result)> callback) {
202+
getResult(std::move(callback), []() {});
203+
}
204+
205+
void Execution::getResult(std::function<void(Result)> callback,
206+
std::function<void()> errored) {
201207
auto promise = kj::newPromiseAndFulfiller<void>();
202208
builder_.AddPromise(std::move(promise.promise));
203209
auto ff = promise.fulfiller.get();
204210
finish_builder_.AddPromise(
205211
std::move(my_builder_)
206212
.Finalize()
207213
.then(
208-
[this, callback,
214+
[this, callback, errored,
209215
fulfiller = std::move(promise.fulfiller)]() mutable {
210216
fulfiller->fulfill();
211217
return execution_.getResultRequest()
@@ -244,7 +250,7 @@ void Execution::getResult(std::function<void(Result)> callback) {
244250
r.getResourceUsage().getStack();
245251
callback(result);
246252
},
247-
[](auto exc) {})
253+
[errored](auto exc) { errored(); })
248254
.eagerlyEvaluate(nullptr);
249255
},
250256
[this, fulfiller = ff](kj::Exception exc) {

cpp/frontend/frontend.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,8 @@ class Execution {
114114
void notifyStart(std::function<void()> callback);
115115

116116
void getResult(std::function<void(Result)> callback);
117+
void getResult(std::function<void(Result)> callback,
118+
std::function<void()> errored);
117119

118120
private:
119121
std::string description_;

cpp/frontend/python/frontend.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ PYBIND11_MODULE(task_maker_frontend, m) {
8080
.def("output", &frontend::Execution::output,
8181
pybind11::return_value_policy::reference)
8282
.def("notifyStart", &frontend::Execution::notifyStart)
83-
.def("getResult", &frontend::Execution::getResult);
83+
.def("getResult", (void (frontend::Execution::*)(
84+
std::function<void(frontend::Result)>)) &
85+
frontend::Execution::getResult)
86+
.def("getResult",
87+
(void (frontend::Execution::*)(std::function<void(frontend::Result)>,
88+
std::function<void()>)) &
89+
frontend::Execution::getResult);
8490

8591
pybind11::class_<frontend::Frontend>(m, "Frontend")
8692
.def(pybind11::init<std::string, int>())

cpp/server/server.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ kj::Promise<void> Execution::getResult(GetResultContext context) {
196196
const util::SHA256_t& hash) {
197197
frontend_context_.file_info_[id].hash = hash;
198198
if (!result.getStatus().isSuccess()) {
199+
KJ_LOG(INFO, "Marking file as failed", id,
200+
description_);
199201
frontend_context_.file_info_[id]
200202
.promise.fulfiller->reject(
201203
KJ_EXCEPTION(FAILED, "Dependency failed"));
@@ -242,6 +244,7 @@ kj::Promise<void> Execution::getResult(GetResultContext context) {
242244
.fulfiller->reject(KJ_EXCEPTION(
243245
FAILED, "Execution stalled!"));
244246
} else {
247+
KJ_LOG(INFO, "Finished execution", description_);
245248
finish_promise_.fulfiller->fulfill();
246249
}
247250
})
@@ -254,7 +257,9 @@ kj::Promise<void> Execution::getResult(GetResultContext context) {
254257
.eagerlyEvaluate(nullptr);
255258
},
256259
[this](kj::Exception exc) {
260+
KJ_LOG(INFO, "Marking execution as failed", description_);
257261
for (auto f : outputs_) {
262+
KJ_LOG(INFO, "Marking as failed", f.first, f.second);
258263
auto& ff =
259264
frontend_context_.file_info_[f.second].promise.fulfiller;
260265
if (ff) ff->reject(KJ_EXCEPTION(FAILED, "Dependency failed"));
@@ -292,13 +297,13 @@ kj::Promise<void> FrontendContext::startEvaluation(
292297
util::File::MaybeGet(file.second.hash,
293298
context.getParams().getSender())
294299
.then(
295-
[id = file.first,
300+
[this, id = file.first,
296301
fulfiller =
297302
std::move(file.second.promise.fulfiller)]() mutable {
298303
KJ_LOG(INFO, "Received file with id " + std::to_string(id));
299304
fulfiller->fulfill();
300305
},
301-
[fulfiller = ff](kj::Exception exc) {
306+
[this, fulfiller = ff](kj::Exception exc) {
302307
fulfiller->reject(kj::cp(exc));
303308
return exc;
304309
})

cpp/util/misc.hpp

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ class UnionPromiseBuilder {
5454
};
5555

5656
public:
57-
UnionPromiseBuilder() : p_(kj::newPromiseAndFulfiller<void>()) {
57+
UnionPromiseBuilder(bool fatalFailure = true)
58+
: fatalFailure_(fatalFailure), p_(kj::newPromiseAndFulfiller<void>()) {
5859
auto info = kj::heap<Info>();
5960
info_ = info.get();
6061
fulfiller_ = p_.fulfiller.get();
@@ -72,13 +73,21 @@ class UnionPromiseBuilder {
7273
fulfiller->fulfill();
7374
}
7475
},
75-
[fulfiller = fulfiller_, info = info_,
76+
[fatalFailure_, fulfiller = fulfiller_, info = info_,
7677
idx = info_->promises.size()](kj::Exception exc) {
77-
fulfiller->reject(kj::cp(exc));
7878
// Cancel all other promises
79-
std::swap(info->promises[0], info->promises[idx]);
80-
while (info->promises.size() > 1) {
81-
info->promises.pop_back();
79+
if (fatalFailure_) {
80+
std::swap(info->promises[0], info->promises[idx]);
81+
while (info->promises.size() > 1) {
82+
info->promises.pop_back();
83+
}
84+
fulfiller->reject(kj::cp(exc));
85+
} else {
86+
info->resolved++;
87+
if (info->finalized &&
88+
info->resolved == info->promises.size()) {
89+
fulfiller->fulfill();
90+
}
8291
}
8392
return exc;
8493
})
@@ -93,8 +102,12 @@ class UnionPromiseBuilder {
93102
return std::move(p_.promise);
94103
}
95104

105+
int GetMissing() { return info_->promises.size() - info_->resolved; }
106+
96107
private:
108+
bool fatalFailure_;
97109
kj::PromiseFulfillerPair<void> p_;
110+
// TODO use std::move(this) rather that kj::heap
98111
Info* info_ = nullptr;
99112
kj::PromiseFulfiller<void>* fulfiller_ = nullptr;
100113
};

python/formats/ioi_format.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ def evaluate_task(frontend: Frontend, task: Task, solutions: List[SourceFile]):
273273
dict((st_num, [tc for tc in st.testcases.keys()])
274274
for st_num, st in task.subtasks.items()))
275275
ui = IOILikeCursesUI(ui_interface)
276-
ui.start()
276+
# ui.start()
277277
ins, outs, vals = generate_inputs(frontend, task, ui_interface)
278278
evaluate_solutions(frontend, task, ins, outs, vals, solutions,
279279
ui_interface)

python/ui.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,22 @@ def getResultEvaluation(result: Result):
266266
result)
267267

268268
evaluation.notifyStart(notifyStartEvaluation)
269-
evaluation.getResult(getResultEvaluation)
269+
evaluation.getResult(
270+
getResultEvaluation,
271+
lambda: print("Skipped evaluation", subtask, testcase, solution))
270272

271273
def add_evaluate_checking(self, subtask: int, testcase: int, solution: str,
272274
checking: Execution):
273275
def notifyStartChecking():
274276
self.testing[solution].testcase_results[subtask][
275277
testcase] = TestcaseSolutionResult.CHECKING
278+
print("Started checking", subtask, testcase, solution)
276279

277280
def getResultChecking(result: Result):
278281
self.testing[solution].update_check_result(subtask, testcase,
279282
result)
280283

281284
checking.notifyStart(notifyStartChecking)
282-
checking.getResult(getResultChecking)
285+
checking.getResult(
286+
getResultChecking,
287+
lambda: print("Skipped checking", subtask, testcase, solution))

0 commit comments

Comments
 (0)