Struct move_model::model::GlobalEnv
source · pub struct GlobalEnv {
pub module_data: Vec<ModuleData>,
pub used_spec_funs: BTreeSet<QualifiedId<SpecFunId>>,
/* private fields */
}
Expand description
Global Environment
Global environment for a set of modules.
Fields§
§module_data: Vec<ModuleData>
List of loaded modules, in order they have been provided using add
.
used_spec_funs: BTreeSet<QualifiedId<SpecFunId>>
A set containing spec functions which are called/used in specs. Note that these are represented without type instantiation because we assume the backend can handle generics in the expression language.
Implementations§
source§impl GlobalEnv
impl GlobalEnv
sourcepub fn display<'a, T>(&'a self, val: &'a T) -> EnvDisplay<'a, T>
pub fn display<'a, T>(&'a self, val: &'a T) -> EnvDisplay<'a, T>
Creates a display container for the given value. There must be an implementation of fmt::Display for an instance to work in formatting.
sourcepub fn set_extension<T: Any>(&self, x: T)
pub fn set_extension<T: Any>(&self, x: T)
Stores extension data in the environment. This can be arbitrary data which is indexed by type. Used by tools which want to store their own data in the environment, like a set of tool dependent options/flags. This can also be used to update extension data.
sourcepub fn get_extension<T: Any>(&self) -> Option<Rc<T>>
pub fn get_extension<T: Any>(&self) -> Option<Rc<T>>
Retrieves extension data from the environment. Use as in env.get_extension::<T>()
.
An Rc&'a T
) to control borrowing.
sourcepub fn update_extension<T: Any + Clone>(&self, f: impl FnOnce(&mut T))
pub fn update_extension<T: Any + Clone>(&self, f: impl FnOnce(&mut T))
Updates extension data. If they are no outstanding references to this extension it is updated in place, otherwise it will be cloned before the update.
sourcepub fn has_extension<T: Any>(&self) -> bool
pub fn has_extension<T: Any>(&self) -> bool
Checks whether there is an extension of type T
.
sourcepub fn clear_extension<T: Any>(&self) -> Option<Rc<T>>
pub fn clear_extension<T: Any>(&self) -> Option<Rc<T>>
Clear extension data from the environment (return the data if it is previously set).
Use as in env.clear_extension::<T>()
and an Rc<T>
is returned if the extension data is
previously stored in the environment.
sourcepub fn new_global_id(&self) -> GlobalId
pub fn new_global_id(&self) -> GlobalId
Create a new global id unique to this environment.
sourcepub fn symbol_pool(&self) -> &SymbolPool
pub fn symbol_pool(&self) -> &SymbolPool
Returns a reference to the symbol pool owned by this environment.
sourcepub fn add_source(&mut self, file_name: &str, source: &str, is_dep: bool) -> FileId
pub fn add_source(&mut self, file_name: &str, source: &str, is_dep: bool) -> FileId
Adds a source to this environment, returning a FileId for it.
sourcepub fn get_target_modules(&self) -> Vec<ModuleEnv<'_>> ⓘ
pub fn get_target_modules(&self) -> Vec<ModuleEnv<'_>> ⓘ
Find all target modules and return in a vector
sourcepub fn add_documentation(
&mut self,
file_id: FileId,
docs: BTreeMap<ByteIndex, String>
)
pub fn add_documentation( &mut self, file_id: FileId, docs: BTreeMap<ByteIndex, String> )
Adds documentation for a file.
sourcepub fn error_with_notes(&self, loc: &Loc, msg: &str, notes: Vec<String>)
pub fn error_with_notes(&self, loc: &Loc, msg: &str, notes: Vec<String>)
Adds an error to this environment, with notes.
sourcepub fn diag(&self, severity: Severity, loc: &Loc, msg: &str)
pub fn diag(&self, severity: Severity, loc: &Loc, msg: &str)
Adds a diagnostic of given severity to this environment.
sourcepub fn diag_with_notes(
&self,
severity: Severity,
loc: &Loc,
msg: &str,
notes: Vec<String>
)
pub fn diag_with_notes( &self, severity: Severity, loc: &Loc, msg: &str, notes: Vec<String> )
Adds a diagnostic of given severity to this environment, with notes.
sourcepub fn diag_with_labels(
&self,
severity: Severity,
loc: &Loc,
msg: &str,
labels: Vec<(Loc, String)>
)
pub fn diag_with_labels( &self, severity: Severity, loc: &Loc, msg: &str, labels: Vec<(Loc, String)> )
Adds a diagnostic of given severity to this environment, with secondary labels.
sourcepub fn has_diag(&self, pattern: &str) -> bool
pub fn has_diag(&self, pattern: &str) -> bool
Checks whether any of the diagnostics contains string.
sourcepub fn clear_diag(&self)
pub fn clear_diag(&self)
Clear all accumulated diagnosis.
sourcepub fn unknown_loc(&self) -> Loc
pub fn unknown_loc(&self) -> Loc
Returns the unknown location.
sourcepub fn unknown_move_ir_loc(&self) -> MoveIrLoc
pub fn unknown_move_ir_loc(&self) -> MoveIrLoc
Returns a Move IR version of the unknown location which is guaranteed to map to the
regular unknown location via to_loc
.
sourcepub fn internal_loc(&self) -> Loc
pub fn internal_loc(&self) -> Loc
Returns the internal location.
sourcepub fn to_loc(&self, loc: &MoveIrLoc) -> Loc
pub fn to_loc(&self, loc: &MoveIrLoc) -> Loc
Converts a Loc as used by the move-lang compiler to the one we are using here.
TODO: move-lang should use FileId as well so we don’t need this here. There is already
a todo in their code to remove the current use of &'static str
for file names in Loc.
sourcepub fn get_file_id(&self, fname: MoveStringSymbol) -> Option<FileId>
pub fn get_file_id(&self, fname: MoveStringSymbol) -> Option<FileId>
Returns the file id for a file name, if defined.
sourcepub fn file_id_to_idx(&self, file_id: FileId) -> u16
pub fn file_id_to_idx(&self, file_id: FileId) -> u16
Maps a FileId to an index which can be mapped back to a FileId.
sourcepub fn file_idx_to_id(&self, file_idx: u16) -> FileId
pub fn file_idx_to_id(&self, file_idx: u16) -> FileId
Maps a an index which was obtained by file_id_to_idx
back to a FileId.
sourcepub fn get_file_and_location(&self, loc: &Loc) -> Option<(String, Location)>
pub fn get_file_and_location(&self, loc: &Loc) -> Option<(String, Location)>
Returns file name and line/column position for a location, if available.
sourcepub fn get_location(&self, loc: &Loc) -> Option<Location>
pub fn get_location(&self, loc: &Loc) -> Option<Location>
Returns line/column position for a location, if available.
sourcepub fn get_source(&self, loc: &Loc) -> Result<&str, Error>
pub fn get_source(&self, loc: &Loc) -> Result<&str, Error>
Return the source text for the given location.
sourcepub fn get_source_file_names(&self) -> Vec<String> ⓘ
pub fn get_source_file_names(&self) -> Vec<String> ⓘ
Return the source file names.
pub fn get_file_count(&self) -> usize
sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if diagnostics have error severity or worse.
sourcepub fn diag_count(&self, min_severity: Severity) -> usize
pub fn diag_count(&self, min_severity: Severity) -> usize
Returns the number of diagnostics.
sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
Returns the number of errors.
sourcepub fn has_warnings(&self) -> bool
pub fn has_warnings(&self) -> bool
Returns true if diagnostics have warning severity or worse.
sourcepub fn report_diag<W: WriteColor>(&self, writer: &mut W, severity: Severity)
pub fn report_diag<W: WriteColor>(&self, writer: &mut W, severity: Severity)
Writes accumulated diagnostics of given or higher severity.
sourcepub fn add_global_invariant(&mut self, inv: GlobalInvariant)
pub fn add_global_invariant(&mut self, inv: GlobalInvariant)
Adds a global invariant to this environment.
sourcepub fn get_global_invariant(&self, id: GlobalId) -> Option<&GlobalInvariant>
pub fn get_global_invariant(&self, id: GlobalId) -> Option<&GlobalInvariant>
Get global invariant by id.
sourcepub fn get_global_invariants_for_memory(
&self,
memory: &QualifiedInstId<StructId>
) -> BTreeSet<GlobalId>
pub fn get_global_invariants_for_memory( &self, memory: &QualifiedInstId<StructId> ) -> BTreeSet<GlobalId>
Return the global invariants which refer to the given memory.
pub fn get_global_invariants_by_module( &self, module_id: ModuleId ) -> BTreeSet<GlobalId>
sourcepub fn is_spec_fun_used(
&self,
module_id: ModuleId,
spec_fun_id: SpecFunId
) -> bool
pub fn is_spec_fun_used( &self, module_id: ModuleId, spec_fun_id: SpecFunId ) -> bool
Returns true if a spec fun is used in specs.
sourcepub fn is_wellknown_event_handle_type(&self, ty: &Type) -> bool
pub fn is_wellknown_event_handle_type(&self, ty: &Type) -> bool
Returns true if the type represents the well-known event handle type.
sourcepub fn add(
&mut self,
loc: Loc,
module: CompiledModule,
source_map: SourceMap,
named_constants: BTreeMap<NamedConstantId, NamedConstantData>,
struct_data: BTreeMap<StructId, StructData>,
function_data: BTreeMap<FunId, FunctionData>,
spec_vars: Vec<SpecVarDecl>,
spec_funs: Vec<SpecFunDecl>,
module_spec: Spec,
spec_block_infos: Vec<SpecBlockInfo>
)
pub fn add( &mut self, loc: Loc, module: CompiledModule, source_map: SourceMap, named_constants: BTreeMap<NamedConstantId, NamedConstantData>, struct_data: BTreeMap<StructId, StructData>, function_data: BTreeMap<FunId, FunctionData>, spec_vars: Vec<SpecVarDecl>, spec_funs: Vec<SpecFunDecl>, module_spec: Spec, spec_block_infos: Vec<SpecBlockInfo> )
Adds a new module to the environment. StructData and FunctionData need to be provided
in definition index order. See create_function_data
and create_struct_data
for how
to create them.
sourcepub fn create_named_constant_data(
&self,
name: Symbol,
loc: Loc,
typ: Type,
value: Value
) -> NamedConstantData
pub fn create_named_constant_data( &self, name: Symbol, loc: Loc, typ: Type, value: Value ) -> NamedConstantData
Creates data for a named constant.
sourcepub fn create_function_data(
&self,
module: &CompiledModule,
def_idx: FunctionDefinitionIndex,
name: Symbol,
loc: Loc,
arg_names: Vec<Symbol>,
type_arg_names: Vec<Symbol>,
spec: Spec
) -> FunctionData
pub fn create_function_data( &self, module: &CompiledModule, def_idx: FunctionDefinitionIndex, name: Symbol, loc: Loc, arg_names: Vec<Symbol>, type_arg_names: Vec<Symbol>, spec: Spec ) -> FunctionData
Creates data for a function, adding any information not contained in bytecode. This is a helper for adding a new module to the environment.
sourcepub fn create_struct_data(
&self,
module: &CompiledModule,
def_idx: StructDefinitionIndex,
name: Symbol,
loc: Loc,
spec: Spec
) -> StructData
pub fn create_struct_data( &self, module: &CompiledModule, def_idx: StructDefinitionIndex, name: Symbol, loc: Loc, spec: Spec ) -> StructData
Creates data for a struct. Currently all information is contained in the byte code. This is a helper for adding a new module to the environment.
sourcepub fn find_module(&self, name: &ModuleName) -> Option<ModuleEnv<'_>>
pub fn find_module(&self, name: &ModuleName) -> Option<ModuleEnv<'_>>
Finds a module by name and returns an environment for it.
sourcepub fn find_module_by_name(&self, simple_name: Symbol) -> Option<ModuleEnv<'_>>
pub fn find_module_by_name(&self, simple_name: Symbol) -> Option<ModuleEnv<'_>>
Finds a module by simple name and returns an environment for it. TODO: we may need to disallow this to support modules of the same simple name but with different addresses in one verification session.
sourcepub fn find_module_by_language_storage_id(
&self,
id: &ModuleId
) -> Option<ModuleEnv<'_>>
pub fn find_module_by_language_storage_id( &self, id: &ModuleId ) -> Option<ModuleEnv<'_>>
Find a module by its bytecode format ID
sourcepub fn find_function_by_language_storage_id_name(
&self,
id: &ModuleId,
name: &Identifier
) -> Option<FunctionEnv<'_>>
pub fn find_function_by_language_storage_id_name( &self, id: &ModuleId, name: &Identifier ) -> Option<FunctionEnv<'_>>
Find a function by its bytecode format name and ID
sourcepub fn find_struct_by_tag(
&self,
tag: &StructTag
) -> Option<QualifiedId<StructId>>
pub fn find_struct_by_tag( &self, tag: &StructTag ) -> Option<QualifiedId<StructId>>
Gets a StructEnv in this module by its StructTag
sourcepub fn get_enclosing_module(&self, loc: &Loc) -> Option<ModuleEnv<'_>>
pub fn get_enclosing_module(&self, loc: &Loc) -> Option<ModuleEnv<'_>>
Return the module enclosing this location.
sourcepub fn get_enclosing_function(&self, loc: &Loc) -> Option<FunctionEnv<'_>>
pub fn get_enclosing_function(&self, loc: &Loc) -> Option<FunctionEnv<'_>>
Returns the function enclosing this location.
sourcepub fn get_enclosing_struct(&self, loc: &Loc) -> Option<StructEnv<'_>>
pub fn get_enclosing_struct(&self, loc: &Loc) -> Option<StructEnv<'_>>
Returns the struct enclosing this location.
sourcepub fn get_function(&self, fun: QualifiedId<FunId>) -> FunctionEnv<'_>
pub fn get_function(&self, fun: QualifiedId<FunId>) -> FunctionEnv<'_>
Return the FunctionEnv
for fun
sourcepub fn get_struct(&self, str: QualifiedId<StructId>) -> StructEnv<'_>
pub fn get_struct(&self, str: QualifiedId<StructId>) -> StructEnv<'_>
Return the StructEnv
for str
pub fn get_module_count(&self) -> usize
sourcepub fn get_module(&self, id: ModuleId) -> ModuleEnv<'_>
pub fn get_module(&self, id: ModuleId) -> ModuleEnv<'_>
Gets a module by id.
sourcepub fn get_struct_qid(&self, qid: QualifiedId<StructId>) -> StructEnv<'_>
pub fn get_struct_qid(&self, qid: QualifiedId<StructId>) -> StructEnv<'_>
Gets a struct by qualified id.
sourcepub fn get_function_qid(&self, qid: QualifiedId<FunId>) -> FunctionEnv<'_>
pub fn get_function_qid(&self, qid: QualifiedId<FunId>) -> FunctionEnv<'_>
Gets a function by qualified id.
sourcepub fn get_modules(&self) -> impl Iterator<Item = ModuleEnv<'_>>
pub fn get_modules(&self) -> impl Iterator<Item = ModuleEnv<'_>>
Returns an iterator for all modules in the environment.
sourcepub fn get_bytecode_modules(&self) -> impl Iterator<Item = &CompiledModule>
pub fn get_bytecode_modules(&self) -> impl Iterator<Item = &CompiledModule>
Returns an iterator for all bytecode modules in the environment.
sourcepub fn get_all_structs_with_conditions(&self) -> Vec<Type> ⓘ
pub fn get_all_structs_with_conditions(&self) -> Vec<Type> ⓘ
Returns all structs in all modules which carry invariants.
sourcepub fn is_property_true(
&self,
properties: &PropertyBag,
name: &str
) -> Option<bool>
pub fn is_property_true( &self, properties: &PropertyBag, name: &str ) -> Option<bool>
Returns true if the boolean property is true.
sourcepub fn get_num_property(
&self,
properties: &PropertyBag,
name: &str
) -> Option<usize>
pub fn get_num_property( &self, properties: &PropertyBag, name: &str ) -> Option<usize>
Returns the value of a number property.
sourcepub fn get_struct_tag(
&self,
mid: ModuleId,
sid: StructId,
ts: &[Type]
) -> Option<StructTag>
pub fn get_struct_tag( &self, mid: ModuleId, sid: StructId, ts: &[Type] ) -> Option<StructTag>
Attempt to compute a struct tag for (mid
, sid
, ts
). Returns Some
if all types in
ts
are closed, None
otherwise
sourcepub fn get_struct_type(&self, mid: ModuleId, sid: StructId, ts: &[Type]) -> MType
pub fn get_struct_type(&self, mid: ModuleId, sid: StructId, ts: &[Type]) -> MType
Attempt to compute a struct type for (mid
, sid
, ts
).
sourcepub fn get_node_loc(&self, node_id: NodeId) -> Loc
pub fn get_node_loc(&self, node_id: NodeId) -> Loc
Gets the location of the given node.
sourcepub fn get_node_type(&self, node_id: NodeId) -> Type
pub fn get_node_type(&self, node_id: NodeId) -> Type
Gets the type of the given node.
sourcepub fn get_node_type_opt(&self, node_id: NodeId) -> Option<Type>
pub fn get_node_type_opt(&self, node_id: NodeId) -> Option<Type>
Gets the type of the given node, if available.
sourcepub fn index_to_node_id(&self, index: usize) -> Option<NodeId>
pub fn index_to_node_id(&self, index: usize) -> Option<NodeId>
Converts an index into a node id.
sourcepub fn next_free_node_number(&self) -> usize
pub fn next_free_node_number(&self) -> usize
Returns the next free node number.
sourcepub fn new_node_id(&self) -> NodeId
pub fn new_node_id(&self) -> NodeId
Allocates a new node id.
sourcepub fn new_node(&self, loc: Loc, ty: Type) -> NodeId
pub fn new_node(&self, loc: Loc, ty: Type) -> NodeId
Allocates a new node id and assigns location and type to it.
sourcepub fn update_node_type(&self, node_id: NodeId, ty: Type)
pub fn update_node_type(&self, node_id: NodeId, ty: Type)
Updates type for the given node id. Must have been set before.
sourcepub fn set_node_instantiation(&self, node_id: NodeId, instantiation: Vec<Type>)
pub fn set_node_instantiation(&self, node_id: NodeId, instantiation: Vec<Type>)
Sets instantiation for the given node id. Must not have been set before.
sourcepub fn update_node_instantiation(&self, node_id: NodeId, instantiation: Vec<Type>)
pub fn update_node_instantiation(&self, node_id: NodeId, instantiation: Vec<Type>)
Updates instantiation for the given node id. Must have been set before.