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

crux-mir: Support nightly-2023-01-23 #1096

Merged
merged 114 commits into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
73df4f6
Normalize naming and organization of rust crates
m10f Mar 2, 2023
b121efe
WIP mir-json
m10f Mar 11, 2023
b4f6235
[WIP] more bugfixes
m10f Mar 16, 2023
82c3cd0
Update `mir-json` submodule
m10f Mar 16, 2023
26d1dc5
re-add missing libs to linker and libs dir
m10f Mar 22, 2023
e4e3a65
build.sh: Set STD_ENV_ARCH
RyanGlScott Mar 22, 2023
1cc32ba
Add `test_output.log`
m10f Mar 22, 2023
e208e98
Remove unneeded RustcRenderedConst newtype
RyanGlScott Apr 3, 2023
b3e74d1
initFnState: Remove unused argument
RyanGlScott Apr 3, 2023
0df0660
genFn/transDefine: Replace unused patterns with wildcards
RyanGlScott Apr 4, 2023
14ce2da
Replace currentFn with a more general FnTransContext
RyanGlScott Apr 4, 2023
6f97467
Translate statics with constant initializers properly
RyanGlScott Apr 4, 2023
cc8d3f2
Add custom op for ctpop
RyanGlScott Apr 5, 2023
0eacf40
lib: Replace RawVec's allocator
RyanGlScott Apr 14, 2023
fa7292a
Translate more types of ConstArrays
RyanGlScott May 2, 2023
370cacc
Update mir-json submodule
RyanGlScott May 2, 2023
6b4370f
patch `core::fmt`
m10f May 2, 2023
8c590e4
crux-mir: Note fmt reimplementation in lib/Patches.md
RyanGlScott May 2, 2023
8a680c4
Mir.TransCustom: Use {impl} consistently
RyanGlScott May 2, 2023
0653a31
lib/crucible: Don't loop infinitely in zeroed()
RyanGlScott May 2, 2023
592b2a1
crux-mir: Regenerate test_output.log
RyanGlScott May 2, 2023
c1f8060
crucible-mir: Translate all ConstTuples, not just unit tuples
RyanGlScott May 2, 2023
0bba133
crucible-mir: Translate constant tuples
RyanGlScott May 3, 2023
b639790
crucible-mir: Add seqcst variants of some atomic intrinsics
RyanGlScott May 3, 2023
07add62
crucible-mir: Add some more {extern}s to custom ops
RyanGlScott May 3, 2023
b57531c
Regenerate test_output.log
RyanGlScott May 4, 2023
6aebf2d
Reapply "implement HashMap in terms of Vec"
RyanGlScott May 4, 2023
70e1387
Implement ptr::invalid/invalid_mut in terms of casts
RyanGlScott May 9, 2023
93c8031
Reapply "Avoid pointer arithmetic in slice iterators"
RyanGlScott May 9, 2023
e7415d0
Stub out ThreadLocalRef
RyanGlScott May 4, 2023
c5b8f25
Permit non-isize-typed enum discriminants
RyanGlScott May 9, 2023
a84dc47
crucible-mir: Infer zero-sized fields in enum variants
RyanGlScott May 10, 2023
2995603
update `mir-json` submodule
m10f May 10, 2023
0f293cf
Add missing pretty-printer case for ThreadLocalRef
RyanGlScott May 11, 2023
621ffc6
Translate slice constants
RyanGlScott May 16, 2023
0f52c5d
Reapply implement str::as_bytes via crucible_identity_transmute
RyanGlScott May 16, 2023
54f7db6
Compute lengths of &str constants properly
RyanGlScott May 17, 2023
0b5105b
Tighten up treatment of atomic intrinsics
RyanGlScott May 17, 2023
b54a15e
boxed.rs: Use crucible's allocator
RyanGlScott May 17, 2023
26de044
lib/Patches.md: Document "boxed.rs: Use crucible's allocator"
RyanGlScott May 17, 2023
7274762
Don't deallocate in box_free and drop
RyanGlScott May 17, 2023
e59402c
Make {sub,mul}_with_overflow use {extern}
RyanGlScott May 18, 2023
b9fec04
Reapply "reimplement from_{le,be}_bytes"
RyanGlScott May 18, 2023
7db42e7
Reapply "reimplement to_{le,be}_bytes"
RyanGlScott May 18, 2023
7b2f924
Use {extern} in transmute custom op
RyanGlScott May 18, 2023
c2aa083
raw_vec.rs: Make sure to always set capacity
RyanGlScott May 18, 2023
0043537
Expunge uses of `rustc_box` and the `box` keyword
RyanGlScott May 18, 2023
a7988e8
Update test_output.log
RyanGlScott May 18, 2023
76c5d19
crux-mir: Repair some test cases with &dyn
RyanGlScott May 18, 2023
098d341
fn_dyn.rs: Use &dyn
RyanGlScott May 18, 2023
ea56c95
crux-mir: Repair checked_* test cases
RyanGlScott May 18, 2023
ea9066b
conditional.rs: Modernize crux::test usage
RyanGlScott May 18, 2023
643ce40
Remove normDefId, compare against ExplodedDefIds
RyanGlScott May 22, 2023
5d35c27
crux-mir: Accept new golden output for some symbolic tests
RyanGlScott May 23, 2023
a29b2ff
crux-mir: Update test_output.log
RyanGlScott May 23, 2023
d7a4776
crux-mir: Override ctlz properly
RyanGlScott May 23, 2023
0be2b4a
build.sh: Use --remap-path-prefix
RyanGlScott May 24, 2023
b7a30ef
crux-mir: Update test_output.log
RyanGlScott May 24, 2023
917fb76
Handle closure constants properly
RyanGlScott May 24, 2023
141803b
Reapply "implement allocate_zeroed to fix vec![0; len]"
RyanGlScott May 24, 2023
b153e90
crucible-mir: Handle constant function pointers
RyanGlScott May 25, 2023
5df73b3
Reapply "reenable old override for slice::len"
RyanGlScott May 25, 2023
8d99d39
crucible-mir: Add sub_ptr custom ops
RyanGlScott May 25, 2023
6308cc8
Remove invalid inline pragmas
RyanGlScott May 25, 2023
22e1e07
crux-mir: Override const and mut slice len as well
RyanGlScott May 26, 2023
2272bc3
Reapply "update &[T] -> &[T; N] TryFrom impl"
RyanGlScott May 26, 2023
e629734
Disable `IsRawEqComparable`-based `SpecArrayEq` instances
RyanGlScott May 26, 2023
6dde646
Reapply "disable bytewise equality comparisons for [T]"
RyanGlScott May 26, 2023
8db861e
crucible-mir: Compute discriminant for initial enum values properly
RyanGlScott May 26, 2023
087ec43
crux-mir-test: Update symbolic golden test output
RyanGlScott May 26, 2023
e9dac28
Update test_output.log
RyanGlScott May 26, 2023
faef7f1
Use crucible_null_hook to implement null/null_mut
RyanGlScott May 30, 2023
8a599bc
crux-mir-test: Accept new coverage output
RyanGlScott May 31, 2023
d6ab13a
crucible-mir: Override clone/clone_from properly
RyanGlScott May 31, 2023
29f737d
Implement Demand using PhantomData instead of a DST
RyanGlScott Jun 1, 2023
b703544
crux-mir: Re-implement timing
RyanGlScott Jun 1, 2023
9e34725
crucible-mir: Translate ThreadLocalRefs properly
RyanGlScott Jun 1, 2023
550bb9c
Replace sys::{condvar,mutex,rwlock} with Crux-specific implementations
RyanGlScott Jun 1, 2023
76784e1
crux-mir-test: Update golden output for symbolic tests
RyanGlScott Jun 1, 2023
74c7e1b
Update test_output.log
RyanGlScott Jun 1, 2023
519f321
crux-mir-test: Sanitize disambiguators in golden test output
RyanGlScott Jun 2, 2023
afbf939
crux-mir-test: Update golden test output
RyanGlScott Jun 2, 2023
65e75fe
Regenerate test_output.log
RyanGlScott Jun 2, 2023
d29bb61
Upgrade to byteorder v1.4.3
RyanGlScott Jun 2, 2023
2236a8e
Use Crucible-friendly implementations of byteorder functions
RyanGlScott Jun 2, 2023
e526e9a
Bump mir-json submodule
RyanGlScott Jun 2, 2023
d8853f0
Accept new golden output for byteorder tests
RyanGlScott Jun 2, 2023
2302923
Hackily support `&dyn Trait` references
RyanGlScott Jun 21, 2023
5a11535
Track crate names and their hashes, use it to look up wired-in names
RyanGlScott Jun 21, 2023
2740aac
Update test_output.log
RyanGlScott Jun 21, 2023
370cb61
crux-mir: Include test crate
RyanGlScott Jun 29, 2023
537dfbe
build.sh: Produce a proper sysroot
RyanGlScott Jun 29, 2023
d4f5074
CI: Re-enable macOS build for crux-mir
RyanGlScott Jul 3, 2023
044ad3d
Remove temporary test_output.log file
RyanGlScott Jul 3, 2023
5d4453f
build.sh: Make rlibs a symlink to rlibs_real/.../lib
RyanGlScott Jul 3, 2023
85e59a9
Remove translate_libs.sh
RyanGlScott Jul 3, 2023
a7c2f6d
Make build.sh the new translate_libs.sh
RyanGlScott Jul 3, 2023
4658042
Document inferElidedVariantFields
RyanGlScott Jul 5, 2023
a1c0bbc
report-coverage: Avoid triggering rust-lang/rust#79813 warning
RyanGlScott Jul 5, 2023
352fed4
crux-mir: Add Box stress test
RyanGlScott Jul 5, 2023
ed718aa
CI: Use up-to-date Rust nightly
RyanGlScott Jul 5, 2023
42a3606
crux-mir/lib/Patches.md: Fill in some TODOs
RyanGlScott Jul 5, 2023
ef8fc37
crucible-mir: Parenthesize some equality constraints
RyanGlScott Jul 5, 2023
9ae78ed
crucible-mir: Avoid some failable do-block matches on ST
RyanGlScott Jul 5, 2023
ee39bf0
crucible-mir: More parentheses
RyanGlScott Jul 6, 2023
e0d77af
Use crux::test instead of crux_test
RyanGlScott Jul 7, 2023
c8eb7b6
crucible-mir: Remove some commented-out old code
RyanGlScott Jul 13, 2023
b794aca
crucible-mir: Document reasoning for some evalRval cases
RyanGlScott Jul 13, 2023
8c11bca
crux-mir: Add test case for ConstKind::Unevaluated
RyanGlScott Jul 13, 2023
0afbb96
Properly implement transStatement case for StmtIntrinsic
RyanGlScott Jul 13, 2023
d2ff2cc
crucible-mir: Expunge defaultDisambiguator and anything that uses it
RyanGlScott Jul 13, 2023
331de03
crucible-mir: ShallowInitBox is unsupported for now
RyanGlScott Jul 13, 2023
e8ac077
Bump mir-json submodule
RyanGlScott Jul 13, 2023
0515e64
crux-mir: Use simpler #[crux::test] attribute for symbolic tests
RyanGlScott Jul 13, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Prev Previous commit
Next Next commit
WIP mir-json
- updated libs
- changed crux_mir to crux::mir in tests
- new lib build script (build.sh)
- changes to crux-mir to support changes to rustc (nightly-2023-01-22)
  • Loading branch information
