Skip to content
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

Update Charon submodule #3823

Merged
merged 72 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
e7f4152
add support for enum, struct, tuple in mod.rs, add some tests
thanhnguyen-aws Nov 15, 2024
0937022
revert changes
thanhnguyen-aws Nov 15, 2024
bb789a7
format code
thanhnguyen-aws Nov 15, 2024
cebeff5
edit according to clippy suggestions
thanhnguyen-aws Nov 15, 2024
694f7ac
add new line at the send of basic0/expected, remove comments in mod.rs
thanhnguyen-aws Nov 18, 2024
6998703
remove more commented functions
thanhnguyen-aws Nov 18, 2024
75dcb09
format code
thanhnguyen-aws Nov 18, 2024
ad57da7
Merge branch 'model-checking:main' into thanh-llbc
thanhnguyen-aws Nov 18, 2024
7ac77f3
add end lines to expected files for the 4 test cases
thanhnguyen-aws Nov 18, 2024
4d40b53
remove comments
thanhnguyen-aws Nov 18, 2024
7977233
update s2n-quic
thanhnguyen-aws Nov 18, 2024
28395c5
re-run kani and fix the expected file
thanhnguyen-aws Nov 18, 2024
2d2f6ce
change function namne find_type_decl_id to get_type_decl_id
thanhnguyen-aws Nov 19, 2024
c729818
change function namne find_type_decl_id to get_type_decl_id
thanhnguyen-aws Nov 19, 2024
dbd7215
added the translation for generic params, fixed the formatting
thanhnguyen-aws Nov 20, 2024
e3bb0ca
Merge branch 'main' into thanh-llbc
thanhnguyen-aws Nov 20, 2024
997db12
comment change
thanhnguyen-aws Nov 20, 2024
3ec593d
fixed the expected testes
thanhnguyen-aws Nov 20, 2024
000d098
fixed clippy
thanhnguyen-aws Nov 20, 2024
4107f81
fixed format
thanhnguyen-aws Nov 20, 2024
43bd739
group use statements and add a test that use generic args
thanhnguyen-aws Nov 21, 2024
137008c
fixed unreachable -> todo
thanhnguyen-aws Nov 21, 2024
df89b51
fixed format
thanhnguyen-aws Nov 21, 2024
2cb0e56
changing some test folders' names
thanhnguyen-aws Nov 22, 2024
0b89120
Merge branch 'model-checking:main' into thanh-llbc
thanhnguyen-aws Nov 25, 2024
24a30a3
Some support for generic
thanhnguyen-aws Nov 25, 2024
6f5347c
translating traits
thanhnguyen-aws Nov 25, 2024
f798051
Merge branch 'main' into generic-llbc
thanhnguyen-aws Nov 26, 2024
30026cc
added trait clauses
thanhnguyen-aws Nov 26, 2024
11f5f10
more on trait
thanhnguyen-aws Nov 27, 2024
28b11e1
save
thanhnguyen-aws Nov 27, 2024
659f83b
save
thanhnguyen-aws Nov 27, 2024
e668d44
save
thanhnguyen-aws Nov 28, 2024
00c9513
update toolchain
thanhnguyen-aws Nov 29, 2024
9f5774c
translate trait
thanhnguyen-aws Dec 30, 2024
7c286c8
editing code
thanhnguyen-aws Dec 31, 2024
865bdd9
fixed clippy
thanhnguyen-aws Dec 31, 2024
0b7c527
update charon
thanhnguyen-aws Jan 2, 2025
d7c91f5
update charon
thanhnguyen-aws Jan 2, 2025
215d11d
fix small bugs
thanhnguyen-aws Jan 2, 2025
5e3fd23
save
thanhnguyen-aws Jan 2, 2025
103603f
update projection
thanhnguyen-aws Jan 3, 2025
d84c48e
merging main
thanhnguyen-aws Jan 3, 2025
f585369
fixed println
thanhnguyen-aws Jan 3, 2025
f336b0a
adding an expected test for trait
thanhnguyen-aws Jan 3, 2025
53983dd
fixed the test
thanhnguyen-aws Jan 3, 2025
3bc4e6d
fix some comments
thanhnguyen-aws Jan 6, 2025
dd8c642
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 7, 2025
7d28582
add comments
thanhnguyen-aws Jan 7, 2025
5459810
add more comments
thanhnguyen-aws Jan 7, 2025
1efa472
formating
thanhnguyen-aws Jan 7, 2025
bd88440
remove expected
thanhnguyen-aws Jan 7, 2025
e28169a
Update kani-compiler/src/codegen_aeneas_llbc/mir_to_ullbc/mod.rs
thanhnguyen-aws Jan 8, 2025
e80166b
add example test for option
thanhnguyen-aws Jan 8, 2025
7930902
comments
thanhnguyen-aws Jan 8, 2025
06d0525
add tests/expected/llbc/option/expected
thanhnguyen-aws Jan 8, 2025
2a2a462
revert change to s2n-quic
thanhnguyen-aws Jan 9, 2025
1799aa6
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 9, 2025
954317d
fixed formating
thanhnguyen-aws Jan 9, 2025
6c76375
add expected for trait impl
thanhnguyen-aws Jan 9, 2025
4f05967
update charon
thanhnguyen-aws Jan 10, 2025
57294f0
sync
thanhnguyen-aws Jan 10, 2025
b2bb054
sync
thanhnguyen-aws Jan 10, 2025
476c3d2
sync
thanhnguyen-aws Jan 11, 2025
1647552
formating
thanhnguyen-aws Jan 11, 2025
d396b4c
fix clippy
thanhnguyen-aws Jan 11, 2025
109e884
fix comments
thanhnguyen-aws Jan 11, 2025
66c7836
update formatting
thanhnguyen-aws Jan 13, 2025
f03517e
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 13, 2025
e71be0b
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 13, 2025
a6de90c
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 13, 2025
dd3ff73
Merge branch 'main' into update-charon
thanhnguyen-aws Jan 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"

