From 1a2d397fa54df6550088e9da39e4c7c14629e216 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 8 Nov 2023 11:38:04 +1100 Subject: [PATCH 1/4] Remove string cache --- melior/src/context.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/melior/src/context.rs b/melior/src/context.rs index 8e5407f7f5..affcbbfd24 100644 --- a/melior/src/context.rs +++ b/melior/src/context.rs @@ -22,9 +22,6 @@ use std::{ffi::c_void, marker::PhantomData, pin::Pin}; #[derive(Debug)] pub struct Context { raw: MlirContext, - // We need to pass null-terminated strings to functions in the MLIR API although - // Rust's strings are not. - string_cache: DashMap, ()>, } impl Context { @@ -32,7 +29,6 @@ impl Context { pub fn new() -> Self { Self { raw: unsafe { mlirContextCreate() }, - string_cache: Default::default(), } } @@ -124,10 +120,6 @@ impl Context { pub(crate) fn to_ref(&self) -> ContextRef { unsafe { ContextRef::from_raw(self.to_raw()) } } - - pub(crate) fn string_cache(&self) -> &DashMap, ()> { - &self.string_cache - } } impl Drop for Context { From 715ffca026de00a71f15fac37f58d659e1eda174 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 8 Nov 2023 11:39:13 +1100 Subject: [PATCH 2/4] Fix --- melior/src/context.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/melior/src/context.rs b/melior/src/context.rs index affcbbfd24..7315cd85ce 100644 --- a/melior/src/context.rs +++ b/melior/src/context.rs @@ -4,7 +4,6 @@ use crate::{ logical_result::LogicalResult, string_ref::StringRef, }; -use dashmap::DashMap; use mlir_sys::{ mlirContextAppendDialectRegistry, mlirContextAttachDiagnosticHandler, mlirContextCreate, mlirContextDestroy, mlirContextDetachDiagnosticHandler, mlirContextEnableMultithreading, @@ -13,7 +12,7 @@ use mlir_sys::{ mlirContextIsRegisteredOperation, mlirContextLoadAllAvailableDialects, mlirContextSetAllowUnregisteredDialects, MlirContext, MlirDiagnostic, MlirLogicalResult, }; -use std::{ffi::c_void, marker::PhantomData, pin::Pin}; +use std::{ffi::c_void, marker::PhantomData}; /// A context of IR, dialects, and passes. /// From 8c1ce92edca16e66cc9848e6a0bd37170f8df068 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 8 Nov 2023 11:39:30 +1100 Subject: [PATCH 3/4] Fix --- melior/src/string_ref.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/melior/src/string_ref.rs b/melior/src/string_ref.rs index 36e0170505..55f74107be 100644 --- a/melior/src/string_ref.rs +++ b/melior/src/string_ref.rs @@ -40,21 +40,6 @@ impl<'a> StringRef<'a> { unsafe { Self::from_raw(string) } } - /// Converts a string into a null-terminated string reference. - #[deprecated] - pub fn from_str(context: &'a Context, string: &str) -> Self { - let entry = context - .string_cache() - .entry(Pin::new(string.into())) - .or_default(); - let string = MlirStringRef { - data: entry.key().as_bytes().as_ptr() as *const i8, - length: entry.key().len(), - }; - - unsafe { Self::from_raw(string) } - } - /// Converts a string reference into a `str`. pub fn as_str(&self) -> Result<&'a str, Utf8Error> { unsafe { From 1a23ceeaa73860bc6ec588a6825ff5085c726e11 Mon Sep 17 00:00:00 2001 From: Yota Toyama Date: Wed, 8 Nov 2023 11:39:57 +1100 Subject: [PATCH 4/4] Fix linting --- melior/src/string_ref.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/melior/src/string_ref.rs b/melior/src/string_ref.rs index 55f74107be..159ca3db7f 100644 --- a/melior/src/string_ref.rs +++ b/melior/src/string_ref.rs @@ -1,9 +1,7 @@ -use crate::Context; use mlir_sys::{mlirStringRefEqual, MlirStringRef}; use std::{ ffi::CStr, marker::PhantomData, - pin::Pin, slice, str::{self, Utf8Error}, };