m10f authored and RyanGlScott committed Jul 3, 2023
commit b121efe28fc3b7a96ec5c6be713eef73010a7ba6
13 changes: 8 additions & 5 deletions crucible-mir/src/Mir/GenericOps.hs
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,21 @@ adtIndices (Adt _aname _kind vars _ _ _ _) col = go 0 vars
lastExplicit' = if isExplicit v then discr else lastExplicit
in discr : go lastExplicit' vs

getDiscr _ (Variant name (Explicit did) _fields _knd) = case Map.lookup did (_functions col) of
getDiscr _ (Variant _ _ _ _ (Just i)) = i

getDiscr _ (Variant name (Explicit did) _fields _knd _) = case Map.lookup did (_functions col) of
Just fn -> case fn^.fbody.mblocks of
[ BasicBlock _info (BasicBlockData [Assign _lhs (Use (OpConstant (Constant _ty (ConstInt i)))) _loc] _term) ] ->
( BasicBlock _info (BasicBlockData [Assign _lhs (Use (OpConstant (Constant _ty (ConstInt i)))) _loc] _term) ):_ ->
fromIntegerLit i

_ -> error "enum discriminant constant should only have one basic block"
_ -> error ("enum discriminant constant should only have one basic block [variant id:" ++ show _aname ++ " discr index:" ++ show name ++ "]")