[[package]]
name = "charon"
version = "0.1.58"
version = "0.1.62"
dependencies = [
"annotate-snippets",
"anstream",
Expand Down
2 changes: 1 addition & 1 deletion charon
Submodule charon updated 111 files
74 changes: 58 additions & 16 deletions kani-compiler/src/codegen_aeneas_llbc/compiler_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ use crate::kani_middle::provide;
use crate::kani_middle::reachability::{collect_reachable_items, filter_crate_items};
use crate::kani_middle::transform::{BodyTransformation, GlobalPasses};
use crate::kani_queries::QueryDb;
use charon_lib::ast::{AnyTransId, TranslatedCrate};
use charon_lib::ast::{AnyTransId, TranslatedCrate, meta::ItemOpacity::*, meta::Span};
use charon_lib::errors::ErrorCtx;
use charon_lib::errors::error_or_panic;
use charon_lib::name_matcher::NamePattern;
use charon_lib::transform::TransformCtx;
use charon_lib::transform::ctx::TransformOptions;
use charon_lib::transform::ctx::{TransformOptions, TransformPass};
use kani_metadata::ArtifactType;
use kani_metadata::{AssignsContract, CompilerArtifactStub};
use rustc_codegen_ssa::back::archive::{
Expand Down Expand Up @@ -133,8 +135,8 @@ impl LlbcCodegenBackend {
// - compute the order in which to extract the definitions
// - find the recursive definitions
// - group the mutually recursive definitions
let reordered_decls = charon_lib::reorder_decls::compute_reordered_decls(&ccx);
ccx.translated.ordered_decls = Some(reordered_decls);
let reordered_decls = charon_lib::transform::reorder_decls::Transform {};
reordered_decls.transform_ctx(&mut ccx);

//
// =================
Expand All @@ -151,10 +153,6 @@ impl LlbcCodegenBackend {

// # Go from ULLBC to LLBC (Low-Level Borrow Calculus) by reconstructing
// the control flow.
charon_lib::ullbc_to_llbc::translate_functions(&mut ccx);

trace!("# LLBC resulting from control-flow reconstruction:\n\n{}\n", ccx);

// Run the micro-passes that clean up bodies.
for pass in charon_lib::transform::LLBC_PASSES.iter() {
pass.run(&mut ccx)
Expand Down Expand Up @@ -385,17 +383,61 @@ where
ret
}

fn create_charon_transformation_context(tcx: TyCtxt) -> TransformCtx {
let options = TransformOptions {
fn get_transform_options(tcx: &TranslatedCrate, error_ctx: &mut ErrorCtx) -> TransformOptions {
let mut parse_pattern = |s: &str| match NamePattern::parse(s) {
Ok(p) => Ok(p),
Err(e) => {
let msg = format!("failed to parse pattern `{s}` ({e})");
error_or_panic!(error_ctx, &TranslatedCrate::default(), Span::dummy(), msg)
}
};
let options = tcx.options.clone();
let item_opacities = {
let mut opacities = vec![];

// This is how to treat items that don't match any other pattern.
if options.extract_opaque_bodies {
opacities.push(("_".to_string(), Transparent));
} else {
opacities.push(("_".to_string(), Foreign));
}

// We always include the items from the crate.
opacities.push(("crate".to_owned(), Transparent));

for pat in options.include.iter() {
opacities.push((pat.to_string(), Transparent));
}
for pat in options.opaque.iter() {
opacities.push((pat.to_string(), Opaque));
}
for pat in options.exclude.iter() {
opacities.push((pat.to_string(), Invisible));
}

// We always hide this trait.
opacities.push(("core::alloc::Allocator".to_string(), Invisible));
opacities
.push(("alloc::alloc::{{impl core::alloc::Allocator for _}}".to_string(), Invisible));

opacities
.into_iter()
.filter_map(|(s, opacity)| parse_pattern(&s).ok().map(|pat| (pat, opacity)))
.collect()
};
TransformOptions {
no_code_duplication: false,
hide_marker_traits: true,
no_merge_goto_chains: false,
item_opacities: Vec::new(),
};
item_opacities,
print_built_llbc: true,
}
}

fn create_charon_transformation_context(tcx: TyCtxt) -> TransformCtx {
let crate_name = tcx.crate_name(LOCAL_CRATE).as_str().into();
let mut translated = TranslatedCrate { crate_name, ..TranslatedCrate::default() };
//This option setting is for Aeneas compatibility
translated.options.hide_marker_traits = true;
let errors = ErrorCtx::new(true, false);
let translated = TranslatedCrate { crate_name, ..TranslatedCrate::default() };
let mut errors = ErrorCtx::new(true, false);
let options = get_transform_options(&translated, &mut errors);
TransformCtx { options, translated, errors }
}
79 changes: 38 additions & 41 deletions kani-compiler/src/codegen_aeneas_llbc/mir_to_ullbc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ use charon_lib::ast::types::{Ty as CharonTy, TyKind as CharonTyKind};
use charon_lib::ast::{
AbortKind as CharonAbortKind, AggregateKind as CharonAggregateKind,
AnyTransId as CharonAnyTransId, Assert as CharonAssert, BinOp as CharonBinOp,
Body as CharonBody, BodyId as CharonBodyId, BorrowKind as CharonBorrowKind,
BuiltinTy as CharonBuiltinTy, Call as CharonCall, CastKind as CharonCastKind,
ConstGeneric as CharonConstGeneric, ConstGenericVar as CharonConstGenericVar,
ConstGenericVarId as CharonConstGenericVarId, ConstantExpr as CharonConstantExpr,
DeBruijnId as CharonDeBruijnId, DeBruijnVar as CharonDeBruijnVar,
Disambiguator as CharonDisambiguator, ExistentialPredicate as CharonExistentialPredicate,
Field as CharonField, FieldId as CharonFieldId, FieldProjKind as CharonFieldProjKind,
File as CharonFile, FileId as CharonFileId, FileName as CharonFileName,
FnOperand as CharonFnOperand, FnPtr as CharonFnPtr, FunDecl as CharonFunDecl,
FunDeclId as CharonFunDeclId, FunId as CharonFunId,
FunIdOrTraitMethodRef as CharonFunIdOrTraitMethodRef, FunSig as CharonFunSig,
GenericArgs as CharonGenericArgs, GenericParams as CharonGenericParams,
GlobalDeclId as CharonGlobalDeclId, GlobalDeclRef as CharonGlobalDeclRef,
IntegerTy as CharonIntegerTy, ItemKind as CharonItemKind, ItemMeta as CharonItemMeta,
ItemOpacity as CharonItemOpacity, Literal as CharonLiteral, LiteralTy as CharonLiteralTy,
Locals as CharonLocals, Name as CharonName, Opaque as CharonOpaque, Operand as CharonOperand,
PathElem as CharonPathElem, Place as CharonPlace, PolyTraitDeclRef as CharonPolyTraitDeclRef,
Body as CharonBody, BorrowKind as CharonBorrowKind, BuiltinTy as CharonBuiltinTy,
Call as CharonCall, CastKind as CharonCastKind, ConstGeneric as CharonConstGeneric,
ConstGenericVar as CharonConstGenericVar, ConstGenericVarId as CharonConstGenericVarId,
ConstantExpr as CharonConstantExpr, DeBruijnId as CharonDeBruijnId,
DeBruijnVar as CharonDeBruijnVar, Disambiguator as CharonDisambiguator,
ExistentialPredicate as CharonExistentialPredicate, Field as CharonField,
FieldId as CharonFieldId, FieldProjKind as CharonFieldProjKind, File as CharonFile,
FileId as CharonFileId, FileName as CharonFileName, FnOperand as CharonFnOperand,
FnPtr as CharonFnPtr, FunDecl as CharonFunDecl, FunDeclId as CharonFunDeclId,
FunId as CharonFunId, FunIdOrTraitMethodRef as CharonFunIdOrTraitMethodRef,
FunSig as CharonFunSig, GenericArgs as CharonGenericArgs, GenericParams as CharonGenericParams,
GenericsSource as CharonGenericsSource, GlobalDeclId as CharonGlobalDeclId,
GlobalDeclRef as CharonGlobalDeclRef, IntegerTy as CharonIntegerTy, ItemKind as CharonItemKind,
ItemMeta as CharonItemMeta, ItemOpacity as CharonItemOpacity, Literal as CharonLiteral,
LiteralTy as CharonLiteralTy, Locals as CharonLocals, Name as CharonName,
Opaque as CharonOpaque, Operand as CharonOperand, PathElem as CharonPathElem,
Place as CharonPlace, PolyTraitDeclRef as CharonPolyTraitDeclRef,
PredicateOrigin as CharonPredicateOrigin, ProjectionElem as CharonProjectionElem,
RawConstantExpr as CharonRawConstantExpr, RefKind as CharonRefKind, Region as CharonRegion,
RegionBinder as CharonRegionBinder, RegionId as CharonRegionId, RegionVar as CharonRegionVar,
Expand Down Expand Up @@ -180,7 +180,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
continue;
};
let c_traitdecl_id = self.translate_traitdecl(trait_def);
let c_genarg = self.translate_generic_args_without_trait(trait_ref.args().clone());
let c_genarg = self
.translate_generic_args_without_trait(trait_ref.args().clone(), trait_def.def_id());
let c_polytrait = CharonPolyTraitDeclRef {
regions: CharonVector::new(),
skip_binder: CharonTraitDeclRef {
Expand Down Expand Up @@ -221,7 +222,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
continue;
};
let c_traitdecl_id = self.translate_traitdecl(trait_def);
let c_genarg = self.translate_generic_args_without_trait(trait_ref.args().clone());
let c_genarg = self
.translate_generic_args_without_trait(trait_ref.args().clone(), trait_def.def_id());
let c_polytrait = CharonPolyTraitDeclRef {
regions: CharonVector::new(),
skip_binder: CharonTraitDeclRef { trait_id: c_traitdecl_id, generics: c_genarg },
Expand Down Expand Up @@ -1167,19 +1169,14 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
}
}

fn translate_function_body(
&mut self,
instance: Instance,
) -> Result<CharonBodyId, CharonOpaque> {
fn translate_function_body(&mut self, instance: Instance) -> Result<CharonBody, CharonOpaque> {
let fndef = match instance.ty().kind() {
TyKind::RigidTy(RigidTy::FnDef(fndef, _)) => fndef,
_ => panic!("Expected a function type"),
};
let mir_body = fndef.body().unwrap();
let body_id = self.translated.bodies.reserve_slot();
let body = self.translate_body(mir_body);
self.translated.bodies.set_slot(body_id, body);
Ok(body_id)
Ok(body)
}

fn translate_body(&mut self, mir_body: Body) -> CharonBody {
Expand All @@ -1195,6 +1192,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
}

fn translate_generic_args(&mut self, ga: GenericArgs, defid: DefId) -> CharonGenericArgs {
let target = CharonGenericsSource::Item(*self.id_map.get(&defid).unwrap());
let genvec = ga.0;
let mut c_regions: CharonVector<CharonRegionId, CharonRegion> = CharonVector::new();
let mut c_types: CharonVector<CharonTypeVarId, CharonTy> = CharonVector::new();
Expand Down Expand Up @@ -1244,6 +1242,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
types: t_types,
const_generics: t_const_generics,
trait_refs: trait_ref.trait_decl_ref.skip_binder.generics.trait_refs.clone(),
target: target.clone(),
};
let traitdecl_id = trait_ref.trait_decl_ref.skip_binder.trait_id;
let subs_traitdeclref = CharonPolyTraitDeclRef {
Expand All @@ -1264,10 +1263,16 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
types: c_types,
const_generics: c_const_generics,
trait_refs,
target,
}
}

fn translate_generic_args_without_trait(&mut self, ga: GenericArgs) -> CharonGenericArgs {
fn translate_generic_args_without_trait(
&mut self,
ga: GenericArgs,
defid: DefId,
) -> CharonGenericArgs {
let target = CharonGenericsSource::Item(*self.id_map.get(&defid).unwrap());
let genvec = ga.0;
let mut c_regions: CharonVector<CharonRegionId, CharonRegion> = CharonVector::new();
let mut c_types: CharonVector<CharonTypeVarId, CharonTy> = CharonVector::new();
Expand Down Expand Up @@ -1295,6 +1300,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
types: c_types,
const_generics: c_const_generics,
trait_refs: CharonVector::new(),
target,
}
}

Expand Down Expand Up @@ -1345,12 +1351,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
CharonTypeId::Builtin(CharonBuiltinTy::Str),
// TODO: find out whether any of the information below should be
// populated for strings
CharonGenericArgs {
regions: CharonVector::new(),
types: CharonVector::new(),
const_generics: CharonVector::new(),
trait_refs: CharonVector::new(),
},
CharonGenericArgs::empty(CharonGenericsSource::Builtin),
)),
RigidTy::Array(ty, tyconst) => {
let c_ty = self.translate_ty(ty);
Expand All @@ -1366,6 +1367,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
types: c_types,
const_generics: c_const_generics,
trait_refs: CharonVector::new(),
target: CharonGenericsSource::Builtin,
},
))
}
Expand All @@ -1380,12 +1382,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
RigidTy::Tuple(ty) => {
let types = ty.iter().map(|ty| self.translate_ty(*ty)).collect();
// TODO: find out if any of the information below is needed
let generic_args = CharonGenericArgs {
regions: CharonVector::new(),
types,
const_generics: CharonVector::new(),
trait_refs: CharonVector::new(),
};
let generic_args = CharonGenericArgs::new_for_builtin(types);
CharonTy::new(CharonTyKind::Adt(CharonTypeId::Tuple, generic_args))
}
RigidTy::FnDef(def_id, _args) => {
Expand Down Expand Up @@ -1414,7 +1411,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
c_types.push(c_ty);
CharonTy::new(CharonTyKind::Adt(
CharonTypeId::Builtin(CharonBuiltinTy::Slice),
CharonGenericArgs::new_from_types(c_types),
CharonGenericArgs::new_for_builtin(c_types),
))
}
RigidTy::RawPtr(ty, mutability) => {
Expand Down Expand Up @@ -1672,7 +1669,7 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
CharonTypeId::Tuple,
None,
None,
CharonGenericArgs::empty(),
CharonGenericArgs::empty(CharonGenericsSource::Builtin),
),
c_operands,
),
Expand Down
Loading