Rust: Set import granularity to Item
By default, `rustfmt` persists the import granularity. In practice, most Rust code has import granularity "Module" due to LSP's actions. "Item" gets rid of import groupings and achieves cleaner diffs and better conflict resolution. Better greppability is a positive side effect. Note: it's an unstable rustfmt feature. `cargo +nightly fmt` must be used instead of `cargo fmt`.
This commit is contained in:
parent
b7c4cd511f
commit
f3a3488cda
35 changed files with 312 additions and 126 deletions
6
.github/actions/setup/action.yml
vendored
6
.github/actions/setup/action.yml
vendored
|
|
@ -114,6 +114,12 @@ runs:
|
|||
if: ${{ inputs.os == 'macOS' || inputs.os == 'Android' }}
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
# TODO: Remove once `imports_granularity` rustfmt option is stable. https://rust-lang.github.io/rustfmt/?version=v1.9.0&search=group#imports_granularity
|
||||
- name: 'Install Nightly Rust toolchain for linting'
|
||||
if: ${{ inputs.type == 'lint' }}
|
||||
shell: bash
|
||||
run: rustup toolchain install nightly --component rustfmt
|
||||
|
||||
- name: 'Install wasm-tools'
|
||||
if: ${{ inputs.type == 'build' }}
|
||||
shell: bash
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
use yuv::{YuvPlanarImage, YuvRange, YuvStandardMatrix};
|
||||
use yuv::YuvPlanarImage;
|
||||
use yuv::YuvRange;
|
||||
use yuv::YuvStandardMatrix;
|
||||
|
||||
#[repr(u8)]
|
||||
pub enum YUVRange {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,14 @@
|
|||
//! code instead of C++. The generated code lives in $OUT_DIR/instruction_generated.rs
|
||||
//! and is included! from src/bytecode/instruction.rs.
|
||||
|
||||
use bytecode_def::{
|
||||
Field, OpDef, STRUCT_ALIGN, compute_layouts, field_type_info, find_m_length_offset, round_up, user_fields,
|
||||
};
|
||||
use bytecode_def::Field;
|
||||
use bytecode_def::OpDef;
|
||||
use bytecode_def::STRUCT_ALIGN;
|
||||
use bytecode_def::compute_layouts;
|
||||
use bytecode_def::field_type_info;
|
||||
use bytecode_def::find_m_length_offset;
|
||||
use bytecode_def::round_up;
|
||||
use bytecode_def::user_fields;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::io::Write;
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@
|
|||
|
||||
use std::ffi::c_void;
|
||||
use std::fmt;
|
||||
use std::ops::{Index, IndexMut};
|
||||
use std::ops::Index;
|
||||
use std::ops::IndexMut;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicPtr, Ordering};
|
||||
use std::sync::atomic::AtomicPtr;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
use crate::fast_hash::HashMap;
|
||||
|
||||
|
|
|
|||
|
|
@ -41,17 +41,29 @@
|
|||
use std::collections::HashSet;
|
||||
|
||||
use num_bigint::BigInt;
|
||||
use num_traits::{One, Signed, ToPrimitive, Zero};
|
||||
use num_traits::One;
|
||||
use num_traits::Signed;
|
||||
use num_traits::ToPrimitive;
|
||||
use num_traits::Zero;
|
||||
|
||||
use crate::ast::*;
|
||||
use crate::lexer::ch;
|
||||
use crate::u32_from_usize;
|
||||
|
||||
use super::ffi::{AbstractOperationKind, WellKnownSymbolKind};
|
||||
use super::generator::{
|
||||
BlockBoundaryType, ConstantValue, FinallyContext, Generator, PendingClassBlueprint, PendingClassElement,
|
||||
PendingLiteralValueKind, PendingSharedFunctionData, ScopedOperand, choose_dst, constant_to_boolean, parse_bigint,
|
||||
};
|
||||
use super::ffi::AbstractOperationKind;
|
||||
use super::ffi::WellKnownSymbolKind;
|
||||
use super::generator::BlockBoundaryType;
|
||||
use super::generator::ConstantValue;
|
||||
use super::generator::FinallyContext;
|
||||
use super::generator::Generator;
|
||||
use super::generator::PendingClassBlueprint;
|
||||
use super::generator::PendingClassElement;
|
||||
use super::generator::PendingLiteralValueKind;
|
||||
use super::generator::PendingSharedFunctionData;
|
||||
use super::generator::ScopedOperand;
|
||||
use super::generator::choose_dst;
|
||||
use super::generator::constant_to_boolean;
|
||||
use super::generator::parse_bigint;
|
||||
use super::instruction::Instruction;
|
||||
use super::operand::*;
|
||||
|
||||
|
|
@ -6502,7 +6514,8 @@ fn generate_class_expression(
|
|||
|
||||
/// Synthesize a default constructor SharedFunctionInstanceData.
|
||||
fn emit_default_constructor(generator: &mut Generator, has_super: bool) -> u32 {
|
||||
use crate::parser::{Parser, ProgramType};
|
||||
use crate::parser::Parser;
|
||||
use crate::parser::ProgramType;
|
||||
|
||||
// Wrap in "function" keyword so it parses as a FunctionDeclaration.
|
||||
let source: Utf16String = if has_super {
|
||||
|
|
|
|||
|
|
@ -24,10 +24,13 @@
|
|||
use std::ffi::c_void;
|
||||
use std::mem::align_of;
|
||||
|
||||
use super::generator::{
|
||||
AssembledBytecode, ConstantValue, ExceptionHandler, Generator, PendingClassBlueprint, PendingClassElement,
|
||||
PendingLiteralValueKind,
|
||||
};
|
||||
use super::generator::AssembledBytecode;
|
||||
use super::generator::ConstantValue;
|
||||
use super::generator::ExceptionHandler;
|
||||
use super::generator::Generator;
|
||||
use super::generator::PendingClassBlueprint;
|
||||
use super::generator::PendingClassElement;
|
||||
use super::generator::PendingLiteralValueKind;
|
||||
use crate::ast::Utf16String;
|
||||
use crate::bytecode::basic_block::SourceMapEntry;
|
||||
use crate::u32_from_usize;
|
||||
|
|
|
|||
|
|
@ -10,14 +10,24 @@
|
|||
//! needed for bytecode generation from the AST.
|
||||
|
||||
use std::cell::RefCell;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::rc::Rc;
|
||||
|
||||
use super::basic_block::{BasicBlock, SourceMapEntry};
|
||||
use super::ffi::{AbstractOperationKind, WellKnownSymbolKind};
|
||||
use super::basic_block::BasicBlock;
|
||||
use super::basic_block::SourceMapEntry;
|
||||
use super::ffi::AbstractOperationKind;
|
||||
use super::ffi::WellKnownSymbolKind;
|
||||
use super::instruction::Instruction;
|
||||
use super::operand::*;
|
||||
use crate::ast::{AstArena, FunctionData, FunctionId, FunctionTable, IdentifierId, LocalType, Position, Utf16String};
|
||||
use crate::ast::AstArena;
|
||||
use crate::ast::FunctionData;
|
||||
use crate::ast::FunctionId;
|
||||
use crate::ast::FunctionTable;
|
||||
use crate::ast::IdentifierId;
|
||||
use crate::ast::LocalType;
|
||||
use crate::ast::Position;
|
||||
use crate::ast::Utf16String;
|
||||
use crate::u32_from_usize;
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,9 @@
|
|||
//! the Rust `Instruction` enum, so it works on freshly-encoded as well as
|
||||
//! freshly-deserialized bytecode.
|
||||
|
||||
use super::instruction::{NUM_OPCODES, instruction_length_from_bytes, validate_instruction};
|
||||
use super::instruction::NUM_OPCODES;
|
||||
use super::instruction::instruction_length_from_bytes;
|
||||
use super::instruction::validate_instruction;
|
||||
|
||||
/// Sentinel u32 used by `Operand::INVALID` and by `Optional<*TableIndex>` for
|
||||
/// "no value". Mirrors the C++ `0xFFFFFFFF` constant used throughout
|
||||
|
|
|
|||
|
|
@ -15,18 +15,31 @@ use std::ffi::c_void;
|
|||
use std::ops::Range;
|
||||
use std::rc::Rc;
|
||||
|
||||
use crate::CompiledProgram;
|
||||
use crate::CompiledProgramBytecode;
|
||||
use crate::ModuleCallbacks;
|
||||
use crate::ast;
|
||||
use crate::bytecode::basic_block::SourceMapEntry;
|
||||
use crate::bytecode::ffi::{
|
||||
AbstractOperationKind, ConstantTag, FFISharedFunctionData, FFIUtf16Slice, WellKnownSymbolKind,
|
||||
};
|
||||
use crate::bytecode::generator::{
|
||||
AssembledBytecode, ConstantValue, ExceptionHandler, FunctionSfdMetadata, Generator, PendingClassBlueprint,
|
||||
PendingClassElement, PendingLiteralValueKind, PendingSharedFunctionData, PrecompiledFunction,
|
||||
};
|
||||
use crate::bytecode::validator::{
|
||||
FFIExceptionHandlerOffsets, FFIValidatorBounds, ValidationErrorKind, validate_bytecode,
|
||||
};
|
||||
use crate::{CompiledProgram, CompiledProgramBytecode, ModuleCallbacks, ast, u32_from_usize};
|
||||
use crate::bytecode::ffi::AbstractOperationKind;
|
||||
use crate::bytecode::ffi::ConstantTag;
|
||||
use crate::bytecode::ffi::FFISharedFunctionData;
|
||||
use crate::bytecode::ffi::FFIUtf16Slice;
|
||||
use crate::bytecode::ffi::WellKnownSymbolKind;
|
||||
use crate::bytecode::generator::AssembledBytecode;
|
||||
use crate::bytecode::generator::ConstantValue;
|
||||
use crate::bytecode::generator::ExceptionHandler;
|
||||
use crate::bytecode::generator::FunctionSfdMetadata;
|
||||
use crate::bytecode::generator::Generator;
|
||||
use crate::bytecode::generator::PendingClassBlueprint;
|
||||
use crate::bytecode::generator::PendingClassElement;
|
||||
use crate::bytecode::generator::PendingLiteralValueKind;
|
||||
use crate::bytecode::generator::PendingSharedFunctionData;
|
||||
use crate::bytecode::generator::PrecompiledFunction;
|
||||
use crate::bytecode::validator::FFIExceptionHandlerOffsets;
|
||||
use crate::bytecode::validator::FFIValidatorBounds;
|
||||
use crate::bytecode::validator::ValidationErrorKind;
|
||||
use crate::bytecode::validator::validate_bytecode;
|
||||
use crate::u32_from_usize;
|
||||
|
||||
const MAGIC: &[u8; 8] = b"LBJSBC\0\0";
|
||||
const FORMAT_VERSION: u32 = 12;
|
||||
|
|
@ -1050,10 +1063,12 @@ unsafe fn materialize_script_declaration_metadata(
|
|||
gdi_context: *mut c_void,
|
||||
) -> bool {
|
||||
unsafe {
|
||||
use crate::bytecode::ffi::{
|
||||
script_gdi_push_annex_b_name, script_gdi_push_function, script_gdi_push_lexical_binding,
|
||||
script_gdi_push_lexical_name, script_gdi_push_var_name, script_gdi_push_var_scoped_name,
|
||||
};
|
||||
use crate::bytecode::ffi::script_gdi_push_annex_b_name;
|
||||
use crate::bytecode::ffi::script_gdi_push_function;
|
||||
use crate::bytecode::ffi::script_gdi_push_lexical_binding;
|
||||
use crate::bytecode::ffi::script_gdi_push_lexical_name;
|
||||
use crate::bytecode::ffi::script_gdi_push_var_name;
|
||||
use crate::bytecode::ffi::script_gdi_push_var_scoped_name;
|
||||
|
||||
for name in &metadata.lexical_names {
|
||||
script_gdi_push_lexical_name(gdi_context, name.as_ptr(), name.len());
|
||||
|
|
|
|||
|
|
@ -35,7 +35,8 @@
|
|||
//! used as identifiers in some contexts).
|
||||
|
||||
use crate::ast::Utf16String;
|
||||
use crate::token::{Token, TokenType};
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenType;
|
||||
use crate::u32_from_usize;
|
||||
|
||||
/// State for tracking template literal nesting.
|
||||
|
|
|
|||
|
|
@ -98,10 +98,13 @@ pub(crate) fn u32_from_usize(value: usize) -> u32 {
|
|||
|
||||
use ast::StatementKind;
|
||||
use bytecode::generator::PendingSharedFunctionData;
|
||||
use parser::{ParseError, Parser, ProgramType};
|
||||
use parser::ParseError;
|
||||
use parser::Parser;
|
||||
use parser::ProgramType;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::c_void;
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::panic::catch_unwind;
|
||||
|
||||
// Compile-time assertion: `ParsedProgram` travels between the parse worker
|
||||
// thread and the main thread, so it must be `Send`. After the StringId and
|
||||
|
|
@ -2125,7 +2128,8 @@ pub unsafe extern "C" fn rust_compile_module(
|
|||
/// Extract import/export metadata from a module's scope and call C++ callbacks.
|
||||
unsafe fn extract_module_metadata(scope: &ast::ScopeData, ctx: *mut c_void, cb: &ModuleCallbacks) {
|
||||
unsafe {
|
||||
use ast::{ExportEntryKind, StatementKind};
|
||||
use ast::ExportEntryKind;
|
||||
use ast::StatementKind;
|
||||
|
||||
// Collect all import entries with their module requests.
|
||||
struct ImportEntryWithRequest {
|
||||
|
|
@ -2585,7 +2589,8 @@ fn extract_gdi_common(
|
|||
function_table: &mut ast::FunctionTable,
|
||||
arena: &std::sync::Arc<ast::AstArena>,
|
||||
) {
|
||||
use ast::{DeclarationKind, StatementKind};
|
||||
use ast::DeclarationKind;
|
||||
use ast::StatementKind;
|
||||
|
||||
// Var names (var declarations at any nesting level + top-level function declarations)
|
||||
for child in &scope.children {
|
||||
|
|
@ -2683,10 +2688,13 @@ unsafe fn extract_eval_gdi(
|
|||
referenced_private_names: &[ast::Utf16String],
|
||||
) {
|
||||
unsafe {
|
||||
use bytecode::ffi::{
|
||||
eval_gdi_push_annex_b_name, eval_gdi_push_function, eval_gdi_push_lexical_binding,
|
||||
eval_gdi_push_private_name, eval_gdi_push_var_name, eval_gdi_push_var_scoped_name, eval_gdi_set_strict,
|
||||
};
|
||||
use bytecode::ffi::eval_gdi_push_annex_b_name;
|
||||
use bytecode::ffi::eval_gdi_push_function;
|
||||
use bytecode::ffi::eval_gdi_push_lexical_binding;
|
||||
use bytecode::ffi::eval_gdi_push_private_name;
|
||||
use bytecode::ffi::eval_gdi_push_var_name;
|
||||
use bytecode::ffi::eval_gdi_push_var_scoped_name;
|
||||
use bytecode::ffi::eval_gdi_set_strict;
|
||||
|
||||
eval_gdi_set_strict(ctx, is_strict);
|
||||
|
||||
|
|
@ -2724,11 +2732,14 @@ unsafe fn extract_script_gdi(
|
|||
arena: &std::sync::Arc<ast::AstArena>,
|
||||
) {
|
||||
unsafe {
|
||||
use ast::{DeclarationKind, StatementKind};
|
||||
use bytecode::ffi::{
|
||||
script_gdi_push_annex_b_name, script_gdi_push_function, script_gdi_push_lexical_binding,
|
||||
script_gdi_push_lexical_name, script_gdi_push_var_name, script_gdi_push_var_scoped_name,
|
||||
};
|
||||
use ast::DeclarationKind;
|
||||
use ast::StatementKind;
|
||||
use bytecode::ffi::script_gdi_push_annex_b_name;
|
||||
use bytecode::ffi::script_gdi_push_function;
|
||||
use bytecode::ffi::script_gdi_push_lexical_binding;
|
||||
use bytecode::ffi::script_gdi_push_lexical_name;
|
||||
use bytecode::ffi::script_gdi_push_var_name;
|
||||
use bytecode::ffi::script_gdi_push_var_scoped_name;
|
||||
|
||||
// Lexical names (let/const/using/class at top level) — script-only step.
|
||||
for child in &scope.children {
|
||||
|
|
@ -3589,7 +3600,9 @@ pub unsafe extern "C" fn rust_validate_bytecode(
|
|||
) -> bool {
|
||||
unsafe {
|
||||
abort_on_panic(|| {
|
||||
use bytecode::validator::{FFIValidationError, ValidationErrorKind, validate_bytecode};
|
||||
use bytecode::validator::FFIValidationError;
|
||||
use bytecode::validator::ValidationErrorKind;
|
||||
use bytecode::validator::validate_bytecode;
|
||||
|
||||
let write_error = |err: FFIValidationError| {
|
||||
if !error_out.is_null() {
|
||||
|
|
@ -3653,7 +3666,8 @@ pub unsafe extern "C" fn rust_validate_bytecode(
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
use std::sync::atomic::AtomicUsize;
|
||||
use std::sync::atomic::Ordering;
|
||||
|
||||
static FREED_FOREIGN_OWNERS: AtomicUsize = AtomicUsize::new(0);
|
||||
|
||||
|
|
|
|||
|
|
@ -32,16 +32,34 @@
|
|||
//! save and restore the full parser state including lexer position, current
|
||||
//! token, error list, and all boolean flags.
|
||||
|
||||
use crate::fast_hash::{HashMap, HashSet};
|
||||
use crate::fast_hash::HashMap;
|
||||
use crate::fast_hash::HashSet;
|
||||
|
||||
use crate::ast::{
|
||||
AstArena, BindingPattern, Expression, ExpressionKind, FunctionData, FunctionId, FunctionParameter, FunctionTable,
|
||||
Identifier, IdentifierId, PrivateIdentifier, ProgramData, ScopeData, ScopeId, SourceRange, Statement,
|
||||
StatementKind, StringId, Utf16String,
|
||||
};
|
||||
use crate::lexer::{Lexer, ch};
|
||||
use crate::scope_collector::{ScopeCollector, ScopeCollectorState};
|
||||
use crate::token::{Token, TokenType};
|
||||
use crate::ast::AstArena;
|
||||
use crate::ast::BindingPattern;
|
||||
use crate::ast::Expression;
|
||||
use crate::ast::ExpressionKind;
|
||||
use crate::ast::FunctionData;
|
||||
use crate::ast::FunctionId;
|
||||
use crate::ast::FunctionParameter;
|
||||
use crate::ast::FunctionTable;
|
||||
use crate::ast::Identifier;
|
||||
use crate::ast::IdentifierId;
|
||||
use crate::ast::PrivateIdentifier;
|
||||
use crate::ast::ProgramData;
|
||||
use crate::ast::ScopeData;
|
||||
use crate::ast::ScopeId;
|
||||
use crate::ast::SourceRange;
|
||||
use crate::ast::Statement;
|
||||
use crate::ast::StatementKind;
|
||||
use crate::ast::StringId;
|
||||
use crate::ast::Utf16String;
|
||||
use crate::lexer::Lexer;
|
||||
use crate::lexer::ch;
|
||||
use crate::scope_collector::ScopeCollector;
|
||||
use crate::scope_collector::ScopeCollectorState;
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenType;
|
||||
|
||||
mod declarations;
|
||||
mod expressions;
|
||||
|
|
|
|||
|
|
@ -6,14 +6,23 @@
|
|||
|
||||
//! Declaration parsing: variables, functions, classes, imports, exports.
|
||||
|
||||
use crate::fast_hash::{HashMap, HashSet};
|
||||
use crate::fast_hash::HashMap;
|
||||
use crate::fast_hash::HashSet;
|
||||
|
||||
use crate::ast::*;
|
||||
use crate::lexer::ch;
|
||||
use crate::parser::{
|
||||
Associativity, DeclarationKind, ForbiddenTokens, FunctionKind, MethodKind, PRECEDENCE_ASSIGNMENT, ParamInfo,
|
||||
ParsedParameters, Parser, Position, ProgramType, PropertyKey,
|
||||
};
|
||||
use crate::parser::Associativity;
|
||||
use crate::parser::DeclarationKind;
|
||||
use crate::parser::ForbiddenTokens;
|
||||
use crate::parser::FunctionKind;
|
||||
use crate::parser::MethodKind;
|
||||
use crate::parser::PRECEDENCE_ASSIGNMENT;
|
||||
use crate::parser::ParamInfo;
|
||||
use crate::parser::ParsedParameters;
|
||||
use crate::parser::Parser;
|
||||
use crate::parser::Position;
|
||||
use crate::parser::ProgramType;
|
||||
use crate::parser::PropertyKey;
|
||||
use crate::token::TokenType;
|
||||
|
||||
fn expression_into_identifier(expression: Expression) -> IdentifierId {
|
||||
|
|
|
|||
|
|
@ -11,12 +11,22 @@ use std::sync::Arc;
|
|||
|
||||
use crate::ast::*;
|
||||
use crate::lexer::ch;
|
||||
use crate::parser::{
|
||||
Associativity, ForbiddenTokens, FunctionKind, MethodKind, PRECEDENCE_ASSIGNMENT, PRECEDENCE_COMMA,
|
||||
PRECEDENCE_MEMBER, PRECEDENCE_UNARY, ParamInfo, ParsedParameters, Parser, Position, PropertyKey,
|
||||
is_strict_reserved_word,
|
||||
};
|
||||
use crate::token::{Token, TokenType};
|
||||
use crate::parser::Associativity;
|
||||
use crate::parser::ForbiddenTokens;
|
||||
use crate::parser::FunctionKind;
|
||||
use crate::parser::MethodKind;
|
||||
use crate::parser::PRECEDENCE_ASSIGNMENT;
|
||||
use crate::parser::PRECEDENCE_COMMA;
|
||||
use crate::parser::PRECEDENCE_MEMBER;
|
||||
use crate::parser::PRECEDENCE_UNARY;
|
||||
use crate::parser::ParamInfo;
|
||||
use crate::parser::ParsedParameters;
|
||||
use crate::parser::Parser;
|
||||
use crate::parser::Position;
|
||||
use crate::parser::PropertyKey;
|
||||
use crate::parser::is_strict_reserved_word;
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenType;
|
||||
|
||||
#[derive(PartialEq, Eq)]
|
||||
enum EscapeMode {
|
||||
|
|
|
|||
|
|
@ -9,10 +9,13 @@
|
|||
use crate::fast_hash::HashSet;
|
||||
|
||||
use crate::ast::*;
|
||||
use crate::parser::{
|
||||
Associativity, ForbiddenTokens, PRECEDENCE_COMMA, Parser, Position, is_strict_reserved_word,
|
||||
is_unconditional_reserved_word,
|
||||
};
|
||||
use crate::parser::Associativity;
|
||||
use crate::parser::ForbiddenTokens;
|
||||
use crate::parser::PRECEDENCE_COMMA;
|
||||
use crate::parser::Parser;
|
||||
use crate::parser::Position;
|
||||
use crate::parser::is_strict_reserved_word;
|
||||
use crate::parser::is_unconditional_reserved_word;
|
||||
use crate::token::TokenType;
|
||||
|
||||
/// Used locally during for-statement parsing before converting to `ast::ForInit`.
|
||||
|
|
|
|||
|
|
@ -49,13 +49,24 @@
|
|||
//! - `IdentifierGroup` — a set of identifier references with the same
|
||||
//! name within one scope (multiple `foo` refs are grouped together)
|
||||
|
||||
use crate::fast_hash::{HashMap, IndexMap};
|
||||
use crate::fast_hash::HashMap;
|
||||
use crate::fast_hash::IndexMap;
|
||||
|
||||
use crate::ast::{
|
||||
FunctionScopeData, IdentifierArena, IdentifierId, LocalBinding, LocalVarKind, LocalVariable, ScopeId, Statement,
|
||||
StringId, Utf16String, VarToInit,
|
||||
};
|
||||
use crate::parser::{DeclarationKind, FunctionKind, ParseError, ProgramType};
|
||||
use crate::ast::FunctionScopeData;
|
||||
use crate::ast::IdentifierArena;
|
||||
use crate::ast::IdentifierId;
|
||||
use crate::ast::LocalBinding;
|
||||
use crate::ast::LocalVarKind;
|
||||
use crate::ast::LocalVariable;
|
||||
use crate::ast::ScopeId;
|
||||
use crate::ast::Statement;
|
||||
use crate::ast::StringId;
|
||||
use crate::ast::Utf16String;
|
||||
use crate::ast::VarToInit;
|
||||
use crate::parser::DeclarationKind;
|
||||
use crate::parser::FunctionKind;
|
||||
use crate::parser::ParseError;
|
||||
use crate::parser::ProgramType;
|
||||
use crate::u32_from_usize;
|
||||
|
||||
// === Enums ===
|
||||
|
|
|
|||
|
|
@ -18,7 +18,8 @@
|
|||
//! - A set of registers for capture group positions
|
||||
//! - A backtrack stack for saving/restoring state
|
||||
|
||||
pub use libunicode_rust::character_types::{PropertyKind, ResolvedProperty};
|
||||
pub use libunicode_rust::character_types::PropertyKind;
|
||||
pub use libunicode_rust::character_types::ResolvedProperty;
|
||||
|
||||
/// A named capture group mapping derived from the pattern's named captures.
|
||||
/// <https://tc39.es/ecma262/#sec-parsepattern>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,18 @@
|
|||
/// High-level regex API.
|
||||
///
|
||||
/// This is the main entry point for using the regex engine.
|
||||
use crate::ast::{Alternative, Atom, Disjunction, Flags, Pattern, Term};
|
||||
use crate::bytecode::{Instruction, NamedGroupEntry, append_code_point_wtf16};
|
||||
use crate::{compiler, parser, vm};
|
||||
use crate::ast::Alternative;
|
||||
use crate::ast::Atom;
|
||||
use crate::ast::Disjunction;
|
||||
use crate::ast::Flags;
|
||||
use crate::ast::Pattern;
|
||||
use crate::ast::Term;
|
||||
use crate::bytecode::Instruction;
|
||||
use crate::bytecode::NamedGroupEntry;
|
||||
use crate::bytecode::append_code_point_wtf16;
|
||||
use crate::compiler;
|
||||
use crate::parser;
|
||||
use crate::vm;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashSet;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,14 @@
|
|||
*/
|
||||
|
||||
use calendrical_calculations::rata_die::RataDie;
|
||||
use icu_calendar::{
|
||||
AnyCalendar, AnyCalendarKind, Date, Iso,
|
||||
types::{DateFields, Month},
|
||||
};
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use icu_calendar::AnyCalendar;
|
||||
use icu_calendar::AnyCalendarKind;
|
||||
use icu_calendar::Date;
|
||||
use icu_calendar::Iso;
|
||||
use icu_calendar::types::DateFields;
|
||||
use icu_calendar::types::Month;
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::panic::catch_unwind;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct FfiISODate {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@
|
|||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::fmt::Write;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn generate_opcodes(manifest_dir: &Path, out_dir: &Path) -> Result<(), Box<dyn Error>> {
|
||||
let opcode_h = manifest_dir.join("../Opcode.h");
|
||||
|
|
|
|||
|
|
@ -6,9 +6,14 @@
|
|||
|
||||
#![allow(clippy::manual_let_else)]
|
||||
|
||||
use libwasm_cranelift::{CompiledFunction, CraneliftInsn, HelperReloc, RuntimeHelpers, compile_to_bytes};
|
||||
use libwasm_cranelift::CompiledFunction;
|
||||
use libwasm_cranelift::CraneliftInsn;
|
||||
use libwasm_cranelift::HelperReloc;
|
||||
use libwasm_cranelift::RuntimeHelpers;
|
||||
use libwasm_cranelift::compile_to_bytes;
|
||||
use std::env;
|
||||
use std::mem::{size_of, size_of_val};
|
||||
use std::mem::size_of;
|
||||
use std::mem::size_of_val;
|
||||
|
||||
#[cfg(all(unix, not(target_os = "macos")))]
|
||||
use std::fs::File;
|
||||
|
|
|
|||
|
|
@ -4,23 +4,37 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
use crate::{CraneliftInsn, RuntimeHelpers};
|
||||
use crate::CompiledFunction;
|
||||
use crate::CraneliftInsn;
|
||||
use crate::HelperId;
|
||||
use crate::HelperReloc;
|
||||
use crate::RuntimeHelpers;
|
||||
|
||||
use cranelift_codegen::Context;
|
||||
use cranelift_codegen::FinalizedRelocTarget;
|
||||
use cranelift_codegen::binemit::Reloc;
|
||||
use cranelift_codegen::ir::condcodes::{FloatCC, IntCC};
|
||||
use cranelift_codegen::ir::AbiParam;
|
||||
use cranelift_codegen::ir::ExtFuncData;
|
||||
use cranelift_codegen::ir::ExternalName;
|
||||
use cranelift_codegen::ir::Function;
|
||||
use cranelift_codegen::ir::InstBuilder;
|
||||
use cranelift_codegen::ir::MemFlags;
|
||||
use cranelift_codegen::ir::Signature;
|
||||
use cranelift_codegen::ir::StackSlotData;
|
||||
use cranelift_codegen::ir::StackSlotKind;
|
||||
use cranelift_codegen::ir::UserExternalName;
|
||||
use cranelift_codegen::ir::UserFuncName;
|
||||
use cranelift_codegen::ir::condcodes::FloatCC;
|
||||
use cranelift_codegen::ir::condcodes::IntCC;
|
||||
use cranelift_codegen::ir::types;
|
||||
use cranelift_codegen::ir::{
|
||||
AbiParam, ExtFuncData, ExternalName, Function, InstBuilder, MemFlags, Signature, StackSlotData, StackSlotKind,
|
||||
UserExternalName, UserFuncName,
|
||||
};
|
||||
use cranelift_codegen::settings::{self, Configurable};
|
||||
use cranelift_codegen::{self, Context};
|
||||
use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext, Variable};
|
||||
use cranelift_codegen::settings::Configurable;
|
||||
use cranelift_codegen::settings::{self};
|
||||
use cranelift_codegen::{self};
|
||||
use cranelift_frontend::FunctionBuilder;
|
||||
use cranelift_frontend::FunctionBuilderContext;
|
||||
use cranelift_frontend::Variable;
|
||||
use cranelift_native;
|
||||
|
||||
use crate::{CompiledFunction, HelperId, HelperReloc};
|
||||
|
||||
// Opcode constants generated from Opcode.h (see build.rs.)
|
||||
#[allow(dead_code)]
|
||||
mod op {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::collections::HashMap;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::c_void;
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::panic::catch_unwind;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct ContentBlockerString {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,8 @@ use std::cell::RefCell;
|
|||
use std::collections::HashMap;
|
||||
use std::env;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
const FFI_HEADER: &str = "HTMLTokenizerRustFFI.h";
|
||||
|
|
|
|||
|
|
@ -12,8 +12,12 @@ pub mod token;
|
|||
pub mod tokenizer;
|
||||
|
||||
use std::ptr;
|
||||
use token::{Attribute, Position, TokenPayload, TokenType};
|
||||
use tokenizer::{HtmlTokenizer, State};
|
||||
use token::Attribute;
|
||||
use token::Position;
|
||||
use token::TokenPayload;
|
||||
use token::TokenType;
|
||||
use tokenizer::HtmlTokenizer;
|
||||
use tokenizer::State;
|
||||
|
||||
/// Opaque handle for the Rust tokenizer, passed across the FFI boundary.
|
||||
pub struct RustFfiTokenizerHandle {
|
||||
|
|
|
|||
|
|
@ -5,11 +5,16 @@
|
|||
*/
|
||||
|
||||
use crate::RustFfiTokenizerHandle;
|
||||
use crate::token::{Token, TokenPayload, TokenType};
|
||||
use crate::tokenizer::{HtmlTokenizer, State};
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenPayload;
|
||||
use crate::token::TokenType;
|
||||
use crate::tokenizer::HtmlTokenizer;
|
||||
use crate::tokenizer::State;
|
||||
use std::ffi::c_void;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::ptr::{NonNull, addr_of_mut};
|
||||
use std::ops::Deref;
|
||||
use std::ops::DerefMut;
|
||||
use std::ptr::NonNull;
|
||||
use std::ptr::addr_of_mut;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@
|
|||
*/
|
||||
|
||||
use crate::decode_utf8_to_u32;
|
||||
use crate::token::{Attribute, Token, TokenPayload, TokenType};
|
||||
use crate::token::Attribute;
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenPayload;
|
||||
use crate::token::TokenType;
|
||||
use crate::tokenizer::HtmlTokenizer;
|
||||
use std::ffi::c_void;
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,12 @@
|
|||
use std::collections::VecDeque;
|
||||
|
||||
use crate::entities::NamedCharacterReferenceMatcher;
|
||||
use crate::token::{Attribute, DoctypeData, Position, Token, TokenPayload, TokenType};
|
||||
use crate::token::Attribute;
|
||||
use crate::token::DoctypeData;
|
||||
use crate::token::Position;
|
||||
use crate::token::Token;
|
||||
use crate::token::TokenPayload;
|
||||
use crate::token::TokenType;
|
||||
|
||||
/// Tokenizer states per the WHATWG HTML spec section 13.2.5.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
use chardetng::{EncodingDetector, Iso2022JpDetection, Utf8Detection};
|
||||
use chardetng::EncodingDetector;
|
||||
use chardetng::Iso2022JpDetection;
|
||||
use chardetng::Utf8Detection;
|
||||
|
||||
/// Attempts to detect the character encoding of a byte stream using frequency analysis.
|
||||
///
|
||||
|
|
|
|||
|
|
@ -13,9 +13,13 @@ mod encoding_detection;
|
|||
pub use libweb_html_tokenizer as html_tokenizer;
|
||||
|
||||
use std::ffi::c_void;
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::panic::AssertUnwindSafe;
|
||||
use std::panic::catch_unwind;
|
||||
|
||||
pub use css_tokenizer::{CssHashType, CssNumberType, CssToken, CssTokenType};
|
||||
pub use css_tokenizer::CssHashType;
|
||||
pub use css_tokenizer::CssNumberType;
|
||||
pub use css_tokenizer::CssToken;
|
||||
pub use css_tokenizer::CssTokenType;
|
||||
|
||||
fn abort_on_panic<F: FnOnce() -> R, R>(f: F) -> R {
|
||||
match catch_unwind(AssertUnwindSafe(f)) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
// crate's unit tests don't need to link against the C++ runtime.
|
||||
#![cfg(not(test))]
|
||||
|
||||
use std::alloc::{GlobalAlloc, Layout};
|
||||
use std::alloc::GlobalAlloc;
|
||||
use std::alloc::Layout;
|
||||
|
||||
unsafe extern "C" {
|
||||
fn ladybird_rust_alloc(size: usize, alignment: usize) -> *mut u8;
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
2026.05.5
|
||||
2026.05.25
|
||||
|
|
|
|||
|
|
@ -48,10 +48,10 @@ else
|
|||
((FAILURES+=1))
|
||||
fi
|
||||
|
||||
if cargo fmt --check ; then
|
||||
echo -e "[${GREEN}OK${NC}]: cargo fmt --check"
|
||||
if cargo +nightly fmt --check ; then
|
||||
echo -e "[${GREEN}OK${NC}]: cargo +nightly fmt --check"
|
||||
else
|
||||
echo -e "[${BOLD_RED}FAIL${NC}]: cargo fmt --check"
|
||||
echo -e "[${BOLD_RED}FAIL${NC}]: cargo +nightly fmt --check"
|
||||
((FAILURES+=1))
|
||||
fi
|
||||
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
[toolchain]
|
||||
channel = "1.95.0"
|
||||
# TODO: Pin to a stable version once `imports_granularity` rustfmt option is stable. https://rust-lang.github.io/rustfmt/?version=v1.9.0&search=group#imports_granularity
|
||||
channel = "nightly"
|
||||
components = ["rustfmt", "clippy"]
|
||||
|
|
|
|||
|
|
@ -3,3 +3,4 @@ hard_tabs = false
|
|||
tab_spaces = 4
|
||||
edition = "2024"
|
||||
style_edition = "2024"
|
||||
imports_granularity = "Item"
|
||||
|
|
|
|||
Loading…
Reference in a new issue