Nothing -> error $ "cannot find discriminant constant " ++ show did ++
" for variant " ++ show name
getDiscr lastExplicit (Variant _vname (Relative i) _fields _kind) =
getDiscr lastExplicit (Variant _vname (Relative i) _fields _kind _) =
lastExplicit + toInteger i

isExplicit (Variant _ (Explicit _) _ _) = True
isExplicit (Variant _ (Explicit _) _ _ _) = True
isExplicit _ = False

--------------------------------------------------------------------------------------
Expand Down Expand Up @@ -155,6 +157,7 @@ instance GenericOps Intrinsic
instance GenericOps Instance
instance GenericOps InstanceKind
instance GenericOps NamedTy
instance GenericOps NonDivergingIntrinsic

-- instances for newtypes
-- we need the deriving strategy 'anyclass' to disambiguate
Expand Down
49 changes: 45 additions & 4 deletions crucible-mir/src/Mir/JSON.hs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,15 @@ instance FromJSON CtorKind where
parseJSON = withObject "CtorKind" $ \v -> case lookupKM "kind" v of
Just (String "Fn") -> pure FnKind
Just (String "Const") -> pure ConstKind
Just (String "Fictive") -> pure FictiveKind
_ -> fail "unspported constructor kind"
instance FromJSON Variant where
parseJSON = withObject "Variant" $ \v -> Variant <$> v .: "name" <*> v .: "discr" <*> v .: "fields" <*> v .: "ctor_kind"
parseJSON = withObject "Variant" $ \v ->
Variant <$> v .: "name"
<*> v .: "discr"
<*> v .: "fields"
<*> v .: "ctor_kind"
<*> do val <- v .:? "discr_value"
convertIntegerText `traverse` val

