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

Move TypeArgument, TypeParameter, and TraitConstraints to be conceptually inside of the type engine #2074

Merged
merged 3 commits into from Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions sway-core/src/convert_parse_tree.rs
@@ -1,3 +1,5 @@
use crate::type_engine::{TraitConstraint, TypeArgument, TypeParameter};

use {
crate::{
constants::{
Expand All @@ -11,9 +13,8 @@ use {
ImportType, IncludeStatement, IntrinsicFunctionKind, LazyOp, Literal, MatchBranch,
MethodName, ParseTree, Purity, Reassignment, ReassignmentTarget, ReturnStatement,
Scrutinee, StorageDeclaration, StorageField, StructDeclaration, StructExpressionField,
StructField, StructScrutineeField, Supertrait, TraitConstraint, TraitDeclaration, TraitFn,
TreeType, TypeArgument, TypeInfo, TypeParameter, UseStatement, VariableDeclaration,
Visibility, WhileLoop,
StructField, StructScrutineeField, Supertrait, TraitDeclaration, TraitFn, TreeType,
TypeInfo, UseStatement, VariableDeclaration, Visibility, WhileLoop,
},
std::{
collections::HashMap,
Expand Down
4 changes: 0 additions & 4 deletions sway-core/src/parse_tree/declaration.rs
Expand Up @@ -7,8 +7,6 @@ mod reassignment;
mod storage;
mod r#struct;
mod r#trait;
mod type_argument;
mod type_parameter;
mod variable;

pub(crate) use abi::*;
Expand All @@ -20,8 +18,6 @@ pub use r#struct::*;
pub use r#trait::*;
pub(crate) use reassignment::*;
pub use storage::*;
pub(crate) use type_argument::*;
pub(crate) use type_parameter::*;
pub use variable::*;

#[derive(Debug, Clone)]
Expand Down
5 changes: 1 addition & 4 deletions sway-core/src/parse_tree/declaration/enum.rs
@@ -1,7 +1,4 @@
use crate::{
parse_tree::{declaration::TypeParameter, Visibility},
type_engine::*,
};
use crate::{parse_tree::Visibility, type_engine::*};

use sway_types::{ident::Ident, span::Span};

Expand Down
7 changes: 5 additions & 2 deletions sway-core/src/parse_tree/declaration/impl_trait.rs
@@ -1,5 +1,8 @@
use super::{FunctionDeclaration, TypeParameter};
use crate::{parse_tree::CallPath, type_engine::TypeInfo};
use super::FunctionDeclaration;
use crate::{
parse_tree::CallPath,
type_engine::{TypeInfo, TypeParameter},
};

use sway_types::span::Span;

Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/parse_tree/declaration/struct.rs
@@ -1,6 +1,6 @@
use crate::{
parse_tree::{declaration::TypeParameter, Visibility},
type_engine::TypeInfo,
parse_tree::Visibility,
type_engine::{TypeInfo, TypeParameter},
};

use sway_types::{ident::Ident, span::Span};
Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/parse_tree/expression/mod.rs
@@ -1,6 +1,7 @@
use crate::{
parse_tree::{CallPath, Literal},
CodeBlock, TypeArgument,
type_engine::TypeArgument,
CodeBlock,
};
use sway_types::{ident::Ident, Span, Spanned};

Expand Down
3 changes: 2 additions & 1 deletion sway-core/src/semantic_analysis/ast_node/declaration/enum.rs
Expand Up @@ -4,7 +4,8 @@ use crate::{
parse_tree::*,
semantic_analysis::*,
type_engine::{
insert_type, look_up_type_id, CopyTypes, CreateTypeId, ReplaceSelfType, TypeId, TypeMapping,
insert_type, look_up_type_id, CopyTypes, CreateTypeId, ReplaceSelfType, TypeId,
TypeMapping, TypeParameter,
},
types::{JsonAbiString, ToJsonAbi},
TypeInfo,
Expand Down
29 changes: 3 additions & 26 deletions sway-core/src/semantic_analysis/ast_node/declaration/impl_trait.rs
Expand Up @@ -6,10 +6,11 @@ use crate::{
error::{err, ok},
semantic_analysis::{Mode, TypeCheckContext},
type_engine::{
insert_type, look_up_type_id, resolve_type, unify_with_self, CopyTypes, TypeId, TypeMapping,
insert_type, look_up_type_id, resolve_type, unify_with_self, CopyTypes, TypeId,
TypeMapping, TypeParameter,
},
CallPath, CompileError, CompileResult, FunctionDeclaration, ImplSelf, ImplTrait, Purity,
TypeInfo, TypeParameter, TypedDeclaration, TypedFunctionDeclaration,
TypeInfo, TypedDeclaration, TypedFunctionDeclaration,
};

use super::TypedTraitFn;
Expand Down Expand Up @@ -85,18 +86,6 @@ impl TypedImplTrait {
errors
);

// check for unconstrained type parameters
check!(
emilyaherbert marked this conversation as resolved.
Show resolved Hide resolved
check_for_unconstrained_type_parameters(
&new_type_parameters,
implementing_for_type_id,
&type_implementing_for_span
),
return err(warnings, errors),
warnings,
errors
);

// Update the context with the new `self` type.
let ctx = ctx.with_self_type(implementing_for_type_id);

Expand Down Expand Up @@ -247,18 +236,6 @@ impl TypedImplTrait {
errors
);

// check for unconstrained type parameters
check!(
check_for_unconstrained_type_parameters(
&new_type_parameters,
implementing_for_type_id,
&type_implementing_for_span
),
return err(warnings, errors),
warnings,
errors
);

let mut ctx = ctx
.with_self_type(implementing_for_type_id)
.with_help_text("")
Expand Down
@@ -1,9 +1,6 @@
use sway_types::{Ident, Span, Spanned};

use crate::{
error::*, namespace::*, type_engine::*, CompileError, CompileResult, TypeArgument, TypeInfo,
TypeParameter,
};
use crate::{error::*, namespace::*, type_engine::*, CompileError, CompileResult, TypeInfo};

use super::CreateTypeId;

Expand Down
@@ -1,15 +1,11 @@
use sway_types::{Ident, Span, Spanned};

use crate::semantic_analysis::{
declaration::EnforceTypeArguments, TypeCheckContext, TypedEnumVariant,
};
use crate::type_engine::CreateTypeId;
use crate::{
error::{err, ok},
type_engine::{insert_type, TypeId},
CompileResult, Literal, Scrutinee, TypeArgument, TypeInfo,
semantic_analysis::{declaration::EnforceTypeArguments, TypeCheckContext, TypedEnumVariant},
type_engine::{insert_type, CreateTypeId, TypeArgument, TypeId},
CompileError, CompileResult, Literal, Scrutinee, StructScrutineeField, TypeInfo,
};
use crate::{CompileError, StructScrutineeField};

#[derive(Debug, Clone)]
pub(crate) struct TypedScrutinee {
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/semantic_analysis/namespace/namespace.rs
Expand Up @@ -4,7 +4,7 @@ use crate::{
declaration::{EnforceTypeArguments, Monomorphize, MonomorphizeHelper},
},
type_engine::*,
CallPath, CompileResult, Ident, TypeArgument, TypedDeclaration, TypedFunctionDeclaration,
CallPath, CompileResult, Ident, TypedDeclaration, TypedFunctionDeclaration,
};

use super::{module::Module, root::Root, submodule_namespace::SubmoduleNamespace, Path, PathBuf};
Expand Down
1 change: 1 addition & 0 deletions sway-core/src/semantic_analysis/node_dependencies.rs
@@ -1,6 +1,7 @@
use std::collections::{HashMap, HashSet};
use std::iter::FromIterator;

use crate::type_engine::{TypeArgument, TypeParameter};
use crate::{
error::*,
parse_tree::*,
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/semantic_analysis/type_check_context.rs
Expand Up @@ -5,8 +5,8 @@ use crate::{
declaration::{EnforceTypeArguments, MonomorphizeHelper},
Namespace,
},
type_engine::{insert_type, unify_with_self, TypeId, TypeInfo},
CompileResult, CompileWarning, TypeArgument, TypeError,
type_engine::{insert_type, unify_with_self, TypeArgument, TypeId, TypeInfo},
CompileResult, CompileWarning, TypeError,
};
use sway_types::{span::Span, Ident, Spanned};

Expand Down
6 changes: 6 additions & 0 deletions sway-core/src/type_engine/mod.rs
Expand Up @@ -4,9 +4,12 @@ mod engine;
mod integer_bits;
mod replace_self_type;
mod resolved_type;
mod trait_constraint;
mod type_argument;
mod type_id;
mod type_info;
mod type_mapping;
mod type_parameter;
mod unresolved_type_check;

pub(crate) use copy_types::*;
Expand All @@ -15,9 +18,12 @@ pub use engine::*;
pub use integer_bits::*;
pub(crate) use replace_self_type::*;
pub(crate) use resolved_type::*;
pub(crate) use trait_constraint::*;
pub(crate) use type_argument::*;
pub use type_id::*;
pub use type_info::*;
pub(crate) use type_mapping::*;
pub(crate) use type_parameter::*;
pub(crate) use unresolved_type_check::*;

use crate::error::*;
Expand Down
6 changes: 6 additions & 0 deletions sway-core/src/type_engine/trait_constraint.rs
@@ -0,0 +1,6 @@
use crate::CallPath;

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub(crate) struct TraitConstraint {
pub(crate) call_path: CallPath,
}
2 changes: 1 addition & 1 deletion sway-core/src/type_engine/type_info.rs
@@ -1,6 +1,6 @@
use super::*;

use crate::{semantic_analysis::*, types::*, CallPath, Ident, TypeArgument, TypeParameter};
use crate::{semantic_analysis::*, types::*, CallPath, Ident};

use sway_types::{span::Span, Spanned};

Expand Down
2 changes: 0 additions & 2 deletions sway-core/src/type_engine/type_mapping.rs
@@ -1,5 +1,3 @@
use crate::TypeParameter;

use super::*;

pub(crate) type TypeMapping = Vec<(TypeId, TypeId)>;
Expand Down
@@ -1,4 +1,4 @@
use crate::{error::*, parse_tree::*, semantic_analysis::*, type_engine::*};
use crate::{error::*, semantic_analysis::*, type_engine::*};

use sway_types::{ident::Ident, span::Span, Spanned};

Expand Down Expand Up @@ -98,8 +98,3 @@ impl TypeParameter {
ok(type_parameter, warnings, errors)
}
}

#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub(crate) struct TraitConstraint {
pub(crate) call_path: CallPath,
}