add a lot more logging to both client and server to analyze #81

> #81 Compiling brush doesn't seem to finish correctly sometimes, which causes loss of data
> Sometimes it seems like the client state can get desynced (server render thread dies due to a panic?) and then the server starts dropping all requests for drawing the brush.
> These panics should never happen of course, but we need better logging first to determine the exact cause.
This commit is contained in:
りき萌 2024-09-02 20:14:20 +02:00
parent 6cfbc4f05f
commit 26d3b8ed8a
5 changed files with 86 additions and 11 deletions

View file

@ -337,11 +337,20 @@ unsafe extern "C" fn haku_compile_brush(
return StatusCode::SourceCodeTooLong;
};
debug!("compiling: lexing");
let mut lexer = Lexer::new(Lexis::new(instance.limits.max_tokens), code);
if lex(&mut lexer).is_err() {
info!("compiling failed: too many tokens");
return StatusCode::TooManyTokens;
};
debug!(
"compiling: lexed successfully to {} tokens",
lexer.lexis.len()
);
debug!("compiling: parsing");
let mut ast = Ast::new(instance.limits.ast_capacity);
let mut parser = Parser::new(
&lexer.lexis,
@ -352,10 +361,21 @@ unsafe extern "C" fn haku_compile_brush(
parser::toplevel(&mut parser);
let (root, mut parser_diagnostics) = match parser.into_ast(&mut ast) {
Ok((r, d)) => (r, d),
Err(IntoAstError::NodeAlloc(_)) => return StatusCode::TooManyAstNodes,
Err(IntoAstError::UnbalancedEvents) => return StatusCode::ParserUnbalancedEvents,
Err(IntoAstError::NodeAlloc(_)) => {
info!("compiling failed: too many AST nodes");
return StatusCode::TooManyAstNodes;
}
Err(IntoAstError::UnbalancedEvents) => {
info!("compiling failed: parser produced unbalanced events");
return StatusCode::ParserUnbalancedEvents;
}
};
debug!(
"compiling: parsed successfully into {} AST nodes",
ast.len()
);
let src = Source {
code,
ast: &ast,
@ -366,7 +386,10 @@ unsafe extern "C" fn haku_compile_brush(
let mut compiler = Compiler::new(&mut instance.defs, &mut chunk);
if let Err(error) = compile_expr(&mut compiler, &src, root) {
match error {
CompileError::Emit => return StatusCode::ChunkTooBig,
CompileError::Emit => {
info!("compiling failed: chunk overflowed while emitting code");
return StatusCode::ChunkTooBig;
}
}
}
let closure_spec = compiler.closure_spec();
@ -376,9 +399,16 @@ unsafe extern "C" fn haku_compile_brush(
diagnostics.append(&mut compiler.diagnostics);
if !diagnostics.is_empty() {
brush.diagnostics = diagnostics;
debug!("compiling failed: diagnostics were emitted");
return StatusCode::DiagnosticsEmitted;
}
debug!(
"compiling: chunk has {} bytes of bytecode",
chunk.bytecode.len()
);
debug!("compiling: {closure_spec:?}");
let chunk_id = match instance.system.add_chunk(chunk) {
Ok(chunk_id) => chunk_id,
Err(_) => return StatusCode::TooManyChunks,