instance FromJSON Field where
parseJSON = withObject "Field" $ \v -> Field <$> v .: "name" <*> v .: "ty"
Expand Down Expand Up @@ -251,6 +256,19 @@ instance FromJSON Statement where
Just (String "StorageLive") -> StorageLive <$> v .: "slvar"
Just (String "StorageDead") -> StorageDead <$> v .: "sdvar"
Just (String "Nop") -> pure Nop
Just (String "Deinit") -> pure Deinit
Just (String "Intrinsic") -> do
kind <- v .: "intrinsic_kind"
ndi <- case kind of
"Assume" -> NDIAssume <$> v .: "operand"
"CopyNonOverlapping" ->
NDICopyNonOverlapping <$> v .: "src"
<*> v .: "dst"
<*> v .: "count"
_ -> fail $ "unknown Intrinsic kind" ++ kind

return $ StmtIntrinsic ndi

k -> fail $ "kind not found for statement: " ++ show k


Expand Down Expand Up @@ -290,6 +308,8 @@ instance FromJSON Rvalue where
Just (String "UnaryOp") -> UnaryOp <$> v .: "uop" <*> v .: "op"
Just (String "Discriminant") -> Discriminant <$> v .: "val"
Just (String "Aggregate") -> Aggregate <$> v .: "akind" <*> v .: "ops"
Just (String "ShallowInitBox") -> ShallowInitBox <$> v .: "ptr" <*> v .: "ty"
Just (String "CopyForDeref") -> CopyForDeref <$> v .: "place"
k -> fail $ "unsupported RValue " ++ show k

instance FromJSON Terminator where
Expand Down Expand Up @@ -322,7 +342,7 @@ instance FromJSON Operand where
instance FromJSON NullOp where
parseJSON = withObject "NullOp" $ \v -> case lookupKM "kind" v of
Just (String "SizeOf") -> pure SizeOf
Just (String "Box") -> pure Box
Just (String "AlignOf") -> pure AlignOf
x -> fail ("bad nullOp: " ++ show x)

instance FromJSON BorrowKind where
Expand Down Expand Up @@ -374,13 +394,23 @@ instance FromJSON Vtable where

