carbon-lang
carbon-lang copied to clipboard
Explorer: change `InstantiateType` to be an `Action` instead of a method
Background
Our current explorer implementation uses a simple function for type instantiation (substitute placeholder type with actual types). A better approach would be to have it be an Action for the action stack.
Goal
InstantiateType replaces all type variables (for example T) by their actual type values (for example i32). The goal is to create a new TypeInstantiationAction (class TypeInstantiationAction : public Action) that produces the same behavior.
The InstantiateType method is declared in interpreter.cpp:139
// Instantiate a type by replacing all type variables that occur inside the
// type by the current values of those variables.
//
// For example, suppose T=i32 and U=bool. Then
// __Fn (Point(T)) -> Point(U)
// becomes
// __Fn (Point(i32)) -> Point(bool)
//
// TODO: This should be an Action.
auto InstantiateType(Nonnull<const Value*> type, SourceLocation source_loc)
-> ErrorOr<Nonnull<const Value*>>;
Suggested approach
At a high-level, this could be achieved by:
- Adding a new
TypeInstantiationActionenum toAction::Kind - Creating a new
TypeInstantiationActionclass, following the example of similar classes likeExpressionAction - Updating code that makes use of
Actions:Interpreter::Step: entry point of actions, to invokeInstantiateTypemethodAction::Print: prints an action
- Changing code that directly invokes
InstantiateType, to instead spawn a newTypeInstantiationAction- For example:
return todo_.Spawn(std::make_unique<TypeInstantiationAction>(...)); - This will require using
act.pos()to add a new step for instantiation, before dependent code can be executed. See Interpreter readme for a description of the action stack
- For example:
Resources
- https://github.com/carbon-language/carbon-lang/blob/trunk/CONTRIBUTING.md
- https://github.com/carbon-language/carbon-lang/blob/trunk/docs/project/contribution_tools.md
#contributing-helpchannel on the Discord
Hi. I'd like to work on this issue
Hi. I would like to work on this and I would like to contribute to Carbon Language
Hey @Pixep sir, I would like to contribute to this issue. Could you please assign this to me?
Hi, I'm just starting out with contributions. I found this issue tagged as Good First and I would like to know more about this issue and contribute to Carbon Language. Also, it would be great if I get to know a bit about the prerequisites.
Hi Mr. @Pixep, I already started working on this issue.. but I found guys asking for "assigning" .. my question is it a must to get assigned before start contributing ?
Hi everyone, i don't believe we have precise rules around contributions, and issues don't have to be assigned to be worked on, but I would recommend waiting for @PaarthAgarwal 's, who was the first to comment here, to avoid duplicating effort. @PaarthAgarwal is this something you are working on?
Yes I am. Will open a PR tomorrow most certainly
@PaarthAgarwal let me know if you need some help resolving this issue CC: @Pixep
I want to contribute in it please assign it to me and also if you don't mind will you please explain me about the issue. Its a humble request
@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it
I found some issues with Global declarations. How can I proceed with documenting them?
@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it
How long do you think you would need @PaarthAgarwal ? I don't think we are in a hurry, as long as we can make progress, so it is up to you.
@Pixep I'm next on the queue, let me try.
@Pixep I got stuck while working on the issue and I think it'll take me more time to understand the codebase. You can assign this issue to others who are interested to work on it
How long do you think you would need @PaarthAgarwal ? I don't think we are in a hurry, as long as we can make progress, so it is up to you.
I don't know. Perhaps issues regarding web development are more suited for me. For example while setting up this project I found documentation to install bazel for Linux Ubuntu inadequate. Would like do to a PR for the same
Alright in that case we can open it to someone else if that is OK with you. People can contribute by reviewing the language design, providing feedback, and working on the Explorer or toolchain, but none are web-related as far as I know, see README.md.
@Pixep should I try for it, Since this issue is open for a long time and is waiting to be completed so you can assign it to me.
Hi @Pixep sir ,I'm interested in working on this and contributing to Carbon Language.
Removing "good first issue" here since we're talking about archiving the explorer.
Closing explorer-specific issues as not-planned for now due to our decision to prioritize working on the toolchain over other implementation work in the near term: https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p3532.md