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
25 changes: 2 additions & 23 deletions crates/wit-component/src/printing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use std::mem;
use std::ops::Deref;
use wit_parser::*;

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

/// A utility for printing WebAssembly interface definitions to a string.
pub struct WitPrinter<O: Output = OutputToString> {
/// Visitor that holds the WIT document being printed.
Expand All @@ -20,8 +17,6 @@ pub struct WitPrinter<O: Output = OutputToString> {

// Whether to print doc comments.
emit_docs: bool,

print_f32_f64: bool,
}

impl Default for WitPrinter {
Expand All @@ -37,10 +32,6 @@ impl<O: Output> WitPrinter<O> {
output,
any_items: false,
emit_docs: true,
print_f32_f64: match std::env::var("WIT_REQUIRE_F32_F64") {
Ok(s) => s == "1",
Err(_) => PRINT_F32_F64_DEFAULT,
},
}
}

Expand Down Expand Up @@ -543,20 +534,8 @@ impl<O: Output> WitPrinter<O> {
Type::S16 => self.output.ty("s16", TypeKind::BuiltIn),
Type::S32 => self.output.ty("s32", TypeKind::BuiltIn),
Type::S64 => self.output.ty("s64", TypeKind::BuiltIn),
Type::F32 => {
if self.print_f32_f64 {
self.output.ty("f32", TypeKind::BuiltIn)
} else {
self.output.ty("f32", TypeKind::BuiltIn)
}
}
Type::F64 => {
if self.print_f32_f64 {
self.output.ty("f64", TypeKind::BuiltIn)
} else {
self.output.ty("f64", TypeKind::BuiltIn)
}
}
Type::F32 => self.output.ty("f32", TypeKind::BuiltIn),
Type::F64 => self.output.ty("f64", TypeKind::BuiltIn),
Type::Char => self.output.ty("char", TypeKind::BuiltIn),
Type::String => self.output.ty("string", TypeKind::BuiltIn),
Type::ErrorContext => self.output.ty("error-context", TypeKind::BuiltIn),
Expand Down
9 changes: 1 addition & 8 deletions crates/wit-parser/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,6 @@ fn eat_id(tokens: &mut Tokenizer<'_>, expected: &str) -> Result<Span> {
pub struct SourceMap {
sources: Vec<Source>,
offset: u32,
require_f32_f64: Option<bool>,
}

#[derive(Clone)]
Expand All @@ -1709,11 +1708,6 @@ impl SourceMap {
SourceMap::default()
}

#[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`].
#[cfg(feature = "std")]
Expand Down Expand Up @@ -1778,7 +1772,6 @@ impl SourceMap {
// passing through the source to get tokenized.
&src.contents[..src.contents.len() - 1],
src.offset,
self.require_f32_f64,
)
.with_context(|| format!("failed to tokenize path: {}", src.path))?;
let mut file = PackageFile::parse(&mut tokens)?;
Expand Down Expand Up @@ -1965,7 +1958,7 @@ pub enum ParsedUsePath {
}

pub fn parse_use_path(s: &str) -> Result<ParsedUsePath> {
let mut tokens = Tokenizer::new(s, 0, None)?;
let mut tokens = Tokenizer::new(s, 0)?;
let path = UsePath::parse(&mut tokens)?;
if tokens.next()?.is_some() {
bail!("trailing tokens in path specifier");
Expand Down
23 changes: 2 additions & 21 deletions crates/wit-parser/src/ast/lex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ pub struct Tokenizer<'a> {
input: &'a str,
span_offset: u32,
chars: CrlfFold<'a>,
require_f32_f64: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -120,15 +119,8 @@ pub enum Error {
},
}

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

impl<'a> Tokenizer<'a> {
pub fn new(
input: &'a str,
span_offset: u32,
require_f32_f64: Option<bool>,
) -> Result<Tokenizer<'a>> {
pub fn new(input: &'a str, span_offset: u32) -> Result<Tokenizer<'a>> {
detect_invalid_input(input)?;

let mut t = Tokenizer {
Expand All @@ -137,15 +129,6 @@ impl<'a> Tokenizer<'a> {
chars: CrlfFold {
chars: input.char_indices(),
},
require_f32_f64: require_f32_f64.unwrap_or_else(|| {
#[cfg(feature = "std")]
match std::env::var("WIT_REQUIRE_F32_F64") {
Ok(s) => s == "1",
Err(_) => REQUIRE_F32_F64_BY_DEFAULT,
}
#[cfg(not(feature = "std"))]
REQUIRE_F32_F64_BY_DEFAULT
}),
};
// Eat utf-8 BOM
t.eatc('\u{feff}');
Expand Down Expand Up @@ -289,8 +272,6 @@ impl<'a> Tokenizer<'a> {
"s64" => S64,
"f32" => F32,
"f64" => F64,
"float32" if !self.require_f32_f64 => F32,
"float64" if !self.require_f32_f64 => F64,
"char" => Char,
"resource" => Resource,
"own" => Own,
Expand Down Expand Up @@ -673,7 +654,7 @@ fn test_validate_id() {
#[test]
fn test_tokenizer() {
fn collect(s: &str) -> Result<Vec<Token>> {
let mut t = Tokenizer::new(s, 0, None)?;
let mut t = Tokenizer::new(s, 0)?;
let mut tokens = Vec::new();
while let Some(token) = t.next()? {
tokens.push(token.1);
Expand Down