instance FromJSON CastKind where
parseJSON = withObject "CastKind" $ \v -> case lookupKM "kind" v of
Just (String "Misc") -> pure Misc
Just (String "Pointer(ReifyFnPointer)") -> pure ReifyFnPointer
Just (String "Pointer(ClosureFnPointer(Normal))") -> pure ClosureFnPointer
Just (String "Pointer(UnsafeFnPointer)") -> pure UnsafeFnPointer
Just (String "Pointer(Unsize)") -> pure Unsize
Just (String "Pointer(MutToConstPointer)") -> pure MutToConstPointer
Just (String "UnsizeVtable") -> UnsizeVtable <$> v .: "vtable"
-- TODO: actually plumb this information through if it is relevant
-- instead of using Misc
Just (String "PointerExposeAddress") -> pure Misc
Just (String "PointerFromExposedAddress") -> pure Misc
Just (String "DynStar") -> pure Misc
Just (String "IntToInt") -> pure Misc
Just (String "FloatToInt") -> pure Misc
Just (String "FloatToFloat") -> pure Misc
Just (String "IntToFloat") -> pure Misc
Just (String "PtrToPtr") -> pure Misc
Just (String "FnPtrToPtr") -> pure Misc
x -> fail ("bad CastKind: " ++ show x)

instance FromJSON Constant where
Expand Down Expand Up @@ -489,6 +519,17 @@ instance FromJSON RustcRenderedConst where
val <- convertIntegerText =<< v .: "val"
return $ ConstRawPtr val

Just (String "array") -> do
elems <- map (\(RustcRenderedConst val) -> val) <$> v .: "elements"
return $ ConstArray elems

Just (String "tuple") -> do
elems <- map (\(RustcRenderedConst val) -> val) <$> v .: "elements"
return $ ConstArray elems

o -> do
fail $ "parseJSON - bad rendered constant kind: " ++ show o

-- mir-json integers are expressed as strings of 128-bit unsigned values
-- for example, -1 is displayed as "18446744073709551615"
-- we need to parse this as a 128 unsigned bit Int value and then
Expand Down
35 changes: 23 additions & 12 deletions crucible-mir/src/Mir/Mir.hs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,10 @@ data VariantDiscr
data CtorKind
= FnKind
| ConstKind
| FictiveKind
deriving (Eq, Ord, Show, Generic)


data Variant = Variant {_vname :: DefId, _vdiscr :: VariantDiscr, _vfields :: [Field], _vctorkind :: CtorKind}
data Variant = Variant {_vname :: DefId, _vdiscr :: VariantDiscr, _vfields :: [Field], _vctorkind :: Maybe CtorKind, _discrval :: Maybe Integer }
deriving (Eq, Ord,Show, Generic)


Expand Down Expand Up @@ -284,6 +283,13 @@ data Statement =
| StorageLive { _slv :: Var }
| StorageDead { _sdv :: Var }
| Nop
| Deinit
| StmtIntrinsic NonDivergingIntrinsic
deriving (Show,Eq, Ord, Generic)

data NonDivergingIntrinsic =
NDIAssume Operand
| NDICopyNonOverlapping Operand Operand Operand
deriving (Show,Eq, Ord, Generic)

data PlaceElem =
Expand Down Expand Up @@ -321,6 +327,8 @@ data Rvalue =
| Discriminant { _dvar :: Lvalue }
| Aggregate { _ak :: AggregateKind, _ops :: [Operand] }
| RAdtAg AdtAg
| ShallowInitBox { _sibptr :: Operand, _sibty :: Ty }
| CopyForDeref Lvalue
deriving (Show,Eq, Ord, Generic)

data AdtAg = AdtAg { _agadt :: Adt, _avgariant :: Integer, _aops :: [Operand], _adtagty :: Ty }
Expand Down Expand Up @@ -377,7 +385,7 @@ data Operand =

data NullOp =
SizeOf
| Box
| AlignOf
deriving (Show,Eq, Ord, Generic)


Expand Down Expand Up @@ -427,15 +435,16 @@ data Vtable = Vtable
}
deriving (Show, Eq, Ord, Generic)

-- TODO: add other castkinds (see json)
data CastKind =
Misc
| ReifyFnPointer
| ClosureFnPointer
| UnsafeFnPointer
| Unsize
| UnsizeVtable VtableName
| MutToConstPointer
deriving (Show,Eq, Ord, Generic)
Misc
| ReifyFnPointer
| ClosureFnPointer
| UnsafeFnPointer
| Unsize
| UnsizeVtable VtableName
| MutToConstPointer
deriving (Show,Eq, Ord, Generic)

