-
-
Notifications
You must be signed in to change notification settings - Fork 158
feat(ios): add iOS 27 platform APIs #8699
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
Closed
proggeramlug
wants to merge
1
commit into
PerryTS:main
from
proggeramlug:codex/issue-5536-ios27-api-support
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
166 changes: 166 additions & 0 deletions
166
crates/perry-codegen/tests/ios_platform_api_lowering.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,166 @@ | ||
| //! Regression coverage for the iOS-only `perry/ios` table (#5536). | ||
|
|
||
| use perry_codegen::{compile_module, AppMetadata, CompileOptions}; | ||
| use perry_hir::types::Type; | ||
| use perry_hir::{Expr, Function, Module, ModuleInitKind, Stmt}; | ||
|
|
||
| fn options(target: Option<&str>) -> CompileOptions { | ||
| CompileOptions { | ||
| target: target.map(str::to_string), | ||
| is_entry_module: false, | ||
| non_entry_module_prefixes: Vec::new(), | ||
| import_function_prefixes: Default::default(), | ||
| import_function_ffi_aliases: Default::default(), | ||
| import_function_origin_names: Default::default(), | ||
| import_function_v8_specifiers: Default::default(), | ||
| import_function_node_submodule: Default::default(), | ||
| namespace_node_submodules: Default::default(), | ||
| namespace_v8_specifiers: Default::default(), | ||
| namespace_member_prefixes: Default::default(), | ||
| namespace_member_origin_names: Default::default(), | ||
| emit_ir_only: true, | ||
| verify_native_regions: false, | ||
| disable_buffer_fast_path: false, | ||
| namespace_imports: Vec::new(), | ||
| namespace_member_nested: Vec::new(), | ||
| imported_classes: Vec::new(), | ||
| imported_enums: Vec::new(), | ||
| imported_async_funcs: Default::default(), | ||
| type_aliases: Default::default(), | ||
| imported_func_param_counts: Default::default(), | ||
| imported_func_has_rest: Default::default(), | ||
| imported_func_synthetic_arguments: Default::default(), | ||
| imported_func_return_types: Default::default(), | ||
| imported_vars: Default::default(), | ||
| output_type: "executable".to_string(), | ||
| needs_stdlib: false, | ||
| needs_ui: true, | ||
| needs_geisterhand: false, | ||
| geisterhand_port: 7676, | ||
| enabled_features: Vec::new(), | ||
| native_module_init_names: Vec::new(), | ||
| js_module_specifiers: Vec::new(), | ||
| bundled_extensions: Vec::new(), | ||
| native_library_functions: Vec::new(), | ||
| i18n_table: None, | ||
| fast_math: false, | ||
| fp_contract_mode: perry_codegen::FpContractMode::Off, | ||
| app_metadata: AppMetadata::default(), | ||
| namespace_entries: Vec::new(), | ||
| dynamic_import_path_to_prefix: Default::default(), | ||
| nextjs_path_init_modules: Vec::new(), | ||
| deferred_module_prefixes: Default::default(), | ||
| module_init_deps: Vec::new(), | ||
| is_dynamic_import_target: false, | ||
| debug_locations: false, | ||
| module_source: None, | ||
| debug_source_line_offset: 0, | ||
| } | ||
| } | ||
|
|
||
| fn call(method: &str, args: Vec<Expr>) -> Stmt { | ||
| Stmt::Expr(Expr::NativeMethodCall { | ||
| module: "perry/ios".to_string(), | ||
| class_name: None, | ||
| object: None, | ||
| method: method.to_string(), | ||
| args, | ||
| }) | ||
| } | ||
|
|
||
| fn module(body: Vec<Stmt>) -> Module { | ||
| Module { | ||
| name: "ios_platform_api_probe".to_string(), | ||
| imports: Vec::new(), | ||
| exports: Vec::new(), | ||
| classes: Vec::new(), | ||
| interfaces: Vec::new(), | ||
| type_aliases: Vec::new(), | ||
| enums: Vec::new(), | ||
| globals: Vec::new(), | ||
| functions: vec![Function { | ||
| id: 1, | ||
| name: "probe".to_string(), | ||
| type_params: Vec::new(), | ||
| params: Vec::new(), | ||
| return_type: Type::Number, | ||
| body, | ||
| is_async: false, | ||
| is_generator: false, | ||
| is_strict: false, | ||
| is_exported: false, | ||
| captures: Vec::new(), | ||
| decorators: Vec::new(), | ||
| was_plain_async: false, | ||
| was_unrolled: false, | ||
| }], | ||
| init: Vec::new(), | ||
| exported_native_instances: Vec::new(), | ||
| exported_func_return_native_instances: Vec::new(), | ||
| exported_objects: Vec::new(), | ||
| exported_functions: Vec::new(), | ||
| script_global_functions: Vec::new(), | ||
| references_global_this: false, | ||
| annexb_global_undefined_names: Vec::new(), | ||
| widgets: Vec::new(), | ||
| uses_fetch: false, | ||
| uses_webassembly: false, | ||
| extern_funcs: Vec::new(), | ||
| init_was_unrolled: false, | ||
| has_top_level_await: false, | ||
| init_kind: ModuleInitKind::Eager, | ||
| async_step_closures: Default::default(), | ||
| closure_display_names: Default::default(), | ||
| class_display_names: Default::default(), | ||
| closure_source_text: Default::default(), | ||
| async_generator_funcs: Default::default(), | ||
| local_source_spans: Default::default(), | ||
| gen_param_prologue_len: Default::default(), | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn ios_layout_and_foundation_model_calls_emit_runtime_symbols() { | ||
| let hir = module(vec![ | ||
| call("getLayoutEnvironment", vec![]), | ||
| call("onLayoutChange", vec![Expr::Number(0.0)]), | ||
| call("offLayoutChange", vec![Expr::Number(1.0)]), | ||
| call("foundationModelAvailability", vec![]), | ||
| // The optional instructions argument must pad to an empty runtime string. | ||
| call("createLanguageModelSession", vec![]), | ||
| call( | ||
| "respond", | ||
| vec![Expr::Number(1.0), Expr::String("Hello".to_string())], | ||
| ), | ||
| call("destroyLanguageModelSession", vec![Expr::Number(1.0)]), | ||
| ]); | ||
| let ir = | ||
| String::from_utf8(compile_module(&hir, options(Some("aarch64-apple-ios17.0"))).unwrap()) | ||
| .unwrap(); | ||
|
|
||
| for symbol in [ | ||
| "@perry_ios_get_layout_environment", | ||
| "@perry_ios_on_layout_change", | ||
| "@perry_ios_off_layout_change", | ||
| "@perry_ios_foundation_model_availability", | ||
| "@perry_ios_foundation_model_session_create", | ||
| "@perry_ios_foundation_model_respond", | ||
| "@perry_ios_foundation_model_session_destroy", | ||
| ] { | ||
| assert!(ir.contains(symbol), "missing {symbol} in IR:\n{ir}"); | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn ios_module_is_rejected_for_non_ios_targets() { | ||
| let error = compile_module( | ||
| &module(vec![call("getLayoutEnvironment", vec![])]), | ||
| options(Some("aarch64-apple-darwin")), | ||
| ) | ||
| .unwrap_err(); | ||
| let error = format!("{error:#}"); | ||
| assert!( | ||
| error.contains("perry/ios is only available"), | ||
| "unexpected diagnostic: {error}" | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| //! `PERRY_IOS_TABLE` — iOS-specific adaptive layout and Foundation Models. | ||
|
|
||
| use super::*; | ||
|
|
||
| /// APIs that intentionally expose iOS-only platform capabilities. Keeping | ||
| /// these out of `PERRY_UI_TABLE` prevents other UI backends from having to | ||
| /// pretend that UIKit scene geometry or Foundation Models exist. | ||
| pub static PERRY_IOS_TABLE: &[MethodRow] = &[ | ||
| MethodRow { | ||
| method: "getLayoutEnvironment", | ||
| runtime: "perry_ios_get_layout_environment", | ||
| args: &[], | ||
| ret: ReturnKind::Widget, | ||
| }, | ||
| MethodRow { | ||
| method: "onLayoutChange", | ||
| runtime: "perry_ios_on_layout_change", | ||
| args: &[ArgKind::Closure], | ||
| ret: ReturnKind::I64AsF64, | ||
| }, | ||
| MethodRow { | ||
| method: "offLayoutChange", | ||
| runtime: "perry_ios_off_layout_change", | ||
| args: &[ArgKind::F64], | ||
| ret: ReturnKind::Void, | ||
| }, | ||
| MethodRow { | ||
| method: "foundationModelAvailability", | ||
| runtime: "perry_ios_foundation_model_availability", | ||
| args: &[], | ||
| ret: ReturnKind::Str, | ||
| }, | ||
| MethodRow { | ||
| method: "createLanguageModelSession", | ||
| runtime: "perry_ios_foundation_model_session_create", | ||
| args: &[ArgKind::Str], | ||
| ret: ReturnKind::I64AsF64, | ||
| }, | ||
| MethodRow { | ||
| method: "respond", | ||
| runtime: "perry_ios_foundation_model_respond", | ||
| args: &[ArgKind::F64, ArgKind::Str], | ||
| ret: ReturnKind::Promise, | ||
| }, | ||
| MethodRow { | ||
| method: "destroyLanguageModelSession", | ||
| runtime: "perry_ios_foundation_model_session_destroy", | ||
| args: &[ArgKind::F64], | ||
| ret: ReturnKind::Void, | ||
| }, | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 151
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 35218
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50371
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 24925
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 50369
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 3544
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 28700
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 28338
🏁 Script executed:
Repository: PerryTS/perry
Length of output: 327
Root the layout snapshot during construction.
ReturnKind::Widgetis correct for this generic object handle, and all three runtime symbols exist. However,snapshot_objectkeeps raw GC-managed pointers whileset_fieldandstring_valueallocate. UseRuntimeHandleScopehandles and re-read the pointers before each setter call.🤖 Prompt for AI Agents