Skip to content
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

Explorer: missing support for class base, abstract, and extends #1881

Closed
Pixep opened this issue Aug 2, 2022 · 4 comments
Closed

Explorer: missing support for class base, abstract, and extends #1881

Pixep opened this issue Aug 2, 2022 · 4 comments
Labels
explorer Action items related to Carbon explorer code long term Issues expected to take over 90 days to resolve.

Comments

@Pixep
Copy link
Contributor

Pixep commented Aug 2, 2022

The explorer generates a non-specific syntax error when trying to use class prefix or extends.

@Tom-debug110
Copy link

haha,I agree you.

@jonmeow jonmeow added the explorer Action items related to Carbon explorer code label Aug 2, 2022
jonmeow pushed a commit that referenced this issue Aug 3, 2022
Provides a first implementation iteration towards class prefix and extension, along with user-friendly error regarding missing implementation for #1881 

**Explorer behavior**
For class prefix `base` and `abstract`: 
```
Class prefixes `base` and `abstract` are not supported yet
```
For extension with `extends`: 
```
Class extension with `extends` is not supported yet
```

**Motivation**
* Provides user-friendly error for these unsupported features
* First implementation increment in supporting class prefix and extension.
jonmeow pushed a commit that referenced this issue Oct 21, 2022
Support class extension with `extends`
Relates to #1881 

Add support for:
* Class extension with `extends`
* Using base class methods and members
@github-actions
Copy link

github-actions bot commented Nov 1, 2022

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time.
This issue is labeled inactive because the last activity was over 90 days ago.

@github-actions github-actions bot added the inactive Issues and PRs which have been inactive for at least 90 days. label Nov 1, 2022
@Pixep Pixep added long term Issues expected to take over 90 days to resolve. and removed inactive Issues and PRs which have been inactive for at least 90 days. labels Nov 1, 2022
zygoloid added a commit that referenced this issue Nov 29, 2022
Relates to #1881

- Add support for `.base` field in structs for [parent class initialization](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/classes.md#constructors)
    - Disabling base class initialization without `.base`
- Support class constructors (`Create() -> Self`) for base classes
- Direct access to base class(es) attributes with `object.var` remains unaffected

Changes:
- Add `TypeChecker::FieldTypesWithBase` to help assessing if a struct with `base` fields can be converted to a class
- Add a new `base_type()` attribute+getter to `NominalClassDeclaration` to as a first step to allow resolving parametrized classes
- Add a new `base` attribute+getter to `NominalClassValue` that contains the base class `NominalClassValue`. It is currently used mainly to get and set members of a class object.
- Add `Interpreter::ConvertClassWithBase` to build `NominalClassValue` from a init struct, that contains `.base` fields with either `NominalClassValue` or `StructValue`
- Add `FindClassField` to find a field in a class or its base classes
- Remove superfluous `ClassDeclaration::base()` in favor of `ClassDeclaration::base_type()`

Limitations;
- Though some work is done in that direction, parametrized base class where time is not know at the declaration site are not supported. Namely the example below does not compile
```
base class A(T:! Type) {}
class B(T:! Type) extends A(T) {}
```
But this one is functional already
```
base class A(T:! Type) {}
class B extends A(i32) {}
```

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
jonmeow pushed a commit that referenced this issue Dec 6, 2022
Relates to #1881 

Features:
* Add basic support for `abstract` class
    * Allow extending an abstract class
    * Prevent direct instantiation of an abstract class
Changes:
* Check that class extensibility for `VariableDefinition` is not `Abstract`
* Add corresponding set of lit tests
jonmeow added a commit that referenced this issue Dec 19, 2022
Features:
* Adds support for [subtyping](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/classes.md#subtyping) for local variables, and function parameters

Changes:
* Update function parameter `Deduce` to handle subtyping
* Update `InstantiateType` to support `PointerType`
* Update `Convert` to support convertion from child class to a base class

Relates to #1881 

Co-authored-by: Jon Ross-Perkins <jperkins@google.com>
Co-authored-by: Geoff Romer <gromer@google.com>
@Pixep
Copy link
Contributor Author

Pixep commented Dec 24, 2022

@jonmeow if we focus this issue on "Inheritance" (outside of virtual methods, etc., as in the wiki), I think we can consider this one "done" to the degree we might want to support it in explorer.

jonmeow pushed a commit that referenced this issue Jan 2, 2023
Features:
* Add `virtual` virtual override keyword for functions
* Support `virtual` class methods using dynamic dispatch

Changes:
* Add `vtable` in `NominalClassType`, 
* Add `NominalClassValue**` in class values pointing to  descendant-most class
* Resolve virtual methods during member lookup

Limitations:
* Does not include yet `impl`, `abstract` virtual override keywords, or the complete logic for virtual function declaration

Depends on #2460 
Relates to #1881 
Relates to #2493
@Pixep
Copy link
Contributor Author

Pixep commented Jan 4, 2023

Closing this one, based on the current Explorer implementation level 🥳

@Pixep Pixep closed this as completed Jan 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
explorer Action items related to Carbon explorer code long term Issues expected to take over 90 days to resolve.
Projects
None yet
Development

No branches or pull requests

3 participants