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

Add migration code for f32/f64. #1364

Merged
Merged
Changes from 1 commit
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
Prev Previous commit
Enable float32/float64 by default.
  • Loading branch information
sunfishcode committed Jan 9, 2024
commit a0226e44f7f8197a61d8c8fc1d413bea80ed14b1
2 changes: 1 addition & 1 deletion crates/wit-component/src/printing.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ use wit_parser::*;

// NB: keep in sync with `crates/wit-parser/src/ast/lex.rs`
const PRINT_SEMICOLONS_DEFAULT: bool = true;
const PRINT_F32_F64_DEFAULT: bool = true;
const PRINT_F32_F64_DEFAULT: bool = false;

/// A utility for printing WebAssembly interface definitions to a string.
pub struct WitPrinter {
17 changes: 14 additions & 3 deletions crates/wit-parser/src/ast.rs
Original file line number Diff line number Diff line change
@@ -1160,6 +1160,7 @@ pub struct SourceMap {
sources: Vec<Source>,
offset: u32,
require_semicolons: Option<bool>,
require_f32_f64: Option<bool>,
}

#[derive(Clone)]
@@ -1180,6 +1181,11 @@ impl SourceMap {
self.require_semicolons = Some(enable);
}

#[doc(hidden)] // NB: only here for a transitionary period
pub fn set_require_f32_f64(&mut self, enable: bool) {
self.require_f32_f64 = Some(enable);
}

/// Reads the file `path` on the filesystem and appends its contents to this
/// [`SourceMap`].
pub fn push_file(&mut self, path: &Path) -> Result<()> {
@@ -1214,8 +1220,13 @@ impl SourceMap {
let mut srcs = self.sources.iter().collect::<Vec<_>>();
srcs.sort_by_key(|src| &src.path);
for src in srcs {
let mut tokens = Tokenizer::new(&src.contents, src.offset, self.require_semicolons)
.with_context(|| format!("failed to tokenize path: {}", src.path.display()))?;
let mut tokens = Tokenizer::new(
&src.contents,
src.offset,
self.require_semicolons,
self.require_f32_f64,
)
.with_context(|| format!("failed to tokenize path: {}", src.path.display()))?;
let ast = Ast::parse(&mut tokens)?;
resolver.push(ast).with_context(|| {
format!("failed to start resolving path: {}", src.path.display())
@@ -1324,7 +1335,7 @@ pub(crate) enum AstUsePath {
}

pub(crate) fn parse_use_path(s: &str) -> Result<AstUsePath> {
let mut tokens = Tokenizer::new(s, 0, Some(true))?;
let mut tokens = Tokenizer::new(s, 0, Some(true), None)?;
let path = UsePath::parse(&mut tokens)?;
if tokens.next()?.is_some() {
bail!("trailing tokens in path specifier");
4 changes: 2 additions & 2 deletions crates/wit-parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
@@ -119,7 +119,7 @@ pub enum Error {

// NB: keep in sync with `crates/wit-component/src/printing.rs`.
const REQUIRE_SEMICOLONS_BY_DEFAULT: bool = true;
const REQUIRE_F32_F64_BY_DEFAULT: bool = true;
const REQUIRE_F32_F64_BY_DEFAULT: bool = false;

impl<'a> Tokenizer<'a> {
pub fn new(
@@ -665,7 +665,7 @@ fn test_validate_id() {
#[test]
fn test_tokenizer() {
fn collect(s: &str) -> Result<Vec<Token>> {
let mut t = Tokenizer::new(s, 0, Some(true))?;
let mut t = Tokenizer::new(s, 0, Some(true), None)?;
let mut tokens = Vec::new();
while let Some(token) = t.next()? {
tokens.push(token.1);