Skip to content

Commit

Permalink
Rename Declaration to Decl in a number of places. (FuelLabs#4324)
Browse files Browse the repository at this point in the history
## Description

Some function signatures are beginning to get rather unwieldy with the
introduction of new traits, impl blocks for types with nested type
arguments, etc.

This change canonicalizes the name "declaration" to "decl". "decl" was
already being used in the `DeclEngine`, and now "decl" is used elsewhere
as well. This change will allow for more simple formatting from `cargo
fmt` and function signatures that are easier to read.

## Checklist

- [x] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [x] I have updated the documentation where relevant (API docs, the
reference, and the Sway book).
- [x] I have added tests that prove my fix is effective or that my
feature works.
- [x] I have added (or requested a maintainer to add) the necessary
`Breaking*` or `New Feature` labels where relevant.
- [x] I have done my best to ensure that my PR adheres to [the Fuel Labs
Code Review
Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md).
- [x] I have requested a review from the relevant team or maintainers.
  • Loading branch information
emilyaherbert authored Mar 23, 2023
1 parent 5fd3cc3 commit 31dc809
Show file tree
Hide file tree
Showing 87 changed files with 1,025 additions and 1,153 deletions.
22 changes: 11 additions & 11 deletions forc-plugins/forc-doc/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use anyhow::Result;
use sway_core::{
decl_engine::*,
language::ty::{TyDeclaration, TyTraitFn, TyTraitInterfaceItem},
language::ty::{TyDecl, TyTraitFn, TyTraitInterfaceItem},
};

trait RequiredMethods {
Expand All @@ -27,19 +27,19 @@ pub(crate) enum Descriptor {
}

impl Descriptor {
/// Decides whether a [TyDeclaration] is [Descriptor::Documentable].
/// Decides whether a [TyDecl] is [Descriptor::Documentable].
pub(crate) fn from_typed_decl(
decl_engine: &DeclEngine,
ty_decl: &TyDeclaration,
ty_decl: &TyDecl,
module_info: ModuleInfo,
document_private_items: bool,
) -> Result<Self> {
const CONTRACT_STORAGE: &str = "Contract Storage";

use swayfmt::parse;
use TyDeclaration::*;
use TyDecl::*;
match ty_decl {
StructDeclaration { decl_id, .. } => {
StructDecl { decl_id, .. } => {
let struct_decl = decl_engine.get_struct(decl_id);
if !document_private_items && struct_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
Expand Down Expand Up @@ -75,7 +75,7 @@ impl Descriptor {
}))
}
}
EnumDeclaration { decl_id, .. } => {
EnumDecl { decl_id, .. } => {
let enum_decl = decl_engine.get_enum(decl_id);
if !document_private_items && enum_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
Expand Down Expand Up @@ -111,7 +111,7 @@ impl Descriptor {
}))
}
}
TraitDeclaration { decl_id, .. } => {
TraitDecl { decl_id, .. } => {
let trait_decl = decl_engine.get_trait(decl_id);
if !document_private_items && trait_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Descriptor {
}))
}
}
AbiDeclaration { decl_id, .. } => {
AbiDecl { decl_id, .. } => {
let abi_decl = decl_engine.get_abi(decl_id);
let item_name = abi_decl.name;
let attrs_opt =
Expand Down Expand Up @@ -198,7 +198,7 @@ impl Descriptor {
raw_attributes: attrs_opt,
}))
}
StorageDeclaration { decl_id, .. } => {
StorageDecl { decl_id, .. } => {
let storage_decl = decl_engine.get_storage(decl_id);
let item_name = sway_types::BaseIdent::new_no_trim(
sway_types::span::Span::from_string(CONTRACT_STORAGE.to_string()),
Expand Down Expand Up @@ -260,7 +260,7 @@ impl Descriptor {
// raw_attributes: None,
// }))
// }
FunctionDeclaration { decl_id, .. } => {
FunctionDecl { decl_id, .. } => {
let fn_decl = decl_engine.get_function(decl_id);
if !document_private_items && fn_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
Expand Down Expand Up @@ -290,7 +290,7 @@ impl Descriptor {
}))
}
}
ConstantDeclaration { decl_id, .. } => {
ConstantDecl { decl_id, .. } => {
let const_decl = decl_engine.get_constant(decl_id);
if !document_private_items && const_decl.visibility.is_private() {
Ok(Descriptor::NonDocumentable)
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-doc/src/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ pub(crate) struct Document {
impl Document {
/// Creates an HTML file name from the [Document].
pub(crate) fn html_filename(&self) -> String {
use sway_core::language::ty::TyDeclaration::StorageDeclaration;
use sway_core::language::ty::TyDecl::StorageDecl;
let name = match &self.item_body.ty_decl {
StorageDeclaration { .. } => None,
StorageDecl { .. } => None,
_ => Some(self.item_header.item_name.as_str()),
};

Expand Down
124 changes: 57 additions & 67 deletions forc-plugins/forc-doc/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use horrorshow::{box_html, helper::doctype, html, prelude::*, Raw};
use std::{collections::BTreeMap, fmt::Write, path::PathBuf};
use sway_core::{
language::ty::{
TyDeclaration::{self, *},
TyDecl::{self, *},
TyEnumVariant, TyProgramKind, TyStorageField, TyStructField, TyTraitFn,
},
transform::{AttributeKind, AttributesMap},
Expand Down Expand Up @@ -68,79 +68,75 @@ impl RenderedDocumentation {
match module_map.get_mut(&location) {
Some(doc_links) => {
match doc.item_body.ty_decl {
StructDeclaration { .. } => match doc_links.get_mut(&BlockTitle::Structs) {
StructDecl { .. } => match doc_links.get_mut(&BlockTitle::Structs) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Structs, vec![doc.link()]);
}
},
EnumDeclaration { .. } => match doc_links.get_mut(&BlockTitle::Enums) {
EnumDecl { .. } => match doc_links.get_mut(&BlockTitle::Enums) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Enums, vec![doc.link()]);
}
},
TraitDeclaration { .. } => match doc_links.get_mut(&BlockTitle::Traits) {
TraitDecl { .. } => match doc_links.get_mut(&BlockTitle::Traits) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Traits, vec![doc.link()]);
}
},
AbiDeclaration { .. } => match doc_links.get_mut(&BlockTitle::Abi) {
AbiDecl { .. } => match doc_links.get_mut(&BlockTitle::Abi) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Abi, vec![doc.link()]);
}
},
StorageDeclaration { .. } => {
StorageDecl { .. } => {
match doc_links.get_mut(&BlockTitle::ContractStorage) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::ContractStorage, vec![doc.link()]);
}
}
}
FunctionDeclaration { .. } => {
match doc_links.get_mut(&BlockTitle::Functions) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Functions, vec![doc.link()]);
}
FunctionDecl { .. } => match doc_links.get_mut(&BlockTitle::Functions) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Functions, vec![doc.link()]);
}
}
ConstantDeclaration { .. } => {
match doc_links.get_mut(&BlockTitle::Constants) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Constants, vec![doc.link()]);
}
},
ConstantDecl { .. } => match doc_links.get_mut(&BlockTitle::Constants) {
Some(links) => links.push(doc.link()),
None => {
doc_links.insert(BlockTitle::Constants, vec![doc.link()]);
}
}
},
_ => {} // TODO: ImplTraitDeclaration
}
}
None => {
let mut doc_links: BTreeMap<BlockTitle, Vec<DocLink>> = BTreeMap::new();
match doc.item_body.ty_decl {
StructDeclaration { .. } => {
StructDecl { .. } => {
doc_links.insert(BlockTitle::Structs, vec![doc.link()]);
}
EnumDeclaration { .. } => {
EnumDecl { .. } => {
doc_links.insert(BlockTitle::Enums, vec![doc.link()]);
}
TraitDeclaration { .. } => {
TraitDecl { .. } => {
doc_links.insert(BlockTitle::Traits, vec![doc.link()]);
}
AbiDeclaration { .. } => {
AbiDecl { .. } => {
doc_links.insert(BlockTitle::Abi, vec![doc.link()]);
}
StorageDeclaration { .. } => {
StorageDecl { .. } => {
doc_links.insert(BlockTitle::ContractStorage, vec![doc.link()]);
}
FunctionDeclaration { .. } => {
FunctionDecl { .. } => {
doc_links.insert(BlockTitle::Functions, vec![doc.link()]);
}
ConstantDeclaration { .. } => {
ConstantDecl { .. } => {
doc_links.insert(BlockTitle::Constants, vec![doc.link()]);
}
_ => {} // TODO: ImplTraitDeclaration
Expand Down Expand Up @@ -187,60 +183,54 @@ impl RenderedDocumentation {
}
// Above we check for the module a link belongs to, here we want _all_ links so the check is much more shallow.
match doc.item_body.ty_decl {
StructDeclaration { .. } => match all_docs.links.get_mut(&BlockTitle::Structs) {
StructDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Structs) {
Some(links) => links.push(doc.link()),
None => {
all_docs.links.insert(BlockTitle::Structs, vec![doc.link()]);
}
},
EnumDeclaration { .. } => match all_docs.links.get_mut(&BlockTitle::Enums) {
EnumDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Enums) {
Some(links) => links.push(doc.link()),
None => {
all_docs.links.insert(BlockTitle::Enums, vec![doc.link()]);
}
},
TraitDeclaration { .. } => match all_docs.links.get_mut(&BlockTitle::Traits) {
TraitDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Traits) {
Some(links) => links.push(doc.link()),
None => {
all_docs.links.insert(BlockTitle::Traits, vec![doc.link()]);
}
},
AbiDeclaration { .. } => match all_docs.links.get_mut(&BlockTitle::Abi) {
AbiDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Abi) {
Some(links) => links.push(doc.link()),
None => {
all_docs.links.insert(BlockTitle::Abi, vec![doc.link()]);
}
},
StorageDeclaration { .. } => {
match all_docs.links.get_mut(&BlockTitle::ContractStorage) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::ContractStorage, vec![doc.link()]);
}
StorageDecl { .. } => match all_docs.links.get_mut(&BlockTitle::ContractStorage) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::ContractStorage, vec![doc.link()]);
}
}
FunctionDeclaration { .. } => {
match all_docs.links.get_mut(&BlockTitle::Functions) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::Functions, vec![doc.link()]);
}
},
FunctionDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Functions) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::Functions, vec![doc.link()]);
}
}
ConstantDeclaration { .. } => {
match all_docs.links.get_mut(&BlockTitle::Constants) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::Constants, vec![doc.link()]);
}
},
ConstantDecl { .. } => match all_docs.links.get_mut(&BlockTitle::Constants) {
Some(links) => links.push(doc.link()),
None => {
all_docs
.links
.insert(BlockTitle::Constants, vec![doc.link()]);
}
}
},
_ => {} // TODO: ImplTraitDeclaration
}
}
Expand Down Expand Up @@ -380,7 +370,7 @@ impl Renderable for ItemHeader {
#[derive(Clone)]
pub(crate) struct ItemBody {
pub(crate) module_info: ModuleInfo,
pub(crate) ty_decl: TyDeclaration,
pub(crate) ty_decl: TyDecl,
/// The item name varies depending on type.
/// We store it during info gathering to avoid
/// multiple match statements.
Expand Down Expand Up @@ -1155,16 +1145,16 @@ impl BlockTitle {
}
}

impl DocBlockTitle for TyDeclaration {
impl DocBlockTitle for TyDecl {
fn as_block_title(&self) -> BlockTitle {
match self {
TyDeclaration::StructDeclaration { .. } => BlockTitle::Structs,
TyDeclaration::EnumDeclaration { .. } => BlockTitle::Enums,
TyDeclaration::TraitDeclaration { .. } => BlockTitle::Traits,
TyDeclaration::AbiDeclaration { .. } => BlockTitle::Abi,
TyDeclaration::StorageDeclaration { .. } => BlockTitle::ContractStorage,
TyDeclaration::ConstantDeclaration { .. } => BlockTitle::Constants,
TyDeclaration::FunctionDeclaration { .. } => BlockTitle::Functions,
TyDecl::StructDecl { .. } => BlockTitle::Structs,
TyDecl::EnumDecl { .. } => BlockTitle::Enums,
TyDecl::TraitDecl { .. } => BlockTitle::Traits,
TyDecl::AbiDecl { .. } => BlockTitle::Abi,
TyDecl::StorageDecl { .. } => BlockTitle::ContractStorage,
TyDecl::ConstantDecl { .. } => BlockTitle::Constants,
TyDecl::FunctionDecl { .. } => BlockTitle::Functions,
_ => {
unreachable!("All other TyDecls are non-documentable and will never be matched on")
}
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/abi_generation/evm_json_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use sway_types::integer_bits::IntegerBits;
use crate::{
asm_generation::EvmAbiResult,
decl_engine::DeclEngine,
language::ty::{TyFunctionDeclaration, TyProgram, TyProgramKind},
language::ty::{TyFunctionDecl, TyProgram, TyProgramKind},
Engines, TypeArgument, TypeEngine, TypeId, TypeInfo,
};

Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn json_abi_param_type(
}

pub(self) fn generate_json_abi_function(
fn_decl: &TyFunctionDeclaration,
fn_decl: &TyFunctionDecl,
type_engine: &TypeEngine,
decl_engine: &DeclEngine,
) -> ethabi::operation::Operation {
Expand Down
8 changes: 4 additions & 4 deletions sway-core/src/abi_generation/fuel_json_abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use sway_types::integer_bits::IntegerBits;
use crate::{
decl_engine::DeclEngine,
language::{
ty::{TyConstantDeclaration, TyFunctionDeclaration, TyProgram, TyProgramKind},
ty::{TyConstantDecl, TyFunctionDecl, TyProgram, TyProgramKind},
CallPath,
},
transform::AttributesMap,
Expand Down Expand Up @@ -190,7 +190,7 @@ fn generate_json_configurables(
.configurables
.iter()
.map(
|TyConstantDeclaration {
|TyConstantDecl {
type_ascription, ..
}| program_abi::TypeDeclaration {
type_id: type_ascription.type_id.index(),
Expand Down Expand Up @@ -226,7 +226,7 @@ fn generate_json_configurables(
.configurables
.iter()
.map(
|TyConstantDeclaration {
|TyConstantDecl {
call_path,
type_ascription,
..
Expand Down Expand Up @@ -868,7 +868,7 @@ fn call_path_display(ctx: &mut JsonAbiContext, call_path: &CallPath) -> String {
buf
}

impl TyFunctionDeclaration {
impl TyFunctionDecl {
pub(self) fn generate_json_abi_function(
&self,
ctx: &mut JsonAbiContext,
Expand Down
Loading

0 comments on commit 31dc809

Please sign in to comment.