Skip to content

Commit

Permalink
Merge branch 'master' into jjcnn/return_path_analysis_exit_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tritao authored Oct 24, 2024
2 parents 35340d3 + be70774 commit 2285dcf
Show file tree
Hide file tree
Showing 18 changed files with 288 additions and 355 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl ty::TyEnumDecl {
impl ty::TyEnumVariant {
pub(crate) fn type_check(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
variant: EnumVariant,
) -> Result<Self, ErrorEmitted> {
let type_engine = ctx.engines.te();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use sway_types::Spanned;
impl ty::TyFunctionParameter {
pub(crate) fn type_check(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
parameter: FunctionParameter,
) -> Result<Self, ErrorEmitted> {
let type_engine = ctx.engines.te();
Expand Down Expand Up @@ -67,7 +67,7 @@ impl ty::TyFunctionParameter {

pub(crate) fn type_check_interface_parameter(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
parameter: &FunctionParameter,
) -> Result<Self, ErrorEmitted> {
let type_engine = ctx.engines.te();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl ty::TyStructDecl {
impl ty::TyStructField {
pub(crate) fn type_check(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
field: StructField,
) -> Result<Self, ErrorEmitted> {
let type_engine = ctx.engines.te();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl ty::TyTraitType {

pub(crate) fn type_check(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
trait_type: parsed::TraitTypeDeclaration,
) -> Result<Self, ErrorEmitted> {
let parsed::TraitTypeDeclaration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl ty::TyVariableDecl {

pub fn type_check(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
var_decl: VariableDeclaration,
) -> Result<Self, ErrorEmitted> {
let engines = &ctx.engines();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ fn type_check_size_of_val(
/// Constraints: None.
fn type_check_size_of_type(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
kind: sway_ast::Intrinsic,
arguments: &[Expression],
type_arguments: &[TypeArgument],
Expand Down Expand Up @@ -710,7 +710,7 @@ fn type_check_size_of_type(
/// Constraints: None.
fn type_check_is_reference_type(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
kind: sway_ast::Intrinsic,
_arguments: &[Expression],
type_arguments: &[TypeArgument],
Expand Down Expand Up @@ -763,7 +763,7 @@ fn type_check_is_reference_type(
/// Constraints: None.
fn type_check_assert_is_str_array(
handler: &Handler,
mut ctx: TypeCheckContext,
ctx: TypeCheckContext,
kind: sway_ast::Intrinsic,
_arguments: &[Expression],
type_arguments: &[TypeArgument],
Expand Down Expand Up @@ -1222,8 +1222,7 @@ fn type_check_state_store_word(
None,
));
let type_argument = type_arguments.first().map(|targ| {
let mut ctx =
ctx.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
let ctx = ctx.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
let initial_type_info = type_engine
.to_typeinfo(targ.type_id, &targ.span)
.map_err(|e| handler.emit_err(e.into()))
Expand Down Expand Up @@ -1318,8 +1317,7 @@ fn type_check_state_quad(
));
let number_of_slots_exp = ty::TyExpression::type_check(handler, ctx.by_ref(), &arguments[2])?;
let type_argument = type_arguments.first().map(|targ| {
let mut ctx =
ctx.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
let ctx = ctx.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
let initial_type_info = type_engine
.to_typeinfo(targ.type_id, &targ.span)
.map_err(|e| handler.emit_err(e.into()))
Expand Down Expand Up @@ -1812,7 +1810,7 @@ fn type_check_smo(

// Type check the type argument
let type_argument = type_arguments.first().map(|targ| {
let mut ctx = ctx
let ctx = ctx
.by_ref()
.with_help_text("")
.with_type_annotation(type_engine.insert(engines, TypeInfo::Unknown, None));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1243,19 +1243,19 @@ impl ty::TyExpression {
let storage_key_ident = Ident::new_with_override("StorageKey".into(), span.clone());

// Search for the struct declaration with the call path above.
let storage_key_decl_opt = ctx
.namespace()
.resolve_root_symbol(
handler,
engines,
&storage_key_mod_path,
&storage_key_ident,
None,
)?
.expect_typed();
let storage_key_struct_decl_ref = storage_key_decl_opt.to_struct_decl(handler, engines)?;
let storage_key_decl = ctx.namespace().root().resolve_symbol(
handler,
engines,
&storage_key_mod_path,
&storage_key_ident,
None,
)?;

let storage_key_struct_decl_id = storage_key_decl
.expect_typed()
.to_struct_decl(handler, engines)?;
let mut storage_key_struct_decl =
(*decl_engine.get_struct(&storage_key_struct_decl_ref)).clone();
(*decl_engine.get_struct(&storage_key_struct_decl_id)).clone();

// Set the type arguments to `StorageKey` to the `access_type`, which is represents the
// type of the data that the `StorageKey` "points" to.
Expand All @@ -1281,7 +1281,7 @@ impl ty::TyExpression {
let storage_key_struct_decl_ref = decl_engine.insert(
storage_key_struct_decl,
decl_engine
.get_parsed_decl_id(&storage_key_struct_decl_ref)
.get_parsed_decl_id(&storage_key_struct_decl_id)
.as_ref(),
);
access_type = type_engine.insert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ pub(crate) fn resolve_method_name(
let mut module_path = call_path.prefixes.clone();
if let (Some(root_mod), root_name) = (
module_path.first().cloned(),
ctx.namespace().root_module_name().clone(),
ctx.namespace().root_module().name().clone(),
) {
if root_mod.as_str() == root_name.as_str() {
module_path.remove(0);
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ pub use contract_helpers::*;
pub use lexical_scope::{Items, LexicalScope, LexicalScopeId, LexicalScopePath};
pub use module::Module;
pub use namespace::Namespace;
pub use namespace::TryInsertingTraitImplOnFailure;
pub use root::ResolvedDeclaration;
pub use root::Root;
pub(super) use trait_map::CodeBlockFirstPass;
pub(super) use trait_map::IsExtendingExistingImpl;
pub(super) use trait_map::IsImplSelf;
pub(super) use trait_map::ResolvedTraitImplItem;
pub(super) use trait_map::TraitMap;
pub use trait_map::TryInsertingTraitImplOnFailure;

use sway_types::Ident;

Expand Down
44 changes: 1 addition & 43 deletions sway-core/src/semantic_analysis/namespace/namespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,12 @@ use super::{
module::Module,
root::{ResolvedDeclaration, Root},
submodule_namespace::SubmoduleNamespace,
trait_map::ResolvedTraitImplItem,
ModulePath, ModulePathBuf,
};

use sway_error::handler::{ErrorEmitted, Handler};
use sway_types::span::Span;

/// Enum used to pass a value asking for insertion of type into trait map when an implementation
/// of the trait cannot be found.
#[derive(Debug)]
pub enum TryInsertingTraitImplOnFailure {
Yes,
No,
}

/// The set of items that represent the namespace context passed throughout type checking.
#[derive(Clone, Debug, Default)]
pub struct Namespace {
Expand Down Expand Up @@ -117,11 +108,6 @@ impl Namespace {
&self.root.module
}

/// The name of the root module
pub fn root_module_name(&self) -> &Ident {
self.root.module.name()
}

/// Access to the current [Module], i.e. the module at the inner `mod_path`.
pub fn module(&self, engines: &Engines) -> &Module {
self.root
Expand All @@ -142,7 +128,7 @@ impl Namespace {
&self,
handler: &Handler,
engines: &Engines,
path: &[Ident],
path: &ModulePath,
) -> Result<&Module, ErrorEmitted> {
self.root.module.lookup_submodule(handler, engines, path)
}
Expand Down Expand Up @@ -203,34 +189,6 @@ impl Namespace {

root_name != &absolute_module_path[0]
}

pub fn get_root_trait_item_for_type(
&self,
handler: &Handler,
engines: &Engines,
name: &Ident,
type_id: TypeId,
as_trait: Option<CallPath>,
) -> Result<ResolvedTraitImplItem, ErrorEmitted> {
self.root
.module
.current_items()
.implemented_traits
.get_trait_item_for_type(handler, engines, name, type_id, as_trait)
}

pub fn resolve_root_symbol(
&self,
handler: &Handler,
engines: &Engines,
mod_path: &ModulePath,
symbol: &Ident,
self_type: Option<TypeId>,
) -> Result<ResolvedDeclaration, ErrorEmitted> {
self.root
.resolve_symbol(handler, engines, mod_path, symbol, self_type)
}

/// Short-hand for calling [Root::resolve_symbol] on `root` with the `mod_path`.
pub(crate) fn resolve_symbol(
&self,
Expand Down
Loading

0 comments on commit 2285dcf

Please sign in to comment.