@@ -424,10 +424,9 @@ void block_arg(Context& C, ValueRefs Args) {
424424
425425static void with_builder_impl (Context& C, mlir::OpBuilder const & Builder,
426426 heavy::Value Thunk) {
427- mlir::MLIRContext* MLIRContext = getCurrentContext (C);
428427 heavy::Value PrevBuilder = C.CreateBinding (heavy::Empty ());
429428 heavy::Value NewBuilder = CreateTagged (C, kind::mlir_builder,
430- mlir::OpBuilder (MLIRContext) );
429+ Builder );
431430
432431 heavy::Value Before = C.CreateLambda (
433432 [](heavy::Context& C, heavy::ValueRefs Args) {
@@ -712,6 +711,8 @@ void load_dialect(Context& C, heavy::ValueRefs Args) {
712711 return C.RaiseError (" expecting dialect name" );
713712
714713 mlir::MLIRContext* MLIRContext = getCurrentContext (C);
714+ // Ensure the registry is up to date.
715+ MLIRContext->appendDialectRegistry (*C.DialectRegistry );
715716 mlir::Dialect* Dialect = MLIRContext->getOrLoadDialect (Name);
716717 if (Dialect == nullptr )
717718 return C.RaiseError (C.CreateString (" failed to load dialect: " , Name), {});
@@ -817,6 +818,7 @@ void HEAVY_MLIR_LOAD_MODULE(heavy::Context& C) {
817818 heavy::initModuleNames (C, HEAVY_MLIR_LIB_STR, {
818819 {" create-op" , HEAVY_MLIR_VAR (create_op)},
819820 {" %create-op" , HEAVY_MLIR_VAR (create_op_impl)},
821+ {" current-builder" , HEAVY_MLIR_VAR (current_builder).get_binding (C)},
820822 {" region" , HEAVY_MLIR_VAR (region)},
821823 {" entry-block" , HEAVY_MLIR_VAR (entry_block)},
822824 {" results" , HEAVY_MLIR_VAR (results)},
0 commit comments