use add_unknown_with

This commit is contained in:
Folkert 2021-05-17 19:51:46 +02:00
parent c5bd06db66
commit 925355eb4e
3 changed files with 33 additions and 8 deletions

View file

@ -271,10 +271,17 @@ fn call_spec(
} => todo!(), } => todo!(),
Foreign { Foreign {
foreign_symbol: _, foreign_symbol: _,
ret_layout: _, ret_layout,
} => { } => {
// NOTE foreign functions are those exposed by the platform let arguments: Vec<_> = call
todo!() .arguments
.iter()
.map(|symbol| env.symbols[symbol])
.collect();
let result_type = layout_spec(builder, ret_layout)?;
builder.add_unknown_with(block, &arguments, result_type)
} }
LowLevel { op, update_mode } => lowlevel_spec( LowLevel { op, update_mode } => lowlevel_spec(
builder, builder,

View file

@ -467,15 +467,27 @@ impl FuncDefBuilder {
block block
} }
/// Add an expression with unknown semantics to a block. /// Add an expression with unknown semantics to a block, operating on a given set of values.
/// ///
/// The analysis engine will conservatively treat this expression as if it could perform any /// The analysis engine will conservatively treat this expression as if it could perform any
/// operation expressible in the modeling language except in-place mutations. /// operation expressible in the modeling language mentioning `args`, except in-place mutations.
///
/// The analysis engine will not consider any possible behaviors which would require access to
/// values in scope not appearing in `args`, or which would require access to any join point in
/// scope.
/// ///
/// This will significantly limit optimizations, but could be useful for prototyping. /// This will significantly limit optimizations, but could be useful for prototyping.
pub fn add_unknown(&mut self, block: BlockId, result_type: TypeId) -> Result<ValueId> { pub fn add_unknown_with(
&mut self,
block: BlockId,
args: &[ValueId],
result_type: TypeId,
) -> Result<ValueId> {
self.check_bid(block)?; self.check_bid(block)?;
self.check_tid(result_type)?; self.check_tid(result_type)?;
for &arg in args {
self.check_vid(arg)?;
}
Ok(ValueId(self.vid_gen.next())) Ok(ValueId(self.vid_gen.next()))
} }

View file

@ -264,13 +264,19 @@ pub unsafe extern "C" fn Morphic_FuncDefBuilder_AddBlock(
} }
#[no_mangle] #[no_mangle]
pub unsafe extern "C" fn Morphic_FuncDefBuilder_AddUnknown( pub unsafe extern "C" fn Morphic_FuncDefBuilder_AddUnknownWith(
self_: *mut FuncDefBuilder, self_: *mut FuncDefBuilder,
block: BlockId, block: BlockId,
args: *const ValueId,
args_len: usize,
result_type: TypeId, result_type: TypeId,
out: *mut ValueId, out: *mut ValueId,
) -> *mut Error { ) -> *mut Error {
*out = check_err!((*self_).add_unknown(block, result_type)); *out = check_err!((*self_).add_unknown_with(
block,
slice::from_raw_parts(args, args_len),
result_type
));
ptr::null_mut() ptr::null_mut()
} }