Skip to content

Commit

Permalink
Create the transform and to_parsed_lang modules. (FuelLabs#3046)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyaherbert authored Oct 15, 2022
1 parent 4b00d28 commit 5c4e440
Show file tree
Hide file tree
Showing 25 changed files with 215 additions and 198 deletions.
4 changes: 2 additions & 2 deletions sway-core/src/language/parsed/declaration/abi.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::AttributesMap;
use crate::transform;

use super::{FunctionDeclaration, TraitFn};

Expand All @@ -15,5 +15,5 @@ pub struct AbiDeclaration {
/// The methods provided to a contract "for free" upon opting in to this interface
pub methods: Vec<FunctionDeclaration>,
pub(crate) span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}
4 changes: 2 additions & 2 deletions sway-core/src/language/parsed/declaration/constant.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
language::{parsed::Expression, Visibility},
transform,
type_system::TypeInfo,
AttributesMap,
};
use sway_types::{Ident, Span};

#[derive(Debug, Clone)]
pub struct ConstantDeclaration {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub type_ascription: TypeInfo,
pub type_ascription_span: Option<Span>,
pub value: Expression,
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/parsed/declaration/enum.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{language::Visibility, type_system::*, AttributesMap};
use crate::{language::Visibility, transform, type_system::*};
use sway_types::{ident::Ident, span::Span};

#[derive(Debug, Clone)]
pub struct EnumDeclaration {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub type_parameters: Vec<TypeParameter>,
pub variants: Vec<EnumVariant>,
pub(crate) span: Span,
Expand All @@ -14,7 +14,7 @@ pub struct EnumDeclaration {
#[derive(Debug, Clone)]
pub struct EnumVariant {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub type_info: TypeInfo,
pub type_span: Span,
pub(crate) tag: usize,
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/parsed/declaration/function.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
language::{parsed::*, *},
transform,
type_system::*,
AttributesMap,
};
use sway_types::{ident::Ident, span::Span};

#[derive(Debug, Clone)]
pub struct FunctionDeclaration {
pub purity: Purity,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub name: Ident,
pub visibility: Visibility,
pub body: CodeBlock,
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/parsed/declaration/storage.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::{language::parsed::Expression, type_system::*, AttributesMap};
use crate::{language::parsed::Expression, transform, type_system::*};
use sway_types::{ident::Ident, span::Span};

#[derive(Debug, Clone)]
/// A declaration of contract storage. Only valid within contract contexts.
/// All values in this struct are mutable and persistent among executions of the same contract deployment.
pub struct StorageDeclaration {
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub fields: Vec<StorageField>,
pub span: Span,
}
Expand All @@ -17,7 +17,7 @@ pub struct StorageDeclaration {
#[derive(Debug, Clone)]
pub struct StorageField {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub type_info: TypeInfo,
pub type_info_span: Span,
pub initializer: Expression,
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/parsed/declaration/struct.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::{
language::Visibility,
transform,
type_system::{TypeInfo, TypeParameter},
AttributesMap,
};
use sway_types::{ident::Ident, span::Span};

#[derive(Debug, Clone)]
pub struct StructDeclaration {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub fields: Vec<StructField>,
pub type_parameters: Vec<TypeParameter>,
pub visibility: Visibility,
Expand All @@ -18,7 +18,7 @@ pub struct StructDeclaration {
#[derive(Debug, Clone)]
pub struct StructField {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub type_info: TypeInfo,
pub(crate) span: Span,
pub type_span: Span,
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/parsed/declaration/trait.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::{FunctionDeclaration, FunctionParameter};

use crate::{language::*, type_system::TypeInfo, AttributesMap};
use crate::{language::*, transform, type_system::TypeInfo};
use sway_types::{ident::Ident, span::Span, Spanned};

#[derive(Debug, Clone)]
pub struct TraitDeclaration {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub interface_surface: Vec<TraitFn>,
pub methods: Vec<FunctionDeclaration>,
pub(crate) supertraits: Vec<Supertrait>,
Expand All @@ -27,7 +27,7 @@ impl Spanned for Supertrait {
#[derive(Debug, Clone)]
pub struct TraitFn {
pub name: Ident,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub purity: Purity,
pub parameters: Vec<FunctionParameter>,
pub return_type: TypeInfo,
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/declaration/abi.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use derivative::Derivative;
use sway_types::{Ident, Span};

use crate::{declaration_engine::DeclarationId, language::parsed, type_system::*, AttributesMap};
use crate::{declaration_engine::DeclarationId, language::parsed, transform, type_system::*};

/// A [TyAbiDeclaration] contains the type-checked version of the parse tree's `AbiDeclaration`.
#[derive(Clone, Debug, Derivative)]
Expand All @@ -19,7 +19,7 @@ pub struct TyAbiDeclaration {
#[derivative(PartialEq = "ignore")]
#[derivative(Eq(bound = ""))]
pub(crate) span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

impl CreateTypeId for TyAbiDeclaration {
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/declaration/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use sway_types::Ident;

use crate::{
language::{ty::*, Visibility},
AttributesMap,
transform,
};

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TyConstantDeclaration {
pub name: Ident,
pub value: TyExpression,
pub(crate) visibility: Visibility,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}
6 changes: 3 additions & 3 deletions sway-core/src/language/ty/declaration/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use std::hash::{Hash, Hasher};

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

use crate::{language::Visibility, type_system::*, AttributesMap};
use crate::{language::Visibility, transform, type_system::*};

#[derive(Clone, Debug, Eq)]
pub struct TyEnumDeclaration {
pub name: Ident,
pub type_parameters: Vec<TypeParameter>,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub variants: Vec<TyEnumVariant>,
pub(crate) span: Span,
pub visibility: Visibility,
Expand Down Expand Up @@ -71,7 +71,7 @@ pub struct TyEnumVariant {
pub type_span: Span,
pub(crate) tag: usize,
pub(crate) span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

// NOTE: Hash and PartialEq must uphold the invariant:
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/declaration/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use sway_types::{Ident, Span, Spanned};
use crate::{
declaration_engine::*,
language::{ty::*, Purity, Visibility},
transform,
type_system::*,
AttributesMap,
};

#[derive(Clone, Debug, Eq)]
Expand All @@ -13,7 +13,7 @@ pub struct TyFunctionDeclaration {
pub body: TyCodeBlock,
pub parameters: Vec<TyFunctionParameter>,
pub span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
pub return_type: TypeId,
pub initial_return_type: TypeId,
pub type_parameters: Vec<TypeParameter>,
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/ty/declaration/storage.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use derivative::Derivative;
use sway_types::{Ident, Span, Spanned};

use crate::{language::ty::*, type_system::*, AttributesMap};
use crate::{language::ty::*, transform, type_system::*};

#[derive(Clone, Debug, Derivative)]
#[derivative(PartialEq, Eq)]
Expand All @@ -10,7 +10,7 @@ pub struct TyStorageDeclaration {
#[derivative(PartialEq = "ignore")]
#[derivative(Eq(bound = ""))]
pub span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

impl Spanned for TyStorageDeclaration {
Expand All @@ -26,7 +26,7 @@ pub struct TyStorageField {
pub type_span: Span,
pub initializer: TyExpression,
pub(crate) span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

// NOTE: Hash and PartialEq must uphold the invariant:
Expand Down
6 changes: 3 additions & 3 deletions sway-core/src/language/ty/declaration/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::hash::{Hash, Hasher};

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

use crate::{language::Visibility, type_system::*, AttributesMap};
use crate::{language::Visibility, transform, type_system::*};

#[derive(Clone, Debug, Eq)]
pub struct TyStructDeclaration {
Expand All @@ -11,7 +11,7 @@ pub struct TyStructDeclaration {
pub type_parameters: Vec<TypeParameter>,
pub visibility: Visibility,
pub(crate) span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

// NOTE: Hash and PartialEq must uphold the invariant:
Expand Down Expand Up @@ -70,7 +70,7 @@ pub struct TyStructField {
pub initial_type_id: TypeId,
pub(crate) span: Span,
pub type_span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

// NOTE: Hash and PartialEq must uphold the invariant:
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/declaration/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ use sway_types::Ident;
use crate::{
declaration_engine::DeclarationId,
language::{parsed, Visibility},
transform,
type_system::*,
AttributesMap,
};

#[derive(Clone, Debug, Derivative)]
Expand All @@ -21,7 +21,7 @@ pub struct TyTraitDeclaration {
pub(crate) methods: Vec<parsed::FunctionDeclaration>,
pub(crate) supertraits: Vec<parsed::Supertrait>,
pub visibility: Visibility,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

impl CopyTypes for TyTraitDeclaration {
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/language/ty/declaration/trait_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use sway_types::{Ident, Span};

use crate::{
language::{ty::*, Purity},
transform,
type_system::*,
AttributesMap,
};

#[derive(Clone, Debug, Derivative)]
Expand All @@ -17,7 +17,7 @@ pub struct TyTraitFn {
#[derivative(PartialEq = "ignore")]
#[derivative(Eq(bound = ""))]
pub return_type_span: Span,
pub attributes: AttributesMap,
pub attributes: transform::AttributesMap,
}

impl CopyTypes for TyTraitFn {
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ mod asm_lang;
mod build_config;
mod concurrent_slab;
mod control_flow_analysis;
mod convert_parse_tree;
pub mod declaration_engine;
pub mod ir_generation;
pub mod language;
mod metadata;
pub mod semantic_analysis;
pub mod source_map;
pub mod transform;
pub mod type_system;

use crate::{error::*, source_map::SourceMap};
pub use asm_generation::from_ir::compile_ir_to_asm;
use asm_generation::FinalizedAsm;
pub use build_config::BuildConfig;
use control_flow_analysis::ControlFlowGraph;
pub use convert_parse_tree::{Attribute, AttributeKind, AttributesMap};
use metadata::MetadataManager;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
Expand All @@ -38,6 +37,7 @@ use sway_types::{ident::Ident, span, Spanned};
pub use type_system::*;

use language::{parsed, ty};
use transform::to_parsed_lang;

/// Given an input `Arc<str>` and an optional [BuildConfig], parse the input into a [SwayParseTree].
///
Expand Down Expand Up @@ -73,7 +73,7 @@ fn parse_file(src: Arc<str>, path: Option<Arc<PathBuf>>) -> CompileResult<sway_a
/// When no `BuildConfig` is given, we're assumed to be parsing in-memory with no submodules.
fn parse_in_memory(src: Arc<str>, include_test_fns: bool) -> CompileResult<parsed::ParseProgram> {
parse_file(src, None).flat_map(|module| {
convert_parse_tree::convert_parse_tree(module, include_test_fns).flat_map(|(kind, tree)| {
to_parsed_lang::convert_parse_tree(module, include_test_fns).flat_map(|(kind, tree)| {
let submodules = Default::default();
let root = parsed::ParseModule { tree, submodules };
ok(parsed::ParseProgram { kind, root }, vec![], vec![])
Expand Down Expand Up @@ -166,7 +166,7 @@ fn parse_module_tree(
let submodules_res = parse_submodules(&module.dependencies, module_dir, include_test_fns);

// Convert from the raw parsed module to the `ParseTree` ready for type-check.
convert_parse_tree::convert_parse_tree(module, include_test_fns).flat_map(
to_parsed_lang::convert_parse_tree(module, include_test_fns).flat_map(
|(prog_kind, tree)| {
submodules_res
.map(|submodules| (prog_kind, parsed::ParseModule { tree, submodules }))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@ use crate::{
},
language::ty,
metadata::MetadataManager,
transform,
type_system::{TypeId, TypeInfo},
AttributesMap, Ident,
Ident,
};
use fuel_tx::StorageSlot;
use sway_error::error::CompileError;
use sway_ir::{Context, Module};
use sway_types::{state::StateIndex, Span, Spanned};

impl ty::TyStorageDeclaration {
pub fn new(fields: Vec<ty::TyStorageField>, span: Span, attributes: AttributesMap) -> Self {
pub fn new(
fields: Vec<ty::TyStorageField>,
span: Span,
attributes: transform::AttributesMap,
) -> Self {
ty::TyStorageDeclaration {
fields,
span,
Expand Down
Loading

0 comments on commit 5c4e440

Please sign in to comment.