-
-
Notifications
You must be signed in to change notification settings - Fork 161
fix: restore class member source and localize default dates #9543
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:fix/9468-9451-method-intl-default
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,15 @@ | ||
| ### Fixed | ||
|
|
||
| - **Class methods and accessors now retain their original source text.** | ||
| `String(C.prototype.method)`, direct `.toString()`, template coercion, and | ||
| reflected getter/setter functions return the source MethodDefinition rather | ||
| than a synthesized native-function body. Object-literal accessors also | ||
| receive their specified `get name` / `set name` function names. CommonJS | ||
| class expressions keep assignment-inferred names without exposing Perry's | ||
| internal anonymous-default registration key. Fixes #9468. | ||
|
|
||
| - **Default `Intl.DateTimeFormat` dates now use the locale's CLDR numeric | ||
| pattern.** The implicit numeric year/month/day field set, its | ||
| `formatToParts()` output, and `Date.prototype.toLocaleDateString()` now agree | ||
| on locale order, separators, and padding instead of falling back to the | ||
| hard-coded US layout. Fixes #9451. |
117 changes: 117 additions & 0 deletions
117
crates/perry-codegen/src/codegen/artifact_source_text.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,117 @@ | ||
| //! Source-text registration for raw class method and accessor symbols. | ||
| //! | ||
| //! Class members are not ordinary closure wrappers, so their retained source | ||
| //! must be paired with the LLVM body symbol codegen actually emitted. Kept out | ||
| //! of `artifacts.rs` so that file remains below the repository's 2,000-line | ||
| //! limit. | ||
|
|
||
| use std::collections::HashSet; | ||
|
|
||
| use perry_hir::types::FuncId; | ||
| use perry_hir::Module as HirModule; | ||
|
|
||
| use crate::module::LlModule; | ||
|
|
||
| use super::helpers::{scoped_method_name, scoped_static_method_name}; | ||
|
|
||
| pub(super) fn extend_class_method_source_text( | ||
| hir: &HirModule, | ||
| module_prefix: &str, | ||
| llmod: &LlModule, | ||
| user_fn_source: &mut Vec<(String, String)>, | ||
| ) { | ||
| // An HIR registry entry is not proof that this module emitted the body: a | ||
| // cross-module or typed-only accessor can remain present without a local | ||
| // definition. Referencing such a symbol from module initialization makes | ||
| // LLVM reject the module, so `has_function` is the final authority. | ||
| let mut seen: HashSet<String> = user_fn_source | ||
| .iter() | ||
| .map(|(symbol, _)| symbol.clone()) | ||
| .collect(); | ||
| let mut push_defined = |func_id: FuncId, symbol: String| { | ||
| let Some(source) = hir.closure_source_text.get(&func_id) else { | ||
| return; | ||
| }; | ||
| if symbol.is_empty() || !llmod.has_function(&symbol) || !seen.insert(symbol.clone()) { | ||
| return; | ||
| } | ||
| user_fn_source.push((symbol, source.clone())); | ||
| }; | ||
|
|
||
| for class in &hir.classes { | ||
| if class.id == 0 { | ||
| continue; | ||
| } | ||
| for method in &class.methods { | ||
| push_defined( | ||
| method.id, | ||
| scoped_method_name(module_prefix, &class.name, &method.name), | ||
| ); | ||
| } | ||
| for member in class | ||
| .computed_members | ||
| .iter() | ||
| .filter(|member| !member.is_static) | ||
| { | ||
| push_defined( | ||
| member.function.id, | ||
| scoped_method_name(module_prefix, &class.name, &member.function.name), | ||
| ); | ||
| } | ||
| for (prop, getter) in &class.getters { | ||
| let symbol = if class.static_accessor_fn_ids.contains(&getter.id) { | ||
| scoped_static_method_name( | ||
| module_prefix, | ||
| class.id, | ||
| &class.name, | ||
| &format!("__get_{prop}"), | ||
| ) | ||
| } else { | ||
| scoped_method_name( | ||
| module_prefix, | ||
| &class.name, | ||
| &format!("__get_{}", getter.name), | ||
| ) | ||
| }; | ||
| push_defined(getter.id, symbol); | ||
| } | ||
| for (prop, setter) in &class.setters { | ||
| let symbol = if class.static_accessor_fn_ids.contains(&setter.id) { | ||
| scoped_static_method_name( | ||
| module_prefix, | ||
| class.id, | ||
| &class.name, | ||
| &format!("__set_{prop}"), | ||
| ) | ||
| } else { | ||
| scoped_method_name( | ||
| module_prefix, | ||
| &class.name, | ||
| &format!("__set_{}", setter.name), | ||
| ) | ||
| }; | ||
| push_defined(setter.id, symbol); | ||
| } | ||
| for method in &class.static_methods { | ||
| push_defined( | ||
| method.id, | ||
| scoped_static_method_name(module_prefix, class.id, &class.name, &method.name), | ||
| ); | ||
| } | ||
| for member in class | ||
| .computed_members | ||
| .iter() | ||
| .filter(|member| member.is_static) | ||
| { | ||
| push_defined( | ||
| member.function.id, | ||
| scoped_static_method_name( | ||
| module_prefix, | ||
| class.id, | ||
| &class.name, | ||
| &member.function.name, | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| } | ||
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
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
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Use the emitted instance-accessor symbol names.
artifacts.rscompiles instance accessors as__get_{prop}and__set_{prop}. These lines build__get_{getter.name}and__set_{setter.name}instead. Forget value(), this looks up__get_get_value, sohas_functionrejects it and reflected getter/setter source is not registered.Use
propin both instance branches.Proposed fix
Also applies to: 90-90
🤖 Prompt for AI Agents