Skip to content

Commit

Permalink
Bring back the relative position calculation to have reasonable error…
Browse files Browse the repository at this point in the history
… messages
  • Loading branch information
cakevm committed Jan 8, 2025
1 parent a672516 commit 801d3ee
Showing 52 changed files with 214 additions and 195 deletions.
2 changes: 1 addition & 1 deletion crates/codegen/src/irgen/statements.rs
Original file line number Diff line number Diff line change
@@ -165,7 +165,7 @@ pub fn statement_gen<'a>(
// Special case:
// If the macro provided to __codesize is the current macro, we need to avoid a
// circular reference If this is the case we will store a
// place holder inside the bytecode and fill it in later when
// placeholder inside the bytecode and fill it in later when
// we have adequate information about the macros eventual size.
// We also need to avoid if the codesize arg is any of the previous macros to
// avoid a circular reference
4 changes: 2 additions & 2 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -312,7 +312,7 @@ impl<'a, 'l> Compiler<'a, 'l> {

// Perform Lexical Analysis
// Create a new lexer from the FileSource, flattening dependencies
let lexer = Lexer::new(full_source.source, Some(file.clone()));
let lexer = Lexer::new(full_source);

// Grab the tokens from the lexer
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
@@ -346,7 +346,7 @@ impl<'a, 'l> Compiler<'a, 'l> {

// Perform Lexical Analysis
// Create a new lexer from the FileSource, flattening dependencies
let lexer = Lexer::new(full_source.source, Some(file.clone()));
let lexer = Lexer::new(full_source);

// Grab the tokens from the lexer
let mut tokens = Vec::new();
2 changes: 1 addition & 1 deletion crates/core/tests/alternative_constructor_macro.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ fn test_alternative_constructor_macro_provided() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
2 changes: 1 addition & 1 deletion crates/core/tests/alternative_main_macro.rs
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ fn test_alternative_main_macro_provided() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
2 changes: 1 addition & 1 deletion crates/core/tests/breaking_jumptable.rs
Original file line number Diff line number Diff line change
@@ -133,7 +133,7 @@ fn test_breaking_jump_table() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

22 changes: 11 additions & 11 deletions crates/core/tests/builtins.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ fn test_codesize_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -59,7 +59,7 @@ fn test_dyn_constructor_arg_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -149,7 +149,7 @@ fn test_tablesize_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -213,7 +213,7 @@ fn test_tablestart_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -277,7 +277,7 @@ fn test_jump_table_exhaustive_usage() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -337,7 +337,7 @@ fn test_jump_table_packed_exhaustive_usage() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -404,7 +404,7 @@ fn test_label_clashing() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -448,7 +448,7 @@ fn test_func_sig_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -488,7 +488,7 @@ fn test_event_hash_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -559,7 +559,7 @@ fn test_error_selector_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -599,7 +599,7 @@ fn test_rightpad_builtin() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

14 changes: 7 additions & 7 deletions crates/core/tests/codegen_errors.rs
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ fn test_storage_pointers_not_derived() {
// let const_end = const_start + "UNKNOWN_CONSTANT_DEFINITION".len();

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let contract = parser.parse().unwrap();
@@ -92,7 +92,7 @@ fn test_invalid_constant_definition() {
let const_end = const_start + "UNKNOWN_CONSTANT_DEFINITION".len() - 1;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
@@ -133,7 +133,7 @@ fn test_missing_constructor() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
@@ -166,7 +166,7 @@ fn test_missing_main() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
@@ -199,7 +199,7 @@ fn test_missing_when_alternative_main_provided() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
@@ -242,7 +242,7 @@ fn test_unknown_macro_definition() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
@@ -289,7 +289,7 @@ fn test_unmatched_jump_label() {
"#;

let full_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("".to_string()));
let mut contract = parser.parse().unwrap();
4 changes: 2 additions & 2 deletions crates/core/tests/compiling.rs
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ const SOURCE: &str = r#"
fn compiles_constructor_bytecode() {
// Lex and Parse the source code
let flattened_source = FullFileSource { source: SOURCE, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -66,7 +66,7 @@ fn compiles_constructor_bytecode() {
fn compiles_runtime_bytecode() {
// Lex and Parse the source code
let flattened_source = FullFileSource { source: SOURCE, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

2 changes: 1 addition & 1 deletion crates/core/tests/erc20.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ fn test_erc20_compile() {
let recursed_file_source = Compiler::recurse_deps(Arc::clone(file_source), &files::Remapper::new("./"), file_provider).unwrap();
let flattened = FileSource::fully_flatten(Arc::clone(&recursed_file_source));
let full_source = FullFileSource { source: &flattened.0, file: Some(Arc::clone(file_source)), spans: flattened.1 };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut contract = parser.parse().unwrap();
2 changes: 1 addition & 1 deletion crates/core/tests/erc721.rs
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ fn test_erc721_compile() {
let recursed_file_source = Compiler::recurse_deps(Arc::clone(file_source), &files::Remapper::new("./"), file_provider).unwrap();
let flattened = FileSource::fully_flatten(Arc::clone(&recursed_file_source));
let full_source = FullFileSource { source: &flattened.0, file: Some(Arc::clone(file_source)), spans: flattened.1 };
let lexer = Lexer::new(full_source.source, None);
let lexer = Lexer::new(full_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, Some("../../huff-examples/erc20/contracts".to_string()));
let mut contract = parser.parse().unwrap();
10 changes: 5 additions & 5 deletions crates/core/tests/exports_events.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ fn test_abi_uint_events() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -56,7 +56,7 @@ fn test_abi_int_events() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -96,7 +96,7 @@ fn test_abi_simple_events() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -135,7 +135,7 @@ fn test_abi_tuple_array_events() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -174,7 +174,7 @@ fn test_abi_nested_tuple_array_events() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
2 changes: 1 addition & 1 deletion crates/core/tests/free_storage_pointer.rs
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ fn test_set_free_storage_pointers() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

4 changes: 2 additions & 2 deletions crates/core/tests/functions.rs
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ fn test_function() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

@@ -186,7 +186,7 @@ fn test_nested_function() {

// Parse tokens
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);

16 changes: 8 additions & 8 deletions crates/core/tests/macro_invoc_args.rs
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ fn test_opcode_macro_args() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -57,7 +57,7 @@ fn test_all_opcodes_in_macro_args() {

// Lex + Parse
let flattened_source = FullFileSource { source: &source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -95,7 +95,7 @@ fn test_constant_macro_arg() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -135,7 +135,7 @@ fn test_bubbled_label_call_macro_arg() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -174,7 +174,7 @@ fn test_bubbled_literal_macro_arg() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -213,7 +213,7 @@ fn test_bubbled_opcode_macro_arg() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -254,7 +254,7 @@ fn test_bubbled_constant_macro_arg() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
@@ -291,7 +291,7 @@ fn test_bubbled_arg_with_different_name() {

// Lex + Parse
let flattened_source = FullFileSource { source, file: None, spans: vec![] };
let lexer = Lexer::new(flattened_source.source, None);
let lexer = Lexer::new(flattened_source);
let tokens = lexer.into_iter().map(|x| x.unwrap()).collect::<Vec<Token>>();
let mut parser = Parser::new(tokens, None);
let mut contract = parser.parse().unwrap();
Loading

0 comments on commit 801d3ee

Please sign in to comment.