-
Notifications
You must be signed in to change notification settings - Fork 334
Semi-formal specification for method resolution #13961
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
Merged
+440
−51
Merged
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
663e4cb
docs for method resolution
Akirathan 00577f7
Testing/documenting the type chains for Atom, Type and Module
JaroslavTulach 5f6fdaa
Simplify docs for method resolution
Akirathan 948a1a9
Removing accidental changes
JaroslavTulach 580587b
Apply suggestion from @JaroslavTulach
Akirathan d841f70
Added some observations to eigen types
Akirathan 8f7d18e
Refer to polyglot readme.
Akirathan c6b9a3e
Add parent type and builtin type terminology
Akirathan 9d4e613
Update docs/types/dynamic-dispatch.md
Akirathan 7590715
Reword and simplify.
Akirathan 497f2ab
Remove argument evaluation section
Akirathan 41914f4
Update docs/types/dynamic-dispatch.md
Akirathan 79ea0a5
Merge branch 'develop' into wip/akirathan/docs-methods
Akirathan 550ef53
fmt
Akirathan 76cdd12
typo
Akirathan 6920f9e
Consistently ujse parameters and arguments
Akirathan 86644aa
Update docs with the newest proposition
Akirathan 2cd8f4d
Removing confusion by using different Text values
JaroslavTulach ea61947
Checking the hierarchy of Any and its eigentype
JaroslavTulach 093156d
Type of Any.type is again Any.type
JaroslavTulach ed299f5
Correct terminology - use preapplied argument instead of default
Akirathan 6a7059b
docs for singleton types
Akirathan f9172f5
Update test to reflect newest semantics
Akirathan cdd2f6e
Add tests for normal type and singleton type chains
Akirathan 60c0c79
Update anyCHain test
Akirathan f7395a2
Implement correct semantics of Type.allTypes
Akirathan 7a9e15e
Merge branch 'develop' into wip/akirathan/docs-methods
Akirathan 14fa297
Revert Type to develop. Remove TypeChainTest.
Akirathan 6e60a90
Revert "Revert Type to develop. Remove TypeChainTest."
Akirathan fbdd7ef
NO changes to Type
Akirathan feeb6ba
Ignore failing TypeChainTest
Akirathan 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,3 +162,137 @@ main = Test.simplify | |
| When invoking a method on _module object_ its _module static methods_ take | ||
| precedence over _instance methods_ defined on `Any`. Thus a module serves | ||
| primarily as a _container for module (static) methods_. | ||
|
|
||
| ## Method Resolution | ||
|
|
||
| This section describes the _method resolution_ process, which resolves a | ||
| concrete method definition for a concrete call site. For a method call | ||
| expression `Receiver.symbol`, this section focuses only on a single dispatch | ||
| based on `Receiver` argument. For multiple dispatch, see the | ||
| [Multiple Dispatch](#multiple-dispatch) section. | ||
|
|
||
| Method resolution algorithm for `Receiver.symbol`: | ||
|
|
||
| 1. **Determine the kind of `Receiver`:** | ||
|
|
||
| - 1.1. If `Receiver` is a type (type object), go to step 2. | ||
| - 1.2. If `Receiver` is a value (instance / atom), go to step 3. | ||
| - 1.3. If `Receiver` is a module, go to step 4. | ||
| - 1.4. If `Receiver` is a polyglot object, go to step 5. | ||
| - 1.5. If there is no `Receiver`, go to step 6. | ||
|
|
||
| 2. **`Receiver` is a type. This call site is a _static method call_:** | ||
|
|
||
| - 2.1. We are looking for either a _static method_ or an _instance method_ | ||
| defined on `Receiver` type. | ||
| - 2.2. If `symbol` is defined on `Receiver`, with or without `self` argument, | ||
| select it and stop. | ||
| - 2.3. If `symbol` is defined on `Any`, with or without `self` argument, | ||
| select it and stop. | ||
| - 2.4. Otherwise, raise `No_Such_Method` panic and stop. | ||
|
|
||
| 3. **`Receiver` is a value (instance / atom):** | ||
|
|
||
| - 3.1. We are looking for an _instance method_. | ||
| - 3.2. If `symbol` is defined on `Receiver` with `self` argument, select it | ||
| and stop. | ||
| - 3.3. If `symbol` is defined on `Any` with `self` argument, select it and | ||
| stop. | ||
| - 3.4. Otherwise, raise `No_Such_Method` panic and stop. | ||
|
|
||
| 4. **`Receiver` is a module. We are looking for a _module method_:** | ||
|
|
||
| - 4.1. Module methods are not allowed to be defined with `self` argument. | ||
| - 4.2. If `symbol` is defined in `Receiver` module, select it and stop. | ||
| - 4.3. Otherwise, raise `No_Such_Method` panic and stop. | ||
|
|
||
| 5. **`Receiver` is a polyglot object. A polyglot object can be:** | ||
|
|
||
| - 5.1. A Java class, imported by `polyglot java import ...` statement. | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - 5.2. Java object instance, created by `Java_Class.new ...` expression. | ||
| - 5.3. Javascript, Python, or any other allowed foreign language object | ||
| returned by a foreign method call. | ||
| - 5.4. Searching for `symbol` on such a `Receiver` is subject to the rules of | ||
| the [polyglot Interoperability](../polyglot/README.md) chapter. | ||
|
|
||
| 6. **There is no `Receiver`:** | ||
| - 6.1. We are looking either for a _module method_ or for a variable in the | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| current scope or any parent scopes. | ||
| - 6.2. Note that in this case, `symbol` does not have to resolve to a method | ||
| definition. This is a general _symbol lookup_ rather than a _method | ||
| resolution_. See [Symbol lookup](#symbol-lookup). | ||
|
|
||
| ### Symbol lookup | ||
|
|
||
| - If `symbol` is defined in the current lexical scope, select it and stop. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| - Iterate parent scopes: from the current lexical scope, up until this module | ||
| scope. If `symbol` is defined in the scope, select it and stop. | ||
| - Look for the `symbol` in all transitively imported modules (in DFS?). If | ||
| `symbol` is defined in any of the modules, select it and stop. | ||
| - Raise `Name_Not_Found` panic and stop. | ||
|
|
||
| ## Method evaluation | ||
|
|
||
| This section describes the _method evaluation_ process. We assume that a | ||
| particular method definition was already selected by the | ||
| [method resolution](#method-resolution) process. | ||
|
|
||
| Let's have `method` be a method definition resolved from | ||
| [Method Resolution](#method-resolution) process, that is defined as | ||
| `method [self] [parName=[defaultValue]]* = <body expression>`. | ||
|
|
||
| If `self` parameter is specified, we call it an _instance method_, otherwise, we | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| call it a _static method_. | ||
|
|
||
| ### Instance method call evaluation | ||
|
|
||
| The method call expression in the format of `obj.method [[argName=]argValue]*`, | ||
| where `obj` is an instance (value / atom) of type `T`, and `method` is an | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _instance method_ with `self` argument defined either on `T` or outside `T` as | ||
| an _extension method_, the method evaluation process is as follows: | ||
|
|
||
| - `self` argument cannot be specified explicitly | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Go to [Arguments evaluation](#argument-evaluation) to evaluate `argValue`s and | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| bind them to `argName`s. | ||
|
|
||
| ### Static method call evaluation | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The method call expression in the format of | ||
| `TypeOrModule.method [[argName=]argValue]*`, where `TypeOrModule` is either a | ||
| type or a module, and `method` is a _static method_ defined on `TypeOrModule`. | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Note that `TypeOrModule` does not have to be specified, if `method` is directly | ||
| imported. | ||
|
|
||
| The method evaluation process is as follows: | ||
|
|
||
| 1. **Determine whether `TypeOrModule` is a type or a module:** | ||
|
|
||
| - 1.1. If `TypeOrModule` is not `Any`, go to 2 | ||
| - 1.2. If `TypeOrModule` is `Any`, go to 4 | ||
|
|
||
| 2. **`TypeOrModule` is not `Any`:** | ||
|
|
||
| - 2.1. If `self` argument is specified explicitly, go to 3. `self` argument | ||
| value is either: | ||
| - Passed via `self` named argument. | ||
| - First positional argument. | ||
| - 2.2. If `self` argument is not specified explicitly, go to 4. | ||
|
|
||
| 3. **`self` is specified explicitly:** | ||
|
|
||
| - 3.1. `self` argument is specified explicitly. | ||
| - 3.2. Bind `self` argument to the provided value. | ||
| - 3.3. Go to [Arguments evaluation](#argument-evaluation) to evaluate rest of | ||
| the arguments. | ||
|
|
||
| 4. **`self` is not specified explicitly:** | ||
|
|
||
| - 4.1. `self` argument is not specified explicitly. This can happen only if | ||
| there are no arguments. Which results in a method reference. | ||
|
|
||
| 5. **`TypeOrModule` is `Any`:** | ||
| - 5.1. TODO ... | ||
Akirathan marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Argument evaluation | ||
|
|
||
| TODO | ||
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.
Uh oh!
There was an error while loading. Please reload this page.