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

Allow inclusion of multiple source files as dependencies for a single contract/script/etc. #62

Merged
merged 75 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
655d991
begin register allocator
May 14, 2021
3e56e38
begin reg alloc
May 15, 2021
a7f469e
mutable virtual registers; basic allocation algorithm skeleton
May 16, 2021
5c50072
mutable registers in allocation
May 17, 2021
e407757
pull in fuel-asm official ops
May 18, 2021
f99b127
switching laptops
May 19, 2021
af1c112
begin work on virtual registers and ops
May 19, 2021
8d6f088
daily checkpoint
May 20, 2021
f44b7fd
add AllocatedOp abstraction
May 20, 2021
61705b9
template for parsing ops
May 20, 2021
8d21ff5
allocation algorithm progress
May 20, 2021
cfa3e4a
change op parsing logic
May 21, 2021
483c46d
WIP parsing inline asm to new ops
May 21, 2021
fb5d61a
more op parsing
May 21, 2021
1723aca
finish parsing virtual ops from asm
May 21, 2021
e961af7
start registers method
May 21, 2021
f61845b
register allocation method
May 21, 2021
c36dbb5
convert virtual registers to allocated ones
May 21, 2021
d35f6bf
switch back to organizational labels for jumps
May 21, 2021
3a973af
realized ops
May 22, 2021
d8c0b83
fully allocate registers and resolve labels
May 22, 2021
ea91252
print allocated registers
May 22, 2021
b822630
merge from master; fix reg alloc algo
May 22, 2021
8347dc3
fill in todo!() errors in asm parsing
May 22, 2021
d2b6b37
resolve all todosudo apt-get install vlc in core_lang
May 22, 2021
60c0b1c
switch to ssh for fuel-asm
May 22, 2021
2156b67
resolve warnings
May 22, 2021
2c126bf
fix git url
May 22, 2021
3598dd8
rustfmt
May 22, 2021
f3ea12e
Merge branch 'master' of github.com:FuelLabs/fuel-vm-hll into allocation
May 22, 2021
8344df4
small self-code-review
May 22, 2021
cd6dbb5
resolve module
May 22, 2021
4315bc2
map the virtual opcodes to fuel_asm ops
May 23, 2021
a2a3ee7
code review feedback
May 23, 2021
a2551fb
Merge branch 'allocation' of github.com:FuelLabs/fuel-vm-hll into act…
May 23, 2021
7b87ee0
factor finalized asm out into its own file
May 23, 2021
f3dd962
merge from master
May 23, 2021
31e9f29
realize data section and instructions to bits
May 25, 2021
c39141a
data section offset label
May 26, 2021
5c21259
initial bytecode generation
May 26, 2021
11e6a17
add forc --asm command
May 26, 2021
e3c1d1a
print out the loading of the data section op
May 26, 2021
db009fb
resolve warnings
May 26, 2021
f23350d
fix register allocater bug
May 27, 2021
1b74664
cleanup
May 27, 2021
980e9c7
fix bad error message
May 27, 2021
88217bd
code review feedback
May 28, 2021
fafb111
Merge branch 'master' of github.com:fuellabs/fuel-vm-hll into actual_…
May 28, 2021
0babc0b
fix doctest
May 28, 2021
01af3d0
fix typo
May 28, 2021
3cea222
reference fuel_core for register constants
May 28, 2021
3f47eb6
add stdlib stuff
May 28, 2021
448536c
allow use of interface surface functions in the methods section of tr…
May 29, 2021
9a41e2a
comment
May 29, 2021
f6f7bea
basic math stdlib
May 29, 2021
b7ac8bf
begin work on include statements
May 30, 2021
5012317
checkpoint while i get breakfast
May 30, 2021
6998c64
parse include statements
May 30, 2021
e48654a
tiny expect fixes
Jun 3, 2021
e0a0758
merge from master
Jun 3, 2021
158e8d7
introduce BuildConfig
Jun 4, 2021
a0a9f67
build_config module
Jun 4, 2021
c321975
do plumbing for new files
Jun 4, 2021
199ead5
render warnings and errors on the right text
Jun 5, 2021
8a7e7b1
use interior library name for module name; support aliasing
Jun 5, 2021
8dbd3b8
sketch out include compilation and dead code analysis
Jun 6, 2021
b482cb8
perform dead code analysis on imported files
Jun 6, 2021
7dfe2f5
TDD: broken test cases
Jun 6, 2021
372b851
test case for included files
Jun 6, 2021
0b01b4b
nested dep example
Jun 6, 2021
81e7f9b
remove todo
Jun 6, 2021
4368e9f
importing absolutely from the root of the project
Jun 7, 2021
7546f11
tests of multi-level dependencies
Jun 7, 2021
54acaae
fix namespace catastrophic short-circuiting when hitting import errors
Jun 7, 2021
400ab26
use constants for message contents; update error message wording
Jun 9, 2021
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
39 changes: 25 additions & 14 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion core_lang/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ rust = "1.50"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
pest = "2.0"
#pest = "2.0"
pest_derive = "2.0"
pest = { git = "https://github.com/sezna/pest.git" , rev = "8aa58791f759daf4caee26e8560e862df5a6afb7" }
sezna marked this conversation as resolved.
Show resolved Hide resolved
thiserror = "1.0"
either = "1.6"
Inflector = "0.11"
Expand Down
10 changes: 5 additions & 5 deletions core_lang/src/asm_generation/expression/enum_instantiation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use crate::asm_lang::{
},
Op,
};
use crate::error::*;
use crate::semantic_analysis::ast_node::TypedEnumDeclaration;
use crate::semantic_analysis::TypedExpression;
use crate::Literal;
use crate::{CompileResult, Ident};
use crate::{
error::*,
semantic_analysis::{ast_node::TypedEnumDeclaration, TypedExpression},
CompileResult, Ident, Literal,
};

