Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@ fn connect_declaration<'eng: 'cfg, 'cfg>(
Ok(Some(entry_node))
}
ty::TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// connect_declaration is only called from AstNode,
// from where a ConstGenericDecl is not reacheable
unreachable!()
}
ty::TyDecl::FunctionDecl(ty::FunctionDecl { decl_id, .. }) => {
let fn_decl = decl_engine.get_function(decl_id);
Expand Down
8 changes: 6 additions & 2 deletions sway-core/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,9 @@ fn connect_declaration<'eng: 'cfg, 'cfg>(
}
}
ty::TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860");
//This is only called from AstNode
// where a ConstGenericDecl is unreacheable
unreachable!()
}
ty::TyDecl::FunctionDecl(ty::FunctionDecl { decl_id, .. }) => {
let fn_decl = decl_engine.get_function(decl_id);
Expand Down Expand Up @@ -2589,7 +2591,9 @@ fn allow_dead_code_ast_node(decl_engine: &DeclEngine, node: &ty::TyAstNode) -> b
allow_dead_code(decl_engine.get_configurable(decl_id).attributes.clone())
}
ty::TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// only called from AstNode from where
// ConstGenericDecl is unreacheable
unreachable!()
}
ty::TyDecl::TraitTypeDecl(ty::TraitTypeDecl { decl_id, .. }) => {
allow_dead_code(decl_engine.get_type(decl_id).attributes.clone())
Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/ir_generation/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,8 @@ impl<'a> FnCompiler<'a> {
unreachable!()
}
ty::TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// ConstGenericDecl is not reacheable from AstNode
unreachable!()
}
ty::TyDecl::EnumDecl(ty::EnumDecl { decl_id, .. }) => {
let ted = self.engines.de().get_enum(decl_id);
Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/language/parsed/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ impl Declaration {
| Declaration::TraitTypeDeclaration(_)
| Declaration::TraitFnDeclaration(_) => Visibility::Public,
Declaration::ConstGenericDeclaration(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// const generics do not have visibility
unreachable!()
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions sway-core/src/language/ty/ast_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ impl TyAstNode {
}
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// Const generics are not reacheable from AstNode
unreachable!()
}
TyDecl::TraitTypeDecl(_) => {}
TyDecl::FunctionDecl(decl) => {
Expand Down Expand Up @@ -336,7 +337,8 @@ impl TyAstNode {
TyDecl::ConstantDecl(_decl) => {}
TyDecl::ConfigurableDecl(_decl) => {}
TyDecl::ConstGenericDecl(_decl) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// Const generics are not reachable from AstNode
unreachable!()
}
TyDecl::TraitTypeDecl(_) => {}
TyDecl::FunctionDecl(decl) => {
Expand Down
27 changes: 19 additions & 8 deletions sway-core/src/language/ty/declaration/const_generic.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::hash::{Hash as _, Hasher};

use crate::{
decl_engine::MaterializeConstGenerics,
engine_threading::HashWithEngines,
has_changes,
language::{parsed::ConstGenericDeclaration, ty::TyExpression, CallPath},
semantic_analysis::{TypeCheckAnalysis, TypeCheckAnalysisContext},
HasChanges, SubstTypes, TypeId,
Engines, HasChanges, SubstTypes, TypeId,
};
use serde::{Deserialize, Serialize};
use sway_error::handler::{ErrorEmitted, Handler};
use sway_types::{BaseIdent, Ident, Named, Span, Spanned};
use sway_types::{Ident, Named, Span, Spanned};

use super::TyDeclParsedType;

Expand All @@ -19,6 +22,20 @@ pub struct TyConstGenericDecl {
pub value: Option<TyExpression>,
}

impl HashWithEngines for TyConstGenericDecl {
fn hash<H: Hasher>(&self, state: &mut H, engines: &Engines) {
let type_engine = engines.te();
let TyConstGenericDecl {
call_path,
return_type,
span: _,
value: _,
} = self;
call_path.hash(state);
type_engine.get(*return_type).hash(state, engines);
}
}

impl SubstTypes for TyConstGenericDecl {
fn subst_inner(&mut self, ctx: &crate::SubstTypesContext) -> crate::HasChanges {
has_changes! {
Expand Down Expand Up @@ -76,12 +93,6 @@ impl TypeCheckAnalysis for TyConstGenericDecl {
}
}

impl TyConstGenericDecl {
pub fn name(&self) -> &BaseIdent {
&self.call_path.suffix
}
}

impl Named for TyConstGenericDecl {
fn name(&self) -> &Ident {
&self.call_path.suffix
Expand Down
24 changes: 11 additions & 13 deletions sway-core/src/language/ty/declaration/declaration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ impl HashWithEngines for TyDecl {
TyDecl::ConfigurableDecl(ConfigurableDecl { decl_id, .. }) => {
decl_engine.get(decl_id).hash(state, engines);
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
TyDecl::ConstGenericDecl(ConstGenericDecl { decl_id }) => {
decl_engine.get(decl_id).hash(state, engines);
}
TyDecl::TraitTypeDecl(TraitTypeDecl { decl_id, .. }) => {
decl_engine.get(decl_id).hash(state, engines);
Expand Down Expand Up @@ -293,9 +293,7 @@ impl SubstTypes for TyDecl {
| TyDecl::StorageDecl(_)
| TyDecl::GenericTypeForFunctionScope(_)
| TyDecl::ErrorRecovery(..) => HasChanges::No,
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
}
TyDecl::ConstGenericDecl(_) => HasChanges::No,
}
}
}
Expand All @@ -311,8 +309,9 @@ impl SpannedWithEngines for TyDecl {
let decl = engines.de().get(decl_id);
decl.span.clone()
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
TyDecl::ConstGenericDecl(ConstGenericDecl { decl_id }) => {
let decl = engines.de().get(decl_id);
decl.span.clone()
}
TyDecl::TraitTypeDecl(TraitTypeDecl { decl_id }) => {
engines.de().get_type(decl_id).span.clone()
Expand Down Expand Up @@ -501,9 +500,7 @@ impl CollectTypesMetadata for TyDecl {
return Ok(vec![]);
}
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
}
TyDecl::ConstGenericDecl(_) => return Ok(vec![]),
TyDecl::ErrorRecovery(..)
| TyDecl::StorageDecl(_)
| TyDecl::TraitDecl(_)
Expand All @@ -529,8 +526,8 @@ impl GetDeclIdent for TyDecl {
TyDecl::ConfigurableDecl(ConfigurableDecl { decl_id }) => {
Some(engines.de().get_configurable(decl_id).name().clone())
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
TyDecl::ConstGenericDecl(ConstGenericDecl { decl_id }) => {
Some(engines.de().get_const_generic(decl_id).name().clone())
}
TyDecl::TraitTypeDecl(TraitTypeDecl { decl_id }) => {
Some(engines.de().get_type(decl_id).name().clone())
Expand Down Expand Up @@ -915,7 +912,8 @@ impl TyDecl {
decl_engine.get_configurable(decl_id).visibility
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// const generics do not have visibility
unreachable!()
}
TyDecl::StructDecl(StructDecl { decl_id, .. }) => {
decl_engine.get_struct(decl_id).visibility
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/expression/expression_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,8 @@ impl DisplayWithEngines for TyExpressionVariant {
impl DebugWithEngines for TyExpressionVariant {
fn fmt(&self, f: &mut fmt::Formatter<'_>, engines: &Engines) -> fmt::Result {
let s = match self {
TyExpressionVariant::ConstGenericExpression { .. } => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
TyExpressionVariant::ConstGenericExpression { call_path, .. } => {
format!("const generics {}", call_path.span().as_str())
}
TyExpressionVariant::Literal(lit) => format!("literal {lit}"),
TyExpressionVariant::FunctionApplication {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,12 @@ impl TyDecl {
ty: GenericArgument::Type(GenericTypeArgument {
initial_type_id: ty.initial_type_id(),
type_id: new_ty,
call_path_tree: ty.call_path_tree().cloned(),
call_path_tree: ty
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
span: ty.span(),
}),
visibility: decl.visibility,
Expand All @@ -553,7 +558,9 @@ impl TyDecl {
unreachable!();
}
parsed::Declaration::ConstGenericDeclaration(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// This is called from AstNode and auto_impl
// both will never ask for a const generic decl
unreachable!()
}
};

Expand All @@ -580,7 +587,9 @@ impl TypeCheckAnalysis for TyDecl {
const_decl.type_check_analyze(handler, ctx)?;
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// Only called from AstNode, from where
// const generics are unreachable
unreachable!()
}
TyDecl::FunctionDecl(node) => {
let fn_decl = ctx.engines.de().get_function(&node.decl_id);
Expand Down Expand Up @@ -640,7 +649,9 @@ impl TypeCheckFinalization for TyDecl {
config_decl.type_check_finalize(handler, ctx)?;
}
TyDecl::ConstGenericDecl(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
// Only called from AstNode from where
// const generics are unreachable
unreachable!()
}
TyDecl::FunctionDecl(node) => {
let mut fn_decl = (*ctx.engines.de().get_function(&node.decl_id)).clone();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,12 @@ fn type_check_size_of_type(
type_id,
initial_type_id,
span: targ.span(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})],
span,
};
Expand Down Expand Up @@ -745,7 +750,12 @@ fn type_check_is_reference_type(
type_id,
initial_type_id,
span: targ.span(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})],
span,
};
Expand Down Expand Up @@ -795,7 +805,12 @@ fn type_check_assert_is_str_array(
type_id,
initial_type_id,
span: targ.span(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})],
span,
};
Expand Down Expand Up @@ -975,7 +990,12 @@ fn type_check_gtf(
type_id,
initial_type_id,
span: targ.span(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})],
span,
},
Expand Down Expand Up @@ -1184,7 +1204,12 @@ fn type_check_state_store_word(
type_id,
initial_type_id,
span: span.clone(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})
});
let intrinsic_function = ty::TyIntrinsicFunctionKind {
Expand Down Expand Up @@ -1275,7 +1300,12 @@ fn type_check_state_quad(
type_id,
initial_type_id,
span: span.clone(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})
});
let intrinsic_function = ty::TyIntrinsicFunctionKind {
Expand Down Expand Up @@ -1692,7 +1722,12 @@ fn type_check_ptr_ops(
type_id,
initial_type_id,
span: targ.span(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})],
span,
},
Expand Down Expand Up @@ -1756,7 +1791,12 @@ fn type_check_smo(
type_id,
initial_type_id,
span: span.clone(),
call_path_tree: targ.call_path_tree().cloned(),
call_path_tree: targ
.as_type_argument()
.unwrap()
.call_path_tree
.as_ref()
.cloned(),
})
});

Expand Down
6 changes: 2 additions & 4 deletions sway-core/src/semantic_analysis/node_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ fn depends_on(
// -------------------------------------------------------------------------------------------------
// Dependencies are just a collection of dependee symbols.

#[derive(Debug)]
#[derive(Debug, Default)]
struct Dependencies {
deps: DependencySet,
}
Expand Down Expand Up @@ -482,9 +482,7 @@ impl Dependencies {
let TypeAliasDeclaration { ty, .. } = &*engines.pe().get_type_alias(decl_id);
self.gather_from_type_argument(engines, ty)
}
Declaration::ConstGenericDeclaration(_) => {
todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860")
}
Declaration::ConstGenericDeclaration(_) => Dependencies::default(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/symbol_resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ impl ResolveSymbols for TypeAliasDeclaration {

impl ResolveSymbols for GenericArgument {
fn resolve_symbols(&mut self, handler: &Handler, ctx: SymbolResolveContext) {
if let Some(call_path) = self.call_path_tree_mut() {
if let Some(call_path) = self.as_type_argument_mut().unwrap().call_path_tree.as_mut() {
call_path.resolve_symbols(handler, ctx);
}
}
Expand Down
Loading
Loading