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
2 changes: 1 addition & 1 deletion crates/perry/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ pub fn run(args: CheckArgs, format: OutputFormat, use_color: bool, verbose: u8)
}
};

all_diagnostics.extend(parse_result.diagnostics.into_iter());
all_diagnostics.extend(parse_result.diagnostics);

// Run fixer analysis if --fix or --fix-dry-run is enabled
if args.fix || args.fix_dry_run {
Expand Down
32 changes: 12 additions & 20 deletions crates/perry/src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Compile command - compiles TypeScript to native executable

use anyhow::{anyhow, Result};
use clap::Args;
use perry_hir::{Module as HirModule, ModuleKind};
use rayon::prelude::*;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::fs;
Expand Down Expand Up @@ -760,7 +758,7 @@ pub fn run_with_parse_cache(
// Named("BlockTag") -> Union([...]) for correct ABI types in function signatures.
let mut all_type_aliases: std::collections::BTreeMap<String, perry_types::Type> =
std::collections::BTreeMap::new();
for (_path, hir_module) in &ctx.native_modules {
for hir_module in ctx.native_modules.values() {
for ta in &hir_module.type_aliases {
if ta.type_params.is_empty() {
all_type_aliases.insert(ta.name.clone(), ta.ty.clone());
Expand Down Expand Up @@ -792,7 +790,7 @@ pub fn run_with_parse_cache(
// `hir_module.imports` doesn't even mention the source module.
let mut all_program_type_names: std::collections::HashSet<String> =
std::collections::HashSet::new();
for (_path, hir_module) in &ctx.native_modules {
for hir_module in ctx.native_modules.values() {
for class in &hir_module.classes {
all_program_type_names.insert(class.name.clone());
}
Expand Down Expand Up @@ -1038,9 +1036,7 @@ pub fn run_with_parse_cache(
BTreeMap::new();
for (path, hir_module) in &ctx.native_modules {
let path_str = path.to_string_lossy().to_string();
let exports = all_module_exports
.entry(path_str.clone())
.or_insert_with(BTreeMap::new);
let exports = all_module_exports.entry(path_str.clone()).or_default();
// Exported functions
for func in &hir_module.functions {
if func.is_exported {
Expand Down Expand Up @@ -1129,7 +1125,7 @@ pub fn run_with_parse_cache(
{
all_module_export_origin_names
.entry(path_str.clone())
.or_insert_with(BTreeMap::new)
.or_default()
.insert(exported.clone(), local.clone());
}
}
Expand Down Expand Up @@ -1311,7 +1307,7 @@ pub fn run_with_parse_cache(
for (module_path, name, origin, origin_name) in new_export_entries {
all_module_exports
.entry(module_path.clone())
.or_insert_with(BTreeMap::new)
.or_default()
.insert(name.clone(), origin);
// Only record the origin-name entry when it actually differs
// from the export name (the common identity case is implicit —
Expand All @@ -1321,7 +1317,7 @@ pub fn run_with_parse_cache(
if origin_name != name {
all_module_export_origin_names
.entry(module_path)
.or_insert_with(BTreeMap::new)
.or_default()
.insert(name, origin_name);
}
}
Expand Down Expand Up @@ -1933,7 +1929,7 @@ pub fn run_with_parse_cache(
// Set of native-module paths that are dynamic-import targets. We
// also build a parallel set keyed by Module::name for flatten_exports.
let mut dyn_target_paths: std::collections::HashSet<PathBuf> = std::collections::HashSet::new();
for (_path, hir_module) in &ctx.native_modules {
for hir_module in ctx.native_modules.values() {
for import in &hir_module.imports {
// `is_dynamic` covers dynamic-only synthetic edges;
// `is_dynamic_target` (#1672) covers a static edge that is
Expand Down Expand Up @@ -1993,9 +1989,7 @@ pub fn run_with_parse_cache(
.iter()
.find(|c| c.name == fe.source_local)
{
perry_codegen::NamespaceEntryKind::LocalClass {
class_id: class.id as u32,
}
perry_codegen::NamespaceEntryKind::LocalClass { class_id: class.id }
} else if let Some(global) = target_hir
.globals
.iter()
Expand Down Expand Up @@ -2032,9 +2026,7 @@ pub fn run_with_parse_cache(
} else if let Some(class) =
src.classes.iter().find(|c| c.name == fe.source_local)
{
perry_codegen::NamespaceEntryKind::LocalClass {
class_id: class.id as u32,
}
perry_codegen::NamespaceEntryKind::LocalClass { class_id: class.id }
} else {
perry_codegen::NamespaceEntryKind::ForeignVar {
source_prefix: source_prefix.clone(),
Expand Down Expand Up @@ -2389,7 +2381,7 @@ pub fn run_with_parse_cache(
}
for spec in &import.specifiers {
if let perry_hir::ImportSpecifier::Namespace { local } = spec {
if !namespace_imports.contains(&local) {
if !namespace_imports.contains(local) {
namespace_imports.push(local.clone());
}
}
Expand Down Expand Up @@ -4236,14 +4228,14 @@ pub fn run_with_parse_cache(
stored_cache_path: true,
});
}
return Ok(NativeObjectArtifact {
Ok(NativeObjectArtifact {
path: obj_path,
bytes: Some(object_code),
fingerprint: object_fingerprint,
cleanup_after_link: true,
reused_cache_path: false,
stored_cache_path: false,
});
})
})
.collect();

Expand Down
3 changes: 1 addition & 2 deletions crates/perry/src/commands/compile/audit_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ fn write_audit_manifest(ctx: &CompilationContext) -> std::io::Result<()> {
let dir = &ctx.cache_dir;
fs::create_dir_all(dir)?;
let path = dir.join("audit.json");
let json = serde_json::to_string_pretty(&manifest)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
let json = serde_json::to_string_pretty(&manifest).map_err(|e| std::io::Error::other(e))?;
fs::write(&path, json)?;
Ok(())
}
Expand Down
22 changes: 10 additions & 12 deletions crates/perry/src/commands/compile/bundle_ios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub(super) fn build_ios_app_bundle(
let app_dir = exe_path.with_extension("app");
let _ = fs::create_dir_all(&app_dir);
let bundle_exe = app_dir.join(exe_path.file_name().unwrap_or_default());
fs::copy(&exe_path, &bundle_exe)?;
let _ = fs::remove_file(&exe_path);
fs::copy(exe_path, &bundle_exe)?;
let _ = fs::remove_file(exe_path);

let exe_stem = exe_path
.file_stem()
Expand Down Expand Up @@ -437,7 +437,7 @@ pub(super) fn build_ios_app_bundle(
// time; the existing `perry publish` flow picks it up
// automatically when present alongside the .app bundle.
let info_plist =
inject_ios_deeplinks(&info_plist, &input, &app_dir, format).unwrap_or(info_plist);
inject_ios_deeplinks(&info_plist, input, &app_dir, format).unwrap_or(info_plist);

// #1178 — augment `app.entitlements` with the
// `com.apple.security.application-groups` array when
Expand All @@ -451,13 +451,13 @@ pub(super) fn build_ios_app_bundle(
// `[ios] push_notifications = true` is set in perry.toml. Without it
// `registerForRemoteNotifications` always fails and no APNs token is
// produced. Idempotent with the deeplinks / app-group passes above.
inject_ios_push_entitlement(&input, &app_dir, format);
inject_ios_push_entitlement(input, &app_dir, format);

// #1138 — `[google_auth]` block in perry.toml feeds the
// GoogleSignIn SDK via Info.plist keys the Swift bridge in
// `@perryts/google-auth` reads at runtime.
let info_plist =
inject_google_auth_info_plist(&info_plist, &input, format).unwrap_or(info_plist);
inject_google_auth_info_plist(&info_plist, input, format).unwrap_or(info_plist);

fs::write(app_dir.join("Info.plist"), info_plist)?;

Expand Down Expand Up @@ -525,8 +525,7 @@ pub(super) fn build_ios_app_bundle(
};

let image_views = if image_path.is_some() {
format!(
r#"
r#"
<subviews>
<imageView clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleAspectFit" image="splash_image" translatesAutoresizingMaskIntoConstraints="NO" id="img-splash-1">
<rect key="frame" x="132.5" y="362" width="128" height="128"/>
Expand All @@ -539,8 +538,7 @@ pub(super) fn build_ios_app_bundle(
<constraints>
<constraint firstItem="img-splash-1" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="cx-1"/>
<constraint firstItem="img-splash-1" firstAttribute="centerY" secondItem="Ze5-6b-2t3" secondAttribute="centerY" id="cy-1"/>
</constraints>"#
)
</constraints>"#.to_string()
} else {
String::new()
};
Expand Down Expand Up @@ -665,7 +663,7 @@ pub(super) fn build_ios_app_bundle(
}

// --- i18n: generate .lproj bundles for iOS/macOS ---
if let (Some(ref table), Some(ref config)) = (&i18n_table, &i18n_config) {
if let (Some(table), Some(config)) = (&i18n_table, &i18n_config) {
if !table.keys.is_empty() {
for (locale_idx, locale) in config.locales.iter().enumerate() {
let lproj_dir = app_dir.join(format!("{}.lproj", locale));
Expand Down Expand Up @@ -697,7 +695,7 @@ pub(super) fn build_ios_app_bundle(
}
}

compile_metallib_for_bundle(&ctx, target, &app_dir, format)?;
compile_metallib_for_bundle(ctx, target, &app_dir, format)?;
stage_native_library_artifacts(ctx, &app_dir, format)?;

// Issue #676: build any [[widget]] entries declared in perry.toml,
Expand All @@ -706,7 +704,7 @@ pub(super) fn build_ios_app_bundle(
// inside the helper.
let widgets_built = {
let is_ios_sim = matches!(target, Some("ios-simulator"));
widget_build::build_declared_widgets_ios(&input, &app_dir, is_ios_sim, &bundle_id, format)?
widget_build::build_declared_widgets_ios(input, &app_dir, is_ios_sim, &bundle_id, format)?
};

match format {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ pub fn function_local_specs(source: &str) -> std::collections::HashSet<String> {
// spec → (seen any site, all sites so far in-function).
let mut state: HashMap<&str, (bool, bool)> = HashMap::new();
let mut next_site = 0usize;
let in_function = |scopes: &[Scope]| scopes.iter().any(|s| *s == Scope::Function);
let in_function = |scopes: &[Scope]| scopes.contains(&Scope::Function);

let mut i = 0usize;
while i < mbytes.len() {
Expand Down
8 changes: 4 additions & 4 deletions crates/perry/src/commands/compile/cjs_wrap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ mod hoist_classes;
mod wrap;

// Cross-sibling helpers — siblings reach for these via `use super::*;`.
pub(self) use detect::is_js_reserved_word;
pub(self) use extract_exports::{
use detect::is_js_reserved_word;
use extract_exports::{
extract_exports_from_source, extract_named_exports_from_require,
extract_object_literal_exports_from_require, extract_single_module_exports_assignment,
module_reexport_specs,
};
pub(self) use extract_requires::{
use extract_requires::{
extract_export_star_specs, extract_require_aliases_with_ranges, extract_require_specifiers,
function_local_specs, identifier_is_declared_binding, identifier_is_reassigned,
};
pub(self) use hoist_classes::{
use hoist_classes::{
extract_top_level_class_decls, rewrite_module_exports_class_expression,
source_has_top_level_return, top_level_class_names,
};
Expand Down
6 changes: 3 additions & 3 deletions crates/perry/src/commands/compile/collect_modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ fn collect_module_one(
..Default::default()
});
let ast_module_owned: swc_ecma_ast::Module;
let ast_module: &swc_ecma_ast::Module = match parse_cache.as_deref_mut() {
let ast_module: &swc_ecma_ast::Module = match parse_cache {
Some(cache) => match parse_cached(cache, &canonical, &source, parse_filename) {
Ok(m) => m,
Err(e) => {
Expand Down Expand Up @@ -1624,14 +1624,14 @@ fn collect_module_one(
}
}

return Ok(ModuleDiscovery {
Ok(ModuleDiscovery {
finish: Some(PreparedModule {
canonical,
module_name,
hir_module,
}),
children: pending,
});
})
}

fn collect_module_finish(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
//! Dynamic-`import()` glob expansion (#1674 sub-part B). Split out of
//! `collect_modules.rs` to keep that file under the file-size gate.

use super::*;

/// #1674 sub-part B: expand a dynamic-`import()` glob pattern
/// (`<prefix>*<suffix>`, where `prefix` is a relative, directory-anchored
/// path) into concrete relative specifiers by reading the importing module's
Expand Down
18 changes: 9 additions & 9 deletions crates/perry/src/commands/compile/link/build_and_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ pub(crate) fn build_and_run_link(
}
}
// Tier-3 (tvOS/watchOS) std-duplication dedup; no-op elsewhere.
cmd.arg(&dedup_stdlib_for_tier3(target, stdlib));
cmd.arg(dedup_stdlib_for_tier3(target, stdlib));
// #466 Phase 4 step 2: well-known bindings normally join the
// link line right after perry-stdlib so they cover the exact
// `_js_*` symbol gap that was just opened by stripping the
Expand All @@ -351,7 +351,7 @@ pub(crate) fn build_and_run_link(
// Also link runtime for symbols DCE'd from stdlib's bundled
// perry-runtime; on tier-3 it's first stripped of stdlib's objects.
if !is_android && !is_windows {
cmd.arg(&dedup_runtime_for_tier3(target, runtime_lib, stdlib));
cmd.arg(dedup_runtime_for_tier3(target, runtime_lib, stdlib));
}
} else {
if ctx.needs_stdlib {
Expand Down Expand Up @@ -826,7 +826,7 @@ pub(crate) fn build_and_run_link(
if let Ok(ref output) = pc_out {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
got_gtk_libs = true;
Expand Down Expand Up @@ -894,7 +894,7 @@ pub(crate) fn build_and_run_link(
if let Ok(ref output) = gst_pc_out {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
got_gst_libs = true;
Expand Down Expand Up @@ -939,7 +939,7 @@ pub(crate) fn build_and_run_link(
if let Ok(ref output) = shumate_pc_out {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
got_shumate_libs = true;
Expand Down Expand Up @@ -977,7 +977,7 @@ pub(crate) fn build_and_run_link(
if let Ok(ref output) = webkit_pc_out {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
got_webkit_libs = true;
Expand Down Expand Up @@ -1362,7 +1362,7 @@ pub(crate) fn build_and_run_link(
&& native_lib.module.contains("plugin");
if force_load {
cmd.arg(format!("-Wl,-force_load,{}", lib.display()));
} else if is_windows && lib.extension().map_or(false, |e| e == "lib") {
} else if is_windows && lib.extension().is_some_and(|e| e == "lib") {
// On Windows, link native staticlibs directly —
// /FORCE:MULTIPLE handles duplicate symbols.
cmd.arg(&lib);
Expand Down Expand Up @@ -1474,7 +1474,7 @@ pub(crate) fn build_and_run_link(
if let Ok(output) = Command::new("pkg-config").args(["--libs", pkg]).output() {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
}
Expand Down Expand Up @@ -1542,7 +1542,7 @@ pub(crate) fn build_and_run_link(
if let Ok(output) = Command::new("pkg-config").args(["--libs", pkg]).output() {
if output.status.success() {
let libs = String::from_utf8_lossy(&output.stdout);
for flag in libs.trim().split_whitespace() {
for flag in libs.split_whitespace() {
cmd.arg(flag);
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/perry/src/commands/compile/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ pub(super) use build_and_run::build_and_run_link;
use link_cache::prepare_link_cache_status;
pub(super) use link_cache::{write_link_cache_manifest, LinkCacheStatus};
pub use platform_cmd::select_linker_command;
pub(super) use windows_link::WINDOWS_APP_MANIFEST; // guarded by windows_link_tests
#[cfg(test)]
pub(super) use windows_link::WINDOWS_APP_MANIFEST; // consumed only by windows_link_tests

#[derive(Debug, Clone, PartialEq, Eq)]
struct NativeBackendLinkMetadata {
Expand Down
6 changes: 2 additions & 4 deletions crates/perry/src/commands/compile/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,8 @@ pub(super) fn resolve_exports_candidates(
const CONDITIONS: &[&str] = &["perry", "node", "import", "module", "default", "require"];
fn collect(value: &serde_json::Value, subpath: &str, out: &mut Vec<String>) {
match value {
serde_json::Value::String(s) => {
if !out.contains(s) {
out.push(s.clone());
}
serde_json::Value::String(s) if !out.contains(s) => {
out.push(s.clone());
}
// Node "exports" fallback arrays (e.g. y18n's
// `[{ "import": "./index.mjs", "require": "./build/index.cjs" }, "./build/index.cjs"]`).
Expand Down
Loading
Loading