pub(crate) fn convert_enum_instantiation_to_asm<'sc>(
decl: &TypedEnumDeclaration<'sc>,
Expand Down
17 changes: 17 additions & 0 deletions core_lang/src/build_config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use std::path::PathBuf;

/// Configuration for the overall build and compilation process.
#[derive(Clone)]
pub struct BuildConfig {
pub(crate) dir_of_code: PathBuf,
}

impl BuildConfig {
// note this is intentionally not the trait Default
// since we need at least a manifest path to work with
pub fn root_from_manifest_path(canonicalized_manifest_path: PathBuf) -> Self {
let mut path = canonicalized_manifest_path.clone();
path.push("src");
Self { dir_of_code: path }
}
}
1 change: 1 addition & 0 deletions core_lang/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub const DEFAULT_FILE_EXTENSION: &str = "sw";
27 changes: 17 additions & 10 deletions core_lang/src/control_flow_analysis/dead_code_analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,19 @@ impl<'sc> ControlFlowGraph<'sc> {
})
.collect()
}
/// Constructs a graph that is designed to identify unused declarations and sections of code.
pub(crate) fn construct_dead_code_graph(

pub(crate) fn append_to_dead_code_graph(
ast: &TypedParseTree<'sc>,
tree_type: TreeType,
) -> Result<Self, CompileError<'sc>> {
let mut graph = ControlFlowGraph {
graph: Graph::new(),
entry_points: vec![],
namespace: Default::default(),
};
graph: &mut ControlFlowGraph<'sc>,
// the `Result` return is just to handle `Unimplemented` errors
) -> Result<(), CompileError<'sc>> {
// do a depth first traversal and cover individual inner ast nodes
let mut leaves = vec![];
let exit_node = Some(graph.add_node(("Program exit".to_string()).into()));
for ast_entrypoint in ast.all_nodes().iter() {
let (l_leaves, _new_exit_node) =
connect_node(ast_entrypoint, &mut graph, &leaves, exit_node, tree_type)?;
connect_node(ast_entrypoint, graph, &leaves, exit_node, tree_type)?;

leaves = l_leaves;
}
Expand Down Expand Up @@ -168,6 +165,16 @@ impl<'sc> ControlFlowGraph<'sc> {
)),
..
}) => true,
ControlFlowGraphNode::ProgramNode(TypedAstNode {
content:
TypedAstNodeContent::Declaration(TypedDeclaration::StructDeclaration(
TypedStructDeclaration {
visibility: Visibility::Public,
..
},
)),
..
}) => true,
ControlFlowGraphNode::ProgramNode(TypedAstNode {
content:
TypedAstNodeContent::Declaration(TypedDeclaration::ImplTrait { .. }),
Expand All @@ -177,7 +184,7 @@ impl<'sc> ControlFlowGraph<'sc> {
})
.collect(),
};
Ok(graph)
Ok(())
}
}
fn connect_node<'sc>(
Expand Down
13 changes: 13 additions & 0 deletions core_lang/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,16 @@ pub enum CompileError<'sc> {
UnknownType { span: Span<'sc> },
#[error("Bytecode can only support programs with up to 2^12 words worth of opcodes. Try refactoring into contract calls? This is a temporary error and will be implemented in the future.")]
TooManyInstructions { span: Span<'sc> },
#[error("No valid Sway file (.sw) was found at {file_path}")]
sezna marked this conversation as resolved.
Show resolved Hide resolved
FileNotFound { span: Span<'sc>, file_path: String },
#[error("The file {file_path} could not be read: {stringified_error}")]
FileCouldNotBeRead {
span: Span<'sc>,
file_path: String,
stringified_error: String,
},
#[error("This imported file must be a library. It must start with \"library <name>\", where \"name\" is the name of the library/module this file contains.")]
sezna marked this conversation as resolved.
Show resolved Hide resolved
ImportMustBeLibrary { span: Span<'sc> },
}

impl<'sc> std::convert::From<TypeError<'sc>> for CompileError<'sc> {
Expand Down Expand Up @@ -780,6 +790,9 @@ impl<'sc> CompileError<'sc> {
UnknownType { span, .. } => span,
InvalidStrType { span, .. } => span,
TooManyInstructions { span, .. } => span,
FileNotFound { span, .. } => span,
FileCouldNotBeRead { span, .. } => span,
ImportMustBeLibrary { span, .. } => span,
}
}

Expand Down
23 changes: 15 additions & 8 deletions core_lang/src/hll.pest
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,21 @@ block_comment_open = {"/*"}
block_comment_close = {"*/"}
fn_returns = {"->"}
path_separator = {"::"}
include_keyword = { "dep" }

// top level
program = {SOI ~ (library|contract|script|predicate)? ~ EOI}

library = {"library" ~ library_name ~ ";" ~ (control_flow|declaration|use_statement)* }
library = {"library" ~ library_name ~ ";" ~ (control_flow|declaration|use_statement|include_statement)* }
library_name = {ident}
contract = {"contract" ~ ";" ~ (control_flow|declaration|use_statement)*}
script = {"script" ~ ";" ~ (control_flow|declaration|use_statement)*}
predicate = {"predicate" ~ ";" ~ (control_flow|declaration|use_statement)*}

contract = {"contract" ~ ";" ~ (control_flow|declaration|use_statement|include_statement)*}
script = {"script" ~ ";" ~ (control_flow|declaration|use_statement|include_statement)*}
predicate = {"predicate" ~ ";" ~ (control_flow|declaration|use_statement|include_statement)*}

// including other files
file_path = { ident ~ ("/" ~ ident)* }
include_statement = { include_keyword ~ file_path ~ alias? ~ ";"}
alias = { "as" ~ ident }
// expressions
expr_inner = _{literal_value|if_exp|parenthesized_expression|asm_expression|code_block|func_app|struct_expression|delineated_path|method_exp|subfield_exp|var_exp|array_exp|match_expression|unit}
parenthesized_expression = {"(" ~ expr ~ ")"}
Expand Down Expand Up @@ -131,9 +136,11 @@ impl_trait = {impl_keyword ~ trait_name ~ type_params? ~ "for" ~ type_name ~

// imports

use_statement = {use_keyword ~ import_path ~ ";"}
import_path = {ident ~ (path_separator ~ (ident|star))*}
star = {"*"}
use_statement = {relative_use_statement | absolute_use_statement}
relative_use_statement = {use_keyword ~ import_path ~ ";"}
absolute_use_statement = {use_keyword ~ path_separator ~ import_path ~ ";"}
import_path = {ident ~ (path_separator ~ (ident|star))*}
star = {"*"}

// loops
while_loop = {while_keyword ~ expr ~ code_block}
Expand Down
Loading