Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ async-trait = "0.1"
aws-config = "1.5"
aws-sdk-kms = "1.44"
byte-unit = "5.1"
bytecount = "0.6"
bytes = "1.7"
chrono = { version = "0.4", default-features = false }
cid = "0.11"
Expand Down
6 changes: 3 additions & 3 deletions forc-pkg/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use std::{
fmt::Display,
path::{Path, PathBuf},
str::FromStr,
sync::Arc,
};
use sway_core::{fuel_prelude::fuel_tx, language::parsed::TreeType, parse_tree_type, BuildTarget};
use sway_error::handler::Handler;
use sway_types::span::Source;
use sway_utils::{
constants, find_nested_manifest_dir, find_parent_manifest_dir,
find_parent_manifest_dir_with_check,
Expand Down Expand Up @@ -417,10 +417,10 @@ impl PackageManifestFile {
}

/// Produces the string of the entry point file.
pub fn entry_string(&self) -> Result<Arc<str>> {
pub fn entry_string(&self) -> Result<Source> {
let entry_path = self.entry_path();
let entry_string = std::fs::read_to_string(entry_path)?;
Ok(Arc::from(entry_string))
Ok(entry_string.as_str().into())
}

/// Parse and return the associated project's program type.
Expand Down
5 changes: 3 additions & 2 deletions forc-plugins/forc-doc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use forc_pkg::{
use forc_tracing::println_action_green;
use forc_util::default_output_directory;
use render::RenderedDocumentation;
use std::sync::Arc;
use std::{
fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -46,7 +47,7 @@ impl<'e> RenderPlan<'e> {
}

pub struct ProgramInfo<'a> {
pub ty_program: TyProgram,
pub ty_program: Arc<TyProgram>,
pub engines: &'a Engines,
pub manifest: &'a ManifestFile,
pub pkg_manifest: &'a PackageManifestFile,
Expand Down Expand Up @@ -197,7 +198,7 @@ fn build_docs(
document_private_items,
)?;
let root_attributes = (!ty_program.root_module.attributes.is_empty())
.then_some(ty_program.root_module.attributes);
.then_some(ty_program.root_module.attributes.clone());
let forc_version = pkg_manifest
.project
.forc_version
Expand Down
4 changes: 1 addition & 3 deletions forc-plugins/forc-fmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use std::{
default::Default,
fs,
path::{Path, PathBuf},
sync::Arc,
};
use sway_utils::{constants, find_parent_manifest_dir, get_sway_files, is_sway_file};
use swayfmt::Formatter;
Expand Down Expand Up @@ -141,8 +140,7 @@ fn format_file(app: &App, file: PathBuf, formatter: &mut Formatter) -> Result<bo
}
if let Ok(file_content) = fs::read_to_string(&file) {
let mut edited = false;
let file_content: Arc<str> = Arc::from(file_content);
match Formatter::format(formatter, file_content.clone()) {
match Formatter::format(formatter, file_content.as_str().into()) {
Ok(formatted_content) => {
if app.check {
if *file_content != formatted_content {
Expand Down
8 changes: 4 additions & 4 deletions forc-plugins/forc-migrate/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ mod references;
mod storage_domains;
mod try_from_bytes_for_b256;

use std::collections::HashSet;
use std::{collections::HashSet, sync::Arc};

use anyhow::{bail, Result};
use duplicate::duplicate_item;
Expand All @@ -34,8 +34,8 @@ use sway_types::Span;
use crate::internal_error;

pub(crate) struct ProgramInfo<'a> {
pub lexed_program: LexedProgram,
pub ty_program: TyProgram,
pub lexed_program: Arc<LexedProgram>,
pub ty_program: Arc<TyProgram>,
pub engines: &'a Engines,
}

Expand All @@ -52,7 +52,7 @@ pub(crate) struct MutProgramInfo<'a> {
impl ProgramInfo<'_> {
pub(crate) fn as_mut(&mut self) -> MutProgramInfo {
MutProgramInfo {
lexed_program: &mut self.lexed_program,
lexed_program: Arc::get_mut(&mut self.lexed_program).unwrap(),
ty_program: &self.ty_program,
engines: self.engines,
}
Expand Down
4 changes: 2 additions & 2 deletions forc-plugins/forc-migrate/src/migrations/storage_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub(super) const DEFINE_BACKWARD_COMPATIBLE_STORAGE_SLOT_KEYS_STEP: MigrationSte
fn review_storage_slot_keys_step(program_info: &ProgramInfo) -> Result<Vec<Span>> {
let mut res = vec![];

let Some(storage_decl_id) = ty_match::storage_decl(&program_info.ty_program) else {
let Some(storage_decl_id) = ty_match::storage_decl(program_info.ty_program.as_ref()) else {
return Ok(res);
};

Expand Down Expand Up @@ -132,7 +132,7 @@ fn define_backward_compatible_storage_slot_keys_step_instruction(
) -> Result<Vec<Span>> {
let mut res = vec![];

let Some(storage_decl_id) = ty_match::storage_decl(&program_info.ty_program) else {
let Some(storage_decl_id) = ty_match::storage_decl(program_info.ty_program.as_ref()) else {
return Ok(res);
};

Expand Down
4 changes: 2 additions & 2 deletions forc-util/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ pub fn format_diagnostic(diagnostic: &Diagnostic) {
let input = span.input();
let mut start_pos = span.start();
let mut end_pos = span.end();
let LineColRange { mut start, end } = span.line_col();
let LineColRange { mut start, end } = span.line_col_one_index();
let input = construct_window(&mut start, end, &mut start_pos, &mut end_pos, input);

let slice = Slice {
Expand Down Expand Up @@ -702,7 +702,7 @@ fn construct_code_snippet<'a>(span: &Span, input: &'a str) -> (&'a str, usize, u
// how many lines to prepend or append to the highlighted region in the window
const NUM_LINES_BUFFER: usize = 2;

let LineColRange { start, end } = span.line_col();
let LineColRange { start, end } = span.line_col_one_index();

let total_lines_in_input = input.chars().filter(|x| *x == '\n').count();
debug_assert!(end.line >= start.line);
Expand Down
7 changes: 5 additions & 2 deletions forc/src/ops/forc_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ use anyhow::Result;
use forc_pkg as pkg;
use forc_pkg::manifest::GenericManifestFile;
use pkg::manifest::ManifestFile;
use std::path::PathBuf;
use std::{path::PathBuf, sync::Arc};
use sway_core::{language::ty, Engines};
use sway_error::handler::Handler;

pub fn check(command: CheckCommand, engines: &Engines) -> Result<(Option<ty::TyProgram>, Handler)> {
pub fn check(
command: CheckCommand,
engines: &Engines,
) -> Result<(Option<Arc<ty::TyProgram>>, Handler)> {
let CheckCommand {
build_target,
path,
Expand Down
8 changes: 3 additions & 5 deletions sway-core/src/asm_generation/evm/evm_asm_builder.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::{collections::HashMap, sync::Arc};

use crate::{
asm_generation::{
asm_builder::AsmBuilder, from_ir::StateAccessType, fuel::data_section::DataSection,
Expand All @@ -8,16 +6,16 @@ use crate::{
asm_lang::Label,
metadata::MetadataManager,
};
use etk_asm::{asm::Assembler, ops::*};
use etk_ops::london::*;
use std::collections::HashMap;
use sway_error::{
error::CompileError,
handler::{ErrorEmitted, Handler},
};
use sway_ir::{Context, *};
use sway_types::Span;

use etk_asm::{asm::Assembler, ops::*};

/// A smart contract is created by sending a transaction with an empty "to" field.
/// When this is done, the Ethereum virtual machine (EVM) runs the bytecode which is
/// set in the init byte array which is a field that can contain EVM bytecode
Expand Down Expand Up @@ -283,7 +281,7 @@ impl<'ir, 'eng> EvmAsmBuilder<'ir, 'eng> {

fn empty_span() -> Span {
let msg = "unknown source location";
Span::new(Arc::from(msg), 0, msg.len(), None).unwrap()
Span::new(msg.into(), 0, msg.len(), None).unwrap()
}

fn get_label(&mut self) -> Label {
Expand Down
4 changes: 2 additions & 2 deletions sway-core/src/asm_generation/finalized_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ fn to_bytecode_mut(
last_span = match (last_span, &span) {
(None, Some(span)) => {
indentation = 4;
let line_col = span.start_pos().line_col();
let line_col = span.start_line_col_one_index();
println!(
"{} @ {}:{}:{}",
span.as_str(),
Expand All @@ -266,7 +266,7 @@ fn to_bytecode_mut(
}
(Some(last), Some(span)) if last != *span => {
indentation = 4;
let line_col = span.start_pos().line_col();
let line_col = span.start_line_col_one_index();
println!(
"{} @ {}:{}:{}",
span.as_str(),
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/control_flow_analysis/flow_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl<'cfg> ControlFlowGraph<'cfg> {
if let Some(source_id) = span.source_id() {
let path = engines.se().get_path(source_id);
let path = path.to_string_lossy();
let LineCol { line, col } = span.start_pos().line_col();
let LineCol { line, col } = span.start_line_col_one_index();
let url_format = url_format
.replace("{path}", path.to_string().as_str())
.replace("{line}", line.to_string().as_str())
Expand Down
6 changes: 5 additions & 1 deletion sway-core/src/engine_threading.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ impl DisplayWithEngines for Span {
let file = self
.source_id()
.and_then(|id| engines.source_engine.get_file_name(id));
f.write_fmt(format_args!("Span {{ {:?}, {} }}", file, self.line_col()))
f.write_fmt(format_args!(
"Span {{ {:?}, {} }}",
file,
self.line_col_one_index()
))
}
}

Expand Down
4 changes: 3 additions & 1 deletion sway-core/src/ir_generation/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,9 @@ mod tests {
let r = crate::compile_to_ast(
&handler,
&engines,
std::sync::Arc::from(format!("library; {prefix} fn f() -> u64 {{ {expr}; 0 }}")),
format!("library; {prefix} fn f() -> u64 {{ {expr}; 0 }}")
.as_str()
.into(),
core_lib,
None,
"test",
Expand Down
2 changes: 1 addition & 1 deletion sway-core/src/language/call_path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl<T: Spanned> Spanned for CallPath<T> {
// the span for the whole call path. Otherwise, we join
// the spans of all the parts.
.filter(|x| {
Arc::ptr_eq(x.src(), suffix_span.src())
Arc::ptr_eq(&x.src().text, &suffix_span.src().text)
&& x.source_id() == suffix_span.source_id()
})
.peekable();
Expand Down
14 changes: 8 additions & 6 deletions sway-core/src/language/programs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;

use super::{lexed::LexedProgram, parsed::ParseProgram, ty::TyProgram};
use crate::semantic_analysis::program::TypeCheckFailed;
use sway_utils::PerformanceData;
Expand All @@ -6,17 +8,17 @@ use sway_utils::PerformanceData;
/// as compilation metrics.
#[derive(Clone, Debug)]
pub struct Programs {
pub lexed: LexedProgram,
pub parsed: ParseProgram,
pub typed: Result<TyProgram, TypeCheckFailed>,
pub lexed: Arc<LexedProgram>,
pub parsed: Arc<ParseProgram>,
pub typed: Result<Arc<TyProgram>, TypeCheckFailed>,
pub metrics: PerformanceData,
}

impl Programs {
pub fn new(
lexed: LexedProgram,
parsed: ParseProgram,
typed: Result<TyProgram, TypeCheckFailed>,
lexed: Arc<LexedProgram>,
parsed: Arc<ParseProgram>,
typed: Result<Arc<TyProgram>, TypeCheckFailed>,
metrics: PerformanceData,
) -> Programs {
Programs {
Expand Down
Loading
Loading