Skip to content

Commit 9cf6fa6

Browse files
shannonzhufacebook-github-bot
authored andcommitted
Rename hardcoded decorator functions to be non-private
Summary: Verified that these names weren't meant to be private, just added a prefix to avoid conflicts. Because inlined decorators generate new functions, this doesn't go through preprocessing a second time to make sure the newly generated (hard coded) function names get mangled properly if they are private. When testing, the "expected" source is parsed with all expected generated functions already there and so these are mangled when they're named in a way that looks private. https://docs.python.org/3/reference/expressions.html?highlight=mangling#atom-identifiers > Private name mangling: When an identifier that textually occurs in a class definition begins with two or more underscore characters and does not end in two or more underscores, it is considered a private name of that class. Private names are transformed to a longer form before code is generated for them. The transformation inserts the class name, with leading underscores removed and a single underscore inserted, in front of the name. For example, the identifier spam occurring in a class named Ham will be transformed to _Hamspam. This transformation is independent of the syntactical context in which the identifier is used. Could either throw in an exta re-preprocessing of the "actual" source after it's gone through decorator inlining, or just change the way we hardcode the generated names to avoid the name mangling (they're not even methods on the class, so it makes no practical difference). Figured just avoiding the mangling situation is cleaner; unblocks D30146161. Reviewed By: dkgi Differential Revision: D30212576 fbshipit-source-id: 2c4b47d91f3e478297fe68ae55413f8bbaced6b1
1 parent 592ad6d commit 9cf6fa6

File tree

8 files changed

+424
-428
lines changed

8 files changed

+424
-428
lines changed

source/interprocedural/decoratorHelper.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ open Pyre
1212
open Statement
1313
open Expression
1414

15-
let inlined_original_function_name = "__original_function"
15+
let inlined_original_function_name = "_original_function"
1616

1717
let make_wrapper_function_name decorator_reference =
1818
Reference.delocalize decorator_reference
1919
|> Reference.last
20-
|> Format.asprintf "__inlined_%s"
20+
|> Format.asprintf "_inlined_%s"
2121
|> Reference.create
2222

2323

24-
let args_local_variable_name = "__args"
24+
let args_local_variable_name = "_args"
2525

26-
let kwargs_local_variable_name = "__kwargs"
26+
let kwargs_local_variable_name = "_kwargs"
2727

2828
type decorator_reference_and_module = {
2929
decorator: Reference.t;
@@ -526,7 +526,7 @@ let call_function_with_precise_parameters
526526
-> None`. Pass precise arguments to any calls to `callee_name`.
527527
528528
In order to support uses of `args` and `kwargs` within `wrapper_define`, we create synthetic
529-
local variables `__args` and `__kwargs` that contain all the arguments. *)
529+
local variables `_args` and `_kwargs` that contain all the arguments. *)
530530
let replace_signature_if_always_passing_on_arguments
531531
~callee_name
532532
~new_signature:({ Define.Signature.parameters = new_parameters; _ } as new_signature)
@@ -543,7 +543,7 @@ let replace_signature_if_always_passing_on_arguments
543543
let prefix_parameters = List.rev remaining_parameters in
544544
let callee_prefix_parameters = List.take new_parameters (List.length prefix_parameters) in
545545

546-
(* We have to rename `args` and `kwargs` to `__args` and `__kwargs` before transforming calls
546+
(* We have to rename `args` and `kwargs` to `_args` and `_kwargs` before transforming calls
547547
to `callee`. We also have to rename any prefix parameters.
548548
549549
Otherwise, if we rename them after replacing calls to `callee`, we might inadvertently

0 commit comments

Comments
 (0)