Skip to content
Draft
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
35 changes: 33 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ jobs:
- os: macOS-latest
steps:
- uses: actions/checkout@v2
- name: Install Mac System dependencies
- name: Install Boost on Mac
if: startsWith(matrix.os,'macOS')
run: |
brew install boost
- name: Install Linux dependencies
- name: Install Boost on Linux
if: startsWith(matrix.os,'ubuntu')
run: |
sudo apt-get install -y libboost-all-dev
Expand All @@ -121,6 +121,37 @@ jobs:
run: cargo test --workspace --all-features --no-run --locked
- name: Run tests
run: cargo test --workspace --all-features --verbose

test-windows-latest:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Install Boost on Windows.
uses: MarkusJx/install-boost@v2.1.0
id: install-boost
with:
boost_version: 1.78.0
platform_version: 2019
toolset: msvc
- name: Install rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- name: Cache Dependencies
uses: Swatinem/rust-cache@v1
- name: Build
run: cargo test --workspace --all-features --no-run --locked
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
Boost_NO_BOOST_CMAKE: ON
- name: Run tests
run: cargo test --workspace --all-features --verbose
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
Boost_NO_BOOST_CMAKE: ON


wasm-test:
runs-on: ubuntu-latest
Expand Down
19 changes: 8 additions & 11 deletions crates/analyzer/tests/snapshots/analysis__strings.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/analyzer/tests/analysis.rs
expression: "build_snapshot(\"features/strings.fe\", &src, module, &db)"
expression: "build_snapshot(&files, module_id, &db)"

---
note:
Expand Down Expand Up @@ -132,29 +132,26 @@ note:
note:
┌─ features/strings.fe:23:5
23 │ ╭ pub fn return_special_chars() -> String<18>:
24 │ │ return "\n\"'\r\t
25 │ │ foo\\"
│ ╰──────────────^ attributes hash: 14991635520577142188
23 │ ╭ pub fn return_special_chars() -> String<9>:
24 │ │ return "\n\"'\r\tfoo\\"
│ ╰───────────────────────────────^ attributes hash: 2714027657010055129
= FunctionSignature {
self_decl: None,
params: [],
return_type: Ok(
String(
FeString {
max_size: 18,
max_size: 9,
},
),
),
}

note:
┌─ features/strings.fe:24:16
24 │ return "\n\"'\r\t
│ ╭────────────────^
25 │ │ foo\\"
│ ╰──────────────^ String<18>: Memory
24 │ return "\n\"'\r\tfoo\\"
│ ^^^^^^^^^^^^^^^^ String<9>: Memory


13 changes: 8 additions & 5 deletions crates/common/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use include_dir::Dir;
use indexmap::indexmap;
use indexmap::IndexMap;
use smol_str::SmolStr;
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::ops::Range;
use std::path::Path;
use std::{fs, io};
Expand All @@ -24,7 +24,10 @@ pub struct SourceFileId(pub u128);

impl SourceFile {
pub fn new(name: &str, content: &str) -> Self {
let hash = keccak::full_as_bytes(content.as_bytes());
// Canonicalize new line character for Windows.
let content_canonicalized = content.replace("\r\n", "\n");
let hash = keccak::full_as_bytes(content_canonicalized.as_bytes());

let line_starts = cs::files::line_starts(content).collect();
Self {
id: SourceFileId(u128::from_be_bytes(hash[..16].try_into().unwrap())),
Expand Down Expand Up @@ -63,21 +66,21 @@ impl FileLoader for OsFileLoader {
}

pub struct FileStore {
pub files: HashMap<SourceFileId, SourceFile>,
pub files: BTreeMap<SourceFileId, SourceFile>,
loader: Box<dyn FileLoader>,
}

impl FileStore {
pub fn new() -> Self {
Self {
files: HashMap::new(),
files: BTreeMap::new(),
loader: Box::new(OsFileLoader),
}
}

pub fn with_loader(loader: Box<dyn FileLoader>) -> Self {
Self {
files: HashMap::new(),
files: BTreeMap::new(),
loader,
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/parser/src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub enum TokenKind {
#[error]
Error,

#[regex(r"\n[ \t]*")]
#[regex(r"[\r]?\n[ \t]*")]
Newline,

/// Virtual tokens emitted by the parser
Expand All @@ -52,8 +52,8 @@ pub enum TokenKind {
#[regex("0[bB][0-1]+")]
Binary,
// Float,
#[regex(r#""([^"\\]|\\.)*""#)]
#[regex(r#"'([^'\\]|\\.)*'"#)]
#[regex(r#""([^"\\\n]|\\.)*""#)]
#[regex(r#"'([^'\\\n]|\\.)*'"#)]
Text,
#[token("true")]
True,
Expand Down
4 changes: 4 additions & 0 deletions crates/test-files/fixtures/compile_errors/string_literal.fe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
contract Foo:
pub fn bar():
let s: String<16> = "This is
Invalid"
5 changes: 2 additions & 3 deletions crates/test-files/fixtures/features/strings.fe
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ contract Foo:
pub fn return_casted_static_string() -> String<100>:
return String<100>("foo")

pub fn return_special_chars() -> String<18>:
return "\n\"'\r\t
foo\\"
pub fn return_special_chars() -> String<9>:
return "\n\"'\r\tfoo\\"
9 changes: 3 additions & 6 deletions crates/tests/src/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -797,10 +797,7 @@ fn strings() {
&mut executor,
"return_special_chars",
&[],
Some(&string_token(
"\n\"'\r\t
foo\\",
)),
Some(&string_token("\n\"'\r\tfoo\\")),
);

harness.events_emitted(
Expand Down Expand Up @@ -1696,8 +1693,8 @@ fn abi_decode_checks() {
// this would break the equivalence of string's `data_offset + data_size` and
// the bytes' `data_offset`, making the encoding invalid
tampered_data[byte_index] = 33;
// the string length is completely valid otherwise. 32 for example will not revert
// tampered_data[byte_index] = 32;
// the string length is completely valid otherwise. 32 for example will not
// revert tampered_data[byte_index] = 32;
harness.test_call_reverts(&mut executor, tampered_data, &revert_data);

// place non-zero byte in padded region of the string
Expand Down