-
Notifications
You must be signed in to change notification settings - Fork 142
Initial changes required to codegen stdlib #210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,13 +97,46 @@ impl<'tcx> GotocCtx<'tcx> { | |
| self.current_fn().mir().basic_blocks().indices().map(|bb| format!("{:?}", bb)).collect() | ||
| } | ||
|
|
||
| fn should_skip_current_fn(&self) -> bool { | ||
| match self.current_fn().readable_name() { | ||
| // https://github.com/model-checking/rmc/issues/202 | ||
| "fmt::ArgumentV1::<'a>::as_usize" => true, | ||
| // https://github.com/model-checking/rmc/issues/203 | ||
| "<(dyn core::any::Any + core::marker::Send + 'static)>::downcast_ref" => true, | ||
| // https://github.com/model-checking/rmc/issues/204 | ||
| x if x.ends_with("__getit") => true, | ||
| // https://github.com/model-checking/rmc/issues/205 | ||
| "panic::Location::<'a>::caller" => true, | ||
| // https://github.com/model-checking/rmc/issues/206 | ||
| "core::sync::atomic::atomic_swap" => true, | ||
| // https://github.com/model-checking/rmc/issues/207 | ||
| "core::slice::<impl [T]>::split_first" => true, | ||
| // https://github.com/model-checking/rmc/issues/208 | ||
| "panicking::take_hook" => true, | ||
| // https://github.com/model-checking/rmc/issues/209 | ||
| "panicking::r#try" => true, | ||
| _ => false, | ||
| } | ||
| } | ||
|
|
||
|
||
| pub fn codegen_function(&mut self, instance: Instance<'tcx>) { | ||
| self.set_current_fn(instance); | ||
| let name = self.current_fn().name(); | ||
| let old_sym = self.symbol_table.lookup(&name).unwrap(); | ||
| assert!(old_sym.is_function()); | ||
| if old_sym.is_function_definition() { | ||
| warn!("Double codegen of {:?}", old_sym); | ||
| } else if self.should_skip_current_fn() { | ||
| debug!("Skipping function {}", self.current_fn().readable_name()); | ||
| let loc = self.codegen_span2(&self.current_fn().mir().span); | ||
| let body = Stmt::assert_false( | ||
| &format!( | ||
| "The function {} is not currently supported by RMC", | ||
| self.current_fn().readable_name() | ||
| ), | ||
| loc, | ||
| ); | ||
| self.symbol_table.update_fn_declaration_with_definition(&name, body); | ||
| } else { | ||
| let mir = self.current_fn().mir(); | ||
| self.print_instance(instance, mir); | ||
|
|
@@ -170,7 +203,7 @@ impl<'tcx> GotocCtx<'tcx> { | |
| fname, | ||
| ctx.fn_typ(), | ||
| None, | ||
| Some(ctx.readable_instance_name(instance)), | ||
| Some(ctx.current_fn().readable_name().to_string()), | ||
| ctx.codegen_span2(&mir.span), | ||
| ) | ||
| }); | ||
|
|
@@ -268,8 +301,10 @@ impl CodegenBackend for GotocCodegenBackend { | |
| MonoItem::Fn(instance) => c.declare_function(instance), | ||
| MonoItem::Static(def_id) => c.declare_static(def_id, item), | ||
| MonoItem::GlobalAsm(_) => { | ||
danielsn marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tcx.sess.err("does not support assembly code"); | ||
| tcx.sess.abort_if_errors() | ||
| warn!( | ||
| "Crate {} contains global ASM, which is not handled by RMC", | ||
| c.crate_name() | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -282,7 +317,7 @@ impl CodegenBackend for GotocCodegenBackend { | |
| match item { | ||
| MonoItem::Fn(instance) => c.codegen_function(instance), | ||
| MonoItem::Static(def_id) => c.codegen_static(def_id, item), | ||
| MonoItem::GlobalAsm(_) => unreachable!(), // we have aborted above | ||
| MonoItem::GlobalAsm(_) => {} // We have already warned above | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,12 @@ impl<'tcx> GotocCtx<'tcx> { | |
| assert!(e.typ().is_rust_box(), "expected rust box {:?}", e); | ||
| let unique_ptr_typ = | ||
| self.symbol_table.lookup_field_type_in_type(e.typ(), "0").unwrap().clone(); | ||
| assert!(unique_ptr_typ.is_rust_unique_pointer()); | ||
| assert!( | ||
| unique_ptr_typ.is_rust_unique_pointer(), | ||
| "{:?}\n\t{}", | ||
| unique_ptr_typ, | ||
| self.current_fn().readable_name() | ||
| ); | ||
| e.member("0", &self.symbol_table).member("pointer", &self.symbol_table) | ||
| } | ||
|
|
||
|
|
@@ -133,7 +138,9 @@ impl Type { | |
| /// Checks if the struct represents a Rust "Unique" | ||
| pub fn is_rust_unique_pointer(&self) -> bool { | ||
| self.type_name().map_or(false, |name| { | ||
| name.starts_with("tag-std::ptr::Unique") || name.starts_with("tag-core::ptr::Unique") | ||
| name.starts_with("tag-std::ptr::Unique") | ||
| || name.starts_with("tag-core::ptr::Unique") | ||
| || name.starts_with("tag-rustc_std_workspace_core::ptr::Unique") | ||
|
||
| }) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