data Constant = Constant Ty ConstVal
deriving (Eq, Ord, Show, Generic)
Expand Down Expand Up @@ -672,7 +681,7 @@ instance TypeOf Rvalue where
in TyTuple [resTy, TyBool]
typeOf (NullaryOp op ty) = case op of
SizeOf -> TyUint USize
Box -> TyAdt (textId "type::adt") (textId "alloc::boxed::Box") (Substs [ty])
AlignOf -> TyUint USize
typeOf (UnaryOp op x) =
let ty = typeOf x
in case op of
Expand All @@ -683,6 +692,8 @@ instance TypeOf Rvalue where
typeOf (Aggregate AKTuple ops) = TyTuple $ map typeOf ops
typeOf (Aggregate AKClosure ops) = TyClosure $ map typeOf ops
typeOf (RAdtAg (AdtAg _ _ _ ty)) = ty
typeOf (ShallowInitBox _ ty) = ty
typeOf (CopyForDeref lv) = typeOf lv

instance TypeOf Operand where
typeOf (Move lv) = typeOf lv
Expand Down
15 changes: 13 additions & 2 deletions crucible-mir/src/Mir/PP.hs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ instance Pretty CtorKind where
pretty = viaShow

instance Pretty Variant where
pretty (Variant nm dscr flds knd) = pretty_fn4 "Variant" nm dscr flds knd
pretty (Variant nm dscr flds knd mbVal) =
pretty "Variant" <>
tupled [pretty nm, pretty dscr, pretty flds, pretty knd, pretty mbVal]

instance Pretty Field where
pretty (Field nm ty) = pretty_fn2 "Field" nm ty
Expand Down Expand Up @@ -164,6 +166,13 @@ instance Pretty Statement where
pretty (StorageLive l) = pretty_fn1 "StorageLive" l <> semi
pretty (StorageDead l) = pretty_fn1 "StorageDead" l <> semi
pretty Nop = pretty "nop" <> semi
pretty Deinit = pretty "DeInit"
pretty (StmtIntrinsic (NDIAssume op)) =
pretty "Intrinsic" <> brackets (pretty "Assume") <> parens (pretty op) <> semi
pretty (StmtIntrinsic (NDICopyNonOverlapping o1 o2 o3)) =
pretty "Intrinsic" <> brackets (pretty "CopyNonOverlapping")
<> tupled (pretty <$> [o1, o2, o3])
<> semi

instance Pretty Lvalue where
pretty (LBase base) = pretty base
Expand Down Expand Up @@ -196,6 +205,8 @@ instance Pretty Rvalue where
pretty (Discriminant a) = pretty_fn1 "Discriminant" a
pretty (Aggregate a b) = pretty_fn2 "Aggregate" a b
pretty (RAdtAg a) = pretty a
pretty (ShallowInitBox ptr ty) = pretty_fn2 "ShallowInitBox" ptr ty
pretty (CopyForDeref lv) = pretty_fn1 "CopyForDeref" lv

instance Pretty AdtAg where
pretty (AdtAg (Adt nm _kind _vs _ _ _ _) i ops _) = pretty_fn3 "AdtAg" nm i ops
Expand Down Expand Up @@ -241,7 +252,7 @@ instance Pretty Constant where

instance Pretty NullOp where
pretty SizeOf = pretty "sizeof"
pretty Box = pretty "box"
pretty AlignOf = pretty "alignof"

instance Pretty BorrowKind where
pretty = viaShow
Expand Down
28 changes: 14 additions & 14 deletions crucible-mir/src/Mir/Trans.hs
Original file line number Diff line number Diff line change
Expand Up @@ -578,19 +578,9 @@ transCheckedBinOp op a b = do

