[rust] add+apply rustfmt config

This commit is contained in:
Joe Savona
2023-07-14 15:33:06 +09:00
parent 18f7481ebf
commit 19b0a49967
18 changed files with 939 additions and 1111 deletions
@@ -1,6 +1,7 @@
use std::collections::HashSet;
use bumpalo::{boxed::Box, collections::String};
use bumpalo::boxed::Box;
use bumpalo::collections::String;
use forget_diagnostics::{Diagnostic, DiagnosticSeverity};
use forget_estree::{
AssignmentTarget, BinaryExpression, BlockStatement, Expression, ForInit, ForStatement,
@@ -13,11 +14,9 @@ use forget_hir::{
PrimitiveValue, TerminalValue,
};
use crate::{
builder::{Binding, Builder, LoopScope},
context::get_context_identifiers,
error::BuildHIRError,
};
use crate::builder::{Binding, Builder, LoopScope};
use crate::context::get_context_identifiers;
use crate::error::BuildHIRError;
/// Converts a React function in ESTree format into HIR. Returns the HIR
/// if it was constructed sucessfully, otherwise a list of diagnostics
@@ -1,10 +1,10 @@
use bumpalo::{
boxed::Box,
collections::{String, Vec},
};
use forget_diagnostics::{invariant, Diagnostic, DiagnosticSeverity};
use std::{cell::RefCell, collections::HashSet, rc::Rc};
use std::cell::RefCell;
use std::collections::HashSet;
use std::rc::Rc;
use bumpalo::boxed::Box;
use bumpalo::collections::{String, Vec};
use forget_diagnostics::{invariant, Diagnostic, DiagnosticSeverity};
use forget_hir::{
BasicBlock, BlockId, BlockKind, Environment, GotoKind, Identifier, IdentifierData, InstrIx,
Instruction, InstructionIdGenerator, InstructionValue, Terminal, TerminalValue, Type, HIR,
@@ -1,7 +1,5 @@
use std::{
error::Error,
fmt::{Debug, Display, Write},
};
use std::error::Error;
use std::fmt::{Debug, Display, Write};
use forget_estree::SourceRange;
use miette::{ByteOffset, SourceSpan};
@@ -8,9 +8,5 @@ pub fn invariant<F>(cond: bool, f: F) -> Result<(), Diagnostic>
where
F: Fn() -> Diagnostic,
{
if cond {
Ok(())
} else {
Err(f())
}
if cond { Ok(()) } else { Err(f()) }
}
File diff suppressed because it is too large Load Diff
@@ -1,4 +1,5 @@
use serde::{de::Visitor, Deserialize, Serialize};
use serde::de::Visitor;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Clone, Debug, PartialEq, PartialOrd, Hash)]
pub enum JsValue {
@@ -9,7 +10,18 @@ pub enum JsValue {
String(String),
}
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, Debug)]
#[derive(
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Serialize,
Deserialize,
Debug
)]
pub struct Number(u64);
impl From<u32> for Number {
@@ -13,10 +13,11 @@ pub use visit::*;
#[cfg(test)]
mod tests {
use super::*;
use insta::{assert_snapshot, glob};
use serde_json;
use super::*;
#[test]
fn fixtures() {
glob!("fixtures/**.json", |path| {
@@ -2,7 +2,16 @@ use std::num::NonZeroU32;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Copy, Clone, Debug, PartialEq, PartialOrd, Hash)]
#[derive(
Serialize,
Deserialize,
Copy,
Clone,
Debug,
PartialEq,
PartialOrd,
Hash
)]
pub struct SourceRange {
pub start: u32,
pub end: NonZeroU32,
@@ -1,7 +1,8 @@
use std::collections::HashSet;
use indexmap::IndexMap;
use quote::{__private::TokenStream, format_ident, quote};
use quote::__private::TokenStream;
use quote::{format_ident, quote};
use serde::{Deserialize, Serialize};
use syn::Type;
@@ -1,4 +1,6 @@
use std::{io::stderr, num::NonZeroU32, sync::Arc};
use std::io::stderr;
use std::num::NonZeroU32;
use std::sync::Arc;
use forget_estree::{Binding, BindingId};
use swc::Compiler;
@@ -412,21 +414,22 @@ fn convert_assignment_target(cx: &Context, target: &PatOrExpr) -> forget_estree:
PatOrExpr::Pat(target) => {
forget_estree::AssignmentTarget::Pattern(convert_pattern(cx, target))
}
PatOrExpr::Expr(target) => {
match target.as_ref() {
Expr::Member(target) => forget_estree::AssignmentTarget::Expression(
forget_estree::Expression::MemberExpression(Box::new(
convert_member_expression(cx, target),
)),
),
Expr::Ident(target) => forget_estree::AssignmentTarget::Pattern(
forget_estree::Pattern::Identifier(Box::new(convert_identifier(cx, target))),
),
_ => {
panic!("Expected assignment target to be member expression or identifier, got {:#?}", target)
}
PatOrExpr::Expr(target) => match target.as_ref() {
Expr::Member(target) => forget_estree::AssignmentTarget::Expression(
forget_estree::Expression::MemberExpression(Box::new(convert_member_expression(
cx, target,
))),
),
Expr::Ident(target) => forget_estree::AssignmentTarget::Pattern(
forget_estree::Pattern::Identifier(Box::new(convert_identifier(cx, target))),
),
_ => {
panic!(
"Expected assignment target to be member expression or identifier, got {:#?}",
target
)
}
}
},
}
}
@@ -1,4 +1,5 @@
use std::{env, fmt::Write};
use std::env;
use std::fmt::Write;
use bumpalo::Bump;
use forget_build_hir::build;
@@ -2,7 +2,8 @@ use std::fmt::Display;
use indexmap::{IndexMap, IndexSet};
use crate::{id_types::BlockId, Identifier, InstrIx, Terminal};
use crate::id_types::BlockId;
use crate::{Identifier, InstrIx, Terminal};
/// Represents a sequence of instructions that will always[1] execute
/// consecutively. Concretely, a block may have zero or more instructions
@@ -1,10 +1,10 @@
use std::{
cell::{Cell, RefCell},
collections::HashMap,
rc::Rc,
};
use std::cell::{Cell, RefCell};
use std::collections::HashMap;
use std::rc::Rc;
use bumpalo::{boxed::Box, collections::Vec, Bump};
use bumpalo::boxed::Box;
use bumpalo::collections::Vec;
use bumpalo::Bump;
use forget_estree::BindingId;
use crate::{
@@ -1,7 +1,5 @@
use bumpalo::{
boxed::Box,
collections::{String, Vec},
};
use bumpalo::boxed::Box;
use bumpalo::collections::{String, Vec};
use indexmap::IndexMap;
use crate::{BasicBlock, BlockId, IdentifierOperand, Instruction};
@@ -1,9 +1,9 @@
use std::{cell::RefCell, fmt::Display, rc::Rc};
use std::cell::RefCell;
use std::fmt::Display;
use std::rc::Rc;
use bumpalo::{
boxed::Box,
collections::{String, Vec},
};
use bumpalo::boxed::Box;
use bumpalo::collections::{String, Vec};
use forget_estree::BinaryOperator;
use crate::{Function, IdentifierId, InstrIx, InstructionId, ScopeId, Type};
@@ -1,4 +1,5 @@
use crate::{instruction::Operand, BlockId, InstructionId};
use crate::instruction::Operand;
use crate::{BlockId, InstructionId};
/// Terminals represent statements or expressions that affect control flow,
/// such as for-of, if-else, return, logical (??), ternaries (?:), etc.
@@ -1,4 +1,5 @@
use std::{cell::RefCell, rc::Rc};
use std::cell::RefCell;
use std::rc::Rc;
use bumpalo::collections::{CollectIn, Vec};
use forget_hir::{
@@ -145,7 +146,10 @@ impl<'a, 'e, 'f> Builder<'a, 'e, 'f> {
fn visit_store(&mut self, lvalue: &mut LValue<'a>) -> () {
let old_identifier = &lvalue.identifier.identifier;
// TODO: use Result (?)
assert!(!self.unknown.contains(&old_identifier.id), "EnterSSA: Expected identifier to be defined before being used. Identifier {old_identifier:?} is undefined.");
assert!(
!self.unknown.contains(&old_identifier.id),
"EnterSSA: Expected identifier to be defined before being used. Identifier {old_identifier:?} is undefined."
);
if self.context.contains(&old_identifier.id) {
let new_identifier = self.get_id_at(self.current, old_identifier);
+8
View File
@@ -0,0 +1,8 @@
# Get help on options with `rustfmt --help=config`
# Please keep these in alphabetical order.
edition = "2021"
group_imports = "StdExternalCrate"
imports_granularity = "Module"
merge_derives = false
use_field_init_shorthand = true
version = "Two"