-- Nullary ops in rust are used for resource allocation, so are not interpreted
transNullaryOp :: M.NullOp -> M.Ty -> MirGenerator h s ret (MirExp s)
transNullaryOp M.Box ty = do
-- Box<T> has special translation to ensure that its representation is just
-- an ordinary pointer.
Some tpr <- tyToReprM ty
ptr <- newMirRef tpr
maybeInitVal <- initialValue ty
case maybeInitVal of
Just (MirExp tpr' initVal) -> do
Refl <- testEqualityOrFail tpr tpr' $
"bad initial value for box: expected " ++ show tpr ++ " but got " ++ show tpr'
writeMirRef ptr initVal
Nothing -> return ()
return $ MirExp (MirReferenceRepr tpr) ptr
transNullaryOp M.AlignOf ty = do
-- TODO: return the actual alignment
return $ MirExp UsizeRepr $ R.App $ usizeLit 4
transNullaryOp M.SizeOf _ = do
-- TODO: return the actual size, once mir-json exports size/layout info
return $ MirExp UsizeRepr $ R.App $ usizeLit 1
Expand Down Expand Up @@ -983,6 +973,9 @@ evalRval rv@(M.RAdtAg (M.AdtAg adt agv ops ty)) = do
mirFail $ "evalRval: Union types are unsupported, for " ++ show (adt ^. adtname)
_ -> mirFail $ "evalRval: unsupported type for AdtAg: " ++ show ty

-- TODO: are these correct?
evalRval rv@(M.ShallowInitBox op ty) = evalOperand op
evalRval rv@(M.CopyForDeref lv) = evalLvalue lv
RyanGlScott marked this conversation as resolved.
Show resolved Hide resolved

evalLvalue :: HasCallStack => M.Lvalue -> MirGenerator h s ret (MirExp s)
evalLvalue lv = evalPlace lv >>= readPlace
Expand Down Expand Up @@ -1162,6 +1155,8 @@ transStatement (M.SetDiscriminant lv i) = do
-- simultaneously), then we could remove AllocateEnum.
ty -> mirFail $ "don't know how to set discriminant of " ++ show ty
transStatement M.Nop = return ()
transStatement M.Deinit = return ()
transStatement (M.StmtIntrinsic _) = return () --TODO: is this true?
RyanGlScott marked this conversation as resolved.
Show resolved Hide resolved

-- | Add a new `BranchTransInfo` entry for the current function. Returns the
-- index of the new entry.
Expand Down Expand Up @@ -1464,10 +1459,15 @@ transTerminator (M.DropAndReplace dlv dop dtarg _ dropFn) _ = do
transStatement (M.Assign dlv (M.Use dop) "<dummy pos>")
jumpToBlock dtarg

transTerminator (M.Call (M.OpConstant (M.Constant _ (M.ConstFunction funid))) cargs cretdest _) tr = do
-- transTerminator (M.Call (M.OpConstant (M.Constant _ (M.ConstFunction funid))) cargs cretdest _) tr = do
-- isCustom <- resolveCustom funid
-- doCall funid cargs cretdest tr -- cleanup ignored

RyanGlScott marked this conversation as resolved.
Show resolved Hide resolved
transTerminator (M.Call (M.OpConstant (M.Constant (M.TyFnDef funid) _)) cargs cretdest _) tr = do
isCustom <- resolveCustom funid
doCall funid cargs cretdest tr -- cleanup ignored


transTerminator (M.Call funcOp cargs cretdest _) tr = do
func <- evalOperand funcOp
ret <- callHandle func RustAbi Nothing cargs
Expand Down
4 changes: 2 additions & 2 deletions crucible-mir/src/Mir/TransTy.hs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ reprTransparentFieldTy col adt = do


variantFields :: TransTyConstraint => M.Collection -> M.Variant -> Some C.CtxRepr
variantFields col (M.Variant _vn _vd vfs _vct) =
variantFields col (M.Variant _vn _vd vfs _vct _mbVal) =
tyReprListToCtx
(map (mapSome fieldType . tyToFieldRepr col . (^. M.fty)) vfs)
(\repr -> Some repr)
Expand Down Expand Up @@ -360,7 +360,7 @@ tyToFieldRepr col ty
| otherwise = viewSome (\tpr -> Some $ FieldRepr $ FkMaybe tpr) (tyToRepr col ty)

variantFields' :: TransTyConstraint => M.Collection -> M.Variant -> Some FieldCtxRepr
variantFields' col (M.Variant _vn _vd vfs _vct) =
variantFields' col (M.Variant _vn _vd vfs _vct _mbVal) =
fieldReprListToCtx
(map (tyToFieldRepr col . (^. M.fty)) vfs)
(\x -> Some x)
Expand Down
Loading